Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ EXTERNAL_FLASH_DEVICES = W25Q32BV
LONGINT_IMPL = MPZ

CIRCUITPY_CODEOP = 0
CIRCUITPY_PARALLELDISPLAYBUS = 0
CIRCUITPY_RAINBOWIO = 0
15 changes: 15 additions & 0 deletions ports/espressif/common-hal/audiobusio/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 8 additions & 2 deletions shared-module/framebufferio/FramebufferDisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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();
}
}

Expand Down
22 changes: 16 additions & 6 deletions supervisor/shared/background_callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Loading