Skip to content

Commit c247e7d

Browse files
committed
Begin refresh rework.
1 parent d37dd4d commit c247e7d

File tree

14 files changed

+254
-221
lines changed

14 files changed

+254
-221
lines changed

ports/atmel-samd/background.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void run_background_tasks(void) {
6060
audio_dma_background();
6161
#endif
6262
#if CIRCUITPY_DISPLAYIO
63-
displayio_refresh_displays();
63+
displayio_background();
6464
#endif
6565

6666
#if CIRCUITPY_NETWORK

ports/nrf/background.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void run_background_tasks(void) {
5656
#endif
5757

5858
#if CIRCUITPY_DISPLAYIO
59-
displayio_refresh_displays();
59+
displayio_background();
6060
#endif
6161
running_background_tasks = false;
6262

ports/stm32f4/background.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void run_background_tasks(void) {
4949
//usb_background();
5050

5151
#if CIRCUITPY_DISPLAYIO
52-
displayio_refresh_displays();
52+
displayio_background();
5353
#endif
5454
running_background_tasks = false;
5555

py/circuitpy_mpconfig.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ extern const struct _mp_obj_module_t terminalio_module;
307307
#define DISPLAYIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_displayio), (mp_obj_t)&displayio_module },
308308
#define FONTIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_fontio), (mp_obj_t)&fontio_module },
309309
#define TERMINALIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_terminalio), (mp_obj_t)&terminalio_module },
310-
#define CIRCUITPY_DISPLAY_LIMIT (3)
310+
#define CIRCUITPY_DISPLAY_LIMIT (1)
311311
#else
312312
#define DISPLAYIO_MODULE
313313
#define FONTIO_MODULE

shared-bindings/displayio/Display.c

+27-10
Original file line numberDiff line numberDiff line change
@@ -212,27 +212,42 @@ STATIC mp_obj_t displayio_display_obj_show(mp_obj_t self_in, mp_obj_t group_in)
212212
}
213213
MP_DEFINE_CONST_FUN_OBJ_2(displayio_display_show_obj, displayio_display_obj_show);
214214

215-
//| .. method:: refresh_soon()
215+
//| .. method:: refresh(*, target_frames_per_second=None, minimum_frames_per_second=1)
216216
//|
217-
//| Queues up a display refresh that happens in the background.
217+
//| Waits for the target frame rate and then refreshes the display. If the call is too late for the given target frame rate, then the refresh returns immediately without updating the screen to hopefully help getting caught up. If the current frame rate is below the minimum frame rate, then an exception will be raised.
218218
//|
219-
STATIC mp_obj_t displayio_display_obj_refresh_soon(mp_obj_t self_in) {
219+
STATIC mp_obj_t displayio_display_obj_refresh(mp_obj_t self_in) {
220220
displayio_display_obj_t *self = native_display(self_in);
221-
common_hal_displayio_display_refresh_soon(self);
221+
common_hal_displayio_display_refresh(self);
222222
return mp_const_none;
223223
}
224224
MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_refresh_soon_obj, displayio_display_obj_refresh_soon);
225225

226-
//| .. method:: wait_for_frame()
226+
//| .. attribute:: auto_refresh
227227
//|
228-
//| Waits until the next frame has been transmitted to the display unless the wait count is
229-
//| behind the rendered frames. In that case, this will return immediately with the wait count.
228+
//| True when the display is refreshed automatically.
230229
//|
231-
STATIC mp_obj_t displayio_display_obj_wait_for_frame(mp_obj_t self_in) {
230+
STATIC mp_obj_t displayio_display_obj_get_auto_refresh(mp_obj_t self_in) {
232231
displayio_display_obj_t *self = native_display(self_in);
233-
return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_display_wait_for_frame(self));
232+
return mp_obj_new_bool(common_hal_displayio_display_get_auto_refresh(self));
234233
}
235-
MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_wait_for_frame_obj, displayio_display_obj_wait_for_frame);
234+
MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_auto_refresh_obj, displayio_display_obj_get_auto_refresh);
235+
236+
STATIC mp_obj_t displayio_display_obj_set_auto_refresh(mp_obj_t self_in, mp_obj_t auto_refresh) {
237+
displayio_display_obj_t *self = native_display(self_in);
238+
239+
common_hal_displayio_display_set_auto_refresh(self, mp_obj_is_true(auto_refresh));
240+
241+
return mp_const_none;
242+
}
243+
MP_DEFINE_CONST_FUN_OBJ_2(displayio_display_set_auto_refresh_obj, displayio_display_obj_set_auto_refresh);
244+
245+
const mp_obj_property_t displayio_display_auto_refresh_obj = {
246+
.base.type = &mp_type_property,
247+
.proxy = {(mp_obj_t)&displayio_display_get_auto_refresh_obj,
248+
(mp_obj_t)&displayio_display_set_auto_refresh_obj,
249+
(mp_obj_t)&mp_const_none_obj},
250+
};
236251

