Compare commits

..

2 Commits

Author SHA1 Message Date
Ken Van Hoeylandt
b61a7a3f5f Use TactilityKernel's time and delay functions instead of TactilityFreeRtos ones 2026-07-28 09:41:06 +02:00
Ken Van Hoeylandt
4ee2931362 Add missing license headers 2026-07-28 00:38:54 +02:00
17 changed files with 59 additions and 39 deletions

View File

@ -1,4 +1,5 @@
#include <tactility/module.h> #include <tactility/module.h>
#include <tactility/delay.h>
#include <tactility/error.h> #include <tactility/error.h>
#include <tactility/log.h> #include <tactility/log.h>
@ -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. // 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(); subscribe_events();

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
#include "unphone_nav_buttons.h" #include "unphone_nav_buttons.h"
#include <tactility/delay.h>
#include <tactility/device.h> #include <tactility/device.h>
#include <tactility/driver.h> #include <tactility/driver.h>
#include <tactility/drivers/gpio_controller.h> #include <tactility/drivers/gpio_controller.h>
@ -76,9 +77,9 @@ static int32_t nav_buttons_thread_main(UnphoneNavButtonsInternal* internal) {
// Debounce all events for a short period of time // Debounce all events for a short period of time
// This is easier than keeping track when each button was last pressed // This is easier than keeping track when each button was last pressed
tt::kernel::delayMillis(50); delay_millis(50);
xQueueReset(internal->event_queue); xQueueReset(internal->event_queue);
tt::kernel::delayMillis(50); delay_millis(50);
xQueueReset(internal->event_queue); xQueueReset(internal->event_queue);
} }
} }

View File

@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once #pragma once
#define LVGL_ICON_LAUNCHER_APPS "\xEE\x97\x83" #define LVGL_ICON_LAUNCHER_APPS "\xEE\x97\x83"

View File

@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once #pragma once
#define LVGL_ICON_SHARED_ADD "\xEE\x85\x85" #define LVGL_ICON_SHARED_ADD "\xEE\x85\x85"

View File

@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once #pragma once
#define LVGL_ICON_STATUSBAR_LOCATION_ON "\xEF\x87\x9B" #define LVGL_ICON_STATUSBAR_LOCATION_ON "\xEF\x87\x9B"

View File

