From f77bea59bcb01a941f9516acf03f5c739066efb1 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Fri, 21 Aug 2026 21:28:11 +0200 Subject: [PATCH] Fix for LVGL file lock when LVGL is not running --- Modules/lvgl-module/source/arch/lvgl_esp32.c | 3 ++ Tactility/Source/file/FileMutexLvgl.cpp | 31 ++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Modules/lvgl-module/source/arch/lvgl_esp32.c b/Modules/lvgl-module/source/arch/lvgl_esp32.c index 63d1134ce..a7f879844 100644 --- a/Modules/lvgl-module/source/arch/lvgl_esp32.c +++ b/Modules/lvgl-module/source/arch/lvgl_esp32.c @@ -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(); } diff --git a/Tactility/Source/file/FileMutexLvgl.cpp b/Tactility/Source/file/FileMutexLvgl.cpp index f8df9430b..8a4b8094f 100644 --- a/Tactility/Source/file/FileMutexLvgl.cpp +++ b/Tactility/Source/file/FileMutexLvgl.cpp @@ -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.