Skip to content
Merged
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
24 changes: 18 additions & 6 deletions ports/espressif/common-hal/mipidsi/Display.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,29 @@ static void clear_panel_handles(mipidsi_display_obj_t *self) {
}
}

// The vsync ISR reads the frame callback and its data as a pair, so they change together.
static portMUX_TYPE frame_cb_lock = portMUX_INITIALIZER_UNLOCKED;

static void set_frame_cb(mipidsi_display_obj_t *self, framebuffer_frame_callback_t cb, void *data) {
portENTER_CRITICAL(&frame_cb_lock);
self->frame_cb = cb;
self->frame_cb_data = data;
portEXIT_CRITICAL(&frame_cb_lock);
}

// The DPI driver requires this callback to live in IRAM. It runs in interrupt context, so it only
// forwards to the framebuffer's frame callback (which hands off to the LVGL port) and returns.
static bool IRAM_ATTR mipidsi_display_vsync_cb(esp_lcd_panel_handle_t panel,
esp_lcd_dpi_panel_event_data_t *edata, void *user_ctx) {
(void)panel;
(void)edata;
mipidsi_display_obj_t *self = user_ctx;
if (self->frame_cb != NULL) {
self->frame_cb(self->frame_cb_data);
portENTER_CRITICAL_ISR(&frame_cb_lock);
framebuffer_frame_callback_t cb = self->frame_cb;
void *data = self->frame_cb_data;
portEXIT_CRITICAL_ISR(&frame_cb_lock);
if (cb != NULL) {
cb(data);
}
return false;
}
Expand Down Expand Up @@ -241,8 +255,7 @@ void common_hal_mipidsi_display_deinit(mipidsi_display_obj_t *self) {
}

// Stop the vsync ISR from reaching a display that is going away before the panel is deleted.
self->frame_cb = NULL;
self->frame_cb_data = NULL;
set_frame_cb(self, NULL, NULL);

// Cleanup backlight
#if (CIRCUITPY_PWMIO)
Expand Down Expand Up @@ -277,8 +290,7 @@ void common_hal_mipidsi_display_refresh(mipidsi_display_obj_t *self) {

void common_hal_mipidsi_display_set_frame_callback(mipidsi_display_obj_t *self,
framebuffer_frame_callback_t cb, void *data) {
self->frame_cb = cb;
self->frame_cb_data = data;
set_frame_cb(self, cb, data);
}

void common_hal_mipidsi_display_refresh_rows(mipidsi_display_obj_t *self, const uint8_t *dirty_row_bitmap) {
Expand Down