237252
//| .. attribute:: brightness
238253
//|
@@ -442,6 +457,8 @@ STATIC const mp_rom_map_elem_t displayio_display_locals_dict_table[] = {
442457
{ MP_ROM_QSTR(MP_QSTR_wait_for_frame), MP_ROM_PTR(&displayio_display_wait_for_frame_obj) },
443458
{ MP_ROM_QSTR(MP_QSTR_fill_row), MP_ROM_PTR(&displayio_display_fill_row_obj) },
444459

460+
{ MP_ROM_QSTR(MP_QSTR_auto_refresh), MP_ROM_PTR(&displayio_display_auto_refresh_obj) },
461+
445462
{ MP_ROM_QSTR(MP_QSTR_brightness), MP_ROM_PTR(&displayio_display_brightness_obj) },
446463
{ MP_ROM_QSTR(MP_QSTR_auto_brightness), MP_ROM_PTR(&displayio_display_auto_brightness_obj) },
447464

shared-bindings/displayio/Display.h

+2-12
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,16 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
4444
bool pixels_in_byte_share_row, uint8_t bytes_per_cell, bool reverse_pixels_in_byte,
4545
uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll,
4646
uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, uint16_t brightness_command,
47-
mp_float_t brightness, bool auto_brightness,
47+
mp_float_t brightness, bool auto_brightness, bool auto_refresh, uint8_t frames_per_second,
4848
bool single_byte_bounds, bool data_as_commands);
4949

50-
int32_t common_hal_displayio_display_wait_for_frame(displayio_display_obj_t* self);
51-
5250
bool common_hal_displayio_display_show(displayio_display_obj_t* self, displayio_group_t* root_group);
5351

54-
void common_hal_displayio_display_refresh_soon(displayio_display_obj_t* self);
52+
void common_hal_displayio_display_refresh(displayio_display_obj_t* self);
5553

5654
bool displayio_display_begin_transaction(displayio_display_obj_t* self);
5755
void displayio_display_end_transaction(displayio_display_obj_t* self);
5856

59-
// The second point of the region is exclusive.
60-
void displayio_display_set_region_to_update(displayio_display_obj_t* self, displayio_area_t* area);
61-
bool displayio_display_frame_queued(displayio_display_obj_t* self);
62-
63-
bool displayio_display_refresh_queued(displayio_display_obj_t* self);
64-
void displayio_display_finish_refresh(displayio_display_obj_t* self);
65-
void displayio_display_send_pixels(displayio_display_obj_t* self, uint8_t* pixels, uint32_t length);
66-
6757
bool common_hal_displayio_display_get_auto_brightness(displayio_display_obj_t* self);
6858
void common_hal_displayio_display_set_auto_brightness(displayio_display_obj_t* self, bool auto_brightness);
6959

shared-bindings/displayio/EPaperDisplay.c

