Implement device management (#199)

- Added `tt::hal::Device` and functions (de)register devices and search for them.
- Refactored apps: `Power` and `Display` settings apps now use the device API to find devices.
- Implemented the new API for all existing drivers for all devices, including the simulator.
- Updated HAL Configuration to return `std::shared_ptr` instead of raw pointers.
- Added test project for headless tests and implemented tests for the new code.
This commit is contained in:
Ken Van Hoeylandt
2025-02-02 15:16:51 +01:00
committed by GitHub
parent c87200a80d
commit cff0605b0a
54 changed files with 655 additions and 109 deletions
+21 -15
View File
@@ -11,14 +11,16 @@
namespace tt::lvgl {
#define TAG "lvglinit"
#define TAG "lvgl_init"
bool initDisplay(const hal::Configuration& config) {
static std::shared_ptr<tt::hal::Display> initDisplay(const hal::Configuration& config) {
assert(config.createDisplay);
auto* display = config.createDisplay();
auto display = config.createDisplay();
assert(display != nullptr);
if (!display->start()) {
TT_LOG_E(TAG, "Display start failed");
return false;
return nullptr;
}
lv_display_t* lvgl_display = display->getLvglDisplay();
@@ -32,17 +34,17 @@ bool initDisplay(const hal::Configuration& config) {
// esp_lvgl_port users user_data by default, so we have to modify the source
// this is a check for when we upgrade esp_lvgl_port and forget to modify it again
assert(existing_display_user_data == nullptr);
lv_display_set_user_data(lvgl_display, display);
lv_display_set_user_data(lvgl_display, display.get());
lv_display_rotation_t rotation = app::display::getRotation();
if (rotation != lv_disp_get_rotation(lv_disp_get_default())) {
lv_disp_set_rotation(lv_disp_get_default(), static_cast<lv_display_rotation_t>(rotation));
}
return true;
return display;
}
bool initTouch(hal::Display* display, hal::Touch* touch) {
static bool initTouch(const std::shared_ptr<hal::Display>& display, const std::shared_ptr<hal::Touch>& touch) {
TT_LOG_I(TAG, "Touch init");
assert(display);
assert(touch);
@@ -54,14 +56,14 @@ bool initTouch(hal::Display* display, hal::Touch* touch) {
}
}
bool initKeyboard(hal::Display* display, hal::Keyboard* keyboard) {
static bool initKeyboard(const std::shared_ptr<hal::Display>& display, const std::shared_ptr<hal::Keyboard>& keyboard) {
TT_LOG_I(TAG, "Keyboard init");
assert(display);
assert(keyboard);
if (keyboard->isAttached()) {
if (keyboard->start(display->getLvglDisplay())) {
lv_indev_t* keyboard_indev = keyboard->getLvglIndev();
lv_indev_set_user_data(keyboard_indev, keyboard);
lv_indev_set_user_data(keyboard_indev, keyboard.get());
tt::lvgl::keypad_set_indev(keyboard_indev);
TT_LOG_I(TAG, "Keyboard started");
return true;
@@ -85,20 +87,24 @@ void init(const hal::Configuration& config) {
return;
}
if (!initDisplay(config)) {
auto display = initDisplay(config);
if (display == nullptr) {
return;
}
hal::registerDevice(display);
hal::Display* display = getDisplay();
hal::Touch* touch = display->createTouch();
auto touch = display->createTouch();
if (touch != nullptr) {
hal::registerDevice(touch);
initTouch(display, touch);
}
if (config.createKeyboard) {
hal::Keyboard* keyboard = config.createKeyboard();
initKeyboard(display, keyboard);
auto keyboard = config.createKeyboard();
if (keyboard != nullptr) {
hal::registerDevice(keyboard);
initKeyboard(display, keyboard);
}
}
TT_LOG_I(TAG, "Finished");