diff --git a/.forgejo/workflows/push.yaml b/.forgejo/workflows/push.yaml index 5121d24..6ccb926 100644 --- a/.forgejo/workflows/push.yaml +++ b/.forgejo/workflows/push.yaml @@ -95,7 +95,6 @@ jobs: - name: Create merged firmware binary run: | if [ "${{ matrix.chip.name }}" == "btclock_v8" ]; then - mkdir -p ${{ matrix.chip.name }}_${{ matrix.epd_variant }} && \ esptool.py --chip ${{ matrix.chip.version }} merge_bin \ -o ${{ matrix.chip.name }}_${{ matrix.epd_variant }}/${{ matrix.chip.name }}_${{ matrix.epd_variant }}.bin \ --flash_mode dio \ @@ -105,7 +104,19 @@ jobs: 0x8000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/partitions.bin \ 0xe000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/ota_data_initial.bin \ 0x10000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/firmware.bin \ - 0x810000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/littlefs.bin; + 0xDF0000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/littlefs_16MB.bin + elif [ "${{ matrix.chip.name }}" == "btclock_rev_b" ]; then + mkdir -p ${{ matrix.chip.name }}_${{ matrix.epd_variant }} && \ + esptool.py --chip ${{ matrix.chip.version }} merge_bin \ + -o ${{ matrix.chip.name }}_${{ matrix.epd_variant }}/${{ matrix.chip.name }}_${{ matrix.epd_variant }}.bin \ + --flash_mode dio \ + --flash_freq 80m \ + --flash_size 8MB \ + 0x0000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/bootloader.bin \ + 0x8000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/partitions.bin \ + 0xe000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/ota_data_initial.bin \ + 0x10000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/firmware.bin \ + 0x6F0000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/littlefs_8MB.bin; else # Original command for other cases mkdir -p ${{ matrix.chip.name }}_${{ matrix.epd_variant }} && \ @@ -116,7 +127,7 @@ jobs: 0x8000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/partitions.bin \ 0xe000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/ota_data_initial.bin \ 0x10000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/firmware.bin \ - 0x370000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/littlefs.bin + 0x380000 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/littlefs_4MB.bin # Adjust the offset for littlefs or other files as needed for the original case fi @@ -127,10 +138,11 @@ jobs: run: shasum -a 256 ${{ matrix.chip.name }}_${{ matrix.epd_variant }}/${{ matrix.chip.name }}_${{ matrix.epd_variant }}.bin | awk '{print $1}' > ${{ matrix.chip.name }}_${{ matrix.epd_variant }}/${{ matrix.chip.name }}_${{ matrix.epd_variant }}.bin.sha256 - name: Create checksum for littlefs partition - run: shasum -a 256 .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/littlefs.bin | awk '{print $1}' > ${{ matrix.chip.name }}_${{ matrix.epd_variant }}/littlefs.bin.sha256 - - - name: Copy all artifacts to output folder - run: cp .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/*.bin .pio/boot_app0.bin ${{ matrix.chip.name }}_${{ matrix.epd_variant }} + run: | + fs_file=$(find .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }} -name "littlefs*.bin") + shasum -a 256 "$fs_file" | awk '{print $1}' > "${fs_file}.sha256" + - name: Copy all artifacts to output folder + run: cp .pio/build/${{ matrix.chip.name }}_${{ matrix.epd_variant }}/*.bin .pio/boot_app0.bin ${{ matrix.chip.name }}_${{ matrix.epd_variant }} - name: Create OTA binary file run: mv ${{ matrix.chip.name }}_${{ matrix.epd_variant }}/firmware.bin ${{ matrix.chip.name }}_${{ matrix.epd_variant }}/${{ matrix.chip.name }}_${{ matrix.epd_variant }}_firmware.bin diff --git a/partition.csv b/partition.csv index 80714ea..eedbf5b 100644 --- a/partition.csv +++ b/partition.csv @@ -3,5 +3,5 @@ nvs, data, nvs, 0x9000, 0x5000, otadata, data, ota, 0xe000, 0x2000, app0, app, ota_0, 0x10000, 0x1b8000, app1, app, ota_1, , 0x1b8000, -spiffs, data, spiffs, , 0x66800, -coredump, data, coredump,, 0x10000, \ No newline at end of file +spiffs, data, spiffs, , 0x66C00, +coredump, data, coredump,, 0x10000, diff --git a/partition_16mb.csv b/partition_16mb.csv index e26e145..7e58611 100644 --- a/partition_16mb.csv +++ b/partition_16mb.csv @@ -1,7 +1,7 @@ # Name, Type, SubType, Offset, Size, Flags -nvs, data, nvs, 36K, 20K, -otadata, data, ota, 56K, 8K, -app0, app, ota_0, 64K, 4096K, -app1, app, ota_1, , 4096K, -spiffs, data, spiffs, , 410K, -coredump, data, coredump,, 64K, +nvs, data, nvs, 0x9000, 0x5000, +otadata, data, ota, 0xe000, 0x2000, +app0, app, ota_0, 0x10000, 0x6F0000, +app1, app, ota_1, , 0x6F0000, +spiffs, data, spiffs, , 0x200000, +coredump, data, coredump,, 0x10000, \ No newline at end of file diff --git a/partition_8mb.csv b/partition_8mb.csv index 778b9f2..025f649 100644 --- a/partition_8mb.csv +++ b/partition_8mb.csv @@ -1,7 +1,7 @@ # Name, Type, SubType, Offset, Size, Flags -nvs, data, nvs, 36K, 20K, -otadata, data, ota, 56K, 8K, -app0, app, ota_0, 64K, 1760K, -app1, app, ota_1, , 1760K, -spiffs, data, spiffs, , 410K, -coredump, data, coredump,, 64K, +nvs, data, nvs, 0x9000, 0x5000, +otadata, data, ota, 0xe000, 0x2000, +app0, app, ota_0, 0x10000, 0x370000, +app1, app, ota_1, , 0x370000, +spiffs, data, spiffs, , 0xCD000, +coredump, data, coredump,, 0x10000, \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 7b0d229..d2abb92 100644 --- a/platformio.ini +++ b/platformio.ini @@ -20,8 +20,9 @@ framework = arduino, espidf monitor_speed = 115200 monitor_filters = esp32_exception_decoder, colorize board_build.filesystem = littlefs -extra_scripts = post:scripts/extra_script.py -board_build.embed_files = x509_crt_bundle +extra_scripts = pre:scripts/pre_script.py, post:scripts/extra_script.py +board_build.embed_files = + x509_crt_bundle build_flags = !python scripts/git_rev.py -DLAST_BUILD_TIME=$UNIX_TIME @@ -35,14 +36,13 @@ lib_deps = https://github.com/joltwallet/esp_littlefs.git bblanchon/ArduinoJson@^7.2.1 mathieucarbou/ESPAsyncWebServer @ 3.3.23 - adafruit/Adafruit BusIO@^1.16.2 - adafruit/Adafruit MCP23017 Arduino Library@^2.3.2 + robtillaart/MCP23017@^0.8.0 adafruit/Adafruit NeoPixel@^1.12.3 - https://github.com/dsbaars/universal_pin + https://github.com/dsbaars/universal_pin#feature/mcp23017_rt https://github.com/dsbaars/GxEPD2#universal_pin https://github.com/tzapu/WiFiManager.git#v2.0.17 rblb/Nostrduino@1.2.8 - + [env:lolin_s3_mini] extends = btclock_base board = lolin_s3_mini @@ -64,7 +64,7 @@ build_unflags = [env:btclock_rev_b] extends = btclock_base board = btclock_rev_b -board_build.partitions = partition.csv +board_build.partitions = partition_8mb.csv build_flags = ${btclock_base.build_flags} -D MCP_INT_PIN=8 diff --git a/scripts/pre_script.py b/scripts/pre_script.py new file mode 100644 index 0000000..45d6bea --- /dev/null +++ b/scripts/pre_script.py @@ -0,0 +1,7 @@ +Import("env") + +flash_size = env.BoardConfig().get("upload.flash_size", "4MB") +fs_image_name = f"littlefs_{flash_size}" +env.Replace(ESP32_FS_IMAGE_NAME=fs_image_name) +env.Replace(ESP8266_FS_IMAGE_NAME=fs_image_name) + diff --git a/src/lib/button_handler.cpp b/src/lib/button_handler.cpp index 437090d..72f1eaa 100644 --- a/src/lib/button_handler.cpp +++ b/src/lib/button_handler.cpp @@ -5,15 +5,15 @@ const TickType_t debounceDelay = pdMS_TO_TICKS(50); TickType_t lastDebounceTime = 0; #ifdef IS_BTCLOCK_V8 -#define BTN_1 0 -#define BTN_2 1 -#define BTN_3 2 -#define BTN_4 3 +#define BTN_1 256 +#define BTN_2 512 +#define BTN_3 1024 +#define BTN_4 2048 #else -#define BTN_1 3 -#define BTN_2 2 -#define BTN_3 1 -#define BTN_4 0 +#define BTN_1 2048 +#define BTN_2 1024 +#define BTN_3 512 +#define BTN_4 256 #endif void buttonTask(void *parameter) { @@ -22,11 +22,12 @@ void buttonTask(void *parameter) { std::lock_guard lock(mcpMutex); TickType_t currentTime = xTaskGetTickCount(); + if ((currentTime - lastDebounceTime) >= debounceDelay) { lastDebounceTime = currentTime; if (!digitalRead(MCP_INT_PIN)) { - uint pin = mcp1.getLastInterruptPin(); + uint pin = mcp1.getInterruptFlagRegister(); switch (pin) { case BTN_1: @@ -43,12 +44,12 @@ void buttonTask(void *parameter) { break; } } - mcp1.clearInterrupts(); + mcp1.getInterruptCaptureRegister(); } else { } // Very ugly, but for some reason this is necessary while (!digitalRead(MCP_INT_PIN)) { - mcp1.clearInterrupts(); + mcp1.getInterruptCaptureRegister(); } } } diff --git a/src/lib/config.cpp b/src/lib/config.cpp index 8f954b2..e9912a9 100644 --- a/src/lib/config.cpp +++ b/src/lib/config.cpp @@ -2,10 +2,12 @@ #define MAX_ATTEMPTS_WIFI_CONNECTION 20 +// zlib_turbo zt; + Preferences preferences; -Adafruit_MCP23X17 mcp1; +MCP23017 mcp1(0x20); #ifdef IS_BTCLOCK_V8 -Adafruit_MCP23X17 mcp2; +MCP23017 mcp2(0x21); #endif #ifdef HAS_FRONTLIGHT @@ -35,7 +37,7 @@ void setup() } { std::lock_guard lockMcp(mcpMutex); - if (mcp1.digitalRead(3) == LOW) + if (mcp1.read1(3) == LOW) { preferences.putBool("wifiConfigured", false); preferences.remove("txPower"); @@ -46,7 +48,7 @@ void setup() } { - if (mcp1.digitalRead(0) == LOW) + if (mcp1.read1(0) == LOW) { // Then loop forever to prevent anything else from writing to the screen while (true) @@ -54,7 +56,7 @@ void setup() delay(1000); } } - else if (mcp1.digitalRead(1) == LOW) + else if (mcp1.read1(1) == LOW) { preferences.clear(); queueLedEffect(LED_EFFECT_WIFI_ERASE_SETTINGS); @@ -66,6 +68,7 @@ void setup() } setupWifi(); + // loadIcons(); setupWebserver(); @@ -106,6 +109,7 @@ void setup() #endif forceFullRefresh(); + } void setupWifi() @@ -132,7 +136,7 @@ void setupWifi() bool buttonPress = false; { std::lock_guard lockMcp(mcpMutex); - buttonPress = (mcp1.digitalRead(2) == LOW); + buttonPress = (mcp1.read1(2) == LOW); } { @@ -507,7 +511,7 @@ void setupHardware() Wire.begin(I2C_SDA_PIN, I2C_SCK_PIN, 400000); - if (!mcp1.begin_I2C(0x20)) + if (!mcp1.begin()) { Serial.println(F("Error MCP23017 1")); @@ -517,17 +521,20 @@ void setupHardware() else { pinMode(MCP_INT_PIN, INPUT_PULLUP); - mcp1.setupInterrupts(false, false, LOW); +// mcp1.setupInterrupts(false, false, LOW); + mcp1.enableControlRegister(MCP23x17_IOCR_ODR); + + mcp1.mirrorInterrupts(true); for (int i = 0; i < 4; i++) { - mcp1.pinMode(i, INPUT_PULLUP); - mcp1.setupInterruptPin(i, LOW); + mcp1.pinMode1(i, INPUT_PULLUP); + mcp1.enableInterrupt(i, LOW); } #ifndef IS_BTCLOCK_V8 for (int i = 8; i <= 14; i++) { - mcp1.pinMode(i, OUTPUT); + mcp1.pinMode1(i, OUTPUT); } #endif } @@ -538,7 +545,7 @@ void setupHardware() #endif #ifdef IS_BTCLOCK_V8 - if (!mcp2.begin_I2C(0x21)) + if (!mcp2.begin()) { Serial.println(F("Error MCP23017 2")); @@ -790,4 +797,19 @@ const char* getFirmwareFilename() { } else { return ""; } -} \ No newline at end of file +} + +// void loadIcons() { +// size_t ocean_logo_size = 886; + +// int iUncompSize = zt.gzip_info((uint8_t *)epd_compress_bitaxe, ocean_logo_size); +// Serial.printf("uncompressed size = %d\n", iUncompSize); + +// uint8_t *pUncompressed; +// pUncompressed = (uint8_t *)malloc(iUncompSize+4); +// int rc = zt.gunzip((uint8_t *)epd_compress_bitaxe, ocean_logo_size, pUncompressed); + +// if (rc == ZT_SUCCESS) { +// Serial.println("Decode success"); +// } +// } \ No newline at end of file diff --git a/src/lib/config.hpp b/src/lib/config.hpp index 8c9da90..53abe17 100644 --- a/src/lib/config.hpp +++ b/src/lib/config.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include #include @@ -83,4 +83,6 @@ void addScreenMapping(int value, const char* name); int findScreenIndexByValue(int value); String replaceAmbiguousChars(String input); -const char* getFirmwareFilename(); \ No newline at end of file +const char* getFirmwareFilename(); + +// void loadIcons(); \ No newline at end of file diff --git a/src/lib/epd.cpp b/src/lib/epd.cpp index 1e27eae..2b30f26 100644 --- a/src/lib/epd.cpp +++ b/src/lib/epd.cpp @@ -191,7 +191,7 @@ void setupDisplays() } // Hold lower button to enable "storage mode" (prevents burn-in of ePaper displays) - if (mcp1.digitalRead(0) == LOW) + if (mcp1.read1(0) == LOW) { setFgColor(GxEPD_BLACK); setBgColor(GxEPD_WHITE); @@ -614,10 +614,19 @@ void renderIcon(const uint dispNum, const String &text, bool partial) iconIndex = 4; } + + + displays[dispNum].drawInvertedBitmap(0,0, epd_icons_allArray[iconIndex], 122, 250, getFgColor()); + +// displays[dispNum].drawInvertedBitmap(0,0, getOceanIcon(), 122, 250, getFgColor()); + + } + + void renderQr(const uint dispNum, const String &text, bool partial) { #ifdef USE_QR diff --git a/src/lib/epd.hpp b/src/lib/epd.hpp index 749f940..1194cf1 100644 --- a/src/lib/epd.hpp +++ b/src/lib/epd.hpp @@ -4,6 +4,7 @@ #include #include + #include #include #include diff --git a/src/lib/shared.cpp b/src/lib/shared.cpp index 20bf6d4..3422ff8 100644 --- a/src/lib/shared.cpp +++ b/src/lib/shared.cpp @@ -143,4 +143,12 @@ String calculateSHA256(WiFiClient *stream, size_t contentLength) { } return result; -} \ No newline at end of file +} + +// uint8_t* getOceanIcon() { +// zlib_turbo zt; +// int iUncompSize = zt.gzip_info((uint8_t *)ocean_logo_comp, ocean_logo_size); +// uint8_t *pUncompressed; +// pUncompressed = (uint8_t *)malloc(iUncompSize+4); +// zt.gunzip((uint8_t *)ocean_logo_comp, ocean_logo_size, pUncompressed); +// } \ No newline at end of file diff --git a/src/lib/shared.hpp b/src/lib/shared.hpp index 19d1df0..4753764 100644 --- a/src/lib/shared.hpp +++ b/src/lib/shared.hpp @@ -1,6 +1,7 @@ #pragma once -#include +#include "MCP23017.h" +// #include #include #include #include @@ -17,9 +18,9 @@ #include "defaults.hpp" -extern Adafruit_MCP23X17 mcp1; +extern MCP23017 mcp1; #ifdef IS_BTCLOCK_V8 -extern Adafruit_MCP23X17 mcp2; +extern MCP23017 mcp2; #endif extern Preferences preferences; extern std::mutex mcpMutex; @@ -73,7 +74,12 @@ const int usPerMinute = 60 * usPerSecond; extern const char *isrg_root_x1cert; extern const uint8_t rootca_crt_bundle_start[] asm("_binary_x509_crt_bundle_start"); +// extern const uint8_t ocean_logo_comp[] asm("_binary_ocean_gz_start"); +// extern const uint8_t ocean_logo_comp_end[] asm("_binary_ocean_gz_end"); +// uint8_t* getOceanIcon(); + +// const size_t ocean_logo_size = ocean_logo_comp_end - ocean_logo_comp; const PROGMEM char UPDATE_FIRMWARE = U_FLASH; const PROGMEM char UPDATE_WEBUI = U_SPIFFS;