diff --git a/App/CMakeLists.txt b/App/CMakeLists.txt new file mode 100644 index 00000000..7a032b65 --- /dev/null +++ b/App/CMakeLists.txt @@ -0,0 +1,44 @@ +cmake_minimum_required(VERSION 3.16) + +if (DEFINED ENV{ESP_IDF_VERSION}) + set(BOARD_COMPONENTS Tactility) + + if("${IDF_TARGET}" STREQUAL "esp32") + list(APPEND BOARD_COMPONENTS + YellowBoard + M5stackCore2 + ) + endif() + + # T-Deck is an S3 platform + if("${IDF_TARGET}" STREQUAL "esp32s3") + list(APPEND BOARD_COMPONENTS + LilygoTdeck + M5stackCoreS3 + WaveshareS3Touch + ) + endif() + + idf_component_register( + SRC_DIRS "Source" + "Source/HelloWorld" + REQUIRES ${BOARD_COMPONENTS} + ) +else() + + file(GLOB_RECURSE SOURCES "Source/*.c*") + add_executable(AppSim ${SOURCES}) + target_link_libraries(AppSim + PRIVATE Tactility + PRIVATE TactilityCore + PRIVATE TactilityHeadless + PRIVATE Simulator + ) + + find_package(SDL2 REQUIRED CONFIG) + target_link_libraries(AppSim PRIVATE ${SDL2_LIBRARIES}) + include_directories(${SDL2_INCLUDE_DIRS}) + + add_definitions(-D_Nullable=) + add_definitions(-D_Nonnull=) +endif() diff --git a/AppEsp32/Kconfig b/App/Kconfig similarity index 100% rename from AppEsp32/Kconfig rename to App/Kconfig diff --git a/AppEsp32/Source/Boards.h b/App/Source/Boards.h similarity index 66% rename from AppEsp32/Source/Boards.h rename to App/Source/Boards.h index f08db744..2040505b 100644 --- a/AppEsp32/Source/Boards.h +++ b/App/Source/Boards.h @@ -1,5 +1,6 @@ #pragma once +#ifdef ESP_PLATFORM #include "sdkconfig.h" // Supported hardware: @@ -22,3 +23,23 @@ #define TT_BOARD_HARDWARE NULL #error Replace TT_BOARD_HARDWARE in main.c with your own. Or copy one of the ./sdkconfig.board.* files into ./sdkconfig. #endif + +#else // else simulator + +#include "Simulator.h" + +#define TT_BOARD_HARDWARE &sim_hardware + +extern "C" { +void app_main(); +} + +int main_stub(); // Main function logic from Simulator board project + +// Actual main that passes on app_main (to be executed in a FreeRTOS task) and bootstraps FreeRTOS +int main() { + setMainForSim(app_main); + return main_stub(); +} + +#endif // ESP_PLATFORM \ No newline at end of file diff --git a/AppEsp32/Source/HelloWorld/HelloWorld.cpp b/App/Source/HelloWorld/HelloWorld.cpp similarity index 100% rename from AppEsp32/Source/HelloWorld/HelloWorld.cpp rename to App/Source/HelloWorld/HelloWorld.cpp diff --git a/AppEsp32/Source/Main.cpp b/App/Source/Main.cpp similarity index 100% rename from AppEsp32/Source/Main.cpp rename to App/Source/Main.cpp diff --git a/AppEsp32/idf_component.yml b/App/idf_component.yml similarity index 100% rename from AppEsp32/idf_component.yml rename to App/idf_component.yml diff --git a/AppEsp32/CMakeLists.txt b/AppEsp32/CMakeLists.txt deleted file mode 100644 index eb024cfb..00000000 --- a/AppEsp32/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -cmake_minimum_required(VERSION 3.16) - -set(BOARD_COMPONENTS Tactility) - -if("${IDF_TARGET}" STREQUAL "esp32") - list(APPEND BOARD_COMPONENTS - YellowBoard - M5stackCore2 - ) -endif() - -# T-Deck is an S3 platform -if("${IDF_TARGET}" STREQUAL "esp32s3") - list(APPEND BOARD_COMPONENTS - LilygoTdeck - M5stackCoreS3 - WaveshareS3Touch - ) -endif() - -idf_component_register( - SRC_DIRS "Source" - "Source/HelloWorld" - REQUIRES ${BOARD_COMPONENTS} -) diff --git a/AppSim/CMakeLists.txt b/AppSim/CMakeLists.txt deleted file mode 100644 index 87bd7a56..00000000 --- a/AppSim/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -cmake_minimum_required(VERSION 3.16) - -file(GLOB_RECURSE SOURCES "Source/*.c*") -add_executable(AppSim ${SOURCES}) -target_link_libraries(AppSim - PRIVATE Tactility - PRIVATE TactilityCore - PRIVATE TactilityHeadless - PRIVATE lvgl -) - -find_package(SDL2 REQUIRED CONFIG) -target_link_libraries(AppSim PRIVATE ${SDL2_LIBRARIES}) -include_directories(${SDL2_INCLUDE_DIRS}) - -add_definitions(-D_Nullable=) -add_definitions(-D_Nonnull=) diff --git a/AppSim/Source/HelloWorld/hello_world.cpp b/AppSim/Source/HelloWorld/hello_world.cpp deleted file mode 100644 index 2bf384e5..00000000 --- a/AppSim/Source/HelloWorld/hello_world.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "lvgl/Toolbar.h" - -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); - - lv_obj_t* label = lv_label_create(parent); - lv_label_set_text(label, "Hello, world!"); - lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); -} - -extern const tt::app::Manifest hello_world_app = { - .id = "HelloWorld", - .name = "Hello World", - .type = tt::app::TypeUser, - .onShow = &app_show -}; diff --git a/AppSim/Source/main.cpp b/AppSim/Source/main.cpp deleted file mode 100644 index acc468ba..00000000 --- a/AppSim/Source/main.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "Tactility.h" - -extern const tt::hal::Configuration sim_hardware; -extern const tt::app::Manifest hello_world_app; - -void app_main() { - static const tt::Configuration config = { - .hardware = &sim_hardware, - .apps = { - &hello_world_app - }, - .services = {}, - .auto_start_app_id = nullptr - }; - - tt::init(&config); -} diff --git a/Boards/Simulator/CMakeLists.txt b/Boards/Simulator/CMakeLists.txt new file mode 100644 index 00000000..e9707d41 --- /dev/null +++ b/Boards/Simulator/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 3.16) + +if (NOT DEFINED ENV{ESP_IDF_VERSION}) + + file(GLOB_RECURSE SOURCES "Source/*.c*") + file(GLOB_RECURSE HEADERS "Source/*.h*") + + add_library(Simulator OBJECT) + + target_sources(Simulator + PRIVATE ${SOURCES} + PUBLIC ${HEADERS} + ) + target_link_libraries(Simulator + PRIVATE Tactility + PRIVATE TactilityCore + PRIVATE TactilityHeadless + PRIVATE lvgl + ) + + add_definitions(-D_Nullable=) + add_definitions(-D_Nonnull=) + +endif() diff --git a/AppSim/Source/FreeRTOSConfig.h b/Boards/Simulator/Source/FreeRTOSConfig.h similarity index 100% rename from AppSim/Source/FreeRTOSConfig.h rename to Boards/Simulator/Source/FreeRTOSConfig.h diff --git a/Boards/Simulator/Source/Simulator.cpp b/Boards/Simulator/Source/Simulator.cpp new file mode 100644 index 00000000..e84fd244 --- /dev/null +++ b/Boards/Simulator/Source/Simulator.cpp @@ -0,0 +1,12 @@ +#include "Simulator.h" + +MainFunction mainFunction = nullptr; + +void setMainForSim(MainFunction newMainFunction) { + mainFunction = newMainFunction; +} + +void executeMainFunction() { + assert(mainFunction); + mainFunction(); +} diff --git a/Boards/Simulator/Source/Simulator.h b/Boards/Simulator/Source/Simulator.h new file mode 100644 index 00000000..818d45bd --- /dev/null +++ b/Boards/Simulator/Source/Simulator.h @@ -0,0 +1,10 @@ +#pragma once + +#include "hal/Configuration.h" + +extern const tt::hal::Configuration sim_hardware; + +typedef void (*MainFunction)(); +void setMainForSim(MainFunction mainFunction); +void executeMainFunction(); +int main_stub(); diff --git a/AppSim/Source/freertos.cpp b/Boards/Simulator/Source/freertos.cpp similarity index 94% rename from AppSim/Source/freertos.cpp rename to Boards/Simulator/Source/freertos.cpp index 5273c8b6..48e782ac 100644 --- a/AppSim/Source/freertos.cpp +++ b/Boards/Simulator/Source/freertos.cpp @@ -1,21 +1,19 @@ -#include "Tactility.h" #include "Thread.h" #include "FreeRTOS.h" #include "task.h" +#include "Simulator.h" #define TAG "freertos" -void app_main(); - static void main_task(TT_UNUSED void* parameter) { TT_LOG_I(TAG, "starting app_main()"); - app_main(); + executeMainFunction(); TT_LOG_I(TAG, "returned from app_main()"); vTaskDelete(nullptr); } -int main() { +int main_stub() { BaseType_t task_result = xTaskCreate( main_task, "main", diff --git a/AppSim/Source/hardware_config.cpp b/Boards/Simulator/Source/hardware_config.cpp similarity index 100% rename from AppSim/Source/hardware_config.cpp rename to Boards/Simulator/Source/hardware_config.cpp diff --git a/AppSim/Source/lv_conf.h b/Boards/Simulator/Source/lv_conf.h similarity index 100% rename from AppSim/Source/lv_conf.h rename to Boards/Simulator/Source/lv_conf.h diff --git a/AppSim/Source/lvgl_hal.cpp b/Boards/Simulator/Source/lvgl_hal.cpp similarity index 100% rename from AppSim/Source/lvgl_hal.cpp rename to Boards/Simulator/Source/lvgl_hal.cpp diff --git a/AppSim/Source/lvgl_hal.h b/Boards/Simulator/Source/lvgl_hal.h similarity index 100% rename from AppSim/Source/lvgl_hal.h rename to Boards/Simulator/Source/lvgl_hal.h diff --git a/AppSim/Source/lvgl_task.cpp b/Boards/Simulator/Source/lvgl_task.cpp similarity index 100% rename from AppSim/Source/lvgl_task.cpp rename to Boards/Simulator/Source/lvgl_task.cpp diff --git a/AppSim/Source/lvgl_task.h b/Boards/Simulator/Source/lvgl_task.h similarity index 100% rename from AppSim/Source/lvgl_task.h rename to Boards/Simulator/Source/lvgl_task.h diff --git a/AppSim/Source/power.cpp b/Boards/Simulator/Source/power.cpp similarity index 100% rename from AppSim/Source/power.cpp rename to Boards/Simulator/Source/power.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index cf985d63..3bc95b58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,10 +16,10 @@ if (DEFINED ENV{ESP_IDF_VERSION}) add_definitions(-DARDUINO_M5STACK_CORE2) add_compile_definitions(ARDUINO_M5STACK_CORE2) - set(COMPONENTS AppEsp32) + set(COMPONENTS App) set(EXTRA_COMPONENT_DIRS "Boards" - "AppEsp32" + "App" "Tactility" "TactilityHeadless" "Libraries/esp_lvgl_port" @@ -35,6 +35,10 @@ if (DEFINED ENV{ESP_IDF_VERSION}) set(EXCLUDE_COMPONENTS "M5stackCoreS3") endif() + if(NOT "${IDF_TARGET}" STREQUAL "Simulator") + set(EXCLUDE_COMPONENTS "Simulator") + endif() + # ESP32-S3 boards if(NOT "${IDF_TARGET}" STREQUAL "esp32s3") set(EXCLUDE_COMPONENTS "LilygoTdeck") @@ -50,6 +54,7 @@ project(TactilityRoot) if (NOT DEFINED ENV{ESP_IDF_VERSION}) add_subdirectory(Tactility) add_subdirectory(TactilityHeadless) + add_subdirectory(Boards/Simulator) endif() add_subdirectory(TactilityCore) @@ -58,30 +63,32 @@ add_subdirectory(Libraries/lv_screenshot) if (NOT DEFINED ENV{ESP_IDF_VERSION}) # FreeRTOS - set(FREERTOS_CONFIG_FILE_DIRECTORY ${PROJECT_SOURCE_DIR}/AppSim/Source CACHE STRING "") + set(FREERTOS_CONFIG_FILE_DIRECTORY ${PROJECT_SOURCE_DIR}/Boards/Simulator/Source CACHE STRING "") set(FREERTOS_PORT GCC_POSIX CACHE STRING "") add_subdirectory(Libraries/FreeRTOS-Kernel) target_compile_definitions(freertos_kernel PUBLIC "projCOVERAGE_TEST=0") target_include_directories(freertos_kernel - PUBLIC AppSim/Source # for FreeRTOSConfig.h + PUBLIC Boards/Simulator/Source # for FreeRTOSConfig.h ) # EmbedTLS + set(ENABLE_TESTING OFF) + set(ENABLE_PROGRAMS OFF) add_subdirectory(Libraries/mbedtls) # Sim app if (NOT DEFINED ENV{SKIP_SDL}) - add_subdirectory(AppSim) + add_subdirectory(App) endif() # Tests add_subdirectory(Tests) # SDL & LVGL - set(LV_CONF_PATH ${PROJECT_SOURCE_DIR}/AppSim/Source/lv_conf.h) + set(LV_CONF_PATH ${PROJECT_SOURCE_DIR}/Boards/Simulator/Source/lv_conf.h) add_subdirectory(Libraries/lvgl) # Added as idf component for ESP and as library for other targets target_include_directories(lvgl - PUBLIC AppSim/Source # for lv_conf.h and lv_drv_conf.h + PUBLIC Boards/Source # for lv_conf.h and lv_drv_conf.h ) # TODO: This is a temporary skipping option for running unit tests @@ -108,6 +115,7 @@ if (NOT DEFINED ENV{ESP_IDF_VERSION}) find_package(SDL2_image REQUIRED) target_include_directories(lvgl PUBLIC ${SDL2_IMAGE_INCLUDE_DIRS}) target_link_libraries(AppSim ${SDL2_IMAGE_LIBRARIES}) + target_link_libraries(Simulator ${SDL2_IMAGE_LIBRARIES}) endif(LV_USE_DRAW_SDL) if (LV_USE_LIBPNG) diff --git a/Documentation/project-structure.puml b/Documentation/project-structure.puml index 06166531..b2b567bf 100644 --- a/Documentation/project-structure.puml +++ b/Documentation/project-structure.puml @@ -8,16 +8,12 @@ note right of theadless : to build and use background services [TactilityCore] as tcore note right of tcore : defines, data types, logging, async, etc. -package "Applications" { - [AppSim] as appsim - [AppEsp32] as appesp -} +[App] as app -note right of appesp : AppEsp depends on the board \n projects for configuration +note right of app : App depends on the board \n projects for configuration +[app] ..> [t] [t] ..> [theadless] [theadless] ..> [tcore] -[appsim] ..> [t] -[appesp] ..> [t] @enduml \ No newline at end of file diff --git a/README.md b/README.md index 005e68fc..37714a75 100644 --- a/README.md +++ b/README.md @@ -124,9 +124,8 @@ Take a look at the [App Lifecycle](Documentation/app-lifecycle.md) or the [depen Directories explained: -- `AppEsp32`: The ESP32 application example -- `AppSim`: The PC/simulator application example -- `Boards`: Contains ESP modules with drivers +- `App`: The application/firmware example project +- `Boards`: Contains board configuration projects with drivers (and simulator) - `Tactility`: The main application platform code - `TactilityHeadless`: Service framework and default services. - `TactilityCore`: Core functionality regarding threads, stdlib, etc. diff --git a/TactilityHeadless/Source/service/wifi/WifiMock.cpp b/TactilityHeadless/Source/service/wifi/WifiMock.cpp index 1ebc2c4d..4ebc6bd1 100644 --- a/TactilityHeadless/Source/service/wifi/WifiMock.cpp +++ b/TactilityHeadless/Source/service/wifi/WifiMock.cpp @@ -176,6 +176,10 @@ static void service_stop(TT_UNUSED Service& service) { wifi = nullptr; } +void wifi_main(void*) { + // NO-OP +} + extern const Manifest manifest = { .id = "Wifi", .onStart = &service_start, diff --git a/run.sh b/run.sh index c73de400..bc1d54bd 100755 --- a/run.sh +++ b/run.sh @@ -5,8 +5,8 @@ else set -e cmake -S ./ -B build-sim cmake --build build-sim -j 12 - cd data - ../build-sim/AppSim/AppSim + cd Data + ../build-sim/App/AppSim cd - fi