Skip to content

Commit a127f81

Browse files
committed
WIP partial plumbing
1 parent 132cd76 commit a127f81

3 files changed

Lines changed: 79 additions & 43 deletions

File tree

py/circuitpy_mpconfig.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ CFLAGS += -DCIRCUITPY_FOURWIRE=$(CIRCUITPY_FOURWIRE)
245245
CIRCUITPY_EPAPERDISPLAY ?= $(CIRCUITPY_DISPLAYIO)
246246
CFLAGS += -DCIRCUITPY_EPAPERDISPLAY=$(CIRCUITPY_EPAPERDISPLAY)
247247

248+
CIRCUITPY_EPAPERDISPLAY_PARTIAL ?= 1
249+
CFLAGS += -DCIRCUITPY_EPAPERDISPLAY_PARTIAL=$(CIRCUITPY_EPAPERDISPLAY_PARTIAL)
250+
248251
CIRCUITPY_I2CDISPLAYBUS ?= $(CIRCUITPY_DISPLAYIO)
249252
CFLAGS += -DCIRCUITPY_I2CDISPLAYBUS=$(CIRCUITPY_I2CDISPLAYBUS)
250253

shared-bindings/epaperdisplay/EPaperDisplay.c

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
//| two_byte_sequence_length: bool = False,
6868
//| start_up_time: float = 0,
6969
//| address_little_endian: bool = False,
70+
//| save_full_framebuffer: bool = False,
71+
//| partial_window_command: Optional[int] = None,
72+
//| partial_start_command: Optional[int] = None,
73+
//| partial_end_command: Optional[int] = None,
7074
//| ) -> None:
7175
//| """Create a EPaperDisplay object on the given display bus (`fourwire.FourWire` or `paralleldisplaybus.ParallelBus`).
7276
//|
@@ -111,7 +115,12 @@
111115
//| :param bool two_byte_sequence_length: When true, use two bytes to define sequence length
112116
//| :param float start_up_time: Time to wait after reset before sending commands
113117
//| :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
114-
//| """
118+
//| :param bool save_full_framebuffer: When true, the display will save the full framebuffer to enable partial updates
119+
//| :param int partial_window_command: Command to set the partial window
120+
//| :param int partial_start_command: Command to start partial update
121+
//| :param int partial_end_command: Command to end partial update
122+
//|
123+
// """
115124
//| ...
116125
//|
117126
static mp_obj_t epaperdisplay_epaperdisplay_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
@@ -122,7 +131,8 @@ static mp_obj_t epaperdisplay_epaperdisplay_make_new(const mp_obj_type_t *type,
122131
ARG_write_color_ram_command, ARG_color_bits_inverted, ARG_highlight_color, ARG_highlight_color2,
123132
ARG_refresh_display_command, ARG_refresh_time, ARG_busy_pin, ARG_busy_state,
124133
ARG_seconds_per_frame, ARG_always_toggle_chip_select, ARG_grayscale, ARG_advanced_color_epaper, ARG_spectra6,
125-
ARG_two_byte_sequence_length, ARG_start_up_time, ARG_address_little_endian };
134+
ARG_two_byte_sequence_length, ARG_start_up_time, ARG_address_little_endian,
135+
ARG_save_full_framebuffer, ARG_partial_window_command, ARG_partial_window_start_command, ARG_partial_window_end_command};
126136
static const mp_arg_t allowed_args[] = {
127137
{ MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ },
128138
{ MP_QSTR_start_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ },
@@ -156,6 +166,10 @@ static mp_obj_t epaperdisplay_epaperdisplay_make_new(const mp_obj_type_t *type,
156166
{ MP_QSTR_two_byte_sequence_length, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
157167
{ MP_QSTR_start_up_time, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NEW_SMALL_INT(0)} },
158168
{ MP_QSTR_address_little_endian, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
169+
{ MP_QSTR_save_full_framebuffer, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
170+
{ MP_QSTR_partial_window_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = NO_COMMAND} },
171+
{ MP_QSTR_partial_start_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = NO_COMMAND} },
172+
{ MP_QSTR_partial_end_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = NO_COMMAND} },
159173
};
160174
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
161175
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@@ -247,6 +261,10 @@ static mp_obj_t epaperdisplay_epaperdisplay_make_new(const mp_obj_type_t *type,
247261
construct_args.spectra6 = args[ARG_spectra6].u_bool;
248262
construct_args.two_byte_sequence_length = two_byte_sequence_length;
249263
construct_args.address_little_endian = args[ARG_address_little_endian].u_bool;
264+
construct_args.save_full_framebuffer = args[ARG_save_full_framebuffer].u_bool;
265+
construct_args.partial_window_command = args[ARG_partial_window_command].u_int;
266+
construct_args.partial_start_command = args[ARG_partial_window_start_command].u_int;
267+
construct_args.partial_end_command = args[ARG_partial_window_end_command].u_int;
250268
common_hal_epaperdisplay_epaperdisplay_construct(self, &construct_args);
251269

252270
return self;
@@ -293,20 +311,27 @@ static mp_obj_t epaperdisplay_epaperdisplay_update_refresh_mode(size_t n_args, c
293311
}
294312
MP_DEFINE_CONST_FUN_OBJ_KW(epaperdisplay_epaperdisplay_update_refresh_mode_obj, 1, epaperdisplay_epaperdisplay_update_refresh_mode);
295313

296-
//| def refresh(self) -> None:
314+
//| def refresh(self, partial: bool = False) -> None:
297315
//| """Refreshes the display immediately or raises an exception if too soon. Use
298316
//| ``time.sleep(display.time_to_refresh)`` to sleep until a refresh can occur."""
299317
//| ...
300318
//|
301-
static mp_obj_t epaperdisplay_epaperdisplay_obj_refresh(mp_obj_t self_in) {
302-
epaperdisplay_epaperdisplay_obj_t *self = native_display(self_in);
303-
bool ok = common_hal_epaperdisplay_epaperdisplay_refresh(self);
319+
static mp_obj_t epaperdisplay_epaperdisplay_obj_refresh(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
320+
enum { ARG_partial };
321+
static const mp_arg_t allowed_args[] = {
322+
{ MP_QSTR_partial, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
323+
};
324+
epaperdisplay_epaperdisplay_obj_t *self = native_display(pos_args[0]);
325+
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
326+
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
327+
328+
bool ok = common_hal_epaperdisplay_epaperdisplay_refresh(self, args[ARG_partial].u_bool);
304329
if (!ok) {
305330
mp_raise_RuntimeError(MP_ERROR_TEXT("Refresh too soon"));
306331
}
307332
return mp_const_none;
308333
}
309-
MP_DEFINE_CONST_FUN_OBJ_1(epaperdisplay_epaperdisplay_refresh_obj, epaperdisplay_epaperdisplay_obj_refresh);
334+
MP_DEFINE_CONST_FUN_OBJ_KW(epaperdisplay_epaperdisplay_refresh_obj, 1, epaperdisplay_epaperdisplay_obj_refresh);
310335

311336
//| time_to_refresh: float
312337
//| """Time, in fractional seconds, until the ePaper display can be refreshed."""

shared-bindings/epaperdisplay/EPaperDisplay.h

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -51,50 +51,58 @@ typedef struct {
5151
bool spectra6;
5252
bool two_byte_sequence_length;
5353
bool address_little_endian;
54+
bool save_full_framebuffer;
55+
uint16_t partial_window_command;
56+
uint16_t partial_start_command;
57+
uint16_t partial_end_command;
5458
} epaperdisplay_construct_args_t;
5559

5660
#define EPAPERDISPLAY_CONSTRUCT_ARGS_DEFAULTS { \
57-
.bus = mp_const_none, \
58-
.start_sequence = NULL, \
59-
.start_sequence_len = 0, \
60-
.start_up_time = 0.0, \
61-
.stop_sequence = NULL, \
62-
.stop_sequence_len = 0, \
63-
.width = 0, \
64-
.height = 0, \
65-
.ram_width = 0, \
66-
.ram_height = 0, \
67-
.colstart = 0, \
68-
.rowstart = 0, \
69-
.rotation = 0, \
70-
.set_column_window_command = NO_COMMAND, \
71-
.set_row_window_command = NO_COMMAND, \
72-
.set_current_column_command = NO_COMMAND, \
73-
.set_current_row_command = NO_COMMAND, \
74-
.write_black_ram_command = NO_COMMAND, \
75-
.black_bits_inverted = false, \
76-
.write_color_ram_command = NO_COMMAND, \
77-
.color_bits_inverted = false, \
78-
.highlight_color = 0x000000, \
79-
.highlight_color2 = 0x000000, \
80-
.refresh_sequence = NULL, \
81-
.refresh_sequence_len = 0, \
82-
.refresh_time = 0.0, \
83-
.busy_pin = NULL, \
84-
.busy_state = false, \
85-
.seconds_per_frame = 0.0, \
86-
.always_toggle_chip_select = false, \
87-
.grayscale = false, \
88-
.acep = false, \
89-
.spectra6 = false, \
90-
.two_byte_sequence_length = false, \
91-
.address_little_endian = false \
61+
.bus = mp_const_none, \
62+
.start_sequence = NULL, \
63+
.start_sequence_len = 0, \
64+
.start_up_time = 0.0, \
65+
.stop_sequence = NULL, \
66+
.stop_sequence_len = 0, \
67+
.width = 0, \
68+
.height = 0, \
69+
.ram_width = 0, \
70+
.ram_height = 0, \
71+
.colstart = 0, \
72+
.rowstart = 0, \
73+
.rotation = 0, \
74+
.set_column_window_command = NO_COMMAND, \
75+
.set_row_window_command = NO_COMMAND, \
76+
.set_current_column_command = NO_COMMAND, \
77+
.set_current_row_command = NO_COMMAND, \
78+
.write_black_ram_command = NO_COMMAND, \
79+
.black_bits_inverted = false, \
80+
.write_color_ram_command = NO_COMMAND, \
81+
.color_bits_inverted = false, \
82+
.highlight_color = 0x000000, \
83+
.highlight_color2 = 0x000000, \
84+
.refresh_sequence = NULL, \
85+
.refresh_sequence_len = 0, \
86+
.refresh_time = 0.0, \
87+
.busy_pin = NULL, \
88+
.busy_state = false, \
89+
.seconds_per_frame = 0.0, \
90+
.always_toggle_chip_select = false, \
91+
.grayscale = false, \
92+
.acep = false, \
93+
.spectra6 = false, \
94+
.two_byte_sequence_length = false, \
95+
.address_little_endian = false \
96+
.save_full_framebuffer = false, \
97+
.partial_window_command = NO_COMMAND, \
98+
.partial_start_command = NO_COMMAND, \
99+
.partial_end_command = NO_COMMAND
92100
}
93101

94102
void common_hal_epaperdisplay_epaperdisplay_construct(epaperdisplay_epaperdisplay_obj_t *self,
95103
const epaperdisplay_construct_args_t *args);
96104

97-
bool common_hal_epaperdisplay_epaperdisplay_refresh(epaperdisplay_epaperdisplay_obj_t *self);
105+
bool common_hal_epaperdisplay_epaperdisplay_refresh(epaperdisplay_epaperdisplay_obj_t *self, bool partial);
98106

99107
mp_obj_t common_hal_epaperdisplay_epaperdisplay_get_root_group(epaperdisplay_epaperdisplay_obj_t *self);
100108
bool common_hal_epaperdisplay_epaperdisplay_set_root_group(epaperdisplay_epaperdisplay_obj_t *self, displayio_group_t *root_group);

0 commit comments

Comments
 (0)