File locking refactored (#631)
Remove FileMutex and wire locking into driver subsystems.
This commit is contained in:
committed by
GitHub
parent
92ca046681
commit
020aa471e2
@@ -31,6 +31,7 @@ constexpr auto* TAG = "JD9853";
|
||||
static const uint8_t GAMMA_CURVE_VALUES[4] = { 0x01, 0x04, 0x02, 0x08 };
|
||||
|
||||
struct Jd9853Internal {
|
||||
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
|
||||
@@ -69,6 +70,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);
|
||||
@@ -134,6 +136,7 @@ static error_t start(Device* device) {
|
||||
// Bring-up sequence, order matches the deprecated HAL's Jd9853Display (proven correct on real
|
||||
// Waveshare S3 Touch LCD 1.47 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 &&
|
||||
@@ -147,6 +150,7 @@ static error_t start(Device* device) {
|
||||
ok = ok && (!config->invert_color || esp_lcd_panel_invert_color(internal->panel_handle, true) == ESP_OK);
|
||||
ok = ok && (config->gamma_curve >= 4 || esp_lcd_panel_io_tx_param(internal->io_handle, LCD_CMD_GAMSET, &GAMMA_CURVE_VALUES[config->gamma_curve], 1) == 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");
|
||||
@@ -164,9 +168,11 @@ static error_t start(Device* device) {
|
||||
static error_t stop(Device* device) {
|
||||
auto* internal = static_cast<Jd9853Internal*>(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;
|
||||
@@ -175,10 +181,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);
|
||||
@@ -192,12 +200,18 @@ static error_t stop(Device* device) {
|
||||
|
||||
static error_t jd9853_reset(Device* device) {
|
||||
auto* internal = static_cast<Jd9853Internal*>(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 jd9853_init(Device* device) {
|
||||
auto* internal = static_cast<Jd9853Internal*>(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 jd9853_draw_bitmap(Device* device, int32_t x_start, int32_t y_start, int32_t x_end, int32_t y_end, const void* color_data) {
|
||||
@@ -205,22 +219,35 @@ static error_t jd9853_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 jd9853_mirror(Device* device, bool x_axis, bool y_axis) {
|
||||
auto* internal = static_cast<Jd9853Internal*>(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 jd9853_swap_xy(Device* device, bool swap_axes) {
|
||||
auto* internal = static_cast<Jd9853Internal*>(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 jd9853_get_swap_xy(Device* device) {
|
||||
@@ -237,7 +264,10 @@ static bool jd9853_get_mirror_y(Device* device) {
|
||||
|
||||
static error_t jd9853_set_gap(Device* device, int32_t x_gap, int32_t y_gap) {
|
||||
auto* internal = static_cast<Jd9853Internal*>(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 jd9853_get_gap_x(Device* device) {
|
||||
@@ -250,17 +280,26 @@ static int32_t jd9853_get_gap_y(Device* device) {
|
||||
|
||||
static error_t jd9853_invert_color(Device* device, bool invert_color_data) {
|
||||
auto* internal = static_cast<Jd9853Internal*>(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 jd9853_disp_on_off(Device* device, bool on_off) {
|
||||
auto* internal = static_cast<Jd9853Internal*>(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 jd9853_disp_sleep(Device* device, bool sleep) {
|
||||
auto* internal = static_cast<Jd9853Internal*>(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 Jd9853Display always set swap_bytes=true on its lvgl_port config
|
||||
|
||||
Reference in New Issue
Block a user