From c09a696b9bc73a0125ab6a67e17f6ce4647a29ff Mon Sep 17 00:00:00 2001 From: tobozo Date: Mon, 1 May 2023 13:14:37 +0200 Subject: [PATCH 01/13] bump version --- library.json | 8 +++++++- library.properties | 4 ++-- src/gitTagVersion.h | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/library.json b/library.json index 6198c8b6..d9567538 100644 --- a/library.json +++ b/library.json @@ -10,7 +10,13 @@ "type": "git", "url": "https://github.com/tobozo/M5Stack-SD-Updater.git" }, - "version": "1.2.4", + "dependencies": [ + { + "name": "ESP32-targz", + "version": ">=1.1.7" + } + ], + "version": "1.2.5", "framework": "arduino", "headers": "M5StackUpdater.h", "platforms": "espressif32" diff --git a/library.properties b/library.properties index a9392682..d1375101 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=M5Stack-SD-Updater -version=1.2.4 +version=1.2.5 author=tobozo maintainer=tobozo sentence=SD Card Loader for M5 Stack @@ -7,4 +7,4 @@ paragraph=Package your apps on an SD card and load them from a menu app, button category=Uncategorized url=https://github.com/tobozo/M5Stack-SD-Updater/ architectures=esp32 -depends=ArduinoJson +depends=ESP32-targz,ArduinoJson diff --git a/src/gitTagVersion.h b/src/gitTagVersion.h index 99b5f135..950dbcdb 100644 --- a/src/gitTagVersion.h +++ b/src/gitTagVersion.h @@ -1,6 +1,6 @@ #define SDU_VERSION_MAJOR 1 #define SDU_VERSION_MINOR 2 -#define SDU_VERSION_PATCH 4 +#define SDU_VERSION_PATCH 5 #define _SDU_STR(x) #x #define SDU_STR(x) _SDU_STR(x) // Macro to convert library version number into an integer From 66c1daf87ab09fb8abb39c145f6107833625cd8b Mon Sep 17 00:00:00 2001 From: tobozo Date: Mon, 1 May 2023 13:15:16 +0200 Subject: [PATCH 02/13] update pio cmd + add sdfat test --- .github/workflows/PlatformioBuild.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/PlatformioBuild.yml b/.github/workflows/PlatformioBuild.yml index a7a43d26..b6635b5a 100644 --- a/.github/workflows/PlatformioBuild.yml +++ b/.github/workflows/PlatformioBuild.yml @@ -64,6 +64,7 @@ jobs: - piocontext: m5stack-core2 - piocontext: m5unified - piocontext: s3box + - { platform-version: 2.0.8, piocontext: sdfat-test } fail-fast: false @@ -101,6 +102,6 @@ jobs: run: | cd ${{ env.PROJECT_DIR }} [[ "${{ env.BRANCH_NAME }}" == "master" ]] && rm dev_lib_deps.ini || echo "Develop!" && pio system prune -f - pio lib -e ${{ matrix.piocontext }}@${{ matrix.platform-version }} install --no-save file://$(realpath ../../../) + pio pkg install -e ${{ matrix.piocontext }}@${{ matrix.platform-version }} --no-save --library file://$(realpath ../../../) pio run -e ${{ matrix.piocontext }}@${{ matrix.platform-version }} From cbead27237c7d641d161f4e7ed90ea54b2695bd3 Mon Sep 17 00:00:00 2001 From: tobozo Date: Mon, 1 May 2023 13:15:37 +0200 Subject: [PATCH 03/13] fix for platformio + SdFat --- src/M5StackUpdater.hpp | 89 ++++--------------- ...at32fs_wrapper.h => sdfat32fs_wrapper.hpp} | 2 + src/misc/update_interface.hpp | 66 ++++++++++++++ 3 files changed, 84 insertions(+), 73 deletions(-) rename src/misc/{sdfat32fs_wrapper.h => sdfat32fs_wrapper.hpp} (99%) create mode 100644 src/misc/update_interface.hpp diff --git a/src/M5StackUpdater.hpp b/src/M5StackUpdater.hpp index 195c027d..cfba5ad8 100644 --- a/src/M5StackUpdater.hpp +++ b/src/M5StackUpdater.hpp @@ -124,96 +124,38 @@ #include #endif +#if __has_include() || defined _LIFFLEFS_H_ + // LittleFS is now part of esp32 package, the older, external version isn't supported + #warning "Older version of is unsupported and will be ignored" + #warning "Use builtin version with #include instead, if using platformio add LittleFS(esp32)@^2.0.0 to lib_deps" +#endif -#if defined SDU_ENABLE_GZ || defined _ESP_TGZ_H || __has_include() // _TGZ_FSFOOLS_ +#define SDU_HAS_FS (defined SDU_HAS_SD || defined SDU_HAS_SD_MMC || defined SDU_HAS_SPIFFS || defined SDU_HAS_LITTLEFS ) + +// call this directive before detecting/loading SdFat otherwise __has_include() directive will be unavailable +#if defined SDU_ENABLE_GZ || defined _ESP_TGZ_H || __has_include() #define SDU_HAS_TARGZ #pragma message "gzip and tar support detected!" #include - - using namespace SDUpdaterNS::UpdateInterfaceNS; - - #define F_Update GzUpdateClass::getInstance() - #define F_UpdateEnd() (mode_z ? F_Update.endgz() : F_Update.end()) - #define F_abort() if (mode_z) F_Update.abortgz(); else F_Update.abort() - #define F_writeStream(updateSource,updateSize) (mode_z ? F_Update.writeGzStream(updateSource,updateSize) : F_Update.writeStream(updateSource)) - #define F_canBegin( usize ) (mode_z ? F_Update.begingz(UPDATE_SIZE_UNKNOWN) : F_Update.begin(usize)) - #define F_end() (mode_z ? F_Update.endgz() : F_Update.end() ) - - namespace SDUpdaterNS - { - namespace ConfigManager - { - static UpdateInterfaceNS::UpdateManagerInterface_t Iface = - { - .begin=[](size_t s)->bool{ return F_canBegin(s); }, - .writeStream=[](Stream &data,size_t size)->size_t{ return F_writeStream(data, size); }, - .abort=[]() { F_abort(); }, - .end=[]()->bool{ return F_end(); }, - .isFinished=[]()->bool{ return F_Update.isFinished(); }, - .canRollBack=[]()->bool{ return F_Update.canRollBack(); }, - .rollBack=[]()->bool{ return F_Update.rollBack(); }, - .onProgress=[](UpdateClass::THandlerFunction_Progress fn){ F_Update.onProgress(fn); }, - .getError=[]()->uint8_t{ return F_Update.getError(); }, - .setBinName=[]( String& fileName, Stream* stream ) { - if( !fileName.endsWith(".gz") ) { - log_d("Not a gz file"); - return; - } - mode_z = stream->peek() == 0x1f; // magic zlib byte - log_d("compression: %s", mode_z ? "enabled" : "disabled" ); - } - }; - }; - }; - -#else - namespace SDUpdaterNS - { - namespace ConfigManager - { - static UpdateInterfaceNS::UpdateManagerInterface_t Iface = - { - .begin=[](size_t s)->bool{ return Update.begin(s); }, - .writeStream=[](Stream &data,size_t size)->size_t{ return Update.writeStream(data); }, - .abort=[]() { Update.abort(); }, - .end=[]()->bool{ return Update.end(); }, - .isFinished=[]()->bool{ return Update.isFinished(); }, - .canRollBack=[]()->bool{ return Update.canRollBack(); }, - .rollBack=[]()->bool{ return Update.rollBack(); }, - .onProgress=[](UpdateClass::THandlerFunction_Progress fn){ Update.onProgress(fn); }, - .getError=[]()->uint8_t{ return Update.getError(); }, - .setBinName=[](String&fileName, Stream* stream){ - if( fileName.endsWith(".gz") ) { - log_e("Gz file detected but gz support is disabled!"); - } - } - }; - }; - } -#endif - - -#if __has_include() || defined _LIFFLEFS_H_ - // LittleFS is now part of esp32 package, the older, external version isn't supported - #warning "Older version of is unsupported, use builtin version with #include instead, if using platformio add LittleFS(esp32)@^2.0.0 to lib_deps" #endif -#define SDU_HAS_FS (defined SDU_HAS_SD || defined SDU_HAS_SD_MMC || defined SDU_HAS_SPIFFS || defined SDU_HAS_LITTLEFS ) #if ! SDU_HAS_FS #define SDU_HAS_SD #if defined USE_SDFATFS #pragma message "SDUpdater will use SdFat" - #undef __has_include - #include - #define __has_include + #if !__has_include() + #warning "SdFat.h is not in the stack list, loading will be forced" + #endif + // WARNING: __has_include() directive is undef'd by SdFat library and platformio makes this global + #include "./misc/sdfat32fs_wrapper.hpp" + // do not use the directive __has_include() after this point #define SDU_SD_BEGIN SDU_SDFatBegin #else #pragma message "SDUpdater didn't detect any preselected filesystem, will use SD as default" #include #define SDU_SD_BEGIN(csPin) SD.begin(csPin) #endif - #endif @@ -321,6 +263,7 @@ #endif +#include "./misc/update_interface.hpp" #include "./ConfigManager/ConfigManager.hpp" #include "./SDUpdater/SDUpdater_Class.hpp" #include "./UI/common.hpp" diff --git a/src/misc/sdfat32fs_wrapper.h b/src/misc/sdfat32fs_wrapper.hpp similarity index 99% rename from src/misc/sdfat32fs_wrapper.h rename to src/misc/sdfat32fs_wrapper.hpp index 39f4f260..361689df 100644 --- a/src/misc/sdfat32fs_wrapper.h +++ b/src/misc/sdfat32fs_wrapper.hpp @@ -15,7 +15,9 @@ #include #include + #undef __has_include #include + #define __has_include // cfr https://en.cppreference.com/w/c/io/fopen + guesses inline oflag_t _convert_access_mode_to_flag(const char* mode, const bool create = false) diff --git a/src/misc/update_interface.hpp b/src/misc/update_interface.hpp new file mode 100644 index 00000000..138d96c0 --- /dev/null +++ b/src/misc/update_interface.hpp @@ -0,0 +1,66 @@ +#pragma once + + +#if defined SDU_HAS_TARGZ + + using namespace SDUpdaterNS::UpdateInterfaceNS; + + #define F_Update GzUpdateClass::getInstance() + #define F_UpdateEnd() (mode_z ? F_Update.endgz() : F_Update.end()) + #define F_abort() if (mode_z) F_Update.abortgz(); else F_Update.abort() + #define F_writeStream(updateSource,updateSize) (mode_z ? F_Update.writeGzStream(updateSource,updateSize) : F_Update.writeStream(updateSource)) + #define F_canBegin( usize ) (mode_z ? F_Update.begingz(UPDATE_SIZE_UNKNOWN) : F_Update.begin(usize)) + #define F_end() (mode_z ? F_Update.endgz() : F_Update.end() ) + + namespace SDUpdaterNS + { + namespace ConfigManager + { + static UpdateInterfaceNS::UpdateManagerInterface_t Iface = + { + .begin=[](size_t s)->bool{ return F_canBegin(s); }, + .writeStream=[](Stream &data,size_t size)->size_t{ return F_writeStream(data, size); }, + .abort=[]() { F_abort(); }, + .end=[]()->bool{ return F_end(); }, + .isFinished=[]()->bool{ return F_Update.isFinished(); }, + .canRollBack=[]()->bool{ return F_Update.canRollBack(); }, + .rollBack=[]()->bool{ return F_Update.rollBack(); }, + .onProgress=[](UpdateClass::THandlerFunction_Progress fn){ F_Update.onProgress(fn); }, + .getError=[]()->uint8_t{ return F_Update.getError(); }, + .setBinName=[]( String& fileName, Stream* stream ) { + if( !fileName.endsWith(".gz") ) { + log_d("Not a gz file"); + return; + } + mode_z = stream->peek() == 0x1f; // magic zlib byte + log_d("compression: %s", mode_z ? "enabled" : "disabled" ); + } + }; + }; + }; + +#else + namespace SDUpdaterNS + { + namespace ConfigManager + { + static UpdateInterfaceNS::UpdateManagerInterface_t Iface = + { + .begin=[](size_t s)->bool{ return Update.begin(s); }, + .writeStream=[](Stream &data,size_t size)->size_t{ return Update.writeStream(data); }, + .abort=[]() { Update.abort(); }, + .end=[]()->bool{ return Update.end(); }, + .isFinished=[]()->bool{ return Update.isFinished(); }, + .canRollBack=[]()->bool{ return Update.canRollBack(); }, + .rollBack=[]()->bool{ return Update.rollBack(); }, + .onProgress=[](UpdateClass::THandlerFunction_Progress fn){ Update.onProgress(fn); }, + .getError=[]()->uint8_t{ return Update.getError(); }, + .setBinName=[](String&fileName, Stream* stream){ + if( fileName.endsWith(".gz") ) { + log_e("Gz file detected but gz support is disabled!"); + } + } + }; + }; + } +#endif From 24c2aaf89cf9ba93197b94d3e0032deaaebcda38 Mon Sep 17 00:00:00 2001 From: tobozo Date: Mon, 1 May 2023 13:15:53 +0200 Subject: [PATCH 04/13] Added gzipped firmware support --- examples/Headless/Headless.ino | 3 +- .../LGFX-SDLoader-Snippet.ino | 1 + .../M5Core2-SDLoader-Snippet.ino | 1 + .../M5Stack-LittleFS-Snippet.ino | 2 +- examples/M5Stack-SD-Menu/core.h | 2 +- .../M5Stack-SDLoader-Snippet.ino | 1 + .../M5StickC-SPIFFS-Loader-Snippet.ino | 1 + examples/M5Unified/M5Unified.ino | 3 +- examples/SdFatUpdater/SdFatUpdater.ino | 2 + examples/Test/build_test/dev_lib_deps.ini | 2 +- examples/Test/build_test/main/main.cpp | 45 ++++++++++++------- examples/Test/build_test/platformio.ini | 30 ++++++++++++- 12 files changed, 69 insertions(+), 24 deletions(-) diff --git a/examples/Headless/Headless.ino b/examples/Headless/Headless.ino index d68bcfe1..edaffcb9 100644 --- a/examples/Headless/Headless.ino +++ b/examples/Headless/Headless.ino @@ -1,8 +1,9 @@ #define SDU_APP_NAME "Headless Example" #define SDU_APP_PATH "/Headless_Example.bin" -#define SDU_HEADLESS // don't load gfx clutter (but implement my own action trigger) +#define SDU_NO_AUTODETECT // don't load gfx clutter (but implement my own action trigger) #define TFCARD_CS_PIN 4 // this is needed by SD.begin() #include // /!\ headless mode skips autodetect and may require to include the filesystem library **before** the M5StackUpdater library +#include // optional: https://github.com/tobozo/ESP32-targz #include diff --git a/examples/LGFX-SDLoader-Snippet/LGFX-SDLoader-Snippet.ino b/examples/LGFX-SDLoader-Snippet/LGFX-SDLoader-Snippet.ino index ec6cea7d..37fcdce3 100644 --- a/examples/LGFX-SDLoader-Snippet/LGFX-SDLoader-Snippet.ino +++ b/examples/LGFX-SDLoader-Snippet/LGFX-SDLoader-Snippet.ino @@ -41,6 +41,7 @@ static LGFX tft; // #define _MOSI 3 #define SDU_APP_NAME "LGFX Loader Snippet" +#include // optional: https://github.com/tobozo/ESP32-targz #include diff --git a/examples/M5Core2-SDLoader-Snippet/M5Core2-SDLoader-Snippet.ino b/examples/M5Core2-SDLoader-Snippet/M5Core2-SDLoader-Snippet.ino index 48642e34..f6a1c192 100644 --- a/examples/M5Core2-SDLoader-Snippet/M5Core2-SDLoader-Snippet.ino +++ b/examples/M5Core2-SDLoader-Snippet/M5Core2-SDLoader-Snippet.ino @@ -2,6 +2,7 @@ #include #define SDU_APP_NAME "M5Core2 SDLoader Snippet" +#include // optional: https://github.com/tobozo/ESP32-targz #include void setup() diff --git a/examples/M5Stack-LittleFS-Snippet/M5Stack-LittleFS-Snippet.ino b/examples/M5Stack-LittleFS-Snippet/M5Stack-LittleFS-Snippet.ino index 0b063805..06aaa152 100644 --- a/examples/M5Stack-LittleFS-Snippet/M5Stack-LittleFS-Snippet.ino +++ b/examples/M5Stack-LittleFS-Snippet/M5Stack-LittleFS-Snippet.ino @@ -41,7 +41,7 @@ */ #include #include - +#include // optional: https://github.com/tobozo/ESP32-targz #define SDU_APP_NAME "M5Stack SDLoader Snippet" #define SDU_APP_PATH "/MY_SKETCH.bin" diff --git a/examples/M5Stack-SD-Menu/core.h b/examples/M5Stack-SD-Menu/core.h index c9e7ea3c..83fe7f19 100644 --- a/examples/M5Stack-SD-Menu/core.h +++ b/examples/M5Stack-SD-Menu/core.h @@ -2,7 +2,7 @@ #include #include // use LGFX display autodetect -#include // support gzipped applications +#include // optional: https://github.com/tobozo/ESP32-targz #define SDU_APP_NAME "Application Launcher" #include // https://github.com/tobozo/M5Stack-SD-Updater diff --git a/examples/M5Stack-SDLoader-Snippet/M5Stack-SDLoader-Snippet.ino b/examples/M5Stack-SDLoader-Snippet/M5Stack-SDLoader-Snippet.ino index 7f7fce90..34648f70 100644 --- a/examples/M5Stack-SDLoader-Snippet/M5Stack-SDLoader-Snippet.ino +++ b/examples/M5Stack-SDLoader-Snippet/M5Stack-SDLoader-Snippet.ino @@ -51,6 +51,7 @@ #include // any other ESP32 device with SD #endif */ +#include // optional: https://github.com/tobozo/ESP32-targz #include //#include // #define SDU_HEADLESS diff --git a/examples/M5StickC-SPIFFS-Loader-Snippet/M5StickC-SPIFFS-Loader-Snippet.ino b/examples/M5StickC-SPIFFS-Loader-Snippet/M5StickC-SPIFFS-Loader-Snippet.ino index 487cea2f..944b49ad 100644 --- a/examples/M5StickC-SPIFFS-Loader-Snippet/M5StickC-SPIFFS-Loader-Snippet.ino +++ b/examples/M5StickC-SPIFFS-Loader-Snippet/M5StickC-SPIFFS-Loader-Snippet.ino @@ -39,6 +39,7 @@ * flash back the menu.bin into memory. * */ +#include // optional: https://github.com/tobozo/ESP32-targz #include #include diff --git a/examples/M5Unified/M5Unified.ino b/examples/M5Unified/M5Unified.ino index 19f51235..ec4083a8 100644 --- a/examples/M5Unified/M5Unified.ino +++ b/examples/M5Unified/M5Unified.ino @@ -1,7 +1,8 @@ + #include #include //#define TFCARD_CS_PIN 4 -#define SDUPDATER_AUTODETECT +#include // optional: https://github.com/tobozo/ESP32-targz #include void setup(void) diff --git a/examples/SdFatUpdater/SdFatUpdater.ino b/examples/SdFatUpdater/SdFatUpdater.ino index d8f48414..5af60d6c 100644 --- a/examples/SdFatUpdater/SdFatUpdater.ino +++ b/examples/SdFatUpdater/SdFatUpdater.ino @@ -1,5 +1,7 @@ #define TFCARD_CS_PIN 4 // customize this + +#include // optional gzipped firmware support -> https://github.com/tobozo/ESP32-targz #include // /!\ When using SdFat, always include LGFX/M5GFX *before* M5StackUpdater.h to prevent problems with macros #define SDU_NO_AUTODETECT // Disable SDUpdater autodetect: this prevents to be auto-selected, however it also disables board detection diff --git a/examples/Test/build_test/dev_lib_deps.ini b/examples/Test/build_test/dev_lib_deps.ini index 866e4978..7ef8f70f 100644 --- a/examples/Test/build_test/dev_lib_deps.ini +++ b/examples/Test/build_test/dev_lib_deps.ini @@ -1,7 +1,7 @@ [lib_sdupdater] lib_deps = M5Stack-SD-Updater - tobozo/ESP32-targz + ESP32-targz [lib_lgfx] lib_deps = diff --git a/examples/Test/build_test/main/main.cpp b/examples/Test/build_test/main/main.cpp index bb80b0fe..7e3bc862 100644 --- a/examples/Test/build_test/main/main.cpp +++ b/examples/Test/build_test/main/main.cpp @@ -1,32 +1,43 @@ -#include // wtf platformio -#include -#if defined TEST_LGFX +#if defined __cplusplus - #include // WTF platformio lib_dep manager fails to resolve this ??? - #include "../../../LGFX-SDLoader-Snippet/LGFX-SDLoader-Snippet.ino" +#include // platformio whines about missing definition for 'size_t' 🤦 -#elif defined TEST_M5Core2 +//#include // wtf platformio +//#include - #include "../../../M5Core2-SDLoader-Snippet/M5Core2-SDLoader-Snippet.ino" + #if defined TEST_LGFX -#elif defined TEST_M5Stack || defined TEST_S3Box + //#include // WTF platformio lib_dep manager fails to resolve this ??? + #include "../../../LGFX-SDLoader-Snippet/LGFX-SDLoader-Snippet.ino" - #include "../../../M5Stack-SDLoader-Snippet/M5Stack-SDLoader-Snippet.ino" + #elif defined TEST_M5Core2 -#elif defined TEST_M5StickC + #include "../../../M5Core2-SDLoader-Snippet/M5Core2-SDLoader-Snippet.ino" - #include "../../../M5StickC-SPIFFS-Loader-Snippet/M5StickC-SPIFFS-Loader-Snippet.ino" + #elif defined TEST_M5Stack || defined TEST_S3Box -#elif defined TEST_M5Unified + #include "../../../M5Stack-SDLoader-Snippet/M5Stack-SDLoader-Snippet.ino" - #include // WTF platformio lib_dep manager fails to resolve this ??? - #include "../../../M5Unified/M5Unified.ino" + #elif defined TEST_M5StickC -#else + #include "../../../M5StickC-SPIFFS-Loader-Snippet/M5StickC-SPIFFS-Loader-Snippet.ino" - #error "No device to test" + #elif defined TEST_M5Unified -#endif + //#include // WTF platformio lib_dep manager fails to resolve this ??? + #include "../../../M5Unified/M5Unified.ino" + + #elif defined TEST_SdFat + + #include "../../../SdFatUpdater/SdFatUpdater.ino" + + #else + #error "No device to test" + + #endif + + +#endif diff --git a/examples/Test/build_test/platformio.ini b/examples/Test/build_test/platformio.ini index 9f726972..4007aedb 100644 --- a/examples/Test/build_test/platformio.ini +++ b/examples/Test/build_test/platformio.ini @@ -47,8 +47,8 @@ platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/ [lib_sdupdater] lib_deps = - M5Stack-SD-Updater - tobozo/ESP32-targz +; M5Stack-SD-Updater +; ESP32-targz [lib_lgfx] lib_deps = @@ -89,6 +89,12 @@ lib_deps = M5GFX Button2 +[lib_sdfatupdater] +lib_deps = + SdFat + ${lib_sdupdater.lib_deps} + ${lib_m5unified.lib_deps} + [lgfx] extends = lib_lgfx @@ -113,6 +119,12 @@ build_flags = -DTEST_M5Core2 extends = lib_m5unified build_flags = -DTEST_M5Unified +[M5Unifier-SdFat] +; board = esp32dev +; extends = lib_sdfatupdater +; build_flags = -DTEST_SdFat + + [S3Box] extends = lib_chimeracore board = esp32dev @@ -139,6 +151,20 @@ build_flags = [env:lgfx] [env:s3box] [env:m5stack-atom] +[env:sdfat-test] + + +[env:sdfat-test2@2.0.8] +board = esp32dev +lib_deps = + SdFat + M5Unified + M5Stack-SD-Updater + ESP32-targz +build_flags = -DTEST_SdFat + +extends = platform_default, M5Unifier-SdFat + ; [env:m5stack-atom@2.0.5] ; extends = esp32_2_0_5, M5Stack From 8ac72d14e5f555ee62ad97abae18413a628ead6c Mon Sep 17 00:00:00 2001 From: tobozo Date: Mon, 1 May 2023 13:42:42 +0200 Subject: [PATCH 05/13] misc CI fixes --- .github/workflows/ArduinoBuild.yml | 12 ++++++------ examples/Test/build_test/dev_lib_deps.ini | 8 +++++++- examples/Test/build_test/platformio.ini | 19 ++++++++++--------- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ArduinoBuild.yml b/.github/workflows/ArduinoBuild.yml index fa7cb0f0..860d38c1 100644 --- a/.github/workflows/ArduinoBuild.yml +++ b/.github/workflows/ArduinoBuild.yml @@ -84,26 +84,26 @@ jobs: sketch-names: M5Stack-SD-Menu.ino,AppStore.ino launcher-name: M5stack-Launcher appstore-name: M5stack-AppStore - required-libraries: "ESP32-Chimera-Core,LovyanGFX,ArduinoJson,ESP32-targz" + required-libraries: "ESP32-Chimera-Core,LovyanGFX,ArduinoJson" - matrix-context: M5Core2 arduino-board: m5stack-core2 sketch-names: M5Stack-SD-Menu.ino,AppStore.ino launcher-name: M5Core2-Launcher appstore-name: M5Core2-AppStore - required-libraries: "ESP32-Chimera-Core,LovyanGFX,ArduinoJson,ESP32-targz" + required-libraries: "ESP32-Chimera-Core,LovyanGFX,ArduinoJson" - matrix-context: M5Fire arduino-board: m5stack-fire sketch-names: M5Stack-SD-Menu.ino,AppStore.ino launcher-name: M5Fire-Launcher appstore-name: M5Fire-AppStore - required-libraries: "ESP32-Chimera-Core,LovyanGFX,ArduinoJson,ESP32-targz" + required-libraries: "ESP32-Chimera-Core,LovyanGFX,ArduinoJson" - matrix-context: OdroidGo arduino-board: odroid_esp32 sketch-names: M5Stack-SD-Menu.ino,AppStore.ino launcher-name: OdroidGo-Launcher appstore-name: OdroidGo-AppStore extra-fqbn: ":PartitionScheme=min_spiffs" - required-libraries: "ESP32-Chimera-Core,LovyanGFX,ArduinoJson,ESP32-targz,Button2" + required-libraries: "ESP32-Chimera-Core,LovyanGFX,ArduinoJson,Button2" #- matrix-context: TTGO-LoRa32-V2-test #arduino-board: ttgo-lora32-v2 #sketch-names: TTGO-test.ino @@ -113,7 +113,7 @@ jobs: arduino-board: m5stack-atom sketch-names: M5Stack-SD-Menu.ino launcher-name: M5Atom-Launcher - required-libraries: "ESP32-Chimera-Core,LovyanGFX,ArduinoJson,ESP32-targz,Button2" + required-libraries: "ESP32-Chimera-Core,LovyanGFX,ArduinoJson,Button2" fail-fast: false @@ -129,7 +129,7 @@ jobs: #platform-url: ${{ matrix.platform-url }} arduino-board-fqbn: esp32:esp32:${{ matrix.arduino-board}}${{ matrix.extra-fqbn }} arduino-platform: esp32:esp32@${{ matrix.sdk-version }} - required-libraries: ${{ matrix.required-libraries }} + required-libraries: ESP32-targz,${{ matrix.required-libraries }} extra-arduino-lib-install-args: --no-deps # extra-arduino-cli-args: ${{ matrix.extra-arduino-cli-args }} extra-arduino-cli-args: "--warnings default " # see https://github.com/ArminJo/arduino-test-compile/issues/28 diff --git a/examples/Test/build_test/dev_lib_deps.ini b/examples/Test/build_test/dev_lib_deps.ini index 7ef8f70f..db89a92f 100644 --- a/examples/Test/build_test/dev_lib_deps.ini +++ b/examples/Test/build_test/dev_lib_deps.ini @@ -1,12 +1,18 @@ [lib_sdupdater] lib_deps = M5Stack-SD-Updater - ESP32-targz + ESP32-targz@^1.1.7 [lib_lgfx] lib_deps = + SD git+https://github.com/lovyan03/LovyanGFX#develop ${lib_sdupdater.lib_deps} +build_flags = + ${env.build_flags} + -D LGFX_AUTODETECT + -D LGFX_USE_V1 +lib_ldf_mode = deep [lib_chimeracore] lib_deps = diff --git a/examples/Test/build_test/platformio.ini b/examples/Test/build_test/platformio.ini index 4007aedb..6782d0a2 100644 --- a/examples/Test/build_test/platformio.ini +++ b/examples/Test/build_test/platformio.ini @@ -47,13 +47,13 @@ platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/ [lib_sdupdater] lib_deps = -; M5Stack-SD-Updater -; ESP32-targz + M5Stack-SD-Updater + ESP32-targz@^1.1.7 [lib_lgfx] lib_deps = - SPI(esp32) - SD(esp32) + SPI + SD ${lib_sdupdater.lib_deps} LovyanGFX build_flags = @@ -70,6 +70,7 @@ lib_deps = [lib_m5unified] lib_deps = + SD ${lib_sdupdater.lib_deps} M5Unified @@ -92,8 +93,8 @@ lib_deps = [lib_sdfatupdater] lib_deps = SdFat + M5Unified ${lib_sdupdater.lib_deps} - ${lib_m5unified.lib_deps} [lgfx] @@ -120,9 +121,9 @@ extends = lib_m5unified build_flags = -DTEST_M5Unified [M5Unifier-SdFat] -; board = esp32dev -; extends = lib_sdfatupdater -; build_flags = -DTEST_SdFat +board = esp32dev +extends = lib_sdfatupdater +build_flags = -DTEST_SdFat [S3Box] @@ -160,7 +161,7 @@ lib_deps = SdFat M5Unified M5Stack-SD-Updater - ESP32-targz + https://github.com/tobozo/ESP32-targz.git#1.1.8 build_flags = -DTEST_SdFat extends = platform_default, M5Unifier-SdFat From 54922426f80c3510a9221aaa4be1a5157bced427 Mon Sep 17 00:00:00 2001 From: tobozo Date: Mon, 1 May 2023 13:52:39 +0200 Subject: [PATCH 06/13] misc CI fixes --- examples/Test/build_test/dev_lib_deps.ini | 1 + examples/Test/build_test/platformio.ini | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/Test/build_test/dev_lib_deps.ini b/examples/Test/build_test/dev_lib_deps.ini index db89a92f..da07dcec 100644 --- a/examples/Test/build_test/dev_lib_deps.ini +++ b/examples/Test/build_test/dev_lib_deps.ini @@ -22,6 +22,7 @@ lib_deps = [lib_m5unified] lib_deps = + SD git+https://github.com/M5Stack/M5GFX#develop git+https://github.com/M5Stack/M5Unified#develop ${lib_sdupdater.lib_deps} diff --git a/examples/Test/build_test/platformio.ini b/examples/Test/build_test/platformio.ini index 6782d0a2..4c1c218c 100644 --- a/examples/Test/build_test/platformio.ini +++ b/examples/Test/build_test/platformio.ini @@ -164,7 +164,7 @@ lib_deps = https://github.com/tobozo/ESP32-targz.git#1.1.8 build_flags = -DTEST_SdFat -extends = platform_default, M5Unifier-SdFat +extends = esp32_2_0_8, M5Unifier-SdFat ; [env:m5stack-atom@2.0.5] From 66d97a6e7b4e62c847b6fe3611b8a06e16cf346e Mon Sep 17 00:00:00 2001 From: tobozo Date: Mon, 1 May 2023 14:04:42 +0200 Subject: [PATCH 07/13] misc CI fixes --- examples/SdFatUpdater/SdFatUpdater.ino | 2 +- src/M5StackUpdater.hpp | 11 +++++++---- src/misc/sdfat32fs_wrapper.hpp | 6 ------ 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/examples/SdFatUpdater/SdFatUpdater.ino b/examples/SdFatUpdater/SdFatUpdater.ino index 5af60d6c..07f631ab 100644 --- a/examples/SdFatUpdater/SdFatUpdater.ino +++ b/examples/SdFatUpdater/SdFatUpdater.ino @@ -18,7 +18,7 @@ #define SDU_HAS_TOUCH #endif - +//#include // not necessary when `USE_SDFATFS` is defined #include SdFs sd; diff --git a/src/M5StackUpdater.hpp b/src/M5StackUpdater.hpp index cfba5ad8..61bbc037 100644 --- a/src/M5StackUpdater.hpp +++ b/src/M5StackUpdater.hpp @@ -144,12 +144,15 @@ #define SDU_HAS_SD #if defined USE_SDFATFS #pragma message "SDUpdater will use SdFat" - #if !__has_include() - #warning "SdFat.h is not in the stack list, loading will be forced" - #endif + #warning "SdFat.h is not in the stack list, loading will be forced" + #undef __has_include + #include + #include + #include + #define __has_include // WARNING: __has_include() directive is undef'd by SdFat library and platformio makes this global #include "./misc/sdfat32fs_wrapper.hpp" - // do not use the directive __has_include() after this point + // do not use the directive __has_include() below this point #define SDU_SD_BEGIN SDU_SDFatBegin #else #pragma message "SDUpdater didn't detect any preselected filesystem, will use SD as default" diff --git a/src/misc/sdfat32fs_wrapper.hpp b/src/misc/sdfat32fs_wrapper.hpp index 361689df..0cc75292 100644 --- a/src/misc/sdfat32fs_wrapper.hpp +++ b/src/misc/sdfat32fs_wrapper.hpp @@ -13,12 +13,6 @@ #error "SD Updater only supports SdFs" #endif - #include - #include - #undef __has_include - #include - #define __has_include - // cfr https://en.cppreference.com/w/c/io/fopen + guesses inline oflag_t _convert_access_mode_to_flag(const char* mode, const bool create = false) { From 9af3ca820f591db5460346e8b37cdb8996b30d0c Mon Sep 17 00:00:00 2001 From: tobozo Date: Mon, 1 May 2023 14:16:23 +0200 Subject: [PATCH 08/13] misc CI fixes --- examples/Test/build_test/dev_lib_deps.ini | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/Test/build_test/dev_lib_deps.ini b/examples/Test/build_test/dev_lib_deps.ini index da07dcec..4b0298b0 100644 --- a/examples/Test/build_test/dev_lib_deps.ini +++ b/examples/Test/build_test/dev_lib_deps.ini @@ -36,3 +36,10 @@ lib_deps = lib_deps = M5StickC ${lib_sdupdater.lib_deps} + + +[lib_sdfatupdater] +lib_deps = + SdFat + M5Unified + ${lib_sdupdater.lib_deps} From f8ba1a56e711916c28a0313de0b1a2113297c169 Mon Sep 17 00:00:00 2001 From: tobozo Date: Mon, 1 May 2023 14:23:11 +0200 Subject: [PATCH 09/13] misc CI fixes --- examples/Test/build_test/platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Test/build_test/platformio.ini b/examples/Test/build_test/platformio.ini index 4c1c218c..5024c743 100644 --- a/examples/Test/build_test/platformio.ini +++ b/examples/Test/build_test/platformio.ini @@ -155,7 +155,7 @@ build_flags = [env:sdfat-test] -[env:sdfat-test2@2.0.8] +[env:sdfat-test@2.0.8] board = esp32dev lib_deps = SdFat From d8dc4ec6281f9ed592ec8bd138a603b2912e34b8 Mon Sep 17 00:00:00 2001 From: tobozo Date: Tue, 2 May 2023 19:07:15 +0200 Subject: [PATCH 10/13] platformio test with preserved __has_include --- examples/Test/build_test/dev_lib_deps.ini | 2 +- examples/Test/build_test/main/main.cpp | 55 +++++++---------------- examples/Test/build_test/platformio.ini | 4 +- src/M5StackUpdater.hpp | 12 +++-- src/misc/types.h | 6 +-- 5 files changed, 31 insertions(+), 48 deletions(-) diff --git a/examples/Test/build_test/dev_lib_deps.ini b/examples/Test/build_test/dev_lib_deps.ini index 4b0298b0..58b1677d 100644 --- a/examples/Test/build_test/dev_lib_deps.ini +++ b/examples/Test/build_test/dev_lib_deps.ini @@ -1,7 +1,7 @@ [lib_sdupdater] lib_deps = M5Stack-SD-Updater - ESP32-targz@^1.1.7 + ESP32-targz [lib_lgfx] lib_deps = diff --git a/examples/Test/build_test/main/main.cpp b/examples/Test/build_test/main/main.cpp index 7e3bc862..e7921a7a 100644 --- a/examples/Test/build_test/main/main.cpp +++ b/examples/Test/build_test/main/main.cpp @@ -1,43 +1,22 @@ -#if defined __cplusplus -#include // platformio whines about missing definition for 'size_t' 🤦 - -//#include // wtf platformio -//#include - - #if defined TEST_LGFX - - //#include // WTF platformio lib_dep manager fails to resolve this ??? - #include "../../../LGFX-SDLoader-Snippet/LGFX-SDLoader-Snippet.ino" - - #elif defined TEST_M5Core2 - - #include "../../../M5Core2-SDLoader-Snippet/M5Core2-SDLoader-Snippet.ino" - - #elif defined TEST_M5Stack || defined TEST_S3Box - - #include "../../../M5Stack-SDLoader-Snippet/M5Stack-SDLoader-Snippet.ino" - - #elif defined TEST_M5StickC - - #include "../../../M5StickC-SPIFFS-Loader-Snippet/M5StickC-SPIFFS-Loader-Snippet.ino" - - #elif defined TEST_M5Unified - - //#include // WTF platformio lib_dep manager fails to resolve this ??? - #include "../../../M5Unified/M5Unified.ino" - - #elif defined TEST_SdFat - - #include "../../../SdFatUpdater/SdFatUpdater.ino" - - #else - - #error "No device to test" - - #endif +//#include + +#if defined TEST_LGFX + #include "../../../LGFX-SDLoader-Snippet/LGFX-SDLoader-Snippet.ino" +#elif defined TEST_M5Core2 + #include "../../../M5Core2-SDLoader-Snippet/M5Core2-SDLoader-Snippet.ino" +#elif defined TEST_M5Stack || defined TEST_S3Box + #include "../../../M5Stack-SDLoader-Snippet/M5Stack-SDLoader-Snippet.ino" +#elif defined TEST_M5StickC + #include "../../../M5StickC-SPIFFS-Loader-Snippet/M5StickC-SPIFFS-Loader-Snippet.ino" +#elif defined TEST_M5Unified + #include "../../../M5Unified/M5Unified.ino" +#elif defined TEST_SdFat + #include "../../../SdFatUpdater/SdFatUpdater.ino" +#else + #error "No device to test" +#endif -#endif diff --git a/examples/Test/build_test/platformio.ini b/examples/Test/build_test/platformio.ini index 5024c743..d0ffb254 100644 --- a/examples/Test/build_test/platformio.ini +++ b/examples/Test/build_test/platformio.ini @@ -48,7 +48,7 @@ platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/ [lib_sdupdater] lib_deps = M5Stack-SD-Updater - ESP32-targz@^1.1.7 + ESP32-targz [lib_lgfx] lib_deps = @@ -161,7 +161,7 @@ lib_deps = SdFat M5Unified M5Stack-SD-Updater - https://github.com/tobozo/ESP32-targz.git#1.1.8 + ESP32-targz@^1.1.8 build_flags = -DTEST_SdFat extends = esp32_2_0_8, M5Unifier-SdFat diff --git a/src/M5StackUpdater.hpp b/src/M5StackUpdater.hpp index 61bbc037..0fe22aba 100644 --- a/src/M5StackUpdater.hpp +++ b/src/M5StackUpdater.hpp @@ -130,7 +130,11 @@ #warning "Use builtin version with #include instead, if using platformio add LittleFS(esp32)@^2.0.0 to lib_deps" #endif -#define SDU_HAS_FS (defined SDU_HAS_SD || defined SDU_HAS_SD_MMC || defined SDU_HAS_SPIFFS || defined SDU_HAS_LITTLEFS ) +#if defined SDU_HAS_SD || defined SDU_HAS_SD_MMC || defined SDU_HAS_SPIFFS || defined SDU_HAS_LITTLEFS + #define SDU_HAS_FS 1 +#else + #define SDU_HAS_FS 0 +#endif // call this directive before detecting/loading SdFat otherwise __has_include() directive will be unavailable #if defined SDU_ENABLE_GZ || defined _ESP_TGZ_H || __has_include() @@ -140,16 +144,16 @@ #endif -#if ! SDU_HAS_FS +#if SDU_HAS_FS==0 #define SDU_HAS_SD #if defined USE_SDFATFS #pragma message "SDUpdater will use SdFat" #warning "SdFat.h is not in the stack list, loading will be forced" - #undef __has_include + //#undef __has_include #include #include #include - #define __has_include + //#define __has_include // WARNING: __has_include() directive is undef'd by SdFat library and platformio makes this global #include "./misc/sdfat32fs_wrapper.hpp" // do not use the directive __has_include() below this point diff --git a/src/misc/types.h b/src/misc/types.h index 69545a31..d17bf578 100644 --- a/src/misc/types.h +++ b/src/misc/types.h @@ -5,9 +5,11 @@ #include #include -#define FN_LAMBDA_VOID(x) []() { x; } +#define FN_LAMBDA_VOID(x) []() { } #define FN_LAMBDA_BOOL(x) []() -> bool { return x; } #define FB_LAMBDA_FALSE []() -> bool { return false; } +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-variable" namespace SDUpdaterNS @@ -45,8 +47,6 @@ namespace SDUpdaterNS }; - - namespace TriggerSource { From 07ceed3b2cab69526f0a476170ecb7da2e6927c7 Mon Sep 17 00:00:00 2001 From: tobozo Date: Wed, 3 May 2023 14:25:26 +0200 Subject: [PATCH 11/13] experimenting with macros (see #180 and #179) --- examples/SdFatUpdater/SdFatUpdater.ino | 45 +++++++-- src/M5StackUpdater.hpp | 127 ++++++++++++------------- src/SDUpdater/SDUpdater_Class.cpp | 2 +- src/SDUpdater/SDUpdater_Class.hpp | 2 +- src/misc/config.h | 3 +- src/misc/sdfat32fs_wrapper.hpp | 10 +- 6 files changed, 107 insertions(+), 82 deletions(-) diff --git a/examples/SdFatUpdater/SdFatUpdater.ino b/examples/SdFatUpdater/SdFatUpdater.ino index 07f631ab..2b712cb0 100644 --- a/examples/SdFatUpdater/SdFatUpdater.ino +++ b/examples/SdFatUpdater/SdFatUpdater.ino @@ -1,21 +1,46 @@ #define TFCARD_CS_PIN 4 // customize this -#include // optional gzipped firmware support -> https://github.com/tobozo/ESP32-targz + #include // /!\ When using SdFat, always include LGFX/M5GFX *before* M5StackUpdater.h to prevent problems with macros +//#include +//#include +#define SDU_NO_PRAGMAS // don't spawn pragma messages during compilation +#define SDU_ENABLE_GZ // auto-load ESP32-targz (will be loaded otherwise is previously included) +//#include // optional gzipped firmware support, overriden by SDU_ENABLE_GZ -> https://github.com/tobozo/ESP32-targz #define SDU_NO_AUTODETECT // Disable SDUpdater autodetect: this prevents to be auto-selected, however it also disables board detection #define USE_SDFATFS // Tell M5StackUpdater to load and wrap SdFat32 into fs::FS::SdFat32FSImpl -#define HAS_M5_API // Use M5 API (M5.BtnA, BtnB, BtnC...) for triggers -#define SDU_USE_DISPLAY // Enable display (progress bar, lobby, buttons) -#define HAS_LGFX // Use LGFX Family display driver with zoom, rotate -#define SDU_Sprite LGFX_Sprite // Inherit Sprite type from M5GFX -#define SDU_DISPLAY_TYPE M5GFX* // inherit display type from M5GFX -#define SDU_DISPLAY_OBJ_PTR &M5.Display // alias display pointer from M5Unified -#define SDU_TouchButton LGFX_Button // inherit Buttons types from M5Unified -#if !defined SDU_HAS_TOUCH && defined ARDUINO_M5STACK_Core2 - #define SDU_HAS_TOUCH +#if __has_include() + + #define HAS_M5_API // Use M5 API (M5.BtnA, BtnB, BtnC...) for triggers + #define SDU_USE_DISPLAY // Enable display (progress bar, lobby, buttons) + #define HAS_LGFX // Use LGFX Family display driver with zoom, rotate + #define SDU_Sprite LGFX_Sprite // Inherit Sprite type from M5GFX + #define SDU_DISPLAY_TYPE M5GFX* // inherit display type from M5GFX + #define SDU_DISPLAY_OBJ_PTR &M5.Display // alias display pointer from M5Unified + #if defined ARDUINO_M5STACK_Core2 + #define SDU_TouchButton LGFX_Button // inherit Buttons types from M5Unified + #define SDU_HAS_TOUCH + #endif + +#elif __has_include() || __has_include() + + #define HAS_M5_API // Use M5 API (M5.BtnA, BtnB, BtnC...) for triggers + #define SDU_USE_DISPLAY // Enable display (progress bar, lobby, buttons) + #define SDU_Sprite TFT_eSprite // Inherit TFT_eSprite type from M5 Core + #define SDU_DISPLAY_TYPE M5Display* // inherit TFT_eSpi type from M5 Core + #define SDU_DISPLAY_OBJ_PTR &M5.Lcd // alias display pointer from M5 Core + #if defined ARDUINO_M5STACK_Core2 && __has_include() + #define SDU_TouchButton TFT_eSPI_Button // inherit Buttons types from TFT_eSPI + #define SDU_HAS_TOUCH + #endif + +#else + + #error "This example only supports the following cores: M5Unified.h, M5Stack.h or M5Core2.h" + #endif //#include // not necessary when `USE_SDFATFS` is defined diff --git a/src/M5StackUpdater.hpp b/src/M5StackUpdater.hpp index 0fe22aba..32047caf 100644 --- a/src/M5StackUpdater.hpp +++ b/src/M5StackUpdater.hpp @@ -94,6 +94,16 @@ #define resetReason (int)rtc_get_reset_reason(0) +// use `#define SDU_NO_PRAGMAS` to disable pragma messages +#if !defined SDU_NO_PRAGMAS + #define SDU_STRINGIFY(a) #a + #define SDU_PRAGMA_MESSAGE(msg) \ + _Pragma( SDU_STRINGIFY( message msg ) ) +#else + #define SDU_PRAGMA_MESSAGE(msg) +#endif + + // inherit filesystem includes from sketch #if defined _SD_H_ #define SDU_HAS_SD @@ -105,20 +115,23 @@ #if !defined SDU_SPI_FREQ #define SDU_SPI_FREQ 80000000 #endif - #pragma message "SD has custom SPI pins" + SDU_PRAGMA_MESSAGE("SD has custom SPI pins") #define SDU_SD_BEGIN [](int csPin)->bool{ SPI.begin(_CLK, _MISO, _MOSI, csPin); SPI.setDataMode(SDU_SPI_MODE); return SD.begin(csPin, SPI, SDU_SPI_FREQ); } #else #define SDU_SD_BEGIN(csPin) SD.begin(csPin) #endif #endif + #if defined _SDMMC_H_ #define SDU_HAS_SD_MMC /*#include */ #endif + #if defined _SPIFFS_H_ #define SDU_HAS_SPIFFS /*#include */ #endif + #if defined _LiffleFS_H_ || __has_include() #define SDU_HAS_LITTLEFS #include @@ -130,43 +143,31 @@ #warning "Use builtin version with #include instead, if using platformio add LittleFS(esp32)@^2.0.0 to lib_deps" #endif -#if defined SDU_HAS_SD || defined SDU_HAS_SD_MMC || defined SDU_HAS_SPIFFS || defined SDU_HAS_LITTLEFS - #define SDU_HAS_FS 1 -#else - #define SDU_HAS_FS 0 +// Note: SdFat can't be detected using __has_include() without creating problems downstream in the code. +// Until this is solved, enabling SdFat is done by adding `#defined USE_SDFATFS` to the sketch before including the library. +#if defined USE_SDFATFS + #define SDU_HAS_SDFS + SDU_PRAGMA_MESSAGE("SDUpdater will use SdFat") + #include "./misc/sdfat32fs_wrapper.hpp" + #define SDU_SDFS_BEGIN SDU_SDFatBegin +#endif + + +#if !defined SDU_HAS_SD && !defined SDU_HAS_SD_MMC && !defined SDU_HAS_SPIFFS && !defined SDU_HAS_LITTLEFS && !defined SDU_HAS_SDFS + SDU_PRAGMA_MESSAGE("SDUpdater didn't detect any preselected filesystem, will use SD as default") + #define SDU_HAS_SD + #include + #define SDU_SD_BEGIN(csPin) SD.begin(csPin) #endif -// call this directive before detecting/loading SdFat otherwise __has_include() directive will be unavailable #if defined SDU_ENABLE_GZ || defined _ESP_TGZ_H || __has_include() #define SDU_HAS_TARGZ - #pragma message "gzip and tar support detected!" + SDU_PRAGMA_MESSAGE("gzip and tar support detected!") #include #endif -#if SDU_HAS_FS==0 - #define SDU_HAS_SD - #if defined USE_SDFATFS - #pragma message "SDUpdater will use SdFat" - #warning "SdFat.h is not in the stack list, loading will be forced" - //#undef __has_include - #include - #include - #include - //#define __has_include - // WARNING: __has_include() directive is undef'd by SdFat library and platformio makes this global - #include "./misc/sdfat32fs_wrapper.hpp" - // do not use the directive __has_include() below this point - #define SDU_SD_BEGIN SDU_SDFatBegin - #else - #pragma message "SDUpdater didn't detect any preselected filesystem, will use SD as default" - #include - #define SDU_SD_BEGIN(csPin) SD.begin(csPin) - #endif -#endif - - -#if !defined SDU_NO_AUTODETECT +#if !defined SDU_NO_AUTODETECT // lobby/buttons #if !defined SDU_HEADLESS #define SDU_USE_DISPLAY // any detected display is default enabled unless SDU_HEADLESS mode is selected @@ -175,8 +176,7 @@ #define HAS_M5_API // This is M5Stack Updater, assume it has the M5.xxx() API, will be undef'd otherwise #if defined _CHIMERA_CORE_ - #pragma message "Chimera Core detected" - //#include + SDU_PRAGMA_MESSAGE("Chimera Core detected") #define SDU_Sprite LGFX_Sprite #define SDU_DISPLAY_TYPE M5Display* #define SDU_DISPLAY_OBJ_PTR &M5.Lcd @@ -187,28 +187,24 @@ #define SDU_HAS_TOUCH #endif #elif defined _M5STACK_H_ - #pragma message "M5Stack.h detected" - //#include + SDU_PRAGMA_MESSAGE("M5Stack.h detected") #define SDU_Sprite TFT_eSprite #define SDU_DISPLAY_TYPE M5Display* #define SDU_DISPLAY_OBJ_PTR &M5.Lcd #elif defined _M5Core2_H_ - #pragma message "M5Core2.h detected" - //#include + SDU_PRAGMA_MESSAGE("M5Core2.h detected") #define SDU_Sprite TFT_eSprite #define SDU_DISPLAY_TYPE M5Display* #define SDU_DISPLAY_OBJ_PTR &M5.Lcd #define SDU_TouchButton TFT_eSPI_Button #define SDU_HAS_TOUCH // M5Core2 has implicitely enabled touch interface #elif defined _M5STICKC_H_ - #pragma message "M5StickC.h detected" - //#include + SDU_PRAGMA_MESSAGE("M5StickC.h detected") #define SDU_Sprite TFT_eSprite #define SDU_DISPLAY_TYPE M5Display* #define SDU_DISPLAY_OBJ_PTR &M5.Lcd #elif defined __M5UNIFIED_HPP__ - #pragma message "M5Unified.h detected" - //#include + SDU_PRAGMA_MESSAGE("M5Unified.h detected") #define SDU_Sprite LGFX_Sprite #define SDU_DISPLAY_TYPE M5GFX* #define SDU_DISPLAY_OBJ_PTR &M5.Display @@ -218,8 +214,7 @@ #define SDU_HAS_TOUCH #endif #else - #pragma message "No display driver detected" - //#error "No display driver detected" + SDU_PRAGMA_MESSAGE(message "No display driver detected") #define SDU_DISPLAY_OBJ_PTR nullptr //#define SDU_DISPLAY_TYPE void* //#define SDU_Sprite void* @@ -231,23 +226,17 @@ #if defined HAS_M5_API // SDUpdater can use M5.update(), and M5.Btnx API #define DEFAULT_BTN_POLLER M5.update() - //#if defined ARDUINO_ESP32_S3_BOX // S3Box only has mute button and Touch - //#define DEFAULT_BTNA_CHECKER S3MuteButton.changed() // use SDUpdater::DigitalPinButton_t - //#define DEFAULT_BTNB_CHECKER false - //#define DEFAULT_BTNC_CHECKER false - //#else - #define DEFAULT_BTNA_CHECKER M5.BtnA.isPressed() - #define DEFAULT_BTNB_CHECKER M5.BtnB.isPressed() - #if defined _M5STICKC_H_ // M5StickC has no BtnC - #define DEFAULT_BTNC_CHECKER false - #else - #define DEFAULT_BTNC_CHECKER M5.BtnC.isPressed() - #endif - //#endif + #define DEFAULT_BTNA_CHECKER M5.BtnA.isPressed() + #define DEFAULT_BTNB_CHECKER M5.BtnB.isPressed() + #if defined _M5STICKC_H_ // M5StickC has no BtnC + #define DEFAULT_BTNC_CHECKER false + #else + #define DEFAULT_BTNC_CHECKER M5.BtnC.isPressed() + #endif #else // SDUpdater will use Serial as trigger source #if !defined SDU_NO_AUTODETECT - #pragma message "No M5 API found" + SDU_PRAGMA_MESSAGE(message "No M5 API found") #endif #define DEFAULT_BTN_POLLER nullptr #define DEFAULT_BTNA_CHECKER false @@ -255,36 +244,36 @@ #define DEFAULT_BTNC_CHECKER false #endif - +// dispatch predefined triggers #if !defined SDU_TRIGGER_SOURCE_DEFAULT #if defined SDU_HAS_TOUCH - #pragma message "Trigger source: Touch Button" + SDU_PRAGMA_MESSAGE("Trigger source: Touch Button") #define SDU_TRIGGER_SOURCE_DEFAULT TriggerSource::SDU_TRIGGER_TOUCHBUTTON #elif defined HAS_M5_API - #pragma message "Trigger source: Push Button" + SDU_PRAGMA_MESSAGE("Trigger source: Push Button") #define SDU_TRIGGER_SOURCE_DEFAULT TriggerSource::SDU_TRIGGER_PUSHBUTTON #else - #pragma message "Trigger source: Serial" + SDU_PRAGMA_MESSAGE("Trigger source: Serial") #define SDU_TRIGGER_SOURCE_DEFAULT TriggerSource::SDU_TRIGGER_SERIAL #endif #endif - +// load the SDUpdater stack #include "./misc/update_interface.hpp" #include "./ConfigManager/ConfigManager.hpp" #include "./SDUpdater/SDUpdater_Class.hpp" #include "./UI/common.hpp" - +// load the lobby and button decorations if applicable #if defined SDU_USE_DISPLAY - #pragma message "Attached UI" + SDU_PRAGMA_MESSAGE("Attached UI") #define SDU_GFX ((SDU_DISPLAY_TYPE)(SDUCfg.display)) // macro for UI.hpp #include "./UI/UI.hpp" - #if defined SDU_HAS_TOUCH - #pragma message "Attached Touch support" + #if defined SDU_HAS_TOUCH // load touch helpers + SDU_PRAGMA_MESSAGE("Attached Touch support") #include "./UI/Touch.hpp" #endif -#else +#else // bind unknown display to SDUCfg.display, whatever it is... #define SDU_GFX ((void*)(SDUCfg.display)) // macro for UI.hpp #endif @@ -465,7 +454,7 @@ namespace SDUpdaterNS #if defined USE_SDFATFS using namespace ConfigManager; if( SDU_SdFatFsPtr ) { - if( !SDU_SD_BEGIN( SDU_SdSpiConfigPtr ) ) { + if( !SDU_SDFS_BEGIN( SDU_SdSpiConfigPtr ) ) { msg[0] = String("SDFat MOUNT FAILED ").c_str(); if( report_errors ) sdu->_error( msg, 2 ); return false; @@ -576,7 +565,9 @@ namespace SDUpdaterNS // load default config auto cfg = SdSpiConfig( SDUCfg.TFCardCsPin, SHARED_SPI, SD_SCK_MHZ(25) ); SdFatCfg = (SdSpiConfig*)malloc( sizeof(SdSpiConfig) + 1 ); - memcpy( SdFatCfg, &cfg, sizeof(SdSpiConfig) ); + void *DstPtr = SdFatCfg; + void *SrcPtr = &cfg; + memcpy( DstPtr, SrcPtr, sizeof(SdSpiConfig) ); } ConfigManager::SDU_SdSpiConfigPtr = SdFatCfg; ConfigManager::SDU_SdFatPtr = &sd; diff --git a/src/SDUpdater/SDUpdater_Class.cpp b/src/SDUpdater/SDUpdater_Class.cpp index ff77c84d..6bd6912a 100644 --- a/src/SDUpdater/SDUpdater_Class.cpp +++ b/src/SDUpdater/SDUpdater_Class.cpp @@ -97,7 +97,7 @@ namespace SDUpdaterNS } - bool SDUpdater::copyFsPartition(File* dst, const esp_partition_t* src, size_t length) + bool SDUpdater::copyFsPartition(fs::File* dst, const esp_partition_t* src, size_t length) { size_t lengthLeft = length; const size_t bufSize = SPI_FLASH_SEC_SIZE; diff --git a/src/SDUpdater/SDUpdater_Class.hpp b/src/SDUpdater/SDUpdater_Class.hpp index 7cfb47dd..b8ba3bf9 100644 --- a/src/SDUpdater/SDUpdater_Class.hpp +++ b/src/SDUpdater/SDUpdater_Class.hpp @@ -79,7 +79,7 @@ namespace SDUpdaterNS void doRollBack( const String& message = "" ); // flash to SD binary replication bool compareFsPartition(const esp_partition_t* src1, fs::File* src2, size_t length); - bool copyFsPartition(File* dst, const esp_partition_t* src, size_t length); + bool copyFsPartition(fs::File* dst, const esp_partition_t* src, size_t length); bool saveSketchToFS(fs::FS &fs, const char* binfilename = PROGMEM {MENU_BIN}, bool skipIfExists = false ); // static methods static void updateNVS(); diff --git a/src/misc/config.h b/src/misc/config.h index 27e82a09..bd452976 100644 --- a/src/misc/config.h +++ b/src/misc/config.h @@ -44,7 +44,8 @@ #define SD_PLATFORM_NAME "TTGO TWatch" #elif defined ARDUINO_M5STACK_ATOM_AND_TFCARD #define SD_PLATFORM_NAME "Atom" +#elif defined ARDUINO_ESP32_S3_BOX + #define SD_PLATFORM_NAME "S3Box" #else - //#pragma message ("Custom ESP32 board detected") #define SD_PLATFORM_NAME "ESP32" #endif diff --git a/src/misc/sdfat32fs_wrapper.hpp b/src/misc/sdfat32fs_wrapper.hpp index 0cc75292..873ffc6a 100644 --- a/src/misc/sdfat32fs_wrapper.hpp +++ b/src/misc/sdfat32fs_wrapper.hpp @@ -13,6 +13,13 @@ #error "SD Updater only supports SdFs" #endif + #undef __has_include + #include + #include + #include + #define __has_include(STR) __has_include__(STR) + + // cfr https://en.cppreference.com/w/c/io/fopen + guesses inline oflag_t _convert_access_mode_to_flag(const char* mode, const bool create = false) { @@ -130,7 +137,8 @@ ret = _fat->begin( *SdFatCfg ); errcode = _fat->card()->errorCode(); errdata = int(_fat->card()->errorData()); - + (void)errcode; + (void)errdata; if (!ret) { log_e( "SDFat init failed with error code: 0x%x, Error Data:0x%x", errcode, errdata ); return false; From 6e96b1f355ed3ec8a011e70f8f3011c60458f4d7 Mon Sep 17 00:00:00 2001 From: tobozo Date: Wed, 3 May 2023 14:55:52 +0200 Subject: [PATCH 12/13] fix for setBinFileName() crashing --- src/ConfigManager/ConfigManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ConfigManager/ConfigManager.cpp b/src/ConfigManager/ConfigManager.cpp index 010f9bb3..3c1e9736 100644 --- a/src/ConfigManager/ConfigManager.cpp +++ b/src/ConfigManager/ConfigManager.cpp @@ -41,7 +41,7 @@ namespace SDUpdaterNS void config_sdu_t::setLabelSave( const char* label ) { labelSave = label; } void config_sdu_t::setAppName( const char* name ) { appName = name; } void config_sdu_t::setAuthorName( const char* name ) { authorName = name; } - void config_sdu_t::setBinFileName( const char* name ) { if( strstr(binFileName, ".gz")!=NULL ) binFileName = name; } + void config_sdu_t::setBinFileName( const char* name ) { if( name && strstr(name, ".gz")!=NULL ) binFileName = name; } void config_sdu_t::useRolllback( bool use ) { use_rollback = use; } void config_sdu_t::setBtnPoller( BtnPollCb cb ) { log_d("Assigning Btn Poller"); buttonsUpdate = cb; } From d21cd5ee46c2c345cd2284c167b753fd353eb698 Mon Sep 17 00:00:00 2001 From: tobozo Date: Wed, 3 May 2023 14:57:18 +0200 Subject: [PATCH 13/13] added LovyanGFX to profiles --- examples/SdFatUpdater/SdFatUpdater.ino | 33 +++++++++++++++++--------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/examples/SdFatUpdater/SdFatUpdater.ino b/examples/SdFatUpdater/SdFatUpdater.ino index 2b712cb0..7370f3d7 100644 --- a/examples/SdFatUpdater/SdFatUpdater.ino +++ b/examples/SdFatUpdater/SdFatUpdater.ino @@ -1,19 +1,32 @@ #define TFCARD_CS_PIN 4 // customize this - -#include // /!\ When using SdFat, always include LGFX/M5GFX *before* M5StackUpdater.h to prevent problems with macros -//#include +#include // Note: don't mix M5Unified with LovyanGFX //#include +//#include +//#define LGFX_AUTODETECT +//#include + + +// M5StackUpdater library configuration #define SDU_NO_PRAGMAS // don't spawn pragma messages during compilation #define SDU_ENABLE_GZ // auto-load ESP32-targz (will be loaded otherwise is previously included) //#include // optional gzipped firmware support, overriden by SDU_ENABLE_GZ -> https://github.com/tobozo/ESP32-targz #define SDU_NO_AUTODETECT // Disable SDUpdater autodetect: this prevents to be auto-selected, however it also disables board detection #define USE_SDFATFS // Tell M5StackUpdater to load and wrap SdFat32 into fs::FS::SdFat32FSImpl +#define SDU_APP_NAME "SdFatUpdater test" +#define SDU_APP_PATH "/SdFatUpdater.bin" -#if __has_include() - +#if __has_include() + LGFX lcd; + #define HAS_M5_API // Use M5 API (M5.BtnA, BtnB, BtnC...) for triggers + #define SDU_USE_DISPLAY // Enable display (progress bar, lobby, b + #define HAS_LGFX // Use LGFX Family display driver with zo + #define SDU_Sprite LGFX_Sprite // Inherit Sprite type from LGFX + #define SDU_DISPLAY_TYPE LGFX* // inherit display type from LGFX + #define SDU_DISPLAY_OBJ_PTR &lcd // alias display pointer from lcd object +#elif __has_include() #define HAS_M5_API // Use M5 API (M5.BtnA, BtnB, BtnC...) for triggers #define SDU_USE_DISPLAY // Enable display (progress bar, lobby, buttons) #define HAS_LGFX // Use LGFX Family display driver with zoom, rotate @@ -21,12 +34,10 @@ #define SDU_DISPLAY_TYPE M5GFX* // inherit display type from M5GFX #define SDU_DISPLAY_OBJ_PTR &M5.Display // alias display pointer from M5Unified #if defined ARDUINO_M5STACK_Core2 - #define SDU_TouchButton LGFX_Button // inherit Buttons types from M5Unified + #define SDU_TouchButton LGFX_Button // inherit Buttons types from M5Unified #define SDU_HAS_TOUCH #endif - #elif __has_include() || __has_include() - #define HAS_M5_API // Use M5 API (M5.BtnA, BtnB, BtnC...) for triggers #define SDU_USE_DISPLAY // Enable display (progress bar, lobby, buttons) #define SDU_Sprite TFT_eSprite // Inherit TFT_eSprite type from M5 Core @@ -39,7 +50,7 @@ #else - #error "This example only supports the following cores: M5Unified.h, M5Stack.h or M5Core2.h" + #error "This example only supports the following cores: LovyanGFX.h, M5Unified.h, M5Stack.h or M5Core2.h" #endif @@ -58,8 +69,8 @@ void setup() SDUCfg.setLabelMenu("< Menu"); // BtnA label: load menu.bin SDUCfg.setLabelSkip("Launch"); // BtnB label: skip the lobby countdown and run the app SDUCfg.setLabelSave("Save"); // BtnC label: save the sketch to the SD - SDUCfg.setAppName("SdFatUpdater test"); // lobby screen label: application name - SDUCfg.setBinFileName("/SdFatUpdater.bin"); // if file path to bin is set for this app, it will be checked at boot and created if not exist + SDUCfg.setAppName( SDU_APP_NAME ); // lobby screen label: application name + SDUCfg.setBinFileName( SDU_APP_PATH ); // if file path to bin is set for this app, it will be checked at boot and created if not exist checkSDUpdater( sd, // filesystem (must be type SdFat32)