@ -1,10 +1,11 @@
#include <Tactility/CoreDefines.h>
#include <Tactility/Mutex.h>
#include <Tactility/SystemEvents.h> #include <Tactility/SystemEvents.h>
#include <Tactility/Mutex.h>
#include <tactility/check.h> #include <tactility/check.h>
#include <tactility/log.h> #include <tactility/log.h>
#include <tactility/time.h>
#include <Tactility/CoreDefines.h>
#include <list> #include <list>
namespace tt::kernel { namespace tt::kernel {

View File

@ -1,13 +1,13 @@
#include "Tactility/app/alertdialog/AlertDialog.h" #include "Tactility/app/alertdialog/AlertDialog.h"
#include <lvgl/widgets/toolbar.h> #include <Tactility/service/loader/Loader.h>
#include "Tactility/service/loader/Loader.h"
#include <Tactility/StringUtils.h> #include <Tactility/StringUtils.h>
#include <lvgl.h>
#include <tactility/log.h> #include <tactility/log.h>
#include <lvgl.h>
#include <lvgl/widgets/toolbar.h>
namespace tt::app::alertdialog { namespace tt::app::alertdialog {
#define PARAMETER_BUNDLE_KEY_TITLE "title" #define PARAMETER_BUNDLE_KEY_TITLE "title"

View File

@ -1,6 +1,8 @@
#include "Tactility/lvgl/Lvgl.h" #include <tactility/delay.h>
#include "tactility/drivers/backlight.h" #include <tactility/drivers/backlight.h>
#include "tactility/drivers/display.h" #include <tactility/drivers/display.h>
#include <tactility/log.h>
#include <tactility/time.h>
#include <Tactility/CpuAffinity.h> #include <Tactility/CpuAffinity.h>
#include <Tactility/Paths.h> #include <Tactility/Paths.h>
@ -10,13 +12,13 @@
#include <Tactility/app/AppPaths.h> #include <Tactility/app/AppPaths.h>
#include <Tactility/app/alertdialog/AlertDialog.h> #include <Tactility/app/alertdialog/AlertDialog.h>
#include <Tactility/hal/usb/Usb.h> #include <Tactility/hal/usb/Usb.h>
#include <Tactility/lvgl/Lvgl.h>
#include <Tactility/lvgl/Style.h> #include <Tactility/lvgl/Style.h>
#include <Tactility/service/loader/Loader.h> #include <Tactility/service/loader/Loader.h>
#include <Tactility/settings/BootSettings.h> #include <Tactility/settings/BootSettings.h>
#include <Tactility/settings/DisplaySettings.h> #include <Tactility/settings/DisplaySettings.h>
#include <lvgl.h> #include <lvgl.h>
#include <tactility/log.h>
#include <atomic> #include <atomic>
@ -108,23 +110,23 @@ class BootApp : public App {
} }
static void waitForMinimalSplashDuration(TickType_t startTime) { 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; const auto ticks_passed = end_time - startTime;
constexpr auto minimum_ticks = (CONFIG_TT_SPLASH_DURATION / portTICK_PERIOD_MS); constexpr auto minimum_ticks = (CONFIG_TT_SPLASH_DURATION / portTICK_PERIOD_MS);
if (minimum_ticks > ticks_passed) { if (minimum_ticks > ticks_passed) {
kernel::delayTicks(minimum_ticks - ticks_passed); delay_ticks(minimum_ticks - ticks_passed);
} }
} }
static int32_t bootThreadCallback() { static int32_t bootThreadCallback() {
LOG_I(TAG, "Starting boot thread"); 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 // 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 // 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 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 // 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 // TODO: Support for multiple displays
LOG_I(TAG, "Setup display"); LOG_I(TAG, "Setup display");

View File

@ -8,6 +8,7 @@
#include <Tactility/lvgl/Toolbar.h> #include <Tactility/lvgl/Toolbar.h>
#include <tactility/device.h> #include <tactility/device.h>
#include <tactility/time.h>
#include <atomic> #include <atomic>
#include <cstring> #include <cstring>
@ -211,7 +212,7 @@ public:
GpsSettingsApp() { GpsSettingsApp() {
// Runs while the screen is shown - there's no push notification for GPS device state // 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. // changes, so this is the only way this screen finds out about them.
timer = std::make_unique<Timer>(Timer::Type::Periodic, kernel::secondsToTicks(1), [this] { timer = std::make_unique<Timer>(Timer::Type::Periodic, seconds_to_ticks(1), [this] {
updateDeviceStates(); updateDeviceStates();
}); });
} }

View File

@ -6,6 +6,7 @@
#include <tactility/device.h> #include <tactility/device.h>
#include <tactility/drivers/power_supply.h> #include <tactility/drivers/power_supply.h>
#include <tactility/time.h>
#include <lvgl/lvgl.h> #include <lvgl/lvgl.h>
#include <lvgl/icons/shared.h> #include <lvgl/icons/shared.h>
@ -53,7 +54,7 @@ struct DeviceEntry {
class PowerApp : public App { 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<DeviceEntry> entries; std::vector<DeviceEntry> entries;

View File

@ -1,8 +1,11 @@
#include <Tactility/TactilityConfig.h> #include "tactility/time.h"
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/Tactility.h>
#include <Tactility/Timer.h>
#include <Tactility/Paths.h> #include <Tactility/Paths.h>
#include <Tactility/Tactility.h>
#include <Tactility/TactilityConfig.h>
#include <Tactility/Timer.h>
#include <Tactility/lvgl/Toolbar.h>
#include <algorithm> #include <algorithm>
#include <cstring> #include <cstring>
@ -242,7 +245,7 @@ static std::shared_ptr<SystemInfoApp> optApp() {
} }
class SystemInfoApp final : public App { 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(); auto app = optApp();
if (app) { if (app) {
lvgl_lock(); 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(); auto app = optApp();
if (app) { if (app) {
lvgl_lock(); lvgl_lock();

View File

@ -11,6 +11,7 @@
#include <tactility/check.h> #include <tactility/check.h>
#include <tactility/log.h> #include <tactility/log.h>
#include <tactility/time.h>
#include <lvgl/fonts.h> #include <lvgl/fonts.h>
#include <lvgl/lvgl.h> #include <lvgl/lvgl.h>
@ -182,7 +183,7 @@ lv_obj_t* statusbar_create(lv_obj_t* parent) {
obj_set_style_bg_invisible(left_spacer); obj_set_style_bg_invisible(left_spacer);
lv_obj_set_flex_grow(left_spacer, 1); 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) { for (int i = 0; i < STATUSBAR_ICON_LIMIT; ++i) {
auto* image = lv_image_create(obj); auto* image = lv_image_create(obj);
lv_obj_set_size(image, icon_size, icon_size); // regular padding doesn't work lv_obj_set_size(image, icon_size, icon_size); // regular padding doesn't work

View File

@ -1,6 +1,8 @@
#ifdef ESP_PLATFORM #ifdef ESP_PLATFORM
#include <Tactility/service/displayidle/DisplayIdleService.h> #include <Tactility/service/displayidle/DisplayIdleService.h>
#include <Tactility/service/ServiceManifest.h>
#include <Tactility/service/ServiceRegistration.h>
#include "BouncingBallsScreensaver.h" #include "BouncingBallsScreensaver.h"
#include "MatrixRainScreensaver.h" #include "MatrixRainScreensaver.h"
@ -8,14 +10,14 @@
#include "Screensaver.h" #include "Screensaver.h"
#include "StackChanScreensaver.h" #include "StackChanScreensaver.h"
#include <Tactility/service/ServiceManifest.h>
#include <Tactility/service/ServiceRegistration.h>
#include <cstdlib> #include <cstdlib>
#include <ctime> #include <ctime>
#include <tactility/delay.h>
#include <tactility/log.h> #include <tactility/log.h>
#include <tactility/drivers/display.h> #include <tactility/drivers/display.h>
#include <tactility/drivers/backlight.h> #include <tactility/drivers/backlight.h>
#include <lvgl/lvgl.h> #include <lvgl/lvgl.h>
namespace tt::service::displayidle { namespace tt::service::displayidle {
@ -221,7 +223,7 @@ bool DisplayIdleService::onStart(ServiceContext& service) {
cachedDisplaySettings = settings::display::loadOrGetDefault(); cachedDisplaySettings = settings::display::loadOrGetDefault();
timer = std::make_unique<Timer>(Timer::Type::Periodic, kernel::millisToTicks(TICK_INTERVAL_MS), [this]{ this->tick(); }); timer = std::make_unique<Timer>(Timer::Type::Periodic, millis_to_ticks(TICK_INTERVAL_MS), [this]{ this->tick(); });
timer->setCallbackPriority(Thread::Priority::Lower); timer->setCallbackPriority(Thread::Priority::Lower);
timer->start(); timer->start();
return true; return true;
@ -238,7 +240,7 @@ void DisplayIdleService::onStop(ServiceContext& service) {
for (int i = 0; i < maxRetries && screensaverOverlay; ++i) { for (int i = 0; i < maxRetries && screensaverOverlay; ++i) {
stopScreensaver(); stopScreensaver();
if (screensaverOverlay && i < maxRetries - 1) { if (screensaverOverlay && i < maxRetries - 1) {
kernel::delayMillis(50); // Brief delay before retry delay_millis(50); // Brief delay before retry
} }
} }
if (screensaverOverlay) { if (screensaverOverlay) {

View File

@ -2,6 +2,7 @@
#include <display/lv_display.h> #include <display/lv_display.h>
#include <lvgl/lvgl.h>
#include <Tactility/Timer.h> #include <Tactility/Timer.h>
#include <Tactility/service/ServiceContext.h> #include <Tactility/service/ServiceContext.h>
@ -9,10 +10,10 @@
#include <Tactility/service/ServiceRegistration.h> #include <Tactility/service/ServiceRegistration.h>
#include <Tactility/settings/KeyboardSettings.h> #include <Tactility/settings/KeyboardSettings.h>
#include <lvgl/lvgl.h>
#include <tactility/device.h> #include <tactility/device.h>
#include <tactility/drivers/backlight.h> #include <tactility/drivers/backlight.h>
#include <tactility/drivers/keyboard.h> #include <tactility/drivers/keyboard.h>
#include <tactility/time.h>
namespace tt::service::keyboardidle { namespace tt::service::keyboardidle {
@ -92,7 +93,7 @@ public:
// Note: Settings changes require service restart to take effect // Note: Settings changes require service restart to take effect
// TODO: Add KeyboardSettingsChanged events for dynamic updates // TODO: Add KeyboardSettingsChanged events for dynamic updates
timer = std::make_unique<Timer>(Timer::Type::Periodic, kernel::millisToTicks(250), [this]{ this->tick(); }); timer = std::make_unique<Timer>(Timer::Type::Periodic, millis_to_ticks(250), [this]{ this->tick(); });
timer->setCallbackPriority(Thread::Priority::Lower); timer->setCallbackPriority(Thread::Priority::Lower);
timer->start(); timer->start();
return true; return true;

View File

@ -8,6 +8,7 @@
#include <Tactility/service/loader/Loader.h> #include <Tactility/service/loader/Loader.h>
#include <Tactility/service/screenshot/ScreenshotTask.h> #include <Tactility/service/screenshot/ScreenshotTask.h>
#include <tactility/delay.h>
#include <tactility/log.h> #include <tactility/log.h>
#include <lvgl/lvgl.h> #include <lvgl/lvgl.h>
@ -71,7 +72,7 @@ void ScreenshotTask::taskMain() {
if (work.type == TASK_WORK_TYPE_DELAY) { if (work.type == TASK_WORK_TYPE_DELAY) {
// Splitting up the delays makes it easier to stop the service // Splitting up the delays makes it easier to stop the service
for (int i = 0; i < (work.delay_in_seconds * 10) && !isInterrupted(); ++i){ for (int i = 0; i < (work.delay_in_seconds * 10) && !isInterrupted(); ++i){
kernel::delayMillis(100); delay_millis(100);
} }
if (!isInterrupted()) { if (!isInterrupted()) {
@ -88,14 +89,14 @@ void ScreenshotTask::taskMain() {
if (appContext != nullptr) { if (appContext != nullptr) {
const app::AppManifest& manifest = appContext->getManifest(); const app::AppManifest& manifest = appContext->getManifest();
if (manifest.appId != last_app_id) { if (manifest.appId != last_app_id) {
kernel::delayMillis(100); delay_millis(100);
last_app_id = manifest.appId; last_app_id = manifest.appId;
auto filename = std::format("{}/screenshot-{}.png", work.path, manifest.appId); auto filename = std::format("{}/screenshot-{}.png", work.path, manifest.appId);
makeScreenshot(filename); makeScreenshot(filename);
} }
} }
// Ensure the LVGL widgets are rendered as the app just started // Ensure the LVGL widgets are rendered as the app just started
kernel::delayMillis(250); delay_millis(250);
} }
} }

View File

@ -11,12 +11,12 @@
#include <Tactility/service/ServiceRegistration.h> #include <Tactility/service/ServiceRegistration.h>
#include <Tactility/service/wifi/WifiBootSplashInit.h> #include <Tactility/service/wifi/WifiBootSplashInit.h>
#include <Tactility/service/wifi/WifiGlobals.h> #include <Tactility/service/wifi/WifiGlobals.h>
#include <Tactility/service/wifi/WifiSettings.h>
#include <tactility/check.h> #include <tactility/check.h>
#include <tactility/device.h> #include <tactility/device.h>
#include <tactility/drivers/wifi.h> #include <tactility/drivers/wifi.h>
#include <tactility/log.h> #include <tactility/log.h>
#include <tactility/time.h>
#include <tactility/wifi_auto_scan.h> #include <tactility/wifi_auto_scan.h>
#include <algorithm> #include <algorithm>
@ -76,7 +76,7 @@ struct WifiServiceState {
bool connectionTargetRemember = false; bool connectionTargetRemember = false;
settings::WifiApSettings connectionTarget; settings::WifiApSettings connectionTarget;
uint16_t scanRecordLimit = TT_WIFI_SCAN_RECORD_LIMIT; uint16_t scanRecordLimit = TT_WIFI_SCAN_RECORD_LIMIT;
TickType_t lastScanTime = kernel::MAX_TICKS; TickType_t lastScanTime = MAX_TICKS;
std::unique_ptr<Timer> autoConnectTimer; std::unique_ptr<Timer> autoConnectTimer;
kernel::SystemEventSubscription bootEventSubscription = kernel::NoSystemEventSubscription; kernel::SystemEventSubscription bootEventSubscription = kernel::NoSystemEventSubscription;
}; };
@ -165,7 +165,7 @@ void dispatchScan() {
LOG_I(TAG, "dispatchScan()"); LOG_I(TAG, "dispatchScan()");
if (!started || state.device == nullptr || !device_is_ready(state.device)) return; 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); error_t result = wifi_scan(state.device);
if (result != ERROR_NONE) { if (result != ERROR_NONE) {
@ -263,7 +263,7 @@ bool shouldScanForAutoConnect() {
!state.pauseAutoConnect && !state.externalScanPause.load(); !state.pauseAutoConnect && !state.externalScanPause.load();
if (!radio_scannable) return false; 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 scan_time_has_looped = current_time < state.lastScanTime;
bool no_recent_scan = (current_time - state.lastScanTime) > (AUTO_SCAN_INTERVAL / portTICK_PERIOD_MS); bool no_recent_scan = (current_time - state.lastScanTime) > (AUTO_SCAN_INTERVAL / portTICK_PERIOD_MS);
return scan_time_has_looped || no_recent_scan; return scan_time_has_looped || no_recent_scan;

View File

@ -31,6 +31,8 @@ static_assert(configTICK_RATE_HZ == 1000);
static_assert(configTICK_RATE_HZ == 1000, "configTICK_RATE_HZ must be 1000"); static_assert(configTICK_RATE_HZ == 1000, "configTICK_RATE_HZ must be 1000");
#endif #endif
#define MAX_TICKS ~((TickType_t)0)
static inline uint32_t get_tick_frequency() { static inline uint32_t get_tick_frequency() {
return configTICK_RATE_HZ; return configTICK_RATE_HZ;
} }