diff --git a/AppEsp32/Source/HelloWorld/HelloWorld.cpp b/AppEsp32/Source/HelloWorld/HelloWorld.cpp index 6c8e4a6b..79b3a05d 100644 --- a/AppEsp32/Source/HelloWorld/HelloWorld.cpp +++ b/AppEsp32/Source/HelloWorld/HelloWorld.cpp @@ -1,7 +1,7 @@ #include "lvgl.h" -#include "Ui/Toolbar.h" +#include "ui/Toolbar.h" -static void app_show(tt::App app, lv_obj_t* parent) { +static void app_show(tt::app::App app, lv_obj_t* parent) { lv_obj_t* toolbar = tt::lvgl::toolbar_create(parent, app); lv_obj_align(toolbar, LV_ALIGN_TOP_MID, 0, 0); @@ -10,9 +10,9 @@ static void app_show(tt::App app, lv_obj_t* parent) { lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); } -extern const tt::AppManifest hello_world_app = { +extern const tt::app::Manifest hello_world_app = { .id = "HelloWorld", .name = "Hello World", - .type = tt::AppTypeUser, + .type = tt::app::TypeUser, .on_show = &app_show, }; diff --git a/AppEsp32/Source/Main.cpp b/AppEsp32/Source/Main.cpp index ea99c8ce..3a69f482 100644 --- a/AppEsp32/Source/Main.cpp +++ b/AppEsp32/Source/Main.cpp @@ -7,7 +7,7 @@ namespace tt::service::wifi { extern void wifi_main(void*); } -extern const tt::AppManifest hello_world_app; +extern const tt::app::Manifest hello_world_app; extern "C" { diff --git a/AppSim/Source/HelloWorld/hello_world.cpp b/AppSim/Source/HelloWorld/hello_world.cpp index 5a7081e6..f2848fd6 100644 --- a/AppSim/Source/HelloWorld/hello_world.cpp +++ b/AppSim/Source/HelloWorld/hello_world.cpp @@ -1,6 +1,6 @@ -#include "Ui/Toolbar.h" +#include "ui/Toolbar.h" -static void app_show(tt::App app, lv_obj_t* parent) { +static void app_show(tt::app::App app, lv_obj_t* parent) { lv_obj_t* toolbar = tt::lvgl::toolbar_create(parent, app); lv_obj_align(toolbar, LV_ALIGN_TOP_MID, 0, 0); @@ -9,9 +9,9 @@ static void app_show(tt::App app, lv_obj_t* parent) { lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); } -extern const tt::AppManifest hello_world_app = { +extern const tt::app::Manifest hello_world_app = { .id = "HelloWorld", .name = "Hello World", - .type = tt::AppTypeUser, + .type = tt::app::TypeUser, .on_show = &app_show }; diff --git a/AppSim/Source/hardware_config.cpp b/AppSim/Source/hardware_config.cpp index e69d2f52..0ad09f2b 100644 --- a/AppSim/Source/hardware_config.cpp +++ b/AppSim/Source/hardware_config.cpp @@ -1,4 +1,4 @@ -#include "Hal/Configuration.h" +#include "hal/Configuration.h" #include "lvgl_task.h" #include "src/lv_init.h" diff --git a/AppSim/Source/lvgl_hal.cpp b/AppSim/Source/lvgl_hal.cpp index 98d5c7f1..88c70fd2 100644 --- a/AppSim/Source/lvgl_hal.cpp +++ b/AppSim/Source/lvgl_hal.cpp @@ -1,5 +1,5 @@ #include "lvgl.h" -#include "Ui/LvglKeypad.h" +#include "ui/LvglKeypad.h" lv_display_t* lvgl_hal_init() { static lv_display_t* display = NULL; diff --git a/AppSim/Source/lvgl_task.cpp b/AppSim/Source/lvgl_task.cpp index 44ba9c34..fd8aecb8 100644 --- a/AppSim/Source/lvgl_task.cpp +++ b/AppSim/Source/lvgl_task.cpp @@ -5,30 +5,28 @@ #include "lvgl_hal.h" #include "TactilityCore.h" #include "Thread.h" -#include "Ui/LvglSync.h" +#include "ui/LvglSync.h" -#include "FreeRTOS.h" -#include "semphr.h" +#include "Mutex.h" #define TAG "lvgl_task" // Mutex for LVGL drawing -static QueueHandle_t lvgl_mutex = NULL; +static tt::Mutex lvgl_mutex(tt::MutexTypeRecursive); +static tt::Mutex task_mutex(tt::MutexTypeRecursive); + static uint32_t task_max_sleep_ms = 10; // Mutex for LVGL task state (to modify task_running state) -static QueueHandle_t task_mutex = NULL; static bool task_running = false; static void lvgl_task(void* arg); static bool task_lock(int timeout_ticks) { - assert(task_mutex != NULL); - return xSemaphoreTakeRecursive(task_mutex, timeout_ticks) == pdTRUE; + return task_mutex.acquire(timeout_ticks) == tt::TtStatusOk; } static void task_unlock() { - assert(task_mutex != NULL); - xSemaphoreGiveRecursive(task_mutex); + task_mutex.release(); } static void task_set_running(bool running) { @@ -45,35 +43,23 @@ bool lvgl_task_is_running() { } static bool lvgl_lock(uint32_t timeout_ticks) { - assert(lvgl_mutex != NULL); - return xSemaphoreTakeRecursive(lvgl_mutex, timeout_ticks) == pdTRUE; + return lvgl_mutex.acquire(timeout_ticks) == tt::TtStatusOk; } static void lvgl_unlock() { - assert(lvgl_mutex != NULL); - xSemaphoreGiveRecursive(lvgl_mutex); + lvgl_mutex.release(); } void lvgl_task_interrupt() { - tt_check(lvgl_lock(tt::TtWaitForever)); + tt_check(task_lock(tt::TtWaitForever)); task_set_running(false); // interrupt task with boolean as flag - lvgl_unlock(); + task_unlock(); } void lvgl_task_start() { TT_LOG_I(TAG, "lvgl task starting"); - if (lvgl_mutex == NULL) { - TT_LOG_D(TAG, "init: creating lvgl mutex"); - lvgl_mutex = xSemaphoreCreateRecursiveMutex(); - } - - if (task_mutex == NULL) { - TT_LOG_D(TAG, "init: creating task mutex"); - task_mutex = xSemaphoreCreateRecursiveMutex(); - } - - tt::lvgl::sync_set(&lvgl_lock, &lvgl_unlock); + tt::lvgl::syncSet(&lvgl_lock, &lvgl_unlock); // Create the main app loop, like ESP-IDF BaseType_t task_result = xTaskCreate( @@ -98,7 +84,7 @@ static void lvgl_task(TT_UNUSED void* arg) { task_set_running(true); while (lvgl_task_is_running()) { - if (lvgl_lock(0)) { + if (lvgl_lock(10)) { task_delay_ms = lv_timer_handler(); lvgl_unlock(); } diff --git a/AppSim/Source/main.cpp b/AppSim/Source/main.cpp index ccb649bf..acc468ba 100644 --- a/AppSim/Source/main.cpp +++ b/AppSim/Source/main.cpp @@ -1,7 +1,7 @@ #include "Tactility.h" extern const tt::hal::Configuration sim_hardware; -extern const tt::AppManifest hello_world_app; +extern const tt::app::Manifest hello_world_app; void app_main() { static const tt::Configuration config = { diff --git a/AppSim/Source/power.cpp b/AppSim/Source/power.cpp index 6983eb2d..a97df182 100644 --- a/AppSim/Source/power.cpp +++ b/AppSim/Source/power.cpp @@ -1,4 +1,4 @@ -#include "Hal/Power.h" +#include "hal/Power.h" static bool is_charging_enabled = false; @@ -23,9 +23,9 @@ static int32_t power_get_current() { } extern const tt::hal::Power power = { - .is_charging = &power_is_charging, - .is_charging_enabled = &power_is_charging_enabled, - .set_charging_enabled = &power_set_charging_enabled, - .get_charge_level = &power_get_charge_level, - .get_current = &power_get_current + .isCharging = &power_is_charging, + .isChargingEnabled = &power_is_charging_enabled, + .setChargingEnabled = &power_set_charging_enabled, + .getChargeLevel = &power_get_charge_level, + .getCurrent = &power_get_current }; diff --git a/Boards/LilygoTdeck/keyboard.cpp b/Boards/LilygoTdeck/keyboard.cpp index 609f7bf1..d0adad6a 100644 --- a/Boards/LilygoTdeck/keyboard.cpp +++ b/Boards/LilygoTdeck/keyboard.cpp @@ -2,8 +2,8 @@ #include "config.h" #include "lvgl.h" #include "TactilityCore.h" -#include "Ui/LvglKeypad.h" -#include "Hal/I2c/I2c.h" +#include "ui/LvglKeypad.h" +#include "hal/i2c/I2c.h" #include #define TAG "tdeck_keyboard" diff --git a/Boards/LilygoTdeck/lilygo_tdeck.h b/Boards/LilygoTdeck/lilygo_tdeck.h index 16c12a03..1c9a111b 100644 --- a/Boards/LilygoTdeck/lilygo_tdeck.h +++ b/Boards/LilygoTdeck/lilygo_tdeck.h @@ -1,5 +1,5 @@ #pragma once -#include "Hal/Configuration.h" +#include "hal/Configuration.h" extern const tt::hal::Configuration lilygo_tdeck; diff --git a/Boards/LilygoTdeck/lvgl.cpp b/Boards/LilygoTdeck/lvgl.cpp index 4fdc446f..8307f8a6 100644 --- a/Boards/LilygoTdeck/lvgl.cpp +++ b/Boards/LilygoTdeck/lvgl.cpp @@ -1,6 +1,6 @@ #include "Log.h" #include "Thread.h" -#include "Ui/LvglSync.h" +#include "ui/LvglSync.h" #include "config.h" #include "display.h" #include "esp_lvgl_port.h" @@ -59,7 +59,7 @@ bool tdeck_init_lvgl() { } // Set syncing functions - tt::lvgl::sync_set(&lvgl_port_lock, &lvgl_port_unlock); + tt::lvgl::syncSet(&lvgl_port_lock, &lvgl_port_unlock); keyboard_alloc(display); diff --git a/Boards/LilygoTdeck/sdcard.cpp b/Boards/LilygoTdeck/sdcard.cpp index 12c7b7ab..2eb8c5e5 100644 --- a/Boards/LilygoTdeck/sdcard.cpp +++ b/Boards/LilygoTdeck/sdcard.cpp @@ -1,11 +1,11 @@ -#include "Hal/Sdcard.h" +#include "hal/sdcard/Sdcard.h" #include "Check.h" #include "Log.h" #include "config.h" #include "esp_vfs_fat.h" #include "sdmmc_cmd.h" -#include "Ui/LvglSync.h" +#include "ui/LvglSync.h" #define TAG "tdeck_sdcard" diff --git a/Boards/M5stackCore2/Source/M5stackCore2.h b/Boards/M5stackCore2/Source/M5stackCore2.h index 12feadce..f90c8fb4 100644 --- a/Boards/M5stackCore2/Source/M5stackCore2.h +++ b/Boards/M5stackCore2/Source/M5stackCore2.h @@ -1,5 +1,5 @@ #pragma once -#include "Hal/Configuration.h" +#include "hal/Configuration.h" extern const tt::hal::Configuration m5stack_core2; diff --git a/Boards/M5stackCoreS3/Source/M5stackCoreS3.h b/Boards/M5stackCoreS3/Source/M5stackCoreS3.h index f396fcc8..9878c56d 100644 --- a/Boards/M5stackCoreS3/Source/M5stackCoreS3.h +++ b/Boards/M5stackCoreS3/Source/M5stackCoreS3.h @@ -1,5 +1,5 @@ #pragma once -#include "Hal/Configuration.h" +#include "hal/Configuration.h" extern const tt::hal::Configuration m5stack_cores3; diff --git a/Boards/M5stackShared/Source/Lvgl.cpp b/Boards/M5stackShared/Source/Lvgl.cpp index 2cfd9807..f0f32003 100644 --- a/Boards/M5stackShared/Source/Lvgl.cpp +++ b/Boards/M5stackShared/Source/Lvgl.cpp @@ -1,7 +1,7 @@ #include "esp_lvgl_port.h" #include "Log.h" #include "Thread.h" -#include "Ui/LvglSync.h" +#include "ui/LvglSync.h" #define TAG "cores3_lvgl" @@ -40,7 +40,7 @@ bool m5stack_lvgl_init() { lv_indev_set_display(touch_indev, display); // Set syncing functions - tt::lvgl::sync_set(&lvgl_port_lock, &lvgl_port_unlock); + tt::lvgl::syncSet(&lvgl_port_lock, &lvgl_port_unlock); return true; } diff --git a/Boards/M5stackShared/Source/M5stackShared.h b/Boards/M5stackShared/Source/M5stackShared.h index 108d13d6..aefe3ef2 100644 --- a/Boards/M5stackShared/Source/M5stackShared.h +++ b/Boards/M5stackShared/Source/M5stackShared.h @@ -1,7 +1,7 @@ #pragma once -#include "Hal/Power.h" -#include "Hal/Sdcard.h" +#include "hal/Power.h" +#include "hal/sdcard/Sdcard.h" extern bool m5stack_bootstrap(); extern bool m5stack_lvgl_init(); diff --git a/Boards/M5stackShared/Source/Power.cpp b/Boards/M5stackShared/Source/Power.cpp index ee29dc49..3d80d0cf 100644 --- a/Boards/M5stackShared/Source/Power.cpp +++ b/Boards/M5stackShared/Source/Power.cpp @@ -1,4 +1,4 @@ -#include "Hal/Power.h" +#include "hal/Power.h" #include "M5Unified.hpp" /** @@ -30,9 +30,9 @@ static int32_t get_current() { } extern const tt::hal::Power m5stack_power = { - .is_charging = &is_charging, - .is_charging_enabled = &is_charging_enabled, - .set_charging_enabled = &set_charging_enabled, - .get_charge_level = &get_charge_level, - .get_current = &get_current + .isCharging = &is_charging, + .isChargingEnabled = &is_charging_enabled, + .setChargingEnabled = &set_charging_enabled, + .getChargeLevel = &get_charge_level, + .getCurrent = &get_current }; diff --git a/Boards/M5stackShared/Source/Sdcard.cpp b/Boards/M5stackShared/Source/Sdcard.cpp index 73717e3e..d2b70d17 100644 --- a/Boards/M5stackShared/Source/Sdcard.cpp +++ b/Boards/M5stackShared/Source/Sdcard.cpp @@ -1,6 +1,6 @@ #include "Check.h" #include "Log.h" -#include "Hal/Sdcard.h" +#include "hal/sdcard/Sdcard.h" #include "esp_vfs_fat.h" #include "sdmmc_cmd.h" diff --git a/Boards/WaveshareS3Touch/lvgl.cpp b/Boards/WaveshareS3Touch/lvgl.cpp index 889abee4..285b9d4f 100644 --- a/Boards/WaveshareS3Touch/lvgl.cpp +++ b/Boards/WaveshareS3Touch/lvgl.cpp @@ -2,10 +2,10 @@ #include "display_i.h" #include "touch_i.h" -#include "Ui/LvglSync.h" +#include "ui/LvglSync.h" bool ws3t_init_lvgl() { - tt::lvgl::sync_set(&ws3t_display_lock, &ws3t_display_unlock); + tt::lvgl::syncSet(&ws3t_display_lock, &ws3t_display_unlock); lv_display_t* display = ws3t_display_create(); if (display == nullptr) { diff --git a/Boards/WaveshareS3Touch/waveshare_s3_touch.h b/Boards/WaveshareS3Touch/waveshare_s3_touch.h index 2bc97826..068ce656 100644 --- a/Boards/WaveshareS3Touch/waveshare_s3_touch.h +++ b/Boards/WaveshareS3Touch/waveshare_s3_touch.h @@ -1,6 +1,6 @@ #pragma once -#include "Hal/Configuration.h" +#include "hal/Configuration.h" // Waveshare S3 Touch LCD 4.3 extern const tt::hal::Configuration waveshare_s3_touch; diff --git a/Boards/YellowBoard/lvgl.cpp b/Boards/YellowBoard/lvgl.cpp index f7d8702c..7dc274ac 100644 --- a/Boards/YellowBoard/lvgl.cpp +++ b/Boards/YellowBoard/lvgl.cpp @@ -1,6 +1,6 @@ #include "esp_lvgl_port.h" #include "Log.h" -#include "Ui/LvglSync.h" +#include "ui/LvglSync.h" #include "Thread.h" #define TAG "twodotfour_lvgl" @@ -50,7 +50,7 @@ bool twodotfour_lvgl_init() { } // Set syncing functions - tt::lvgl::sync_set(&lvgl_port_lock, &lvgl_port_unlock); + tt::lvgl::syncSet(&lvgl_port_lock, &lvgl_port_unlock); return true; } diff --git a/Boards/YellowBoard/sdcard.cpp b/Boards/YellowBoard/sdcard.cpp index 2884250d..c529beb1 100644 --- a/Boards/YellowBoard/sdcard.cpp +++ b/Boards/YellowBoard/sdcard.cpp @@ -1,4 +1,4 @@ -#include "Hal/Sdcard.h" +#include "hal/sdcard/Sdcard.h" #include "Check.h" #include "Log.h" #include "config.h" diff --git a/Boards/YellowBoard/yellow_board.h b/Boards/YellowBoard/yellow_board.h index 99ceb8d3..03abb453 100644 --- a/Boards/YellowBoard/yellow_board.h +++ b/Boards/YellowBoard/yellow_board.h @@ -1,6 +1,6 @@ #pragma once -#include "Hal/Configuration.h" +#include "hal/Configuration.h" // Capacitive touch version of the 2.4" yellow board extern const tt::hal::Configuration yellow_board_24inch_cap; diff --git a/CODING_STYLE.md b/CODING_STYLE.md index 11578c30..6aea9183 100644 --- a/CODING_STYLE.md +++ b/CODING_STYLE.md @@ -1,78 +1,71 @@ -# C coding Style +# C++ coding Style The basic formatting rules are set in `.clang-format`. Use auto-formatting in your editor. -All code should target C language revision C11/C17. +All code should target C++ language revision 17. ## Naming ### Files -Files are snake-case. +Files are upper camel case. -- Files: `^[0-9a-z_]+$` -- Directories: `^[0-9a-z_]+$` +- Files: `^[0-9a-zA-Z]+$` +- Directories: `^[0-9a-zA-Z]+$` Example: -```c -some_feature.c -some_feature.h +```c++ +SomeFeature.cpp +SomeFeature.h ``` Private/internal headers are postfixed with `_i` before the file extension. -Like `some_feature_i.h` +Like `SomeFeature_i.h` + +### Folders + +Project folders include: +- `Source` for source files and public header files +- `Private` for private header files +- `Include` for projects that require separate header files + +Sources for a specific namespace must go into a folder with the lowercase name of that namespace. +The only exception to this is the root namespace, as this doesn't require its own subfolder. ### Function names -Names are snake-case. - -The `tt_` prefix is used for public functions that are part of `tactility/` or `tactility-core/` -Internal/static functions don't have prefix requirements, but prefixes are allowed. - -The prefix is **not** used for drivers, services and apps. - -Public functions have the feature name after `tt_`. - -If a feature has setters or getters, it's added after the feature name part. +Names are lower camel case. Example: -```c -void tt_counter_get_limit() { +```c++ +void getLimit() { // ... } ``` -Function names that allocate or free memory should end in `_alloc` and `_free`. +### Preprocessor + +Preprocessor functions are written in snake-case and prefixed with `tt_`, for example: + +```c++ +#define tt_assert(x) __tt_assert_internal(x) +``` ### Type names -Consts are snake-case with capital letters. +Consts are lower camel case with capital letters. + +Typedefs for structs and datatype aliases are upper camel case. -Typedefs for structs and datatype aliases are PascalCase. Examples: -```c +```c++ typedef uint32_t SomeAlias; +const SomeAlias myAlias; + typedef struct { // ... } SomeStruct; ``` - -### Internal struct with public handle - -When you have a `struct` data type that is private and you want to expose a handle (pointer), -append the internal name with `Data` like this: - -**feature.c** -```c -typedef struct { - // ... -} MutexData; -``` - -**feature.h** -```c -typedef void* Mutex; -``` diff --git a/COPYRIGHT.md b/COPYRIGHT.md index 674bdf10..8681042b 100644 --- a/COPYRIGHT.md +++ b/COPYRIGHT.md @@ -1,13 +1,27 @@ +### ESP-IDF + +This project uses ESP-IDF to compile the ESP32 firmware. + +Website: https://www.espressif.com/ + +License: [GPL v3.0](https://github.com/espressif/esp-idf/blob/master/LICENSE) + ### Flipper Zero Firmware + +Some of the code in this project has been adapted from the Flipper Zero firmware. +It was changed to fit the Tactility project. + Website: https://github.com/flipperdevices/flipperzero-firmware/ -License: GPL v3.0 -https://github.com/flipperdevices/flipperzero-firmware/blob/dev/LICENSE + +License: [GPL v3.0](https://github.com/flipperdevices/flipperzero-firmware/blob/dev/LICENSE) + ### Google Fonts + Website: https://fonts.google.com/icons -License: Apache License, version 2.0 -https://fonts.google.com/attribution + +License: [Apache License, version 2.0](https://fonts.google.com/attribution) ### Components -See `/components` for the respective projects and their licenses. +See `/components` for the respective projects and their licenses. diff --git a/README.md b/README.md index a11b0cb6..005e68fc 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ UI is created with [lvgl](https://github.com/lvgl/lvgl) which has lots of [widge Creating a touch-capable UI is [easy](https://docs.lvgl.io/9.0/get-started/quick-overview.html) and doesn't require your own render loop! ```C++ -static void app_show(App app, lv_obj_t* parent) { +static void app_show(tt::app::App app, lv_obj_t* parent) { // Default toolbar with app name and close button lv_obj_t* toolbar = tt::lvgl::toolbar_create(parent, app); lv_obj_align(toolbar, LV_ALIGN_TOP_MID, 0, 0); @@ -54,10 +54,10 @@ static void app_show(App app, lv_obj_t* parent) { // Widgets are auto-removed from the parent when the app is closed } -extern const AppManifest manifest = { +extern const tt::app::Manifest manifest = { .id = "HelloWorld", // Used to identify and start an app .name = "Hello World", // Shown on the desktop and app's toolbar - .type = AppTypeUser, + .type = TypeUser, .on_show = &app_show // A minimal setup sets the on_show() function }; ``` diff --git a/Tactility/Private/App_i.h b/Tactility/Private/App_i.h deleted file mode 100644 index 6bd500e6..00000000 --- a/Tactility/Private/App_i.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include "App.h" - -#include "AppManifest.h" -#include "Mutex.h" - -namespace tt { - -class AppData { -public: - Mutex* mutex; - const AppManifest* manifest; - AppState state = AppStateInitial; - /** @brief Memory marker at start of app, to detect memory leaks */ - size_t memory = 0; - AppFlags flags = { - .flags = 0 - }; - /** @brief Optional parameters to start the app with - * When these are stored in the app struct, the struct takes ownership. - * Do not mutate after app creation. - */ - Bundle parameters; - /** @brief @brief Contextual data related to the running app's instance - * The app can attach its data to this. - * The lifecycle is determined by the on_start and on_stop methods in the AppManifest. - * These manifest methods can optionally allocate/free data that is attached here. - */ - void* _Nullable data = nullptr; -}; - -} // namespace diff --git a/Tactility/Private/LvglInit_i.h b/Tactility/Private/LvglInit_i.h deleted file mode 100644 index 792ab954..00000000 --- a/Tactility/Private/LvglInit_i.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include "Hal/Configuration.h" - -namespace tt { - -void lvgl_init(const hal::Configuration* config); - -} // namespace diff --git a/Tactility/Private/Services/Gui/Gui_i.h b/Tactility/Private/service/gui/Gui_i.h similarity index 88% rename from Tactility/Private/Services/Gui/Gui_i.h rename to Tactility/Private/service/gui/Gui_i.h index 2dcc9005..1c94408b 100644 --- a/Tactility/Private/Services/Gui/Gui_i.h +++ b/Tactility/Private/service/gui/Gui_i.h @@ -3,9 +3,9 @@ #include "MessageQueue.h" #include "Mutex.h" #include "Pubsub.h" -#include "Services/Gui/Gui.h" -#include "Services/Gui/ViewPort.h" -#include "Services/Gui/ViewPort_i.h" +#include "service/gui/Gui.h" +#include "service/gui/ViewPort.h" +#include "service/gui/ViewPort_i.h" #include namespace tt::service::gui { diff --git a/Tactility/Private/Services/Gui/ViewPort_i.h b/Tactility/Private/service/gui/ViewPort_i.h similarity index 93% rename from Tactility/Private/Services/Gui/ViewPort_i.h rename to Tactility/Private/service/gui/ViewPort_i.h index 1253f8ef..06b3eb0a 100644 --- a/Tactility/Private/Services/Gui/ViewPort_i.h +++ b/Tactility/Private/service/gui/ViewPort_i.h @@ -1,6 +1,6 @@ #pragma once -#include "Services/Gui/ViewPort.h" +#include "service/gui/ViewPort.h" namespace tt::service::gui { diff --git a/Tactility/Private/Services/Loader/Loader_i.h b/Tactility/Private/service/loader/Loader_i.h similarity index 89% rename from Tactility/Private/Services/Loader/Loader_i.h rename to Tactility/Private/service/loader/Loader_i.h index 8e9e7607..b5784d20 100644 --- a/Tactility/Private/Services/Loader/Loader_i.h +++ b/Tactility/Private/service/loader/Loader_i.h @@ -1,12 +1,11 @@ #pragma once -#include "ApiLock.h" -#include "AppManifest.h" +#include "app/Manifest.h" #include "MessageQueue.h" #include "Pubsub.h" #include "Thread.h" -#include "Services/Gui/ViewPort.h" -#include "Services/Loader/Loader.h" +#include "service/gui/ViewPort.h" +#include "service/loader/Loader.h" #ifdef ESP_PLATFORM #include "freertos/FreeRTOS.h" @@ -53,8 +52,7 @@ public: // This lock blocks anyone from starting an app as long // as an app is already running via loader_start() // This lock's lifecycle is not owned by this class. - // TODO: Convert to smart pointer - ApiLock api_lock; + EventFlag* _Nullable api_lock; LoaderMessageType type; struct { @@ -93,8 +91,8 @@ public: result = { .raw_value = nullptr }; } - void setLock(ApiLock lock) { - api_lock = lock; + void setApiLock(EventFlag* eventFlag) { + api_lock = eventFlag; } void cleanup() { @@ -111,7 +109,7 @@ struct Loader { MessageQueue queue = MessageQueue(1, sizeof(LoaderMessage)); Mutex* mutex; int8_t app_stack_index; - App app_stack[APP_STACK_SIZE]; + app::App app_stack[APP_STACK_SIZE]; }; } // namespace diff --git a/Tactility/Private/ui/LvglInit_i.h b/Tactility/Private/ui/LvglInit_i.h new file mode 100644 index 00000000..33d8ff33 --- /dev/null +++ b/Tactility/Private/ui/LvglInit_i.h @@ -0,0 +1,9 @@ +#pragma once + +#include "hal/Configuration.h" + +namespace tt::ui { + +void initLvgl(const hal::Configuration* config); + +} // namespace diff --git a/Tactility/Source/AppManifestRegistry.h b/Tactility/Source/AppManifestRegistry.h deleted file mode 100644 index 693f3528..00000000 --- a/Tactility/Source/AppManifestRegistry.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "AppManifest.h" -#include -#include - -namespace tt { - -void app_manifest_registry_init(); -void app_manifest_registry_add(const AppManifest* manifest); -void app_manifest_registry_remove(const AppManifest* manifest); -const AppManifest _Nullable* app_manifest_registry_find_by_id(const std::string& id); -std::vector app_manifest_registry_get(); - -} // namespace diff --git a/Tactility/Source/Tactility.cpp b/Tactility/Source/Tactility.cpp index 765f14c3..5d0f0ddb 100644 --- a/Tactility/Source/Tactility.cpp +++ b/Tactility/Source/Tactility.cpp @@ -1,10 +1,10 @@ #include "Tactility.h" -#include "AppManifestRegistry.h" -#include "LvglInit_i.h" -#include "ServiceRegistry.h" +#include "app/ManifestRegistry.h" +#include "service/ServiceRegistry.h" +#include "service/loader/Loader.h" #include "TactilityHeadless.h" -#include "Services/Loader/Loader.h" +#include "ui/LvglInit_i.h" namespace tt { @@ -15,13 +15,13 @@ static const Configuration* config_instance = NULL; // region Default services namespace service { - namespace gui { extern const ServiceManifest manifest; } - namespace loader { extern const ServiceManifest manifest; } - namespace screenshot { extern const ServiceManifest manifest; } - namespace statusbar { extern const ServiceManifest manifest; } + namespace gui { extern const Manifest manifest; } + namespace loader { extern const Manifest manifest; } + namespace screenshot { extern const Manifest manifest; } + namespace statusbar { extern const Manifest manifest; } } -static const std::vector system_services = { +static const std::vector system_services = { &service::loader::manifest, &service::gui::manifest, // depends on loader service #ifndef ESP_PLATFORM // Screenshots don't work yet on ESP32 @@ -35,26 +35,26 @@ static const std::vector system_services = { // region Default apps namespace app { - namespace desktop { extern const AppManifest manifest; } - namespace files { extern const AppManifest manifest; } - namespace gpio { extern const AppManifest manifest; } - namespace image_viewer { extern const AppManifest manifest; } - namespace screenshot { extern const AppManifest manifest; } - namespace settings { extern const AppManifest manifest; } - namespace settings::display { extern const AppManifest manifest; } - namespace settings::i2c { extern const AppManifest manifest; } - namespace settings::power { extern const AppManifest manifest; } - namespace system_info { extern const AppManifest manifest; } - namespace text_viewer { extern const AppManifest manifest; } - namespace wifi_connect { extern const AppManifest manifest; } - namespace wifi_manage { extern const AppManifest manifest; } + namespace desktop { extern const Manifest manifest; } + namespace files { extern const Manifest manifest; } + namespace gpio { extern const Manifest manifest; } + namespace image_viewer { extern const Manifest manifest; } + namespace screenshot { extern const Manifest manifest; } + namespace settings { extern const Manifest manifest; } + namespace settings::display { extern const Manifest manifest; } + namespace settings::i2c { extern const Manifest manifest; } + namespace settings::power { extern const Manifest manifest; } + namespace system_info { extern const Manifest manifest; } + namespace text_viewer { extern const Manifest manifest; } + namespace wifi_connect { extern const Manifest manifest; } + namespace wifi_manage { extern const Manifest manifest; } } #ifndef ESP_PLATFORM -extern const AppManifest screenshot_app; +extern const app::Manifest screenshot_app; #endif -static const std::vector system_apps = { +static const std::vector system_apps = { &app::desktop::manifest, &app::files::manifest, &app::gpio::manifest, @@ -84,10 +84,10 @@ static void register_system_apps() { } } -static void register_user_apps(const AppManifest* const apps[TT_CONFIG_APPS_LIMIT]) { +static void register_user_apps(const app::Manifest* const apps[TT_CONFIG_APPS_LIMIT]) { TT_LOG_I(TAG, "Registering user apps"); for (size_t i = 0; i < TT_CONFIG_APPS_LIMIT; i++) { - const AppManifest* manifest = apps[i]; + const app::Manifest* manifest = apps[i]; if (manifest != nullptr) { app_manifest_registry_add(manifest); } else { @@ -100,18 +100,18 @@ static void register_user_apps(const AppManifest* const apps[TT_CONFIG_APPS_LIMI static void register_and_start_system_services() { TT_LOG_I(TAG, "Registering and starting system services"); for (const auto& service_manifest: system_services) { - service_registry_add(service_manifest); - tt_check(service_registry_start(service_manifest->id)); + addService(service_manifest); + tt_check(service::startService(service_manifest->id)); } } -static void register_and_start_user_services(const ServiceManifest* const services[TT_CONFIG_SERVICES_LIMIT]) { +static void register_and_start_user_services(const service::Manifest* const services[TT_CONFIG_SERVICES_LIMIT]) { TT_LOG_I(TAG, "Registering and starting user services"); for (size_t i = 0; i < TT_CONFIG_SERVICES_LIMIT; i++) { - const ServiceManifest* manifest = services[i]; + const service::Manifest* manifest = services[i]; if (manifest != nullptr) { - service_registry_add(manifest); - tt_check(service_registry_start(manifest->id)); + addService(manifest); + tt_check(service::startService(manifest->id)); } else { // reached end of list break; @@ -127,9 +127,9 @@ void init(const Configuration* config) { initHeadless(*config->hardware); - lvgl_init(config->hardware); + ui::initLvgl(config->hardware); - app_manifest_registry_init(); + app::app_manifest_registry_init(); // Note: the order of starting apps and services is critical! // System services are registered first so the apps below can find them if needed diff --git a/Tactility/Source/Tactility.h b/Tactility/Source/Tactility.h index e5ed5d8e..4f0a71a5 100644 --- a/Tactility/Source/Tactility.h +++ b/Tactility/Source/Tactility.h @@ -1,8 +1,8 @@ #pragma once -#include "AppManifest.h" -#include "Hal/Configuration.h" -#include "ServiceManifest.h" +#include "app/Manifest.h" +#include "hal/Configuration.h" +#include "service/Manifest.h" #include "TactilityConfig.h" namespace tt { @@ -10,8 +10,8 @@ namespace tt { typedef struct { const hal::Configuration* hardware; // List of user applications - const AppManifest* const apps[TT_CONFIG_APPS_LIMIT]; - const ServiceManifest* const services[TT_CONFIG_SERVICES_LIMIT]; + const app::Manifest* const apps[TT_CONFIG_APPS_LIMIT]; + const service::Manifest* const services[TT_CONFIG_SERVICES_LIMIT]; const char* auto_start_app_id; } Configuration; diff --git a/Tactility/Source/App.cpp b/Tactility/Source/app/App.cpp similarity index 77% rename from Tactility/Source/App.cpp rename to Tactility/Source/app/App.cpp index 66ae2fde..f379d9d0 100644 --- a/Tactility/Source/App.cpp +++ b/Tactility/Source/app/App.cpp @@ -1,16 +1,16 @@ -#include "App_i.h" +#include "app/App.h" -namespace tt { +namespace tt::app { #define TAG "app" -void AppInstance::setState(AppState newState) { +void AppInstance::setState(State newState) { mutex.acquire(TtWaitForever); state = newState; mutex.release(); } -AppState AppInstance::getState() { +State AppInstance::getState() { mutex.acquire(TtWaitForever); auto result = state; mutex.release(); @@ -23,18 +23,18 @@ AppState AppInstance::getState() { * Consider creating MutableBundle vs Bundle. * Consider not exposing bundle, but expose `app_get_bundle_int(key)` methods with locking in it. */ -const AppManifest& AppInstance::getManifest() { +const Manifest& AppInstance::getManifest() { return manifest; } -AppFlags AppInstance::getFlags() { +Flags AppInstance::getFlags() { mutex.acquire(TtWaitForever); auto result = flags; mutex.release(); return result; } -void AppInstance::setFlags(AppFlags newFlags) { +void AppInstance::setFlags(Flags newFlags) { mutex.acquire(TtWaitForever); flags = newFlags; mutex.release(); @@ -57,7 +57,7 @@ const Bundle& AppInstance::getParameters() { return parameters; } -App tt_app_alloc(const AppManifest& manifest, const Bundle& parameters) { +App tt_app_alloc(const Manifest& manifest, const Bundle& parameters) { auto* instance = new AppInstance(manifest, parameters); return static_cast(instance); } @@ -67,23 +67,23 @@ void tt_app_free(App app) { delete instance; } -void tt_app_set_state(App app, AppState state) { +void tt_app_set_state(App app, State state) { static_cast(app)->setState(state); } -AppState tt_app_get_state(App app) { +State tt_app_get_state(App app) { return static_cast(app)->getState(); } -const AppManifest& tt_app_get_manifest(App app) { +const Manifest& tt_app_get_manifest(App app) { return static_cast(app)->getManifest(); } -AppFlags tt_app_get_flags(App app) { +Flags tt_app_get_flags(App app) { return static_cast(app)->getFlags(); } -void tt_app_set_flags(App app, AppFlags flags) { +void tt_app_set_flags(App app, Flags flags) { return static_cast(app)->setFlags(flags); } diff --git a/Tactility/Source/App.h b/Tactility/Source/app/App.h similarity index 61% rename from Tactility/Source/App.h rename to Tactility/Source/app/App.h index 731a363b..9e4a9e52 100644 --- a/Tactility/Source/App.h +++ b/Tactility/Source/app/App.h @@ -1,32 +1,35 @@ #pragma once -#include "AppManifest.h" +#include "Manifest.h" #include "Bundle.h" #include "Mutex.h" -namespace tt { +namespace tt::app { typedef enum { - AppStateInitial, // App is being activated in loader - AppStateStarted, // App is in memory - AppStateShowing, // App view is created - AppStateHiding, // App view is destroyed - AppStateStopped // App is not in memory -} AppState; + StateInitial, // App is being activated in loader + StateStarted, // App is in memory + StateShowing, // App view is created + StateHiding, // App view is destroyed + StateStopped // App is not in memory +} State; typedef union { struct { bool show_statusbar : 1; }; unsigned char flags; -} AppFlags; +} Flags; class AppInstance { + +private: + Mutex mutex = Mutex(MutexTypeNormal); - const AppManifest& manifest; - AppState state = AppStateInitial; - AppFlags flags = { .show_statusbar = true }; + const Manifest& manifest; + State state = StateInitial; + Flags flags = { .show_statusbar = true }; /** @brief Optional parameters to start the app with * When these are stored in the app struct, the struct takes ownership. * Do not mutate after app creation. @@ -38,21 +41,23 @@ class AppInstance { * These manifest methods can optionally allocate/free data that is attached here. */ void* _Nullable data = nullptr; + public: - AppInstance(const AppManifest& manifest) : + + AppInstance(const Manifest& manifest) : manifest(manifest) {} - AppInstance(const AppManifest& manifest, const Bundle& parameters) : + AppInstance(const Manifest& manifest, const Bundle& parameters) : manifest(manifest), parameters(parameters) {} - void setState(AppState state); - AppState getState(); + void setState(State state); + State getState(); - const AppManifest& getManifest(); + const Manifest& getManifest(); - AppFlags getFlags(); - void setFlags(AppFlags flags); + Flags getFlags(); + void setFlags(Flags flags); _Nullable void* getData(); void setData(void* data); @@ -66,22 +71,22 @@ public: * @return */ [[deprecated("use class")]] -App tt_app_alloc(const AppManifest& manifest, const Bundle& parameters); +App tt_app_alloc(const Manifest& manifest, const Bundle& parameters); [[deprecated("use class")]] void tt_app_free(App app); [[deprecated("use class")]] -void tt_app_set_state(App app, AppState state); +void tt_app_set_state(App app, State state); [[deprecated("use class")]] -AppState tt_app_get_state(App app); +State tt_app_get_state(App app); [[deprecated("use class")]] -const AppManifest& tt_app_get_manifest(App app); +const Manifest& tt_app_get_manifest(App app); [[deprecated("use class")]] -AppFlags tt_app_get_flags(App app); +Flags tt_app_get_flags(App app); [[deprecated("use class")]] -void tt_app_set_flags(App app, AppFlags flags); +void tt_app_set_flags(App app, Flags flags); [[deprecated("use class")]] void* _Nullable tt_app_get_data(App app); diff --git a/Tactility/Source/Apps/Desktop/Desktop.cpp b/Tactility/Source/app/Desktop/Desktop.cpp similarity index 77% rename from Tactility/Source/Apps/Desktop/Desktop.cpp rename to Tactility/Source/app/Desktop/Desktop.cpp index 71874b8e..e2e734e7 100644 --- a/Tactility/Source/Apps/Desktop/Desktop.cpp +++ b/Tactility/Source/app/Desktop/Desktop.cpp @@ -1,21 +1,21 @@ -#include "AppManifestRegistry.h" +#include "app/ManifestRegistry.h" #include "Assets.h" #include "Check.h" #include "lvgl.h" #include -#include "Services/Loader/Loader.h" +#include "service/loader/Loader.h" namespace tt::app::desktop { static void on_app_pressed(lv_event_t* e) { lv_event_code_t code = lv_event_get_code(e); if (code == LV_EVENT_CLICKED) { - const auto* manifest = static_cast(lv_event_get_user_data(e)); + const auto* manifest = static_cast(lv_event_get_user_data(e)); service::loader::start_app(manifest->id, false, Bundle()); } } -static void create_app_widget(const AppManifest* manifest, void* parent) { +static void create_app_widget(const Manifest* manifest, void* parent) { tt_check(parent); auto* list = static_cast(parent); const void* icon = !manifest->icon.empty() ? manifest->icon.c_str() : TT_ASSETS_APP_ICON_FALLBACK; @@ -33,23 +33,23 @@ static void desktop_show(TT_UNUSED App app, lv_obj_t* parent) { lv_list_add_text(list, "User"); for (const auto& manifest: manifests) { - if (manifest->type == AppTypeUser) { + if (manifest->type == TypeUser) { create_app_widget(manifest, list); } } lv_list_add_text(list, "System"); for (const auto& manifest: manifests) { - if (manifest->type == AppTypeSystem) { + if (manifest->type == TypeSystem) { create_app_widget(manifest, list); } } } -extern const AppManifest manifest = { +extern const Manifest manifest = { .id = "Desktop", .name = "Desktop", - .type = AppTypeDesktop, + .type = TypeDesktop, .on_show = &desktop_show, }; diff --git a/Tactility/Source/Apps/Display/Display.cpp b/Tactility/Source/app/Display/Display.cpp similarity index 97% rename from Tactility/Source/Apps/Display/Display.cpp rename to Tactility/Source/app/Display/Display.cpp index 53743306..7a76ce56 100644 --- a/Tactility/Source/Apps/Display/Display.cpp +++ b/Tactility/Source/app/Display/Display.cpp @@ -1,9 +1,9 @@ -#include "App.h" +#include "app/App.h" #include "Assets.h" #include "DisplayPreferences.h" #include "Tactility.h" -#include "Ui/Style.h" -#include "Ui/Toolbar.h" +#include "ui/Style.h" +#include "ui/Toolbar.h" #include "lvgl.h" namespace tt::app::settings::display { @@ -122,11 +122,11 @@ static void app_hide(TT_UNUSED App app) { } } -extern const AppManifest manifest = { +extern const Manifest manifest = { .id = "Display", .name = "Display", .icon = TT_ASSETS_APP_ICON_DISPLAY_SETTINGS, - .type = AppTypeSettings, + .type = TypeSettings, .on_start = nullptr, .on_stop = nullptr, .on_show = &app_show, diff --git a/Tactility/Source/Apps/Display/DisplayPreferences.cpp b/Tactility/Source/app/Display/DisplayPreferences.cpp similarity index 100% rename from Tactility/Source/Apps/Display/DisplayPreferences.cpp rename to Tactility/Source/app/Display/DisplayPreferences.cpp diff --git a/Tactility/Source/Apps/Display/DisplayPreferences.h b/Tactility/Source/app/Display/DisplayPreferences.h similarity index 100% rename from Tactility/Source/Apps/Display/DisplayPreferences.h rename to Tactility/Source/app/Display/DisplayPreferences.h diff --git a/Tactility/Source/Apps/Files/FileUtils.cpp b/Tactility/Source/app/Files/FileUtils.cpp similarity index 100% rename from Tactility/Source/Apps/Files/FileUtils.cpp rename to Tactility/Source/app/Files/FileUtils.cpp diff --git a/Tactility/Source/Apps/Files/FileUtils.h b/Tactility/Source/app/Files/FileUtils.h similarity index 100% rename from Tactility/Source/Apps/Files/FileUtils.h rename to Tactility/Source/app/Files/FileUtils.h diff --git a/Tactility/Source/Apps/Files/Files.cpp b/Tactility/Source/app/Files/Files.cpp similarity index 96% rename from Tactility/Source/Apps/Files/Files.cpp rename to Tactility/Source/app/Files/Files.cpp index 449d22dc..2c208bde 100644 --- a/Tactility/Source/Apps/Files/Files.cpp +++ b/Tactility/Source/app/Files/Files.cpp @@ -1,15 +1,15 @@ #include "FilesData.h" - -#include "App.h" +#include "Tactility.h" +#include "app/App.h" #include "Assets.h" #include "Check.h" #include "FileUtils.h" #include "StringUtils.h" -#include "Apps/ImageViewer/ImageViewer.h" -#include "Apps/TextViewer/TextViewer.h" +#include "app/ImageViewer/ImageViewer.h" +#include "app/TextViewer/TextViewer.h" #include "lvgl.h" -#include "Services/Loader/Loader.h" -#include "Ui/Toolbar.h" +#include "service/loader/Loader.h" +#include "ui/Toolbar.h" #include #include @@ -221,11 +221,11 @@ static void on_stop(App app) { // endregion Lifecycle -extern const AppManifest manifest = { +extern const Manifest manifest = { .id = "Files", .name = "Files", .icon = TT_ASSETS_APP_ICON_FILES, - .type = AppTypeSystem, + .type = TypeSystem, .on_start = &on_start, .on_stop = &on_stop, .on_show = &on_show, diff --git a/Tactility/Source/Apps/Files/FilesData.cpp b/Tactility/Source/app/Files/FilesData.cpp similarity index 100% rename from Tactility/Source/Apps/Files/FilesData.cpp rename to Tactility/Source/app/Files/FilesData.cpp diff --git a/Tactility/Source/Apps/Files/FilesData.h b/Tactility/Source/app/Files/FilesData.h similarity index 100% rename from Tactility/Source/Apps/Files/FilesData.h rename to Tactility/Source/app/Files/FilesData.h diff --git a/Tactility/Source/Apps/Gpio/Gpio.cpp b/Tactility/Source/app/Gpio/Gpio.cpp similarity index 97% rename from Tactility/Source/Apps/Gpio/Gpio.cpp rename to Tactility/Source/app/Gpio/Gpio.cpp index 5781525f..315f3f38 100644 --- a/Tactility/Source/Apps/Gpio/Gpio.cpp +++ b/Tactility/Source/app/Gpio/Gpio.cpp @@ -1,10 +1,11 @@ #include "Mutex.h" #include "Thread.h" -#include "Services/Loader/Loader.h" -#include "Ui/Toolbar.h" +#include "Tactility.h" +#include "service/loader/Loader.h" +#include "ui/Toolbar.h" #include "GpioHal.h" -#include "Ui/LvglSync.h" +#include "ui/LvglSync.h" namespace tt::app::gpio { @@ -200,10 +201,10 @@ static void on_stop(App app) { // endregion App lifecycle -extern const AppManifest manifest = { +extern const Manifest manifest = { .id = "Gpio", .name = "GPIO", - .type = AppTypeSystem, + .type = TypeSystem, .on_start = &on_start, .on_stop = &on_stop, .on_show = &app_show, diff --git a/Tactility/Source/Apps/Gpio/GpioHal.cpp b/Tactility/Source/app/Gpio/GpioHal.cpp similarity index 100% rename from Tactility/Source/Apps/Gpio/GpioHal.cpp rename to Tactility/Source/app/Gpio/GpioHal.cpp diff --git a/Tactility/Source/Apps/Gpio/GpioHal.h b/Tactility/Source/app/Gpio/GpioHal.h similarity index 100% rename from Tactility/Source/Apps/Gpio/GpioHal.h rename to Tactility/Source/app/Gpio/GpioHal.h diff --git a/Tactility/Source/Apps/I2cSettings/I2cSettings.cpp b/Tactility/Source/app/I2cSettings/I2cSettings.cpp similarity index 96% rename from Tactility/Source/Apps/I2cSettings/I2cSettings.cpp rename to Tactility/Source/app/I2cSettings/I2cSettings.cpp index 9ea08b35..1e5656ba 100644 --- a/Tactility/Source/Apps/I2cSettings/I2cSettings.cpp +++ b/Tactility/Source/app/I2cSettings/I2cSettings.cpp @@ -1,8 +1,8 @@ #include "Assets.h" -#include "Hal/I2c/I2c.h" +#include "hal/i2c/I2c.h" #include "Tactility.h" -#include "Ui/Style.h" -#include "Ui/Toolbar.h" +#include "ui/Style.h" +#include "ui/Toolbar.h" #include "lvgl.h" namespace tt::app::settings::i2c { @@ -85,11 +85,11 @@ static void on_show(App app, lv_obj_t* parent) { } } -extern const AppManifest manifest = { +extern const Manifest manifest = { .id = "I2cSettings", .name = "I2C", .icon = TT_ASSETS_APP_ICON_I2C_SETTINGS, - .type = AppTypeSettings, + .type = TypeSettings, .on_show = &on_show }; diff --git a/Tactility/Source/Apps/ImageViewer/ImageViewer.cpp b/Tactility/Source/app/ImageViewer/ImageViewer.cpp similarity index 90% rename from Tactility/Source/Apps/ImageViewer/ImageViewer.cpp rename to Tactility/Source/app/ImageViewer/ImageViewer.cpp index 65d58e31..7263aaeb 100644 --- a/Tactility/Source/Apps/ImageViewer/ImageViewer.cpp +++ b/Tactility/Source/app/ImageViewer/ImageViewer.cpp @@ -1,8 +1,8 @@ #include "ImageViewer.h" #include "Log.h" #include "lvgl.h" -#include "Ui/Style.h" -#include "Ui/Toolbar.h" +#include "ui/Style.h" +#include "ui/Toolbar.h" namespace tt::app::image_viewer { @@ -31,10 +31,10 @@ static void on_show(App app, lv_obj_t* parent) { } } -extern const AppManifest manifest = { +extern const Manifest manifest = { .id = "ImageViewer", .name = "Image Viewer", - .type = AppTypeHidden, + .type = TypeHidden, .on_show = &on_show }; diff --git a/Tactility/Source/Apps/ImageViewer/ImageViewer.h b/Tactility/Source/app/ImageViewer/ImageViewer.h similarity index 100% rename from Tactility/Source/Apps/ImageViewer/ImageViewer.h rename to Tactility/Source/app/ImageViewer/ImageViewer.h diff --git a/Tactility/Source/AppManifest.h b/Tactility/Source/app/Manifest.h similarity index 84% rename from Tactility/Source/AppManifest.h rename to Tactility/Source/app/Manifest.h index d9e4f8ac..c8b3517d 100644 --- a/Tactility/Source/AppManifest.h +++ b/Tactility/Source/app/Manifest.h @@ -6,29 +6,29 @@ // Forward declarations typedef struct _lv_obj_t lv_obj_t; -namespace tt { +namespace tt::app { typedef void* App; typedef enum { /** A desktop app sits at the root of the app stack managed by the Loader service */ - AppTypeDesktop, + TypeDesktop, /** Apps that generally aren't started from the desktop (e.g. image viewer) */ - AppTypeHidden, + TypeHidden, /** Standard apps, provided by the system. */ - AppTypeSystem, + TypeSystem, /** The apps that are launched/shown by the Settings app. The Settings app itself is of type AppTypeSystem. */ - AppTypeSettings, + TypeSettings, /** User-provided apps. */ - AppTypeUser -} AppType; + TypeUser +} Type; typedef void (*AppOnStart)(App app); typedef void (*AppOnStop)(App app); typedef void (*AppOnShow)(App app, lv_obj_t* parent); typedef void (*AppOnHide)(App app); -typedef struct AppManifest { +typedef struct Manifest { /** * The identifier by which the app is launched by the system and other apps. */ @@ -47,7 +47,7 @@ typedef struct AppManifest { /** * App type affects launch behaviour. */ - const AppType type = AppTypeUser; + const Type type = TypeUser; /** * Non-blocking method to call when app is started. @@ -71,7 +71,7 @@ typedef struct AppManifest { } AppManifest; struct { - bool operator()(const AppManifest* a, const AppManifest* b) const { return a->name < b->name; } + bool operator()(const Manifest* a, const Manifest* b) const { return a->name < b->name; } } SortAppManifestByName; } // namespace diff --git a/Tactility/Source/AppManifestRegistry.cpp b/Tactility/Source/app/ManifestRegistry.cpp similarity index 67% rename from Tactility/Source/AppManifestRegistry.cpp rename to Tactility/Source/app/ManifestRegistry.cpp index 16ceb773..6bcb8ee7 100644 --- a/Tactility/Source/AppManifestRegistry.cpp +++ b/Tactility/Source/app/ManifestRegistry.cpp @@ -1,13 +1,13 @@ -#include "AppManifestRegistry.h" +#include "ManifestRegistry.h" #include "Mutex.h" #include "TactilityCore.h" #include #define TAG "app_registry" -namespace tt { +namespace tt::app { -typedef std::unordered_map AppManifestMap; +typedef std::unordered_map AppManifestMap; static AppManifestMap app_manifest_map; static Mutex* hash_mutex = nullptr; @@ -26,7 +26,7 @@ void app_manifest_registry_init() { tt_assert(hash_mutex == nullptr); hash_mutex = tt_mutex_alloc(MutexTypeNormal); } -void app_manifest_registry_add(const AppManifest* manifest) { +void app_manifest_registry_add(const Manifest* manifest) { TT_LOG_I(TAG, "adding %s", manifest->id.c_str()); app_registry_lock(); @@ -34,16 +34,16 @@ void app_manifest_registry_add(const AppManifest* manifest) { app_registry_unlock(); } -_Nullable const AppManifest * app_manifest_registry_find_by_id(const std::string& id) { +_Nullable const Manifest * app_manifest_registry_find_by_id(const std::string& id) { app_registry_lock(); auto iterator = app_manifest_map.find(id); - _Nullable const AppManifest* result = iterator != app_manifest_map.end() ? iterator->second : nullptr; + _Nullable const Manifest* result = iterator != app_manifest_map.end() ? iterator->second : nullptr; app_registry_unlock(); return result; } -std::vector app_manifest_registry_get() { - std::vector manifests; +std::vector app_manifest_registry_get() { + std::vector manifests; app_registry_lock(); for (const auto& item: app_manifest_map) { manifests.push_back(item.second); diff --git a/Tactility/Source/app/ManifestRegistry.h b/Tactility/Source/app/ManifestRegistry.h new file mode 100644 index 00000000..33840737 --- /dev/null +++ b/Tactility/Source/app/ManifestRegistry.h @@ -0,0 +1,15 @@ +#pragma once + +#include "Manifest.h" +#include +#include + +namespace tt::app { + +void app_manifest_registry_init(); +void app_manifest_registry_add(const Manifest* manifest); +void app_manifest_registry_remove(const Manifest* manifest); +const Manifest _Nullable* app_manifest_registry_find_by_id(const std::string& id); +std::vector app_manifest_registry_get(); + +} // namespace diff --git a/Tactility/Source/Apps/Power/Power.cpp b/Tactility/Source/app/Power/Power.cpp similarity index 87% rename from Tactility/Source/Apps/Power/Power.cpp rename to Tactility/Source/app/Power/Power.cpp index 18956d91..d77a41dc 100644 --- a/Tactility/Source/Apps/Power/Power.cpp +++ b/Tactility/Source/app/Power/Power.cpp @@ -1,11 +1,11 @@ -#include "App.h" +#include "app/App.h" #include "Assets.h" #include "lvgl.h" #include "Tactility.h" #include "Timer.h" -#include "Ui/LvglSync.h" -#include "Ui/Style.h" -#include "Ui/Toolbar.h" +#include "ui/LvglSync.h" +#include "ui/Style.h" +#include "ui/Toolbar.h" namespace tt::app::settings::power { @@ -22,11 +22,11 @@ typedef struct { static void app_update_ui(void* callbackContext) { auto* data = (AppData*)callbackContext; - bool charging_enabled = data->power->is_charging_enabled(); - const char* charge_state = data->power->is_charging() ? "yes" : "no"; - uint8_t charge_level = data->power->get_charge_level(); + bool charging_enabled = data->power->isChargingEnabled(); + const char* charge_state = data->power->isCharging() ? "yes" : "no"; + uint8_t charge_level = data->power->getChargeLevel(); uint16_t charge_level_scaled = (int16_t)charge_level * 100 / 255; - int32_t current = data->power->get_current(); + int32_t current = data->power->getCurrent(); lvgl::lock(ms_to_ticks(1000)); lv_obj_set_state(data->enable_switch, LV_STATE_CHECKED, charging_enabled); @@ -46,8 +46,8 @@ static void on_power_enabled_change(lv_event_t* event) { if (code == LV_EVENT_VALUE_CHANGED) { bool is_on = lv_obj_has_state(enable_switch, LV_STATE_CHECKED); auto* data = static_cast(lv_event_get_user_data(event)); - if (data->power->is_charging_enabled() != is_on) { - data->power->set_charging_enabled(is_on); + if (data->power->isChargingEnabled() != is_on) { + data->power->setChargingEnabled(is_on); app_update_ui(data); } } @@ -109,11 +109,11 @@ static void app_stop(App app) { delete data; } -extern const AppManifest manifest = { +extern const Manifest manifest = { .id = "Power", .name = "Power", .icon = TT_ASSETS_APP_ICON_POWER_SETTINGS, - .type = AppTypeSettings, + .type = TypeSettings, .on_start = &app_start, .on_stop = &app_stop, .on_show = &app_show, diff --git a/Tactility/Source/Apps/Screenshot/Screenshot.cpp b/Tactility/Source/app/Screenshot/Screenshot.cpp similarity index 91% rename from Tactility/Source/Apps/Screenshot/Screenshot.cpp rename to Tactility/Source/app/Screenshot/Screenshot.cpp index 9cd5d081..f3e3a870 100644 --- a/Tactility/Source/Apps/Screenshot/Screenshot.cpp +++ b/Tactility/Source/app/Screenshot/Screenshot.cpp @@ -17,11 +17,11 @@ static void on_stop(App app) { free(ui); } -extern const AppManifest manifest = { +extern const Manifest manifest = { .id = "Screenshot", .name = "_Screenshot", // So it gets put at the bottom of the desktop and becomes less visible on small screen devices .icon = LV_SYMBOL_IMAGE, - .type = AppTypeSystem, + .type = TypeSystem, .on_start = &on_start, .on_stop = &on_stop, .on_show = &on_show, diff --git a/Tactility/Source/Apps/Screenshot/ScreenshotUi.cpp b/Tactility/Source/app/Screenshot/ScreenshotUi.cpp similarity index 97% rename from Tactility/Source/Apps/Screenshot/ScreenshotUi.cpp rename to Tactility/Source/app/Screenshot/ScreenshotUi.cpp index bd672a07..4f515b9f 100644 --- a/Tactility/Source/Apps/Screenshot/ScreenshotUi.cpp +++ b/Tactility/Source/app/Screenshot/ScreenshotUi.cpp @@ -1,10 +1,10 @@ #include "ScreenshotUi.h" #include "TactilityCore.h" -#include "Hal/Sdcard.h" -#include "Services/Gui/Gui.h" -#include "Services/Screenshot/Screenshot.h" -#include "Ui/Toolbar.h" +#include "hal/sdcard/Sdcard.h" +#include "service/gui/Gui.h" +#include "service/screenshot/Screenshot.h" +#include "ui/Toolbar.h" namespace tt::app::screenshot { @@ -106,7 +106,7 @@ static void create_path_ui(ScreenshotUi* ui, lv_obj_t* parent) { lv_obj_set_flex_grow(path_textarea, 1); ui->path_textarea = path_textarea; if (get_platform() == PlatformEsp) { - if (hal::sdcard::get_state() == hal::sdcard::StateMounted) { + if (hal::sdcard::getState() == hal::sdcard::StateMounted) { lv_textarea_set_text(path_textarea, "A:/sdcard"); } else { lv_textarea_set_text(path_textarea, "Error: no SD card"); diff --git a/Tactility/Source/Apps/Screenshot/ScreenshotUi.h b/Tactility/Source/app/Screenshot/ScreenshotUi.h similarity index 94% rename from Tactility/Source/Apps/Screenshot/ScreenshotUi.h rename to Tactility/Source/app/Screenshot/ScreenshotUi.h index 3a0b68d3..4a11ecc3 100644 --- a/Tactility/Source/Apps/Screenshot/ScreenshotUi.h +++ b/Tactility/Source/app/Screenshot/ScreenshotUi.h @@ -1,6 +1,6 @@ #pragma once -#include "App.h" +#include "app/App.h" #include "lvgl.h" namespace tt::app::screenshot { diff --git a/Tactility/Source/Apps/Settings/Settings.cpp b/Tactility/Source/app/Settings/Settings.cpp similarity index 78% rename from Tactility/Source/Apps/Settings/Settings.cpp rename to Tactility/Source/app/Settings/Settings.cpp index cfc743b5..0d2acec9 100644 --- a/Tactility/Source/Apps/Settings/Settings.cpp +++ b/Tactility/Source/app/Settings/Settings.cpp @@ -1,8 +1,8 @@ -#include "AppManifestRegistry.h" +#include "app/ManifestRegistry.h" #include "Assets.h" #include "Check.h" -#include "Services/Loader/Loader.h" -#include "Ui/Toolbar.h" +#include "service/loader/Loader.h" +#include "ui/Toolbar.h" #include "lvgl.h" #include @@ -11,12 +11,12 @@ namespace tt::app::settings { static void on_app_pressed(lv_event_t* e) { lv_event_code_t code = lv_event_get_code(e); if (code == LV_EVENT_CLICKED) { - const auto* manifest = static_cast(lv_event_get_user_data(e)); + const auto* manifest = static_cast(lv_event_get_user_data(e)); service::loader::start_app(manifest->id, false, Bundle()); } } -static void create_app_widget(const AppManifest* manifest, void* parent) { +static void create_app_widget(const Manifest* manifest, void* parent) { tt_check(parent); auto* list = (lv_obj_t*)parent; const void* icon = !manifest->icon.empty() ? manifest->icon.c_str() : TT_ASSETS_APP_ICON_FALLBACK; @@ -36,17 +36,17 @@ static void on_show(App app, lv_obj_t* parent) { auto manifests = app_manifest_registry_get(); std::sort(manifests.begin(), manifests.end(), SortAppManifestByName); for (const auto& manifest: manifests) { - if (manifest->type == AppTypeSettings) { + if (manifest->type == TypeSettings) { create_app_widget(manifest, list); } } } -extern const AppManifest manifest = { +extern const Manifest manifest = { .id = "Settings", .name = "Settings", .icon = TT_ASSETS_APP_ICON_SETTINGS, - .type = AppTypeSystem, + .type = TypeSystem, .on_start = nullptr, .on_stop = nullptr, .on_show = &on_show, diff --git a/Tactility/Source/Apps/SystemInfo/SystemInfo.cpp b/Tactility/Source/app/SystemInfo/SystemInfo.cpp similarity index 97% rename from Tactility/Source/Apps/SystemInfo/SystemInfo.cpp rename to Tactility/Source/app/SystemInfo/SystemInfo.cpp index fb390e04..bbfece81 100644 --- a/Tactility/Source/Apps/SystemInfo/SystemInfo.cpp +++ b/Tactility/Source/app/SystemInfo/SystemInfo.cpp @@ -1,7 +1,7 @@ #include "Assets.h" #include "lvgl.h" #include "Tactility.h" -#include "Ui/Toolbar.h" +#include "ui/Toolbar.h" namespace tt::app::system_info { @@ -101,11 +101,11 @@ static void on_show(App app, lv_obj_t* parent) { } -extern const AppManifest manifest = { +extern const Manifest manifest = { .id = "SystemInfo", .name = "System Info", .icon = TT_ASSETS_APP_ICON_SYSTEM_INFO, - .type = AppTypeSystem, + .type = TypeSystem, .on_start = nullptr, .on_stop = nullptr, .on_show = &on_show diff --git a/Tactility/Source/Apps/TextViewer/TextViewer.cpp b/Tactility/Source/app/TextViewer/TextViewer.cpp similarity index 88% rename from Tactility/Source/Apps/TextViewer/TextViewer.cpp rename to Tactility/Source/app/TextViewer/TextViewer.cpp index 15d245be..69c4a015 100644 --- a/Tactility/Source/Apps/TextViewer/TextViewer.cpp +++ b/Tactility/Source/app/TextViewer/TextViewer.cpp @@ -1,9 +1,9 @@ #include "Log.h" #include "TextViewer.h" #include "lvgl.h" -#include "Ui/LabelUtils.h" -#include "Ui/Style.h" -#include "Ui/Toolbar.h" +#include "ui/LabelUtils.h" +#include "ui/Style.h" +#include "ui/Toolbar.h" #define TAG "text_viewer" @@ -31,10 +31,10 @@ static void on_show(App app, lv_obj_t* parent) { } } -extern const AppManifest manifest = { +extern const Manifest manifest = { .id = "TextViewer", .name = "Text Viewer", - .type = AppTypeHidden, + .type = TypeHidden, .on_show = &on_show }; diff --git a/Tactility/Source/Apps/TextViewer/TextViewer.h b/Tactility/Source/app/TextViewer/TextViewer.h similarity index 100% rename from Tactility/Source/Apps/TextViewer/TextViewer.h rename to Tactility/Source/app/TextViewer/TextViewer.h diff --git a/Tactility/Source/Apps/WifiConnect/WifiConnect.cpp b/Tactility/Source/app/WifiConnect/WifiConnect.cpp similarity index 95% rename from Tactility/Source/Apps/WifiConnect/WifiConnect.cpp rename to Tactility/Source/app/WifiConnect/WifiConnect.cpp index 1457d7f8..ddc1e1b0 100644 --- a/Tactility/Source/Apps/WifiConnect/WifiConnect.cpp +++ b/Tactility/Source/app/WifiConnect/WifiConnect.cpp @@ -1,11 +1,11 @@ #include "WifiConnect.h" -#include "App.h" +#include "app/App.h" #include "TactilityCore.h" #include "WifiConnectStateUpdating.h" -#include "Services/Loader/Loader.h" -#include "Services/Wifi/Wifi.h" -#include "Ui/LvglSync.h" +#include "service/loader/Loader.h" +#include "service/wifi/Wifi.h" +#include "ui/LvglSync.h" namespace tt::app::wifi_connect { @@ -132,11 +132,11 @@ static void app_stop(App app) { tt_app_set_data(app, nullptr); } -extern const AppManifest manifest = { +extern const Manifest manifest = { .id = "WifiConnect", .name = "Wi-Fi Connect", .icon = LV_SYMBOL_WIFI, - .type = AppTypeSettings, + .type = TypeSettings, .on_start = &app_start, .on_stop = &app_stop, .on_show = &app_show, diff --git a/Tactility/Source/Apps/WifiConnect/WifiConnect.h b/Tactility/Source/app/WifiConnect/WifiConnect.h similarity index 93% rename from Tactility/Source/Apps/WifiConnect/WifiConnect.h rename to Tactility/Source/app/WifiConnect/WifiConnect.h index 366169b0..12fd8067 100644 --- a/Tactility/Source/Apps/WifiConnect/WifiConnect.h +++ b/Tactility/Source/app/WifiConnect/WifiConnect.h @@ -4,7 +4,7 @@ #include "WifiConnectBindings.h" #include "WifiConnectState.h" #include "WifiConnectView.h" -#include "Services/Wifi/Wifi.h" +#include "service/wifi/Wifi.h" namespace tt::app::wifi_connect { diff --git a/Tactility/Source/Apps/WifiConnect/WifiConnectBindings.h b/Tactility/Source/app/WifiConnect/WifiConnectBindings.h similarity index 87% rename from Tactility/Source/Apps/WifiConnect/WifiConnectBindings.h rename to Tactility/Source/app/WifiConnect/WifiConnectBindings.h index 5153861f..a68406c3 100644 --- a/Tactility/Source/Apps/WifiConnect/WifiConnectBindings.h +++ b/Tactility/Source/app/WifiConnect/WifiConnectBindings.h @@ -1,6 +1,6 @@ #pragma once -#include "Services/Wifi/WifiSettings.h" +#include "service/wifi/WifiSettings.h" namespace tt::app::wifi_connect { diff --git a/Tactility/Source/Apps/WifiConnect/WifiConnectBundle.h b/Tactility/Source/app/WifiConnect/WifiConnectBundle.h similarity index 100% rename from Tactility/Source/Apps/WifiConnect/WifiConnectBundle.h rename to Tactility/Source/app/WifiConnect/WifiConnectBundle.h diff --git a/Tactility/Source/Apps/WifiConnect/WifiConnectState.h b/Tactility/Source/app/WifiConnect/WifiConnectState.h similarity index 72% rename from Tactility/Source/Apps/WifiConnect/WifiConnectState.h rename to Tactility/Source/app/WifiConnect/WifiConnectState.h index 7d736a89..e3c69487 100644 --- a/Tactility/Source/Apps/WifiConnect/WifiConnectState.h +++ b/Tactility/Source/app/WifiConnect/WifiConnectState.h @@ -1,8 +1,7 @@ #pragma once -#include "App.h" -#include "Services/Wifi/Wifi.h" -#include "Services/Wifi/WifiSettings.h" +#include "service/wifi/Wifi.h" +#include "service/wifi/WifiSettings.h" namespace tt::app::wifi_connect { diff --git a/Tactility/Source/Apps/WifiConnect/WifiConnectStateUpdating.cpp b/Tactility/Source/app/WifiConnect/WifiConnectStateUpdating.cpp similarity index 100% rename from Tactility/Source/Apps/WifiConnect/WifiConnectStateUpdating.cpp rename to Tactility/Source/app/WifiConnect/WifiConnectStateUpdating.cpp diff --git a/Tactility/Source/Apps/WifiConnect/WifiConnectStateUpdating.h b/Tactility/Source/app/WifiConnect/WifiConnectStateUpdating.h similarity index 100% rename from Tactility/Source/Apps/WifiConnect/WifiConnectStateUpdating.h rename to Tactility/Source/app/WifiConnect/WifiConnectStateUpdating.h diff --git a/Tactility/Source/Apps/WifiConnect/WifiConnectView.cpp b/Tactility/Source/app/WifiConnect/WifiConnectView.cpp similarity index 98% rename from Tactility/Source/Apps/WifiConnect/WifiConnectView.cpp rename to Tactility/Source/app/WifiConnect/WifiConnectView.cpp index 0b161ddf..eceb78eb 100644 --- a/Tactility/Source/Apps/WifiConnect/WifiConnectView.cpp +++ b/Tactility/Source/app/WifiConnect/WifiConnectView.cpp @@ -6,10 +6,10 @@ #include "WifiConnectState.h" #include "WifiConnectStateUpdating.h" #include "lvgl.h" -#include "Services/Gui/Gui.h" -#include "Services/Wifi/WifiSettings.h" -#include "Ui/Style.h" -#include "Ui/Toolbar.h" +#include "service/gui/Gui.h" +#include "service/wifi/WifiSettings.h" +#include "ui/Style.h" +#include "ui/Toolbar.h" namespace tt::app::wifi_connect { diff --git a/Tactility/Source/Apps/WifiConnect/WifiConnectView.h b/Tactility/Source/app/WifiConnect/WifiConnectView.h similarity index 96% rename from Tactility/Source/Apps/WifiConnect/WifiConnectView.h rename to Tactility/Source/app/WifiConnect/WifiConnectView.h index 979b63e7..14c2f79a 100644 --- a/Tactility/Source/Apps/WifiConnect/WifiConnectView.h +++ b/Tactility/Source/app/WifiConnect/WifiConnectView.h @@ -1,5 +1,6 @@ #pragma once +#include "app/App.h" #include "WifiConnectBindings.h" #include "WifiConnectState.h" #include "lvgl.h" diff --git a/Tactility/Source/Apps/WifiManager/WifiManage.cpp b/Tactility/Source/app/WifiManager/WifiManage.cpp similarity index 95% rename from Tactility/Source/Apps/WifiManager/WifiManage.cpp rename to Tactility/Source/app/WifiManager/WifiManage.cpp index ea15a39e..7cfdc9b0 100644 --- a/Tactility/Source/Apps/WifiManager/WifiManage.cpp +++ b/Tactility/Source/app/WifiManager/WifiManage.cpp @@ -1,11 +1,11 @@ #include "WifiManage.h" -#include "App.h" -#include "Apps/WifiConnect/WifiConnectBundle.h" +#include "app/App.h" +#include "app/WifiConnect/WifiConnectBundle.h" #include "TactilityCore.h" -#include "Services/Loader/Loader.h" -#include "Services/Wifi/WifiSettings.h" -#include "Ui/LvglSync.h" +#include "service/loader/Loader.h" +#include "service/wifi/WifiSettings.h" +#include "ui/LvglSync.h" #include "WifiManageStateUpdating.h" #include "WifiManageView.h" @@ -166,11 +166,11 @@ static void app_stop(App app) { tt_app_set_data(app, nullptr); } -extern const AppManifest manifest = { +extern const Manifest manifest = { .id = "WifiManage", .name = "Wi-Fi", .icon = LV_SYMBOL_WIFI, - .type = AppTypeSettings, + .type = TypeSettings, .on_start = &app_start, .on_stop = &app_stop, .on_show = &app_show, diff --git a/Tactility/Source/Apps/WifiManager/WifiManage.h b/Tactility/Source/app/WifiManager/WifiManage.h similarity index 92% rename from Tactility/Source/Apps/WifiManager/WifiManage.h rename to Tactility/Source/app/WifiManager/WifiManage.h index c47655fe..22f51b4a 100644 --- a/Tactility/Source/Apps/WifiManager/WifiManage.h +++ b/Tactility/Source/app/WifiManager/WifiManage.h @@ -2,7 +2,7 @@ #include "Mutex.h" #include "WifiManageView.h" -#include "Services/Wifi/Wifi.h" +#include "service/wifi/Wifi.h" namespace tt::app::wifi_manage { diff --git a/Tactility/Source/Apps/WifiManager/WifiManageBindings.h b/Tactility/Source/app/WifiManager/WifiManageBindings.h similarity index 100% rename from Tactility/Source/Apps/WifiManager/WifiManageBindings.h rename to Tactility/Source/app/WifiManager/WifiManageBindings.h diff --git a/Tactility/Source/Apps/WifiManager/WifiManageState.h b/Tactility/Source/app/WifiManager/WifiManageState.h similarity index 91% rename from Tactility/Source/Apps/WifiManager/WifiManageState.h rename to Tactility/Source/app/WifiManager/WifiManageState.h index ec613e6e..119dd527 100644 --- a/Tactility/Source/Apps/WifiManager/WifiManageState.h +++ b/Tactility/Source/app/WifiManager/WifiManageState.h @@ -1,6 +1,6 @@ #pragma once -#include "Services/Wifi/Wifi.h" +#include "service/wifi/Wifi.h" namespace tt::app::wifi_manage { diff --git a/Tactility/Source/Apps/WifiManager/WifiManageStateUpdating.cpp b/Tactility/Source/app/WifiManager/WifiManageStateUpdating.cpp similarity index 100% rename from Tactility/Source/Apps/WifiManager/WifiManageStateUpdating.cpp rename to Tactility/Source/app/WifiManager/WifiManageStateUpdating.cpp diff --git a/Tactility/Source/Apps/WifiManager/WifiManageStateUpdating.h b/Tactility/Source/app/WifiManager/WifiManageStateUpdating.h similarity index 100% rename from Tactility/Source/Apps/WifiManager/WifiManageStateUpdating.h rename to Tactility/Source/app/WifiManager/WifiManageStateUpdating.h diff --git a/Tactility/Source/Apps/WifiManager/WifiManageView.cpp b/Tactility/Source/app/WifiManager/WifiManageView.cpp similarity index 98% rename from Tactility/Source/Apps/WifiManager/WifiManageView.cpp rename to Tactility/Source/app/WifiManager/WifiManageView.cpp index 930897fe..6375c510 100644 --- a/Tactility/Source/Apps/WifiManager/WifiManageView.cpp +++ b/Tactility/Source/app/WifiManager/WifiManageView.cpp @@ -2,10 +2,10 @@ #include "Log.h" #include "WifiManageState.h" -#include "Services/Statusbar/Statusbar.h" -#include "Services/Wifi/Wifi.h" -#include "Ui/Style.h" -#include "Ui/Toolbar.h" +#include "service/statusbar/Statusbar.h" +#include "service/wifi/Wifi.h" +#include "ui/Style.h" +#include "ui/Toolbar.h" namespace tt::app::wifi_manage { diff --git a/Tactility/Source/Apps/WifiManager/WifiManageView.h b/Tactility/Source/app/WifiManager/WifiManageView.h similarity index 96% rename from Tactility/Source/Apps/WifiManager/WifiManageView.h rename to Tactility/Source/app/WifiManager/WifiManageView.h index 27f6912c..27bd73b5 100644 --- a/Tactility/Source/Apps/WifiManager/WifiManageView.h +++ b/Tactility/Source/app/WifiManager/WifiManageView.h @@ -1,6 +1,6 @@ #pragma once -#include "App.h" +#include "app/App.h" #include "WifiManageBindings.h" #include "WifiManageState.h" #include "lvgl.h" diff --git a/Tactility/Source/Services/Gui/Gui.cpp b/Tactility/Source/service/gui/Gui.cpp similarity index 87% rename from Tactility/Source/Services/Gui/Gui.cpp rename to Tactility/Source/service/gui/Gui.cpp index e3e915f3..898bbe26 100644 --- a/Tactility/Source/Services/Gui/Gui.cpp +++ b/Tactility/Source/service/gui/Gui.cpp @@ -1,9 +1,8 @@ -#include "Services/Gui/Gui_i.h" - #include "Tactility.h" -#include "Services/Loader/Loader.h" -#include "Ui/LvglKeypad.h" -#include "Ui/LvglSync.h" +#include "service/gui/Gui_i.h" +#include "service/loader/Loader.h" +#include "ui/LvglKeypad.h" +#include "ui/LvglSync.h" #ifdef ESP_PLATFORM #include "freertos/FreeRTOS.h" @@ -25,8 +24,8 @@ typedef void (*PubSubCallback)(const void* message, void* context); void loader_callback(const void* message, TT_UNUSED void* context) { auto* event = static_cast(message); if (event->type == loader::LoaderEventTypeApplicationShowing) { - App* app = event->app_showing.app; - const AppManifest& app_manifest = tt_app_get_manifest(app); + app::App* app = event->app_showing.app; + const app::Manifest& app_manifest = app::tt_app_get_manifest(app); show_app(app, app_manifest.on_show, app_manifest.on_hide); } else if (event->type == loader::LoaderEventTypeApplicationHiding) { hide_app(); @@ -36,7 +35,7 @@ void loader_callback(const void* message, TT_UNUSED void* context) { Gui* gui_alloc() { auto* instance = static_cast(malloc(sizeof(Gui))); memset(instance, 0, sizeof(Gui)); - tt_check(instance != NULL); + tt_check(instance != nullptr); instance->thread = new Thread( "gui", 4096, // Last known minimum was 2800 for launching desktop @@ -84,9 +83,9 @@ void request_draw() { thread_flags_set(thread_id, GUI_THREAD_FLAG_DRAW); } -void show_app(App app, ViewPortShowCallback on_show, ViewPortHideCallback on_hide) { +void show_app(app::App app, ViewPortShowCallback on_show, ViewPortHideCallback on_hide) { lock(); - tt_check(gui->app_view_port == NULL); + tt_check(gui->app_view_port == nullptr); gui->app_view_port = view_port_alloc(app, on_show, on_hide); unlock(); request_draw(); @@ -95,7 +94,7 @@ void show_app(App app, ViewPortShowCallback on_show, ViewPortHideCallback on_hid void hide_app() { lock(); ViewPort* view_port = gui->app_view_port; - tt_check(view_port != NULL); + tt_check(view_port != nullptr); // We must lock the LVGL port, because the viewport hide callbacks // might call LVGL APIs (e.g. to remove the keyboard from the screen root) @@ -155,10 +154,10 @@ static void stop(TT_UNUSED Service& service) { gui_free(gui); } -extern const ServiceManifest manifest = { +extern const Manifest manifest = { .id = "Gui", - .on_start = &start, - .on_stop = &stop + .onStart = &start, + .onStop = &stop }; // endregion diff --git a/Tactility/Source/Services/Gui/Gui.h b/Tactility/Source/service/gui/Gui.h similarity index 90% rename from Tactility/Source/Services/Gui/Gui.h rename to Tactility/Source/service/gui/Gui.h index 3767d370..56bd53c4 100644 --- a/Tactility/Source/Services/Gui/Gui.h +++ b/Tactility/Source/service/gui/Gui.h @@ -1,7 +1,6 @@ #pragma once -#include "App.h" -#include "ServiceManifest.h" +#include "app/App.h" #include "ViewPort.h" namespace tt::service::gui { @@ -15,7 +14,7 @@ typedef struct Gui Gui; * @param on_show * @param on_hide */ -void show_app(App app, ViewPortShowCallback on_show, ViewPortHideCallback on_hide); +void show_app(app::App app, ViewPortShowCallback on_show, ViewPortHideCallback on_hide); /** * Hide the current app's viewport. diff --git a/Tactility/Source/Services/Gui/GuiDraw.cpp b/Tactility/Source/service/gui/GuiDraw.cpp similarity index 85% rename from Tactility/Source/Services/Gui/GuiDraw.cpp rename to Tactility/Source/service/gui/GuiDraw.cpp index 2d6a9a7e..8e2cad71 100644 --- a/Tactility/Source/Services/Gui/GuiDraw.cpp +++ b/Tactility/Source/service/gui/GuiDraw.cpp @@ -1,15 +1,15 @@ #include "Check.h" #include "Log.h" -#include "Services/Gui/Gui_i.h" -#include "Ui/LvglSync.h" -#include "Ui/Statusbar.h" -#include "Ui/Style.h" +#include "service/gui/Gui_i.h" +#include "ui/LvglSync.h" +#include "ui/Statusbar.h" +#include "ui/Style.h" namespace tt::service::gui { #define TAG "gui" -static lv_obj_t* create_app_views(Gui* gui, lv_obj_t* parent, App app) { +static lv_obj_t* create_app_views(Gui* gui, lv_obj_t* parent, app::App app) { lvgl::obj_set_style_bg_blacken(parent); lv_obj_t* vertical_container = lv_obj_create(parent); @@ -19,7 +19,7 @@ static lv_obj_t* create_app_views(Gui* gui, lv_obj_t* parent, App app) { lvgl::obj_set_style_bg_blacken(vertical_container); // TODO: Move statusbar into separate ViewPort - AppFlags flags = tt_app_get_flags(app); + app::Flags flags = app::tt_app_get_flags(app); if (flags.show_statusbar) { lvgl::statusbar_create(vertical_container); } @@ -49,7 +49,7 @@ void redraw(Gui* gui) { ViewPort* view_port = gui->app_view_port; if (view_port != nullptr) { - App app = view_port->app; + app::App app = view_port->app; lv_obj_t* container = create_app_views(gui, gui->lvgl_parent, app); view_port_show(view_port, container); } else { diff --git a/Tactility/Source/Services/Gui/Keyboard.cpp b/Tactility/Source/service/gui/Keyboard.cpp similarity index 93% rename from Tactility/Source/Services/Gui/Keyboard.cpp rename to Tactility/Source/service/gui/Keyboard.cpp index 49e1ce8a..64b51e67 100644 --- a/Tactility/Source/Services/Gui/Keyboard.cpp +++ b/Tactility/Source/service/gui/Keyboard.cpp @@ -1,8 +1,8 @@ -#include "Services/Gui/Gui_i.h" - +#include "Check.h" #include "TactilityConfig.h" -#include "Ui/LvglKeypad.h" -#include "Ui/LvglSync.h" +#include "service/gui/Gui_i.h" +#include "ui/LvglKeypad.h" +#include "ui/LvglSync.h" namespace tt::service::gui { diff --git a/Tactility/Source/Services/Gui/ViewPort.cpp b/Tactility/Source/service/gui/ViewPort.cpp similarity index 92% rename from Tactility/Source/Services/Gui/ViewPort.cpp rename to Tactility/Source/service/gui/ViewPort.cpp index bcafbcd8..e825b50e 100644 --- a/Tactility/Source/Services/Gui/ViewPort.cpp +++ b/Tactility/Source/service/gui/ViewPort.cpp @@ -1,15 +1,15 @@ #include "ViewPort.h" #include "Check.h" -#include "Services/Gui/ViewPort_i.h" -#include "Ui/Style.h" +#include "service/gui/ViewPort_i.h" +#include "ui/Style.h" namespace tt::service::gui { #define TAG "viewport" ViewPort* view_port_alloc( - App app, + app::App app, ViewPortShowCallback on_show, ViewPortHideCallback on_hide ) { diff --git a/Tactility/Source/Services/Gui/ViewPort.h b/Tactility/Source/service/gui/ViewPort.h similarity index 82% rename from Tactility/Source/Services/Gui/ViewPort.h rename to Tactility/Source/service/gui/ViewPort.h index 9e848f05..c4381534 100644 --- a/Tactility/Source/Services/Gui/ViewPort.h +++ b/Tactility/Source/service/gui/ViewPort.h @@ -1,6 +1,6 @@ #pragma once -#include "App.h" +#include "app/App.h" #include "lvgl.h" namespace tt::service::gui { @@ -8,13 +8,13 @@ namespace tt::service::gui { /** ViewPort Draw callback * @warning called from GUI thread */ -typedef void (*ViewPortShowCallback)(App app, lv_obj_t* parent); -typedef void (*ViewPortHideCallback)(App app); +typedef void (*ViewPortShowCallback)(app::App app, lv_obj_t* parent); +typedef void (*ViewPortHideCallback)(app::App app); // TODO: Move internally, use handle publicly typedef struct { - App app; + app::App app; ViewPortShowCallback on_show; ViewPortHideCallback _Nullable on_hide; bool app_toolbar; @@ -30,7 +30,7 @@ typedef struct { * @return ViewPort instance */ ViewPort* view_port_alloc( - App app, + app::App app, ViewPortShowCallback on_show, ViewPortHideCallback on_hide ); diff --git a/Tactility/Source/Services/Loader/Loader.cpp b/Tactility/Source/service/loader/Loader.cpp similarity index 74% rename from Tactility/Source/Services/Loader/Loader.cpp rename to Tactility/Source/service/loader/Loader.cpp index 805803aa..a2a1263d 100644 --- a/Tactility/Source/Services/Loader/Loader.cpp +++ b/Tactility/Source/service/loader/Loader.cpp @@ -1,16 +1,17 @@ -#include "ApiLock.h" -#include "AppManifest.h" -#include "AppManifestRegistry.h" -#include "App_i.h" -#include "ServiceManifest.h" -#include "Services/Gui/Gui.h" -#include "Services/Loader/Loader_i.h" +#include "Tactility.h" +#include "app/Manifest.h" +#include "app/ManifestRegistry.h" +#include "service/Manifest.h" +#include "service/gui/Gui.h" +#include "service/loader/Loader_i.h" #ifdef ESP_PLATFORM #include "esp_heap_caps.h" #include "freertos/FreeRTOS.h" #else #include "FreeRTOS.h" +#include "ui/LvglSync.h" + #endif namespace tt::service::loader { @@ -39,7 +40,7 @@ static Loader* loader_alloc() { ); loader_singleton->mutex = tt_mutex_alloc(MutexTypeRecursive); loader_singleton->app_stack_index = -1; - memset(loader_singleton->app_stack, 0, sizeof(App) * APP_STACK_SIZE); + memset(loader_singleton->app_stack, 0, sizeof(app::App) * APP_STACK_SIZE); return loader_singleton; } @@ -67,6 +68,7 @@ static void loader_unlock() { LoaderStatus start_app(const std::string& id, bool blocking, const Bundle& bundle) { tt_assert(loader_singleton); + LoaderMessageLoaderStatusResult result = { .value = LoaderStatusOk }; @@ -74,15 +76,19 @@ LoaderStatus start_app(const std::string& id, bool blocking, const Bundle& bundl auto* start_message = new LoaderMessageAppStart(id, bundle); LoaderMessage message(start_message, result); - ApiLock lock = blocking ? tt_api_lock_alloc_locked() : nullptr; - if (lock != nullptr) { - message.setLock(lock); + EventFlag* event_flag = blocking ? new EventFlag() : nullptr; + if (event_flag != nullptr) { + message.setApiLock(event_flag); } loader_singleton->queue.put(&message, TtWaitForever); - if (lock != nullptr) { - tt_api_lock_wait_unlock_and_free(message.api_lock); + if (event_flag != nullptr) { + /* TODO: Check if task id is not the LVGL one, + because otherwise this fails as the apps starting logic will try to lock lvgl + to update the UI and fail. */ + event_flag->wait(TT_API_LOCK_EVENT); + delete event_flag; } return result.value; @@ -94,10 +100,10 @@ void stop_app() { loader_singleton->queue.put(&message, TtWaitForever); } -App _Nullable get_current_app() { +app::App _Nullable get_current_app() { tt_assert(loader_singleton); loader_lock(); - App app = (loader_singleton->app_stack_index >= 0) + app::App app = (loader_singleton->app_stack_index >= 0) ? loader_singleton->app_stack[loader_singleton->app_stack_index] : nullptr; loader_unlock(); @@ -112,26 +118,26 @@ PubSub* get_pubsub() { return loader_singleton->pubsub_external; } -static const char* app_state_to_string(AppState state) { +static const char* app_state_to_string(app::State state) { switch (state) { - case AppStateInitial: + case app::StateInitial: return "initial"; - case AppStateStarted: + case app::StateStarted: return "started"; - case AppStateShowing: + case app::StateShowing: return "showing"; - case AppStateHiding: + case app::StateHiding: return "hiding"; - case AppStateStopped: + case app::StateStopped: return "stopped"; default: return "?"; } } -static void app_transition_to_state(App app, AppState state) { - const AppManifest& manifest = tt_app_get_manifest(app); - const AppState old_state = tt_app_get_state(app); +static void app_transition_to_state(app::App app, app::State state) { + const app::Manifest& manifest = app::tt_app_get_manifest(app); + const app::State old_state = app::tt_app_get_state(app); TT_LOG_I( TAG, @@ -142,49 +148,49 @@ static void app_transition_to_state(App app, AppState state) { ); switch (state) { - case AppStateInitial: - tt_app_set_state(app, AppStateInitial); + case app::StateInitial: + tt_app_set_state(app, app::StateInitial); break; - case AppStateStarted: + case app::StateStarted: if (manifest.on_start != nullptr) { manifest.on_start(app); } - tt_app_set_state(app, AppStateStarted); + tt_app_set_state(app, app::StateStarted); break; - case AppStateShowing: { + case app::StateShowing: { LoaderEvent event_showing = { .type = LoaderEventTypeApplicationShowing, .app_showing = { - .app = static_cast(app) + .app = static_cast(app) } }; tt_pubsub_publish(loader_singleton->pubsub_external, &event_showing); - tt_app_set_state(app, AppStateShowing); + tt_app_set_state(app, app::StateShowing); break; } - case AppStateHiding: { + case app::StateHiding: { LoaderEvent event_hiding = { .type = LoaderEventTypeApplicationHiding, .app_hiding = { - .app = static_cast(app) + .app = static_cast(app) } }; tt_pubsub_publish(loader_singleton->pubsub_external, &event_hiding); - tt_app_set_state(app, AppStateHiding); + tt_app_set_state(app, app::StateHiding); break; } - case AppStateStopped: + case app::StateStopped: if (manifest.on_stop) { manifest.on_stop(app); } - tt_app_set_data(app, nullptr); - tt_app_set_state(app, AppStateStopped); + app::tt_app_set_data(app, nullptr); + tt_app_set_state(app, app::StateStopped); break; } } static LoaderStatus loader_do_start_app_with_manifest( - const AppManifest* manifest, + const app::Manifest* manifest, const Bundle& bundle ) { TT_LOG_I(TAG, "start with manifest %s", manifest->id.c_str()); @@ -199,19 +205,19 @@ static LoaderStatus loader_do_start_app_with_manifest( int8_t previous_index = loader_singleton->app_stack_index; loader_singleton->app_stack_index++; - App app = tt_app_alloc(*manifest, bundle); + app::App app = tt_app_alloc(*manifest, bundle); tt_check(loader_singleton->app_stack[loader_singleton->app_stack_index] == nullptr); loader_singleton->app_stack[loader_singleton->app_stack_index] = app; - app_transition_to_state(app, AppStateInitial); - app_transition_to_state(app, AppStateStarted); + app_transition_to_state(app, app::StateInitial); + app_transition_to_state(app, app::StateStarted); // We might have to hide the previous app first if (previous_index != -1) { - App previous_app = loader_singleton->app_stack[previous_index]; - app_transition_to_state(previous_app, AppStateHiding); + app::App previous_app = loader_singleton->app_stack[previous_index]; + app_transition_to_state(previous_app, app::StateHiding); } - app_transition_to_state(app, AppStateShowing); + app_transition_to_state(app, app::StateShowing); loader_unlock(); @@ -221,7 +227,7 @@ static LoaderStatus loader_do_start_app_with_manifest( LoaderEvent event_external = { .type = LoaderEventTypeApplicationStarted, .app_started = { - .app = static_cast(app) + .app = static_cast(app) } }; tt_pubsub_publish(loader_singleton->pubsub_external, &event_external); @@ -235,7 +241,7 @@ static LoaderStatus do_start_by_id( ) { TT_LOG_I(TAG, "Start by id %s", id.c_str()); - const AppManifest* manifest = app_manifest_registry_find_by_id(id); + const app::Manifest* manifest = app::app_manifest_registry_find_by_id(id); if (manifest == nullptr) { return LoaderStatusErrorUnknownApp; } else { @@ -262,12 +268,12 @@ static void do_stop_app() { } // Stop current app - App app_to_stop = loader_singleton->app_stack[current_app_index]; - const AppManifest& manifest = tt_app_get_manifest(app_to_stop); - app_transition_to_state(app_to_stop, AppStateHiding); - app_transition_to_state(app_to_stop, AppStateStopped); + app::App app_to_stop = loader_singleton->app_stack[current_app_index]; + const app::Manifest& manifest = app::tt_app_get_manifest(app_to_stop); + app_transition_to_state(app_to_stop, app::StateHiding); + app_transition_to_state(app_to_stop, app::StateStopped); - tt_app_free(app_to_stop); + app::tt_app_free(app_to_stop); loader_singleton->app_stack[current_app_index] = nullptr; loader_singleton->app_stack_index--; @@ -277,8 +283,8 @@ static void do_stop_app() { // Resume previous app tt_assert(loader_singleton->app_stack[loader_singleton->app_stack_index] != nullptr); - App app_to_resume = loader_singleton->app_stack[loader_singleton->app_stack_index]; - app_transition_to_state(app_to_resume, AppStateShowing); + app::App app_to_resume = loader_singleton->app_stack[loader_singleton->app_stack_index]; + app_transition_to_state(app_to_resume, app::StateShowing); loader_unlock(); @@ -309,7 +315,7 @@ static int32_t loader_main(TT_UNUSED void* parameter) { message.payload.start->bundle ); if (message.api_lock != nullptr) { - tt_api_lock_unlock(message.api_lock); + message.api_lock->set(TT_API_LOCK_EVENT); } message.cleanup(); break; @@ -354,10 +360,10 @@ static void loader_stop(TT_UNUSED Service& service) { loader_singleton = nullptr; } -extern const ServiceManifest manifest = { +extern const Manifest manifest = { .id = "Loader", - .on_start = &loader_start, - .on_stop = &loader_stop + .onStart = &loader_start, + .onStop = &loader_stop }; // endregion diff --git a/Tactility/Source/Services/Loader/Loader.h b/Tactility/Source/service/loader/Loader.h similarity index 87% rename from Tactility/Source/Services/Loader/Loader.h rename to Tactility/Source/service/loader/Loader.h index 2a81f8ca..aad722ac 100644 --- a/Tactility/Source/Services/Loader/Loader.h +++ b/Tactility/Source/service/loader/Loader.h @@ -1,10 +1,9 @@ #pragma once -#include "AppManifest.h" +#include "app/Manifest.h" #include "Bundle.h" #include "Pubsub.h" -#include "ServiceManifest.h" -#include "TactilityCore.h" +#include "service/Manifest.h" namespace tt::service::loader { @@ -25,19 +24,19 @@ typedef enum { } LoaderEventType; typedef struct { - App* app; + app::App* app; } LoaderEventAppStarted; typedef struct { - App* app; + app::App* app; } LoaderEventAppShowing; typedef struct { - App* app; + app::App* app; } LoaderEventAppHiding; typedef struct { - const AppManifest* manifest; + const app::Manifest* manifest; } LoaderEventAppStopped; typedef struct { @@ -64,7 +63,7 @@ LoaderStatus start_app(const std::string& id, bool blocking, const Bundle& bundl */ void stop_app(); -App _Nullable get_current_app(); +app::App _Nullable get_current_app(); /** * @brief PubSub for LoaderEvent diff --git a/Tactility/Source/Services/Screenshot/Screenshot.cpp b/Tactility/Source/service/screenshot/Screenshot.cpp similarity index 88% rename from Tactility/Source/Services/Screenshot/Screenshot.cpp rename to Tactility/Source/service/screenshot/Screenshot.cpp index 0ebf42ed..90e9551d 100644 --- a/Tactility/Source/Services/Screenshot/Screenshot.cpp +++ b/Tactility/Source/service/screenshot/Screenshot.cpp @@ -3,15 +3,15 @@ #include "Mutex.h" #include "ScreenshotTask.h" -#include "Service.h" -#include "ServiceRegistry.h" +#include "service/Service.h" +#include "service/ServiceRegistry.h" #include "TactilityCore.h" namespace tt::service::screenshot { #define TAG "sdcard_service" -extern const ServiceManifest manifest; +extern const Manifest manifest; typedef struct { Mutex* mutex; @@ -57,7 +57,7 @@ static void on_stop(Service& service) { } void start_apps(const char* path) { - _Nullable auto* service = service_find(manifest.id); + _Nullable auto* service = findServiceById(manifest.id); if (service == nullptr) { TT_LOG_E(TAG, "Service not found"); return; @@ -76,7 +76,7 @@ void start_apps(const char* path) { } void start_timed(const char* path, uint8_t delay_in_seconds, uint8_t amount) { - _Nullable auto* service = service_find(manifest.id); + _Nullable auto* service = findServiceById(manifest.id); if (service == nullptr) { TT_LOG_E(TAG, "Service not found"); return; @@ -95,7 +95,7 @@ void start_timed(const char* path, uint8_t delay_in_seconds, uint8_t amount) { } void stop() { - _Nullable Service* service = service_find(manifest.id); + _Nullable Service* service = findServiceById(manifest.id); if (service == nullptr) { TT_LOG_E(TAG, "Service not found"); return; @@ -115,7 +115,7 @@ void stop() { } ScreenshotMode get_mode() { - _Nullable auto* service = service_find(manifest.id); + _Nullable auto* service = findServiceById(manifest.id); if (service == nullptr) { TT_LOG_E(TAG, "Service not found"); return ScreenshotModeNone; @@ -132,10 +132,10 @@ bool is_started() { return get_mode() != ScreenshotModeNone; } -extern const ServiceManifest manifest = { +extern const Manifest manifest = { .id = "Screenshot", - .on_start = &on_start, - .on_stop = &on_stop + .onStart = &on_start, + .onStop = &on_stop }; } // namespace diff --git a/Tactility/Source/Services/Screenshot/Screenshot.h b/Tactility/Source/service/screenshot/Screenshot.h similarity index 100% rename from Tactility/Source/Services/Screenshot/Screenshot.h rename to Tactility/Source/service/screenshot/Screenshot.h diff --git a/Tactility/Source/Services/Screenshot/ScreenshotTask.cpp b/Tactility/Source/service/screenshot/ScreenshotTask.cpp similarity index 95% rename from Tactility/Source/Services/Screenshot/ScreenshotTask.cpp rename to Tactility/Source/service/screenshot/ScreenshotTask.cpp index 05247fff..e55d562b 100644 --- a/Tactility/Source/Services/Screenshot/ScreenshotTask.cpp +++ b/Tactility/Source/service/screenshot/ScreenshotTask.cpp @@ -1,12 +1,12 @@ #include "ScreenshotTask.h" #include "lv_screenshot.h" -#include "App.h" +#include "app/App.h" #include "Mutex.h" #include "TactilityCore.h" #include "Thread.h" -#include "Services/Loader/Loader.h" -#include "Ui/LvglSync.h" +#include "service/loader/Loader.h" +#include "ui/LvglSync.h" namespace tt::service::screenshot { @@ -98,9 +98,9 @@ static int32_t screenshot_task(void* context) { break; // Interrupted loop } } else if (data->work.type == TASK_WORK_TYPE_APPS) { - App _Nullable app = loader::get_current_app(); + app::App _Nullable app = loader::get_current_app(); if (app) { - const AppManifest& manifest = tt_app_get_manifest(app); + const app::Manifest& manifest = app::tt_app_get_manifest(app); if (manifest.id != last_app_id) { delay_ms(100); last_app_id = manifest.id; diff --git a/Tactility/Source/Services/Screenshot/ScreenshotTask.h b/Tactility/Source/service/screenshot/ScreenshotTask.h similarity index 100% rename from Tactility/Source/Services/Screenshot/ScreenshotTask.h rename to Tactility/Source/service/screenshot/ScreenshotTask.h diff --git a/Tactility/Source/Services/Statusbar/Statusbar.cpp b/Tactility/Source/service/statusbar/Statusbar.cpp similarity index 95% rename from Tactility/Source/Services/Statusbar/Statusbar.cpp rename to Tactility/Source/service/statusbar/Statusbar.cpp index 0f0f024b..79b76ef4 100644 --- a/Tactility/Source/Services/Statusbar/Statusbar.cpp +++ b/Tactility/Source/service/statusbar/Statusbar.cpp @@ -1,11 +1,11 @@ #include "Assets.h" -#include "Hal/Power.h" -#include "Hal/Sdcard.h" +#include "hal/Power.h" +#include "hal/sdcard/Sdcard.h" #include "Mutex.h" -#include "Service.h" -#include "Services/Wifi/Wifi.h" +#include "service/Service.h" +#include "service/wifi/Wifi.h" #include "Tactility.h" -#include "Ui/Statusbar.h" +#include "ui/Statusbar.h" namespace tt::service::statusbar { @@ -86,7 +86,7 @@ static _Nullable const char* sdcard_get_status_icon(hal::sdcard::State state) { } static void update_sdcard_icon(ServiceData* data) { - hal::sdcard::State state = hal::sdcard::get_state(); + hal::sdcard::State state = hal::sdcard::getState(); const char* desired_icon = sdcard_get_status_icon(state); if (data->sdcard_last_icon != desired_icon) { lvgl::statusbar_icon_set_image(data->sdcard_icon_id, desired_icon); @@ -102,7 +102,7 @@ static void update_sdcard_icon(ServiceData* data) { static _Nullable const char* power_get_status_icon() { _Nullable const hal::Power* power = getConfiguration()->hardware->power; if (power != nullptr) { - uint8_t charge = power->get_charge_level(); + uint8_t charge = power->getChargeLevel(); if (charge >= 230) { return TT_ASSETS_ICON_POWER_100; } else if (charge >= 161) { @@ -207,10 +207,10 @@ static void on_stop(Service& service) { service_data_free(data); } -extern const ServiceManifest manifest = { +extern const Manifest manifest = { .id = "Statusbar", - .on_start = &on_start, - .on_stop = &on_stop + .onStart = &on_start, + .onStop = &on_stop }; // endregion service diff --git a/Tactility/Source/Services/Statusbar/Statusbar.h b/Tactility/Source/service/statusbar/Statusbar.h similarity index 100% rename from Tactility/Source/Services/Statusbar/Statusbar.h rename to Tactility/Source/service/statusbar/Statusbar.h diff --git a/Tactility/Source/Ui/LabelUtils.cpp b/Tactility/Source/ui/LabelUtils.cpp similarity index 100% rename from Tactility/Source/Ui/LabelUtils.cpp rename to Tactility/Source/ui/LabelUtils.cpp diff --git a/Tactility/Source/Ui/LabelUtils.h b/Tactility/Source/ui/LabelUtils.h similarity index 100% rename from Tactility/Source/Ui/LabelUtils.h rename to Tactility/Source/ui/LabelUtils.h diff --git a/Tactility/Source/LvglInit.cpp b/Tactility/Source/ui/LvglInit.cpp similarity index 79% rename from Tactility/Source/LvglInit.cpp rename to Tactility/Source/ui/LvglInit.cpp index 7c7afba0..c492b9ab 100644 --- a/Tactility/Source/LvglInit.cpp +++ b/Tactility/Source/ui/LvglInit.cpp @@ -1,10 +1,10 @@ -#include "Apps/Display/DisplayPreferences.h" +#include "app/Display/DisplayPreferences.h" #include "lvgl.h" -#include "LvglInit_i.h" +#include "hal/Configuration.h" -namespace tt { +namespace tt::ui { -void lvgl_init(const hal::Configuration* config) { +void initLvgl(const hal::Configuration* config) { hal::SetBacklightDuty set_backlight_duty = config->display.setBacklightDuty; if (set_backlight_duty != nullptr) { int32_t backlight_duty = app::settings::display::preferences_get_backlight_duty(); diff --git a/Tactility/Source/Ui/LvglKeypad.cpp b/Tactility/Source/ui/LvglKeypad.cpp similarity index 100% rename from Tactility/Source/Ui/LvglKeypad.cpp rename to Tactility/Source/ui/LvglKeypad.cpp diff --git a/Tactility/Source/Ui/LvglKeypad.h b/Tactility/Source/ui/LvglKeypad.h similarity index 100% rename from Tactility/Source/Ui/LvglKeypad.h rename to Tactility/Source/ui/LvglKeypad.h diff --git a/Tactility/Source/Ui/LvglSync.cpp b/Tactility/Source/ui/LvglSync.cpp similarity index 54% rename from Tactility/Source/Ui/LvglSync.cpp rename to Tactility/Source/ui/LvglSync.cpp index a02b4700..39efeaf7 100644 --- a/Tactility/Source/Ui/LvglSync.cpp +++ b/Tactility/Source/ui/LvglSync.cpp @@ -1,27 +1,25 @@ #include "LvglSync.h" +#include "Check.h" + namespace tt::lvgl { static LvglLock lock_singleton = nullptr; static LvglUnlock unlock_singleton = nullptr; -void sync_set(LvglLock lock, LvglUnlock unlock) { +void syncSet(LvglLock lock, LvglUnlock unlock) { lock_singleton = lock; unlock_singleton = unlock; } bool lock(uint32_t timeout_ticks) { - if (lock_singleton) { - return lock_singleton(timeout_ticks); - } else { - return true; - } + tt_check(lock_singleton); + return lock_singleton(timeout_ticks); } void unlock() { - if (unlock_singleton) { - unlock_singleton(); - } + tt_check(unlock_singleton); + unlock_singleton(); } } // namespace diff --git a/Tactility/Source/Ui/LvglSync.h b/Tactility/Source/ui/LvglSync.h similarity index 75% rename from Tactility/Source/Ui/LvglSync.h rename to Tactility/Source/ui/LvglSync.h index daa7b315..bdce15d0 100644 --- a/Tactility/Source/Ui/LvglSync.h +++ b/Tactility/Source/ui/LvglSync.h @@ -1,6 +1,5 @@ #pragma once -#include #include namespace tt::lvgl { @@ -8,7 +7,7 @@ namespace tt::lvgl { typedef bool (*LvglLock)(uint32_t timeout_ticks); typedef void (*LvglUnlock)(); -void sync_set(LvglLock lock, LvglUnlock unlock); +void syncSet(LvglLock lock, LvglUnlock unlock); bool lock(uint32_t timeout_ticks); void unlock(); diff --git a/Tactility/Source/Ui/Spacer.cpp b/Tactility/Source/ui/Spacer.cpp similarity index 100% rename from Tactility/Source/Ui/Spacer.cpp rename to Tactility/Source/ui/Spacer.cpp diff --git a/Tactility/Source/Ui/Spacer.h b/Tactility/Source/ui/Spacer.h similarity index 100% rename from Tactility/Source/Ui/Spacer.h rename to Tactility/Source/ui/Spacer.h diff --git a/Tactility/Source/Ui/Statusbar.cpp b/Tactility/Source/ui/Statusbar.cpp similarity index 99% rename from Tactility/Source/Ui/Statusbar.cpp rename to Tactility/Source/ui/Statusbar.cpp index 1821172b..4f4909c0 100644 --- a/Tactility/Source/Ui/Statusbar.cpp +++ b/Tactility/Source/ui/Statusbar.cpp @@ -4,8 +4,8 @@ #include "Mutex.h" #include "Pubsub.h" #include "TactilityCore.h" -#include "Ui/Spacer.h" -#include "Ui/Style.h" +#include "ui/Spacer.h" +#include "ui/Style.h" #include "LvglSync.h" #include "lvgl.h" diff --git a/Tactility/Source/Ui/Statusbar.h b/Tactility/Source/ui/Statusbar.h similarity index 95% rename from Tactility/Source/Ui/Statusbar.h rename to Tactility/Source/ui/Statusbar.h index d4a06390..08ab90e0 100644 --- a/Tactility/Source/Ui/Statusbar.h +++ b/Tactility/Source/ui/Statusbar.h @@ -1,7 +1,7 @@ #pragma once #include "lvgl.h" -#include "App.h" +#include "app/App.h" namespace tt::lvgl { diff --git a/Tactility/Source/Ui/Style.cpp b/Tactility/Source/ui/Style.cpp similarity index 100% rename from Tactility/Source/Ui/Style.cpp rename to Tactility/Source/ui/Style.cpp diff --git a/Tactility/Source/Ui/Style.h b/Tactility/Source/ui/Style.h similarity index 100% rename from Tactility/Source/Ui/Style.h rename to Tactility/Source/ui/Style.h diff --git a/Tactility/Source/Ui/Toolbar.cpp b/Tactility/Source/ui/Toolbar.cpp similarity index 95% rename from Tactility/Source/Ui/Toolbar.cpp rename to Tactility/Source/ui/Toolbar.cpp index dd2e1c64..275877ff 100644 --- a/Tactility/Source/Ui/Toolbar.cpp +++ b/Tactility/Source/ui/Toolbar.cpp @@ -1,9 +1,10 @@ #define LV_USE_PRIVATE_API 1 // For actual lv_obj_t declaration #include "Toolbar.h" +#include "Tactility.h" -#include "Services/Loader/Loader.h" -#include "Ui/Spacer.h" -#include "Ui/Style.h" +#include "service/loader/Loader.h" +#include "ui/Spacer.h" +#include "ui/Style.h" namespace tt::lvgl { @@ -85,8 +86,8 @@ lv_obj_t* toolbar_create(lv_obj_t* parent, const std::string& title) { return obj; } -lv_obj_t* toolbar_create(lv_obj_t* parent, App app) { - const AppManifest& manifest = tt_app_get_manifest(app); +lv_obj_t* toolbar_create(lv_obj_t* parent, app::App app) { + const app::Manifest& manifest = app::tt_app_get_manifest(app); lv_obj_t* toolbar = toolbar_create(parent, manifest.name); toolbar_set_nav_action(toolbar, LV_SYMBOL_CLOSE, &stop_app, nullptr); return toolbar; diff --git a/Tactility/Source/Ui/Toolbar.h b/Tactility/Source/ui/Toolbar.h similarity index 90% rename from Tactility/Source/Ui/Toolbar.h rename to Tactility/Source/ui/Toolbar.h index c7031fa4..15457ce3 100644 --- a/Tactility/Source/Ui/Toolbar.h +++ b/Tactility/Source/ui/Toolbar.h @@ -1,7 +1,7 @@ #pragma once #include "lvgl.h" -#include "App.h" +#include "app/App.h" namespace tt::lvgl { @@ -19,7 +19,7 @@ typedef struct { } ToolbarAction; lv_obj_t* toolbar_create(lv_obj_t* parent, const std::string& title); -lv_obj_t* toolbar_create(lv_obj_t* parent, tt::App app); +lv_obj_t* toolbar_create(lv_obj_t* parent, app::App app); void toolbar_set_title(lv_obj_t* obj, const std::string& title); void toolbar_set_nav_action(lv_obj_t* obj, const char* icon, lv_event_cb_t callback, void* user_data); uint8_t toolbar_add_action(lv_obj_t* obj, const char* icon, const char* text, lv_event_cb_t callback, void* user_data); diff --git a/TactilityCore/CMakeLists.txt b/TactilityCore/CMakeLists.txt index a67b2291..84658065 100644 --- a/TactilityCore/CMakeLists.txt +++ b/TactilityCore/CMakeLists.txt @@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 3.16) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -file(GLOB SOURCES "Source/*.c*") -file(GLOB HEADERS "Source/*.h*") +file(GLOB_RECURSE SOURCES "Source/*.c*") +file(GLOB_RECURSE HEADERS "Source/*.h*") add_library(TactilityCore OBJECT) diff --git a/TactilityCore/Source/ApiLock.h b/TactilityCore/Source/ApiLock.h deleted file mode 100644 index 76a5bd72..00000000 --- a/TactilityCore/Source/ApiLock.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "EventFlag.h" - -typedef tt::EventFlag* ApiLock; - -#define TT_API_LOCK_EVENT (1U << 0) - -#define tt_api_lock_alloc_locked() tt::event_flag_alloc() - -#define tt_api_lock_wait_unlock(_lock) \ - tt::event_flag_wait(_lock, TT_API_LOCK_EVENT, tt::TtFlagWaitAny, tt::TtWaitForever) - -#define tt_api_lock_free(_lock) tt::event_flag_free(_lock) - -#define tt_api_lock_unlock(_lock) tt::event_flag_set(_lock, TT_API_LOCK_EVENT) - -#define tt_api_lock_wait_unlock_and_free(_lock) \ - tt_api_lock_wait_unlock(_lock); \ - tt_api_lock_free(_lock); diff --git a/TactilityCore/Source/Bundle.h b/TactilityCore/Source/Bundle.h index 17fcbc24..5ba8f053 100644 --- a/TactilityCore/Source/Bundle.h +++ b/TactilityCore/Source/Bundle.h @@ -5,7 +5,6 @@ #pragma once #include -#include #include #include diff --git a/TactilityCore/Source/EventFlag.cpp b/TactilityCore/Source/EventFlag.cpp index eb9d30d8..da0058d5 100644 --- a/TactilityCore/Source/EventFlag.cpp +++ b/TactilityCore/Source/EventFlag.cpp @@ -3,68 +3,54 @@ #include "Check.h" #include "CoreDefines.h" -#ifdef ESP_TARGET -#include "freertos/FreeRTOS.h" -#include "freertos/event_groups.h" -#else -#include "FreeRTOS.h" -#include "event_groups.h" -#endif - #define TT_EVENT_FLAG_MAX_BITS_EVENT_GROUPS 24U #define TT_EVENT_FLAG_INVALID_BITS (~((1UL << TT_EVENT_FLAG_MAX_BITS_EVENT_GROUPS) - 1U)) namespace tt { -EventFlag* event_flag_alloc() { +EventFlag::EventFlag() { tt_assert(!TT_IS_IRQ_MODE()); - - EventGroupHandle_t handle = xEventGroupCreate(); + handle = xEventGroupCreate(); tt_check(handle); - - return static_cast(handle); } -void event_flag_free(EventFlag* instance) { +EventFlag::~EventFlag() { tt_assert(!TT_IS_IRQ_MODE()); - vEventGroupDelete((EventGroupHandle_t)instance); + vEventGroupDelete(handle); } -uint32_t event_flag_set(EventFlag* instance, uint32_t flags) { - tt_assert(instance); +uint32_t EventFlag::set(uint32_t flags) const { + tt_assert(handle); tt_assert((flags & TT_EVENT_FLAG_INVALID_BITS) == 0U); - auto hEventGroup = static_cast(instance); uint32_t rflags; BaseType_t yield; if (TT_IS_IRQ_MODE()) { yield = pdFALSE; - if (xEventGroupSetBitsFromISR(hEventGroup, (EventBits_t)flags, &yield) == pdFAIL) { + if (xEventGroupSetBitsFromISR(handle, (EventBits_t)flags, &yield) == pdFAIL) { rflags = (uint32_t)TtFlagErrorResource; } else { rflags = flags; portYIELD_FROM_ISR(yield); } } else { - rflags = xEventGroupSetBits(hEventGroup, (EventBits_t)flags); + rflags = xEventGroupSetBits(handle, (EventBits_t)flags); } /* Return event flags after setting */ - return (rflags); + return rflags; } -uint32_t event_flag_clear(EventFlag* instance, uint32_t flags) { - tt_assert(instance); +uint32_t EventFlag::clear(uint32_t flags) const { tt_assert((flags & TT_EVENT_FLAG_INVALID_BITS) == 0U); - auto hEventGroup = static_cast(instance); uint32_t rflags; if (TT_IS_IRQ_MODE()) { - rflags = xEventGroupGetBitsFromISR(hEventGroup); + rflags = xEventGroupGetBitsFromISR(handle); - if (xEventGroupClearBitsFromISR(hEventGroup, (EventBits_t)flags) == pdFAIL) { + if (xEventGroupClearBitsFromISR(handle, (EventBits_t)flags) == pdFAIL) { rflags = (uint32_t)TtStatusErrorResource; } else { /* xEventGroupClearBitsFromISR only registers clear operation in the timer command queue. */ @@ -73,42 +59,36 @@ uint32_t event_flag_clear(EventFlag* instance, uint32_t flags) { portYIELD_FROM_ISR(pdTRUE); } } else { - rflags = xEventGroupClearBits(hEventGroup, (EventBits_t)flags); + rflags = xEventGroupClearBits(handle, (EventBits_t)flags); } /* Return event flags before clearing */ - return (rflags); + return rflags; } -uint32_t event_flag_get(EventFlag* instance) { - tt_assert(instance); - - auto hEventGroup = static_cast(instance); +uint32_t EventFlag::get() const { uint32_t rflags; if (TT_IS_IRQ_MODE()) { - rflags = xEventGroupGetBitsFromISR(hEventGroup); + rflags = xEventGroupGetBitsFromISR(handle); } else { - rflags = xEventGroupGetBits(hEventGroup); + rflags = xEventGroupGetBits(handle); } /* Return current event flags */ return (rflags); } -uint32_t event_flag_wait( - EventFlag* instance, +uint32_t EventFlag::wait( uint32_t flags, uint32_t options, uint32_t timeout -) { +) const { tt_assert(!TT_IS_IRQ_MODE()); - tt_assert(instance); tt_assert((flags & TT_EVENT_FLAG_INVALID_BITS) == 0U); - auto hEventGroup = static_cast(instance); BaseType_t wait_all; - BaseType_t exit_clr; + BaseType_t exit_clear; uint32_t rflags; if (options & TtFlagWaitAll) { @@ -118,15 +98,15 @@ uint32_t event_flag_wait( } if (options & TtFlagNoClear) { - exit_clr = pdFAIL; + exit_clear = pdFAIL; } else { - exit_clr = pdTRUE; + exit_clear = pdTRUE; } rflags = xEventGroupWaitBits( - hEventGroup, + handle, (EventBits_t)flags, - exit_clr, + exit_clear, wait_all, (TickType_t)timeout ); @@ -149,8 +129,7 @@ uint32_t event_flag_wait( } } - /* Return event flags before clearing */ - return (rflags); + return rflags; } } // namespace diff --git a/TactilityCore/Source/EventFlag.h b/TactilityCore/Source/EventFlag.h index c0a07eda..867b95d0 100644 --- a/TactilityCore/Source/EventFlag.h +++ b/TactilityCore/Source/EventFlag.h @@ -2,62 +2,35 @@ #include "CoreTypes.h" +#ifdef ESP_TARGET +#include "freertos/FreeRTOS.h" +#include "freertos/event_groups.h" +#else +#include "FreeRTOS.h" +#include "event_groups.h" +#endif + namespace tt { -typedef void EventFlag; +#define TT_API_LOCK_EVENT (1U << 0) -/** Allocate EventFlag - * - * @return pointer to EventFlag +/** + * Wrapper for FreeRTOS xEventGroup. */ -EventFlag* event_flag_alloc(); - -/** Deallocate EventFlag - * - * @param instance pointer to EventFlag - */ -void event_flag_free(EventFlag* instance); - -/** Set flags - * - * @param instance pointer to EventFlag - * @param[in] flags The flags - * - * @return Resulting flags or error (TtStatus) - */ -uint32_t event_flag_set(EventFlag* instance, uint32_t flags); - -/** Clear flags - * - * @param instance pointer to EventFlag - * @param[in] flags The flags - * - * @return Resulting flags or error (TtStatus) - */ -uint32_t event_flag_clear(EventFlag* instance, uint32_t flags); - -/** Get flags - * - * @param instance pointer to EventFlag - * - * @return Resulting flags - */ -uint32_t event_flag_get(EventFlag* instance); - -/** Wait flags - * - * @param instance pointer to EventFlag - * @param[in] flags The flags - * @param[in] options The option flags - * @param[in] timeout The timeout - * - * @return Resulting flags or error (TtStatus) - */ -uint32_t event_flag_wait( - EventFlag* instance, - uint32_t flags, - uint32_t options, - uint32_t timeout -); +class EventFlag { +private: + EventGroupHandle_t handle; +public: + EventFlag(); + ~EventFlag(); + uint32_t set(uint32_t flags) const; + uint32_t clear(uint32_t flags) const; + uint32_t get() const; + uint32_t wait( + uint32_t flags, + uint32_t options = TtFlagWaitAny, + uint32_t timeout = TtWaitForever + ) const; +}; } // namespace diff --git a/TactilityCore/Source/Log.cpp b/TactilityCore/Source/Log.cpp index 43d00265..6321d370 100644 --- a/TactilityCore/Source/Log.cpp +++ b/TactilityCore/Source/Log.cpp @@ -12,7 +12,7 @@ namespace tt { -static char loglevel_to_prefix(LogLevel level) { +static char toPrefix(LogLevel level) { switch (level) { case LogLevelError: return 'E'; @@ -29,7 +29,7 @@ static char loglevel_to_prefix(LogLevel level) { } } -static const char* loglevel_to_colour(LogLevel level) { +static const char* toColour(LogLevel level) { switch (level) { case LogLevelError: return "\033[1;31m"; @@ -46,7 +46,7 @@ static const char* loglevel_to_colour(LogLevel level) { } } -uint64_t log_timestamp() { +static uint64_t getTimestamp() { #ifdef ESP_PLATFORM if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED) { return clock() / CLOCKS_PER_SEC * 1000; @@ -73,9 +73,9 @@ uint64_t log_timestamp() { void log(LogLevel level, const char* tag, const char* format, ...) { printf( "%s%c (%lu) %s: ", - loglevel_to_colour(level), - loglevel_to_prefix(level), - log_timestamp(), + toColour(level), + toPrefix(level), + getTimestamp(), tag ); diff --git a/TactilityCore/Source/Mutex.h b/TactilityCore/Source/Mutex.h index c952b9a3..fbcddc71 100644 --- a/TactilityCore/Source/Mutex.h +++ b/TactilityCore/Source/Mutex.h @@ -22,6 +22,10 @@ typedef enum { MutexTypeRecursive, } MutexType; +/** + * Wrapper for FreeRTOS xSemaphoreCreateMutex and xSemaphoreCreateRecursiveMutex + * Can be used in IRQ mode (within ISR context) + */ class Mutex { private: SemaphoreHandle_t semaphore; diff --git a/TactilityCore/Source/Semaphore.cpp b/TactilityCore/Source/Semaphore.cpp index ab2d5731..2cfa398c 100644 --- a/TactilityCore/Source/Semaphore.cpp +++ b/TactilityCore/Source/Semaphore.cpp @@ -2,127 +2,89 @@ #include "Check.h" #include "CoreDefines.h" -#ifdef ESP_PLATFORM -#include "freertos/FreeRTOS.h" -#include "freertos/semphr.h" -#else -#include "FreeRTOS.h" -#include "semphr.h" -#endif - namespace tt { -Semaphore* tt_semaphore_alloc(uint32_t max_count, uint32_t initial_count) { +Semaphore::Semaphore(uint32_t maxCount, uint32_t initialCount) { tt_assert(!TT_IS_IRQ_MODE()); - tt_assert((max_count > 0U) && (initial_count <= max_count)); + tt_assert((maxCount > 0U) && (initialCount <= maxCount)); - SemaphoreHandle_t hSemaphore = nullptr; - if (max_count == 1U) { - hSemaphore = xSemaphoreCreateBinary(); - if ((hSemaphore != nullptr) && (initial_count != 0U)) { - if (xSemaphoreGive(hSemaphore) != pdPASS) { - vSemaphoreDelete(hSemaphore); - hSemaphore = nullptr; + if (maxCount == 1U) { + handle = xSemaphoreCreateBinary(); + if ((handle != nullptr) && (initialCount != 0U)) { + if (xSemaphoreGive(handle) != pdPASS) { + vSemaphoreDelete(handle); + handle = nullptr; } } } else { - hSemaphore = xSemaphoreCreateCounting(max_count, initial_count); + handle = xSemaphoreCreateCounting(maxCount, initialCount); } - tt_check(hSemaphore); - - return (Semaphore*)hSemaphore; + tt_check(handle); } -void tt_semaphore_free(Semaphore* instance) { - tt_assert(instance); +Semaphore::~Semaphore() { tt_assert(!TT_IS_IRQ_MODE()); - - SemaphoreHandle_t hSemaphore = (SemaphoreHandle_t)instance; - - vSemaphoreDelete(hSemaphore); + vSemaphoreDelete(handle); } -TtStatus tt_semaphore_acquire(Semaphore* instance, uint32_t timeout) { - tt_assert(instance); - - SemaphoreHandle_t hSemaphore = (SemaphoreHandle_t)instance; - TtStatus status; - BaseType_t yield; - - status = TtStatusOk; - +TtStatus Semaphore::acquire(uint32_t timeout) const { if (TT_IS_IRQ_MODE()) { if (timeout != 0U) { - status = TtStatusErrorParameter; + return TtStatusErrorParameter; } else { - yield = pdFALSE; + BaseType_t yield = pdFALSE; - if (xSemaphoreTakeFromISR(hSemaphore, &yield) != pdPASS) { - status = TtStatusErrorResource; + if (xSemaphoreTakeFromISR(handle, &yield) != pdPASS) { + return TtStatusErrorResource; } else { portYIELD_FROM_ISR(yield); + return TtStatusOk; } } } else { - if (xSemaphoreTake(hSemaphore, (TickType_t)timeout) != pdPASS) { + if (xSemaphoreTake(handle, (TickType_t)timeout) != pdPASS) { if (timeout != 0U) { - status = TtStatusErrorTimeout; + return TtStatusErrorTimeout; } else { - status = TtStatusErrorResource; + return TtStatusErrorResource; } + } else { + return TtStatusOk; } } - - return status; } -TtStatus tt_semaphore_release(Semaphore* instance) { - tt_assert(instance); - - SemaphoreHandle_t hSemaphore = (SemaphoreHandle_t)instance; - TtStatus stat; - BaseType_t yield; - - stat = TtStatusOk; - +TtStatus Semaphore::release() const { if (TT_IS_IRQ_MODE()) { - yield = pdFALSE; + BaseType_t yield = pdFALSE; - if (xSemaphoreGiveFromISR(hSemaphore, &yield) != pdTRUE) { - stat = TtStatusErrorResource; + if (xSemaphoreGiveFromISR(handle, &yield) != pdTRUE) { + return TtStatusErrorResource; } else { portYIELD_FROM_ISR(yield); + return TtStatusOk; } } else { - if (xSemaphoreGive(hSemaphore) != pdPASS) { - stat = TtStatusErrorResource; + if (xSemaphoreGive(handle) != pdPASS) { + return TtStatusErrorResource; + } else { + return TtStatusOk; } } - - /* Return execution status */ - return (stat); } -uint32_t tt_semaphore_get_count(Semaphore* instance) { - tt_assert(instance); - - SemaphoreHandle_t hSemaphore = (SemaphoreHandle_t)instance; - uint32_t count; - +uint32_t Semaphore::getCount() const { if (TT_IS_IRQ_MODE()) { // TODO: uxSemaphoreGetCountFromISR is not supported on esp-idf 5.1.2 - perhaps later on? #ifdef uxSemaphoreGetCountFromISR - count = (uint32_t)uxSemaphoreGetCountFromISR(hSemaphore); + return uxSemaphoreGetCountFromISR(handle); #else - count = (uint32_t)uxQueueMessagesWaitingFromISR((QueueHandle_t)hSemaphore); + return uxQueueMessagesWaitingFromISR((QueueHandle_t)hSemaphore); #endif } else { - count = (uint32_t)uxSemaphoreGetCount(hSemaphore); + return uxSemaphoreGetCount(handle); } - - /* Return number of tokens */ - return (count); } } // namespace diff --git a/TactilityCore/Source/Semaphore.h b/TactilityCore/Source/Semaphore.h index 888cb272..79bd675c 100644 --- a/TactilityCore/Source/Semaphore.h +++ b/TactilityCore/Source/Semaphore.h @@ -3,48 +3,50 @@ #include "CoreTypes.h" #include "Thread.h" +#ifdef ESP_PLATFORM +#include "freertos/FreeRTOS.h" +#include "freertos/semphr.h" +#else +#include "FreeRTOS.h" +#include "semphr.h" +#endif + namespace tt { -typedef void Semaphore; - -/** Allocate semaphore - * - * @param[in] max_count The maximum count - * @param[in] initial_count The initial count - * - * @return pointer to Semaphore instance +/** + * Wrapper for xSemaphoreCreateBinary (max count == 1) and xSemaphoreCreateCounting (max count > 1) + * Can be used in IRQ mode (within ISR context) */ -Semaphore* tt_semaphore_alloc(uint32_t max_count, uint32_t initial_count); +class Semaphore { +private: + SemaphoreHandle_t handle; +public: + /** + * @param[in] maxCount The maximum count + * @param[in] initialCount The initial count + */ + Semaphore(uint32_t maxCount, uint32_t initialCount); -/** Free semaphore - * - * @param instance The pointer to Semaphore instance - */ -void tt_semaphore_free(Semaphore* instance); + /** + * @param instance The pointer to Semaphore instance + */ + ~Semaphore(); -/** Acquire semaphore - * - * @param instance The pointer to Semaphore instance - * @param[in] timeout The timeout - * - * @return The status. - */ -TtStatus tt_semaphore_acquire(Semaphore* instance, uint32_t timeout); + /** Acquire semaphore + * @param[in] timeout The timeout + * @return the status + */ + TtStatus acquire(uint32_t timeout) const; -/** Release semaphore - * - * @param instance The pointer to Semaphore instance - * - * @return The status. - */ -TtStatus tt_semaphore_release(Semaphore* instance); + /** Release semaphore + * @return the status + */ + TtStatus release() const; -/** Get semaphore count - * - * @param instance The pointer to Semaphore instance - * - * @return Semaphore count - */ -uint32_t tt_semaphore_get_count(Semaphore* instance); + /** Get semaphore count + * @return semaphore count + */ + uint32_t getCount() const; +}; } // namespace diff --git a/TactilityCore/Source/StreamBuffer.cpp b/TactilityCore/Source/StreamBuffer.cpp index 34adbbc9..7108b338 100644 --- a/TactilityCore/Source/StreamBuffer.cpp +++ b/TactilityCore/Source/StreamBuffer.cpp @@ -4,91 +4,70 @@ #include "CoreDefines.h" #include "CoreTypes.h" -#ifdef ESP_PLATFORM -#include "freertos/FreeRTOS.h" -#include "freertos/stream_buffer.h" -#else -#include "FreeRTOS.h" -#include "stream_buffer.h" -#endif - namespace tt { -StreamBuffer* stream_buffer_alloc(size_t size, size_t trigger_level) { +StreamBuffer::StreamBuffer(size_t size, size_t triggerLevel) { tt_assert(size != 0); - - StreamBufferHandle_t handle = xStreamBufferCreate(size, trigger_level); + handle = xStreamBufferCreate(size, triggerLevel); tt_check(handle); - - return handle; }; -void stream_buffer_free(StreamBuffer* stream_buffer) { - tt_assert(stream_buffer); - vStreamBufferDelete((StreamBufferHandle_t)stream_buffer); +StreamBuffer::~StreamBuffer() { + vStreamBufferDelete(handle); }; -bool stream_set_trigger_level(StreamBuffer* stream_buffer, size_t trigger_level) { - tt_assert(stream_buffer); - return xStreamBufferSetTriggerLevel((StreamBufferHandle_t)stream_buffer, trigger_level) == pdTRUE; +bool StreamBuffer::setTriggerLevel(size_t triggerLevel) const { + return xStreamBufferSetTriggerLevel(handle, triggerLevel) == pdTRUE; }; -size_t stream_buffer_send( - StreamBuffer* stream_buffer, +size_t StreamBuffer::send( const void* data, size_t length, uint32_t timeout -) { - size_t ret; - +) const { if (TT_IS_IRQ_MODE()) { BaseType_t yield; - ret = xStreamBufferSendFromISR((StreamBufferHandle_t)stream_buffer, data, length, &yield); + size_t result = xStreamBufferSendFromISR(handle, data, length, &yield); portYIELD_FROM_ISR(yield); + return result; } else { - ret = xStreamBufferSend((StreamBufferHandle_t)stream_buffer, data, length, timeout); + return xStreamBufferSend(handle, data, length, timeout); } - - return ret; }; -size_t stream_buffer_receive( - StreamBuffer* stream_buffer, +size_t StreamBuffer::receive( void* data, size_t length, uint32_t timeout -) { - size_t ret; - +) const { if (TT_IS_IRQ_MODE()) { BaseType_t yield; - ret = xStreamBufferReceiveFromISR((StreamBufferHandle_t)stream_buffer, data, length, &yield); + size_t result = xStreamBufferReceiveFromISR(handle, data, length, &yield); portYIELD_FROM_ISR(yield); + return result; } else { - ret = xStreamBufferReceive((StreamBufferHandle_t)stream_buffer, data, length, timeout); + return xStreamBufferReceive(handle, data, length, timeout); } - - return ret; } -size_t stream_buffer_bytes_available(StreamBuffer* stream_buffer) { - return xStreamBufferBytesAvailable((StreamBufferHandle_t)stream_buffer); +size_t StreamBuffer::getAvailableReadBytes() const { + return xStreamBufferBytesAvailable(handle); }; -size_t stream_buffer_spaces_available(StreamBuffer* stream_buffer) { - return xStreamBufferSpacesAvailable((StreamBufferHandle_t)stream_buffer); +size_t StreamBuffer::getAvailableWriteBytes() const { + return xStreamBufferSpacesAvailable(handle); }; -bool stream_buffer_is_full(StreamBuffer* stream_buffer) { - return xStreamBufferIsFull((StreamBufferHandle_t)stream_buffer) == pdTRUE; +bool StreamBuffer::isFull() const { + return xStreamBufferIsFull(handle) == pdTRUE; }; -bool stream_buffer_is_empty(StreamBuffer* stream_buffer) { - return (xStreamBufferIsEmpty((StreamBufferHandle_t)stream_buffer) == pdTRUE); +bool StreamBuffer::isEmpty() const { + return xStreamBufferIsEmpty(handle) == pdTRUE; }; -TtStatus stream_buffer_reset(StreamBuffer* stream_buffer) { - if (xStreamBufferReset((StreamBufferHandle_t)stream_buffer) == pdPASS) { +TtStatus StreamBuffer::reset() const { + if (xStreamBufferReset(handle) == pdPASS) { return TtStatusOk; } else { return TtStatusError; diff --git a/TactilityCore/Source/StreamBuffer.h b/TactilityCore/Source/StreamBuffer.h index e3fc3af3..805ad952 100644 --- a/TactilityCore/Source/StreamBuffer.h +++ b/TactilityCore/Source/StreamBuffer.h @@ -1,152 +1,148 @@ -/** - * @file stream_buffer.h - * Tactility stream buffer primitive. - * - * Stream buffers are used to send a continuous stream of data from one task or - * interrupt to another. Their implementation is light weight, making them - * particularly suited for interrupt to task and core to core communication - * scenarios. - * - * ***NOTE***: Stream buffer implementation assumes there is only one task or - * interrupt that will write to the buffer (the writer), and only one task or - * interrupt that will read from the buffer (the reader). - */ #pragma once #include "CoreTypes.h" #include #include +#ifdef ESP_PLATFORM +#include "freertos/FreeRTOS.h" +#include "freertos/stream_buffer.h" +#else +#include "FreeRTOS.h" +#include "stream_buffer.h" +#endif + namespace tt { -typedef void StreamBuffer; - /** - * @brief Allocate stream buffer instance. - * Stream buffer implementation assumes there is only one task or + * Stream buffers are used to send a continuous stream of data from one task or + * interrupt to another. Their implementation is light weight, making them + * particularly suited for interrupt to task and core to core communication + * scenarios. + * + * **NOTE**: Stream buffer implementation assumes there is only one task or * interrupt that will write to the buffer (the writer), and only one task or * interrupt that will read from the buffer (the reader). - * - * @param size The total number of bytes the stream buffer will be able to hold at any one time. - * @param trigger_level The number of bytes that must be in the stream buffer - * before a task that is blocked on the stream buffer to wait for data is moved out of the blocked state. - * @return The stream buffer instance. */ -StreamBuffer* stream_buffer_alloc(size_t size, size_t trigger_level); +class StreamBuffer { +private: + StreamBufferHandle_t handle; -/** - * @brief Free stream buffer instance - * - * @param stream_buffer The stream buffer instance. - */ -void stream_buffer_free(StreamBuffer* stream_buffer); +public: -/** - * @brief Set trigger level for stream buffer. - * A stream buffer's trigger level is the number of bytes that must be in the - * stream buffer before a task that is blocked on the stream buffer to - * wait for data is moved out of the blocked state. - * - * @param stream_buffer The stream buffer instance - * @param trigger_level The new trigger level for the stream buffer. - * @return true if trigger level can be be updated (new trigger level was less than or equal to the stream buffer's length). - * @return false if trigger level can't be be updated (new trigger level was greater than the stream buffer's length). - */ -bool stream_set_trigger_level(StreamBuffer* stream_buffer, size_t trigger_level); + /** + * Stream buffer implementation assumes there is only one task or + * interrupt that will write to the buffer (the writer), and only one task or + * interrupt that will read from the buffer (the reader). + * + * @param size The total number of bytes the stream buffer will be able to hold at any one time. + * @param triggerLevel The number of bytes that must be in the stream buffer + * before a task that is blocked on the stream buffer to wait for data is moved out of the blocked state. + * @return The stream buffer instance. + */ + StreamBuffer(size_t size, size_t triggerLevel); -/** - * @brief Sends bytes to a stream buffer. The bytes are copied into the stream buffer. - * Wakes up task waiting for data to become available if called from ISR. - * - * @param stream_buffer The stream buffer instance. - * @param data A pointer to the data that is to be copied into the stream buffer. - * @param length The maximum number of bytes to copy from data into the stream buffer. - * @param timeout The maximum amount of time the task should remain in the - * Blocked state to wait for space to become available if the stream buffer is full. - * Will return immediately if timeout is zero. - * Setting timeout to TtWaitForever will cause the task to wait indefinitely. - * Ignored if called from ISR. - * @return The number of bytes actually written to the stream buffer. - */ -size_t stream_buffer_send( - StreamBuffer* stream_buffer, - const void* data, - size_t length, - uint32_t timeout -); + ~StreamBuffer(); -/** - * @brief Receives bytes from a stream buffer. - * Wakes up task waiting for space to become available if called from ISR. - * - * @param stream_buffer The stream buffer instance. - * @param data A pointer to the buffer into which the received bytes will be - * copied. - * @param length The length of the buffer pointed to by the data parameter. - * @param timeout The maximum amount of time the task should remain in the - * Blocked state to wait for data to become available if the stream buffer is empty. - * Will return immediately if timeout is zero. - * Setting timeout to TtWaitForever will cause the task to wait indefinitely. - * Ignored if called from ISR. - * @return The number of bytes read from the stream buffer, if any. - */ -size_t stream_buffer_receive( - StreamBuffer* stream_buffer, - void* data, - size_t length, - uint32_t timeout -); + /** + * @brief Set trigger level for stream buffer. + * A stream buffer's trigger level is the number of bytes that must be in the + * stream buffer before a task that is blocked on the stream buffer to + * wait for data is moved out of the blocked state. + * + * @param triggerLevel The new trigger level for the stream buffer. + * @return true if trigger level can be be updated (new trigger level was less than or equal to the stream buffer's length). + * @return false if trigger level can't be be updated (new trigger level was greater than the stream buffer's length). + */ + [[nodiscard]] bool setTriggerLevel(size_t triggerLevel) const; -/** - * @brief Queries a stream buffer to see how much data it contains, which is equal to - * the number of bytes that can be read from the stream buffer before the stream - * buffer would be empty. - * - * @param stream_buffer The stream buffer instance. - * @return The number of bytes that can be read from the stream buffer before - * the stream buffer would be empty. - */ -size_t stream_buffer_bytes_available(StreamBuffer* stream_buffer); + /** + * @brief Sends bytes to a stream buffer. The bytes are copied into the stream buffer. + * Wakes up task waiting for data to become available if called from ISR. + * + * @param data A pointer to the data that is to be copied into the stream buffer. + * @param length The maximum number of bytes to copy from data into the stream buffer. + * @param timeout The maximum amount of time the task should remain in the + * Blocked state to wait for space to become available if the stream buffer is full. + * Will return immediately if timeout is zero. + * Setting timeout to TtWaitForever will cause the task to wait indefinitely. + * Ignored if called from ISR. + * @return The number of bytes actually written to the stream buffer. + */ + [[nodiscard]] size_t send( + const void* data, + size_t length, + uint32_t timeout + ) const; -/** - * @brief Queries a stream buffer to see how much free space it contains, which is - * equal to the amount of data that can be sent to the stream buffer before it - * is full. - * - * @param stream_buffer The stream buffer instance. - * @return The number of bytes that can be written to the stream buffer before - * the stream buffer would be full. - */ -size_t stream_buffer_spaces_available(StreamBuffer* stream_buffer); + /** + * @brief Receives bytes from a stream buffer. + * Wakes up task waiting for space to become available if called from ISR. + * + * @param data A pointer to the buffer into which the received bytes will be + * copied. + * @param length The length of the buffer pointed to by the data parameter. + * @param timeout The maximum amount of time the task should remain in the + * Blocked state to wait for data to become available if the stream buffer is empty. + * Will return immediately if timeout is zero. + * Setting timeout to TtWaitForever will cause the task to wait indefinitely. + * Ignored if called from ISR. + * @return The number of bytes read from the stream buffer, if any. + */ + [[nodiscard]] size_t receive( + void* data, + size_t length, + uint32_t timeout + ) const; -/** - * @brief Queries a stream buffer to see if it is full. - * - * @param stream_buffer stream buffer instance. - * @return true if the stream buffer is full. - * @return false if the stream buffer is not full. - */ -bool stream_buffer_is_full(StreamBuffer* stream_buffer); + /** + * @brief Queries a stream buffer to see how much data it contains, which is equal to + * the number of bytes that can be read from the stream buffer before the stream + * buffer would be empty. + * + * @return The number of bytes that can be read from the stream buffer before + * the stream buffer would be empty. + */ + [[nodiscard]] size_t getAvailableReadBytes() const; -/** - * @brief Queries a stream buffer to see if it is empty. - * - * @param stream_buffer The stream buffer instance. - * @return true if the stream buffer is empty. - * @return false if the stream buffer is not empty. - */ -bool tt_stream_buffer_is_empty(StreamBuffer* stream_buffer); + /** + * @brief Queries a stream buffer to see how much free space it contains, which is + * equal to the amount of data that can be sent to the stream buffer before it + * is full. + * + * @return The number of bytes that can be written to the stream buffer before + * the stream buffer would be full. + */ + [[nodiscard]] size_t getAvailableWriteBytes() const; + + /** + * @brief Queries a stream buffer to see if it is full. + * + * @return true if the stream buffer is full. + * @return false if the stream buffer is not full. + */ + [[nodiscard]] bool isFull() const; + + /** + * @brief Queries a stream buffer to see if it is empty. + * + * @param stream_buffer The stream buffer instance. + * @return true if the stream buffer is empty. + * @return false if the stream buffer is not empty. + */ + [[nodiscard]] bool isEmpty() const; + + /** + * @brief Resets a stream buffer to its initial, empty, state. Any data that was + * in the stream buffer is discarded. A stream buffer can only be reset if there + * are no tasks blocked waiting to either send to or receive from the stream buffer. + * + * @return TtStatusOk if the stream buffer is reset. + * @return TtStatusError if there was a task blocked waiting to send to or read + * from the stream buffer then the stream buffer is not reset. + */ + [[nodiscard]] TtStatus reset() const; +}; -/** - * @brief Resets a stream buffer to its initial, empty, state. Any data that was - * in the stream buffer is discarded. A stream buffer can only be reset if there - * are no tasks blocked waiting to either send to or receive from the stream buffer. - * - * @param stream_buffer The stream buffer instance. - * @return TtStatusOk if the stream buffer is reset. - * @return TtStatusError if there was a task blocked waiting to send to or read - * from the stream buffer then the stream buffer is not reset. - */ -TtStatus tt_stream_buffer_reset(StreamBuffer* stream_buffer); } // namespace diff --git a/TactilityCore/Source/TactilityCore.h b/TactilityCore/Source/TactilityCore.h index 56d7eb85..6760b319 100644 --- a/TactilityCore/Source/TactilityCore.h +++ b/TactilityCore/Source/TactilityCore.h @@ -6,7 +6,7 @@ #include "CoreDefines.h" #include "CoreExtraDefines.h" #include "CoreTypes.h" -#include "Critical.h" +#include "critical/Critical.h" #include "EventFlag.h" #include "Kernel.h" #include "Log.h" diff --git a/TactilityCore/Source/Critical.cpp b/TactilityCore/Source/critical/Critical.cpp similarity index 100% rename from TactilityCore/Source/Critical.cpp rename to TactilityCore/Source/critical/Critical.cpp diff --git a/TactilityCore/Source/Critical.h b/TactilityCore/Source/critical/Critical.h similarity index 100% rename from TactilityCore/Source/Critical.h rename to TactilityCore/Source/critical/Critical.h diff --git a/TactilityCore/Source/Crypt.cpp b/TactilityCore/Source/crypt/Crypt.cpp similarity index 100% rename from TactilityCore/Source/Crypt.cpp rename to TactilityCore/Source/crypt/Crypt.cpp diff --git a/TactilityCore/Source/Crypt.h b/TactilityCore/Source/crypt/Crypt.h similarity index 100% rename from TactilityCore/Source/Crypt.h rename to TactilityCore/Source/crypt/Crypt.h diff --git a/TactilityCore/Source/Hash.cpp b/TactilityCore/Source/crypt/Hash.cpp similarity index 96% rename from TactilityCore/Source/Hash.cpp rename to TactilityCore/Source/crypt/Hash.cpp index 1ee5f8ad..9b4bf6cb 100644 --- a/TactilityCore/Source/Hash.cpp +++ b/TactilityCore/Source/crypt/Hash.cpp @@ -1,6 +1,6 @@ #include "Hash.h" -namespace tt::hash { +namespace tt::crypt { uint32_t djb2(const char* str) { uint32_t hash = 5381; diff --git a/TactilityCore/Source/Hash.h b/TactilityCore/Source/crypt/Hash.h similarity index 94% rename from TactilityCore/Source/Hash.h rename to TactilityCore/Source/crypt/Hash.h index 83e5856e..407afc8f 100644 --- a/TactilityCore/Source/Hash.h +++ b/TactilityCore/Source/crypt/Hash.h @@ -3,7 +3,7 @@ #include #include -namespace tt::hash { +namespace tt::crypt { /** * Implementation of DJB2 hashing algorithm. diff --git a/TactilityHeadless/Private/EspInit.h b/TactilityHeadless/Private/EspInit.h index 1f8a26da..73c3240d 100644 --- a/TactilityHeadless/Private/EspInit.h +++ b/TactilityHeadless/Private/EspInit.h @@ -4,7 +4,7 @@ namespace tt { -void esp_init(); +void initEsp(); } // namespace diff --git a/TactilityHeadless/Private/EspPartitions_i.h b/TactilityHeadless/Private/EspPartitions_i.h index 5cd5238d..93d5ffc7 100644 --- a/TactilityHeadless/Private/EspPartitions_i.h +++ b/TactilityHeadless/Private/EspPartitions_i.h @@ -6,7 +6,7 @@ namespace tt { -esp_err_t esp_partitions_init(); +esp_err_t initEspPartitions(); } // namespace diff --git a/TactilityHeadless/Private/Hal/Hal_i.h b/TactilityHeadless/Private/hal/Hal_i.h similarity index 76% rename from TactilityHeadless/Private/Hal/Hal_i.h rename to TactilityHeadless/Private/hal/Hal_i.h index 683a198d..ff91c127 100644 --- a/TactilityHeadless/Private/Hal/Hal_i.h +++ b/TactilityHeadless/Private/hal/Hal_i.h @@ -1,6 +1,6 @@ #pragma once -#include "Hal/Configuration.h" +#include "hal/Configuration.h" namespace tt::hal { diff --git a/TactilityHeadless/Source/EspInit.cpp b/TactilityHeadless/Source/EspInit.cpp index 61e1368b..204f6d47 100644 --- a/TactilityHeadless/Source/EspInit.cpp +++ b/TactilityHeadless/Source/EspInit.cpp @@ -13,7 +13,7 @@ namespace tt { #define TAG "tactility" // Initialize NVS -static void esp_nvs_init() { +static void initEspNvs() { esp_err_t ret = nvs_flash_init(); if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { TT_LOG_I(TAG, "nvs erasing"); @@ -24,15 +24,15 @@ static void esp_nvs_init() { TT_LOG_I(TAG, "nvs initialized"); } -static void esp_network_init() { +static void initEspNetwork() { ESP_ERROR_CHECK(esp_netif_init()); ESP_ERROR_CHECK(esp_event_loop_create_default()); } -void esp_init() { - esp_nvs_init(); - esp_partitions_init(); - esp_network_init(); +void initEsp() { + initEspNvs(); + initEspPartitions(); + initEspNetwork(); } } // namespace diff --git a/TactilityHeadless/Source/EspPartitions.cpp b/TactilityHeadless/Source/EspPartitions.cpp index 5a70d5a2..b578e3bc 100644 --- a/TactilityHeadless/Source/EspPartitions.cpp +++ b/TactilityHeadless/Source/EspPartitions.cpp @@ -11,7 +11,7 @@ namespace tt { static const char* TAG = "filesystem"; -static esp_err_t nvs_flash_init_safely() { +static esp_err_t initNvsFlashSafely() { esp_err_t result = nvs_flash_init(); if (result == ESP_ERR_NVS_NO_FREE_PAGES || result == ESP_ERR_NVS_NEW_VERSION_FOUND) { ESP_ERROR_CHECK(nvs_flash_erase()); @@ -20,7 +20,7 @@ static esp_err_t nvs_flash_init_safely() { return result; } -static esp_err_t spiffs_init(esp_vfs_spiffs_conf_t* conf) { +static esp_err_t initSpiffs(esp_vfs_spiffs_conf_t* conf) { esp_err_t ret = esp_vfs_spiffs_register(conf); if (ret != ESP_OK) { if (ret == ESP_FAIL) { @@ -43,8 +43,8 @@ static esp_err_t spiffs_init(esp_vfs_spiffs_conf_t* conf) { return ESP_OK; } -esp_err_t esp_partitions_init() { - ESP_ERROR_CHECK(nvs_flash_init_safely()); +esp_err_t initEspPartitions() { + ESP_ERROR_CHECK(initNvsFlashSafely()); esp_vfs_spiffs_conf_t assets_spiffs = { .base_path = MOUNT_POINT_ASSETS, @@ -53,7 +53,7 @@ esp_err_t esp_partitions_init() { .format_if_mount_failed = false }; - if (spiffs_init(&assets_spiffs) != ESP_OK) { + if (initSpiffs(&assets_spiffs) != ESP_OK) { return ESP_FAIL; } @@ -64,7 +64,7 @@ esp_err_t esp_partitions_init() { .format_if_mount_failed = false }; - if (spiffs_init(&config_spiffs) != ESP_OK) { + if (initSpiffs(&config_spiffs) != ESP_OK) { return ESP_FAIL; } diff --git a/TactilityHeadless/Source/Preferences.h b/TactilityHeadless/Source/Preferences.h index bbc45473..332a9c0c 100644 --- a/TactilityHeadless/Source/Preferences.h +++ b/TactilityHeadless/Source/Preferences.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include namespace tt { diff --git a/TactilityHeadless/Source/PreferencesMock.cpp b/TactilityHeadless/Source/PreferencesMock.cpp index 9334250e..82338ec0 100644 --- a/TactilityHeadless/Source/PreferencesMock.cpp +++ b/TactilityHeadless/Source/PreferencesMock.cpp @@ -2,7 +2,6 @@ #include "Bundle.h" #include "Preferences.h" -#include "TactilityCore.h" namespace tt { diff --git a/TactilityHeadless/Source/ServiceRegistry.h b/TactilityHeadless/Source/ServiceRegistry.h deleted file mode 100644 index 30e34b84..00000000 --- a/TactilityHeadless/Source/ServiceRegistry.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "ServiceManifest.h" -#include "TactilityCore.h" - -namespace tt { - -typedef void (*ServiceManifestCallback)(const ServiceManifest*, void* context); - -void service_registry_init(); - -void service_registry_add(const ServiceManifest* manifest); -void service_registry_remove(const ServiceManifest* manifest); -_Nullable const ServiceManifest* service_registry_find_manifest_by_id(const std::string& id); -void service_registry_for_each_manifest(ServiceManifestCallback callback, void* _Nullable context); - -bool service_registry_start(const std::string& id); -bool service_registry_stop(const std::string& id); - -Service* _Nullable service_find(const std::string& id); - -} // namespace diff --git a/TactilityHeadless/Source/TactilityHeadless.cpp b/TactilityHeadless/Source/TactilityHeadless.cpp index bde0ff4d..f5b17734 100644 --- a/TactilityHeadless/Source/TactilityHeadless.cpp +++ b/TactilityHeadless/Source/TactilityHeadless.cpp @@ -1,8 +1,8 @@ #include "TactilityHeadless.h" -#include "Hal/Configuration.h" -#include "Hal/Hal_i.h" -#include "ServiceManifest.h" -#include "ServiceRegistry.h" +#include "hal/Configuration.h" +#include "hal/Hal_i.h" +#include "service/Manifest.h" +#include "service/ServiceRegistry.h" #ifdef ESP_PLATFORM #include "EspInit.h" @@ -12,10 +12,10 @@ namespace tt { #define TAG "tactility" -namespace service::wifi { extern const ServiceManifest manifest; } -namespace service::sdcard { extern const ServiceManifest manifest; } +namespace service::wifi { extern const Manifest manifest; } +namespace service::sdcard { extern const Manifest manifest; } -static const ServiceManifest* const system_services[] = { +static const service::Manifest* const system_services[] = { &service::sdcard::manifest, &service::wifi::manifest }; @@ -24,16 +24,16 @@ static const hal::Configuration* hardwareConfig = nullptr; static void register_and_start_system_services() { TT_LOG_I(TAG, "Registering and starting system services"); - int app_count = sizeof(system_services) / sizeof(ServiceManifest*); + int app_count = sizeof(system_services) / sizeof(service::Manifest*); for (int i = 0; i < app_count; ++i) { - service_registry_add(system_services[i]); - tt_check(service_registry_start(system_services[i]->id)); + addService(system_services[i]); + tt_check(service::startService(system_services[i]->id)); } } void initHeadless(const hal::Configuration& config) { #ifdef ESP_PLATFORM - esp_init(); + initEsp(); #endif hardwareConfig = &config; hal::init(config); diff --git a/TactilityHeadless/Source/TactilityHeadless.h b/TactilityHeadless/Source/TactilityHeadless.h index 1697438e..2b117fb5 100644 --- a/TactilityHeadless/Source/TactilityHeadless.h +++ b/TactilityHeadless/Source/TactilityHeadless.h @@ -1,6 +1,6 @@ #pragma once -#include "Hal/Configuration.h" +#include "hal/Configuration.h" #include "TactilityHeadlessConfig.h" namespace tt { diff --git a/TactilityHeadless/Source/Hal/Configuration.h b/TactilityHeadless/Source/hal/Configuration.h similarity index 95% rename from TactilityHeadless/Source/Hal/Configuration.h rename to TactilityHeadless/Source/hal/Configuration.h index 390935c1..e347c828 100644 --- a/TactilityHeadless/Source/Hal/Configuration.h +++ b/TactilityHeadless/Source/hal/Configuration.h @@ -1,9 +1,8 @@ #pragma once #include "Power.h" -#include "Sdcard.h" -#include "I2c/I2c.h" -#include "TactilityCore.h" +#include "hal/sdcard/Sdcard.h" +#include "hal/i2c/I2c.h" namespace tt::hal { diff --git a/TactilityHeadless/Source/Hal/Hal.cpp b/TactilityHeadless/Source/hal/Hal.cpp similarity index 94% rename from TactilityHeadless/Source/Hal/Hal.cpp rename to TactilityHeadless/Source/hal/Hal.cpp index 5616e1f5..b37a6c7a 100644 --- a/TactilityHeadless/Source/Hal/Hal.cpp +++ b/TactilityHeadless/Source/hal/Hal.cpp @@ -1,5 +1,5 @@ -#include "Hal/Hal_i.h" -#include "Hal/I2c/I2c.h" +#include "hal/Hal_i.h" +#include "hal/i2c/I2c.h" #define TAG "hal" diff --git a/TactilityHeadless/Source/Hal/Power.h b/TactilityHeadless/Source/hal/Power.h similarity index 66% rename from TactilityHeadless/Source/Hal/Power.h rename to TactilityHeadless/Source/hal/Power.h index 6a687a45..89404eb2 100644 --- a/TactilityHeadless/Source/Hal/Power.h +++ b/TactilityHeadless/Source/hal/Power.h @@ -11,11 +11,11 @@ typedef uint8_t (*PowerGetBatteryCharge)(); // Power value [0, 255] which maps t typedef int32_t (*PowerGetCurrent)(); // Consumption or charge current in mAh typedef struct { - PowerIsCharging is_charging; - PowerIsChargingEnabled is_charging_enabled; - PowerSetChargingEnabled set_charging_enabled; - PowerGetBatteryCharge get_charge_level; - PowerGetCurrent get_current; + PowerIsCharging isCharging; + PowerIsChargingEnabled isChargingEnabled; + PowerSetChargingEnabled setChargingEnabled; + PowerGetBatteryCharge getChargeLevel; + PowerGetCurrent getCurrent; } Power; } // namespace tt diff --git a/TactilityHeadless/Source/Hal/I2c/I2c.cpp b/TactilityHeadless/Source/hal/i2c/I2c.cpp similarity index 100% rename from TactilityHeadless/Source/Hal/I2c/I2c.cpp rename to TactilityHeadless/Source/hal/i2c/I2c.cpp diff --git a/TactilityHeadless/Source/Hal/I2c/I2c.h b/TactilityHeadless/Source/hal/i2c/I2c.h similarity index 100% rename from TactilityHeadless/Source/Hal/I2c/I2c.h rename to TactilityHeadless/Source/hal/i2c/I2c.h diff --git a/TactilityHeadless/Source/Hal/I2c/I2cCompat.h b/TactilityHeadless/Source/hal/i2c/I2cCompat.h similarity index 100% rename from TactilityHeadless/Source/Hal/I2c/I2cCompat.h rename to TactilityHeadless/Source/hal/i2c/I2cCompat.h diff --git a/TactilityHeadless/Source/Hal/I2c/I2cMock.cpp b/TactilityHeadless/Source/hal/i2c/I2cMock.cpp similarity index 100% rename from TactilityHeadless/Source/Hal/I2c/I2cMock.cpp rename to TactilityHeadless/Source/hal/i2c/I2cMock.cpp diff --git a/TactilityHeadless/Source/Hal/Sdcard.cpp b/TactilityHeadless/Source/hal/sdcard/Sdcard.cpp similarity index 98% rename from TactilityHeadless/Source/Hal/Sdcard.cpp rename to TactilityHeadless/Source/hal/sdcard/Sdcard.cpp index 35762173..7968348c 100644 --- a/TactilityHeadless/Source/Hal/Sdcard.cpp +++ b/TactilityHeadless/Source/hal/sdcard/Sdcard.cpp @@ -49,7 +49,7 @@ bool mount(const SdCard* sdcard) { } } -State get_state() { +State getState() { if (data.context == nullptr) { return StateUnmounted; } else if (data.sdcard->is_mounted(data.context)) { diff --git a/TactilityHeadless/Source/Hal/Sdcard.h b/TactilityHeadless/Source/hal/sdcard/Sdcard.h similarity index 97% rename from TactilityHeadless/Source/Hal/Sdcard.h rename to TactilityHeadless/Source/hal/sdcard/Sdcard.h index d3f69e49..33ad1ff8 100644 --- a/TactilityHeadless/Source/Hal/Sdcard.h +++ b/TactilityHeadless/Source/hal/sdcard/Sdcard.h @@ -29,7 +29,7 @@ typedef struct { } SdCard; bool mount(const SdCard* sdcard); -State get_state(); +State getState(); bool unmount(uint32_t timeout_ticks); } // namespace diff --git a/TactilityHeadless/Source/ServiceManifest.h b/TactilityHeadless/Source/service/Manifest.h similarity index 70% rename from TactilityHeadless/Source/ServiceManifest.h rename to TactilityHeadless/Source/service/Manifest.h index 135ada17..29da10fe 100644 --- a/TactilityHeadless/Source/ServiceManifest.h +++ b/TactilityHeadless/Source/service/Manifest.h @@ -1,16 +1,15 @@ #pragma once -#include "TactilityCore.h" #include -namespace tt { +namespace tt::service { class Service; typedef void (*ServiceOnStart)(Service& service); typedef void (*ServiceOnStop)(Service& service); -typedef struct ServiceManifest { +typedef struct Manifest { /** * The identifier by which the app is launched by the system and other apps. */ @@ -19,13 +18,13 @@ typedef struct ServiceManifest { /** * Non-blocking method to call when service is started. */ - const ServiceOnStart on_start = nullptr; + const ServiceOnStart onStart = nullptr; /** * Non-blocking method to call when service is stopped. */ - const ServiceOnStop on_stop = nullptr; + const ServiceOnStop onStop = nullptr; -} ServiceManifest; +} Manifest; } // namespace diff --git a/TactilityHeadless/Source/Service.cpp b/TactilityHeadless/Source/service/Service.cpp similarity index 60% rename from TactilityHeadless/Source/Service.cpp rename to TactilityHeadless/Source/service/Service.cpp index 24fcc5e4..43568393 100644 --- a/TactilityHeadless/Source/Service.cpp +++ b/TactilityHeadless/Source/service/Service.cpp @@ -1,11 +1,11 @@ #include "Service.h" -#include "ServiceManifest.h" +#include "Manifest.h" -namespace tt { +namespace tt::service { -Service::Service(const ServiceManifest& manifest) : manifest(manifest) {} +Service::Service(const service::Manifest& manifest) : manifest(manifest) {} -const ServiceManifest& Service::getManifest() const { return manifest; } +const service::Manifest& Service::getManifest() const { return manifest; } void* Service::getData() const { mutex.acquire(TtWaitForever); diff --git a/TactilityHeadless/Source/Service.h b/TactilityHeadless/Source/service/Service.h similarity index 53% rename from TactilityHeadless/Source/Service.h rename to TactilityHeadless/Source/service/Service.h index ba538ba1..8a6acbc4 100644 --- a/TactilityHeadless/Source/Service.h +++ b/TactilityHeadless/Source/service/Service.h @@ -1,20 +1,20 @@ #pragma once #include "Mutex.h" -#include "ServiceManifest.h" +#include "Manifest.h" -namespace tt { +namespace tt::service { class Service { private: Mutex mutex = Mutex(MutexTypeNormal); - const ServiceManifest& manifest; + const service::Manifest& manifest; void* data = nullptr; public: - Service(const ServiceManifest& manifest); + Service(const service::Manifest& manifest); - [[nodiscard]] const ServiceManifest& getManifest() const; + [[nodiscard]] const service::Manifest& getManifest() const; [[nodiscard]] void* getData() const; void setData(void* newData); }; diff --git a/TactilityHeadless/Source/ServiceRegistry.cpp b/TactilityHeadless/Source/service/ServiceRegistry.cpp similarity index 66% rename from TactilityHeadless/Source/ServiceRegistry.cpp rename to TactilityHeadless/Source/service/ServiceRegistry.cpp index e8a7301e..fb9850a2 100644 --- a/TactilityHeadless/Source/ServiceRegistry.cpp +++ b/TactilityHeadless/Source/service/ServiceRegistry.cpp @@ -2,25 +2,25 @@ #include "Mutex.h" #include "Service.h" -#include "ServiceManifest.h" +#include "Manifest.h" #include "TactilityCore.h" #include #include -namespace tt { +namespace tt::service { #define TAG "service_registry" -typedef std::unordered_map ServiceManifestMap; +typedef std::unordered_map ManifestMap; typedef std::unordered_map ServiceInstanceMap; -static ServiceManifestMap service_manifest_map; +static ManifestMap service_manifest_map; static ServiceInstanceMap service_instance_map; static Mutex manifest_mutex(MutexTypeNormal); static Mutex instance_mutex(MutexTypeNormal); -void service_registry_add(const ServiceManifest* manifest) { +void addService(const Manifest* manifest) { TT_LOG_I(TAG, "adding %s", manifest->id.c_str()); manifest_mutex.acquire(TtWaitForever); @@ -28,10 +28,10 @@ void service_registry_add(const ServiceManifest* manifest) { manifest_mutex.release(); } -const ServiceManifest* _Nullable service_registry_find_manifest_by_id(const std::string& id) { +const Manifest* _Nullable findManifestId(const std::string& id) { manifest_mutex.acquire(TtWaitForever); auto iterator = service_manifest_map.find(id); - _Nullable const ServiceManifest * manifest = iterator != service_manifest_map.end() ? iterator->second : nullptr; + _Nullable const Manifest * manifest = iterator != service_manifest_map.end() ? iterator->second : nullptr; manifest_mutex.release(); return manifest; } @@ -44,25 +44,17 @@ static Service* _Nullable service_registry_find_instance_by_id(const std::string return service; } -void service_registry_for_each_manifest(ServiceManifestCallback callback, void* _Nullable context) { - manifest_mutex.acquire(TtWaitForever); - for (auto& it : service_manifest_map) { - callback(it.second, context); - } - manifest_mutex.release(); -} - // TODO: return proper error/status instead of BOOL -bool service_registry_start(const std::string& id) { +bool startService(const std::string& id) { TT_LOG_I(TAG, "starting %s", id.c_str()); - const ServiceManifest* manifest = service_registry_find_manifest_by_id(id); + const Manifest* manifest = findManifestId(id); if (manifest == nullptr) { TT_LOG_E(TAG, "manifest not found for service %s", id.c_str()); return false; } auto* service = new Service(*manifest); - manifest->on_start(*service); + manifest->onStart(*service); instance_mutex.acquire(TtWaitForever); service_instance_map[manifest->id] = service; @@ -72,11 +64,11 @@ bool service_registry_start(const std::string& id) { return true; } -_Nullable Service* service_find(const std::string& service_id) { +_Nullable Service* findServiceById(const std::string& service_id) { return (Service*)service_registry_find_instance_by_id(service_id); } -bool service_registry_stop(const std::string& id) { +bool stopService(const std::string& id) { TT_LOG_I(TAG, "stopping %s", id.c_str()); Service* service = service_registry_find_instance_by_id(id); if (service == nullptr) { @@ -84,7 +76,7 @@ bool service_registry_stop(const std::string& id) { return false; } - service->getManifest().on_stop(*service); + service->getManifest().onStop(*service); delete service; instance_mutex.acquire(TtWaitForever); diff --git a/TactilityHeadless/Source/service/ServiceRegistry.h b/TactilityHeadless/Source/service/ServiceRegistry.h new file mode 100644 index 00000000..888b47fd --- /dev/null +++ b/TactilityHeadless/Source/service/ServiceRegistry.h @@ -0,0 +1,20 @@ +#pragma once + +#include "Manifest.h" + +namespace tt::service { + +typedef void (*ManifestCallback)(const Manifest*, void* context); + +void initRegistry(); + +void addService(const Manifest* manifest); +void removeService(const Manifest* manifest); + +bool startService(const std::string& id); +bool stopService(const std::string& id); + +const Manifest* _Nullable findManifestId(const std::string& id); +Service* _Nullable findServiceById(const std::string& id); + +} // namespace diff --git a/TactilityHeadless/Source/Services/Sdcard/Sdcard.cpp b/TactilityHeadless/Source/service/sdcard/Sdcard.cpp similarity index 86% rename from TactilityHeadless/Source/Services/Sdcard/Sdcard.cpp rename to TactilityHeadless/Source/service/sdcard/Sdcard.cpp index d3f4a142..87c5610e 100644 --- a/TactilityHeadless/Source/Services/Sdcard/Sdcard.cpp +++ b/TactilityHeadless/Source/service/sdcard/Sdcard.cpp @@ -1,7 +1,7 @@ #include #include "Mutex.h" -#include "Service.h" +#include "service/Service.h" #include "TactilityCore.h" #include "TactilityHeadless.h" @@ -14,7 +14,7 @@ static int32_t sdcard_task(void* context); typedef struct { Mutex* mutex; Thread* thread; - hal::sdcard::State last_state; + hal::sdcard::State lastState; bool interrupted; } ServiceData; @@ -28,7 +28,7 @@ static ServiceData* service_data_alloc() { &sdcard_task, data ), - .last_state = hal::sdcard::StateUnmounted, + .lastState = hal::sdcard::StateUnmounted, .interrupted = false }; data->thread->setPriority(Thread::PriorityLow); @@ -57,15 +57,15 @@ static int32_t sdcard_task(void* context) { interrupted = data->interrupted; - hal::sdcard::State new_state = hal::sdcard::get_state(); + hal::sdcard::State new_state = hal::sdcard::getState(); 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)); } - if (new_state != data->last_state) { - data->last_state = new_state; + if (new_state != data->lastState) { + data->lastState = new_state; } service_data_unlock(data); @@ -98,10 +98,10 @@ static void on_stop(Service& service) { } } -extern const ServiceManifest manifest = { +extern const Manifest manifest = { .id = "sdcard", - .on_start = &on_start, - .on_stop = &on_stop + .onStart = &on_start, + .onStop = &on_stop }; } // namespace diff --git a/TactilityHeadless/Source/Services/Wifi/Wifi.h b/TactilityHeadless/Source/service/wifi/Wifi.h similarity index 100% rename from TactilityHeadless/Source/Services/Wifi/Wifi.h rename to TactilityHeadless/Source/service/wifi/Wifi.h diff --git a/TactilityHeadless/Source/Services/Wifi/WifiEsp.cpp b/TactilityHeadless/Source/service/wifi/WifiEsp.cpp similarity index 97% rename from TactilityHeadless/Source/Services/Wifi/WifiEsp.cpp rename to TactilityHeadless/Source/service/wifi/WifiEsp.cpp index 03285d3f..6a7db0b4 100644 --- a/TactilityHeadless/Source/Services/Wifi/WifiEsp.cpp +++ b/TactilityHeadless/Source/service/wifi/WifiEsp.cpp @@ -9,11 +9,12 @@ #include "freertos/event_groups.h" #include "Log.h" #include "Pubsub.h" -#include "Service.h" +#include "service/Service.h" #include "WifiSettings.h" #include #include #include +#include namespace tt::service::wifi { @@ -67,7 +68,7 @@ public: bool secure_connection = false; esp_event_handler_instance_t event_handler_any_id = nullptr; esp_event_handler_instance_t event_handler_got_ip = nullptr; - EventGroupHandle_t event_group; + EventFlag connection_wait_flags; settings::WifiApSettings connection_target = { .ssid = { 0 }, .password = { 0 }, @@ -88,7 +89,6 @@ static void unlock(Wifi* wifi); Wifi::Wifi() : radio_state(WIFI_RADIO_OFF) { pubsub = tt_pubsub_alloc(); - event_group = xEventGroupCreate(); } Wifi::~Wifi() { @@ -309,7 +309,7 @@ static void event_handler(TT_UNUSED void* arg, esp_event_base_t event_base, int3 } } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { if (wifi_singleton->radio_state != WIFI_RADIO_OFF_PENDING) { - xEventGroupSetBits(wifi_singleton->event_group, WIFI_FAIL_BIT); + wifi_singleton->connection_wait_flags.set(WIFI_FAIL_BIT); TT_LOG_I(TAG, "event_handler: disconnected"); wifi_singleton->radio_state = WIFI_RADIO_ON; publish_event_simple(wifi_singleton, WifiEventTypeDisconnected); @@ -317,7 +317,7 @@ static void event_handler(TT_UNUSED void* arg, esp_event_base_t event_base, int3 } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { auto* event = static_cast(event_data); TT_LOG_I(TAG, "event_handler: got ip:" IPSTR, IP2STR(&event->ip_info.ip)); - xEventGroupSetBits(wifi_singleton->event_group, WIFI_CONNECTED_BIT); + wifi_singleton->connection_wait_flags.set(WIFI_CONNECTED_BIT); } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_SCAN_DONE) { auto* event = static_cast(event_data); TT_LOG_I(TAG, "event_handler: wifi scanning done (scan id %u)", event->scan_id); @@ -595,13 +595,7 @@ static void connect_internal(Wifi* wifi) { /* Waiting until either the connection is established (WIFI_CONNECTED_BIT) * or connection failed for the maximum number of re-tries (WIFI_FAIL_BIT). * The bits are set by wifi_event_handler() */ - EventBits_t bits = xEventGroupWaitBits( - wifi->event_group, - WIFI_CONNECTED_BIT | WIFI_FAIL_BIT, - pdFALSE, - pdFALSE, - portMAX_DELAY - ); + uint32_t bits = wifi_singleton->connection_wait_flags.wait(WIFI_FAIL_BIT | WIFI_CONNECTED_BIT); if (bits & WIFI_CONNECTED_BIT) { wifi->radio_state = WIFI_RADIO_CONNECTION_ACTIVE; @@ -624,7 +618,7 @@ static void connect_internal(Wifi* wifi) { TT_LOG_E(TAG, "UNEXPECTED EVENT"); } - xEventGroupClearBits(wifi_singleton->event_group, WIFI_FAIL_BIT | WIFI_CONNECTED_BIT); + wifi_singleton->connection_wait_flags.clear(WIFI_FAIL_BIT | WIFI_CONNECTED_BIT); } static void disconnect_internal_but_keep_active(Wifi* wifi) { @@ -752,10 +746,10 @@ static void service_stop(Service& service) { tt_crash("not fully implemented"); } -extern const ServiceManifest manifest = { +extern const Manifest manifest = { .id = "Wifi", - .on_start = &service_start, - .on_stop = &service_stop + .onStart = &service_start, + .onStop = &service_stop }; } // namespace diff --git a/TactilityHeadless/Source/Services/Wifi/WifiGlobals.h b/TactilityHeadless/Source/service/wifi/WifiGlobals.h similarity index 100% rename from TactilityHeadless/Source/Services/Wifi/WifiGlobals.h rename to TactilityHeadless/Source/service/wifi/WifiGlobals.h diff --git a/TactilityHeadless/Source/Services/Wifi/WifiMock.cpp b/TactilityHeadless/Source/service/wifi/WifiMock.cpp similarity index 96% rename from TactilityHeadless/Source/Services/Wifi/WifiMock.cpp rename to TactilityHeadless/Source/service/wifi/WifiMock.cpp index 601e39c5..1ebc2c4d 100644 --- a/TactilityHeadless/Source/Services/Wifi/WifiMock.cpp +++ b/TactilityHeadless/Source/service/wifi/WifiMock.cpp @@ -7,7 +7,7 @@ #include "MessageQueue.h" #include "Mutex.h" #include "Pubsub.h" -#include "Service.h" +#include "service/Service.h" #include #include @@ -176,10 +176,10 @@ static void service_stop(TT_UNUSED Service& service) { wifi = nullptr; } -extern const ServiceManifest manifest = { +extern const Manifest manifest = { .id = "Wifi", - .on_start = &service_start, - .on_stop = &service_stop + .onStart = &service_start, + .onStop = &service_stop }; } // namespace diff --git a/TactilityHeadless/Source/Services/Wifi/WifiSettings.h b/TactilityHeadless/Source/service/wifi/WifiSettings.h similarity index 100% rename from TactilityHeadless/Source/Services/Wifi/WifiSettings.h rename to TactilityHeadless/Source/service/wifi/WifiSettings.h diff --git a/TactilityHeadless/Source/Services/Wifi/WifiSettingsEsp.cpp b/TactilityHeadless/Source/service/wifi/WifiSettingsEsp.cpp similarity index 98% rename from TactilityHeadless/Source/Services/Wifi/WifiSettingsEsp.cpp rename to TactilityHeadless/Source/service/wifi/WifiSettingsEsp.cpp index 515d163f..83a8e2ec 100644 --- a/TactilityHeadless/Source/Services/Wifi/WifiSettingsEsp.cpp +++ b/TactilityHeadless/Source/service/wifi/WifiSettingsEsp.cpp @@ -6,9 +6,8 @@ #include "nvs_flash.h" #include "Log.h" -#include "Hash.h" -#include "Check.h" -#include "Crypt.h" +#include "crypt/Hash.h" +#include "crypt/Crypt.h" #define TAG "wifi_settings" #define TT_NVS_NAMESPACE "wifi_settings" // limited by NVS_KEY_NAME_MAX_SIZE diff --git a/TactilityHeadless/Source/Services/Wifi/WifiSettingsMock.cpp b/TactilityHeadless/Source/service/wifi/WifiSettingsMock.cpp similarity index 100% rename from TactilityHeadless/Source/Services/Wifi/WifiSettingsMock.cpp rename to TactilityHeadless/Source/service/wifi/WifiSettingsMock.cpp