Refactor LVGL code into kernel module (#472)
* **New Features** * Added a standalone LVGL module and enabled LVGL support in the simulator for richer local UI testing. * **Refactor** * HAL and LVGL split into distinct modules; startup and device attach/detach flows reorganized for clearer lifecycle management. * Public APIs tightened with clearer nullability/documentation. * **Bug Fixes** * More consistent LVGL start/stop and device attach/detach behavior for improved stability.
This commit is contained in:
committed by
GitHub
parent
3fe1dc0312
commit
9f721e6655
@@ -2,11 +2,15 @@
|
||||
#include <sdkconfig.h>
|
||||
#endif
|
||||
|
||||
#include <format>
|
||||
#include <map>
|
||||
|
||||
#include <Tactility/Tactility.h>
|
||||
#include <Tactility/TactilityConfig.h>
|
||||
|
||||
#include <Tactility/app/AppManifestParsing.h>
|
||||
#include <Tactility/app/AppRegistration.h>
|
||||
#include <Tactility/CpuAffinity.h>
|
||||
#include <Tactility/DispatcherThread.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <Tactility/file/FileLock.h>
|
||||
@@ -19,14 +23,12 @@
|
||||
#include <Tactility/network/NtpPrivate.h>
|
||||
#include <Tactility/service/ServiceManifest.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
#include <Tactility/service/loader/Loader.h>
|
||||
#include <Tactility/settings/TimePrivate.h>
|
||||
|
||||
#include <tactility/concurrent/thread.h>
|
||||
#include <tactility/kernel_init.h>
|
||||
#include <tactility/hal_device_module.h>
|
||||
|
||||
#include <map>
|
||||
#include <format>
|
||||
#include <tactility/lvgl_module.h>
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <Tactility/InitEsp.h>
|
||||
@@ -336,8 +338,9 @@ void run(const Configuration& config, Module* platformModule, Module* deviceModu
|
||||
return;
|
||||
}
|
||||
|
||||
// HAL compatibility module: it creates kernel driver wrappers for tt::hal::Device
|
||||
// Module parent
|
||||
check(module_parent_construct(&tactility_module_parent) == ERROR_NONE);
|
||||
// hal-device-module
|
||||
check(module_set_parent(&hal_device_module, &tactility_module_parent) == ERROR_NONE);
|
||||
check(module_start(&hal_device_module) == ERROR_NONE);
|
||||
|
||||
@@ -355,7 +358,22 @@ void run(const Configuration& config, Module* platformModule, Module* deviceModu
|
||||
network::ntp::init();
|
||||
|
||||
registerAndStartPrimaryServices();
|
||||
lvgl::init(hardware);
|
||||
|
||||
lvgl_module_configure((LvglModuleConfig) {
|
||||
.on_start = lvgl::attachDevices,
|
||||
.on_stop = lvgl::detachDevices,
|
||||
.task_priority = THREAD_PRIORITY_HIGHER,
|
||||
/** Minimum seems to be about 3500. In some scenarios, the WiFi app crashes at 8192,
|
||||
* so we now have 9120 to run in a stable manner. We should figure out a way to avoid this.
|
||||
* Perhaps we can give apps their own stack space and deal with lvgl callback handlers in a clever way. */
|
||||
.task_stack_size = 9120,
|
||||
#ifdef ESP_PLATFORM
|
||||
.task_affinity = getCpuAffinityConfiguration().graphics
|
||||
#endif
|
||||
});
|
||||
check(module_set_parent(&lvgl_module, &tactility_module_parent) == ERROR_NONE);
|
||||
lvgl::start();
|
||||
|
||||
registerAndStartSecondaryServices();
|
||||
|
||||
LOGGER.info("Core systems ready");
|
||||
@@ -371,7 +389,8 @@ void run(const Configuration& config, Module* platformModule, Module* deviceModu
|
||||
}
|
||||
}
|
||||
|
||||
const Configuration* _Nullable getConfiguration() {
|
||||
/** return the configuration or nullptr if it's not initialized */
|
||||
const Configuration* getConfiguration() {
|
||||
return config_instance;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace tt::app {
|
||||
|
||||
constexpr auto* TAG = "App";
|
||||
|
||||
LaunchId start(const std::string& id, std::shared_ptr<const Bundle> _Nullable parameters) {
|
||||
LaunchId start(const std::string& id, std::shared_ptr<const Bundle> parameters) {
|
||||
const auto service = service::loader::findLoaderService();
|
||||
assert(service != nullptr);
|
||||
return service->start(id, std::move(parameters));
|
||||
@@ -35,15 +35,15 @@ bool isRunning(const std::string& id) {
|
||||
return service->isRunning(id);
|
||||
}
|
||||
|
||||
std::shared_ptr<AppContext> _Nullable getCurrentAppContext() {
|
||||
std::shared_ptr<AppContext> getCurrentAppContext() {
|
||||
const auto service = service::loader::findLoaderService();
|
||||
assert(service != nullptr);
|
||||
return service->getCurrentAppContext();
|
||||
}
|
||||
|
||||
std::shared_ptr<App> _Nullable getCurrentApp() {
|
||||
std::shared_ptr<App> getCurrentApp() {
|
||||
const auto app_context = getCurrentAppContext();
|
||||
return (app_context != nullptr) ? app_context->getApp() : nullptr;
|
||||
return (app_context != nullptr) ? app_context->getApp() : nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ bool removeAppManifest(const std::string& id) {
|
||||
return app_manifest_map.erase(id) == 1;
|
||||
}
|
||||
|
||||
_Nullable std::shared_ptr<AppManifest> findAppManifestById(const std::string& id) {
|
||||
std::shared_ptr<AppManifest> findAppManifestById(const std::string& id) {
|
||||
hash_mutex.lock();
|
||||
auto result = app_manifest_map.find(id);
|
||||
hash_mutex.unlock();
|
||||
|
||||
@@ -34,13 +34,13 @@ class ElfApp final : public App {
|
||||
public:
|
||||
|
||||
struct Parameters {
|
||||
CreateData _Nullable createData = nullptr;
|
||||
DestroyData _Nullable destroyData = nullptr;
|
||||
OnCreate _Nullable onCreate = nullptr;
|
||||
OnDestroy _Nullable onDestroy = nullptr;
|
||||
OnShow _Nullable onShow = nullptr;
|
||||
OnHide _Nullable onHide = nullptr;
|
||||
OnResult _Nullable onResult = nullptr;
|
||||
CreateData createData = nullptr;
|
||||
DestroyData destroyData = nullptr;
|
||||
OnCreate onCreate = nullptr;
|
||||
OnDestroy onDestroy = nullptr;
|
||||
OnShow onShow = nullptr;
|
||||
OnHide onHide = nullptr;
|
||||
OnResult onResult = nullptr;
|
||||
};
|
||||
|
||||
static void setParameters(const Parameters& parameters) {
|
||||
@@ -202,13 +202,13 @@ size_t ElfApp::staticParametersSetCount = 0;
|
||||
std::shared_ptr<Lock> ElfApp::staticParametersLock = std::make_shared<Mutex>();
|
||||
|
||||
void setElfAppParameters(
|
||||
CreateData _Nullable createData,
|
||||
DestroyData _Nullable destroyData,
|
||||
OnCreate _Nullable onCreate,
|
||||
OnDestroy _Nullable onDestroy,
|
||||
OnShow _Nullable onShow,
|
||||
OnHide _Nullable onHide,
|
||||
OnResult _Nullable onResult
|
||||
CreateData createData,
|
||||
DestroyData destroyData,
|
||||
OnCreate onCreate,
|
||||
OnDestroy onDestroy,
|
||||
OnShow onShow,
|
||||
OnHide onHide,
|
||||
OnResult onResult
|
||||
) {
|
||||
ElfApp::setParameters({
|
||||
.createData = createData,
|
||||
|
||||
@@ -30,7 +30,7 @@ class AppHubApp final : public App {
|
||||
std::vector<AppHubEntry> entries;
|
||||
Mutex mutex;
|
||||
|
||||
static std::shared_ptr<AppHubApp> _Nullable findAppInstance() {
|
||||
static std::shared_ptr<AppHubApp> findAppInstance() {
|
||||
auto app_context = getCurrentAppContext();
|
||||
if (app_context->getManifest().appId != manifest.appId) {
|
||||
return nullptr;
|
||||
|
||||
@@ -71,7 +71,7 @@ public:
|
||||
};
|
||||
|
||||
/** Returns the app data if the app is active. Note that this could clash if the same app is started twice and a background thread is slow. */
|
||||
std::shared_ptr<I2cScannerApp> _Nullable optApp() {
|
||||
std::shared_ptr<I2cScannerApp> optApp() {
|
||||
auto appContext = getCurrentAppContext();
|
||||
if (appContext != nullptr && appContext->getManifest().appId == manifest.appId) {
|
||||
return std::static_pointer_cast<I2cScannerApp>(appContext->getApp());
|
||||
|
||||
@@ -20,7 +20,7 @@ extern const AppManifest manifest;
|
||||
class PowerApp;
|
||||
|
||||
/** Returns the app data if the app is active. Note that this could clash if the same app is started twice and a background thread is slow. */
|
||||
std::shared_ptr<PowerApp> _Nullable optApp() {
|
||||
std::shared_ptr<PowerApp> optApp() {
|
||||
auto appContext = getCurrentAppContext();
|
||||
if (appContext != nullptr && appContext->getManifest().appId == manifest.appId) {
|
||||
return std::static_pointer_cast<PowerApp>(appContext->getApp());
|
||||
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
|
||||
|
||||
/** Returns the app data if the app is active. Note that this could clash if the same app is started twice and a background thread is slow. */
|
||||
std::shared_ptr<ScreenshotApp> _Nullable optApp() {
|
||||
std::shared_ptr<ScreenshotApp> optApp() {
|
||||
auto appContext = getCurrentAppContext();
|
||||
if (appContext != nullptr && appContext->getManifest().appId == manifest.appId) {
|
||||
return std::static_pointer_cast<ScreenshotApp>(appContext->getApp());
|
||||
|
||||
@@ -274,7 +274,7 @@ extern const AppManifest manifest;
|
||||
|
||||
class SystemInfoApp;
|
||||
|
||||
static std::shared_ptr<SystemInfoApp> _Nullable optApp() {
|
||||
static std::shared_ptr<SystemInfoApp> optApp() {
|
||||
auto appContext = getCurrentAppContext();
|
||||
if (appContext != nullptr && appContext->getManifest().appId == manifest.appId) {
|
||||
return std::static_pointer_cast<SystemInfoApp>(appContext->getApp());
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace tt::app::wifimanage {
|
||||
|
||||
static const auto LOGGER = Logger("WifiManageView");
|
||||
|
||||
std::shared_ptr<WifiManage> _Nullable optWifiManage();
|
||||
std::shared_ptr<WifiManage> optWifiManage();
|
||||
|
||||
static uint8_t mapRssiToPercentage(int rssi) {
|
||||
auto abs_rssi = std::abs(rssi);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
namespace tt::file {
|
||||
|
||||
std::shared_ptr<Lock> _Nullable findLock(const std::string& path) {
|
||||
std::shared_ptr<Lock> findLock(const std::string& path) {
|
||||
return hal::sdcard::findSdCardLock(path);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
namespace tt::hal::sdcard {
|
||||
|
||||
std::shared_ptr<SdCardDevice> _Nullable find(const std::string& path) {
|
||||
std::shared_ptr<SdCardDevice> find(const std::string& path) {
|
||||
auto sdcards = findDevices<SdCardDevice>(Device::Type::SdCard);
|
||||
for (auto& sdcard : sdcards) {
|
||||
if (sdcard->isMounted() && path.starts_with(sdcard->getMountPath())) {
|
||||
|
||||
@@ -20,7 +20,7 @@ struct BootModeData {
|
||||
static Mode currentMode = Mode::Default;
|
||||
static RTC_NOINIT_ATTR BootModeData bootModeData;
|
||||
|
||||
sdmmc_card_t* _Nullable getCard() {
|
||||
sdmmc_card_t* getCard() {
|
||||
auto sdcards = findDevices<sdcard::SpiSdCardDevice>(Device::Type::SdCard);
|
||||
|
||||
std::shared_ptr<sdcard::SpiSdCardDevice> usable_sdcard;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
static const auto LOGGER = tt::Logger("USB");
|
||||
|
||||
namespace tt::hal::usb {
|
||||
extern sdmmc_card_t* _Nullable getCard();
|
||||
extern sdmmc_card_t* getCard();
|
||||
}
|
||||
|
||||
enum {
|
||||
|
||||
@@ -34,10 +34,6 @@ static const char* getEventName(SystemEvent event) {
|
||||
return TT_STRINGIFY(NetworkConnected);
|
||||
case NetworkDisconnected:
|
||||
return TT_STRINGIFY(NetworkDisconnected);
|
||||
case LvglStarted:
|
||||
return TT_STRINGIFY(LvglStarted);
|
||||
case LvglStopped:
|
||||
return TT_STRINGIFY(LvglStopped);
|
||||
case Time:
|
||||
return TT_STRINGIFY(Time);
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
#include <Tactility/Thread.h>
|
||||
#include <Tactility/CpuAffinity.h>
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/Mutex.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
|
||||
#include <esp_lvgl_port.h>
|
||||
|
||||
namespace tt::lvgl {
|
||||
|
||||
// LVGL
|
||||
// The minimum task stack seems to be about 3500, but that crashes the wifi app in some scenarios
|
||||
// At 8192, it sometimes crashes when wifi-auto enables and is busy connecting and then you open WifiManage
|
||||
constexpr auto LVGL_TASK_STACK_DEPTH = 9216;
|
||||
|
||||
static const auto LOGGER = Logger("EspLvglPort");
|
||||
|
||||
bool initEspLvglPort() {
|
||||
LOGGER.debug("Init");
|
||||
const lvgl_port_cfg_t lvgl_cfg = {
|
||||
.task_priority = static_cast<UBaseType_t>(Thread::Priority::Critical),
|
||||
.task_stack = LVGL_TASK_STACK_DEPTH,
|
||||
.task_affinity = getCpuAffinityConfiguration().graphics,
|
||||
.task_max_sleep_ms = 500,
|
||||
.timer_period_ms = 5
|
||||
};
|
||||
|
||||
if (lvgl_port_init(&lvgl_cfg) != ESP_OK) {
|
||||
LOGGER.error("Init failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
syncSet(&lvgl_port_lock, &lvgl_port_unlock);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace tt::lvgl
|
||||
|
||||
#endif
|
||||
@@ -7,47 +7,24 @@
|
||||
#include <Tactility/lvgl/Keyboard.h>
|
||||
#include <Tactility/lvgl/Lvgl.h>
|
||||
#include <Tactility/lvgl/LvglSync.h>
|
||||
#include <Tactility/kernel/SystemEvents.h>
|
||||
#include <Tactility/service/ServiceRegistration.h>
|
||||
#include <Tactility/settings/DisplaySettings.h>
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <Tactility/lvgl/EspLvglPort.h>
|
||||
#endif
|
||||
#include <tactility/lvgl_module.h>
|
||||
#include <tactility/module.h>
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
namespace tt::lvgl {
|
||||
|
||||
static const auto LOGGER = Logger("Lvgl");
|
||||
|
||||
static bool started = false;
|
||||
|
||||
void init(const hal::Configuration& config) {
|
||||
LOGGER.info("Init started");
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
if (config.lvglInit == hal::LvglInit::Default && !initEspLvglPort()) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
start();
|
||||
|
||||
LOGGER.info("Init finished");
|
||||
}
|
||||
static const auto LOGGER = Logger("LVGL");
|
||||
|
||||
bool isStarted() {
|
||||
return started;
|
||||
return module_is_started(&lvgl_module);
|
||||
}
|
||||
|
||||
void start() {
|
||||
LOGGER.info("Start LVGL");
|
||||
|
||||
if (started) {
|
||||
LOGGER.warn("Can't start LVGL twice");
|
||||
return;
|
||||
}
|
||||
void attachDevices() {
|
||||
LOGGER.info("Adding devices");
|
||||
|
||||
auto lock = getSyncLock()->asScopedLock();
|
||||
lock.lock();
|
||||
@@ -56,7 +33,7 @@ void start() {
|
||||
|
||||
LOGGER.info("Start displays");
|
||||
auto displays = hal::findDevices<hal::display::DisplayDevice>(hal::Device::Type::Display);
|
||||
for (const auto& display : displays) {
|
||||
for (const auto& display: displays) {
|
||||
if (display->supportsLvgl()) {
|
||||
if (display->startLvgl()) {
|
||||
LOGGER.info("Started {}", display->getName());
|
||||
@@ -82,7 +59,7 @@ void start() {
|
||||
if (primary_display != nullptr) {
|
||||
LOGGER.info("Start touch devices");
|
||||
auto touch_devices = hal::findDevices<hal::touch::TouchDevice>(hal::Device::Type::Touch);
|
||||
for (const auto& touch_device : touch_devices) {
|
||||
for (const auto& touch_device: touch_devices) {
|
||||
// Start any touch devices that haven't been started yet
|
||||
if (touch_device->supportsLvgl() && touch_device->getLvglIndev() == nullptr) {
|
||||
if (touch_device->startLvgl(primary_display->getLvglDisplay())) {
|
||||
@@ -96,7 +73,7 @@ void start() {
|
||||
// Start keyboards
|
||||
LOGGER.info("Start keyboards");
|
||||
auto keyboards = hal::findDevices<hal::keyboard::KeyboardDevice>(hal::Device::Type::Keyboard);
|
||||
for (const auto& keyboard : keyboards) {
|
||||
for (const auto& keyboard: keyboards) {
|
||||
if (keyboard->isAttached()) {
|
||||
if (keyboard->startLvgl(primary_display->getLvglDisplay())) {
|
||||
lv_indev_t* keyboard_indev = keyboard->getLvglIndev();
|
||||
@@ -111,7 +88,7 @@ void start() {
|
||||
// Start encoders
|
||||
LOGGER.info("Start encoders");
|
||||
auto encoders = hal::findDevices<hal::encoder::EncoderDevice>(hal::Device::Type::Encoder);
|
||||
for (const auto& encoder : encoders) {
|
||||
for (const auto& encoder: encoders) {
|
||||
if (encoder->startLvgl(primary_display->getLvglDisplay())) {
|
||||
LOGGER.info("Started {}", encoder->getName());
|
||||
} else {
|
||||
@@ -141,21 +118,10 @@ void start() {
|
||||
LOGGER.error("Statusbar service is not in Stopped state");
|
||||
}
|
||||
}
|
||||
|
||||
// Finalize
|
||||
|
||||
kernel::publishSystemEvent(kernel::SystemEvent::LvglStarted);
|
||||
|
||||
started = true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
LOGGER.info("Stopping LVGL");
|
||||
|
||||
if (!started) {
|
||||
LOGGER.warn("Can't stop LVGL: not started");
|
||||
return;
|
||||
}
|
||||
void detachDevices() {
|
||||
LOGGER.info("Removing devices");
|
||||
|
||||
auto lock = getSyncLock()->asScopedLock();
|
||||
lock.lock();
|
||||
@@ -169,7 +135,7 @@ void stop() {
|
||||
|
||||
LOGGER.info("Stopping keyboards");
|
||||
auto keyboards = hal::findDevices<hal::keyboard::KeyboardDevice>(hal::Device::Type::Keyboard);
|
||||
for (auto keyboard : keyboards) {
|
||||
for (auto keyboard: keyboards) {
|
||||
if (keyboard->getLvglIndev() != nullptr) {
|
||||
keyboard->stopLvgl();
|
||||
}
|
||||
@@ -180,7 +146,7 @@ void stop() {
|
||||
LOGGER.info("Stopping touch");
|
||||
// The display generally stops their own touch devices, but we'll clean up anything that didn't
|
||||
auto touch_devices = hal::findDevices<hal::touch::TouchDevice>(hal::Device::Type::Touch);
|
||||
for (auto touch_device : touch_devices) {
|
||||
for (auto touch_device: touch_devices) {
|
||||
if (touch_device->getLvglIndev() != nullptr) {
|
||||
touch_device->stopLvgl();
|
||||
}
|
||||
@@ -191,7 +157,7 @@ void stop() {
|
||||
LOGGER.info("Stopping encoders");
|
||||
// The display generally stops their own touch devices, but we'll clean up anything that didn't
|
||||
auto encoder_devices = hal::findDevices<hal::encoder::EncoderDevice>(hal::Device::Type::Encoder);
|
||||
for (auto encoder_device : encoder_devices) {
|
||||
for (auto encoder_device: encoder_devices) {
|
||||
if (encoder_device->getLvglIndev() != nullptr) {
|
||||
encoder_device->stopLvgl();
|
||||
}
|
||||
@@ -200,17 +166,19 @@ void stop() {
|
||||
|
||||
LOGGER.info("Stopping displays");
|
||||
auto displays = hal::findDevices<hal::display::DisplayDevice>(hal::Device::Type::Display);
|
||||
for (auto display : displays) {
|
||||
for (auto display: displays) {
|
||||
if (display->supportsLvgl() && display->getLvglDisplay() != nullptr && !display->stopLvgl()) {
|
||||
LOGGER.error("Failed to detach display from LVGL");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
started = false;
|
||||
void start() {
|
||||
check(module_start(&lvgl_module) == ERROR_NONE);
|
||||
}
|
||||
|
||||
kernel::publishSystemEvent(kernel::SystemEvent::LvglStopped);
|
||||
|
||||
LOGGER.info("Stopped LVGL");
|
||||
void stop() {
|
||||
check(module_stop(&lvgl_module) == ERROR_NONE);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -1,39 +1,16 @@
|
||||
#include "Tactility/lvgl/LvglSync.h"
|
||||
|
||||
#include <Tactility/Mutex.h>
|
||||
#include <tactility/lvgl_module.h>
|
||||
|
||||
namespace tt::lvgl {
|
||||
|
||||
static Mutex lockMutex;
|
||||
|
||||
static bool defaultLock(uint32_t timeoutMillis) {
|
||||
return lockMutex.lock(timeoutMillis);
|
||||
}
|
||||
|
||||
static void defaultUnlock() {
|
||||
lockMutex.unlock();
|
||||
}
|
||||
|
||||
static LvglLock lock_singleton = defaultLock;
|
||||
static LvglUnlock unlock_singleton = defaultUnlock;
|
||||
|
||||
void syncSet(LvglLock lock, LvglUnlock unlock) {
|
||||
auto old_lock = lock_singleton;
|
||||
auto old_unlock = unlock_singleton;
|
||||
|
||||
// Ensure the old lock is not engaged when changing locks
|
||||
old_lock((uint32_t)kernel::MAX_TICKS);
|
||||
lock_singleton = lock;
|
||||
unlock_singleton = unlock;
|
||||
old_unlock();
|
||||
}
|
||||
|
||||
bool lock(TickType_t timeout) {
|
||||
return lock_singleton(pdMS_TO_TICKS(timeout == 0 ? kernel::MAX_TICKS : timeout));
|
||||
return lvgl_try_lock_timed(timeout);
|
||||
}
|
||||
|
||||
void unlock() {
|
||||
unlock_singleton();
|
||||
lvgl_unlock();
|
||||
}
|
||||
|
||||
class LvglSync : public Lock {
|
||||
@@ -41,11 +18,11 @@ public:
|
||||
~LvglSync() override = default;
|
||||
|
||||
bool lock(TickType_t timeoutTicks) const override {
|
||||
return lvgl::lock(timeoutTicks);
|
||||
return lvgl_try_lock_timed(timeoutTicks);
|
||||
}
|
||||
|
||||
void unlock() const override {
|
||||
lvgl::unlock();
|
||||
lvgl_unlock();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ void addService(const ServiceManifest& manifest, bool autoStart) {
|
||||
addService(std::make_shared<const ServiceManifest>(manifest), autoStart);
|
||||
}
|
||||
|
||||
std::shared_ptr<const ServiceManifest> _Nullable findManifestById(const std::string& id) {
|
||||
std::shared_ptr<const ServiceManifest> findManifestById(const std::string& id) {
|
||||
manifest_mutex.lock();
|
||||
auto iterator = service_manifest_map.find(id);
|
||||
auto manifest = iterator != service_manifest_map.end() ? iterator->second : nullptr;
|
||||
@@ -52,7 +52,7 @@ std::shared_ptr<const ServiceManifest> _Nullable findManifestById(const std::str
|
||||
return manifest;
|
||||
}
|
||||
|
||||
static std::shared_ptr<ServiceInstance> _Nullable findServiceInstanceById(const std::string& id) {
|
||||
static std::shared_ptr<ServiceInstance> findServiceInstanceById(const std::string& id) {
|
||||
manifest_mutex.lock();
|
||||
auto iterator = service_instance_map.find(id);
|
||||
auto service = iterator != service_instance_map.end() ? iterator->second : nullptr;
|
||||
@@ -92,11 +92,11 @@ bool startService(const std::string& id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<ServiceContext> _Nullable findServiceContextById(const std::string& id) {
|
||||
std::shared_ptr<ServiceContext> findServiceContextById(const std::string& id) {
|
||||
return findServiceInstanceById(id);
|
||||
}
|
||||
|
||||
std::shared_ptr<Service> _Nullable findServiceById(const std::string& id) {
|
||||
std::shared_ptr<Service> findServiceById(const std::string& id) {
|
||||
auto instance = findServiceInstanceById(id);
|
||||
return instance != nullptr ? instance->getService() : nullptr;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ constexpr bool hasTimeElapsed(TickType_t now, TickType_t timeInThePast, TickType
|
||||
return (now - timeInThePast) >= expireTimeInTicks;
|
||||
}
|
||||
|
||||
GpsService::GpsDeviceRecord* _Nullable GpsService::findGpsRecord(const std::shared_ptr<GpsDevice>& device) {
|
||||
GpsService::GpsDeviceRecord* GpsService::findGpsRecord(const std::shared_ptr<GpsDevice>& device) {
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
|
||||
@@ -40,6 +40,47 @@ void GuiService::onLoaderEvent(LoaderService::Event event) {
|
||||
int32_t GuiService::guiMain() {
|
||||
auto service = findServiceById<GuiService>(manifest.id);
|
||||
|
||||
if (!lvgl::lock(5000)) {
|
||||
LOGGER.error("LVGL guiMain start failed as LVGL couldn't be locked");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// The screen root is created in the main task instead of during onStart because
|
||||
// it allows onStart() to succeed faster and allows widget creation to happen in the background
|
||||
|
||||
auto* screen_root = lv_screen_active();
|
||||
if (screen_root == nullptr) {
|
||||
LOGGER.error("No display found, exiting GUI task");
|
||||
lvgl::unlock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
service->keyboardGroup = lv_group_create();
|
||||
lv_obj_set_style_border_width(screen_root, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_pad_all(screen_root, 0, LV_STATE_DEFAULT);
|
||||
|
||||
lv_obj_t* vertical_container = lv_obj_create(screen_root);
|
||||
lv_obj_set_size(vertical_container, LV_PCT(100), LV_PCT(100));
|
||||
lv_obj_set_flex_flow(vertical_container, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_style_pad_all(vertical_container, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_pad_gap(vertical_container, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_bg_color(vertical_container, lv_color_black(), LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_border_width(vertical_container, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_radius(vertical_container, 0, LV_STATE_DEFAULT);
|
||||
|
||||
service->statusbarWidget = lvgl::statusbar_create(vertical_container);
|
||||
|
||||
auto* app_container = lv_obj_create(vertical_container);
|
||||
lv_obj_set_style_pad_all(app_container, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_border_width(app_container, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_width(app_container, LV_PCT(100));
|
||||
lv_obj_set_flex_grow(app_container, 1);
|
||||
lv_obj_set_flex_flow(app_container, LV_FLEX_FLOW_COLUMN);
|
||||
|
||||
service->appRootWidget = app_container;
|
||||
|
||||
lvgl::unlock();
|
||||
|
||||
while (true) {
|
||||
uint32_t flags = 0;
|
||||
if (service->threadFlags.wait(GUI_THREAD_FLAG_ALL, false, true, &flags, portMAX_DELAY)) {
|
||||
@@ -62,6 +103,9 @@ int32_t GuiService::guiMain() {
|
||||
}
|
||||
}
|
||||
|
||||
service->appRootWidget = nullptr;
|
||||
service->statusbarWidget = nullptr;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -87,6 +131,12 @@ void GuiService::redraw() {
|
||||
// Lock GUI and LVGL
|
||||
lock();
|
||||
|
||||
if (appRootWidget == nullptr) {
|
||||
LOGGER.warn("No root widget");
|
||||
unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
if (lvgl::lock(1000)) {
|
||||
lv_obj_clean(appRootWidget);
|
||||
|
||||
@@ -113,7 +163,7 @@ void GuiService::redraw() {
|
||||
lv_obj_t* container = createAppViews(appRootWidget);
|
||||
appToRender->getApp()->onShow(*appToRender, container);
|
||||
} else {
|
||||
LOGGER.warn("nothing to draw");
|
||||
LOGGER.warn("Nothing to draw");
|
||||
}
|
||||
|
||||
// Unlock GUI and LVGL
|
||||
@@ -126,18 +176,11 @@ void GuiService::redraw() {
|
||||
}
|
||||
|
||||
bool GuiService::onStart(ServiceContext& service) {
|
||||
auto* screen_root = lv_screen_active();
|
||||
if (screen_root == nullptr) {
|
||||
LOGGER.error("No display found");
|
||||
return false;
|
||||
}
|
||||
|
||||
thread = new Thread(
|
||||
GUI_TASK_NAME,
|
||||
4096, // Last known minimum was 2800 for launching desktop
|
||||
[]() { return guiMain(); }
|
||||
guiMain
|
||||
);
|
||||
|
||||
thread->setPriority(THREAD_PRIORITY_SERVICE);
|
||||
|
||||
const auto loader = findLoaderService();
|
||||
@@ -146,37 +189,8 @@ bool GuiService::onStart(ServiceContext& service) {
|
||||
onLoaderEvent(event);
|
||||
});
|
||||
|
||||
lvgl::lock(portMAX_DELAY);
|
||||
|
||||
keyboardGroup = lv_group_create();
|
||||
lv_obj_set_style_border_width(screen_root, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_pad_all(screen_root, 0, LV_STATE_DEFAULT);
|
||||
|
||||
lv_obj_t* vertical_container = lv_obj_create(screen_root);
|
||||
lv_obj_set_size(vertical_container, LV_PCT(100), LV_PCT(100));
|
||||
lv_obj_set_flex_flow(vertical_container, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_style_pad_all(vertical_container, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_pad_gap(vertical_container, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_bg_color(vertical_container, lv_color_black(), LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_border_width(vertical_container, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_radius(vertical_container, 0, LV_STATE_DEFAULT);
|
||||
|
||||
statusbarWidget = lvgl::statusbar_create(vertical_container);
|
||||
|
||||
auto* app_container = lv_obj_create(vertical_container);
|
||||
lv_obj_set_style_pad_all(app_container, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_border_width(app_container, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_width(app_container, LV_PCT(100));
|
||||
lv_obj_set_flex_grow(app_container, 1);
|
||||
lv_obj_set_flex_flow(app_container, LV_FLEX_FLOW_COLUMN);
|
||||
|
||||
appRootWidget = app_container;
|
||||
|
||||
lvgl::unlock();
|
||||
|
||||
isStarted = true;
|
||||
|
||||
thread->setPriority(THREAD_PRIORITY_SERVICE);
|
||||
thread->start();
|
||||
|
||||
return true;
|
||||
@@ -192,20 +206,24 @@ void GuiService::onStop(ServiceContext& service) {
|
||||
appToRender = nullptr;
|
||||
isStarted = false;
|
||||
|
||||
auto task_handle = thread->getTaskHandle();
|
||||
threadFlags.set(GUI_THREAD_FLAG_EXIT);
|
||||
thread->join();
|
||||
delete thread;
|
||||
|
||||
unlock();
|
||||
thread->join();
|
||||
|
||||
check(lvgl::lock(1000 / portTICK_PERIOD_MS));
|
||||
lv_group_delete(keyboardGroup);
|
||||
lvgl::unlock();
|
||||
if (lvgl::lock()) {
|
||||
if (keyboardGroup != nullptr) {
|
||||
lv_group_delete(keyboardGroup);
|
||||
keyboardGroup = nullptr;
|
||||
}
|
||||
lvgl::unlock();
|
||||
} else {
|
||||
LOGGER.error("Failed to lock LVGL during GUI stop");
|
||||
}
|
||||
|
||||
delete thread;
|
||||
}
|
||||
|
||||
void GuiService::requestDraw() {
|
||||
auto task_handle = thread->getTaskHandle();
|
||||
threadFlags.set(GUI_THREAD_FLAG_DRAW);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
namespace tt::service::loader {
|
||||
|
||||
static const auto LOGGER = Logger("Boot");
|
||||
static const auto LOGGER = Logger("Loader");
|
||||
|
||||
constexpr auto LOADER_TIMEOUT = (100 / portTICK_PERIOD_MS);
|
||||
|
||||
@@ -297,7 +297,7 @@ void LoaderService::stopAll(const std::string& id) {
|
||||
});
|
||||
}
|
||||
|
||||
std::shared_ptr<app::AppContext> _Nullable LoaderService::getCurrentAppContext() {
|
||||
std::shared_ptr<app::AppContext> LoaderService::getCurrentAppContext() {
|
||||
const auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
if (appStack.empty()) {
|
||||
@@ -318,7 +318,7 @@ bool LoaderService::isRunning(const std::string& id) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<LoaderService> _Nullable findLoaderService() {
|
||||
std::shared_ptr<LoaderService> findLoaderService() {
|
||||
return service::findServiceById<LoaderService>(manifest.id);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ static const auto LOGGER = Logger("ScreenshotService");
|
||||
|
||||
extern const ServiceManifest manifest;
|
||||
|
||||
std::shared_ptr<ScreenshotService> _Nullable optScreenshotService() {
|
||||
std::shared_ptr<ScreenshotService> optScreenshotService() {
|
||||
return service::findServiceById<ScreenshotService>(manifest.id);
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ static const char* getSdCardStatusIcon(hal::sdcard::SdCardDevice::State state) {
|
||||
}
|
||||
}
|
||||
|
||||
static _Nullable const char* getPowerStatusIcon() {
|
||||
static const char* getPowerStatusIcon() {
|
||||
// TODO: Support multiple power devices?
|
||||
std::shared_ptr<hal::power::PowerDevice> power;
|
||||
hal::findDevices<hal::power::PowerDevice>(hal::Device::Type::Power, [&power](const auto& device) {
|
||||
|
||||
@@ -62,9 +62,9 @@ public:
|
||||
// for example: when scanning and you turn off the radio, the scan should probably stop or turning off
|
||||
// the radio should disable the on/off button in the app as it is pending.
|
||||
/** @brief The network interface when wifi is started */
|
||||
esp_netif_t* _Nullable netif = nullptr;
|
||||
esp_netif_t* netif = nullptr;
|
||||
/** @brief Scanning results */
|
||||
wifi_ap_record_t* _Nullable scan_list = nullptr;
|
||||
wifi_ap_record_t* scan_list = nullptr;
|
||||
/** @brief The current item count in scan_list (-1 when scan_list is NULL) */
|
||||
uint16_t scan_list_count = 0;
|
||||
/** @brief Maximum amount of records to scan (value > 0) */
|
||||
|
||||
Reference in New Issue
Block a user