Fixes and improvements (#620)

- Standardized keyboard input using Unicode-based key codes across supported devices and the simulator. Keyboards don't emit `LV_KEY_*` anymore.
- Refactored lilygo encoder driver into a reusable GPIO rotary encoder driver (see `Drivers/gpio-encoder-module/`). Added more features to the config file.
- Improved LVGL keyboard device management, including duplicate prevention and reliable reconnects.
- LVGL file mutex now registers with lvgl start/stop
- Improved LVGL startup/shutdown stability and memory allocation reliability.
- Increased simulator LVGL memory capacity and improved USB device-class handling.
This commit is contained in:
Ken Van Hoeylandt
2026-08-23 17:21:16 +02:00
committed by GitHub
parent 4fea48f433
commit db48dfe812
51 changed files with 1219 additions and 602 deletions
+5 -3
View File
@@ -74,6 +74,7 @@ constexpr auto* TAG = "Tactility";
static DispatcherHandle_t mainDispatcherHandle = dispatcher_alloc();
void initFileMutexForLvgl();
void deinitFileMutexForLvgl();
namespace {
@@ -423,6 +424,8 @@ static void applySavedTouchCalibration() {
#endif // CONFIG_TT_TOUCH_CALIBRATION_SUPPORTED
static void onLvglStarted() {
initFileMutexForLvgl();
window_manager_configure(windowManagerScreenInit);
check(module_ensure_started(&lvgl_window_manager_module) == ERROR_NONE);
@@ -453,6 +456,8 @@ static void onLvglStarted() {
}
static void onLvglStopped() {
deinitFileMutexForLvgl();
if (softwareKeyboard.object != nullptr) {
lvgl_software_keyboard_destruct(&softwareKeyboard);
}
@@ -510,9 +515,6 @@ void run(Module* const dtsModules[], const DtsDevice dtsDevices[]) {
registerAndStartServices();
// Must start right before LVGL
initFileMutexForLvgl();
lvgl_module_configure((LvglModuleConfig) {
.on_start = onLvglStarted,
.on_stop = onLvglStopped,
-1
View File
@@ -273,7 +273,6 @@ void runBootSequence(TickType_t startTime) {
#endif
if (!setupUsbBootMode()) {
LOG_I(TAG, "initFromBootApp");
registerApps();
waitForMinimalSplashDuration(startTime);
startNextApp();
+44 -13
View File
@@ -6,23 +6,48 @@
#include <tactility/filesystem/file_system.h>
#include <lvgl/lvgl.h>
#include <vector>
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 {
std::vector<FileMutexId> registered_ids;
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.
*/
void initFileMutexForLvgl() {
file_system_for_each(nullptr, [](FileSystem* fs, void* context) {
file_system_for_each(&registered_ids, [](FileSystem* fs, void* context) {
char mount_path[64];
if (file_system_get_path(fs, mount_path, sizeof(mount_path)) != ERROR_NONE) {
return true;
@@ -56,17 +81,15 @@ void initFileMutexForLvgl() {
struct Context {
const char* mountPath;
std::vector<FileMutexId>* registeredIds;
};
Context ctx = { .mountPath = mount_path };
Context ctx = { .mountPath = mount_path, .registeredIds = static_cast<std::vector<FileMutexId>*>(context) };
device_for_each_child(parent, &ctx, [](Device* child, void* context) -> bool {
Context* ctx = static_cast<Context*>(context);
if (device_get_type(child) == &DISPLAY_TYPE) {
LOG_I(TAG, "Adding file mutex for %s as it shares a bus with a display", ctx->mountPath);
file_mutex_register(
&lvgl_mutex,
ctx->mountPath
);
ctx->registeredIds->push_back(file_mutex_add(&lvgl_mutex, ctx->mountPath));
return false;
} else {
LOG_D(TAG, "child of parent, %s: not DISPLAY_TYPE", child->name);
@@ -84,7 +107,7 @@ void initFileMutexForLvgl() {
return;
}
file_system_for_each(nullptr, [](FileSystem* fs, void* context) {
file_system_for_each(&registered_ids, [](FileSystem* fs, void* context) {
char mount_path[64];
if (file_system_get_path(fs, mount_path, sizeof(mount_path)) != ERROR_NONE) {
return true;
@@ -96,9 +119,17 @@ void initFileMutexForLvgl() {
}
LOG_I(TAG, "Adding file mutex for %s (SD card) - a display is present and may contend for bus/DMA resources", mount_path);
file_mutex_register(&lvgl_mutex, mount_path);
auto* ids = static_cast<std::vector<FileMutexId>*>(context);
ids->push_back(file_mutex_add(&lvgl_mutex, mount_path));
return true;
});
}
void deinitFileMutexForLvgl() {
for (FileMutexId id : registered_ids) {
file_mutex_remove(id);
}
registered_ids.clear();
}
}
@@ -63,21 +63,25 @@ void onKeyboardDeviceStarted(Device* device) {
void onKeyboardDeviceStopped(Device* device) {
auto lock = bindingsMutex().asScopedLock();
lock.lock();
lv_indev_t* indev = nullptr;
auto& list = bindings();
for (auto it = list.begin(); it != list.end(); ++it) {
if (it->device == device) {
indev = it->indev;
list.erase(it);
break;
}
}
if (indev == nullptr) {
return;
}
// Not every indev bound to a keyboard device goes through onKeyboardDeviceStarted() and
// bindings() above. lvgl_devices_attach() also binds whatever KEYBOARD_TYPE devices are
// already started at LVGL startup, before this listener is even registered (see
// startKeyboardDeviceListener()'s call site). Look the indev up directly so that path's
// devices still get detached before the kernel device is destructed, instead of leaving a
// dangling indev that reads a freed device on the next LVGL tick.
lvgl_lock();
lvgl_keyboard_remove(indev);
lv_indev_t* indev = lvgl_keyboard_find_by_device(device);
if (indev != nullptr) {
lvgl_keyboard_remove(indev);
}
lvgl_unlock();
}
+14 -4
View File
@@ -126,11 +126,12 @@ static void statusbar_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj)
LV_TRACE_OBJ_CREATE("begin");
lv_obj_remove_flag(obj, LV_OBJ_FLAG_SCROLLABLE);
LV_TRACE_OBJ_CREATE("finished");
auto* statusbar = (Statusbar*)obj;
statusbar->pubsub_subscription = statusbar_data.pubsub->subscribe([statusbar](auto) {
statusbar_pubsub_event(statusbar);
});
// Deliberately does NOT subscribe to statusbar_data.pubsub here - that happens at the end of
// statusbar_create(), once statusbar->icons[] is actually populated. Subscribing this early
// would let a concurrent statusbar_icon_add()/_remove()/_set_image()/_set_visibility() call
// from another task publish and run update_icon() on a still-null icons[] slot before this
// instance's own creation loop below has had a chance to fill it in.
if (!statusbar_data.time_update_timer->isRunning()) {
statusbar_data.time_update_timer->start();
system_event_callback_add(KERNEL_EVENT_TIME_CHANGED, onTimeChanged, nullptr);
@@ -190,7 +191,16 @@ lv_obj_t* statusbar_create(lv_obj_t* parent) {
update_icon(image, &(statusbar_data.icons[i]));
}
// Only now is statusbar->icons[] fully populated - see statusbar_constructor()'s comment for
// why the subscription can't be registered any earlier. Subscribing before unlocking (rather
// than after) closes a narrow window where a concurrent statusbar_icon_add()/_remove()/
// _set_image()/_set_visibility() call could publish - and be missed by this instance - after
// the icons are populated but before it's subscribed.
statusbar->pubsub_subscription = statusbar_data.pubsub->subscribe([statusbar](auto) {
statusbar_pubsub_event(statusbar);
});
statusbar_data.mutex.unlock();
return obj;
}