From fbd9e3284b55fca757758c2ebfae3479435acf92 Mon Sep 17 00:00:00 2001 From: Dan Kulinski Date: Wed, 12 Jan 2022 20:45:35 -0700 Subject: [PATCH 1/3] Add two byte length check --- shared-bindings/displayio/EPaperDisplay.c | 10 ++++++---- shared-bindings/displayio/EPaperDisplay.h | 2 +- shared-module/displayio/EPaperDisplay.c | 9 +++++++-- shared-module/displayio/EPaperDisplay.h | 1 + 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/shared-bindings/displayio/EPaperDisplay.c b/shared-bindings/displayio/EPaperDisplay.c index 64f7031f4d..aa14594d97 100644 --- a/shared-bindings/displayio/EPaperDisplay.c +++ b/shared-bindings/displayio/EPaperDisplay.c @@ -63,7 +63,7 @@ //| refresh_display_command: int, refresh_time: float = 40, //| busy_pin: Optional[microcontroller.Pin] = None, busy_state: bool = True, //| seconds_per_frame: float = 180, always_toggle_chip_select: bool = False, -//| grayscale: bool = False) -> None: +//| grayscale: bool = False, two_byte_sequence_length: bool = False) -> None: //| """Create a EPaperDisplay object on the given display bus (`displayio.FourWire` or `paralleldisplay.ParallelBus`). //| //| The ``start_sequence`` and ``stop_sequence`` are bitpacked to minimize the ram impact. Every @@ -100,7 +100,8 @@ //| :param bool busy_state: State of the busy pin when the display is busy //| :param float seconds_per_frame: Minimum number of seconds between screen refreshes //| :param bool always_toggle_chip_select: When True, chip select is toggled every byte -//| :param bool grayscale: When true, the color ram is the low bit of 2-bit grayscale""" +//| :param bool grayscale: When true, the color ram is the low bit of 2-bit grayscale +//| :param bool two_byte_sequence_length: When true, use two bytes to define sequence length""" //| ... //| 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) { @@ -110,7 +111,7 @@ STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size ARG_set_current_row_command, ARG_write_black_ram_command, ARG_black_bits_inverted, ARG_write_color_ram_command, ARG_color_bits_inverted, ARG_highlight_color, ARG_refresh_display_command, ARG_refresh_time, ARG_busy_pin, ARG_busy_state, - ARG_seconds_per_frame, ARG_always_toggle_chip_select, ARG_grayscale }; + ARG_seconds_per_frame, ARG_always_toggle_chip_select, ARG_grayscale, ARG_two_byte_sequence_length }; static const mp_arg_t allowed_args[] = { { MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_start_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -138,6 +139,7 @@ STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size { MP_QSTR_seconds_per_frame, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NEW_SMALL_INT(180)} }, { MP_QSTR_always_toggle_chip_select, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, { MP_QSTR_grayscale, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, + { MP_QSTR_two_byte_sequence_length, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -182,7 +184,7 @@ STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size args[ARG_write_black_ram_command].u_int, args[ARG_black_bits_inverted].u_bool, write_color_ram_command, args[ARG_color_bits_inverted].u_bool, highlight_color, args[ARG_refresh_display_command].u_int, refresh_time, busy_pin, args[ARG_busy_state].u_bool, seconds_per_frame, - args[ARG_always_toggle_chip_select].u_bool, args[ARG_grayscale].u_bool + args[ARG_always_toggle_chip_select].u_bool, args[ARG_grayscale].u_bool, args[ARG_two_byte_sequence_length].u_bool ); return self; diff --git a/shared-bindings/displayio/EPaperDisplay.h b/shared-bindings/displayio/EPaperDisplay.h index c23fb27455..ba6dffcb4b 100644 --- a/shared-bindings/displayio/EPaperDisplay.h +++ b/shared-bindings/displayio/EPaperDisplay.h @@ -42,7 +42,7 @@ void common_hal_displayio_epaperdisplay_construct(displayio_epaperdisplay_obj_t uint16_t set_column_window_command, uint16_t set_row_window_command, uint16_t set_current_column_command, uint16_t set_current_row_command, uint16_t write_black_ram_command, bool black_bits_inverted, uint16_t write_color_ram_command, bool color_bits_inverted, uint32_t highlight_color, uint16_t refresh_display_command, mp_float_t refresh_time, - const mcu_pin_obj_t *busy_pin, bool busy_state, mp_float_t seconds_per_frame, bool always_toggle_chip_select, bool grayscale); + const mcu_pin_obj_t *busy_pin, bool busy_state, mp_float_t seconds_per_frame, bool always_toggle_chip_select, bool grayscale, bool two_byte_sequence_length); bool common_hal_displayio_epaperdisplay_refresh(displayio_epaperdisplay_obj_t *self); diff --git a/shared-module/displayio/EPaperDisplay.c b/shared-module/displayio/EPaperDisplay.c index d2190c1b42..864a54ac87 100644 --- a/shared-module/displayio/EPaperDisplay.c +++ b/shared-module/displayio/EPaperDisplay.c @@ -54,7 +54,7 @@ void common_hal_displayio_epaperdisplay_construct(displayio_epaperdisplay_obj_t uint16_t set_column_window_command, uint16_t set_row_window_command, uint16_t set_current_column_command, uint16_t set_current_row_command, uint16_t write_black_ram_command, bool black_bits_inverted, uint16_t write_color_ram_command, bool color_bits_inverted, uint32_t highlight_color, uint16_t refresh_display_command, mp_float_t refresh_time, - const mcu_pin_obj_t *busy_pin, bool busy_state, mp_float_t seconds_per_frame, bool chip_select, bool grayscale) { + const mcu_pin_obj_t *busy_pin, bool busy_state, mp_float_t seconds_per_frame, bool chip_select, bool grayscale, bool two_byte_sequence_length) { if (highlight_color != 0x000000) { self->core.colorspace.tricolor = true; self->core.colorspace.tricolor_hue = displayio_colorconverter_compute_hue(highlight_color); @@ -85,6 +85,7 @@ void common_hal_displayio_epaperdisplay_construct(displayio_epaperdisplay_obj_t self->stop_sequence_len = stop_sequence_len; self->busy.base.type = &mp_type_NoneType; + self->two_byte_sequence_length = two_byte_sequence_length; if (busy_pin != NULL) { self->busy.base.type = &digitalio_digitalinout_type; common_hal_digitalio_digitalinout_construct(&self->busy, busy_pin); @@ -145,8 +146,12 @@ STATIC void send_command_sequence(displayio_epaperdisplay_obj_t *self, const uint8_t *cmd = sequence + i; uint8_t data_size = *(cmd + 1); bool delay = (data_size & DELAY) != 0; - data_size &= ~DELAY; const uint8_t *data = cmd + 2; + data_size &= ~DELAY; + if (self->two_byte_sequence_length) { + data_size = (data_size & ~DELAY) + *(cmd + 2); + data = cmd + 3; + } displayio_display_core_begin_transaction(&self->core); self->core.send(self->core.bus, DISPLAY_COMMAND, self->chip_select, cmd, 1); self->core.send(self->core.bus, DISPLAY_DATA, self->chip_select, data, data_size); diff --git a/shared-module/displayio/EPaperDisplay.h b/shared-module/displayio/EPaperDisplay.h index 65a4dd7743..55feaf964b 100644 --- a/shared-module/displayio/EPaperDisplay.h +++ b/shared-module/displayio/EPaperDisplay.h @@ -57,6 +57,7 @@ typedef struct { bool refreshing; bool grayscale; display_chip_select_behavior_t chip_select; + bool two_byte_sequence_length; } displayio_epaperdisplay_obj_t; void displayio_epaperdisplay_change_refresh_mode_parameters(displayio_epaperdisplay_obj_t *self, From ca8299e51bbafe463f56a7c766a3e1787422b698 Mon Sep 17 00:00:00 2001 From: Dan Kulinski Date: Fri, 14 Jan 2022 15:24:08 -0700 Subject: [PATCH 2/3] Update logic for offset --- shared-module/displayio/EPaperDisplay.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/shared-module/displayio/EPaperDisplay.c b/shared-module/displayio/EPaperDisplay.c index 864a54ac87..b1e998048e 100644 --- a/shared-module/displayio/EPaperDisplay.c +++ b/shared-module/displayio/EPaperDisplay.c @@ -149,7 +149,7 @@ STATIC void send_command_sequence(displayio_epaperdisplay_obj_t *self, const uint8_t *data = cmd + 2; data_size &= ~DELAY; if (self->two_byte_sequence_length) { - data_size = (data_size & ~DELAY) + *(cmd + 2); + data_size = ((data_size & ~DELAY) << 8) + *(cmd + 2); data = cmd + 3; } displayio_display_core_begin_transaction(&self->core); @@ -169,6 +169,9 @@ STATIC void send_command_sequence(displayio_epaperdisplay_obj_t *self, wait_for_busy(self); } i += 2 + data_size; + if (self->two_byte_sequence_length) { + i++; + } } } From 60801066b2f078fc36988dcdd50bd6b23e3c37f8 Mon Sep 17 00:00:00 2001 From: Dan Kulinski Date: Mon, 24 Jan 2022 12:34:01 -0700 Subject: [PATCH 3/3] Fix magtag, openbook for EPaperDisplay constructor --- ports/atmel-samd/boards/openbook_m4/board.c | 3 ++- ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ports/atmel-samd/boards/openbook_m4/board.c b/ports/atmel-samd/boards/openbook_m4/board.c index 1ff83b95b7..660c514e83 100644 --- a/ports/atmel-samd/boards/openbook_m4/board.c +++ b/ports/atmel-samd/boards/openbook_m4/board.c @@ -98,7 +98,8 @@ void board_init(void) { false, // busy_state 5, // seconds_per_frame false, // chip_select (don't always toggle chip select) - false); // grayscale + false, // grayscale + false); // two_byte_sequence_length } bool board_requests_safe_mode(void) { diff --git a/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c b/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c index 020e6f6a1f..a32e8ce9be 100644 --- a/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c +++ b/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c @@ -164,7 +164,8 @@ void board_init(void) { false, // busy_state 5.0, // seconds_per_frame false, // always_toggle_chip_select - true); // grayscale + true, // grayscale + false); // two_byte_sequence_length } bool board_requests_safe_mode(void) {