66#include "shared-bindings/displayio/Display.h"
77#include "shared-bindings/displayio/Group.h"
88#include "shared-bindings/displayio/Palette.h"
9+ #include "supervisor/shared/autoreload.h"
910#include "supervisor/shared/display.h"
1011#include "supervisor/memory.h"
1112#include "supervisor/usb.h"
@@ -18,7 +19,13 @@ static inline void swap(uint16_t* a, uint16_t* b) {
1819 * b = temp ;
1920}
2021
22+ bool refreshing_displays = false;
23+
2124void displayio_refresh_displays (void ) {
25+ if (refreshing_displays ) {
26+ return ;
27+ }
28+ refreshing_displays = true;
2229 for (uint8_t i = 0 ; i < CIRCUITPY_DISPLAY_LIMIT ; i ++ ) {
2330 if (displays [i ].display .base .type == NULL || displays [i ].display .base .type == & mp_type_NoneType ) {
2431 continue ;
@@ -27,6 +34,7 @@ void displayio_refresh_displays(void) {
2734 displayio_display_update_backlight (display );
2835
2936 if (!displayio_display_frame_queued (display )) {
37+ refreshing_displays = false;
3038 return ;
3139 }
3240 if (displayio_display_refresh_queued (display )) {
@@ -89,8 +97,9 @@ void displayio_refresh_displays(void) {
8997 index += 1 ;
9098 // The buffer is full, send it.
9199 if (index >= buffer_size ) {
92- if (!displayio_display_send_pixels (display , buffer , buffer_size / 2 )) {
100+ if (!displayio_display_send_pixels (display , buffer , buffer_size / 2 ) || reload_requested ) {
93101 displayio_display_finish_region_update (display );
102+ refreshing_displays = false;
94103 return ;
95104 }
96105 // TODO(tannewt): Make refresh displays faster so we don't starve other
@@ -103,12 +112,14 @@ void displayio_refresh_displays(void) {
103112 // Send the remaining data.
104113 if (index && !displayio_display_send_pixels (display , buffer , index * 2 )) {
105114 displayio_display_finish_region_update (display );
115+ refreshing_displays = false;
106116 return ;
107117 }
108118 displayio_display_finish_region_update (display );
109119 }
110120 displayio_display_finish_refresh (display );
111121 }
122+ refreshing_displays = false;
112123}
113124
114125void common_hal_displayio_release_displays (void ) {
0 commit comments