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:
committed by
GitHub
parent
4fea48f433
commit
db48dfe812
@@ -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(®istered_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(®istered_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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user