File locking refactored (#631)

Remove FileMutex and wire locking into driver subsystems.
This commit is contained in:
Ken Van Hoeylandt
2026-08-28 01:06:53 +02:00
committed by GitHub
parent 92ca046681
commit 020aa471e2
44 changed files with 766 additions and 993 deletions
+48 -9
View File
@@ -25,6 +25,7 @@ constexpr auto* TAG = "GC9A01";
#define GET_CONFIG(device) (static_cast<const Gc9a01Config*>((device)->config))
struct Gc9a01Internal {
Device* spi_controller;
esp_lcd_panel_io_handle_t io_handle;
esp_lcd_panel_handle_t panel_handle;
// See st7796-module's identical field for why this exists: draw_bitmap() must block until
@@ -63,6 +64,7 @@ static error_t start(Device* device) {
return ERROR_OUT_OF_MEMORY;
}
internal->spi_controller = parent;
internal->draw_done_semaphore = xSemaphoreCreateBinary();
if (internal->draw_done_semaphore == nullptr) {
free(internal);
@@ -123,6 +125,7 @@ static error_t start(Device* device) {
// Bring-up sequence, order matches the deprecated HAL's Gc9a01Display (proven correct on real
// Waveshare S3 Touch LCD 1.28 hardware). Every failure path below must clean up fully: unlike
// stop_device, this is never retried by the kernel if start_device fails.
spi_controller_lock(internal->spi_controller);
bool ok =
esp_lcd_panel_reset(internal->panel_handle) == ESP_OK &&
esp_lcd_panel_init(internal->panel_handle) == ESP_OK;
@@ -134,6 +137,7 @@ static error_t start(Device* device) {
ok = ok && ((!config->mirror_x && !config->mirror_y) || esp_lcd_panel_mirror(internal->panel_handle, config->mirror_x, config->mirror_y) == ESP_OK);
ok = ok && (!config->invert_color || esp_lcd_panel_invert_color(internal->panel_handle, true) == ESP_OK);
ok = ok && esp_lcd_panel_disp_on_off(internal->panel_handle, true) == ESP_OK;
spi_controller_unlock(internal->spi_controller);
if (!ok) {
LOG_E(TAG, "Failed to bring up panel");
@@ -151,9 +155,11 @@ static error_t start(Device* device) {
static error_t stop(Device* device) {
auto* internal = static_cast<Gc9a01Internal*>(device_get_driver_data(device));
spi_controller_lock(internal->spi_controller);
if (internal->panel_handle != nullptr) {
if (esp_lcd_panel_del(internal->panel_handle) != ESP_OK) {
LOG_E(TAG, "Failed to delete panel");
spi_controller_unlock(internal->spi_controller);
return ERROR_RESOURCE;
}
internal->panel_handle = nullptr;
@@ -162,10 +168,12 @@ static error_t stop(Device* device) {
if (internal->io_handle != nullptr) {
if (esp_lcd_panel_io_del(internal->io_handle) != ESP_OK) {
LOG_E(TAG, "Failed to delete panel IO");
spi_controller_unlock(internal->spi_controller);
return ERROR_RESOURCE;
}
internal->io_handle = nullptr;
}
spi_controller_unlock(internal->spi_controller);
vSemaphoreDelete(internal->draw_done_semaphore);
free(internal);
@@ -179,12 +187,18 @@ static error_t stop(Device* device) {
static error_t gc9a01_reset(Device* device) {
auto* internal = static_cast<Gc9a01Internal*>(device_get_driver_data(device));
return esp_lcd_panel_reset(internal->panel_handle) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
spi_controller_lock(internal->spi_controller);
error_t result = esp_lcd_panel_reset(internal->panel_handle) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
spi_controller_unlock(internal->spi_controller);
return result;
}
static error_t gc9a01_init(Device* device) {
auto* internal = static_cast<Gc9a01Internal*>(device_get_driver_data(device));
return esp_lcd_panel_init(internal->panel_handle) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
spi_controller_lock(internal->spi_controller);
error_t result = esp_lcd_panel_init(internal->panel_handle) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
spi_controller_unlock(internal->spi_controller);
return result;
}
static error_t gc9a01_draw_bitmap(Device* device, int32_t x_start, int32_t y_start, int32_t x_end, int32_t y_end, const void* color_data) {
@@ -192,22 +206,35 @@ static error_t gc9a01_draw_bitmap(Device* device, int32_t x_start, int32_t y_sta
xSemaphoreTake(internal->draw_done_semaphore, 0);
if (esp_lcd_panel_draw_bitmap(internal->panel_handle, x_start, y_start, x_end, y_end, color_data) != ESP_OK) {
spi_controller_lock(internal->spi_controller);
esp_err_t ret = esp_lcd_panel_draw_bitmap(internal->panel_handle, x_start, y_start, x_end, y_end, color_data);
if (ret != ESP_OK) {
spi_controller_unlock(internal->spi_controller);
return ERROR_RESOURCE;
}
// Hold the bus lock across the wait too, not just the queueing call: the command/data phases
// aren't wrapped in their own acquire_bus by esp_lcd_panel_io_spi, so another bus user could
// otherwise interleave with this transfer while it's still in flight.
xSemaphoreTake(internal->draw_done_semaphore, portMAX_DELAY);
spi_controller_unlock(internal->spi_controller);
return ERROR_NONE;
}
static error_t gc9a01_mirror(Device* device, bool x_axis, bool y_axis) {
auto* internal = static_cast<Gc9a01Internal*>(device_get_driver_data(device));
return esp_lcd_panel_mirror(internal->panel_handle, x_axis, y_axis) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
spi_controller_lock(internal->spi_controller);
error_t result = esp_lcd_panel_mirror(internal->panel_handle, x_axis, y_axis) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
spi_controller_unlock(internal->spi_controller);
return result;
}
static error_t gc9a01_swap_xy(Device* device, bool swap_axes) {
auto* internal = static_cast<Gc9a01Internal*>(device_get_driver_data(device));
return esp_lcd_panel_swap_xy(internal->panel_handle, swap_axes) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
spi_controller_lock(internal->spi_controller);
error_t result = esp_lcd_panel_swap_xy(internal->panel_handle, swap_axes) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
spi_controller_unlock(internal->spi_controller);
return result;
}
static bool gc9a01_get_swap_xy(Device* device) {
@@ -224,7 +251,10 @@ static bool gc9a01_get_mirror_y(Device* device) {
static error_t gc9a01_set_gap(Device* device, int32_t x_gap, int32_t y_gap) {
auto* internal = static_cast<Gc9a01Internal*>(device_get_driver_data(device));
return esp_lcd_panel_set_gap(internal->panel_handle, x_gap, y_gap) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
spi_controller_lock(internal->spi_controller);
error_t result = esp_lcd_panel_set_gap(internal->panel_handle, x_gap, y_gap) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
spi_controller_unlock(internal->spi_controller);
return result;
}
static int32_t gc9a01_get_gap_x(Device* device) {
@@ -237,17 +267,26 @@ static int32_t gc9a01_get_gap_y(Device* device) {
static error_t gc9a01_invert_color(Device* device, bool invert_color_data) {
auto* internal = static_cast<Gc9a01Internal*>(device_get_driver_data(device));
return esp_lcd_panel_invert_color(internal->panel_handle, invert_color_data) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
spi_controller_lock(internal->spi_controller);
error_t result = esp_lcd_panel_invert_color(internal->panel_handle, invert_color_data) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
spi_controller_unlock(internal->spi_controller);
return result;
}
static error_t gc9a01_disp_on_off(Device* device, bool on_off) {
auto* internal = static_cast<Gc9a01Internal*>(device_get_driver_data(device));
return esp_lcd_panel_disp_on_off(internal->panel_handle, on_off) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
spi_controller_lock(internal->spi_controller);
error_t result = esp_lcd_panel_disp_on_off(internal->panel_handle, on_off) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
spi_controller_unlock(internal->spi_controller);
return result;
}
static error_t gc9a01_disp_sleep(Device* device, bool sleep) {
auto* internal = static_cast<Gc9a01Internal*>(device_get_driver_data(device));
return esp_lcd_panel_disp_sleep(internal->panel_handle, sleep) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
spi_controller_lock(internal->spi_controller);
error_t result = esp_lcd_panel_disp_sleep(internal->panel_handle, sleep) == ESP_OK ? ERROR_NONE : ERROR_RESOURCE;
spi_controller_unlock(internal->spi_controller);
return result;
}
// The deprecated HAL's Gc9a01Display always set swap_bytes=true on its lvgl_port config