Fix for LVGL file lock when LVGL is not running

This commit is contained in:
Ken Van Hoeylandt 2026-08-21 21:28:11 +02:00
parent 700c332219
commit f77bea59bc
2 changed files with 29 additions and 5 deletions

View File

@ -20,16 +20,19 @@ static bool initialized = false;
void lvgl_lock(void) {
if (!initialized) { return; }
if (!lvgl_is_running()) { return; }
lvgl_port_lock(portMAX_DELAY);
}
bool lvgl_try_lock(uint32_t timeoutTicks) {
if (!initialized) { return false; }
if (!lvgl_is_running()) { return false; }
// lvgl_port_lock expects milliseconds
return lvgl_port_lock(timeoutTicks * portTICK_PERIOD_MS);
}
void lvgl_unlock(void) {
if (!lvgl_is_running()) { return; }
if (!initialized) { return; }
lvgl_port_unlock();
}

View File

@ -9,14 +9,35 @@
constexpr auto* TAG = "file_mutex_lvgl";
struct Device;
namespace tt {
static const FileMutex lvgl_mutex = {
.lock = lvgl_lock,
.try_lock = lvgl_try_lock,
.unlock = lvgl_unlock,
namespace {
void wrapped_lvgl_lock() {
if (!lvgl_is_running()) return;
lvgl_lock();
}
bool wrapped_lvgl_try_lock(uint32_t timeout) {
// Return lock success, so the file operation can continue when LVGL is not running
// lvgl_try_lock() fails to lock if LVGL is not running
if (!lvgl_is_running()) return true;
return lvgl_try_lock(timeout);
}
void wrapped_lvgl_unlock() {
if (!lvgl_is_running()) return;
lvgl_unlock();
}
const FileMutex lvgl_mutex = {
.lock = wrapped_lvgl_lock,
.try_lock = wrapped_lvgl_try_lock,
.unlock = wrapped_lvgl_unlock,
};
}
namespace tt {
/**
* Finds file systems with a device (e.g. sd card) that is owned by a SPI controller.
* If the SPI controller has a display on the bus, we create an LVGL lock for the file system path.