Hal refactored (#99)
This commit is contained in:
committed by
GitHub
parent
0188ce721c
commit
33bb742dfb
@@ -125,15 +125,18 @@ static void register_and_start_user_services(const service::Manifest* const serv
|
||||
}
|
||||
}
|
||||
|
||||
void init(const Configuration* config) {
|
||||
void init(const Configuration& config) {
|
||||
TT_LOG_I(TAG, "init started");
|
||||
|
||||
tt_assert(config.hardware);
|
||||
const hal::Configuration& hardware = *config.hardware;
|
||||
|
||||
// Assign early so starting services can use it
|
||||
config_instance = config;
|
||||
config_instance = &config;
|
||||
|
||||
initHeadless(*config->hardware);
|
||||
initHeadless(hardware);
|
||||
|
||||
lvgl::init(config->hardware);
|
||||
lvgl::init(hardware);
|
||||
|
||||
// Note: the order of starting apps and services is critical!
|
||||
// System services are registered first so the apps below can find them if needed
|
||||
@@ -142,16 +145,16 @@ void init(const Configuration* config) {
|
||||
register_system_apps();
|
||||
// Then we register and start user services. They are started after system app
|
||||
// registration just in case they want to figure out which system apps are installed.
|
||||
register_and_start_user_services(config->services);
|
||||
register_and_start_user_services(config.services);
|
||||
// Now we register the user apps, as they might rely on the user services.
|
||||
register_user_apps(config->apps);
|
||||
register_user_apps(config.apps);
|
||||
|
||||
TT_LOG_I(TAG, "init starting desktop app");
|
||||
service::loader::startApp(app::boot::manifest.id, true, Bundle());
|
||||
|
||||
if (config->auto_start_app_id) {
|
||||
TT_LOG_I(TAG, "init auto-starting %s", config->auto_start_app_id);
|
||||
service::loader::startApp(config->auto_start_app_id, true, Bundle());
|
||||
if (config.auto_start_app_id) {
|
||||
TT_LOG_I(TAG, "init auto-starting %s", config.auto_start_app_id);
|
||||
service::loader::startApp(config.auto_start_app_id, true, Bundle());
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "init complete");
|
||||
|
||||
@@ -19,7 +19,7 @@ typedef struct {
|
||||
* Attempts to initialize Tactility and all configured hardware.
|
||||
* @param config
|
||||
*/
|
||||
void init(const Configuration* config);
|
||||
void init(const Configuration& config);
|
||||
|
||||
/**
|
||||
* While technically nullable, this instance is always set if tt_init() succeeds.
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#include <Timer.h>
|
||||
#include <Check.h>
|
||||
#include <Thread.h>
|
||||
#include <Kernel.h>
|
||||
#include "Assets.h"
|
||||
#include "app/App.h"
|
||||
#include "lvgl.h"
|
||||
#include "hal/Display.h"
|
||||
#include "service/loader/Loader.h"
|
||||
#include "lvgl/Style.h"
|
||||
#include "app/display/DisplayPreferences.h"
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "sdkconfig.h"
|
||||
@@ -26,7 +27,16 @@ struct Data {
|
||||
|
||||
static int32_t threadCallback(TT_UNUSED void* context) {
|
||||
TickType_t start_time = tt::get_ticks();
|
||||
// Do stuff
|
||||
|
||||
auto* lvgl_display = lv_display_get_default();
|
||||
tt_assert(lvgl_display != nullptr);
|
||||
auto* hal_display = (tt::hal::Display*)lv_display_get_user_data(lvgl_display);
|
||||
tt_assert(hal_display != nullptr);
|
||||
if (hal_display->supportsBacklightDuty()) {
|
||||
int32_t backlight_duty = app::display::preferences_get_backlight_duty();
|
||||
hal_display->setBacklightDuty(backlight_duty);
|
||||
}
|
||||
|
||||
TickType_t end_time = tt::get_ticks();
|
||||
TickType_t ticks_passed = end_time - start_time;
|
||||
TickType_t minimum_ticks = (CONFIG_TT_SPLASH_DURATION / portTICK_PERIOD_MS);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Tactility.h"
|
||||
#include "lvgl/Toolbar.h"
|
||||
#include "lvgl.h"
|
||||
#include "hal/Display.h"
|
||||
|
||||
namespace tt::app::display {
|
||||
|
||||
@@ -14,16 +15,18 @@ static uint8_t backlight_duty = 255;
|
||||
|
||||
static void slider_event_cb(lv_event_t* event) {
|
||||
auto* slider = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
||||
const Configuration* config = getConfiguration();
|
||||
hal::SetBacklightDuty set_backlight_duty = config->hardware->display.setBacklightDuty;
|
||||
auto* lvgl_display = lv_display_get_default();
|
||||
tt_assert(lvgl_display != nullptr);
|
||||
auto* hal_display = (tt::hal::Display*)lv_display_get_user_data(lvgl_display);
|
||||
tt_assert(hal_display != nullptr);
|
||||
|
||||
if (set_backlight_duty != nullptr) {
|
||||
if (hal_display->supportsBacklightDuty()) {
|
||||
int32_t slider_value = lv_slider_get_value(slider);
|
||||
|
||||
backlight_duty = (uint8_t)slider_value;
|
||||
backlight_duty_set = true;
|
||||
|
||||
set_backlight_duty(backlight_duty);
|
||||
hal_display->setBacklightDuty(backlight_duty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,9 +94,12 @@ static void app_show(App& app, lv_obj_t* parent) {
|
||||
lv_slider_set_range(brightness_slider, 0, 255);
|
||||
lv_obj_add_event_cb(brightness_slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, nullptr);
|
||||
|
||||
const Configuration* config = getConfiguration();
|
||||
hal::SetBacklightDuty set_backlight_duty = config->hardware->display.setBacklightDuty;
|
||||
if (set_backlight_duty == nullptr) {
|
||||
auto* lvgl_display = lv_display_get_default();
|
||||
tt_assert(lvgl_display != nullptr);
|
||||
auto* hal_display = (tt::hal::Display*)lv_display_get_user_data(lvgl_display);
|
||||
tt_assert(hal_display != nullptr);
|
||||
|
||||
if (!hal_display->supportsBacklightDuty()) {
|
||||
lv_slider_set_value(brightness_slider, 255, LV_ANIM_OFF);
|
||||
lv_obj_add_state(brightness_slider, LV_STATE_DISABLED);
|
||||
} else {
|
||||
|
||||
@@ -35,6 +35,7 @@ int scandir(
|
||||
) {
|
||||
DIR* dir = opendir(path);
|
||||
if (dir == nullptr) {
|
||||
TT_LOG_E(TAG, "Failed to open dir %s", path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,103 @@
|
||||
#include "app/display/DisplayPreferences.h"
|
||||
#include "lvgl.h"
|
||||
#include "hal/Configuration.h"
|
||||
#include "hal/Display.h"
|
||||
#include "hal/Touch.h"
|
||||
#include "hal/Keyboard.h"
|
||||
#include "lvgl/LvglKeypad.h"
|
||||
#include "lvgl/Lvgl.h"
|
||||
|
||||
namespace tt::lvgl {
|
||||
|
||||
void init(const hal::Configuration* config) {
|
||||
hal::SetBacklightDuty set_backlight_duty = config->display.setBacklightDuty;
|
||||
if (set_backlight_duty != nullptr) {
|
||||
int32_t backlight_duty = app::display::preferences_get_backlight_duty();
|
||||
set_backlight_duty(backlight_duty);
|
||||
#define TAG "lvglinit"
|
||||
|
||||
bool initDisplay(const hal::Configuration& config) {
|
||||
assert(config.createDisplay);
|
||||
auto* display = config.createDisplay();
|
||||
if (!display->start()) {
|
||||
TT_LOG_E(TAG, "Display start failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
lv_display_t* lvgl_display = display->getLvglDisplay();
|
||||
tt_assert(lvgl_display);
|
||||
|
||||
if (display->supportsBacklightDuty()) {
|
||||
display->setBacklightDuty(0);
|
||||
}
|
||||
|
||||
void* existing_display_user_data = lv_display_get_user_data(lvgl_display);
|
||||
// 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
|
||||
tt_assert(existing_display_user_data == nullptr);
|
||||
lv_display_set_user_data(lvgl_display, display);
|
||||
|
||||
lv_display_rotation_t rotation = app::display::preferences_get_rotation();
|
||||
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;
|
||||
}
|
||||
|
||||
bool initTouch(hal::Display* display, hal::Touch* touch) {
|
||||
TT_LOG_I(TAG, "Touch init");
|
||||
tt_assert(display);
|
||||
tt_assert(touch);
|
||||
if (touch->start(display->getLvglDisplay())) {
|
||||
return true;
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Touch init failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool initKeyboard(hal::Display* display, hal::Keyboard* keyboard) {
|
||||
TT_LOG_I(TAG, "Keyboard init");
|
||||
tt_assert(display);
|
||||
tt_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);
|
||||
tt::lvgl::keypad_set_indev(keyboard_indev);
|
||||
TT_LOG_I(TAG, "Keyboard started");
|
||||
return true;
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Keyboard start failed");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
TT_LOG_E(TAG, "Keyboard attach failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void init(const hal::Configuration& config) {
|
||||
TT_LOG_I(TAG, "Starting");
|
||||
|
||||
if (config.initLvgl != nullptr && !config.initLvgl()) {
|
||||
TT_LOG_E(TAG, "LVGL init failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!initDisplay(config)) {
|
||||
return;
|
||||
}
|
||||
|
||||
hal::Display* display = getDisplay();
|
||||
|
||||
hal::Touch* touch = display->createTouch();
|
||||
if (touch != nullptr) {
|
||||
initTouch(display, touch);
|
||||
}
|
||||
|
||||
if (config.createKeyboard) {
|
||||
hal::Keyboard* keyboard = config.createKeyboard();
|
||||
initKeyboard(display, keyboard);
|
||||
}
|
||||
|
||||
TT_LOG_I(TAG, "Finished");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "lvgl/Lvgl.h"
|
||||
#include "Check.h"
|
||||
|
||||
namespace tt::lvgl {
|
||||
|
||||
hal::Display* getDisplay() {
|
||||
auto* lvgl_display = lv_display_get_default();
|
||||
tt_assert(lvgl_display != nullptr);
|
||||
auto* hal_display = (tt::hal::Display*)lv_display_get_user_data(lvgl_display);
|
||||
tt_assert(hal_display != nullptr);
|
||||
return hal_display;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "hal/Display.h"
|
||||
|
||||
namespace tt::lvgl {
|
||||
hal::Display* getDisplay();
|
||||
}
|
||||
@@ -1,11 +1,20 @@
|
||||
#include <Mutex.h>
|
||||
#include "LvglSync.h"
|
||||
|
||||
#include "Check.h"
|
||||
|
||||
namespace tt::lvgl {
|
||||
|
||||
static LvglLock lock_singleton = nullptr;
|
||||
static LvglUnlock unlock_singleton = nullptr;
|
||||
Mutex lockMutex;
|
||||
|
||||
static bool defaultLock(uint32_t timeoutTicks) {
|
||||
return lockMutex.acquire(timeoutTicks) == TtStatusOk;
|
||||
}
|
||||
|
||||
static void defaultUnlock() {
|
||||
lockMutex.release();
|
||||
}
|
||||
|
||||
static LvglLock lock_singleton = defaultLock;
|
||||
static LvglUnlock unlock_singleton = defaultUnlock;
|
||||
|
||||
void syncSet(LvglLock lock, LvglUnlock unlock) {
|
||||
lock_singleton = lock;
|
||||
@@ -13,12 +22,10 @@ void syncSet(LvglLock lock, LvglUnlock unlock) {
|
||||
}
|
||||
|
||||
bool lock(uint32_t timeout_ticks) {
|
||||
tt_check(lock_singleton);
|
||||
return lock_singleton(timeout_ticks);
|
||||
}
|
||||
|
||||
void unlock() {
|
||||
tt_check(unlock_singleton);
|
||||
unlock_singleton();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ typedef bool (*LvglLock)(uint32_t timeout_ticks);
|
||||
typedef void (*LvglUnlock)();
|
||||
|
||||
void syncSet(LvglLock lock, LvglUnlock unlock);
|
||||
bool isSyncSet();
|
||||
bool lock(uint32_t timeout_ticks);
|
||||
void unlock();
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace tt::service::screenshot {
|
||||
|
||||
#define TAG "sdcard_service"
|
||||
#define TAG "screenshot_service"
|
||||
|
||||
extern const Manifest manifest;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user