Skip to content

Commit 5478610

Browse files
authored
Merge pull request #1708 from makermelissa/ssd1351-fix
Added option to allow Displays with Single Byte Boundaries
2 parents 7e99b2d + e254597 commit 5478610

File tree

7 files changed

+33
-15
lines changed

7 files changed

+33
-15
lines changed

ports/atmel-samd/boards/hallowing_m0_express/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ void board_init(void) {
9393
0x37, // set vertical scroll command
9494
display_init_sequence,
9595
sizeof(display_init_sequence),
96-
&pin_PA00);
96+
&pin_PA00,
97+
false); // single_byte_bounds
9798
common_hal_displayio_display_set_auto_brightness(display, true);
9899
}
99100

ports/atmel-samd/boards/pybadge/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ void board_init(void) {
9999
0x37, // set vertical scroll command
100100
display_init_sequence,
101101
sizeof(display_init_sequence),
102-
&pin_PA00);
102+
&pin_PA00,
103+
false); // single_byte_bounds
103104
common_hal_displayio_display_set_auto_brightness(display, true);
104105
}
105106

ports/atmel-samd/boards/pyportal/board.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ void board_init(void) {
9090
0x37, // Set vertical scroll command
9191
display_init_sequence,
9292
sizeof(display_init_sequence),
93-
&pin_PB31);
93+
&pin_PB31,
94+
false); // single_byte_bounds
95+
9496
common_hal_displayio_display_set_auto_brightness(display, true);
9597
}
9698

shared-bindings/displayio/Display.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
//| Most people should not use this class directly. Use a specific display driver instead that will
5151
//| contain the initialization sequence at minimum.
5252
//|
53-
//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None)
53+
//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, single_byte_bounds=False)
5454
//|
5555
//| Create a Display object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`).
5656
//|
@@ -91,9 +91,10 @@
9191
//| :param int write_ram_command: Command used to write pixels values into the update region
9292
//| :param int set_vertical_scroll: Command used to set the first row to show
9393
//| :param microcontroller.Pin backlight_pin: Pin connected to the display's backlight
94+
//| :param bool single_byte_bounds: Display column and row commands use single bytes
9495
//|
9596
STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
96-
enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin };
97+
enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_single_byte_bounds };
9798
static const mp_arg_t allowed_args[] = {
9899
{ MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ },
99100
{ MP_QSTR_init_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ },
@@ -108,6 +109,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
108109
{ MP_QSTR_write_ram_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2c} },
109110
{ MP_QSTR_set_vertical_scroll, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x0} },
110111
{ MP_QSTR_backlight_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
112+
{ MP_QSTR_single_byte_bounds, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
111113
};
112114
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
113115
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@@ -146,7 +148,8 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
146148
args[ARG_color_depth].u_int, args[ARG_set_column_command].u_int, args[ARG_set_row_command].u_int,
147149
args[ARG_write_ram_command].u_int,
148150
args[ARG_set_vertical_scroll].u_int,
149-
bufinfo.buf, bufinfo.len, MP_OBJ_TO_PTR(backlight_pin));
151+
bufinfo.buf, bufinfo.len, MP_OBJ_TO_PTR(backlight_pin),
152+
args[ARG_single_byte_bounds].u_bool);
150153

151154
return self;
152155
}

shared-bindings/displayio/Display.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
4040
mp_obj_t bus, uint16_t width, uint16_t height,
4141
int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t color_depth,
4242
uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll,
43-
uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin);
43+
uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, bool single_byte_bounds);
4444

4545
int32_t common_hal_displayio_display_wait_for_frame(displayio_display_obj_t* self);
4646

shared-module/displayio/Display.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
4444
mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart, uint16_t rotation,
4545
uint16_t color_depth, uint8_t set_column_command, uint8_t set_row_command,
4646
uint8_t write_ram_command, uint8_t set_vertical_scroll, uint8_t* init_sequence, uint16_t init_sequence_len,
47-
const mcu_pin_obj_t* backlight_pin) {
47+
const mcu_pin_obj_t* backlight_pin, bool single_byte_bounds) {
4848
self->color_depth = color_depth;
4949
self->set_column_command = set_column_command;
5050
self->set_row_command = set_row_command;
@@ -54,6 +54,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
5454
self->colstart = colstart;
5555
self->rowstart = rowstart;
5656
self->auto_brightness = false;
57+
self->single_byte_bounds = single_byte_bounds;
5758

5859
if (MP_OBJ_IS_TYPE(bus, &displayio_parallelbus_type)) {
5960
self->begin_transaction = common_hal_displayio_parallelbus_begin_transaction;
@@ -211,16 +212,25 @@ void displayio_display_end_transaction(displayio_display_obj_t* self) {
211212
}
212213

213214
void displayio_display_set_region_to_update(displayio_display_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
214-
// TODO(tannewt): Handle displays with single byte bounds.
215215
uint16_t data[2];
216216
self->send(self->bus, true, &self->set_column_command, 1);
217-
data[0] = __builtin_bswap16(x0 + self->colstart);
218-
data[1] = __builtin_bswap16(x1 - 1 + self->colstart);
219-
self->send(self->bus, false, (uint8_t*) data, 4);
217+
if (self->single_byte_bounds) {
218+
data[0] = __builtin_bswap16(((x0 + self->colstart) << 8) | ((x1 - 1 + self->colstart) & 0xFF));
219+
self->send(self->bus, false, (uint8_t*) data, 2);
220+
} else {
221+
data[0] = __builtin_bswap16(x0 + self->colstart);
222+
data[1] = __builtin_bswap16(x1 - 1 + self->colstart);
223+
self->send(self->bus, false, (uint8_t*) data, 4);
224+
}
220225
self->send(self->bus, true, &self->set_row_command, 1);
221-
data[0] = __builtin_bswap16(y0 + self->rowstart);
222-
data[1] = __builtin_bswap16(y1 - 1 + self->rowstart);
223-
self->send(self->bus, false, (uint8_t*) data, 4);
226+
if (self->single_byte_bounds) {
227+
data[0] = __builtin_bswap16(((y0 + self->rowstart) << 8) | ((y1 - 1 + self->rowstart) & 0xFF));
228+
self->send(self->bus, false, (uint8_t*) data, 2);
229+
} else {
230+
data[0] = __builtin_bswap16(y0 + self->rowstart);
231+
data[1] = __builtin_bswap16(y1 - 1 + self->rowstart);
232+
self->send(self->bus, false, (uint8_t*) data, 4);
233+
}
224234
self->send(self->bus, true, &self->write_ram_command, 1);
225235
}
226236

shared-module/displayio/Display.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ typedef struct {
4949
uint64_t last_refresh;
5050
int16_t colstart;
5151
int16_t rowstart;
52+
bool single_byte_bounds;
5253
display_bus_begin_transaction begin_transaction;
5354
display_bus_send send;
5455
display_bus_end_transaction end_transaction;

0 commit comments

Comments
 (0)