+28-17
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
//| Most people should not use this class directly. Use a specific display driver instead that will
5252
//| contain the startup and shutdown sequences at minimum.
5353
//|
54-
//| .. class:: EPaperDisplay(display_bus, start_sequence, stop_sequence, *, width, height, ram_width, ram_height, colstart=0, rowstart=0, rotation=0, set_column_window_command=None, set_row_window_command=None, single_byte_bounds=False, write_black_ram_command, black_bits_inverted=False, write_color_ram_command=None, color_bits_inverted=False, refresh_display_command, busy_pin=None, busy_state=True, seconds_per_frame=180, always_toggle_chip_select=False)
54+
//| .. class:: EPaperDisplay(display_bus, start_sequence, stop_sequence, *, width, height, ram_width, ram_height, colstart=0, rowstart=0, rotation=0, set_column_window_command=None, set_row_window_command=None, single_byte_bounds=False, write_black_ram_command, black_bits_inverted=False, write_color_ram_command=None, color_bits_inverted=False, highlight_color=0x000000, refresh_display_command, busy_pin=None, busy_state=True, seconds_per_frame=180, always_toggle_chip_select=False)
5555
//|
5656
//| Create a EPaperDisplay object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`).
5757
//|
@@ -81,15 +81,15 @@
8181
//| :param bool black_bits_inverted: True if 0 bits are used to show black pixels. Otherwise, 1 means to show black.
8282
//| :param int write_color_ram_command: Command used to write pixels values into the update region
8383
//| :param bool color_bits_inverted: True if 0 bits are used to show the color. Otherwise, 1 means to show color.
84-
//| :param int third_color: Color of third ePaper color in RGB888.
84+
//| :param int highlight_color: RGB888 of source color to highlight with third ePaper color.
8585
//| :param int refresh_display_command: Command used to start a display refresh
8686
//| :param microcontroller.Pin busy_pin: Pin used to signify the display is busy
8787
//| :param bool busy_state: State of the busy pin when the display is busy
8888
//| :param int seconds_per_frame: Minimum number of seconds between screen refreshes
8989
//| :param bool always_toggle_chip_select: When True, chip select is toggled every byte
9090
//|
9191
STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
92-
enum { ARG_display_bus, ARG_start_sequence, ARG_stop_sequence, ARG_width, ARG_height, ARG_ram_width, ARG_ram_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_set_column_window_command, ARG_set_row_window_command, ARG_set_current_column_command, ARG_set_current_row_command, ARG_write_black_ram_command, ARG_black_bits_inverted, ARG_write_color_ram_command, ARG_color_bits_inverted, ARG_third_color, ARG_refresh_display_command, ARG_busy_pin, ARG_busy_state, ARG_seconds_per_frame, ARG_always_toggle_chip_select };
92+
enum { ARG_display_bus, ARG_start_sequence, ARG_stop_sequence, ARG_width, ARG_height, ARG_ram_width, ARG_ram_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_set_column_window_command, ARG_set_row_window_command, ARG_set_current_column_command, 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_busy_pin, ARG_busy_state, ARG_seconds_per_frame, ARG_always_toggle_chip_select };
9393
static const mp_arg_t allowed_args[] = {
9494
{ MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ },
9595
{ MP_QSTR_start_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ },
@@ -109,7 +109,7 @@ STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size
109109
{ MP_QSTR_black_bits_inverted, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
110110
{ MP_QSTR_write_color_ram_command, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
111111
{ MP_QSTR_color_bits_inverted, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
112-
{ MP_QSTR_third_color, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x000000} },
112+
{ MP_QSTR_highlight_color, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x000000} },
113113
{ MP_QSTR_refresh_display_command, MP_ARG_INT | MP_ARG_REQUIRED },
114114
{ MP_QSTR_busy_pin, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
115115
{ MP_QSTR_busy_state, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
@@ -155,7 +155,7 @@ STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size
155155
mp_float_t seconds_per_frame = mp_obj_get_float(args[ARG_seconds_per_frame].u_obj);
156156

157157
mp_int_t write_color_ram_command = NO_COMMAND;
158-
mp_int_t third_color = args[ARG_third_color].u_int;
158+
mp_int_t highlight_color = args[ARG_highlight_color].u_int;
159159
if (args[ARG_write_color_ram_command].u_obj != mp_const_none) {
160160
write_color_ram_command = mp_obj_get_int(args[ARG_write_color_ram_command].u_obj);
161161
}
@@ -168,7 +168,7 @@ STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size
168168
args[ARG_width].u_int, args[ARG_height].u_int, args[ARG_ram_width].u_int, args[ARG_ram_height].u_int, args[ARG_colstart].u_int, args[ARG_rowstart].u_int, rotation,
169169
args[ARG_set_column_window_command].u_int, args[ARG_set_row_window_command].u_int,
170170
args[ARG_set_current_column_command].u_int, args[ARG_set_current_row_command].u_int,
171-
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, third_color, args[ARG_refresh_display_command].u_int,
171+
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,
172172
busy_pin, args[ARG_busy_state].u_bool, seconds_per_frame, args[ARG_always_toggle_chip_select].u_bool
173173
);
174174

@@ -203,27 +203,38 @@ STATIC mp_obj_t displayio_epaperdisplay_obj_show(mp_obj_t self_in, mp_obj_t grou
203203
}
204204
MP_DEFINE_CONST_FUN_OBJ_2(displayio_epaperdisplay_show_obj, displayio_epaperdisplay_obj_show);
205205

206-
//| .. method:: refresh_soon()
206+
//| .. method:: refresh()
207207
//|
208-
//| Queues up a display refresh that happens in the background.
208+
//| Refreshes the display immediately or raises an exception if too soon. Use
209+
//| ``time.sleep(display.time_to_refresh)`` to sleep until a refresh can occur.
209210
//|
210211
STATIC mp_obj_t displayio_epaperdisplay_obj_refresh_soon(mp_obj_t self_in) {
211212
displayio_epaperdisplay_obj_t *self = native_display(self_in);
212-
common_hal_displayio_epaperdisplay_refresh_soon(self);
213+
bool ok = common_hal_displayio_epaperdisplay_refresh(self);
214+
if (!ok) {
215+
mp_raise_RuntimeError(translate("Refresh too soon"));
216+
}
213217
return mp_const_none;
214218
}
215219
MP_DEFINE_CONST_FUN_OBJ_1(displayio_epaperdisplay_refresh_soon_obj, displayio_epaperdisplay_obj_refresh_soon);
216220

217-
//| .. method:: wait_for_frame()
221+
//| .. attribute:: time_to_refresh
218222
//|
219-
//| Waits until the next frame has been transmitted to the display unless the wait count is
220-
//| behind the rendered frames. In that case, this will return immediately with the wait count.
223+
//| Time, in fractional seconds, until the ePaper display can be refreshed.
221224
//|
222-
STATIC mp_obj_t displayio_epaperdisplay_obj_wait_for_frame(mp_obj_t self_in) {
225+
//|
226+
STATIC mp_obj_t displayio_epaperdisplay_obj_get_time_to_refresh(mp_obj_t self_in) {
223227
displayio_epaperdisplay_obj_t *self = native_display(self_in);
224-
return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_epaperdisplay_wait_for_frame(self));
228+
return mp_obj_new_float(common_hal_displayio_epaperdisplay_get_time_to_refresh(self));
225229
}
226-
MP_DEFINE_CONST_FUN_OBJ_1(displayio_epaperdisplay_wait_for_frame_obj, displayio_epaperdisplay_obj_wait_for_frame);
230+
MP_DEFINE_CONST_FUN_OBJ_1(displayio_epaperdisplay_get_time_to_refresh_obj, displayio_epaperdisplay_obj_get_time_to_refresh);
231+
232+
const mp_obj_property_t displayio_epaperdisplay_time_to_refresh_obj = {
233+
.base.type = &mp_type_property,
234+
.proxy = {(mp_obj_t)&displayio_epaperdisplay_get_time_to_refresh_obj,
235+
(mp_obj_t)&mp_const_none_obj,
236+
(mp_obj_t)&mp_const_none_obj},
237+
};
227238

228239
//| .. attribute:: width
229240
//|
@@ -282,12 +293,12 @@ const mp_obj_property_t displayio_epaperdisplay_bus_obj = {
282293

283294
STATIC const mp_rom_map_elem_t displayio_epaperdisplay_locals_dict_table[] = {
284295
{ MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&displayio_epaperdisplay_show_obj) },
285-
{ MP_ROM_QSTR(MP_QSTR_refresh_soon), MP_ROM_PTR(&displayio_epaperdisplay_refresh_soon_obj) },
286-
{ MP_ROM_QSTR(MP_QSTR_wait_for_frame), MP_ROM_PTR(&displayio_epaperdisplay_wait_for_frame_obj) },
296+
{ MP_ROM_QSTR(MP_QSTR_refresh_soon), MP_ROM_PTR(&displayio_epaperdisplay_refresh_obj) },
287297

288298
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&displayio_epaperdisplay_width_obj) },
289299
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_epaperdisplay_height_obj) },
290300
{ MP_ROM_QSTR(MP_QSTR_bus), MP_ROM_PTR(&displayio_epaperdisplay_bus_obj) },
301+
{ MP_ROM_QSTR(MP_QSTR_time_to_refresh), MP_ROM_PTR(&displayio_epaperdisplay_time_to_refresh_obj) },
291302
};
292303
STATIC MP_DEFINE_CONST_DICT(displayio_epaperdisplay_locals_dict, displayio_epaperdisplay_locals_dict_table);
293304

