From b61a7a3f5f911da809333d38a3455d6202bafb70 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Tue, 28 Jul 2026 09:41:06 +0200 Subject: [PATCH] Use TactilityKernel's time and delay functions instead of TactilityFreeRtos ones --- Devices/lilygo-tdeck/source/module.cpp | 3 ++- .../source/drivers/unphone_nav_buttons.cpp | 5 +++-- Tactility/Source/SystemEvents.cpp | 5 +++-- .../Source/app/alertdialog/AlertDialog.cpp | 8 ++++---- Tactility/Source/app/boot/Boot.cpp | 18 ++++++++++-------- .../Source/app/gpssettings/GpsSettings.cpp | 3 ++- Tactility/Source/app/power/Power.cpp | 3 ++- Tactility/Source/app/systeminfo/SystemInfo.cpp | 15 +++++++++------ Tactility/Source/lvgl/Statusbar.cpp | 3 ++- .../Source/service/displayidle/DisplayIdle.cpp | 10 ++++++---- .../service/keyboardidle/KeyboardIdle.cpp | 5 +++-- .../service/screenshot/ScreenshotTask.cpp | 7 ++++--- Tactility/Source/service/wifi/Wifi.cpp | 8 ++++---- TactilityKernel/include/tactility/time.h | 2 ++ 14 files changed, 56 insertions(+), 39 deletions(-) diff --git a/Devices/lilygo-tdeck/source/module.cpp b/Devices/lilygo-tdeck/source/module.cpp index 5916a8447..9087099f1 100644 --- a/Devices/lilygo-tdeck/source/module.cpp +++ b/Devices/lilygo-tdeck/source/module.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -42,7 +43,7 @@ static error_t start() { } // Avoids crash when no SD card is inserted. It's unknown why, but likely is related to power draw. - tt::kernel::delayMillis(100); + delay_millis(100); subscribe_events(); diff --git a/Devices/unphone/source/drivers/unphone_nav_buttons.cpp b/Devices/unphone/source/drivers/unphone_nav_buttons.cpp index 7e3eefeab..26162dfa8 100644 --- a/Devices/unphone/source/drivers/unphone_nav_buttons.cpp +++ b/Devices/unphone/source/drivers/unphone_nav_buttons.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "unphone_nav_buttons.h" +#include #include #include #include @@ -76,9 +77,9 @@ static int32_t nav_buttons_thread_main(UnphoneNavButtonsInternal* internal) { // Debounce all events for a short period of time // This is easier than keeping track when each button was last pressed - tt::kernel::delayMillis(50); + delay_millis(50); xQueueReset(internal->event_queue); - tt::kernel::delayMillis(50); + delay_millis(50); xQueueReset(internal->event_queue); } } diff --git a/Tactility/Source/SystemEvents.cpp b/Tactility/Source/SystemEvents.cpp index 6a761bdd2..2f2834072 100644 --- a/Tactility/Source/SystemEvents.cpp +++ b/Tactility/Source/SystemEvents.cpp @@ -1,10 +1,11 @@ +#include +#include #include -#include #include #include +#include -#include #include namespace tt::kernel { diff --git a/Tactility/Source/app/alertdialog/AlertDialog.cpp b/Tactility/Source/app/alertdialog/AlertDialog.cpp index 7f1ac2609..656a73ea2 100644 --- a/Tactility/Source/app/alertdialog/AlertDialog.cpp +++ b/Tactility/Source/app/alertdialog/AlertDialog.cpp @@ -1,13 +1,13 @@ #include "Tactility/app/alertdialog/AlertDialog.h" -#include -#include "Tactility/service/loader/Loader.h" - +#include #include -#include #include +#include +#include + namespace tt::app::alertdialog { #define PARAMETER_BUNDLE_KEY_TITLE "title" diff --git a/Tactility/Source/app/boot/Boot.cpp b/Tactility/Source/app/boot/Boot.cpp index a713d6861..706266f9a 100644 --- a/Tactility/Source/app/boot/Boot.cpp +++ b/Tactility/Source/app/boot/Boot.cpp @@ -1,6 +1,8 @@ -#include "Tactility/lvgl/Lvgl.h" -#include "tactility/drivers/backlight.h" -#include "tactility/drivers/display.h" +#include +#include +#include +#include +#include #include #include @@ -10,13 +12,13 @@ #include #include #include +#include #include #include #include #include #include -#include #include @@ -108,23 +110,23 @@ class BootApp : public App { } static void waitForMinimalSplashDuration(TickType_t startTime) { - const auto end_time = kernel::getTicks(); + const auto end_time = get_ticks(); const auto ticks_passed = end_time - startTime; constexpr auto minimum_ticks = (CONFIG_TT_SPLASH_DURATION / portTICK_PERIOD_MS); if (minimum_ticks > ticks_passed) { - kernel::delayTicks(minimum_ticks - ticks_passed); + delay_ticks(minimum_ticks - ticks_passed); } } static int32_t bootThreadCallback() { LOG_I(TAG, "Starting boot thread"); - const auto start_time = kernel::getTicks(); + const auto start_time = get_ticks(); // Give the UI some time to redraw // If we don't do this, various init calls will read files and block SPI IO for the display // This would result in a blank/black screen being shown during this phase of the boot process // This works with 5 ms on a T-Lora Pager, so we give it 10 ms to be safe - kernel::delayMillis(10); + delay_millis(10); // TODO: Support for multiple displays LOG_I(TAG, "Setup display"); diff --git a/Tactility/Source/app/gpssettings/GpsSettings.cpp b/Tactility/Source/app/gpssettings/GpsSettings.cpp index e2af6a3af..98e725c38 100644 --- a/Tactility/Source/app/gpssettings/GpsSettings.cpp +++ b/Tactility/Source/app/gpssettings/GpsSettings.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -211,7 +212,7 @@ public: GpsSettingsApp() { // Runs while the screen is shown - there's no push notification for GPS device state // changes, so this is the only way this screen finds out about them. - timer = std::make_unique(Timer::Type::Periodic, kernel::secondsToTicks(1), [this] { + timer = std::make_unique(Timer::Type::Periodic, seconds_to_ticks(1), [this] { updateDeviceStates(); }); } diff --git a/Tactility/Source/app/power/Power.cpp b/Tactility/Source/app/power/Power.cpp index 09a863353..03708a6e3 100644 --- a/Tactility/Source/app/power/Power.cpp +++ b/Tactility/Source/app/power/Power.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -53,7 +54,7 @@ struct DeviceEntry { class PowerApp : public App { - Timer update_timer = Timer(Timer::Type::Periodic, kernel::millisToTicks(1000),[]() { onTimer(); }); + Timer update_timer = Timer(Timer::Type::Periodic, millis_to_ticks(1000),[]() { onTimer(); }); std::vector entries; diff --git a/Tactility/Source/app/systeminfo/SystemInfo.cpp b/Tactility/Source/app/systeminfo/SystemInfo.cpp index fabade818..564a7f057 100644 --- a/Tactility/Source/app/systeminfo/SystemInfo.cpp +++ b/Tactility/Source/app/systeminfo/SystemInfo.cpp @@ -1,8 +1,11 @@ -#include -#include -#include -#include +#include "tactility/time.h" + + #include +#include +#include +#include +#include #include #include @@ -242,7 +245,7 @@ static std::shared_ptr optApp() { } class SystemInfoApp final : public App { - Timer memoryTimer = Timer(Timer::Type::Periodic, kernel::millisToTicks(10000), [] { + Timer memoryTimer = Timer(Timer::Type::Periodic, millis_to_ticks(10000), [] { auto app = optApp(); if (app) { lvgl_lock(); @@ -251,7 +254,7 @@ class SystemInfoApp final : public App { } }); - Timer tasksTimer = Timer(Timer::Type::Periodic, kernel::millisToTicks(15000), [] { + Timer tasksTimer = Timer(Timer::Type::Periodic, millis_to_ticks(15000), [] { auto app = optApp(); if (app) { lvgl_lock(); diff --git a/Tactility/Source/lvgl/Statusbar.cpp b/Tactility/Source/lvgl/Statusbar.cpp index 0d964eecd..7d254129b 100644 --- a/Tactility/Source/lvgl/Statusbar.cpp +++ b/Tactility/Source/lvgl/Statusbar.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -182,7 +183,7 @@ lv_obj_t* statusbar_create(lv_obj_t* parent) { obj_set_style_bg_invisible(left_spacer); lv_obj_set_flex_grow(left_spacer, 1); - statusbar_data.mutex.lock(kernel::MAX_TICKS); + statusbar_data.mutex.lock(MAX_TICKS); for (int i = 0; i < STATUSBAR_ICON_LIMIT; ++i) { auto* image = lv_image_create(obj); lv_obj_set_size(image, icon_size, icon_size); // regular padding doesn't work diff --git a/Tactility/Source/service/displayidle/DisplayIdle.cpp b/Tactility/Source/service/displayidle/DisplayIdle.cpp index 3ef86869c..f25c0c4ac 100644 --- a/Tactility/Source/service/displayidle/DisplayIdle.cpp +++ b/Tactility/Source/service/displayidle/DisplayIdle.cpp @@ -1,6 +1,8 @@ #ifdef ESP_PLATFORM #include +#include +#include #include "BouncingBallsScreensaver.h" #include "MatrixRainScreensaver.h" @@ -8,14 +10,14 @@ #include "Screensaver.h" #include "StackChanScreensaver.h" -#include -#include #include #include +#include #include #include #include + #include namespace tt::service::displayidle { @@ -221,7 +223,7 @@ bool DisplayIdleService::onStart(ServiceContext& service) { cachedDisplaySettings = settings::display::loadOrGetDefault(); - timer = std::make_unique(Timer::Type::Periodic, kernel::millisToTicks(TICK_INTERVAL_MS), [this]{ this->tick(); }); + timer = std::make_unique(Timer::Type::Periodic, millis_to_ticks(TICK_INTERVAL_MS), [this]{ this->tick(); }); timer->setCallbackPriority(Thread::Priority::Lower); timer->start(); return true; @@ -238,7 +240,7 @@ void DisplayIdleService::onStop(ServiceContext& service) { for (int i = 0; i < maxRetries && screensaverOverlay; ++i) { stopScreensaver(); if (screensaverOverlay && i < maxRetries - 1) { - kernel::delayMillis(50); // Brief delay before retry + delay_millis(50); // Brief delay before retry } } if (screensaverOverlay) { diff --git a/Tactility/Source/service/keyboardidle/KeyboardIdle.cpp b/Tactility/Source/service/keyboardidle/KeyboardIdle.cpp index 33942156d..24a96c29e 100644 --- a/Tactility/Source/service/keyboardidle/KeyboardIdle.cpp +++ b/Tactility/Source/service/keyboardidle/KeyboardIdle.cpp @@ -2,6 +2,7 @@ #include +#include #include #include @@ -9,10 +10,10 @@ #include #include -#include #include #include #include +#include namespace tt::service::keyboardidle { @@ -92,7 +93,7 @@ public: // Note: Settings changes require service restart to take effect // TODO: Add KeyboardSettingsChanged events for dynamic updates - timer = std::make_unique(Timer::Type::Periodic, kernel::millisToTicks(250), [this]{ this->tick(); }); + timer = std::make_unique(Timer::Type::Periodic, millis_to_ticks(250), [this]{ this->tick(); }); timer->setCallbackPriority(Thread::Priority::Lower); timer->start(); return true; diff --git a/Tactility/Source/service/screenshot/ScreenshotTask.cpp b/Tactility/Source/service/screenshot/ScreenshotTask.cpp index b91b088da..84e70e6bc 100644 --- a/Tactility/Source/service/screenshot/ScreenshotTask.cpp +++ b/Tactility/Source/service/screenshot/ScreenshotTask.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -71,7 +72,7 @@ void ScreenshotTask::taskMain() { if (work.type == TASK_WORK_TYPE_DELAY) { // Splitting up the delays makes it easier to stop the service for (int i = 0; i < (work.delay_in_seconds * 10) && !isInterrupted(); ++i){ - kernel::delayMillis(100); + delay_millis(100); } if (!isInterrupted()) { @@ -88,14 +89,14 @@ void ScreenshotTask::taskMain() { if (appContext != nullptr) { const app::AppManifest& manifest = appContext->getManifest(); if (manifest.appId != last_app_id) { - kernel::delayMillis(100); + delay_millis(100); last_app_id = manifest.appId; auto filename = std::format("{}/screenshot-{}.png", work.path, manifest.appId); makeScreenshot(filename); } } // Ensure the LVGL widgets are rendered as the app just started - kernel::delayMillis(250); + delay_millis(250); } } diff --git a/Tactility/Source/service/wifi/Wifi.cpp b/Tactility/Source/service/wifi/Wifi.cpp index d3b074077..64781f3ec 100644 --- a/Tactility/Source/service/wifi/Wifi.cpp +++ b/Tactility/Source/service/wifi/Wifi.cpp @@ -11,12 +11,12 @@ #include #include #include -#include #include #include #include #include +#include #include #include @@ -76,7 +76,7 @@ struct WifiServiceState { bool connectionTargetRemember = false; settings::WifiApSettings connectionTarget; uint16_t scanRecordLimit = TT_WIFI_SCAN_RECORD_LIMIT; - TickType_t lastScanTime = kernel::MAX_TICKS; + TickType_t lastScanTime = MAX_TICKS; std::unique_ptr autoConnectTimer; kernel::SystemEventSubscription bootEventSubscription = kernel::NoSystemEventSubscription; }; @@ -165,7 +165,7 @@ void dispatchScan() { LOG_I(TAG, "dispatchScan()"); if (!started || state.device == nullptr || !device_is_ready(state.device)) return; - state.lastScanTime = kernel::getTicks(); + state.lastScanTime = get_ticks(); error_t result = wifi_scan(state.device); if (result != ERROR_NONE) { @@ -263,7 +263,7 @@ bool shouldScanForAutoConnect() { !state.pauseAutoConnect && !state.externalScanPause.load(); if (!radio_scannable) return false; - TickType_t current_time = kernel::getTicks(); + TickType_t current_time = get_ticks(); bool scan_time_has_looped = current_time < state.lastScanTime; bool no_recent_scan = (current_time - state.lastScanTime) > (AUTO_SCAN_INTERVAL / portTICK_PERIOD_MS); return scan_time_has_looped || no_recent_scan; diff --git a/TactilityKernel/include/tactility/time.h b/TactilityKernel/include/tactility/time.h index af5ff11cc..707e09783 100644 --- a/TactilityKernel/include/tactility/time.h +++ b/TactilityKernel/include/tactility/time.h @@ -31,6 +31,8 @@ static_assert(configTICK_RATE_HZ == 1000); static_assert(configTICK_RATE_HZ == 1000, "configTICK_RATE_HZ must be 1000"); #endif +#define MAX_TICKS ~((TickType_t)0) + static inline uint32_t get_tick_frequency() { return configTICK_RATE_HZ; }