diff --git a/.github/actions/build-firmware/action.yml b/.github/actions/build-firmware/action.yml index 0314ca74..3df7f648 100644 --- a/.github/actions/build-firmware/action.yml +++ b/.github/actions/build-firmware/action.yml @@ -4,9 +4,6 @@ inputs: board-name: description: The name of the board required: true - version: - description: The name of the board - required: true sdkconfig: description: The sdkconfig file to build required: true @@ -32,6 +29,6 @@ runs: - name: 'Upload Artifact' uses: actions/upload-artifact@v4 with: - name: tactility-${{ inputs.board-name }}-${{ inputs.version }} + name: tactility-${{ inputs.board-name }} path: build/Tactility.bin retention-days: 5 diff --git a/.github/workflows/build-firmware.yml b/.github/workflows/build-firmware.yml index 6ce6a855..240f0ad8 100644 --- a/.github/workflows/build-firmware.yml +++ b/.github/workflows/build-firmware.yml @@ -12,7 +12,6 @@ jobs: uses: ./.github/actions/build-firmware with: board-name: yellowboard - version: snapshot sdkconfig: sdkconfig.board.yellow_board arch: esp32 lilygo-tdeck: @@ -23,7 +22,6 @@ jobs: uses: ./.github/actions/build-firmware with: board-name: lilygotdeck - version: snapshot sdkconfig: sdkconfig.board.lilygo_tdeck arch: esp32s3 m5stack-core2: @@ -34,7 +32,6 @@ jobs: uses: ./.github/actions/build-firmware with: board-name: m5stackcore2 - version: snapshot sdkconfig: sdkconfig.board.m5stack_core2 arch: esp32 m5stack-cores3: @@ -45,6 +42,5 @@ jobs: uses: ./.github/actions/build-firmware with: board-name: m5stackcores3 - version: snapshot sdkconfig: sdkconfig.board.m5stack_cores3 arch: esp32s3 diff --git a/App/Source/Main.cpp b/App/Source/Main.cpp index b4f1096e..97f42e75 100644 --- a/App/Source/Main.cpp +++ b/App/Source/Main.cpp @@ -22,7 +22,7 @@ void app_main() { &hello_world_app, }, .services = {}, - .auto_start_app_id = nullptr + .autoStartAppId = nullptr }; tt::run(config); diff --git a/Boards/LilygoTdeck/Source/hal/TdeckTouch.cpp b/Boards/LilygoTdeck/Source/hal/TdeckTouch.cpp index 22906f73..ed35f511 100644 --- a/Boards/LilygoTdeck/Source/hal/TdeckTouch.cpp +++ b/Boards/LilygoTdeck/Source/hal/TdeckTouch.cpp @@ -3,7 +3,7 @@ #include "esp_err.h" #include "esp_lcd_touch_gt911.h" #include "Log.h" -#include "Kernel.h" +#include "kernel/Kernel.h" #include "esp_lvgl_port.h" #define TAG "tdeck_touch" diff --git a/Boards/Simulator/Source/LvglTask.cpp b/Boards/Simulator/Source/LvglTask.cpp index 17f33327..0d1120d4 100644 --- a/Boards/Simulator/Source/LvglTask.cpp +++ b/Boards/Simulator/Source/LvglTask.cpp @@ -11,8 +11,8 @@ #define TAG "lvgl_task" // Mutex for LVGL drawing -static tt::Mutex lvgl_mutex(tt::MutexTypeRecursive); -static tt::Mutex task_mutex(tt::MutexTypeRecursive); +static tt::Mutex lvgl_mutex(tt::Mutex::TypeRecursive); +static tt::Mutex task_mutex(tt::Mutex::TypeRecursive); static uint32_t task_max_sleep_ms = 10; // Mutex for LVGL task state (to modify task_running state) diff --git a/Boards/Simulator/Source/hal/Configuration.cpp b/Boards/Simulator/Source/hal/Configuration.cpp index 6a69c1a4..a0cf648e 100644 --- a/Boards/Simulator/Source/hal/Configuration.cpp +++ b/Boards/Simulator/Source/hal/Configuration.cpp @@ -17,7 +17,7 @@ static bool initBoot() { TT_UNUSED static void deinitPower() { lvgl_task_interrupt(); while (lvgl_task_is_running()) { - tt::delay_ms(10); + tt::kernel::delayMillis(10); } #if LV_ENABLE_GC || !LV_MEM_CUSTOM diff --git a/CMakeLists.txt b/CMakeLists.txt index 3760dc27..09c6ea57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.16) add_definitions(-DTT_DEBUG) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_ASM_COMPILE_OBJECT "${CMAKE_CXX_COMPILER_TARGET}") diff --git a/Documentation/ideas.md b/Documentation/ideas.md index c0139738..635246c7 100644 --- a/Documentation/ideas.md +++ b/Documentation/ideas.md @@ -1,4 +1,6 @@ # TODOs +- Gpio: Use Timer instead of Thread +- I2cScannerThread: Use Timer instead of Thread - Bug: I2C Scanner is on M5Stack devices is broken - WiFi AP Connect app: add "Forget" option. - T-Deck Plus: Implement battery status diff --git a/Libraries/lv_screenshot/CMakeLists.txt b/Libraries/lv_screenshot/CMakeLists.txt index 8ca85ee8..3daaa702 100644 --- a/Libraries/lv_screenshot/CMakeLists.txt +++ b/Libraries/lv_screenshot/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.16) -set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) diff --git a/Tactility/CMakeLists.txt b/Tactility/CMakeLists.txt index 065abf6c..2d467257 100644 --- a/Tactility/CMakeLists.txt +++ b/Tactility/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.16) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) if (DEFINED ENV{ESP_IDF_VERSION}) diff --git a/Tactility/Private/app/AppInstance.h b/Tactility/Private/app/AppInstance.h index 8b16beb3..520e14e8 100644 --- a/Tactility/Private/app/AppInstance.h +++ b/Tactility/Private/app/AppInstance.h @@ -37,7 +37,7 @@ class AppInstance : public AppContext { private: - Mutex mutex = Mutex(MutexTypeNormal); + Mutex mutex = Mutex(Mutex::TypeNormal); const AppManifest& manifest; State state = StateInitial; Flags flags = { .showStatusbar = true }; diff --git a/Tactility/Private/service/loader/Loader_i.h b/Tactility/Private/service/loader/Loader_i.h index 60bd988b..51bd74c9 100644 --- a/Tactility/Private/service/loader/Loader_i.h +++ b/Tactility/Private/service/loader/Loader_i.h @@ -143,7 +143,7 @@ struct Loader { std::shared_ptr pubsub_internal = std::make_shared(); std::shared_ptr pubsub_external = std::make_shared(); MessageQueue queue = MessageQueue(2, sizeof(LoaderMessage)); // 2 entries, so you can stop the current app while starting a new one without blocking - Mutex mutex = Mutex(MutexTypeRecursive); + Mutex mutex = Mutex(Mutex::TypeRecursive); std::stack app_stack; }; diff --git a/Tactility/Source/Tactility.cpp b/Tactility/Source/Tactility.cpp index bda82b4c..b3fd019f 100644 --- a/Tactility/Source/Tactility.cpp +++ b/Tactility/Source/Tactility.cpp @@ -155,9 +155,9 @@ void run(const Configuration& config) { TT_LOG_I(TAG, "init starting desktop app"); service::loader::startApp(app::boot::manifest.id, true); - 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); + if (config.autoStartAppId) { + TT_LOG_I(TAG, "init auto-starting %s", config.autoStartAppId); + service::loader::startApp(config.autoStartAppId, true); } TT_LOG_I(TAG, "init complete"); diff --git a/Tactility/Source/Tactility.h b/Tactility/Source/Tactility.h index 5dfa5e0f..d97f1e07 100644 --- a/Tactility/Source/Tactility.h +++ b/Tactility/Source/Tactility.h @@ -12,7 +12,7 @@ typedef struct { // List of user applications const app::AppManifest* const apps[TT_CONFIG_APPS_LIMIT]; const service::ServiceManifest* const services[TT_CONFIG_SERVICES_LIMIT]; - const char* auto_start_app_id; + const char* autoStartAppId; } Configuration; /** diff --git a/Tactility/Source/app/ManifestRegistry.cpp b/Tactility/Source/app/ManifestRegistry.cpp index b4a56bbb..dd2c54bc 100644 --- a/Tactility/Source/app/ManifestRegistry.cpp +++ b/Tactility/Source/app/ManifestRegistry.cpp @@ -10,7 +10,7 @@ namespace tt::app { typedef std::unordered_map AppManifestMap; static AppManifestMap app_manifest_map; -static Mutex hash_mutex(MutexTypeNormal); +static Mutex hash_mutex(Mutex::TypeNormal); void addApp(const AppManifest* manifest) { TT_LOG_I(TAG, "Registering manifest %s", manifest->id.c_str()); diff --git a/Tactility/Source/app/boot/Boot.cpp b/Tactility/Source/app/boot/Boot.cpp index f0316e39..fdabb48c 100644 --- a/Tactility/Source/app/boot/Boot.cpp +++ b/Tactility/Source/app/boot/Boot.cpp @@ -1,13 +1,13 @@ -#include -#include -#include #include "Assets.h" +#include "TactilityCore.h" + #include "app/AppContext.h" -#include "lvgl.h" +#include "app/display/DisplaySettings.h" #include "hal/Display.h" #include "service/loader/Loader.h" #include "lvgl/Style.h" -#include "app/display/DisplaySettings.h" + +#include "lvgl.h" #ifdef ESP_PLATFORM #include "sdkconfig.h" @@ -26,7 +26,7 @@ struct Data { }; static int32_t threadCallback(TT_UNUSED void* context) { - TickType_t start_time = tt::get_ticks(); + TickType_t start_time = tt::kernel::getTicks(); auto* lvgl_display = lv_display_get_default(); tt_assert(lvgl_display != nullptr); @@ -37,11 +37,11 @@ static int32_t threadCallback(TT_UNUSED void* context) { hal_display->setBacklightDuty(backlight_duty); } - TickType_t end_time = tt::get_ticks(); + TickType_t end_time = tt::kernel::getTicks(); TickType_t ticks_passed = end_time - start_time; TickType_t minimum_ticks = (CONFIG_TT_SPLASH_DURATION / portTICK_PERIOD_MS); if (minimum_ticks > ticks_passed) { - tt::delay_ticks(minimum_ticks - ticks_passed); + tt::kernel::delayTicks(minimum_ticks - ticks_passed); } tt::service::loader::stopApp(); tt::service::loader::startApp("Desktop"); diff --git a/Tactility/Source/app/files/Files.cpp b/Tactility/Source/app/files/Files.cpp index 6f0becbc..4412f1bf 100644 --- a/Tactility/Source/app/files/Files.cpp +++ b/Tactility/Source/app/files/Files.cpp @@ -81,7 +81,7 @@ static void onNavigateUpPressed(TT_UNUSED lv_event_t* event) { if (strcmp(files_data->current_path, "/") != 0) { TT_LOG_I(TAG, "Navigating upwards"); char new_absolute_path[MAX_PATH_LENGTH]; - if (string_get_path_parent(files_data->current_path, new_absolute_path)) { + if (string::getPathParent(files_data->current_path, new_absolute_path)) { data_set_entries_for_path(files_data, new_absolute_path); } } @@ -102,7 +102,7 @@ static void viewFile(const char* path, const char* filename) { // For PC we need to make the path relative to the current work directory, // because that's how LVGL maps its 'drive letter' to the file system. char* processed_filepath; - if (get_platform() == PlatformSimulator) { + if (kernel::getPlatform() == kernel::PlatformSimulator) { char cwd[PATH_MAX]; if (getcwd(cwd, sizeof(cwd)) == nullptr) { TT_LOG_E(TAG, "Failed to get current working directory"); @@ -126,7 +126,7 @@ static void viewFile(const char* path, const char* filename) { service::loader::startApp("ImageViewer", false, bundle); } else if (isSupportedTextFile(filename)) { auto bundle = std::make_shared(); - if (get_platform() == PlatformEsp) { + if (kernel::getPlatform() == kernel::PlatformEsp) { bundle->putString(TEXT_VIEWER_FILE_ARGUMENT, processed_filepath); } else { // Remove forward slash, because we need a relative path @@ -220,7 +220,7 @@ static void onShow(AppContext& app, lv_obj_t* parent) { static void onStart(AppContext& app) { auto data = std::make_shared(); // PC platform is bound to current work directory because of the LVGL file system mapping - if (get_platform() == PlatformSimulator) { + if (kernel::getPlatform() == kernel::PlatformSimulator) { char cwd[PATH_MAX]; if (getcwd(cwd, sizeof(cwd)) != nullptr) { data_set_entries_for_path(data, cwd); diff --git a/Tactility/Source/app/files/FilesData.cpp b/Tactility/Source/app/files/FilesData.cpp index 5aa4caf2..6761c852 100644 --- a/Tactility/Source/app/files/FilesData.cpp +++ b/Tactility/Source/app/files/FilesData.cpp @@ -42,7 +42,7 @@ bool data_set_entries_for_path(std::shared_ptr data, const char* path) { * ESP32 does not have a root directory, so we have to create it manually. * We'll add the NVS Flash partitions and the binding for the sdcard. */ - if (get_platform() == PlatformEsp && strcmp(path, "/") == 0) { + if (kernel::getPlatform() == kernel::PlatformEsp && strcmp(path, "/") == 0) { int dir_entries_count = 3; auto** dir_entries = static_cast(malloc(sizeof(struct dirent*) * 3)); diff --git a/Tactility/Source/app/gpio/Gpio.cpp b/Tactility/Source/app/gpio/Gpio.cpp index b60faec8..8c406683 100644 --- a/Tactility/Source/app/gpio/Gpio.cpp +++ b/Tactility/Source/app/gpio/Gpio.cpp @@ -91,7 +91,7 @@ static int32_t taskMain(void* context) { bool interrupted = false; while (!interrupted) { - delay_ms(100); + kernel::delayMillis(100); gpio->updatePinStates(); gpio->updatePinWidgets(); diff --git a/Tactility/Source/app/i2cscanner/I2cHelpers.cpp b/Tactility/Source/app/i2cscanner/I2cHelpers.cpp index 823b8636..6f4efb68 100644 --- a/Tactility/Source/app/i2cscanner/I2cHelpers.cpp +++ b/Tactility/Source/app/i2cscanner/I2cHelpers.cpp @@ -27,7 +27,7 @@ std::string getPortNamesForDropdown() { } port_index++; } - return string_join(config_names, "\n"); + return string::join(config_names, "\n"); } } diff --git a/Tactility/Source/app/i2cscanner/I2cScanner.h b/Tactility/Source/app/i2cscanner/I2cScanner.h index ffb79640..e652561f 100644 --- a/Tactility/Source/app/i2cscanner/I2cScanner.h +++ b/Tactility/Source/app/i2cscanner/I2cScanner.h @@ -19,7 +19,7 @@ enum ScanState { struct Data { // Core - Mutex mutex = Mutex(MutexTypeRecursive); + Mutex mutex = Mutex(Mutex::TypeRecursive); Thread* _Nullable scanThread = nullptr; // State ScanState scanState; diff --git a/Tactility/Source/app/power/Power.cpp b/Tactility/Source/app/power/Power.cpp index 5d518c99..44d9efb3 100644 --- a/Tactility/Source/app/power/Power.cpp +++ b/Tactility/Source/app/power/Power.cpp @@ -41,7 +41,7 @@ static void updateUi(std::shared_ptr data) { uint16_t charge_level_scaled = (int16_t)charge_level * 100 / 255; int32_t current = data->power->getCurrent(); - lvgl::lock(ms_to_ticks(1000)); + lvgl::lock(kernel::millisToTicks(1000)); lv_obj_set_state(data->enable_switch, LV_STATE_CHECKED, charging_enabled); lv_label_set_text_fmt(data->charge_state, "Charging: %s", charge_state); lv_label_set_text_fmt(data->charge_level, "Charge level: %d%%", charge_level_scaled); @@ -110,7 +110,7 @@ static void onShow(AppContext& app, lv_obj_t* parent) { data->current = lv_label_create(wrapper); updateUi(data); - data->update_timer->start(ms_to_ticks(1000)); + data->update_timer->start(kernel::millisToTicks(1000)); } static void onHide(TT_UNUSED AppContext& app) { diff --git a/Tactility/Source/app/screenshot/ScreenshotUi.cpp b/Tactility/Source/app/screenshot/ScreenshotUi.cpp index 08aee1c7..4bbf507c 100644 --- a/Tactility/Source/app/screenshot/ScreenshotUi.cpp +++ b/Tactility/Source/app/screenshot/ScreenshotUi.cpp @@ -124,7 +124,7 @@ static void create_path_ui(std::shared_ptr ui, lv_obj_t* parent) { lv_textarea_set_one_line(path_textarea, true); lv_obj_set_flex_grow(path_textarea, 1); ui->path_textarea = path_textarea; - if (get_platform() == PlatformEsp) { + if (kernel::getPlatform() == kernel::PlatformEsp) { if (hal::sdcard::getState() == hal::sdcard::StateMounted) { lv_textarea_set_text(path_textarea, "A:/sdcard"); } else { diff --git a/Tactility/Source/app/selectiondialog/SelectionDialog.cpp b/Tactility/Source/app/selectiondialog/SelectionDialog.cpp index b6cf414b..94ee4e6b 100644 --- a/Tactility/Source/app/selectiondialog/SelectionDialog.cpp +++ b/Tactility/Source/app/selectiondialog/SelectionDialog.cpp @@ -16,9 +16,14 @@ namespace tt::app::selectiondialog { #define TAG "selection_dialog" -void setItemsParameter(Bundle& bundle, const std::vector& items) { - std::string result = string_join(items, PARAMETER_ITEM_CONCATENATION_TOKEN); - bundle.putString(PARAMETER_BUNDLE_KEY_ITEMS, result); +extern const AppManifest manifest; + +void start(std::string title, const std::vector& items) { + std::string items_joined = string::join(items, PARAMETER_ITEM_CONCATENATION_TOKEN); + auto bundle = std::make_shared(); + bundle->putString(PARAMETER_BUNDLE_KEY_TITLE, title); + bundle->putString(PARAMETER_BUNDLE_KEY_ITEMS, items_joined); + service::loader::startApp(manifest.id, false, bundle); } int32_t getResultIndex(const Bundle& bundle) { @@ -31,10 +36,6 @@ void setResultIndex(std::shared_ptr bundle, int32_t index) { bundle->putInt32(RESULT_BUNDLE_KEY_INDEX, index); } -void setTitleParameter(std::shared_ptr bundle, const std::string& title) { - bundle->putString(PARAMETER_BUNDLE_KEY_TITLE, title); -} - static std::string getTitleParameter(std::shared_ptr bundle) { std::string result; if (bundle->optString(PARAMETER_BUNDLE_KEY_TITLE, result)) { @@ -76,7 +77,7 @@ static void onShow(AppContext& app, lv_obj_t* parent) { tt_check(parameters != nullptr, "Parameters missing"); std::string items_concatenated; if (parameters->optString(PARAMETER_BUNDLE_KEY_ITEMS, items_concatenated)) { - std::vector items = string_split(items_concatenated, PARAMETER_ITEM_CONCATENATION_TOKEN); + std::vector items = string::split(items_concatenated, PARAMETER_ITEM_CONCATENATION_TOKEN); if (items.empty() || items.front().empty()) { TT_LOG_E(TAG, "No items provided"); app.setResult(ResultError); diff --git a/Tactility/Source/app/selectiondialog/SelectionDialog.h b/Tactility/Source/app/selectiondialog/SelectionDialog.h index b189e4c8..0bc384be 100644 --- a/Tactility/Source/app/selectiondialog/SelectionDialog.h +++ b/Tactility/Source/app/selectiondialog/SelectionDialog.h @@ -14,10 +14,7 @@ */ namespace tt::app::selectiondialog { - /** App startup parameters */ - - void setTitleParameter(Bundle& bundle, const std::string& title); - void setItemsParameter(Bundle& bundle, const std::vector& items); + void start(std::string title, const std::vector& items); /** App result data */ diff --git a/Tactility/Source/app/wifimanage/State.h b/Tactility/Source/app/wifimanage/State.h index 74fbe7eb..26f9fcd7 100644 --- a/Tactility/Source/app/wifimanage/State.h +++ b/Tactility/Source/app/wifimanage/State.h @@ -10,7 +10,7 @@ namespace tt::app::wifimanage { */ class State { - Mutex mutex = Mutex(MutexTypeRecursive); + Mutex mutex = Mutex(Mutex::TypeRecursive); bool scanning; service::wifi::WifiRadioState radioState; std::vector apRecords; diff --git a/Tactility/Source/lvgl/Statusbar.cpp b/Tactility/Source/lvgl/Statusbar.cpp index 0c72d5db..73de4d98 100644 --- a/Tactility/Source/lvgl/Statusbar.cpp +++ b/Tactility/Source/lvgl/Statusbar.cpp @@ -39,7 +39,7 @@ typedef struct { } Statusbar; static void statusbar_init() { - statusbar_data.mutex = tt_mutex_alloc(MutexTypeRecursive); + statusbar_data.mutex = tt_mutex_alloc(Mutex::TypeRecursive); statusbar_data.pubsub = std::make_shared(); for (int i = 0; i < STATUSBAR_ICON_LIMIT; i++) { statusbar_data.icons[i].image = nullptr; @@ -83,7 +83,7 @@ static const lv_obj_class_t statusbar_class = { static void statusbar_pubsub_event(TT_UNUSED const void* message, void* obj) { TT_LOG_I(TAG, "event"); auto* statusbar = static_cast(obj); - if (lock(ms_to_ticks(100))) { + if (lock(kernel::millisToTicks(100))) { update_main(statusbar); lv_obj_invalidate(&statusbar->obj); unlock(); diff --git a/Tactility/Source/service/gui/Gui.cpp b/Tactility/Source/service/gui/Gui.cpp index c6426f0a..5c5faf8b 100644 --- a/Tactility/Source/service/gui/Gui.cpp +++ b/Tactility/Source/service/gui/Gui.cpp @@ -36,7 +36,7 @@ Gui* gui_alloc() { &gui_main, nullptr ); - instance->mutex = tt_mutex_alloc(MutexTypeRecursive); + instance->mutex = tt_mutex_alloc(Mutex::TypeRecursive); instance->keyboard = nullptr; instance->loader_pubsub_subscription = tt_pubsub_subscribe(loader::getPubsub(), &loader_callback, instance); tt_check(lvgl::lock(1000 / portTICK_PERIOD_MS)); diff --git a/Tactility/Source/service/loader/Loader.cpp b/Tactility/Source/service/loader/Loader.cpp index dad3d873..3a4fbde2 100644 --- a/Tactility/Source/service/loader/Loader.cpp +++ b/Tactility/Source/service/loader/Loader.cpp @@ -16,6 +16,7 @@ namespace tt::service::loader { #define TAG "loader" +#define LOADER_EVENT_FLAG 1 typedef struct { LoaderEventType type; @@ -77,7 +78,7 @@ LoaderStatus startApp(const std::string& id, bool blocking, std::shared_ptrwait(TT_API_LOCK_EVENT); + event_flag->wait(LOADER_EVENT_FLAG); delete event_flag; } @@ -330,7 +331,7 @@ static int32_t loader_main(TT_UNUSED void* parameter) { message.payload.start->parameters ); if (message.api_lock != nullptr) { - message.api_lock->set(TT_API_LOCK_EVENT); + message.api_lock->set(LOADER_EVENT_FLAG); } message.cleanup(); break; diff --git a/Tactility/Source/service/screenshot/ScreenshotTask.cpp b/Tactility/Source/service/screenshot/ScreenshotTask.cpp index 28fba052..ca3933c7 100644 --- a/Tactility/Source/service/screenshot/ScreenshotTask.cpp +++ b/Tactility/Source/service/screenshot/ScreenshotTask.cpp @@ -43,7 +43,7 @@ ScreenshotTask* alloc() { auto* data = static_cast(malloc(sizeof(ScreenshotTaskData))); *data = (ScreenshotTaskData) { .thread = nullptr, - .mutex = tt_mutex_alloc(MutexTypeRecursive), + .mutex = tt_mutex_alloc(Mutex::TypeRecursive), .interrupted = false }; return data; @@ -76,7 +76,7 @@ static int32_t screenshot_task(void* context) { if (data->work.type == TASK_WORK_TYPE_DELAY) { // Splitting up the delays makes it easier to stop the service for (int i = 0; i < (data->work.delay_in_seconds * 10) && !is_interrupted(data); ++i){ - delay_ms(100); + kernel::delayMillis(100); } if (is_interrupted(data)) { @@ -102,7 +102,7 @@ static int32_t screenshot_task(void* context) { if (app) { const app::AppManifest& manifest = app->getManifest(); if (manifest.id != last_app_id) { - delay_ms(100); + kernel::delayMillis(100); last_app_id = manifest.id; char filename[SCREENSHOT_PATH_LIMIT + 32]; @@ -116,7 +116,7 @@ static int32_t screenshot_task(void* context) { lvgl::unlock(); } } - delay_ms(250); + kernel::delayMillis(250); } } diff --git a/TactilityCore/CMakeLists.txt b/TactilityCore/CMakeLists.txt index 84658065..ad4c68dc 100644 --- a/TactilityCore/CMakeLists.txt +++ b/TactilityCore/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.16) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) file(GLOB_RECURSE SOURCES "Source/*.c*") diff --git a/TactilityCore/Source/Bundle.h b/TactilityCore/Source/Bundle.h index 5ba8f053..619d3f22 100644 --- a/TactilityCore/Source/Bundle.h +++ b/TactilityCore/Source/Bundle.h @@ -23,7 +23,7 @@ private: } Type; typedef struct { - const char* key; + std::string key; Type type; union { bool value_bool; diff --git a/TactilityCore/Source/Check.cpp b/TactilityCore/Source/Check.cpp index a088e4ff..855ed8b2 100644 --- a/TactilityCore/Source/Check.cpp +++ b/TactilityCore/Source/Check.cpp @@ -1,12 +1,11 @@ #include "Check.h" -#include "CoreDefines.h" #include "Log.h" #include "RtosCompatTask.h" #define TAG "kernel" -static void tt_print_memory_info() { +static void logMemoryInfo() { #ifdef ESP_PLATFORM TT_LOG_E(TAG, "default caps:"); TT_LOG_E(TAG, " total: %u", heap_caps_get_total_size(MALLOC_CAP_DEFAULT)); @@ -19,19 +18,23 @@ static void tt_print_memory_info() { #endif } -static void tt_print_task_info() { +static void logTaskInfo() { const char* name = pcTaskGetName(nullptr); const char* safe_name = name ? name : "main"; TT_LOG_E(TAG, "Task: %s", safe_name); TT_LOG_E(TAG, "Stack watermark: %u", uxTaskGetStackHighWaterMark(NULL) * 4); } -TT_NORETURN void tt_crash_implementation() { - tt_print_task_info(); - tt_print_memory_info(); +namespace tt { + +TT_NORETURN void _crash() { + logTaskInfo(); + logMemoryInfo(); // TODO: Add breakpoint when debugger is attached. #ifdef ESP_TARGET esp_system_abort("System halted. Connect debugger for more info."); #endif __builtin_unreachable(); } + +} diff --git a/TactilityCore/Source/Check.h b/TactilityCore/Source/Check.h index 151ce283..1354b372 100644 --- a/TactilityCore/Source/Check.h +++ b/TactilityCore/Source/Check.h @@ -15,17 +15,29 @@ #include "Log.h" #include +#include "CoreDefines.h" #define TT_NORETURN [[noreturn]] /** Crash system */ -TT_NORETURN void tt_crash_implementation(); +namespace tt { + /** + * Don't call this directly. Use tt_crash() as it will trace info. + */ + TT_NORETURN void _crash(); +} /** Crash system with message. */ -#define tt_crash(message) \ - do { \ - TT_LOG_E("crash", "%s\n\tat %s:%d", ((message) ? (message) : ""), __FILE__, __LINE__); \ - tt_crash_implementation(); \ +#define tt_crash(...) TT_ARG_CAT(_tt_crash,TT_ARGCOUNT(__VA_ARGS__))(__VA_ARGS__) + +#define _tt_crash0() do { \ + TT_LOG_E("crash", "at %s:%d", __FILE__, __LINE__); \ + tt::_crash(); \ + } while (0) + +#define _tt_crash1(message) do { \ + TT_LOG_E("crash", "%s\n\tat %s:%d", message, __FILE__, __LINE__); \ + tt::_crash(); \ } while (0) /** Halt system @@ -53,7 +65,7 @@ TT_NORETURN void tt_crash_implementation(); * @param optional message (const char*) */ -#define tt_check(x, ...) if (!(x)) { TT_LOG_E("check", "Failed: %s", #x); tt_crash_implementation(); } +#define tt_check(x, ...) if (!(x)) { TT_LOG_E("check", "Failed: %s", #x); tt::_crash(); } /** Only in debug build: Assert condition and crash if assert failed */ #ifdef TT_DEBUG diff --git a/TactilityCore/Source/CoreDefines.h b/TactilityCore/Source/CoreDefines.h index 88876446..eefd6b63 100644 --- a/TactilityCore/Source/CoreDefines.h +++ b/TactilityCore/Source/CoreDefines.h @@ -31,3 +31,19 @@ #define TT_IS_ISR() (TT_IS_IRQ_MODE()) #define TT_CHECK_RETURN __attribute__((__warn_unused_result__)) + +// region Variable arguments support + +// Adapted from https://stackoverflow.com/a/78848701/3848666 +#define TT_ARG_IGNORE(X) +#define TT_ARG_CAT(X,Y) _TT_ARG_CAT(X,Y) +#define _TT_ARG_CAT(X,Y) X ## Y +#define TT_ARGCOUNT(...) _TT_ARGCOUNT ## __VA_OPT__(1(__VA_ARGS__) TT_ARG_IGNORE) (0) +#define _TT_ARGCOUNT1(X,...) _TT_ARGCOUNT ## __VA_OPT__(2(__VA_ARGS__) TT_ARG_IGNORE) (1) +#define _TT_ARGCOUNT2(X,...) _TT_ARGCOUNT ## __VA_OPT__(3(__VA_ARGS__) TT_ARG_IGNORE) (2) +#define _TT_ARGCOUNT3(X,...) _TT_ARGCOUNT ## __VA_OPT__(4(__VA_ARGS__) TT_ARG_IGNORE) (3) +#define _TT_ARGCOUNT4(X,...) _TT_ARGCOUNT ## __VA_OPT__(5(__VA_ARGS__) TT_ARG_IGNORE) (4) +#define _TT_ARGCOUNT5(X,...) 5 +#define _TT_ARGCOUNT(X) X + +// endregion \ No newline at end of file diff --git a/TactilityCore/Source/Dispatcher.cpp b/TactilityCore/Source/Dispatcher.cpp index db2d1bf7..db497c23 100644 --- a/TactilityCore/Source/Dispatcher.cpp +++ b/TactilityCore/Source/Dispatcher.cpp @@ -7,7 +7,7 @@ namespace tt { #define BACKPRESSURE_WARNING_COUNT 100 Dispatcher::Dispatcher() : - mutex(MutexTypeNormal) + mutex(Mutex::TypeNormal) {} Dispatcher::~Dispatcher() { diff --git a/TactilityCore/Source/EventFlag.h b/TactilityCore/Source/EventFlag.h index b49e11e9..3538381c 100644 --- a/TactilityCore/Source/EventFlag.h +++ b/TactilityCore/Source/EventFlag.h @@ -5,8 +5,6 @@ namespace tt { -#define TT_API_LOCK_EVENT (1U << 0) - /** * Wrapper for FreeRTOS xEventGroup. */ diff --git a/TactilityCore/Source/MessageQueue.cpp b/TactilityCore/Source/MessageQueue.cpp index c0ceaf47..d62dc7f1 100644 --- a/TactilityCore/Source/MessageQueue.cpp +++ b/TactilityCore/Source/MessageQueue.cpp @@ -1,17 +1,17 @@ #include "MessageQueue.h" #include "Check.h" -#include "Kernel.h" +#include "kernel/Kernel.h" namespace tt { MessageQueue::MessageQueue(uint32_t msg_count, uint32_t msg_size) { - tt_assert((kernel_is_irq() == 0U) && (msg_count > 0U) && (msg_size > 0U)); + tt_assert((kernel::isIrq() == 0U) && (msg_count > 0U) && (msg_size > 0U)); queue_handle = xQueueCreate(msg_count, msg_size); tt_check(queue_handle); } MessageQueue::~MessageQueue() { - tt_assert(kernel_is_irq() == 0U); + tt_assert(kernel::isIrq() == 0U); vQueueDelete(queue_handle); } @@ -21,7 +21,7 @@ TtStatus MessageQueue::put(const void* msg_ptr, uint32_t timeout) { stat = TtStatusOk; - if (kernel_is_irq() != 0U) { + if (kernel::isIrq() != 0U) { if ((queue_handle == nullptr) || (msg_ptr == nullptr) || (timeout != 0U)) { stat = TtStatusErrorParameter; } else { @@ -57,7 +57,7 @@ TtStatus MessageQueue::get(void* msg_ptr, uint32_t timeout_ticks) { stat = TtStatusOk; - if (kernel_is_irq() != 0U) { + if (kernel::isIrq() != 0U) { if ((queue_handle == nullptr) || (msg_ptr == nullptr) || (timeout_ticks != 0U)) { stat = TtStatusErrorParameter; } else { @@ -122,7 +122,7 @@ uint32_t MessageQueue::getCount() const { if (queue_handle == nullptr) { count = 0U; - } else if (kernel_is_irq() != 0U) { + } else if (kernel::isIrq() != 0U) { count = uxQueueMessagesWaitingFromISR(queue_handle); } else { count = uxQueueMessagesWaiting(queue_handle); @@ -139,7 +139,7 @@ uint32_t MessageQueue::getSpace() const { if (mq == nullptr) { space = 0U; - } else if (kernel_is_irq() != 0U) { + } else if (kernel::isIrq() != 0U) { isrm = taskENTER_CRITICAL_FROM_ISR(); /* space = pxQueue->uxLength - pxQueue->uxMessagesWaiting; */ @@ -157,7 +157,7 @@ uint32_t MessageQueue::getSpace() const { TtStatus MessageQueue::reset() { TtStatus stat; - if (kernel_is_irq() != 0U) { + if (kernel::isIrq() != 0U) { stat = TtStatusErrorISR; } else if (queue_handle == nullptr) { stat = TtStatusErrorParameter; diff --git a/TactilityCore/Source/Mutex.cpp b/TactilityCore/Source/Mutex.cpp index 5df8e39c..e2ba4cd6 100644 --- a/TactilityCore/Source/Mutex.cpp +++ b/TactilityCore/Source/Mutex.cpp @@ -22,13 +22,13 @@ namespace tt { #define tt_mutex_info(mutex, text) #endif -Mutex::Mutex(MutexType type) : type(type) { +Mutex::Mutex(Type type) : type(type) { tt_mutex_info(data, "alloc"); switch (type) { - case MutexTypeNormal: + case TypeNormal: semaphore = xSemaphoreCreateMutex(); break; - case MutexTypeRecursive: + case TypeRecursive: semaphore = xSemaphoreCreateRecursiveMutex(); break; default: @@ -51,7 +51,7 @@ TtStatus Mutex::acquire(uint32_t timeout) const { tt_mutex_info(mutex, "acquire"); switch (type) { - case MutexTypeNormal: + case TypeNormal: if (xSemaphoreTake(semaphore, timeout) != pdPASS) { if (timeout != 0U) { return TtStatusErrorTimeout; @@ -62,7 +62,7 @@ TtStatus Mutex::acquire(uint32_t timeout) const { return TtStatusOk; } break; - case MutexTypeRecursive: + case TypeRecursive: if (xSemaphoreTakeRecursive(semaphore, timeout) != pdPASS) { if (timeout != 0U) { return TtStatusErrorTimeout; @@ -84,7 +84,7 @@ TtStatus Mutex::release() const { tt_mutex_info(mutex, "release"); switch (type) { - case MutexTypeNormal: { + case TypeNormal: { if (xSemaphoreGive(semaphore) != pdPASS) { return TtStatusErrorResource; } else { @@ -92,7 +92,7 @@ TtStatus Mutex::release() const { } break; } - case MutexTypeRecursive: + case TypeRecursive: if (xSemaphoreGiveRecursive(semaphore) != pdPASS) { return TtStatusErrorResource; } else { @@ -115,7 +115,7 @@ std::unique_ptr Mutex::scoped() const { return std::move(std::make_unique(*this)); } -Mutex* tt_mutex_alloc(MutexType type) { +Mutex* tt_mutex_alloc(Mutex::Type type) { return new Mutex(type); } diff --git a/TactilityCore/Source/Mutex.h b/TactilityCore/Source/Mutex.h index 5c823268..26b79d43 100644 --- a/TactilityCore/Source/Mutex.h +++ b/TactilityCore/Source/Mutex.h @@ -14,21 +14,27 @@ namespace tt { class ScopedMutexUsage; -typedef enum { - MutexTypeNormal, - MutexTypeRecursive, -} MutexType; - /** * Wrapper for FreeRTOS xSemaphoreCreateMutex and xSemaphoreCreateRecursiveMutex * Can be used in IRQ mode (within ISR context) */ class Mutex { -private: - SemaphoreHandle_t semaphore; - MutexType type; + public: - explicit Mutex(MutexType type = MutexTypeNormal); + + enum Type { + TypeNormal, + TypeRecursive, + }; + +private: + + SemaphoreHandle_t semaphore; + Type type; + +public: + + explicit Mutex(Type type = TypeNormal); ~Mutex(); TtStatus acquire(uint32_t timeout) const; @@ -68,7 +74,7 @@ public: */ [[deprecated("use class")]] -Mutex* tt_mutex_alloc(MutexType type); +Mutex* tt_mutex_alloc(Mutex::Type type); /** Free Mutex * diff --git a/TactilityCore/Source/StringUtils.cpp b/TactilityCore/Source/StringUtils.cpp index daeb85ad..04ccdd52 100644 --- a/TactilityCore/Source/StringUtils.cpp +++ b/TactilityCore/Source/StringUtils.cpp @@ -3,9 +3,9 @@ #include #include -namespace tt { +namespace tt::string { -int string_find_last_index(const char* text, size_t from_index, char find) { +int findLastIndex(const char* text, size_t from_index, char find) { for (size_t i = from_index; i >= 0; i--) { if (text[i] == find) { return (int)i; @@ -14,8 +14,8 @@ int string_find_last_index(const char* text, size_t from_index, char find) { return -1; } -bool string_get_path_parent(const char* path, char* output) { - int index = string_find_last_index(path, strlen(path) - 1, '/'); +bool getPathParent(const char* path, char* output) { + int index = findLastIndex(path, strlen(path) - 1, '/'); if (index == -1) { return false; } else if (index == 0) { @@ -29,7 +29,7 @@ bool string_get_path_parent(const char* path, char* output) { } } -std::vector string_split(const std::string&input, const std::string&delimiter) { +std::vector split(const std::string&input, const std::string&delimiter) { size_t token_index = 0; size_t delimiter_index; const size_t delimiter_length = delimiter.length(); @@ -50,7 +50,7 @@ std::vector string_split(const std::string&input, const std::string return result; } -std::string string_join(const std::vector& input, const std::string& delimiter) { +std::string join(const std::vector& input, const std::string& delimiter) { std::stringstream stream; size_t size = input.size(); diff --git a/TactilityCore/Source/StringUtils.h b/TactilityCore/Source/StringUtils.h index d51a937c..e2ee8f20 100644 --- a/TactilityCore/Source/StringUtils.h +++ b/TactilityCore/Source/StringUtils.h @@ -4,7 +4,7 @@ #include #include -namespace tt { +namespace tt::string { /** * Find the last occurrence of a character. @@ -13,7 +13,7 @@ namespace tt { * @param[in] find the character to search for * @return the index of the found character, or -1 if none found */ -int string_find_last_index(const char* text, size_t from_index, char find); +int findLastIndex(const char* text, size_t from_index, char find); /** * Given a filesystem path as input, try and get the parent path. @@ -21,7 +21,7 @@ int string_find_last_index(const char* text, size_t from_index, char find); * @param[out] output an output buffer that is allocated to at least the size of "current" * @return true when successful */ -bool string_get_path_parent(const char* path, char* output); +bool getPathParent(const char* path, char* output); /** * Splits the provided input into separate pieces with delimiter as separator text. @@ -30,7 +30,7 @@ bool string_get_path_parent(const char* path, char* output); * @param input the input to split up * @param delimiter a non-empty string to recognize as separator */ -std::vector string_split(const std::string& input, const std::string& delimiter); +std::vector split(const std::string& input, const std::string& delimiter); /** * Join a set of tokens into a single string, given a delimiter (separator). @@ -40,6 +40,6 @@ std::vector string_split(const std::string& input, const std::strin * @param input the tokens to join together * @param delimiter the separator to join with */ -std::string string_join(const std::vector& input, const std::string& delimiter); +std::string join(const std::vector& input, const std::string& delimiter); } // namespace diff --git a/TactilityCore/Source/TactilityCore.h b/TactilityCore/Source/TactilityCore.h index 6760b319..e5616518 100644 --- a/TactilityCore/Source/TactilityCore.h +++ b/TactilityCore/Source/TactilityCore.h @@ -6,7 +6,10 @@ #include "CoreDefines.h" #include "CoreExtraDefines.h" #include "CoreTypes.h" -#include "critical/Critical.h" #include "EventFlag.h" -#include "Kernel.h" +#include "kernel/Kernel.h" +#include "kernel/critical/Critical.h" +#include "kernel/Kernel.h" #include "Log.h" +#include "Mutex.h" +#include "Thread.h" diff --git a/TactilityCore/Source/Thread.cpp b/TactilityCore/Source/Thread.cpp index 49ba3bc3..afb8c794 100644 --- a/TactilityCore/Source/Thread.cpp +++ b/TactilityCore/Source/Thread.cpp @@ -3,7 +3,7 @@ #include "Check.h" #include "CoreDefines.h" -#include "Kernel.h" +#include "kernel/Kernel.h" #include "Log.h" namespace tt { @@ -197,7 +197,7 @@ bool Thread::join() { // If your thread exited, but your app stuck here: some other thread uses // all cpu time, which delays kernel from releasing task handle while (data.taskHandle) { - delay_ms(10); + kernel::delayMillis(10); } return true; diff --git a/TactilityCore/Source/Timer.cpp b/TactilityCore/Source/Timer.cpp index b17fd1e5..59a7eff8 100644 --- a/TactilityCore/Source/Timer.cpp +++ b/TactilityCore/Source/Timer.cpp @@ -2,7 +2,7 @@ #include #include "Check.h" -#include "Kernel.h" +#include "kernel/Kernel.h" #include "RtosCompat.h" namespace tt { @@ -16,7 +16,7 @@ static void timer_callback(TimerHandle_t hTimer) { } Timer::Timer(Type type, Callback callback, std::shared_ptr callbackContext) { - tt_assert((kernel_is_irq() == 0U) && (callback != nullptr)); + tt_assert((kernel::isIrq() == 0U) && (callback != nullptr)); this->callback = callback; this->callbackContext = std::move(callbackContext); @@ -33,12 +33,12 @@ Timer::Timer(Type type, Callback callback, std::shared_ptr callbackContext } Timer::~Timer() { - tt_assert(!kernel_is_irq()); + tt_assert(!kernel::isIrq()); tt_check(xTimerDelete(timerHandle, portMAX_DELAY) == pdPASS); } TtStatus Timer::start(uint32_t ticks) { - tt_assert(!kernel_is_irq()); + tt_assert(!kernel::isIrq()); tt_assert(ticks < portMAX_DELAY); if (xTimerChangePeriod(timerHandle, ticks, portMAX_DELAY) == pdPASS) { @@ -49,7 +49,7 @@ TtStatus Timer::start(uint32_t ticks) { } TtStatus Timer::restart(uint32_t ticks) { - tt_assert(!kernel_is_irq()); + tt_assert(!kernel::isIrq()); tt_assert(ticks < portMAX_DELAY); if (xTimerChangePeriod(timerHandle, ticks, portMAX_DELAY) == pdPASS && @@ -61,24 +61,24 @@ TtStatus Timer::restart(uint32_t ticks) { } TtStatus Timer::stop() { - tt_assert(!kernel_is_irq()); + tt_assert(!kernel::isIrq()); tt_check(xTimerStop(timerHandle, portMAX_DELAY) == pdPASS); return TtStatusOk; } bool Timer::isRunning() { - tt_assert(!kernel_is_irq()); + tt_assert(!kernel::isIrq()); return xTimerIsTimerActive(timerHandle) == pdTRUE; } uint32_t Timer::getExpireTime() { - tt_assert(!kernel_is_irq()); + tt_assert(!kernel::isIrq()); return (uint32_t)xTimerGetExpiryTime(timerHandle); } void Timer::pendingCallback(PendingCallback callback, void* callbackContext, uint32_t arg) { BaseType_t ret = pdFAIL; - if (kernel_is_irq()) { + if (kernel::isIrq()) { ret = xTimerPendFunctionCallFromISR(callback, callbackContext, arg, nullptr); } else { ret = xTimerPendFunctionCall(callback, callbackContext, arg, TtWaitForever); @@ -87,7 +87,7 @@ void Timer::pendingCallback(PendingCallback callback, void* callbackContext, uin } void Timer::setThreadPriority(TimerThreadPriority priority) { - tt_assert(!kernel_is_irq()); + tt_assert(!kernel::isIrq()); TaskHandle_t task_handle = xTimerGetTimerDaemonTaskHandle(); tt_assert(task_handle); // Don't call this method before timer task start diff --git a/TactilityCore/Source/crypt/Crypt.cpp b/TactilityCore/Source/crypt/Crypt.cpp index 18a5db37..c0d64d21 100644 --- a/TactilityCore/Source/crypt/Crypt.cpp +++ b/TactilityCore/Source/crypt/Crypt.cpp @@ -4,6 +4,7 @@ #include "Log.h" #include "mbedtls/aes.h" #include +#include #ifdef ESP_PLATFORM #include "esp_cpu.h" @@ -95,7 +96,7 @@ static void get_nvs_key(uint8_t key[32]) { * @param[out] out output buffer for result of XOR * @param[in] length data length (all buffers must be at least this size) */ -static void xor_key(const uint8_t* in_left, const uint8_t* in_right, uint8_t* out, size_t length) { +static void xorKey(const uint8_t* in_left, const uint8_t* in_right, uint8_t* out, size_t length) { for (int i = 0; i < length; ++i) { out[i] = in_left[i] ^ in_right[i]; } @@ -105,7 +106,7 @@ static void xor_key(const uint8_t* in_left, const uint8_t* in_right, uint8_t* ou * Combines a stored key and a hardware key into a single reliable key value. * @param[out] key the key output */ -static void get_key(uint8_t key[32]) { +static void getKey(uint8_t key[32]) { #if !defined(CONFIG_SECURE_BOOT) || !defined(CONFIG_SECURE_FLASH_ENC_ENABLED) TT_LOG_W(TAG, "Using tt_secure_* code with secure boot and/or flash encryption disabled."); TT_LOG_W(TAG, "An attacker with physical access to your ESP32 can decrypt your secure data."); @@ -117,14 +118,14 @@ static void get_key(uint8_t key[32]) { #ifdef ESP_PLATFORM get_hardware_key(hardware_key); get_nvs_key(nvs_key); - xor_key(hardware_key, nvs_key, key, 32); + xorKey(hardware_key, nvs_key, key, 32); #else TT_LOG_W(TAG, "Using unsafe key for debugging purposes."); memset(key, 0, 32); #endif } -void get_iv_from_data(const void* data, size_t data_length, uint8_t iv[16]) { +void getIv(const void* data, size_t data_length, uint8_t iv[16]) { memset((void*)iv, 0, 16); uint8_t* data_bytes = (uint8_t*)data; for (int i = 0; i < data_length; ++i) { @@ -133,11 +134,7 @@ void get_iv_from_data(const void* data, size_t data_length, uint8_t iv[16]) { } } -void get_iv_from_string(const char* input, uint8_t iv[16]) { - get_iv_from_data((const void*)input, strlen(input), iv); -} - -static int aes256_crypt_cbc( +static int aes256CryptCbc( const uint8_t key[32], int mode, size_t length, @@ -166,25 +163,25 @@ static int aes256_crypt_cbc( int encrypt(const uint8_t iv[16], uint8_t* in_data, uint8_t* out_data, size_t length) { tt_check(length % 16 == 0, "Length is not a multiple of 16 bytes (for AES 256"); uint8_t key[32]; - get_key(key); + getKey(key); // TODO: Is this still needed after switching to regular AES functions? uint8_t iv_copy[16]; memcpy(iv_copy, iv, sizeof(iv_copy)); - return aes256_crypt_cbc(key, MBEDTLS_AES_ENCRYPT, length, iv_copy, in_data, out_data); + return aes256CryptCbc(key, MBEDTLS_AES_ENCRYPT, length, iv_copy, in_data, out_data); } int decrypt(const uint8_t iv[16], uint8_t* in_data, uint8_t* out_data, size_t length) { tt_check(length % 16 == 0, "Length is not a multiple of 16 bytes (for AES 256"); uint8_t key[32]; - get_key(key); + getKey(key); // TODO: Is this still needed after switching to regular AES functions? uint8_t iv_copy[16]; memcpy(iv_copy, iv, sizeof(iv_copy)); - return aes256_crypt_cbc(key, MBEDTLS_AES_DECRYPT, length, iv_copy, in_data, out_data); + return aes256CryptCbc(key, MBEDTLS_AES_DECRYPT, length, iv_copy, in_data, out_data); } } // namespace diff --git a/TactilityCore/Source/crypt/Crypt.h b/TactilityCore/Source/crypt/Crypt.h index b2ae33f7..6ced0483 100644 --- a/TactilityCore/Source/crypt/Crypt.h +++ b/TactilityCore/Source/crypt/Crypt.h @@ -20,6 +20,7 @@ #include #include +#include namespace tt::crypt { @@ -29,14 +30,7 @@ namespace tt::crypt { * @param data_length input data length * @param iv output IV */ -void get_iv_from_data(const void* data, size_t data_length, uint8_t iv[16]); - -/** -* @brief Fills the IV with zeros and then creates an IV based on the input data. - * @param input input text - * @param iv output IV - */ -void get_iv_from_string(const char* input, uint8_t iv[16]); +void getIv(const void* data, size_t data_length, uint8_t iv[16]); /** * @brief Encrypt data. diff --git a/TactilityCore/Source/Kernel.cpp b/TactilityCore/Source/kernel/Kernel.cpp similarity index 82% rename from TactilityCore/Source/Kernel.cpp rename to TactilityCore/Source/kernel/Kernel.cpp index 98c65b9c..26f97cfa 100644 --- a/TactilityCore/Source/Kernel.cpp +++ b/TactilityCore/Source/kernel/Kernel.cpp @@ -1,4 +1,4 @@ -#include "Kernel.h" +#include "kernel/Kernel.h" #include "Check.h" #include "CoreDefines.h" #include "CoreTypes.h" @@ -10,18 +10,18 @@ #include #endif -namespace tt { +namespace tt::kernel { -bool kernel_is_irq() { +bool isIrq() { return TT_IS_IRQ_MODE(); } -bool kernel_is_running() { +bool isRunning() { return xTaskGetSchedulerState() != taskSCHEDULER_RUNNING; } -int32_t kernel_lock() { - tt_assert(!kernel_is_irq()); +int32_t lock() { + tt_assert(!isIrq()); int32_t lock; @@ -45,8 +45,8 @@ int32_t kernel_lock() { return (lock); } -int32_t kernel_unlock() { - tt_assert(!kernel_is_irq()); +int32_t unlock() { + tt_assert(!isIrq()); int32_t lock; @@ -75,8 +75,8 @@ int32_t kernel_unlock() { return (lock); } -int32_t kernel_restore_lock(int32_t lock) { - tt_assert(!kernel_is_irq()); +int32_t restoreLock(int32_t lock) { + tt_assert(!isIrq()); switch (xTaskGetSchedulerState()) { case taskSCHEDULER_SUSPENDED: @@ -106,13 +106,13 @@ int32_t kernel_restore_lock(int32_t lock) { return (lock); } -uint32_t kernel_get_tick_frequency() { +uint32_t getTickFrequency() { /* Return frequency in hertz */ return (configTICK_RATE_HZ); } -void delay_ticks(TickType_t ticks) { - tt_assert(!kernel_is_irq()); +void delayTicks(TickType_t ticks) { + tt_assert(!isIrq()); if (ticks == 0U) { taskYIELD(); } else { @@ -120,8 +120,8 @@ void delay_ticks(TickType_t ticks) { } } -TtStatus delay_until_tick(TickType_t tick) { - tt_assert(!kernel_is_irq()); +TtStatus delayUntilTick(TickType_t tick) { + tt_assert(!isIrq()); TickType_t tcnt, delay; TtStatus stat; @@ -147,10 +147,10 @@ TtStatus delay_until_tick(TickType_t tick) { return (stat); } -TickType_t get_ticks() { +TickType_t getTicks() { TickType_t ticks; - if (kernel_is_irq() != 0U) { + if (isIrq() != 0U) { ticks = xTaskGetTickCountFromISR(); } else { ticks = xTaskGetTickCount(); @@ -159,7 +159,7 @@ TickType_t get_ticks() { return ticks; } -TickType_t ms_to_ticks(uint32_t milliseconds) { +TickType_t millisToTicks(uint32_t milliseconds) { #if configTICK_RATE_HZ == 1000 return (TickType_t)milliseconds; #else @@ -167,7 +167,7 @@ TickType_t ms_to_ticks(uint32_t milliseconds) { #endif } -void delay_ms(uint32_t milliseconds) { +void delayMillis(uint32_t milliseconds) { if (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) { if (milliseconds > 0 && milliseconds < portMAX_DELAY - 1) { milliseconds += 1; @@ -175,14 +175,14 @@ void delay_ms(uint32_t milliseconds) { #if configTICK_RATE_HZ_RAW == 1000 tt_delay_tick(milliseconds); #else - delay_ticks(ms_to_ticks(milliseconds)); + delayTicks(kernel::millisToTicks(milliseconds)); #endif } else if (milliseconds > 0) { - delay_us(milliseconds * 1000); + kernel::delayMicros(milliseconds * 1000); } } -void delay_us(uint32_t microseconds) { +void delayMicros(uint32_t microseconds) { #ifdef ESP_PLATFORM ets_delay_us(microseconds); #else @@ -190,7 +190,7 @@ void delay_us(uint32_t microseconds) { #endif } -Platform get_platform() { +Platform getPlatform() { #ifdef ESP_PLATFORM return PlatformEsp; #else diff --git a/TactilityCore/Source/Kernel.h b/TactilityCore/Source/kernel/Kernel.h similarity index 82% rename from TactilityCore/Source/Kernel.h rename to TactilityCore/Source/kernel/Kernel.h index dbd532c5..19b29d92 100644 --- a/TactilityCore/Source/Kernel.h +++ b/TactilityCore/Source/kernel/Kernel.h @@ -8,7 +8,7 @@ #include "FreeRTOS.h" #endif -namespace tt { +namespace tt::kernel { typedef enum { PlatformEsp, @@ -30,13 +30,13 @@ typedef enum { * * @return true if CPU is in IRQ or kernel running and IRQ is masked */ -bool kernel_is_irq(); +bool isIrq(); /** Check if kernel is running * * @return true if running, false otherwise */ -bool kernel_is_running(); +bool isRunning(); /** Lock kernel, pause process scheduling * @@ -44,7 +44,7 @@ bool kernel_is_running(); * * @return previous lock state(0 - unlocked, 1 - locked) */ -int32_t kernel_lock(); +int32_t lock(); /** Unlock kernel, resume process scheduling * @@ -52,7 +52,7 @@ int32_t kernel_lock(); * * @return previous lock state(0 - unlocked, 1 - locked) */ -int32_t kernel_unlock(); +int32_t unlock(); /** Restore kernel lock state * @@ -62,15 +62,15 @@ int32_t kernel_unlock(); * * @return new lock state or error */ -int32_t kernel_restore_lock(int32_t lock); +int32_t restoreLock(int32_t lock); /** Get kernel systick frequency * * @return systick counts per second */ -uint32_t kernel_get_tick_frequency(); +uint32_t getTickFrequency(); -TickType_t get_ticks(); +TickType_t getTicks(); /** Delay execution * @@ -80,7 +80,7 @@ TickType_t get_ticks(); * * @param[in] ticks The ticks count to pause */ -void delay_ticks(TickType_t ticks); +void delayTicks(TickType_t ticks); /** Delay until tick * @@ -90,14 +90,14 @@ void delay_ticks(TickType_t ticks); * * @return The status. */ -TtStatus delay_until_tick(uint32_t tick); +TtStatus delayUntilTick(uint32_t tick); /** Convert milliseconds to ticks * - * @param[in] milliseconds time in milliseconds + * @param[in] milliSeconds time in milliseconds * @return time in ticks */ -TickType_t ms_to_ticks(uint32_t milliseconds); +TickType_t millisToTicks(uint32_t milliSeconds); /** Delay in milliseconds * @@ -108,18 +108,18 @@ TickType_t ms_to_ticks(uint32_t milliseconds); * * @warning Cannot be used from ISR * - * @param[in] milliseconds milliseconds to wait + * @param[in] milliSeconds milliseconds to wait */ -void delay_ms(uint32_t milliseconds); +void delayMillis(uint32_t milliSeconds); /** Delay in microseconds * * Implemented using Cortex DWT counter. Blocking and non aliased. * - * @param[in] microseconds microseconds to wait + * @param[in] microSeconds microseconds to wait */ -void delay_us(uint32_t microseconds); +void delayMicros(uint32_t microSeconds); -Platform get_platform(); +Platform getPlatform(); } // namespace diff --git a/TactilityCore/Source/critical/Critical.cpp b/TactilityCore/Source/kernel/critical/Critical.cpp similarity index 65% rename from TactilityCore/Source/critical/Critical.cpp rename to TactilityCore/Source/kernel/critical/Critical.cpp index 24ae200e..7c5cd2f7 100644 --- a/TactilityCore/Source/critical/Critical.cpp +++ b/TactilityCore/Source/kernel/critical/Critical.cpp @@ -9,18 +9,18 @@ static portMUX_TYPE critical_mutex; #define TT_ENTER_CRITICAL() taskENTER_CRITICAL() #endif -namespace tt::critical { +namespace tt::kernel::critical { TtCriticalInfo enter() { - TtCriticalInfo info; + TtCriticalInfo info = { + .isrm = 0, + .fromIsr = TT_IS_ISR(), + .kernelRunning = (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) + }; - info.isrm = 0; - info.from_isr = TT_IS_ISR(); - info.kernel_running = (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING); - - if (info.from_isr) { + if (info.fromIsr) { info.isrm = taskENTER_CRITICAL_FROM_ISR(); - } else if (info.kernel_running) { + } else if (info.kernelRunning) { TT_ENTER_CRITICAL(); } else { portDISABLE_INTERRUPTS(); @@ -30,9 +30,9 @@ TtCriticalInfo enter() { } void exit(TtCriticalInfo info) { - if (info.from_isr) { + if (info.fromIsr) { taskEXIT_CRITICAL_FROM_ISR(info.isrm); - } else if (info.kernel_running) { + } else if (info.kernelRunning) { TT_ENTER_CRITICAL(); } else { portENABLE_INTERRUPTS(); diff --git a/TactilityCore/Source/critical/Critical.h b/TactilityCore/Source/kernel/critical/Critical.h similarity index 83% rename from TactilityCore/Source/critical/Critical.h rename to TactilityCore/Source/kernel/critical/Critical.h index fc404924..e5706c6e 100644 --- a/TactilityCore/Source/critical/Critical.h +++ b/TactilityCore/Source/kernel/critical/Critical.h @@ -10,12 +10,12 @@ #define TT_CRITICAL_EXIT() __tt_critical_exit(__tt_critical_info); #endif -namespace tt::critical { +namespace tt::kernel::critical { typedef struct { uint32_t isrm; - bool from_isr; - bool kernel_running; + bool fromIsr; + bool kernelRunning; } TtCriticalInfo; TtCriticalInfo enter(); diff --git a/TactilityHeadless/CMakeLists.txt b/TactilityHeadless/CMakeLists.txt index 87a1f975..cf9415a4 100644 --- a/TactilityHeadless/CMakeLists.txt +++ b/TactilityHeadless/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.16) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) if (DEFINED ENV{ESP_IDF_VERSION}) diff --git a/TactilityHeadless/Private/service/ServiceInstance.h b/TactilityHeadless/Private/service/ServiceInstance.h index 142c9e79..b3d9577f 100644 --- a/TactilityHeadless/Private/service/ServiceInstance.h +++ b/TactilityHeadless/Private/service/ServiceInstance.h @@ -8,7 +8,7 @@ class ServiceInstance : public ServiceContext { private: - Mutex mutex = Mutex(MutexTypeNormal); + Mutex mutex = Mutex(Mutex::TypeNormal); const service::ServiceManifest& manifest; std::shared_ptr data = nullptr; diff --git a/TactilityHeadless/Source/TactilityHeadless.h b/TactilityHeadless/Source/TactilityHeadless.h index bf92b5f2..b714f409 100644 --- a/TactilityHeadless/Source/TactilityHeadless.h +++ b/TactilityHeadless/Source/TactilityHeadless.h @@ -1,5 +1,6 @@ #pragma once +#include "TactilityCore.h" #include "hal/Configuration.h" #include "TactilityHeadlessConfig.h" #include "Dispatcher.h" diff --git a/TactilityHeadless/Source/hal/i2c/I2cMock.cpp b/TactilityHeadless/Source/hal/i2c/I2cMock.cpp index b256f272..f4f0e88f 100644 --- a/TactilityHeadless/Source/hal/i2c/I2cMock.cpp +++ b/TactilityHeadless/Source/hal/i2c/I2cMock.cpp @@ -3,10 +3,8 @@ /** * This code is based on i2c_manager from https://github.com/ropg/i2c_manager/blob/master/i2c_manager/i2c_manager.c (original has MIT license) */ -#include +#include "TactilityCore.h" #include "I2c.h" -#include "Log.h" -#include "Mutex.h" namespace tt::hal::i2c { diff --git a/TactilityHeadless/Source/hal/sdcard/Sdcard.cpp b/TactilityHeadless/Source/hal/sdcard/Sdcard.cpp index 7968348c..20622ed9 100644 --- a/TactilityHeadless/Source/hal/sdcard/Sdcard.cpp +++ b/TactilityHeadless/Source/hal/sdcard/Sdcard.cpp @@ -7,7 +7,7 @@ namespace tt::hal::sdcard { #define TAG "sdcard" -static Mutex mutex(MutexTypeRecursive); +static Mutex mutex(Mutex::TypeRecursive); typedef struct { const SdCard* sdcard; diff --git a/TactilityHeadless/Source/service/ServiceRegistry.cpp b/TactilityHeadless/Source/service/ServiceRegistry.cpp index 1fb0fbda..022f1771 100644 --- a/TactilityHeadless/Source/service/ServiceRegistry.cpp +++ b/TactilityHeadless/Source/service/ServiceRegistry.cpp @@ -17,8 +17,8 @@ typedef std::unordered_map ServiceInstanceMap; static ManifestMap service_manifest_map; static ServiceInstanceMap service_instance_map; -static Mutex manifest_mutex(MutexTypeNormal); -static Mutex instance_mutex(MutexTypeNormal); +static Mutex manifest_mutex(Mutex::TypeNormal); +static Mutex instance_mutex(Mutex::TypeNormal); void addService(const ServiceManifest* manifest) { TT_LOG_I(TAG, "Adding %s", manifest->id.c_str()); diff --git a/TactilityHeadless/Source/service/sdcard/Sdcard.cpp b/TactilityHeadless/Source/service/sdcard/Sdcard.cpp index 8a7b1707..b68e43b1 100644 --- a/TactilityHeadless/Source/service/sdcard/Sdcard.cpp +++ b/TactilityHeadless/Source/service/sdcard/Sdcard.cpp @@ -42,7 +42,7 @@ static void onUpdate(std::shared_ptr context) { if (new_state == hal::sdcard::StateError) { TT_LOG_W(TAG, "Sdcard error - unmounting. Did you eject the card in an unsafe manner?"); - hal::sdcard::unmount(ms_to_ticks(1000)); + hal::sdcard::unmount(kernel::millisToTicks(1000)); } if (new_state != data->lastState) { diff --git a/TactilityHeadless/Source/service/wifi/WifiEsp.cpp b/TactilityHeadless/Source/service/wifi/WifiEsp.cpp index 2e991968..d1011b50 100644 --- a/TactilityHeadless/Source/service/wifi/WifiEsp.cpp +++ b/TactilityHeadless/Source/service/wifi/WifiEsp.cpp @@ -2,15 +2,10 @@ #include "Wifi.h" -#include "MessageQueue.h" -#include "Mutex.h" -#include "Check.h" -#include "Log.h" +#include "TactilityHeadless.h" #include "Timer.h" #include "service/ServiceContext.h" #include "WifiSettings.h" -#include "TactilityCore.h" -#include "TactilityHeadless.h" #include "freertos/FreeRTOS.h" @@ -47,8 +42,8 @@ private: public: /** @brief Locking mechanism for modifying the Wifi instance */ - Mutex radioMutex = Mutex(MutexTypeRecursive); - Mutex dataMutex = Mutex(MutexTypeRecursive); + Mutex radioMutex = Mutex(Mutex::TypeRecursive); + Mutex dataMutex = Mutex(Mutex::TypeRecursive); std::unique_ptr autoConnectTimer; /** @brief The public event bus */ std::shared_ptr pubsub = std::make_shared(); @@ -664,7 +659,7 @@ static void dispatchScan(std::shared_ptr context) { } // TODO: Thread safety - wifi->last_scan_time = tt::get_ticks(); + wifi->last_scan_time = tt::kernel::getTicks(); if (esp_wifi_scan_start(nullptr, false) != ESP_OK) { TT_LOG_I(TAG, "Can't start scan"); @@ -872,7 +867,7 @@ static bool shouldScanForAutoConnect(std::shared_ptr wifi) { return false; } - TickType_t current_time = tt::get_ticks(); + TickType_t current_time = tt::kernel::getTicks(); bool scan_time_has_looped = (current_time < wifi->last_scan_time); bool no_recent_scan = (current_time - wifi->last_scan_time) > (AUTO_SCAN_INTERVAL / portTICK_PERIOD_MS); diff --git a/TactilityHeadless/Source/service/wifi/WifiMock.cpp b/TactilityHeadless/Source/service/wifi/WifiMock.cpp index a98e457e..3f907651 100644 --- a/TactilityHeadless/Source/service/wifi/WifiMock.cpp +++ b/TactilityHeadless/Source/service/wifi/WifiMock.cpp @@ -49,7 +49,7 @@ static void publish_event_simple(Wifi* wifi, WifiEventType type) { static Wifi* wifi_alloc() { auto* instance = static_cast(malloc(sizeof(Wifi))); - instance->mutex = tt_mutex_alloc(MutexTypeRecursive); + instance->mutex = tt_mutex_alloc(Mutex::TypeRecursive); instance->pubsub = std::make_shared(); instance->scan_active = false; instance->radio_state = WIFI_RADIO_CONNECTION_ACTIVE; diff --git a/TactilityHeadless/Source/service/wifi/WifiSettingsEsp.cpp b/TactilityHeadless/Source/service/wifi/WifiSettingsEsp.cpp index 83a8e2ec..bebc0131 100644 --- a/TactilityHeadless/Source/service/wifi/WifiSettingsEsp.cpp +++ b/TactilityHeadless/Source/service/wifi/WifiSettingsEsp.cpp @@ -54,7 +54,7 @@ bool load(const char* ssid, WifiApSettings* settings) { result = nvs_get_blob(handle, ssid, &encrypted_settings, &length); uint8_t iv[16]; - crypt::get_iv_from_string(ssid, iv); + crypt::getIv(ssid, strlen(ssid), iv); int decrypt_result = crypt::decrypt( iv, (uint8_t*)encrypted_settings.password, @@ -97,7 +97,7 @@ bool save(const WifiApSettings* settings) { encrypted_settings.password[TT_WIFI_CREDENTIALS_PASSWORD_LIMIT] = 0; uint8_t iv[16]; - crypt::get_iv_from_data(settings->ssid, strlen(settings->ssid), iv); + crypt::getIv(settings->ssid, strlen(settings->ssid), iv); int encrypt_result = crypt::encrypt( iv, (uint8_t*)settings->password, diff --git a/Tests/TactilityCore/DispatcherTest.cpp b/Tests/TactilityCore/DispatcherTest.cpp index f6045431..e238041f 100644 --- a/Tests/TactilityCore/DispatcherTest.cpp +++ b/Tests/TactilityCore/DispatcherTest.cpp @@ -14,7 +14,7 @@ void increment_callback(TT_UNUSED std::shared_ptr context) { void value_checker(std::shared_ptr context) { auto value = std::static_pointer_cast(context); if (*value != value_chacker_expected) { - tt_crash_implementation(); + tt_crash("Test error"); } } @@ -24,7 +24,7 @@ TEST_CASE("dispatcher should not call callback if consume isn't called") { auto context = std::make_shared(); dispatcher.dispatch(&increment_callback, std::move(context)); - delay_ticks(10); + kernel::delayTicks(10); CHECK_EQ(counter, 0); } diff --git a/Tests/TactilityCore/MutexTest.cpp b/Tests/TactilityCore/MutexTest.cpp index 40c4ca9a..3e3203f4 100644 --- a/Tests/TactilityCore/MutexTest.cpp +++ b/Tests/TactilityCore/MutexTest.cpp @@ -11,7 +11,7 @@ static int thread_with_mutex_parameter(void* parameter) { } TEST_CASE("a mutex can block a thread") { - auto* mutex = tt_mutex_alloc(MutexTypeNormal); + auto* mutex = tt_mutex_alloc(Mutex::TypeNormal); tt_mutex_acquire(mutex, TtWaitForever); Thread* thread = new Thread( @@ -22,12 +22,12 @@ TEST_CASE("a mutex can block a thread") { ); thread->start(); - delay_ms(5); + kernel::delayMillis(5); CHECK_EQ(thread->getState(), Thread::StateRunning); tt_mutex_release(mutex); - delay_ms(5); + kernel::delayMillis(5); CHECK_EQ(thread->getState(), Thread::StateStopped); thread->join(); diff --git a/Tests/TactilityCore/StringTest.cpp b/Tests/TactilityCore/StringTest.cpp index de19bba9..d27a7b79 100644 --- a/Tests/TactilityCore/StringTest.cpp +++ b/Tests/TactilityCore/StringTest.cpp @@ -1,66 +1,63 @@ #include "doctest.h" #include "StringUtils.h" -using namespace tt; -using namespace std; - -// region string_split +// region split TEST_CASE("splitting an empty string results in an empty vector") { - auto result = string_split("", "."); + auto result = tt::string::split("", "."); CHECK_EQ(result.empty(), true); } TEST_CASE("splitting a string with a single token results in a vector with that token") { - auto result = string_split("token", "."); + auto result = tt::string::split("token", "."); CHECK_EQ(result.size(), 1); CHECK_EQ(result.front(), "token"); } TEST_CASE("splitting a string with multiple tokens results in a vector with those tokens") { - auto result = string_split("token1;token2;token3;", ";"); + auto result = tt::string::split("token1;token2;token3;", ";"); CHECK_EQ(result.size(), 3); CHECK_EQ(result[0], "token1"); CHECK_EQ(result[1], "token2"); CHECK_EQ(result[2], "token3"); } -// endregion string_split +// endregion split -// region string_join +// region join TEST_CASE("joining an empty vector results in an empty string") { - vector tokens = {}; - auto result = string_join(tokens, "."); + std::vector tokens = {}; + auto result = tt::string::join(tokens, "."); CHECK_EQ(result, ""); } TEST_CASE("joining a single token results in a string with that value") { - vector tokens = { + std::vector tokens = { "token" }; - auto result = string_join(tokens, "."); + auto result = tt::string::join(tokens, "."); CHECK_EQ(result, "token"); } TEST_CASE("joining multiple tokens results in a string with all the tokens and the delimiter") { - vector tokens = { + std::vector tokens = { "token1", "token2", "token3", }; - auto result = string_join(tokens, "."); + auto result = tt::string::join(tokens, "."); CHECK_EQ(result, "token1.token2.token3"); } TEST_CASE("joining with empty tokens leads to an extra delimiter") { - vector tokens = { + std::vector tokens = { "token1", "", "token2", }; - auto result = string_join(tokens, "."); + auto result = tt::string::join(tokens, "."); CHECK_EQ(result, "token1..token2"); } -// endregion string_join +// endregion join diff --git a/Tests/TactilityCore/ThreadTest.cpp b/Tests/TactilityCore/ThreadTest.cpp index 20496c4d..193d8470 100644 --- a/Tests/TactilityCore/ThreadTest.cpp +++ b/Tests/TactilityCore/ThreadTest.cpp @@ -7,7 +7,7 @@ using namespace tt; static int interruptable_thread(void* parameter) { bool* interrupted = (bool*)parameter; while (!*interrupted) { - delay_ms(5); + kernel::delayMillis(5); } return 0; } diff --git a/Tests/TactilityCore/TimerTest.cpp b/Tests/TactilityCore/TimerTest.cpp index 8c8d1b84..ef3d86f7 100644 --- a/Tests/TactilityCore/TimerTest.cpp +++ b/Tests/TactilityCore/TimerTest.cpp @@ -20,7 +20,7 @@ TEST_CASE("a timer passes the context correctly") { auto foo = std::make_shared(1); auto* timer = new Timer(Timer::TypeOnce, &timer_callback_with_context, foo); timer->start(1); - delay_ticks(10); + kernel::delayTicks(10); timer->stop(); delete timer; @@ -31,10 +31,10 @@ TEST_CASE("TimerTypePeriodic timers can be stopped and restarted") { auto counter = std::make_shared(0); auto* timer = new Timer(Timer::TypePeriodic, &timer_callback_with_counter, counter); timer->start(1); - delay_ticks(10); + kernel::delayTicks(10); timer->stop(); timer->start(1); - delay_ticks(10); + kernel::delayTicks(10); timer->stop(); delete timer; @@ -46,7 +46,7 @@ TEST_CASE("TimerTypePeriodic calls the callback periodically") { int ticks_to_run = 10; auto* timer = new Timer(Timer::TypePeriodic, &timer_callback_with_counter, counter); timer->start(1); - delay_ticks(ticks_to_run); + kernel::delayTicks(ticks_to_run); timer->stop(); delete timer; @@ -57,10 +57,10 @@ TEST_CASE("restarting TimerTypeOnce timers calls the callback again") { auto counter = std::make_shared(0); auto* timer = new Timer(Timer::TypeOnce, &timer_callback_with_counter, counter); timer->start(1); - delay_ticks(10); + kernel::delayTicks(10); timer->stop(); timer->start(1); - delay_ticks(10); + kernel::delayTicks(10); timer->stop(); delete timer;