diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..51ce0b7 --- /dev/null +++ b/.clang-format @@ -0,0 +1,5 @@ +BasedOnStyle: LLVM +IndentWidth: 4 +ColumnLimit: 100 +PointerAlignment: Left +SortIncludes: CaseSensitive diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..8ec7c35 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,11 @@ +Checks: > + -*, + bugprone-*, + performance-*, + portability-*, + modernize-use-nullptr, + -bugprone-reserved-identifier, + -modernize-use-nullptr, + -performance-enum-size +WarningsAsErrors: '*' +HeaderFilterRegex: '(^|/)(poc/common|poc/host)/' diff --git a/.clangd b/.clangd index 437f255..7e27706 100644 --- a/.clangd +++ b/.clangd @@ -1,2 +1,3 @@ CompileFlags: + Add: [-Ipoc/common/components/frame_poc_runtime/include] Remove: [-f*, -m*] diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index dafb8ad..b7c64f6 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,4 +1,4 @@ -ARG DOCKER_TAG=latest +ARG DOCKER_TAG=v6.0.2 FROM espressif/idf:${DOCKER_TAG} ENV LC_ALL=C.UTF-8 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 246b79f..d86e17e 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,7 +1,10 @@ { "name": "ESP-IDF QEMU", "build": { - "dockerfile": "Dockerfile" + "dockerfile": "Dockerfile", + "args": { + "DOCKER_TAG": "v6.0.2" + } }, "customizations": { "vscode": { diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 15a965c..c19ad1e 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -2,7 +2,7 @@ "configurations": [ { "name": "ESP-IDF", - "compilerPath": "/home/lain/.espressif/tools/xtensa-esp-elf/esp-15.2.0_20251204/xtensa-esp-elf/bin/xtensa-esp32-elf-gcc", + "compilerPath": "/home/lain/.espressif/tools/xtensa-esp-elf/esp-15.2.0_20251204/xtensa-esp-elf/bin/xtensa-esp32s3-elf-gcc", "compileCommands": "/home/lain/Projects/esp_study/esp_study/.build/dev/compile_commands.json", "intelliSenseMode": "gcc-x86", "includePath": [ diff --git a/.vscode/settings.json b/.vscode/settings.json index 509c913..1078925 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -29,5 +29,18 @@ "--background-index", "--query-driver=**", "--compile-commands-dir=/home/lain/Projects/esp_study/esp_study/.build/dev" - ] + ], + "chat.tools.terminal.autoApprove": { + "/^awk '/\\^FRAME_ERR_\\[A-Z_\\]\\+ -\\[0-9\\]\\+ / \\{ defs\\[\\$1\\]\\+\\+; values\\[\\$2\\]\\+\\+ \\} \\{ rest=\\$0; while \\(match\\(rest, /FRAME_ERR_\\[A-Z_\\]\\+/\\)\\) \\{ refs\\[substr\\(rest, RSTART, RLENGTH\\)\\]=1; rest=substr\\(rest, RSTART\\+RLENGTH\\) \\} \\} END \\{ for \\(code in refs\\) if \\(!\\(code in defs\\)\\) \\{ print \"missing: \" code; bad=1 \\} for \\(code in defs\\) if \\(defs\\[code\\] != 1\\) \\{ print \"duplicate definition: \" code; bad=1 \\} for \\(value in values\\) if \\(values\\[value\\] != 1\\) \\{ print \"duplicate value: \" value; bad=1 \\} exit bad \\}' _doc/project\\.md; and set fences \\(rg -c '\\^```' _doc/project\\.md\\); printf 'fences=%s\\\\n' \"\\$fences\"; and test \\(math \"\\$fences % 2\"\\) -eq 0; and git diff --no-index --check /dev/null _doc/project\\.md; set diff_code \\$status; test \\$diff_code -eq 1$/": { + "approve": true, + "matchCommandLine": true + }, + "/^git --no-pager status --short && printf 'document-lines=' && wc -l < _doc/project\\.md && printf 'document-bytes=' && wc -c < _doc/project\\.md$/": { + "approve": true, + "matchCommandLine": true + } + }, + "idf.customExtraVars": { + "IDF_TARGET": "esp32s3" + } } diff --git a/CMakeLists.txt b/CMakeLists.txt index c8d5972..7ad6a18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,14 @@ cmake_minimum_required(VERSION 3.25) -if(NOT DEFINED IDF_TARGET) - set(IDF_TARGET "esp32s3" CACHE STRING "ESP-IDF target") -endif() +set(FRAME_REQUIRED_IDF_TAG "v6.0.2" CACHE STRING + "Exact ESP-IDF release tag required by the architecture") +set(FRAME_REQUIRED_IDF_COMMIT "7101770dc6db2667b3c477cc31365dd1acd6db4e" CACHE STRING + "Exact ESP-IDF commit required by the architecture") +set(FRAME_REQUIRED_COMPILER_VERSION "15.2.0" CACHE STRING + "Exact Xtensa GCC version required by the architecture") + +include("${CMAKE_CURRENT_LIST_DIR}/cmake/FramePlatform.cmake") +frame_require_esp_idf("${FRAME_REQUIRED_IDF_TAG}") if(NOT DEFINED SDKCONFIG) set(SDKCONFIG "${CMAKE_BINARY_DIR}/sdkconfig") @@ -13,8 +19,15 @@ if(NOT DEFINED SDKCONFIG_DEFAULTS) "${CMAKE_SOURCE_DIR}/sdkconfig.defaults;${CMAKE_SOURCE_DIR}/sdkconfig.defaults.dev") endif() -set(CMAKE_CXX_STANDARD 26) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(esp_study) \ No newline at end of file +project(esp_study) + +frame_verify_platform("${FRAME_REQUIRED_IDF_COMMIT}" "${FRAME_REQUIRED_COMPILER_VERSION}") + +# ESP-IDF v6.0.2 deliberately defaults components to GNU C++26. Frame code is +# compiled as strict C++26 by appending the stricter dialect after IDF options. +idf_build_set_property(CXX_COMPILE_OPTIONS "-std=c++26" APPEND) + +if(CMAKE_CXX_STANDARD LESS 26) + message(FATAL_ERROR "The selected toolchain does not provide C++26 mode.") +endif() diff --git a/CMakePresets.json b/CMakePresets.json index 670c2a9..1ad4a62 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -6,31 +6,27 @@ "patch": 0 }, "configurePresets": [ - { - "name": "idf-base", - "hidden": true, - "generator": "Ninja", - "binaryDir": "${sourceDir}/.build/${presetName}", - "cacheVariables": { - "IDF_TARGET": "esp32s3", - "SDKCONFIG": "${sourceDir}/.build/${presetName}/sdkconfig" - } - }, { "name": "dev", - "inherits": "idf-base", "displayName": "Default (development)", "description": "Development configuration", + "generator": "Ninja", + "binaryDir": "${sourceDir}/.build/dev", "cacheVariables": { + "IDF_TARGET": "esp32s3", + "SDKCONFIG": "${sourceDir}/.build/dev/sdkconfig", "SDKCONFIG_DEFAULTS": "${sourceDir}/sdkconfig.defaults;${sourceDir}/sdkconfig.defaults.dev" } }, { "name": "prod", - "inherits": "idf-base", "displayName": "Production", "description": "Production configuration", + "generator": "Ninja", + "binaryDir": "${sourceDir}/.build/prod", "cacheVariables": { + "IDF_TARGET": "esp32s3", + "SDKCONFIG": "${sourceDir}/.build/prod/sdkconfig", "SDKCONFIG_DEFAULTS": "${sourceDir}/sdkconfig.defaults;${sourceDir}/sdkconfig.defaults.prod" } } diff --git a/cmake/FramePlatform.cmake b/cmake/FramePlatform.cmake new file mode 100644 index 0000000..96ba4db --- /dev/null +++ b/cmake/FramePlatform.cmake @@ -0,0 +1,85 @@ +include_guard(GLOBAL) + +macro(frame_require_esp_idf required_tag) + if(NOT DEFINED ENV{IDF_PATH} OR "$ENV{IDF_PATH}" STREQUAL "") + message(FATAL_ERROR + "IDF_PATH is not set. Export the ESP-IDF ${required_tag} environment first.") + endif() + + if(NOT EXISTS "$ENV{IDF_PATH}/tools/cmake/project.cmake") + message(FATAL_ERROR + "IDF_PATH does not point to an ESP-IDF checkout: $ENV{IDF_PATH}") + endif() + + execute_process( + COMMAND git -C "$ENV{IDF_PATH}" describe --tags --exact-match + RESULT_VARIABLE FRAME_IDF_TAG_RESULT + OUTPUT_VARIABLE FRAME_IDF_TAG + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if(NOT FRAME_IDF_TAG_RESULT EQUAL 0 OR + NOT "${FRAME_IDF_TAG}" STREQUAL "${required_tag}") + message(FATAL_ERROR + "ESP-IDF must be checked out at exact tag ${required_tag}; detected '${FRAME_IDF_TAG}'.") + endif() + + if(NOT DEFINED IDF_TARGET) + set(IDF_TARGET "esp32s3" CACHE STRING "ESP-IDF target") + endif() + + if(NOT IDF_TARGET STREQUAL "esp32s3") + message(FATAL_ERROR "This project only supports IDF_TARGET=esp32s3.") + endif() + + set(CMAKE_CXX_STANDARD 26) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + set(CMAKE_CXX_EXTENSIONS OFF) +endmacro() + +function(frame_verify_platform required_commit required_compiler_version) + if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + message(FATAL_ERROR + "Frame requires the ESP-IDF GNU Xtensa compiler; detected ${CMAKE_CXX_COMPILER_ID}.") + endif() + + if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL required_compiler_version) + message(FATAL_ERROR + "Frame requires Xtensa GCC ${required_compiler_version}; detected ${CMAKE_CXX_COMPILER_VERSION}.") + endif() + + execute_process( + COMMAND git -C "$ENV{IDF_PATH}" rev-parse HEAD + RESULT_VARIABLE commit_result + OUTPUT_VARIABLE detected_commit + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT commit_result EQUAL 0 OR NOT detected_commit STREQUAL required_commit) + message(FATAL_ERROR + "ESP-IDF commit must be ${required_commit}; detected '${detected_commit}'.") + endif() + + execute_process( + COMMAND git -C "$ENV{IDF_PATH}" status --short + RESULT_VARIABLE status_result + OUTPUT_VARIABLE idf_changes + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT status_result EQUAL 0 OR NOT idf_changes STREQUAL "") + message(FATAL_ERROR "The ESP-IDF checkout must be clean for a reproducible Frame build.") + endif() + + execute_process( + COMMAND "${CMAKE_CXX_COMPILER}" -dumpmachine + RESULT_VARIABLE machine_result + OUTPUT_VARIABLE compiler_machine + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT machine_result EQUAL 0 OR NOT compiler_machine STREQUAL "xtensa-esp-elf") + message(FATAL_ERROR + "Frame requires compiler target xtensa-esp-elf; detected '${compiler_machine}'.") + endif() + + message(STATUS + "Frame platform: IDF ${required_commit}, ${compiler_machine} GCC ${CMAKE_CXX_COMPILER_VERSION}, ${IDF_TARGET}") +endfunction() diff --git a/components/app_framework/CMakeLists.txt b/components/app_framework/CMakeLists.txt deleted file mode 100644 index efcbd55..0000000 --- a/components/app_framework/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -idf_component_register(SRCS - "application.cc" - "context.cc" - "loader.cc" - INCLUDE_DIRS ".") \ No newline at end of file diff --git a/components/app_framework/application.cc b/components/app_framework/application.cc deleted file mode 100644 index aef3b73..0000000 --- a/components/app_framework/application.cc +++ /dev/null @@ -1,45 +0,0 @@ -#include "application.hh" - -#include // For std::nothrow -#include // For std::stop_source, std::stop_token, std::nostopstate -#include // For std::jthread - -#include "context.hh" // For context -#include "loader.hh" // For loader::ui, loader::service - -class impl { -public: - impl() - : ui_thread_(&impl::ui_thread_function, this), - service_thread_(&impl::service_thread_function, this), - context_() {}; - ~impl() noexcept = default; - - void run() { - context_.run(); - } - -private: - void ui_thread_function(std::stop_token token) { - // Implementation of the UI thread function - loader::ui ui_instance; - ui_instance.set_context(&context_); - } - - void service_thread_function(std::stop_token token) { - // Implementation of the service thread function - loader::service service_instance; - service_instance.set_context(&context_); - } - -private: - std::jthread ui_thread_; - std::jthread service_thread_; - context context_; -}; - -application::application() : pimpl_(new(std::nothrow) impl()) {} - -application::~application() noexcept { delete pimpl_; } - -void application::run() { pimpl_->run(); } \ No newline at end of file diff --git a/components/app_framework/application.hh b/components/app_framework/application.hh deleted file mode 100644 index 8aaff51..0000000 --- a/components/app_framework/application.hh +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef APPLICATION_HH -#define APPLICATION_HH -#pragma once - -class impl; - -class application { -public: - application(); - ~application() noexcept; - - void run(); - -private: - impl *pimpl_; -}; - -#endif // APPLICATION_HH \ No newline at end of file diff --git a/components/app_framework/context.cc b/components/app_framework/context.cc deleted file mode 100644 index e69de29..0000000 diff --git a/components/app_framework/context.hh b/components/app_framework/context.hh deleted file mode 100644 index d79b80a..0000000 --- a/components/app_framework/context.hh +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef CONTEXT_HH -#define CONTEXT_HH -#pragma once -// 事件循环上下文 -class context { -public: - context() = default; - ~context() noexcept = default; - - void run() noexcept; -}; -#endif // CONTEXT_HH \ No newline at end of file diff --git a/components/app_framework/loader.cc b/components/app_framework/loader.cc deleted file mode 100644 index e69de29..0000000 diff --git a/components/app_framework/loader.hh b/components/app_framework/loader.hh deleted file mode 100644 index 94e6870..0000000 --- a/components/app_framework/loader.hh +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef LOADER_HH -#define LOADER_HH -#pragma once - -class context; - -namespace loader { -class ui { -public: - ui() = default; - ~ui() noexcept = default; - - void set_context(context *ctx); -}; - -class service { -public: - service() = default; - ~service() noexcept = default; - - void set_context(context *ctx); -}; -} // namespace loader - -#endif // LOADER_HH \ No newline at end of file diff --git a/components/display_service/CMakeLists.txt b/components/display_service/CMakeLists.txt deleted file mode 100644 index a96dced..0000000 --- a/components/display_service/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -idf_component_register() diff --git a/components/network_service/CMakeLists.txt b/components/network_service/CMakeLists.txt deleted file mode 100644 index a96dced..0000000 --- a/components/network_service/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -idf_component_register() diff --git a/components/ota_service/CMakeLists.txt b/components/ota_service/CMakeLists.txt deleted file mode 100644 index a96dced..0000000 --- a/components/ota_service/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -idf_component_register() diff --git a/components/startup_ui/CMakeLists.txt b/components/startup_ui/CMakeLists.txt deleted file mode 100644 index a96dced..0000000 --- a/components/startup_ui/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -idf_component_register() diff --git a/components/storage_service/CMakeLists.txt b/components/storage_service/CMakeLists.txt deleted file mode 100644 index 27a2547..0000000 --- a/components/storage_service/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -idf_component_register(REQUIRES littlefs) - -littlefs_create_partition_image(assets_fs "../../assets" FLASH_IN_PROJECT) diff --git a/components/storage_service/idf_component.yml b/components/storage_service/idf_component.yml deleted file mode 100644 index 86021f9..0000000 --- a/components/storage_service/idf_component.yml +++ /dev/null @@ -1,3 +0,0 @@ -dependencies: - idf: ">=6.0.0,<6.1.0" - joltwallet/littlefs: "~=1.22.3" diff --git a/dependencies.lock b/dependencies.lock index f8b83b4..0b0f023 100644 --- a/dependencies.lock +++ b/dependencies.lock @@ -3,19 +3,6 @@ dependencies: source: type: idf version: 6.0.2 - joltwallet/littlefs: - component_hash: 3af20a3d75c49db9dc2286fd50862c34055c9f578419ad1f2bf7ed3ed01391fe - dependencies: - - name: idf - require: private - version: '>=5.0' - source: - registry_url: https://components.espressif.com/ - type: service - version: 1.22.3 -direct_dependencies: -- idf -- joltwallet/littlefs -manifest_hash: 25f711fa39d438b5d864dd7aeb4896a3f989485a893f69e56fc846156a31272a +manifest_hash: d52a0103e27a79c6636ba44efeb692dc7d97512e8deb6cddb52bf3f7f29847f2 target: esp32s3 version: 3.0.0 diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 2a15157..d362681 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,9 +1,4 @@ idf_component_register(SRCS "main.cc" - INCLUDE_DIRS "." - PRIV_REQUIRES - app_framework - startup_ui - display_service - network_service - storage_service - ota_service) \ No newline at end of file + INCLUDE_DIRS ".") + +target_compile_options(${COMPONENT_LIB} PRIVATE -std=c++26) diff --git a/main/idf_component.yml b/main/idf_component.yml new file mode 100644 index 0000000..1493e4d --- /dev/null +++ b/main/idf_component.yml @@ -0,0 +1 @@ +version: "0.0.0" diff --git a/main/main.cc b/main/main.cc index 1c9173e..0ec7812 100644 --- a/main/main.cc +++ b/main/main.cc @@ -1,7 +1,7 @@ -// #include "application.hh" +// Product firmware is intentionally a no-op until the v4.2 architecture +// sign-off passes (_doc/requirements-v4.2.md GOV-004; _doc/development-plan.md D0: +// do not build product service skeletons to bypass the coding gate). extern "C" void app_main(void) { - // application app; - // app.run(); } diff --git a/partitions.csv b/partitions.csv index 526c9b1..32ce39d 100644 --- a/partitions.csv +++ b/partitions.csv @@ -1,8 +1,9 @@ # Name, Type, SubType, Offset, Size, Flags -nvs, data, nvs, 0x9000, 0x15000, +nvs, data, nvs, 0x9000, 0x14000, +nvs_keys, data, nvs_keys,0x1D000, 0x1000, encrypted otadata, data, ota, 0x1E000, 0x2000, coredump, data, coredump,0x20000, 0x20000, ota_0, app, ota_0, 0x40000, 0x500000, ota_1, app, ota_1, 0x540000, 0x500000, -plugin_fs, data, littlefs,0xA40000, 0x200000, -assets_fs, data, littlefs,0xC40000, 0x3C0000, +plugin_fs, data, littlefs,0xA40000, 0x4C0000, +system_fs, data, littlefs,0xF00000, 0x100000, diff --git a/sdkconfig.defaults b/sdkconfig.defaults index e249e52..606be45 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -1,5 +1,7 @@ CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y CONFIG_ESPTOOLPY_FLASHFREQ_80M=y +CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y +CONFIG_FREERTOS_HZ=1000 CONFIG_SPIRAM=y CONFIG_SPIRAM_MODE_OCT=y @@ -8,6 +10,9 @@ CONFIG_SPIRAM_SPEED_80M=y CONFIG_SPIRAM_USE_MALLOC=y # CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM is not set +# pthread uses TLS index 0 in ESP-IDF v6.0.2; index 1 is reserved for Frame. +CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=2 + CONFIG_PARTITION_TABLE_CUSTOM=y CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y