From 7bae86143791cfc79f8ac28bb0b215d04e2417ef Mon Sep 17 00:00:00 2001 From: ania-lain Date: Fri, 28 Aug 2026 16:47:38 +0800 Subject: [PATCH] =?UTF-8?q?#add:=20=E5=AE=8C=E6=88=90=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E7=9A=84=E9=A1=B9=E7=9B=AE=E7=BB=93=E6=9E=84=E6=90=AD=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .clangd | 2 + .devcontainer/Dockerfile | 13 +++ .devcontainer/devcontainer.json | 19 +++++ .gitignore | 84 ++++++++++++++++++++ .vscode/c_cpp_properties.json | 20 +++++ .vscode/launch.json | 10 +++ .vscode/settings.json | 33 ++++++++ CMakeLists.txt | 20 +++++ CMakePresets.json | 48 +++++++++++ components/app_framework/CMakeLists.txt | 5 ++ components/app_framework/application.cc | 45 +++++++++++ components/app_framework/application.hh | 18 +++++ components/app_framework/context.cc | 0 components/app_framework/context.hh | 12 +++ components/app_framework/loader.cc | 0 components/app_framework/loader.hh | 25 ++++++ components/display_service/CMakeLists.txt | 1 + components/network_service/CMakeLists.txt | 1 + components/ota_service/CMakeLists.txt | 1 + components/startup_ui/CMakeLists.txt | 1 + components/storage_service/CMakeLists.txt | 3 + components/storage_service/idf_component.yml | 3 + dependencies.lock | 21 +++++ main/CMakeLists.txt | 9 +++ main/main.cc | 7 ++ partitions.csv | 8 ++ sdkconfig.defaults | 17 ++++ sdkconfig.defaults.dev | 4 + sdkconfig.defaults.prod | 4 + 29 files changed, 434 insertions(+) create mode 100644 .clangd create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .gitignore create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 CMakeLists.txt create mode 100644 CMakePresets.json create mode 100644 components/app_framework/CMakeLists.txt create mode 100644 components/app_framework/application.cc create mode 100644 components/app_framework/application.hh create mode 100644 components/app_framework/context.cc create mode 100644 components/app_framework/context.hh create mode 100644 components/app_framework/loader.cc create mode 100644 components/app_framework/loader.hh create mode 100644 components/display_service/CMakeLists.txt create mode 100644 components/network_service/CMakeLists.txt create mode 100644 components/ota_service/CMakeLists.txt create mode 100644 components/startup_ui/CMakeLists.txt create mode 100644 components/storage_service/CMakeLists.txt create mode 100644 components/storage_service/idf_component.yml create mode 100644 dependencies.lock create mode 100644 main/CMakeLists.txt create mode 100644 main/main.cc create mode 100644 partitions.csv create mode 100644 sdkconfig.defaults create mode 100644 sdkconfig.defaults.dev create mode 100644 sdkconfig.defaults.prod diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..437f255 --- /dev/null +++ b/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + Remove: [-f*, -m*] diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..dafb8ad --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,13 @@ +ARG DOCKER_TAG=latest +FROM espressif/idf:${DOCKER_TAG} + +ENV LC_ALL=C.UTF-8 +ENV LANG=C.UTF-8 + +RUN apt-get update -y && apt-get install udev -y + +RUN echo "source /opt/esp/idf/export.sh > /dev/null 2>&1" >> ~/.bashrc + +ENTRYPOINT [ "/opt/esp/entrypoint.sh" ] + +CMD ["/bin/bash", "-c"] \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..246b79f --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,19 @@ +{ + "name": "ESP-IDF QEMU", + "build": { + "dockerfile": "Dockerfile" + }, + "customizations": { + "vscode": { + "settings": { + "terminal.integrated.defaultProfile.linux": "bash", + "idf.gitPath": "/usr/bin/git" + }, + "extensions": [ + "espressif.esp-idf-extension", + "espressif.esp-idf-web" + ] + } + }, + "runArgs": ["--privileged"] +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f7843f0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,84 @@ +# macOS +.DS_Store +.AppleDouble +.LSOverride + +# Directory metadata +.directory + +# Temporary files +*~ +*.swp +*.swo +*.bak +*.tmp + +# Log files +*.log + +# Build artifacts and directories +**/build/ +build/ +/.build/ +*.o +*.a +*.out +*.exe # For any host-side utilities compiled on Windows + +# ESP-IDF specific build outputs +*.bin +*.elf +*.map +flasher_args.json # Generated in build directory +sdkconfig.old +sdkconfig + +# ESP-IDF dependencies +# For older versions or manual component management +/components/.idf/ +**/components/.idf/ +# For modern ESP-IDF component manager +managed_components/ +# If ESP-IDF tools are installed/referenced locally to the project +.espressif/ + +# CMake generated files +CMakeCache.txt +CMakeFiles/ +cmake_install.cmake +install_manifest.txt +CTestTestfile.cmake + +# Python environment files +*.pyc +*.pyo +*.pyd +__pycache__/ +*.egg-info/ +dist/ + +# Virtual environment folders +venv/ +.venv/ +env/ + +# Language Servers +.clangd/ +.ccls-cache/ +compile_commands.json + +# Windows specific +Thumbs.db +ehthumbs.db +Desktop.ini + +# User-specific configuration files +/CMakeUserPresets.json +*.user +*.workspace # General workspace files, can be from various tools +*.suo # Visual Studio Solution User Options +*.sln.docstates # Visual Studio + +.build + +.cache \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..15a965c --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,20 @@ +{ + "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", + "compileCommands": "/home/lain/Projects/esp_study/esp_study/.build/dev/compile_commands.json", + "intelliSenseMode": "gcc-x86", + "includePath": [ + "${workspaceFolder}/**" + ], + "browse": { + "path": [ + "${workspaceFolder}" + ], + "limitSymbolsToIncludedHeaders": true + } + } + ], + "version": 4 +} diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..3694ae4 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,10 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "gdbtarget", + "request": "attach", + "name": "Eclipse CDT GDB Adapter" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..509c913 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,33 @@ +{ + "C_Cpp.intelliSenseEngine": "disabled", + "idf.extensionActivationMode": "always", + "cmake.configureOnOpen": false, + "cmake.configureOnEdit": false, + "cmake.automaticReconfigure": false, + "cmake.autoSelectActiveFolder": false, + "cmake.options.advanced": { + "build": { + "statusBarVisibility": "inherit", + "inheritDefault": "hidden" + }, + "launch": { + "statusBarVisibility": "inherit", + "inheritDefault": "hidden" + }, + "debug": { + "statusBarVisibility": "inherit", + "inheritDefault": "hidden" + } + }, + "idf.openOcdConfigs": [ + "board/esp32s3-builtin.cfg" + ], + "idf.port": "/dev/ttyACM0", + "idf.currentSetup": "/home/lain/.espressif/v6.0.2/esp-idf", + "clangd.path": "/home/lain/.espressif/tools/esp-clang/esp-20.1.1_20250829/esp-clang/bin/clangd", + "clangd.arguments": [ + "--background-index", + "--query-driver=**", + "--compile-commands-dir=/home/lain/Projects/esp_study/esp_study/.build/dev" + ] +} diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c8d5972 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.25) + +if(NOT DEFINED IDF_TARGET) + set(IDF_TARGET "esp32s3" CACHE STRING "ESP-IDF target") +endif() + +if(NOT DEFINED SDKCONFIG) + set(SDKCONFIG "${CMAKE_BINARY_DIR}/sdkconfig") +endif() + +if(NOT DEFINED SDKCONFIG_DEFAULTS) + set(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 diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..670c2a9 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,48 @@ +{ + "version": 3, + "cmakeMinimumRequired": { + "major": 3, + "minor": 25, + "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", + "cacheVariables": { + "SDKCONFIG_DEFAULTS": "${sourceDir}/sdkconfig.defaults;${sourceDir}/sdkconfig.defaults.dev" + } + }, + { + "name": "prod", + "inherits": "idf-base", + "displayName": "Production", + "description": "Production configuration", + "cacheVariables": { + "SDKCONFIG_DEFAULTS": "${sourceDir}/sdkconfig.defaults;${sourceDir}/sdkconfig.defaults.prod" + } + } + ], + "buildPresets": [ + { + "name": "dev", + "configurePreset": "dev" + }, + { + "name": "prod", + "configurePreset": "prod" + } + ] +} diff --git a/components/app_framework/CMakeLists.txt b/components/app_framework/CMakeLists.txt new file mode 100644 index 0000000..efcbd55 --- /dev/null +++ b/components/app_framework/CMakeLists.txt @@ -0,0 +1,5 @@ +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 new file mode 100644 index 0000000..aef3b73 --- /dev/null +++ b/components/app_framework/application.cc @@ -0,0 +1,45 @@ +#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 new file mode 100644 index 0000000..8aaff51 --- /dev/null +++ b/components/app_framework/application.hh @@ -0,0 +1,18 @@ +#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 new file mode 100644 index 0000000..e69de29 diff --git a/components/app_framework/context.hh b/components/app_framework/context.hh new file mode 100644 index 0000000..d79b80a --- /dev/null +++ b/components/app_framework/context.hh @@ -0,0 +1,12 @@ +#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 new file mode 100644 index 0000000..e69de29 diff --git a/components/app_framework/loader.hh b/components/app_framework/loader.hh new file mode 100644 index 0000000..94e6870 --- /dev/null +++ b/components/app_framework/loader.hh @@ -0,0 +1,25 @@ +#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 new file mode 100644 index 0000000..a96dced --- /dev/null +++ b/components/display_service/CMakeLists.txt @@ -0,0 +1 @@ +idf_component_register() diff --git a/components/network_service/CMakeLists.txt b/components/network_service/CMakeLists.txt new file mode 100644 index 0000000..a96dced --- /dev/null +++ b/components/network_service/CMakeLists.txt @@ -0,0 +1 @@ +idf_component_register() diff --git a/components/ota_service/CMakeLists.txt b/components/ota_service/CMakeLists.txt new file mode 100644 index 0000000..a96dced --- /dev/null +++ b/components/ota_service/CMakeLists.txt @@ -0,0 +1 @@ +idf_component_register() diff --git a/components/startup_ui/CMakeLists.txt b/components/startup_ui/CMakeLists.txt new file mode 100644 index 0000000..a96dced --- /dev/null +++ b/components/startup_ui/CMakeLists.txt @@ -0,0 +1 @@ +idf_component_register() diff --git a/components/storage_service/CMakeLists.txt b/components/storage_service/CMakeLists.txt new file mode 100644 index 0000000..27a2547 --- /dev/null +++ b/components/storage_service/CMakeLists.txt @@ -0,0 +1,3 @@ +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 new file mode 100644 index 0000000..86021f9 --- /dev/null +++ b/components/storage_service/idf_component.yml @@ -0,0 +1,3 @@ +dependencies: + idf: ">=6.0.0,<6.1.0" + joltwallet/littlefs: "~=1.22.3" diff --git a/dependencies.lock b/dependencies.lock new file mode 100644 index 0000000..f8b83b4 --- /dev/null +++ b/dependencies.lock @@ -0,0 +1,21 @@ +dependencies: + idf: + 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 +target: esp32s3 +version: 3.0.0 diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt new file mode 100644 index 0000000..2a15157 --- /dev/null +++ b/main/CMakeLists.txt @@ -0,0 +1,9 @@ +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 diff --git a/main/main.cc b/main/main.cc new file mode 100644 index 0000000..1c9173e --- /dev/null +++ b/main/main.cc @@ -0,0 +1,7 @@ +// #include "application.hh" + +extern "C" void app_main(void) +{ + // application app; + // app.run(); +} diff --git a/partitions.csv b/partitions.csv new file mode 100644 index 0000000..526c9b1 --- /dev/null +++ b/partitions.csv @@ -0,0 +1,8 @@ +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x15000, +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, diff --git a/sdkconfig.defaults b/sdkconfig.defaults new file mode 100644 index 0000000..e249e52 --- /dev/null +++ b/sdkconfig.defaults @@ -0,0 +1,17 @@ +CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y +CONFIG_ESPTOOLPY_FLASHFREQ_80M=y + +CONFIG_SPIRAM=y +CONFIG_SPIRAM_MODE_OCT=y +CONFIG_SPIRAM_TYPE_AUTO=y +CONFIG_SPIRAM_SPEED_80M=y +CONFIG_SPIRAM_USE_MALLOC=y +# CONFIG_FREERTOS_TASK_CREATE_ALLOW_EXT_MEM is not set + +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" +CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y + +CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH=y +CONFIG_ESP_COREDUMP_CHECK_BOOT=y +CONFIG_ESP_COREDUMP_STACK_SIZE=2048 diff --git a/sdkconfig.defaults.dev b/sdkconfig.defaults.dev new file mode 100644 index 0000000..082f50a --- /dev/null +++ b/sdkconfig.defaults.dev @@ -0,0 +1,4 @@ +CONFIG_ESPTOOLPY_FLASHMODE_DIO=y +CONFIG_COMPILER_OPTIMIZATION_DEBUG=y +CONFIG_LOG_DEFAULT_LEVEL_INFO=y +CONFIG_ESP_COREDUMP_LOGS=y diff --git a/sdkconfig.defaults.prod b/sdkconfig.defaults.prod new file mode 100644 index 0000000..7331bb2 --- /dev/null +++ b/sdkconfig.defaults.prod @@ -0,0 +1,4 @@ +CONFIG_ESPTOOLPY_FLASHMODE_QIO=y +CONFIG_COMPILER_OPTIMIZATION_PERF=y +CONFIG_LOG_DEFAULT_LEVEL_WARN=y +# CONFIG_ESP_COREDUMP_LOGS is not set