Skip to content

Commit 7089ea4

Browse files
committed
Add address_little_endian for displayio
Add address_little_endian for epaper displays with little endian (low byte first) addresses. Also clears allocated display and display bus memory so it has a known state. The acep member wasn't always set so it varied accidentally. Fixes #7560. May fix #7778. Fixes #5119.
1 parent d078bc3 commit 7089ea4

File tree

14 files changed

+181
-129
lines changed

14 files changed

+181
-129
lines changed

shared-bindings/displayio/EPaperDisplay.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@
8080
//| grayscale: bool = False,
8181
//| advanced_color_epaper: bool = False,
8282
//| two_byte_sequence_length: bool = False,
83-
//| start_up_time: float = 0
83+
//| start_up_time: float = 0,
84+
//| address_little_endian: bool = False
8485
//| ) -> None:
8586
//| """Create a EPaperDisplay object on the given display bus (`displayio.FourWire` or `paralleldisplay.ParallelBus`).
8687
//|
@@ -122,6 +123,7 @@
122123
//| :param bool advanced_color_epaper: When true, the display is a 7-color advanced color epaper (ACeP)
123124
//| :param bool two_byte_sequence_length: When true, use two bytes to define sequence length
124125
//| :param float start_up_time: Time to wait after reset before sending commands
126+
//| :param bool address_little_endian: Send the least significant byte (not bit) of multi-byte addresses first. Ignored when ram is addressed with one byte
125127
//| """
126128
//| ...
127129
STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
@@ -132,7 +134,7 @@ STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size
132134
ARG_write_color_ram_command, ARG_color_bits_inverted, ARG_highlight_color,
133135
ARG_refresh_display_command, ARG_refresh_time, ARG_busy_pin, ARG_busy_state,
134136
ARG_seconds_per_frame, ARG_always_toggle_chip_select, ARG_grayscale, ARG_advanced_color_epaper,
135-
ARG_two_byte_sequence_length, ARG_start_up_time };
137+
ARG_two_byte_sequence_length, ARG_start_up_time, ARG_address_little_endian };
136138
static const mp_arg_t allowed_args[] = {
137139
{ MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ },
138140
{ MP_QSTR_start_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ },
@@ -163,6 +165,7 @@ STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size
163165
{ MP_QSTR_advanced_color_epaper, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
164166
{ MP_QSTR_two_byte_sequence_length, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
165167
{ MP_QSTR_start_up_time, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NEW_SMALL_INT(0)} },
168+
{ MP_QSTR_address_little_endian, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
166169
};
167170
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
168171
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@@ -228,7 +231,8 @@ STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size
228231
args[ARG_write_black_ram_command].u_int, args[ARG_black_bits_inverted].u_bool, write_color_ram_command,
229232
args[ARG_color_bits_inverted].u_bool, highlight_color, refresh_buf, refresh_buf_len, refresh_time,
230233
busy_pin, args[ARG_busy_state].u_bool, seconds_per_frame,
231-
args[ARG_always_toggle_chip_select].u_bool, args[ARG_grayscale].u_bool, args[ARG_advanced_color_epaper].u_bool, two_byte_sequence_length
234+
args[ARG_always_toggle_chip_select].u_bool, args[ARG_grayscale].u_bool, args[ARG_advanced_color_epaper].u_bool,
235+
two_byte_sequence_length, args[ARG_address_little_endian].u_bool
232236
);
233237

234238
return self;

shared-bindings/displayio/EPaperDisplay.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,18 @@ extern const mp_obj_type_t displayio_epaperdisplay_type;
3737
#define NO_COMMAND 0x100
3838

3939
void common_hal_displayio_epaperdisplay_construct(displayio_epaperdisplay_obj_t *self,
40-
mp_obj_t bus, const uint8_t *start_sequence, uint16_t start_sequence_len, mp_float_t start_up_time, const uint8_t *stop_sequence, uint16_t stop_sequence_len,
41-
uint16_t width, uint16_t height, uint16_t ram_width, uint16_t ram_height, int16_t colstart, int16_t rowstart, uint16_t rotation,
40+
mp_obj_t bus, const uint8_t *start_sequence, uint16_t start_sequence_len, mp_float_t start_up_time,
41+
const uint8_t *stop_sequence, uint16_t stop_sequence_len,
42+
uint16_t width, uint16_t height, uint16_t ram_width, uint16_t ram_height,
43+
int16_t colstart, int16_t rowstart, uint16_t rotation,
4244
uint16_t set_column_window_command, uint16_t set_row_window_command,
4345
uint16_t set_current_column_command, uint16_t set_current_row_command,
44-
uint16_t write_black_ram_command, bool black_bits_inverted, uint16_t write_color_ram_command, bool color_bits_inverted, uint32_t highlight_color, const uint8_t *refresh_sequence, uint16_t refresh_sequence_len, mp_float_t refresh_time,
45-
const mcu_pin_obj_t *busy_pin, bool busy_state, mp_float_t seconds_per_frame, bool always_toggle_chip_select, bool grayscale, bool acep, bool two_byte_sequence_length);
46+
uint16_t write_black_ram_command, bool black_bits_inverted,
47+
uint16_t write_color_ram_command, bool color_bits_inverted, uint32_t highlight_color,
48+
const uint8_t *refresh_sequence, uint16_t refresh_sequence_len, mp_float_t refresh_time,
49+
const mcu_pin_obj_t *busy_pin, bool busy_state, mp_float_t seconds_per_frame,
50+
bool always_toggle_chip_select, bool grayscale, bool acep, bool two_byte_sequence_length,
51+
bool address_little_endian);
4652