shared-bindings/displayio/EPaperDisplay.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,24 @@ void common_hal_displayio_epaperdisplay_construct(displayio_epaperdisplay_obj_t*
4343
uint16_t width, uint16_t height, uint16_t ram_width, uint16_t ram_height, int16_t colstart, int16_t rowstart, uint16_t rotation,
4444
uint16_t set_column_window_command, uint16_t set_row_window_command,
4545
uint16_t set_current_column_command, uint16_t set_current_row_command,
46-
uint16_t write_black_ram_command, bool black_bits_inverted, uint16_t write_color_ram_command, bool color_bits_inverted, uint32_t third_color, uint16_t refresh_display_command,
46+
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,
4747
const mcu_pin_obj_t* busy_pin, bool busy_state, mp_float_t seconds_per_frame, bool always_toggle_chip_select);
4848

4949
int32_t common_hal_displayio_epaperdisplay_wait_for_frame(displayio_epaperdisplay_obj_t* self);
5050

5151
bool common_hal_displayio_epaperdisplay_show(displayio_epaperdisplay_obj_t* self, displayio_group_t* root_group);
5252

53-
void common_hal_displayio_epaperdisplay_refresh_soon(displayio_epaperdisplay_obj_t* self);
54-
5553
bool displayio_epaperdisplay_begin_transaction(displayio_epaperdisplay_obj_t* self);
5654
void displayio_epaperdisplay_end_transaction(displayio_epaperdisplay_obj_t* self);
5755

56+
bool displayio_epaperdisplay_refresh(displayio_epaperdisplay_obj_t* self);
57+
58+
mp_float_t displayio_epaperdisplay_get_time_to_refresh(displayio_epaperdisplay_obj_t* self);
59+
5860
// The second point of the region is exclusive.
5961
void displayio_epaperdisplay_set_region_to_update(displayio_epaperdisplay_obj_t* self, displayio_area_t* area);
6062
bool displayio_epaperdisplay_frame_queued(displayio_epaperdisplay_obj_t* self);
6163

62-
bool displayio_epaperdisplay_refresh_queued(displayio_epaperdisplay_obj_t* self);
6364
void displayio_epaperdisplay_finish_refresh(displayio_epaperdisplay_obj_t* self);
6465
void displayio_epaperdisplay_send_pixels(displayio_epaperdisplay_obj_t* self, uint8_t* pixels, uint32_t length);
6566

0 commit comments

Comments
 (0)