Merge develop into main (#321)

- Implemented `TouchDriver` for `Xpt2046SoftSpi`
- Refactored system initialization
This commit is contained in:
Ken Van Hoeylandt
2025-09-06 17:17:39 +02:00
committed by GitHub
parent 65335578a4
commit 457c21ffd8
9 changed files with 208 additions and 176 deletions
+2 -1
View File
@@ -9,7 +9,7 @@
namespace tt {
static const char* TAG = "Partitions";
constexpr auto* TAG = "Partitions";
static esp_err_t initNvsFlashSafely() {
esp_err_t result = nvs_flash_init();
@@ -37,6 +37,7 @@ size_t getSectorSize() {
}
esp_err_t initPartitionsEsp() {
TT_LOG_I(TAG, "Init partitions");
ESP_ERROR_CHECK(initNvsFlashSafely());
const esp_vfs_fat_mount_config_t mount_config = {
+5 -7
View File
@@ -186,7 +186,7 @@ void initFromBootApp() {
}
void run(const Configuration& config) {
TT_LOG_D(TAG, "run");
TT_LOG_I(TAG, "Tactility v%s on %s (%s)", TT_VERSION, CONFIG_TT_BOARD_NAME, CONFIG_TT_BOARD_ID);
assert(config.hardware);
const hal::Configuration& hardware = *config.hardware;
@@ -194,27 +194,25 @@ void run(const Configuration& config) {
// Assign early so starting services can use it
config_instance = &config;
TT_LOG_I(TAG, "Tactility v%s on %s (%s)", TT_VERSION, CONFIG_TT_BOARD_NAME, CONFIG_TT_BOARD_ID);
#ifdef ESP_PLATFORM
initEsp();
#endif
settings::initTimeZone();
hal::init(*config.hardware);
hal::sdcard::mountAll();
network::ntp::init();
registerAndStartPrimaryServices();
lvgl::init(hardware);
registerAndStartSecondaryServices();
TT_LOG_I(TAG, "starting boot app");
TT_LOG_I(TAG, "Core systems ready");
TT_LOG_I(TAG, "Starting boot app");
// The boot app takes care of registering system apps, user services and user apps
addApp(app::boot::manifest);
service::loader::startApp(app::boot::manifest.id);
TT_LOG_I(TAG, "init complete");
TT_LOG_I(TAG, "Processing main dispatcher");
TT_LOG_I(TAG, "Main dispatcher ready");
while (true) {
mainDispatcher.consume();
}
+4 -3
View File
@@ -9,21 +9,22 @@
namespace tt {
#define TAG "tactility"
constexpr auto* TAG = "Tactility";
// Initialize NVS
static void initNvs() {
TT_LOG_I(TAG, "Init NVS");
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
TT_LOG_I(TAG, "nvs erasing");
TT_LOG_I(TAG, "NVS erasing");
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
TT_LOG_I(TAG, "nvs initialized");
}
static void initNetwork() {
TT_LOG_I(TAG, "Init network");
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
}
+35
View File
@@ -8,6 +8,7 @@
#include "Tactility/hal/uart/UartInit.h"
#include <Tactility/hal/display/DisplayDevice.h>
#include <Tactility/hal/sdcard/SdCardMounting.h>
#include <Tactility/hal/touch/TouchDevice.h>
#include <Tactility/kernel/SystemEvents.h>
@@ -34,6 +35,13 @@ void registerDevices(const Configuration& configuration) {
}
}
if (configuration.createDisplay != nullptr) {
auto display = configuration.createDisplay();
if (display != nullptr) {
registerDevice(display);
}
}
auto devices = configuration.createDevices();
for (auto& device : devices) {
registerDevice(device);
@@ -50,6 +58,29 @@ void registerDevices(const Configuration& configuration) {
}
}
static void startDisplays() {
TT_LOG_I(TAG, "Start displays");
auto displays = hal::findDevices<display::DisplayDevice>(Device::Type::Display);
for (auto& display : displays) {
if (!display->start()) {
TT_LOG_E(TAG, "Display start failed");
} else {
TT_LOG_I(TAG, "Started %s", display->getName().c_str());
if (display->supportsBacklightDuty()) {
display->setBacklightDuty(0);
}
auto touch = display->getTouchDevice();
if (touch != nullptr && !touch->start()) {
TT_LOG_E(TAG, "Touch start failed");
} else {
TT_LOG_I(TAG, "Started %s", touch->getName().c_str());
}
}
}
}
void init(const Configuration& configuration) {
kernel::publishSystemEvent(kernel::SystemEvent::BootInitHalBegin);
@@ -72,6 +103,10 @@ void init(const Configuration& configuration) {
registerDevices(configuration);
sdcard::mountAll(); // Warning: This needs to happen BEFORE displays are initialized on the SPI bus
startDisplays(); // Warning: SPI displays need to start after SPI SD cards are mounted
kernel::publishSystemEvent(kernel::SystemEvent::BootInitHalEnd);
}
+19 -56
View File
@@ -22,35 +22,6 @@ constexpr auto* TAG = "Lvgl";
static bool started = false;
// TODO: Move to hal init
static void initDisplays(const hal::Configuration& config) {
TT_LOG_I(TAG, "Init displays");
if (config.createDisplay != nullptr) {
auto display = config.createDisplay();
if (display != nullptr) {
hal::registerDevice(display);
}
}
TT_LOG_I(TAG, "Start displays");
auto displays = hal::findDevices<hal::display::DisplayDevice>(hal::Device::Type::Display);
for (auto& display : displays) {
if (!display->start()) {
TT_LOG_E(TAG, "Display start failed");
}
if (display->supportsBacklightDuty()) {
display->setBacklightDuty(0);
}
auto touch = display->getTouchDevice();
if (touch != nullptr) {
hal::registerDevice(touch);
touch->start();
}
}
}
void init(const hal::Configuration& config) {
TT_LOG_I(TAG, "Init started");
@@ -60,8 +31,6 @@ void init(const hal::Configuration& config) {
}
#endif
initDisplays(config);
start();
TT_LOG_I(TAG, "Init finished");
@@ -105,32 +74,30 @@ void start() {
// Start touch
TT_LOG_I(TAG, "Start touch devices");
auto touch_devices = hal::findDevices<hal::touch::TouchDevice>(hal::Device::Type::Touch);
for (auto touch_device : touch_devices) {
if (displays.size() > 0) {
// TODO: Consider implementing support for multiple displays
auto display = displays[0];
// TODO: Consider implementing support for multiple displays
auto primary_display = !displays.empty() ? displays[0] : nullptr;
// Start display-related peripherals
if (primary_display != nullptr) {
TT_LOG_I(TAG, "Start touch devices");
auto touch_devices = hal::findDevices<hal::touch::TouchDevice>(hal::Device::Type::Touch);
for (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(display->getLvglDisplay())) {
if (touch_device->startLvgl(primary_display->getLvglDisplay())) {
TT_LOG_I(TAG, "Started %s", touch_device->getName().c_str());
} else {
TT_LOG_E(TAG, "Start failed for %s", touch_device->getName().c_str());
}
}
}
}
// Start keyboards
TT_LOG_I(TAG, "Start keyboards");
auto keyboards = hal::findDevices<hal::keyboard::KeyboardDevice>(hal::Device::Type::Keyboard);
for (auto keyboard : keyboards) {
if (displays.size() > 0) {
// TODO: Consider implementing support for multiple displays
auto display = displays[0];
// Start keyboards
TT_LOG_I(TAG, "Start keyboards");
auto keyboards = hal::findDevices<hal::keyboard::KeyboardDevice>(hal::Device::Type::Keyboard);
for (auto keyboard : keyboards) {
if (keyboard->isAttached()) {
if (keyboard->startLvgl(display->getLvglDisplay())) {
if (keyboard->startLvgl(primary_display->getLvglDisplay())) {
lv_indev_t* keyboard_indev = keyboard->getLvglIndev();
hardware_keyboard_set_indev(keyboard_indev);
TT_LOG_I(TAG, "Started %s", keyboard->getName().c_str());
@@ -139,16 +106,12 @@ void start() {
}
}
}
}
// Start encoders
TT_LOG_I(TAG, "Start encoders");
auto encoders = hal::findDevices<hal::encoder::EncoderDevice>(hal::Device::Type::Encoder);
for (auto encoder : encoders) {
if (displays.size() > 0) {
// TODO: Consider implementing support for multiple displays
auto display = displays[0];
if (encoder->startLvgl(display->getLvglDisplay())) {
// Start encoders
TT_LOG_I(TAG, "Start encoders");
auto encoders = hal::findDevices<hal::encoder::EncoderDevice>(hal::Device::Type::Encoder);
for (auto encoder : encoders) {
if (encoder->startLvgl(primary_display->getLvglDisplay())) {
TT_LOG_I(TAG, "Started %s", encoder->getName().c_str());
} else {
TT_LOG_E(TAG, "Start failed for %s", encoder->getName().c_str());