Skip to content

Commit 7944f50

Browse files
committed
displayio, framebufferio: Enable supervisor tick when a display is auto-refresh
This is a step towards restoring the efficiency of the background tasks
1 parent cbcdff6 commit 7944f50

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

shared-module/displayio/Display.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
137137
// Set the group after initialization otherwise we may send pixels while we delay in
138138
// initialization.
139139
common_hal_displayio_display_show(self, &circuitpython_splash);
140-
self->auto_refresh = auto_refresh;
140+
common_hal_displayio_display_set_auto_refresh(self, auto_refresh);
141141
}
142142

143143
bool common_hal_displayio_display_show(displayio_display_obj_t* self, displayio_group_t* root_group) {
@@ -383,6 +383,13 @@ bool common_hal_displayio_display_get_auto_refresh(displayio_display_obj_t* self
383383
void common_hal_displayio_display_set_auto_refresh(displayio_display_obj_t* self,
384384
bool auto_refresh) {
385385
self->first_manual_refresh = !auto_refresh;
386+
if (auto_refresh != self->auto_refresh) {
387+
if (auto_refresh) {
388+
supervisor_enable_tick();
389+
} else {
390+
supervisor_disable_tick();
391+
}
392+
}
386393
self->auto_refresh = auto_refresh;
387394
}
388395

@@ -409,6 +416,7 @@ void displayio_display_background(displayio_display_obj_t* self) {
409416
}
410417

411418
void release_display(displayio_display_obj_t* self) {
419+
common_hal_displayio_display_set_auto_refresh(self, false);
412420
release_display_core(&self->core);
413421
#if (CIRCUITPY_PULSEIO)
414422
if (self->backlight_pwm.base.type == &pulseio_pwmout_type) {
@@ -423,7 +431,7 @@ void release_display(displayio_display_obj_t* self) {
423431
}
424432

425433
void reset_display(displayio_display_obj_t* self) {
426-
self->auto_refresh = true;
434+
common_hal_displayio_display_set_auto_refresh(self, true);
427435
self->auto_brightness = true;
428436
common_hal_displayio_display_show(self, NULL);
429437
}

shared-module/displayio/EPaperDisplay.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ void displayio_epaperdisplay_finish_refresh(displayio_epaperdisplay_obj_t* self)
187187
displayio_display_core_begin_transaction(&self->core);
188188
self->core.send(self->core.bus, DISPLAY_COMMAND, self->chip_select, &self->refresh_display_command, 1);
189189
displayio_display_core_end_transaction(&self->core);
190+
supervisor_enable_tick();
190191
self->refreshing = true;
191192

192193
displayio_display_core_finish_refresh(&self->core);
@@ -301,6 +302,7 @@ bool common_hal_displayio_epaperdisplay_refresh(displayio_epaperdisplay_obj_t* s
301302

302303
if (self->refreshing && self->busy.base.type == &digitalio_digitalinout_type) {
303304
if (common_hal_digitalio_digitalinout_get_value(&self->busy) != self->busy_state) {
305+
supervisor_disable_tick();
304306
self->refreshing = false;
305307
// Run stop sequence but don't wait for busy because busy is set when sleeping.
306308
send_command_sequence(self, false, self->stop_sequence, self->stop_sequence_len);
@@ -342,6 +344,7 @@ void displayio_epaperdisplay_background(displayio_epaperdisplay_obj_t* self) {
342344
refresh_done = supervisor_ticks_ms64() - self->core.last_refresh > self->refresh_time;
343345
}
344346
if (refresh_done) {
347+
supervisor_disable_tick();
345348
self->refreshing = false;
346349
// Run stop sequence but don't wait for busy because busy is set when sleeping.
347350
send_command_sequence(self, false, self->stop_sequence, self->stop_sequence_len);
@@ -352,6 +355,7 @@ void displayio_epaperdisplay_background(displayio_epaperdisplay_obj_t* self) {
352355
void release_epaperdisplay(displayio_epaperdisplay_obj_t* self) {
353356
if (self->refreshing) {
354357
wait_for_busy(self);
358+
supervisor_disable_tick();
355359
self->refreshing = false;
356360
// Run stop sequence but don't wait for busy because busy is set when sleeping.
357361
send_command_sequence(self, false, self->stop_sequence, self->stop_sequence_len);

shared-module/framebufferio/FramebufferDisplay.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebu
7979
// Set the group after initialization otherwise we may send pixels while we delay in
8080
// initialization.
8181
common_hal_framebufferio_framebufferdisplay_show(self, &circuitpython_splash);
82-
self->auto_refresh = auto_refresh;
82+
common_hal_framebufferio_framebufferdisplay_set_auto_refresh(self, auto_refresh);
8383
}
8484

8585
bool common_hal_framebufferio_framebufferdisplay_show(framebufferio_framebufferdisplay_obj_t* self, displayio_group_t* root_group) {
@@ -280,6 +280,13 @@ bool common_hal_framebufferio_framebufferdisplay_get_auto_refresh(framebufferio_
280280
void common_hal_framebufferio_framebufferdisplay_set_auto_refresh(framebufferio_framebufferdisplay_obj_t* self,
281281
bool auto_refresh) {
282282
self->first_manual_refresh = !auto_refresh;
283+
if (auto_refresh != self->auto_refresh) {
284+
if (auto_refresh) {
285+
supervisor_enable_tick();
286+
} else {
287+
supervisor_disable_tick();
288+
}
289+
}
283290
self->auto_refresh = auto_refresh;
284291
}
285292

@@ -297,12 +304,13 @@ void framebufferio_framebufferdisplay_background(framebufferio_framebufferdispla
297304
}
298305

299306
void release_framebufferdisplay(framebufferio_framebufferdisplay_obj_t* self) {
307+
common_hal_framebufferio_framebufferdisplay_set_auto_refresh(self, false);
300308
release_display_core(&self->core);
301309
self->framebuffer_protocol->deinit(self->framebuffer);
302310
}
303311

304312
void reset_framebufferdisplay(framebufferio_framebufferdisplay_obj_t* self) {
305-
self->auto_refresh = true;
313+
common_hal_framebufferio_framebufferdisplay_set_auto_refresh(self, true);
306314
common_hal_framebufferio_framebufferdisplay_show(self, NULL);
307315
}
308316

0 commit comments

Comments
 (0)