diff --git a/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.mk b/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.mk index 6bfe6624866..fb62ff22980 100644 --- a/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.mk +++ b/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.mk @@ -11,4 +11,5 @@ EXTERNAL_FLASH_DEVICES = W25Q32BV LONGINT_IMPL = MPZ CIRCUITPY_CODEOP = 0 +CIRCUITPY_PARALLELDISPLAYBUS = 0 CIRCUITPY_RAINBOWIO = 0 diff --git a/ports/espressif/common-hal/audiobusio/__init__.c b/ports/espressif/common-hal/audiobusio/__init__.c index dae711100d3..4843e457f1a 100644 --- a/ports/espressif/common-hal/audiobusio/__init__.c +++ b/ports/espressif/common-hal/audiobusio/__init__.c @@ -12,6 +12,10 @@ #include "bindings/espidf/__init__.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" +#include "soc/soc_caps.h" +#if defined(SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE) && SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE +#include "esp_cache.h" +#endif #include "shared-module/audiocore/__init__.h" @@ -114,7 +118,18 @@ static void i2s_fill_buffer(i2s_t *self) { static void i2s_callback_fun(void *self_in) { i2s_t *self = self_in; + #if defined(SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE) && SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE + void *buffer = self->next_buffer; + size_t buffer_size = self->next_buffer_size; + #endif i2s_fill_buffer(self); + #if defined(SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE) && SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE + // Internal RAM is cached. IDF writes the buffer back right after on_sent, before + // we fill it here, so write it back again or the DMA plays stale data. + if (buffer != NULL) { + esp_cache_msync(buffer, buffer_size, ESP_CACHE_MSYNC_FLAG_DIR_C2M); + } + #endif } static bool i2s_event_interrupt(i2s_chan_handle_t handle, i2s_event_data_t *event, void *self_in) { diff --git a/shared-module/framebufferio/FramebufferDisplay.c b/shared-module/framebufferio/FramebufferDisplay.c index 72f0dd65311..d0d31faeace 100644 --- a/shared-module/framebufferio/FramebufferDisplay.c +++ b/shared-module/framebufferio/FramebufferDisplay.c @@ -13,6 +13,7 @@ #include "shared-bindings/time/__init__.h" #include "shared-module/displayio/__init__.h" #include "shared-module/displayio/display_core.h" +#include "supervisor/background_callback.h" #include "supervisor/shared/display.h" #include "supervisor/shared/tick.h" @@ -226,8 +227,8 @@ static bool _refresh_area(framebufferio_framebufferdisplay_obj_t *self, const di #if CIRCUITPY_WEB_WORKFLOW display_stream_area_updated(&self->core, &subrectangle); #endif - // Run background tasks so they can run during an explicit refresh. - // Auto-refresh won't run background tasks here because it is a background task itself. + // Run background tasks so they can run during a refresh. Auto-refresh allows + // them in framebufferio_framebufferdisplay_background(). RUN_BACKGROUND_TASKS; // Run USB background tasks so they can run during an implicit refresh. @@ -338,7 +339,12 @@ void framebufferio_framebufferdisplay_background(framebufferio_framebufferdispla _update_backlight(self); if (self->auto_refresh && (supervisor_ticks_ms64() - self->core.last_refresh) > self->native_ms_per_frame) { + // Auto-refresh runs inside a background callback, which blocks other callbacks. + // Allow callbacks so RUN_BACKGROUND_TASKS in _refresh_area() can run them. + // refresh_in_progress stops a nested refresh of this display. + background_callback_allow(); _refresh_display(self); + background_callback_prevent(); } } diff --git a/supervisor/shared/background_callback.c b/supervisor/shared/background_callback.c index ffeb78bbb83..65a0bcbf4c0 100644 --- a/supervisor/shared/background_callback.c +++ b/supervisor/shared/background_callback.c @@ -69,11 +69,19 @@ void PLACE_IN_ITCM(background_callback_run_all)(void) { return; } ++background_prevention_count; - background_callback_t *cb = (background_callback_t *)callback_head; - callback_head = NULL; - callback_tail = NULL; - while (cb) { - background_callback_t *next = cb->next; + // Run the callbacks queued now, taking each one off the live queue just before it + // runs. A callback that allows background tasks (like a display auto-refresh) can + // then run the rest in a nested call. Stop at the current tail so callbacks added + // while running wait for the next call. + background_callback_t *last = (background_callback_t *)callback_tail; + while (callback_head) { + background_callback_t *cb = (background_callback_t *)callback_head; + callback_head = cb->next; + if (callback_head) { + callback_head->prev = NULL; + } else { + callback_tail = NULL; + } cb->next = cb->prev = NULL; background_callback_fun fun = cb->fun; void *data = cb->data; @@ -83,7 +91,9 @@ void PLACE_IN_ITCM(background_callback_run_all)(void) { fun(data); } CALLBACK_CRITICAL_BEGIN; - cb = next; + if (cb == last) { + break; + } } --background_prevention_count; CALLBACK_CRITICAL_END;