Skip to content

Commit 4a3c636

Browse files
authored
Merge pull request #5874 from dkulinski/epaper_two_byte_length
Update EPaperDisplay to allow for two byte sequence length
2 parents 782fa36 + 19f9163 commit 4a3c636

File tree

6 files changed

+22
-9
lines changed

6 files changed

+22
-9
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ void board_init(void) {
9898
false, // busy_state
9999
5, // seconds_per_frame
100100
false, // chip_select (don't always toggle chip select)
101-
false); // grayscale
101+
false, // grayscale
102+
false); // two_byte_sequence_length
102103
}
103104

104105
bool board_requests_safe_mode(void) {

ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ void board_init(void) {
160160
false, // busy_state
161161
5.0, // seconds_per_frame
162162
false, // always_toggle_chip_select
163-
true); // grayscale
163+
true, // grayscale
164+
false); // two_byte_sequence_length
164165
}
165166

166167
bool board_requests_safe_mode(void) {

shared-bindings/displayio/EPaperDisplay.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
//| refresh_display_command: int, refresh_time: float = 40,
6464
//| busy_pin: Optional[microcontroller.Pin] = None, busy_state: bool = True,
6565
//| seconds_per_frame: float = 180, always_toggle_chip_select: bool = False,
66-
//| grayscale: bool = False) -> None:
66+
//| grayscale: bool = False, two_byte_sequence_length: bool = False) -> None:
6767
//| """Create a EPaperDisplay object on the given display bus (`displayio.FourWire` or `paralleldisplay.ParallelBus`).
6868
//|
6969
//| The ``start_sequence`` and ``stop_sequence`` are bitpacked to minimize the ram impact. Every
@@ -100,7 +100,8 @@
100100
//| :param bool busy_state: State of the busy pin when the display is busy
101101
//| :param float seconds_per_frame: Minimum number of seconds between screen refreshes
102102
//| :param bool always_toggle_chip_select: When True, chip select is toggled every byte
103-
//| :param bool grayscale: When true, the color ram is the low bit of 2-bit grayscale"""
103+
//| :param bool grayscale: When true, the color ram is the low bit of 2-bit grayscale
104+
//| :param bool two_byte_sequence_length: When true, use two bytes to define sequence length"""
104105
//| ...
105106
//|
106107
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
110111
ARG_set_current_row_command, ARG_write_black_ram_command, ARG_black_bits_inverted,
111112
ARG_write_color_ram_command, ARG_color_bits_inverted, ARG_highlight_color,
112113
ARG_refresh_display_command, ARG_refresh_time, ARG_busy_pin, ARG_busy_state,
113-
ARG_seconds_per_frame, ARG_always_toggle_chip_select, ARG_grayscale };
114+
ARG_seconds_per_frame, ARG_always_toggle_chip_select, ARG_grayscale, ARG_two_byte_sequence_length };
114115
static const mp_arg_t allowed_args[] = {
115116
{ MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ },
116117
{ 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
138139
{ MP_QSTR_seconds_per_frame, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NEW_SMALL_INT(180)} },
139140
{ MP_QSTR_always_toggle_chip_select, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
140141
{ MP_QSTR_grayscale, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
142+
{ MP_QSTR_two_byte_sequence_length, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
141143
};
142144
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
143145
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
182184
args[ARG_write_black_ram_command].u_int, args[ARG_black_bits_inverted].u_bool, write_color_ram_command,
183185
args[ARG_color_bits_inverted].u_bool, highlight_color, args[ARG_refresh_display_command].u_int, refresh_time,
184186
busy_pin, args[ARG_busy_state].u_bool, seconds_per_frame,
185-
args[ARG_always_toggle_chip_select].u_bool, args[ARG_grayscale].u_bool
187+
args[ARG_always_toggle_chip_select].u_bool, args[ARG_grayscale].u_bool, args[ARG_two_byte_sequence_length].u_bool
186188
);
187189

188190
return self;

shared-bindings/displayio/EPaperDisplay.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void common_hal_displayio_epaperdisplay_construct(displayio_epaperdisplay_obj_t
4242
uint16_t set_column_window_command, uint16_t set_row_window_command,
4343
uint16_t set_current_column_command, uint16_t set_current_row_command,
4444
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,
45-
const mcu_pin_obj_t *busy_pin, bool busy_state, mp_float_t seconds_per_frame, bool always_toggle_chip_select, bool grayscale);
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 two_byte_sequence_length);
4646

4747
bool common_hal_displayio_epaperdisplay_refresh(displayio_epaperdisplay_obj_t *self);
4848

shared-module/displayio/EPaperDisplay.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void common_hal_displayio_epaperdisplay_construct(displayio_epaperdisplay_obj_t
5454
uint16_t set_column_window_command, uint16_t set_row_window_command,
5555
uint16_t set_current_column_command, uint16_t set_current_row_command,
5656
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,
57-
const mcu_pin_obj_t *busy_pin, bool busy_state, mp_float_t seconds_per_frame, bool chip_select, bool grayscale) {
57+
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) {
5858
if (highlight_color != 0x000000) {
5959
self->core.colorspace.tricolor = true;
6060
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
8585
self->stop_sequence_len = stop_sequence_len;
8686

8787
self->busy.base.type = &mp_type_NoneType;
88+
self->two_byte_sequence_length = two_byte_sequence_length;
8889
if (busy_pin != NULL) {
8990
self->busy.base.type = &digitalio_digitalinout_type;
9091
common_hal_digitalio_digitalinout_construct(&self->busy, busy_pin);
@@ -145,8 +146,12 @@ STATIC void send_command_sequence(displayio_epaperdisplay_obj_t *self,
145146
const uint8_t *cmd = sequence + i;
146147
uint8_t data_size = *(cmd + 1);
147148
bool delay = (data_size & DELAY) != 0;
148-
data_size &= ~DELAY;
149149
const uint8_t *data = cmd + 2;
150+
data_size &= ~DELAY;
151+
if (self->two_byte_sequence_length) {
152+
data_size = ((data_size & ~DELAY) << 8) + *(cmd + 2);
153+
data = cmd + 3;
154+
}
150155
displayio_display_core_begin_transaction(&self->core);
151156
self->core.send(self->core.bus, DISPLAY_COMMAND, self->chip_select, cmd, 1);
152157
self->core.send(self->core.bus, DISPLAY_DATA, self->chip_select, data, data_size);
@@ -164,6 +169,9 @@ STATIC void send_command_sequence(displayio_epaperdisplay_obj_t *self,
164169
wait_for_busy(self);
165170
}
166171
i += 2 + data_size;
172+
if (self->two_byte_sequence_length) {
173+
i++;
174+
}
167175
}
168176
}
169177

shared-module/displayio/EPaperDisplay.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ typedef struct {
5757
bool refreshing;
5858
bool grayscale;
5959
display_chip_select_behavior_t chip_select;
60+
bool two_byte_sequence_length;
6061
} displayio_epaperdisplay_obj_t;
6162

6263
void displayio_epaperdisplay_change_refresh_mode_parameters(displayio_epaperdisplay_obj_t *self,

0 commit comments

Comments
 (0)