4753
bool common_hal_displayio_epaperdisplay_refresh(displayio_epaperdisplay_obj_t *self);
4854

shared-module/_stage/__init__.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ void render_stage(
4646
area.y1 = y0 * scale;
4747
area.x2 = x1 * scale;
4848
area.y2 = y1 * scale;
49-
displayio_display_core_set_region_to_update(
50-
&display->core, display->set_column_command, display->set_row_command,
51-
NO_COMMAND, NO_COMMAND, display->data_as_commands, false, &area,
52-
display->SH1107_addressing);
49+
displayio_display_core_set_region_to_update(&display->core, &area);
5350

5451
while (!displayio_display_core_begin_transaction(&display->core)) {
5552
RUN_BACKGROUND_TASKS;

shared-module/board/__init__.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ void reset_board_buses(void) {
190190
bool display_using_i2c = false;
191191
#if CIRCUITPY_DISPLAYIO
192192
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
193-
if (displays[i].bus_base.type == &displayio_i2cdisplay_type && displays[i].i2cdisplay_bus.bus == &i2c_obj[instance]) {
193+
if (display_buses[i].bus_base.type == &displayio_i2cdisplay_type && display_buses[i].i2cdisplay_bus.bus == &i2c_obj[instance]) {
194194
display_using_i2c = true;
195195
break;
196196
}
@@ -211,13 +211,13 @@ void reset_board_buses(void) {
211211
bool display_using_spi = false;
212212
#if CIRCUITPY_DISPLAYIO
213213
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
214-
mp_const_obj_t bus_type = displays[i].bus_base.type;
215-
if (bus_type == &displayio_fourwire_type && displays[i].fourwire_bus.bus == &spi_obj[instance]) {
214+
mp_const_obj_t bus_type = display_buses[i].bus_base.type;
215+
if (bus_type == &displayio_fourwire_type && display_buses[i].fourwire_bus.bus == &spi_obj[instance]) {
216216
display_using_spi = true;
217217
break;
218218
}
219219
#if CIRCUITPY_SHARPDISPLAY
220-
if (displays[i].bus_base.type == &sharpdisplay_framebuffer_type && displays[i].sharpdisplay.bus == &spi_obj[instance]) {
220+
if (bus_type == &sharpdisplay_framebuffer_type && display_buses[i].sharpdisplay.bus == &spi_obj[instance]) {
221221
display_using_spi = true;
222222
break;
223223
}

shared-module/displayio/Display.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,14 @@ void common_hal_displayio_display_construct(displayio_display_obj_t *self,
6464
ram_height = 0xff;
6565
}
6666
displayio_display_core_construct(&self->core, bus, width, height, ram_width, ram_height, colstart, rowstart, rotation,
67-
color_depth, grayscale, pixels_in_byte_share_row, bytes_per_cell, reverse_pixels_in_byte, reverse_bytes_in_word);
67+
color_depth, grayscale, pixels_in_byte_share_row, bytes_per_cell, reverse_pixels_in_byte, reverse_bytes_in_word,
68+
set_column_command, set_row_command, NO_COMMAND, NO_COMMAND, self->data_as_commands, false /* always_toggle_chip_select */,
69+
SH1107_addressing && color_depth == 1, false /*address_little_endian */);
6870

69-
self->set_column_command = set_column_command;
70-
self->set_row_command = set_row_command;
7171
self->write_ram_command = write_ram_command;
7272
self->brightness_command = brightness_command;
7373
self->first_manual_refresh = !auto_refresh;
74-
self->data_as_commands = data_as_commands;
7574
self->backlight_on_high = backlight_on_high;
76-
self->SH1107_addressing = SH1107_addressing && color_depth == 1;
7775

7876
self->native_frames_per_second = native_frames_per_second;
7977
self->native_ms_per_frame = 1000 / native_frames_per_second;
@@ -294,9 +292,7 @@ STATIC bool _refresh_area(displayio_display_obj_t *self, const displayio_area_t
294292
}
295293
remaining_rows -= rows_per_buffer;
296294

297-
displayio_display_core_set_region_to_update(&self->core, self->set_column_command,
298-
self->set_row_command, NO_COMMAND, NO_COMMAND, self->data_as_commands, false,
299-
&subrectangle, self->SH1107_addressing);
295+
displayio_display_core_set_region_to_update(&self->core, &subrectangle);
300296

301297
uint16_t subrectangle_size_bytes;
302298
if (self->core.colorspace.depth >= 8) {

shared-module/displayio/EPaperDisplay.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,28 +58,30 @@ void common_hal_displayio_epaperdisplay_construct(displayio_epaperdisplay_obj_t
5858
uint16_t write_color_ram_command, bool color_bits_inverted, uint32_t highlight_color,
5959
const uint8_t *refresh_sequence, uint16_t refresh_sequence_len, mp_float_t refresh_time,
6060
const mcu_pin_obj_t *busy_pin, bool busy_state, mp_float_t seconds_per_frame,
61-
bool chip_select, bool grayscale, bool acep, bool two_byte_sequence_length) {
61+
bool chip_select, bool grayscale, bool acep, bool two_byte_sequence_length, bool address_little_endian) {
6262
uint16_t color_depth = 1;
6363
bool core_grayscale = true;
6464
if (highlight_color != 0x000000) {
6565
self->core.colorspace.tricolor = true;
6666
self->core.colorspace.tricolor_hue = displayio_colorconverter_compute_hue(highlight_color);
6767
self->core.colorspace.tricolor_luma = displayio_colorconverter_compute_luma(highlight_color);
68+
} else {
69+
self->core.colorspace.tricolor = false;
6870
}
71+
self->acep = acep;
72+
self->core.colorspace.sevencolor = acep;
6973
if (acep) {
70-
self->core.colorspace.sevencolor = true;
7174
color_depth = 4; // bits. 7 colors + clean
72-
self->acep = acep;
7375
grayscale = false;
7476
core_grayscale = false;
7577
}
7678

77-
displayio_display_core_construct(&self->core, bus, width, height, ram_width, ram_height, colstart, rowstart, rotation, color_depth, core_grayscale, true, 1, true, true);
79+
displayio_display_core_construct(&self->core, bus, width, height, ram_width, ram_height,
80+
colstart, rowstart, rotation, color_depth, core_grayscale, true, 1, true, true,
81+
set_column_window_command, set_row_window_command, set_current_column_command, set_current_row_command,
82+
false /* data_as_commands */, chip_select,
83+
false /* SH1107_addressing */, address_little_endian);
7884

79-
self->set_column_window_command = set_column_window_command;
80-
self->set_row_window_command = set_row_window_command;
81-
self->set_current_column_command = set_current_column_command;
82-
self->set_current_row_command = set_current_row_command;
8385
self->write_black_ram_command = write_black_ram_command;
8486
self->black_bits_inverted = black_bits_inverted;
8587
self->write_color_ram_command = write_color_ram_command;
@@ -137,7 +139,7 @@ STATIC const displayio_area_t *displayio_epaperdisplay_get_refresh_areas(display
137139
if (self->core.current_group != NULL) {
138140
first_area = displayio_group_get_refresh_areas(self->core.current_group, NULL);
139141
}
140-
if (first_area != NULL && self->set_row_window_command == NO_COMMAND) {
142+
if (first_area != NULL) {
141143
self->core.area.next = NULL;
142144
return &self->core.area;
143145
}
@@ -310,10 +312,8 @@ STATIC bool displayio_epaperdisplay_refresh_area(displayio_epaperdisplay_obj_t *
310312
for (uint8_t pass = 0; pass < passes; pass++) {
311313
uint16_t remaining_rows = displayio_area_height(&clipped);
312314

313-
if (self->set_row_window_command != NO_COMMAND) {
314-
displayio_display_core_set_region_to_update(&self->core, self->set_column_window_command,
315-
self->set_row_window_command, self->set_current_column_command, self->set_current_row_command,
316-
false, self->chip_select, &clipped, false /* SH1107_addressing */);
315+
if (self->core.row_command != NO_COMMAND) {
316+
displayio_display_core_set_region_to_update(&self->core, &clipped);
317317
}
318318

319319
uint8_t write_command = self->write_black_ram_command;

shared-module/displayio/EPaperDisplay.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ typedef struct {
4646
uint16_t refresh_sequence_len;
4747
uint16_t start_up_time_ms;
4848
uint16_t refresh_time;
49-
uint16_t set_column_window_command;
50-
uint16_t set_row_window_command;
51-
uint16_t set_current_column_command;
52-
uint16_t set_current_row_command;
5349
uint16_t write_black_ram_command;
5450
uint16_t write_color_ram_command;
5551
uint8_t hue;

shared-module/displayio/TileGrid.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,6 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self,
543543
((uint8_t *)buffer)[offset / pixels_per_byte] |= output_pixel.pixel << shift;
544544
}
545545
}
546-
(void)input_pixel;
547546
}
548547
}
549548
return full_coverage;

0 commit comments

Comments
 (0)