Skip to content

Commit e759769

Browse files
authored
Merge pull request #3175 from jepler/background-callback-bugs
Background callback bugfixes
2 parents 565d002 + c243c13 commit e759769

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

shared-module/displayio/__init__.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,7 @@ void reset_displays(void) {
190190
common_hal_displayio_epaperdisplay_show(display, NULL);
191191
#if CIRCUITPY_FRAMEBUFFERIO
192192
} else if (displays[i].framebuffer_display.base.type == &framebufferio_framebufferdisplay_type) {
193-
framebufferio_framebufferdisplay_obj_t* display = &displays[i].framebuffer_display;
194-
display->auto_refresh = true;
195-
common_hal_framebufferio_framebufferdisplay_show(display, NULL);
193+
framebufferio_framebufferdisplay_reset(&displays[i].framebuffer_display);
196194
#endif
197195
}
198196
}

shared-module/framebufferio/FramebufferDisplay.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,8 @@ void framebufferio_framebufferdisplay_collect_ptrs(framebufferio_framebufferdisp
318318
gc_collect_ptr(self->framebuffer);
319319
displayio_display_core_collect_ptrs(&self->core);
320320
}
321+
322+
void framebufferio_framebufferdisplay_reset(framebufferio_framebufferdisplay_obj_t* self) {
323+
common_hal_framebufferio_framebufferdisplay_set_auto_refresh(self, true);
324+
common_hal_framebufferio_framebufferdisplay_show(self, NULL);
325+
}

shared-module/framebufferio/FramebufferDisplay.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ typedef struct {
5555
void framebufferio_framebufferdisplay_background(framebufferio_framebufferdisplay_obj_t* self);
5656
void release_framebufferdisplay(framebufferio_framebufferdisplay_obj_t* self);
5757
void reset_framebufferdisplay(framebufferio_framebufferdisplay_obj_t* self);
58+
void framebufferio_framebufferdisplay_reset(framebufferio_framebufferdisplay_obj_t* self);
5859

5960
void framebufferio_framebufferdisplay_collect_ptrs(framebufferio_framebufferdisplay_obj_t* self);
6061

supervisor/shared/background_callback.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
* THE SOFTWARE.
2525
*/
2626

27+
#include <string.h>
28+
2729
#include "py/gc.h"
2830
#include "py/mpconfig.h"
2931
#include "supervisor/background_callback.h"
@@ -101,6 +103,12 @@ void background_callback_end_critical_section() {
101103

102104
void background_callback_reset() {
103105
CALLBACK_CRITICAL_BEGIN;
106+
background_callback_t *cb = (background_callback_t*)callback_head;
107+
while(cb) {
108+
background_callback_t *next = cb->next;
109+
memset(cb, 0, sizeof(*cb));
110+
cb = next;
111+
}
104112
callback_head = NULL;
105113
callback_tail = NULL;
106114
in_background_callback = false;

supervisor/shared/tick.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666

6767
static volatile uint64_t PLACE_IN_DTCM_BSS(background_ticks);
6868

69-
static background_callback_t callback;
69+
static background_callback_t tick_callback;
7070

7171
volatile uint64_t last_finished_tick = 0;
7272

@@ -119,7 +119,7 @@ void supervisor_tick(void) {
119119
#endif
120120
}
121121
#endif
122-
background_callback_add(&callback, supervisor_background_tasks, NULL);
122+
background_callback_add(&tick_callback, supervisor_background_tasks, NULL);
123123
}
124124

125125
uint64_t supervisor_ticks_ms64() {

supervisor/shared/usb/usb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ void usb_init(void) {
6464
tusb_init();
6565

6666
#if MICROPY_KBD_EXCEPTION
67-
// Set Ctrl+C as wanted char, tud_cdc_rx_wanted_cb() callback will be invoked when Ctrl+C is received
68-
// This callback always got invoked regardless of mp_interrupt_char value since we only set it once here
67+
// Set Ctrl+C as wanted char, tud_cdc_rx_wanted_cb() usb_callback will be invoked when Ctrl+C is received
68+
// This usb_callback always got invoked regardless of mp_interrupt_char value since we only set it once here
6969
tud_cdc_set_wanted_char(CHAR_CTRL_C);
7070
#endif
7171

@@ -83,14 +83,14 @@ void usb_background(void) {
8383
}
8484
}
8585

86-
static background_callback_t callback;
86+
static background_callback_t usb_callback;
8787
static void usb_background_do(void* unused) {
8888
usb_background();
8989
}
9090

9191
void usb_irq_handler(void) {
9292
tud_int_handler(0);
93-
background_callback_add(&callback, usb_background_do, NULL);
93+
background_callback_add(&usb_callback, usb_background_do, NULL);
9494
}
9595

9696
//--------------------------------------------------------------------+

0 commit comments

Comments
 (0)