22#include <string.h>
33#include "shared-module/displayio/__init__.h"
44
5+ #include "py/reload.h"
56#include "shared-bindings/displayio/Bitmap.h"
67#include "shared-bindings/displayio/Display.h"
78#include "shared-bindings/displayio/Group.h"
89#include "shared-bindings/displayio/Palette.h"
10+ #include "supervisor/shared/autoreload.h"
911#include "supervisor/shared/display.h"
1012#include "supervisor/memory.h"
1113#include "supervisor/usb.h"
@@ -18,7 +20,19 @@ static inline void swap(uint16_t* a, uint16_t* b) {
1820 * b = temp ;
1921}
2022
23+ bool refreshing_displays = false;
24+
2125void displayio_refresh_displays (void ) {
26+ // Somehow reloads from the sdcard are being lost. So, cheat and reraise.
27+ if (reload_requested ) {
28+ mp_raise_reload_exception ();
29+ return ;
30+ }
31+
32+ if (refreshing_displays ) {
33+ return ;
34+ }
35+ refreshing_displays = true;
2236 for (uint8_t i = 0 ; i < CIRCUITPY_DISPLAY_LIMIT ; i ++ ) {
2337 if (displays [i ].display .base .type == NULL || displays [i ].display .base .type == & mp_type_NoneType ) {
2438 continue ;
@@ -27,6 +41,7 @@ void displayio_refresh_displays(void) {
2741 displayio_display_update_backlight (display );
2842
2943 if (!displayio_display_frame_queued (display )) {
44+ refreshing_displays = false;
3045 return ;
3146 }
3247 if (displayio_display_refresh_queued (display )) {
@@ -89,8 +104,9 @@ void displayio_refresh_displays(void) {
89104 index += 1 ;
90105 // The buffer is full, send it.
91106 if (index >= buffer_size ) {
92- if (!displayio_display_send_pixels (display , buffer , buffer_size / 2 )) {
107+ if (!displayio_display_send_pixels (display , buffer , buffer_size / 2 ) || reload_requested ) {
93108 displayio_display_finish_region_update (display );
109+ refreshing_displays = false;
94110 return ;
95111 }
96112 // TODO(tannewt): Make refresh displays faster so we don't starve other
@@ -103,12 +119,14 @@ void displayio_refresh_displays(void) {
103119 // Send the remaining data.
104120 if (index && !displayio_display_send_pixels (display , buffer , index * 2 )) {
105121 displayio_display_finish_region_update (display );
122+ refreshing_displays = false;
106123 return ;
107124 }
108125 displayio_display_finish_region_update (display );
109126 }
110127 displayio_display_finish_refresh (display );
111128 }
129+ refreshing_displays = false;
112130}
113131
114132void common_hal_displayio_release_displays (void ) {
0 commit comments