From 89287f43c9c5f4f1a67646633784f6018ceaaf5d Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Thu, 21 Sep 2023 17:41:21 +0200 Subject: [PATCH 01/11] bugfix, optimization --- src/drivers/storage/SDCard.cpp | 17 ++++++++--------- src/drivers/storage/SDCard.h | 2 +- src/drivers/storage/nvMemory.cpp | 2 +- src/drivers/storage/nvMemory.h | 4 +--- src/drivers/storage/storage.h | 12 ++++++------ src/mining.cpp | 6 +++--- src/wManager.cpp | 13 ++++++++----- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/drivers/storage/SDCard.cpp b/src/drivers/storage/SDCard.cpp index fe06bde..d4bd273 100644 --- a/src/drivers/storage/SDCard.cpp +++ b/src/drivers/storage/SDCard.cpp @@ -26,13 +26,12 @@ SDCard::~SDCard() unmount(); } -void SDCard::SD2nvMemory(nvMemory* nvMem) +void SDCard::SD2nvMemory(nvMemory* nvMem, TSettings* Settings) { - TSettings Settings; - if (loadConfigFile(&Settings)) + if (loadConfigFile(Settings)) { - nvMem->saveConfig(&Settings); - WiFi.begin(Settings.WifiSSID, Settings.WifiPW); + nvMem->saveConfig(Settings); + WiFi.begin(Settings->WifiSSID, Settings->WifiPW); Serial.println("SDCard: Settings transfered to internal memory. Restarting now."); ESP.restart(); } @@ -60,9 +59,9 @@ bool SDCard::loadConfigFile(TSettings* Settings) unmount(); if (!error) { - strcpy(Settings->WifiSSID, json[JSON_KEY_SSID] | Settings->WifiSSID); - strcpy(Settings->WifiPW, json[JSON_KEY_PASW] | Settings->WifiPW); - strcpy(Settings->PoolAddress, json[JSON_KEY_POOLURL] | Settings->PoolAddress); + Settings->WifiSSID = json[JSON_KEY_SSID] | Settings->WifiSSID; + Settings->WifiPW = json[JSON_KEY_PASW] | Settings->WifiPW; + Settings->PoolAddress = json[JSON_KEY_POOLURL] | Settings->PoolAddress; strcpy(Settings->BtcWallet, json[JSON_KEY_WALLETID] | Settings->BtcWallet); if (json.containsKey(JSON_KEY_POOLPORT)) Settings->PoolPort = json[JSON_KEY_POOLPORT].as(); @@ -149,7 +148,7 @@ bool SDCard::initSDcard() SDCard::SDCard() {} SDCard::~SDCard() {} -void SDCard::SD2nvMemory(nvMemory* nvMem) {}; +void SDCard::SD2nvMemory(nvMemory* nvMem, TSettings* Settings) {}; bool SDCard::loadConfigFile(TSettings* Settings) { return false; } bool SDCard::initSDcard() { return false; } void unmount() {} diff --git a/src/drivers/storage/SDCard.h b/src/drivers/storage/SDCard.h index b2e91f5..d1da16f 100644 --- a/src/drivers/storage/SDCard.h +++ b/src/drivers/storage/SDCard.h @@ -21,7 +21,7 @@ class SDCard public: SDCard(); ~SDCard(); - void SD2nvMemory(nvMemory* nvMem); + void SD2nvMemory(nvMemory* nvMem, TSettings* Settings); bool loadConfigFile(TSettings* Settings); private: bool initSDcard(); diff --git a/src/drivers/storage/nvMemory.cpp b/src/drivers/storage/nvMemory.cpp index a686589..0f737aa 100644 --- a/src/drivers/storage/nvMemory.cpp +++ b/src/drivers/storage/nvMemory.cpp @@ -84,7 +84,7 @@ bool nvMemory::loadConfig(TSettings* Settings) Serial.print('\n'); if (!error) { - strcpy(Settings->PoolAddress, json[JSON_KEY_POOLURL] | Settings->PoolAddress); + Settings->PoolAddress = json[JSON_KEY_POOLURL] | Settings->PoolAddress; strcpy(Settings->BtcWallet, json[JSON_KEY_WALLETID] | Settings->BtcWallet); if (json.containsKey(JSON_KEY_POOLPORT)) Settings->PoolPort = json[JSON_KEY_POOLPORT].as(); diff --git a/src/drivers/storage/nvMemory.h b/src/drivers/storage/nvMemory.h index 163431c..3b22c7e 100644 --- a/src/drivers/storage/nvMemory.h +++ b/src/drivers/storage/nvMemory.h @@ -21,9 +21,7 @@ private: bool Initialized_; }; -#ifdef NVMEM_SPIFFS -#define ESP_DRD_USE_SPIFFS true -#else +#ifndef NVMEM_SPIFFS #error We need some kind of permanent storage implementation! #endif //NVMEM_TYPE diff --git a/src/drivers/storage/storage.h b/src/drivers/storage/storage.h index 8aa0668..5da92e3 100644 --- a/src/drivers/storage/storage.h +++ b/src/drivers/storage/storage.h @@ -1,7 +1,7 @@ #ifndef _STORAGE_H_ #define _STORAGE_H_ -#include +#include #define DEFAULT_SSID "NerdMinerAP" #define DEFAULT_WIFIPW "MineYourCoins" @@ -23,12 +23,12 @@ struct TSettings { - char WifiSSID[80]{ DEFAULT_SSID }; - char WifiPW[80]{ DEFAULT_WIFIPW }; - char PoolAddress[80]{ DEFAULT_POOLURL }; + String WifiSSID{ DEFAULT_SSID }; + String WifiPW{ DEFAULT_WIFIPW }; + String PoolAddress{ DEFAULT_POOLURL }; char BtcWallet[80]{ DEFAULT_WALLETID }; - uint32_t PoolPort{ DEFAULT_POOLPORT }; - uint32_t Timezone{ DEFAULT_TIMEZONE }; + int PoolPort{ DEFAULT_POOLPORT }; + int Timezone{ DEFAULT_TIMEZONE }; bool saveStats{ DEFAULT_SAVESTATS }; }; diff --git a/src/mining.cpp b/src/mining.cpp index d6f5694..0b7dccb 100644 --- a/src/mining.cpp +++ b/src/mining.cpp @@ -59,14 +59,14 @@ bool checkPoolConnection(void) { //Resolve first time pool DNS and save IP if(serverIP == IPAddress(1,1,1,1)) { - WiFi.hostByName(Settings.PoolAddress, serverIP); + WiFi.hostByName(Settings.PoolAddress.c_str(), serverIP); Serial.printf("Resolved DNS and save ip (first time) got: %s\n", serverIP.toString()); } //Try connecting pool IP if (!client.connect(serverIP, Settings.PoolPort)) { - Serial.println("Imposible to connect to : " + String(Settings.PoolAddress)); - WiFi.hostByName(Settings.PoolAddress, serverIP); + Serial.println("Imposible to connect to : " + Settings.PoolAddress); + WiFi.hostByName(Settings.PoolAddress.c_str(), serverIP); Serial.printf("Resolved DNS got: %s\n", serverIP.toString()); vTaskDelay(1000 / portTICK_PERIOD_MS); return false; diff --git a/src/wManager.cpp b/src/wManager.cpp index 93afff4..bd89146 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -1,6 +1,8 @@ +#define ESP_DRD_USE_SPIFFS true // Include Libraries //#include ".h" + #include #include @@ -89,7 +91,7 @@ void init_WifiManager() if (SDCrd.loadConfigFile(&Settings)) { //Config file on SD card. - SDCrd.SD2nvMemory(&nvMem); // reboot on success. + SDCrd.SD2nvMemory(&nvMem, &Settings); // reboot on success. } else { @@ -122,7 +124,7 @@ void init_WifiManager() // Custom elements // Text box (String) - 80 characters maximum - WiFiManagerParameter pool_text_box("Poolurl", "Pool url", Settings.PoolAddress, 80); + WiFiManagerParameter pool_text_box("Poolurl", "Pool url", Settings.PoolAddress.c_str(), 80); // Need to convert numerical input to string to display the default value. char convertedValue[6]; @@ -168,7 +170,7 @@ void init_WifiManager() { //Could be break forced after edditing, so save new config Serial.println("failed to connect and hit timeout"); - strncpy(Settings.PoolAddress, pool_text_box.getValue(), sizeof(Settings.PoolAddress)); + Settings.PoolAddress = pool_text_box.getValue(); Settings.PoolPort = atoi(port_text_box_num.getValue()); strncpy(Settings.BtcWallet, addr_text_box.getValue(), sizeof(Settings.BtcWallet)); Settings.Timezone = atoi(time_text_box_num.getValue()); @@ -187,7 +189,7 @@ void init_WifiManager() //Tratamos de conectar con la configuración inicial ya almacenada mMonitor.NerdStatus = NM_Connecting; wm.setCaptivePortalEnable(false); // disable captive portal redirection - if (!wm.autoConnect(Settings.WifiSSID, Settings.WifiPW)) + if (!wm.autoConnect(Settings.WifiSSID.c_str(), Settings.WifiPW.c_str())) { Serial.println("Failed to connect and hit timeout"); //delay(3000); @@ -210,7 +212,8 @@ void init_WifiManager() // Lets deal with the user config values // Copy the string value - strncpy(Settings.PoolAddress, pool_text_box.getValue(), sizeof(Settings.PoolAddress)); + Settings.PoolAddress = pool_text_box.getValue(); + //strncpy(Settings.PoolAddress, pool_text_box.getValue(), sizeof(Settings.PoolAddress)); Serial.print("PoolString: "); Serial.println(Settings.PoolAddress); From 0f65433875a4164064da88f832f12b84e4c4a17c Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Wed, 20 Sep 2023 19:42:07 +0200 Subject: [PATCH 02/11] restore old keys in SPIFFS --- README.md | 4 ++-- src/drivers/storage/nvMemory.cpp | 26 +++++++++++++------------- src/drivers/storage/storage.h | 23 ++++++++++++++++++----- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index dd37a9c..53ad837 100644 --- a/README.md +++ b/README.md @@ -90,12 +90,12 @@ After programming, you will only need to setup your Wifi and BTC address. 1. Create a file named "config.json" in your card's root, containing the the following structure. Adjust the settings to your needs: { "SSID": "myWifiSSID", - "PW": "myWifiPassword", + "WifiPW": "myWifiPassword", "PoolUrl": "public-pool.io", "PoolPort": 21496, "BtcWallet": "walletID", "Timezone": 2, - "saveStats": false + "SaveStats": false } 1. Insert the SD card. 1. Hold down the "reset configurations" button as described below to reset the configurations and/or boot without settings in your nvmemory. diff --git a/src/drivers/storage/nvMemory.cpp b/src/drivers/storage/nvMemory.cpp index 0f737aa..cc5f997 100644 --- a/src/drivers/storage/nvMemory.cpp +++ b/src/drivers/storage/nvMemory.cpp @@ -29,11 +29,11 @@ bool nvMemory::saveConfig(TSettings* Settings) // Create a JSON document StaticJsonDocument<512> json; - json[JSON_KEY_POOLURL] = Settings->PoolAddress; - json[JSON_KEY_POOLPORT] = Settings->PoolPort; - json[JSON_KEY_WALLETID] = Settings->BtcWallet; - json[JSON_KEY_TIMEZONE] = Settings->Timezone; - json[JSON_KEY_STATS2NV] = Settings->saveStats; + json[JSON_SPIFFS_KEY_POOLURL] = Settings->PoolAddress; + json[JSON_SPIFFS_KEY_POOLPORT] = Settings->PoolPort; + json[JSON_SPIFFS_KEY_WALLETID] = Settings->BtcWallet; + json[JSON_SPIFFS_KEY_TIMEZONE] = Settings->Timezone; + json[JSON_SPIFFS_KEY_STATS2NV] = Settings->saveStats; // Open config file File configFile = SPIFFS.open(JSON_CONFIG_FILE, "w"); @@ -84,14 +84,14 @@ bool nvMemory::loadConfig(TSettings* Settings) Serial.print('\n'); if (!error) { - Settings->PoolAddress = json[JSON_KEY_POOLURL] | Settings->PoolAddress; - strcpy(Settings->BtcWallet, json[JSON_KEY_WALLETID] | Settings->BtcWallet); - if (json.containsKey(JSON_KEY_POOLPORT)) - Settings->PoolPort = json[JSON_KEY_POOLPORT].as(); - if (json.containsKey(JSON_KEY_TIMEZONE)) - Settings->Timezone = json[JSON_KEY_TIMEZONE].as(); - if (json.containsKey(JSON_KEY_STATS2NV)) - Settings->saveStats = json[JSON_KEY_STATS2NV].as(); + Settings->PoolAddress = json[JSON_SPIFFS_KEY_POOLURL] | Settings->PoolAddress; + strcpy(Settings->BtcWallet, json[JSON_SPIFFS_KEY_WALLETID] | Settings->BtcWallet); + if (json.containsKey(JSON_SPIFFS_KEY_POOLPORT)) + Settings->PoolPort = json[JSON_SPIFFS_KEY_POOLPORT].as(); + if (json.containsKey(JSON_SPIFFS_KEY_TIMEZONE)) + Settings->Timezone = json[JSON_SPIFFS_KEY_TIMEZONE].as(); + if (json.containsKey(JSON_SPIFFS_KEY_STATS2NV)) + Settings->saveStats = json[JSON_SPIFFS_KEY_STATS2NV].as(); return true; } else diff --git a/src/drivers/storage/storage.h b/src/drivers/storage/storage.h index 5da92e3..76e80cd 100644 --- a/src/drivers/storage/storage.h +++ b/src/drivers/storage/storage.h @@ -3,6 +3,9 @@ #include +// config files + +// default settings #define DEFAULT_SSID "NerdMinerAP" #define DEFAULT_WIFIPW "MineYourCoins" #define DEFAULT_POOLURL "public-pool.io" @@ -11,16 +14,26 @@ #define DEFAULT_TIMEZONE 2 #define DEFAULT_SAVESTATS false -// JSON config file -#define JSON_CONFIG_FILE "/config.json" -#define JSON_KEY_SSID "SSID" -#define JSON_KEY_PASW "PW" +// JSON config files +#define JSON_CONFIG_FILE "/config.json" + +// JSON config file SD card (for user interaction, readme.md) +#define JSON_KEY_SSID "SSID" +#define JSON_KEY_PASW "WifiPW" #define JSON_KEY_POOLURL "PoolUrl" #define JSON_KEY_WALLETID "BtcWallet" #define JSON_KEY_POOLPORT "PoolPort" #define JSON_KEY_TIMEZONE "Timezone" -#define JSON_KEY_STATS2NV "saveStats" +#define JSON_KEY_STATS2NV "SaveStats" +// JSON config file SPIFFS (different for backward compatibility with existing devices) +#define JSON_SPIFFS_KEY_POOLURL "poolString" +#define JSON_SPIFFS_KEY_POOLPORT "portNumber" +#define JSON_SPIFFS_KEY_WALLETID "btcString" +#define JSON_SPIFFS_KEY_TIMEZONE "gmtZone" +#define JSON_SPIFFS_KEY_STATS2NV "saveStatsToNVS" + +// settings struct TSettings { String WifiSSID{ DEFAULT_SSID }; From 9e819923c8a9380a075b61976e05e4cc67e559d7 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Thu, 21 Sep 2023 17:02:15 +0200 Subject: [PATCH 03/11] add version (fix build error), improve readability --- platformio.ini | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/platformio.ini b/platformio.ini index a66d3a5..cf41920 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,6 +12,8 @@ globallib_dir = lib default_envs = esp32cam, ESP32-2432S028R, NerminerV2, ESP32-devKitv1, NerminerV2-S3-DONGLE, NerminerV2-S3-AMOLED, NerminerV2-T-QT, NerdminerV2-T-Display_V1, ESP32-2432S028R +;-------------------------------------------------------------------- + [env:NerminerV2] platform = espressif32 board = esp32-s3-devkitc-1 @@ -38,11 +40,13 @@ build_flags = lib_deps = https://github.com/takkaO/OpenFontRender bblanchon/ArduinoJson@^6.21.2 - https://github.com/tzapu/WiFiManager.git + https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2 mathertel/OneButton @ ^2.0.3 arduino-libraries/NTPClient ;https://github.com/golden-guy/Arduino_wolfssl.git#v5.5.4 +;-------------------------------------------------------------------- + [env:ESP32-devKitv1] platform = espressif32 board = esp32dev @@ -62,10 +66,12 @@ build_flags = lib_deps = https://github.com/takkaO/OpenFontRender bblanchon/ArduinoJson@^6.21.2 - https://github.com/tzapu/WiFiManager.git + https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2 mathertel/OneButton @ ^2.0.3 arduino-libraries/NTPClient +;-------------------------------------------------------------------- + [env:TTGO-T-Display] platform = espressif32 board = esp32dev ;esp-wrover-kit @@ -85,11 +91,13 @@ build_flags = lib_deps = https://github.com/takkaO/OpenFontRender bblanchon/ArduinoJson@^6.21.2 - https://github.com/tzapu/WiFiManager.git + https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2 mathertel/OneButton @ ^2.0.3 arduino-libraries/NTPClient ;https://github.com/golden-guy/Arduino_wolfssl.git#v5.5.4 +;-------------------------------------------------------------------- + [env:NerminerV2-S3-AMOLED] platform = espressif32 board = lilygo-t-amoled @@ -102,11 +110,13 @@ build_flags = lib_deps = https://github.com/takkaO/OpenFontRender bblanchon/ArduinoJson@^6.21.2 - https://github.com/tzapu/WiFiManager.git + https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2 mathertel/OneButton @ ^2.0.3 arduino-libraries/NTPClient https://github.com/golden-guy/Arduino_wolfssl.git#v5.5.4 +;-------------------------------------------------------------------- + [env:NerminerV2-S3-DONGLE] platform = espressif32 board = esp32-s3-devkitc-1 @@ -119,12 +129,14 @@ build_flags = lib_deps = https://github.com/takkaO/OpenFontRender bblanchon/ArduinoJson@^6.21.2 - https://github.com/tzapu/WiFiManager.git + https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2 mathertel/OneButton @ ^2.0.3 arduino-libraries/NTPClient https://github.com/FastLED/FastLED ;https://github.com/golden-guy/Arduino_wolfssl.git#v5.5.4 +;-------------------------------------------------------------------- + [env:esp32cam] platform = espressif32 ;(ESP32-D0WD-V3) board = esp32cam @@ -136,18 +148,23 @@ monitor_filters = monitor_speed = 115200 upload_speed = 921600 board_build.partitions = huge_app.csv +board_build.arduino.memory_type = dio_qspi build_flags = -D ESP32_CAM + -D BOARD_HAS_PSRAM -D MONITOR_SPEED=${this.monitor_speed} + ;-D DEBUG_MINING + ;-D DEBUG_MEMORY lib_deps = - ;https://github.com/takkaO/OpenFontRender bblanchon/ArduinoJson@^6.21.2 - https://github.com/tzapu/WiFiManager.git + https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2 mathertel/OneButton @ ^2.0.3 arduino-libraries/NTPClient lib_ignore = TFT_eSPI +;-------------------------------------------------------------------- + [env:NerminerV2-T-QT] platform = espressif32 board = esp32-s3-t-qt-pro @@ -167,10 +184,12 @@ build_flags = lib_deps = https://github.com/takkaO/OpenFontRender bblanchon/ArduinoJson@^6.21.2 - https://github.com/tzapu/WiFiManager.git + https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2 mathertel/OneButton @ ^2.0.3 arduino-libraries/NTPClient - + +;-------------------------------------------------------------------- + [env:ESP32-2432S028R] platform = espressif32 board = esp32dev @@ -204,11 +223,13 @@ build_flags = lib_deps = https://github.com/takkaO/OpenFontRender bblanchon/ArduinoJson@^6.21.2 - https://github.com/tzapu/WiFiManager.git + https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2 mathertel/OneButton @ ^2.0.3 arduino-libraries/NTPClient bodmer/TFT_eSPI @ ^2.5.31 +;-------------------------------------------------------------------- + [env:NerdminerV2-T-Display_V1] platform = espressif32 board = ttgo-lora32-v1 @@ -226,7 +247,6 @@ build_flags = lib_deps = https://github.com/takkaO/OpenFontRender bblanchon/ArduinoJson@^6.21.2 - https://github.com/tzapu/WiFiManager.git + https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2 mathertel/OneButton @ ^2.0.3 https://github.com/arduino-libraries/NTPClient - From 71d539bc5c366feaa648a2356a50cb8b3e0bebcc Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Wed, 20 Sep 2023 20:12:05 +0200 Subject: [PATCH 04/11] debug_mem: print min free heap --- src/mining.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mining.cpp b/src/mining.cpp index 0b7dccb..f8ca70e 100644 --- a/src/mining.cpp +++ b/src/mining.cpp @@ -116,7 +116,7 @@ void runStratumWorker(void *name) { Serial.printf("\n[WORKER] Started. Running %s on core %d\n", (char *)name, xPortGetCoreID()); #ifdef DEBUG_MEMORY - Serial.printf("### [Total Heap / Free heap]: %d / %d \n", ESP.getHeapSize(), ESP.getFreeHeap()); + Serial.printf("### [Total Heap / Free heap / Min free heap]: %d / %d / %d \n", ESP.getHeapSize(), ESP.getFreeHeap(), ESP.getMinFreeHeap()); #endif // connect to pool @@ -452,7 +452,7 @@ void runMonitor(void *name) } #ifdef DEBUG_MEMORY - Serial.printf("### [Total Heap / Free heap]: %d / %d \n", ESP.getHeapSize(), ESP.getFreeHeap()); + Serial.printf("### [Total Heap / Free heap / Min free heap]: %d / %d / %d \n", ESP.getHeapSize(), ESP.getFreeHeap(), ESP.getMinFreeHeap()); Serial.printf("### Max stack usage: %d\n", uxTaskGetStackHighWaterMark(NULL)); #endif From 7c5ec51abbd32c1d3ee56f1ddcf2342f8fedc03e Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Thu, 21 Sep 2023 17:19:53 +0200 Subject: [PATCH 05/11] add spi access to sd card --- src/drivers/devices/esp32CAM.h | 20 ++++++++++++++++- src/drivers/storage/SDCard.cpp | 41 ++++++++++++++++++++++++---------- src/drivers/storage/SDCard.h | 23 ++++++++++++++++--- 3 files changed, 68 insertions(+), 16 deletions(-) diff --git a/src/drivers/devices/esp32CAM.h b/src/drivers/devices/esp32CAM.h index 54d7460..f58bd6d 100644 --- a/src/drivers/devices/esp32CAM.h +++ b/src/drivers/devices/esp32CAM.h @@ -6,7 +6,14 @@ #define NO_DISPLAY -// SDMMC interface: 1-bit mode (might cause issues): +// example how to configure SD card. +// if you would define everything, +// to select 1 bit mode, make sure SDMMC_D1-3 are undefined +// to use spi mode, make sure all SDMMC_x pins are undefined + +/* +// use SDMMC interface: +// 1-bit mode (might cause issues): #define SDMMC_CLK 14 #define SDMMC_CMD 15 #define SDMMC_D0 2 @@ -14,5 +21,16 @@ #define SDMMC_D1 4 #define SDMMC_D2 12 #define SDMMC_D3 13 +*/ + +// use SPI interface +// (default SPI unit provided by ) +// setup SPI pins. +#define SDSPI_CS 13 +// The following pins will be ignored, if a tft display is set up. (!defined NO_DISPLAY) +// check display settings to find the appropriate lines. +#define SDSPI_CLK 14 +#define SDSPI_MOSI 15 +#define SDSPI_MISO 2 #endif // _ESP32_CAM_H_ diff --git a/src/drivers/storage/SDCard.cpp b/src/drivers/storage/SDCard.cpp index d4bd273..e852bf0 100644 --- a/src/drivers/storage/SDCard.cpp +++ b/src/drivers/storage/SDCard.cpp @@ -9,16 +9,22 @@ #include "SDCard.h" #if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4) - #include +#elif defined (BUILD_SDSPI) +#include +#include +#endif // interface type + +#if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4) || defined (BUILD_SDSPI) SDCard::SDCard() { #if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4) iSD_ = &SD_MMC; #elif defined (BUILD_SDSPI) -#error You chose to run the sd card in SPI mode. This is not implemented yet. -#endif + ispi_ = &SPI; + iSD_ = &SD; +#endif // interface type } SDCard::~SDCard() @@ -94,6 +100,9 @@ bool SDCard::loadConfigFile(TSettings* Settings) void SDCard::unmount() { iSD_->end(); +#ifdef BUILD_SDSPI_SETUP + ispi_->end(); +#endif // BUILD_SDSPI_SETUP Serial.println("SDCard: Unmounted"); } @@ -111,19 +120,27 @@ bool SDCard::initSDcard() if (iSD_->cardType() == CARD_NONE) { iSD_->setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0, SDMMC_D1, SDMMC_D2, SDMMC_D3); - Serial.println("SDCard: 4-Bit Mode."); cardInitialized = iSD_->begin("/sd", false); + Serial.println("SDCard: 4-Bit Mode."); } #elif defined (BUILD_SDMMC_1) - #warning SDMMC : 1 - bit mode is not always working.If you experience issues, try other modes. - if (iSD_->cardType() == CARD_NONE) - { - iSD_->setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0); - Serial.println("SDCard: 1-Bit Mode."); - cardInitialized = iSD_->begin("/sd", true); - } + #warning SDMMC : 1 - bit mode is not always working. If you experience issues, try other modes. + if (iSD_->cardType() == CARD_NONE) + { + iSD_->setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0); + cardInitialized = iSD_->begin("/sd", true); + Serial.println("SDCard: 1-Bit Mode."); + } #elif defined (BUILD_SDSPI) -#error You chose to run the sd card in SPI mode. This is not implemented yet. + if (iSD_->cardType() == CARD_NONE) + { + #ifdef BUILD_SDSPI_SETUP + ispi_->end(); + ispi_->begin(SDSPI_CLK, SDSPI_MISO, SDSPI_MOSI, SDSPI_CS); + #endif //BUILD_SDSPI_SETUP + cardInitialized = iSD_->begin(SDSPI_CS, *ispi_); + Serial.println("SDCard: SPI mode."); + } #else Serial.println("SDCard: interface not available."); return false; diff --git a/src/drivers/storage/SDCard.h b/src/drivers/storage/SDCard.h index d1da16f..37d0bd4 100644 --- a/src/drivers/storage/SDCard.h +++ b/src/drivers/storage/SDCard.h @@ -5,14 +5,31 @@ #include "nvMemory.h" #include "..\devices\device.h" +// configuration example and description in /devices/esp32cam.h + +// select interface and options according to provided pins #if defined (SDMMC_D0) && defined (SDMMC_D1) && defined (SDMMC_D2) && defined (SDMMC_D3) #define BUILD_SDMMC_4 +#undef BUILD_SDMMC_1 +#undef BUILD_SDSPI #include +#warning SD card support in 4-Bit mode enabled! #elif defined (SDMMC_D0) && !(defined (SDMMC_D1) && defined (SDMMC_D2) && defined (SDMMC_D3)) #define BUILD_SDMMC_1 +#undef BUILD_SDMMC_4 +#undef BUILD_SDSPI #include -#else -#warning SD card support disabled! +#warning SD card support in 1-Bit mode enabled! +#elif defined (SDSPI_CS) +#undef BUILD_SDMMC_1 +#undef BUILD_SDMMC_4 +#define BUILD_SDSPI +#if defined (SDSPI_CLK) && defined (SDSPI_MOSI) && defined (SDSPI_MISO) && defined (NO_DISPLAY) +#define BUILD_SDSPI_SETUP +#endif // SPIPINS +#include +#include +#warning SD card support in SPI mode enabled! #endif // Handles the transfer of settings from sd card to nv memory (wifi credentials are handled by wifimanager) @@ -30,7 +47,7 @@ private: #if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4) fs::SDMMCFS* iSD_; #elif defined (BUILD_SDSPI) -#error You chose to run the SD card in SPI mode. This is not implemented yet. + SPIClass* ispi_; fs::SDFS* iSD_; #endif }; From 45dacd4f7843f65a9e4af64eefcd007668fcb16c Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Thu, 21 Sep 2023 17:22:57 +0200 Subject: [PATCH 06/11] add documentation --- src/drivers/storage/SDCard.cpp | 6 ++++++ src/drivers/storage/nvMemory.cpp | 15 +++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/drivers/storage/SDCard.cpp b/src/drivers/storage/SDCard.cpp index e852bf0..48a5c73 100644 --- a/src/drivers/storage/SDCard.cpp +++ b/src/drivers/storage/SDCard.cpp @@ -32,6 +32,9 @@ SDCard::~SDCard() unmount(); } +/// @brief Transfer settings from config file on a SD card to the device. +/// @param nvMemory* where to save +/// @param TSettings* passing a struct is required, to save memory void SDCard::SD2nvMemory(nvMemory* nvMem, TSettings* Settings) { if (loadConfigFile(Settings)) @@ -43,6 +46,9 @@ void SDCard::SD2nvMemory(nvMemory* nvMem, TSettings* Settings) } } +/// @brief Retreives settings from a config file on a SD card. +/// @param TSettings* Struct to update with new Settings +/// @return true on success bool SDCard::loadConfigFile(TSettings* Settings) { // Load existing configuration file diff --git a/src/drivers/storage/nvMemory.cpp b/src/drivers/storage/nvMemory.cpp index cc5f997..9467a72 100644 --- a/src/drivers/storage/nvMemory.cpp +++ b/src/drivers/storage/nvMemory.cpp @@ -9,10 +9,7 @@ #include "..\devices\device.h" #include "storage.h" -nvMemory::nvMemory() -{ - Initialized_ = false; -} +nvMemory::nvMemory() : Initialized_(false){}; nvMemory::~nvMemory() { @@ -20,6 +17,9 @@ nvMemory::~nvMemory() SPIFFS.end(); }; +/// @brief Save settings to config file on SPIFFS +/// @param TSettings* Settings to be saved. +/// @return true on success bool nvMemory::saveConfig(TSettings* Settings) { if (init()) @@ -60,6 +60,9 @@ bool nvMemory::saveConfig(TSettings* Settings) return false; } +/// @brief Load settings from config file located in SPIFFS. +/// @param TSettings* Struct to update with new settings. +/// @return true on success bool nvMemory::loadConfig(TSettings* Settings) { // Uncomment if we need to format filesystem @@ -113,12 +116,16 @@ bool nvMemory::loadConfig(TSettings* Settings) return false; } +/// @brief Delete config file from SPIFFS +/// @return true on successs bool nvMemory::deleteConfig() { Serial.println("SPIFS: Erasing config file.."); return SPIFFS.remove(JSON_CONFIG_FILE); //Borramos fichero } +/// @brief Prepare and mount SPIFFS +/// @return true on success bool nvMemory::init() { if (!Initialized_) From bfb01da2c8fb2e7ce38ac0ab94367b209efc7a3a Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Thu, 21 Sep 2023 18:03:22 +0200 Subject: [PATCH 07/11] add display to esp32cam --- lib/TFT_eSPI/User_Setup_Select.h | 3 ++ .../Setup212_ESP32Cam_DongleDisplay.h | 52 +++++++++++++++++++ platformio.ini | 3 +- src/drivers/devices/esp32CAM.h | 2 +- src/drivers/displays/dongleDisplayDriver.cpp | 7 +++ 5 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 lib/TFT_eSPI/User_Setups/Setup212_ESP32Cam_DongleDisplay.h diff --git a/lib/TFT_eSPI/User_Setup_Select.h b/lib/TFT_eSPI/User_Setup_Select.h index 185f994..2ebed60 100644 --- a/lib/TFT_eSPI/User_Setup_Select.h +++ b/lib/TFT_eSPI/User_Setup_Select.h @@ -149,6 +149,9 @@ #ifdef NERMINER_S3_DONGLE #include // For the LilyGo T-Dongle S3 based ESP32 with ST7735 80 x 160 TFT #endif +#ifdef ESP32_CAM +#include // For the LilyGo T-Dongle S3 based ESP32 with ST7735 80 x 160 TFT +#endif //#include // Setup file for Bw16-based boards with ST7735 160 x 80 TFT //#include // Template file for a setup diff --git a/lib/TFT_eSPI/User_Setups/Setup212_ESP32Cam_DongleDisplay.h b/lib/TFT_eSPI/User_Setups/Setup212_ESP32Cam_DongleDisplay.h new file mode 100644 index 0000000..1137fe2 --- /dev/null +++ b/lib/TFT_eSPI/User_Setups/Setup212_ESP32Cam_DongleDisplay.h @@ -0,0 +1,52 @@ +// Config for esp32cam, using dongledriver w ESP32 and ST7735 80 x 160 display +#define USER_SETUP_ID 212 + +#define ST7735_DRIVER // Configure all registers + +#define TFT_WIDTH 80 +#define TFT_HEIGHT 160 + +// #define ST7735_INITB +// #define ST7735_GREENTAB +// #define ST7735_GREENTAB2 +// #define ST7735_GREENTAB3 +// #define ST7735_GREENTAB128 // For 128 x 128 display +#define ST7735_GREENTAB160x80 // For 160 x 80 display (BGR, inverted, 26 offset) +// #define ST7735_REDTAB +//#define ST7735_BLACKTAB +// #define ST7735_REDTAB160x80 // For 160 x 80 display with 24 pixel offset + +//#define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue +#define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red + +//#define TFT_INVERSION_ON +//#define TFT_INVERSION_OFF + +// Generic ESP32 setup +#define TFT_MISO 2 +#define TFT_MOSI 15 +#define TFT_SCLK 14 +#define TFT_CS 12 +#define TFT_DC 16 +#define TFT_RST 4 // Connect reset to ensure display initialises + +#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH +#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters +#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters +#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm +#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:. +#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-. +//#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT +#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts + +#define SMOOTH_FONT + + +#define SPI_FREQUENCY 27000000 +//#define SPI_FREQUENCY 40000000 + +#define SPI_READ_FREQUENCY 20000000 + +//#define SPI_TOUCH_FREQUENCY 2500000 + +// #define SUPPORT_TRANSACTIONS \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index cf41920..aa07a60 100644 --- a/platformio.ini +++ b/platformio.ini @@ -160,8 +160,9 @@ lib_deps = https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2 mathertel/OneButton @ ^2.0.3 arduino-libraries/NTPClient + https://github.com/takkaO/OpenFontRender lib_ignore = - TFT_eSPI + ;TFT_eSPI ;-------------------------------------------------------------------- diff --git a/src/drivers/devices/esp32CAM.h b/src/drivers/devices/esp32CAM.h index f58bd6d..39d4391 100644 --- a/src/drivers/devices/esp32CAM.h +++ b/src/drivers/devices/esp32CAM.h @@ -4,7 +4,7 @@ #define PIN_BUTTON_1 0 #define LED_PIN 33 -#define NO_DISPLAY +#define DONGLE_DISPLAY // NO_DISPLAY // example how to configure SD card. // if you would define everything, diff --git a/src/drivers/displays/dongleDisplayDriver.cpp b/src/drivers/displays/dongleDisplayDriver.cpp index f6b4fe0..9e27d0f 100644 --- a/src/drivers/displays/dongleDisplayDriver.cpp +++ b/src/drivers/displays/dongleDisplayDriver.cpp @@ -9,7 +9,10 @@ #include "version.h" #include "monitor.h" #include "OpenFontRender.h" + +#ifdef USE_LED #include +#endif #define WIDTH 160 #define HEIGHT 80 @@ -26,6 +29,7 @@ OpenFontRender render; TFT_eSPI tft = TFT_eSPI(); TFT_eSprite background = TFT_eSprite(&tft); +#ifdef USE_LED #define MAX_BRIGHTNESS 16 #define SLOW_FADE 1; #define FAST_FADE 4; @@ -34,6 +38,7 @@ CRGB leds(0, 0, 0); int brightness = 0; int fadeDirection = 1; int fadeAmount = 0; +#endif // USE_LED extern monitor_data mMonitor; @@ -74,8 +79,10 @@ extern monitor_data mMonitor; void dongleDisplay_Init(void) { + #ifdef USE_LED FastLED.addLeds(&leds, 1); FastLED.show(); + #endif // USE_LED tft.init(); tft.setRotation(3); From 4e4c24f4049382b4213f6b42900e03b76d50ec86 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Fri, 22 Sep 2023 01:34:28 +0200 Subject: [PATCH 08/11] update SD spi access --- src/NerdMinerV2.ino.cpp | 4 +- src/drivers/devices/esp32CAM.h | 4 +- src/drivers/storage/SDCard.cpp | 138 ++++++++++++++++++--------------- src/drivers/storage/SDCard.h | 62 +++++++++------ src/wManager.cpp | 3 +- 5 files changed, 122 insertions(+), 89 deletions(-) diff --git a/src/NerdMinerV2.ino.cpp b/src/NerdMinerV2.ino.cpp index 9904d15..95a4359 100644 --- a/src/NerdMinerV2.ino.cpp +++ b/src/NerdMinerV2.ino.cpp @@ -11,6 +11,7 @@ #include "mining.h" #include "monitor.h" #include "drivers/displays/display.h" +#include "drivers/storage/SDCard.h" //3 seconds WDT #define WDT_TIMEOUT 3 @@ -25,9 +26,10 @@ OneButton button2(PIN_BUTTON_2); #endif - extern monitor_data mMonitor; +SDCard SDCrd = SDCard(); + /**********************⚡ GLOBAL Vars *******************************/ unsigned long start = millis(); diff --git a/src/drivers/devices/esp32CAM.h b/src/drivers/devices/esp32CAM.h index 39d4391..2949491 100644 --- a/src/drivers/devices/esp32CAM.h +++ b/src/drivers/devices/esp32CAM.h @@ -27,8 +27,8 @@ // (default SPI unit provided by ) // setup SPI pins. #define SDSPI_CS 13 -// The following pins will be ignored, if a tft display is set up. (!defined NO_DISPLAY) -// check display settings to find the appropriate lines. +// The following pins can be retreived from the TFT_eSPI lib, +// if a display that is using it is activated. #define SDSPI_CLK 14 #define SDSPI_MOSI 15 #define SDSPI_MISO 2 diff --git a/src/drivers/storage/SDCard.cpp b/src/drivers/storage/SDCard.cpp index 48a5c73..89eb984 100644 --- a/src/drivers/storage/SDCard.cpp +++ b/src/drivers/storage/SDCard.cpp @@ -1,4 +1,3 @@ - #include #include #include @@ -7,6 +6,7 @@ #include "nvMemory.h" #include "..\devices\device.h" #include "SDCard.h" +//#include "..\lib\TFT_eSPI\User_Setup_Select.h" #if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4) #include @@ -17,19 +17,43 @@ #if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4) || defined (BUILD_SDSPI) -SDCard::SDCard() +/// @param int ID only relevant in SPI mode, if you want to use a non standard SPI Unit. +SDCard::SDCard(int ID):cardInitialized_(false),cardBusy_(false) { #if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4) iSD_ = &SD_MMC; #elif defined (BUILD_SDSPI) - ispi_ = &SPI; + if(ID>=0) + { + ispi_ = new SPIClass(ID); + newInstance_ = true; + } + else + { + ispi_ = &SPI; + newInstance_ = false; + } iSD_ = &SD; #endif // interface type +initSDcard(); } SDCard::~SDCard() { - unmount(); + iSD_->end(); + if(newInstance_) + { + ispi_->end(); + delete ispi_; + } + Serial.println("SDCard: Unmounted"); +} + +/// @brief Check if the card is accessed right now. +/// @return true if active +bool SDCard::cardBusy() +{ + return !cardBusy_; } /// @brief Transfer settings from config file on a SD card to the device. @@ -54,7 +78,7 @@ bool SDCard::loadConfigFile(TSettings* Settings) // Load existing configuration file // Read configuration from FS json - if (initSDcard()) + if (cardAvailable()) { if (iSD_->exists(JSON_CONFIG_FILE)) { @@ -62,15 +86,16 @@ bool SDCard::loadConfigFile(TSettings* Settings) File configFile = iSD_->open(JSON_CONFIG_FILE, "r"); if (configFile) { + cardBusy_ = true; StaticJsonDocument<512> json; DeserializationError error = deserializeJson(json, configFile); configFile.close(); + cardBusy_ = false; Serial.println("SDCard: Loading config file"); - serializeJsonPretty(json, Serial); - Serial.print('\n'); - unmount(); if (!error) { + serializeJsonPretty(json, Serial); + Serial.print('\n'); Settings->WifiSSID = json[JSON_KEY_SSID] | Settings->WifiSSID; Settings->WifiPW = json[JSON_KEY_PASW] | Settings->WifiPW; Settings->PoolAddress = json[JSON_KEY_POOLURL] | Settings->PoolAddress; @@ -98,82 +123,71 @@ bool SDCard::loadConfigFile(TSettings* Settings) { Serial.println("SDCard: No config file available!"); } - unmount(); } return false; } -void SDCard::unmount() +/// @brief Check if a SD card is inserted. +/// @return true if inserted. +bool SDCard::cardAvailable() { - iSD_->end(); -#ifdef BUILD_SDSPI_SETUP - ispi_->end(); -#endif // BUILD_SDSPI_SETUP - Serial.println("SDCard: Unmounted"); -} - -bool SDCard::initSDcard() -{ - if (iSD_->cardType() != CARD_NONE) - { - Serial.println("SDCard: Already mounted."); - return true; - } - Serial.println("SDCard: Mounting card."); - - bool cardInitialized = false; -#if defined (BUILD_SDMMC_4) - if (iSD_->cardType() == CARD_NONE) - { - iSD_->setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0, SDMMC_D1, SDMMC_D2, SDMMC_D3); - cardInitialized = iSD_->begin("/sd", false); - Serial.println("SDCard: 4-Bit Mode."); - } -#elif defined (BUILD_SDMMC_1) - #warning SDMMC : 1 - bit mode is not always working. If you experience issues, try other modes. - if (iSD_->cardType() == CARD_NONE) - { - iSD_->setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0); - cardInitialized = iSD_->begin("/sd", true); - Serial.println("SDCard: 1-Bit Mode."); - } -#elif defined (BUILD_SDSPI) - if (iSD_->cardType() == CARD_NONE) - { - #ifdef BUILD_SDSPI_SETUP - ispi_->end(); - ispi_->begin(SDSPI_CLK, SDSPI_MISO, SDSPI_MOSI, SDSPI_CS); - #endif //BUILD_SDSPI_SETUP - cardInitialized = iSD_->begin(SDSPI_CS, *ispi_); - Serial.println("SDCard: SPI mode."); - } -#else - Serial.println("SDCard: interface not available."); - return false; -#endif // dataPinsDefined - if (cardInitialized) + if (cardInitialized_) { if (iSD_->cardType() != CARD_NONE) { - Serial.println("SDCard: Mounted."); + Serial.println("SDCard: Inserted."); return true; } else { - Serial.println("SDCard: Mounting failed."); - iSD_->end(); + Serial.println("SDCard: Not inserted."); } } + else + { + Serial.println("SDCard: Interface not initialized."); + } return false; } +/// @brief Init SD card interface. Normaly not required, as this is called by the constructor. +/// @return true on success +bool SDCard::initSDcard() +{ + if (!cardAvailable()) + { + Serial.println("SDCard: init SD card interface."); +#if defined (BUILD_SDMMC_4) + iSD_->setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0, SDMMC_D1, SDMMC_D2, SDMMC_D3); + cardInitialized_ = iSD_->begin("/sd", false); + Serial.println("SDCard: 4-Bit Mode."); + } +#elif defined (BUILD_SDMMC_1) +#warning SDMMC : 1 - bit mode is not always working. If you experience issues, try other modes. + iSD_->setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0); + cardInitialized_ = iSD_->begin("/sd", true); + Serial.println("SDCard: 1-Bit Mode."); + } +#elif defined (BUILD_SDSPI) + ispi_->begin(SDSPI_CLK, SDSPI_MISO, SDSPI_MOSI, SDSPI_CS); + cardInitialized_ = iSD_->begin(SDSPI_CS, *ispi_); + Serial.println("SDCard: SPI mode."); + } +#else + Serial.println("SDCard: interface not defined."); + return false; +#endif // dataPinsDefined + cardAvailable(); + return cardInitialized_; +} + #else -SDCard::SDCard() {} +SDCard::SDCard(int ID) {} SDCard::~SDCard() {} void SDCard::SD2nvMemory(nvMemory* nvMem, TSettings* Settings) {}; bool SDCard::loadConfigFile(TSettings* Settings) { return false; } bool SDCard::initSDcard() { return false; } -void unmount() {} +bool SDCard::cardAvailable() { return false; } #endif //BUILD_SDMMC \ No newline at end of file diff --git a/src/drivers/storage/SDCard.h b/src/drivers/storage/SDCard.h index 37d0bd4..775adbb 100644 --- a/src/drivers/storage/SDCard.h +++ b/src/drivers/storage/SDCard.h @@ -9,46 +9,62 @@ // select interface and options according to provided pins #if defined (SDMMC_D0) && defined (SDMMC_D1) && defined (SDMMC_D2) && defined (SDMMC_D3) -#define BUILD_SDMMC_4 -#undef BUILD_SDMMC_1 -#undef BUILD_SDSPI -#include -#warning SD card support in 4-Bit mode enabled! + #define BUILD_SDMMC_4 + #undef BUILD_SDMMC_1 + #undef BUILD_SDSPI + #include + #warning SD card support in 4-Bit mode enabled! #elif defined (SDMMC_D0) && !(defined (SDMMC_D1) && defined (SDMMC_D2) && defined (SDMMC_D3)) -#define BUILD_SDMMC_1 -#undef BUILD_SDMMC_4 -#undef BUILD_SDSPI -#include -#warning SD card support in 1-Bit mode enabled! + #define BUILD_SDMMC_1 + #undef BUILD_SDMMC_4 + #undef BUILD_SDSPI + #include + #warning SD card support in 1-Bit mode enabled! #elif defined (SDSPI_CS) -#undef BUILD_SDMMC_1 -#undef BUILD_SDMMC_4 -#define BUILD_SDSPI -#if defined (SDSPI_CLK) && defined (SDSPI_MOSI) && defined (SDSPI_MISO) && defined (NO_DISPLAY) -#define BUILD_SDSPI_SETUP -#endif // SPIPINS -#include -#include -#warning SD card support in SPI mode enabled! + #undef BUILD_SDMMC_1 + #undef BUILD_SDMMC_4 + #define BUILD_SDSPI + + #include + #include + #include "..\lib\TFT_eSPI\User_Setup_Select.h" + + #ifndef NO_DISPLAY + #if !defined(SDSPI_CLK) && defined(TFT_CLK) + #define SDSPI_CLK TFT_CLK + #endif // SDSPI_CLK + #if !defined(SDSPI_MOSI) && defined(TFT_MOSI) + #define SDSPI_MOSI TFT_MOSI + #endif // SDSPI_MOSI + #if !defined(SDSPI_MISO) && defined(TFT_MISO) + #define SDSPI_MISO TFT_MISO + #endif // SDSPI_MISO + #elif !defined(SDSPI_CLK) || !defined(SDSPI_MOSI) || !defined(SDSPI_MISO) + #error: Please define SDSPI pins! + #endif // NO_DISPLAY + + #warning SD card support in SPI mode enabled! #endif -// Handles the transfer of settings from sd card to nv memory (wifi credentials are handled by wifimanager) class SDCard { public: - SDCard(); + SDCard(int ID=-1); ~SDCard(); void SD2nvMemory(nvMemory* nvMem, TSettings* Settings); bool loadConfigFile(TSettings* Settings); + bool cardAvailable(); + bool cardBusy(); private: bool initSDcard(); - void unmount(); - + bool cardInitialized_; + bool cardBusy_; #if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4) fs::SDMMCFS* iSD_; #elif defined (BUILD_SDSPI) SPIClass* ispi_; fs::SDFS* iSD_; + bool newInstance_; #endif }; diff --git a/src/wManager.cpp b/src/wManager.cpp index bd89146..41ebff3 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -27,6 +27,8 @@ extern monitor_data mMonitor; nvMemory nvMem; +extern SDCard SDCrd; + void saveConfigCallback() // Callback notifying us of the need to save configuration { @@ -87,7 +89,6 @@ void init_WifiManager() if (!nvMem.loadConfig(&Settings)) { //No config file on internal flash. - SDCard SDCrd; if (SDCrd.loadConfigFile(&Settings)) { //Config file on SD card. From 02202e1361e28a48ddb4589a8cc7729c08ec83c2 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Fri, 22 Sep 2023 01:36:10 +0200 Subject: [PATCH 09/11] update cam display --- .../User_Setups/Setup212_ESP32Cam_DongleDisplay.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/TFT_eSPI/User_Setups/Setup212_ESP32Cam_DongleDisplay.h b/lib/TFT_eSPI/User_Setups/Setup212_ESP32Cam_DongleDisplay.h index 1137fe2..f248b13 100644 --- a/lib/TFT_eSPI/User_Setups/Setup212_ESP32Cam_DongleDisplay.h +++ b/lib/TFT_eSPI/User_Setups/Setup212_ESP32Cam_DongleDisplay.h @@ -26,9 +26,13 @@ #define TFT_MISO 2 #define TFT_MOSI 15 #define TFT_SCLK 14 -#define TFT_CS 12 -#define TFT_DC 16 -#define TFT_RST 4 // Connect reset to ensure display initialises +#define TFT_CS 12 +#define TFT_DC 0 +#define TFT_RST 22 // Connect reset to ensure display initialises (not really required). + +#if (TFT_MISO == 16) || (TFT_MOSI == 16)|| (TFT_SCLK == 16)|| (TFT_CS == 16)|| (TFT_DC == 16)|| (TFT_RST == 16) +#warning: Using GPIO16 for display might crash on initializing the display! +#endif #define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH #define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters From fce8135b9c04812add0806ac77f712089d28724b Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Wed, 27 Sep 2023 17:45:37 +0200 Subject: [PATCH 10/11] fix --- src/drivers/storage/SDCard.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/drivers/storage/SDCard.cpp b/src/drivers/storage/SDCard.cpp index 89eb984..9fbab53 100644 --- a/src/drivers/storage/SDCard.cpp +++ b/src/drivers/storage/SDCard.cpp @@ -6,7 +6,6 @@ #include "nvMemory.h" #include "..\devices\device.h" #include "SDCard.h" -//#include "..\lib\TFT_eSPI\User_Setup_Select.h" #if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4) #include @@ -17,7 +16,7 @@ #if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4) || defined (BUILD_SDSPI) -/// @param int ID only relevant in SPI mode, if you want to use a non standard SPI Unit. +/// @param int ID only relevant in SPI mode, if you want to set up a custom SPI unit. Ignored in SD bus mode. SDCard::SDCard(int ID):cardInitialized_(false),cardBusy_(false) { #if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4) @@ -35,7 +34,7 @@ SDCard::SDCard(int ID):cardInitialized_(false),cardBusy_(false) } iSD_ = &SD; #endif // interface type -initSDcard(); + initSDcard(); } SDCard::~SDCard() @@ -53,7 +52,7 @@ SDCard::~SDCard() /// @return true if active bool SDCard::cardBusy() { - return !cardBusy_; + return cardBusy_; } /// @brief Transfer settings from config file on a SD card to the device. @@ -189,5 +188,6 @@ void SDCard::SD2nvMemory(nvMemory* nvMem, TSettings* Settings) {}; bool SDCard::loadConfigFile(TSettings* Settings) { return false; } bool SDCard::initSDcard() { return false; } bool SDCard::cardAvailable() { return false; } +bool SDCard::cardBusy() { return false; } -#endif //BUILD_SDMMC \ No newline at end of file +#endif //BUILD_SDMMC From a587c131abf6f124d47df9fb30c5444c8b993cb9 Mon Sep 17 00:00:00 2001 From: elmo128 <60213508+elmo128@users.noreply.github.com> Date: Thu, 28 Sep 2023 06:05:45 +0200 Subject: [PATCH 11/11] Update SDCard.cpp fix --- src/drivers/storage/SDCard.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/drivers/storage/SDCard.cpp b/src/drivers/storage/SDCard.cpp index 9fbab53..2364106 100644 --- a/src/drivers/storage/SDCard.cpp +++ b/src/drivers/storage/SDCard.cpp @@ -40,11 +40,13 @@ SDCard::SDCard(int ID):cardInitialized_(false),cardBusy_(false) SDCard::~SDCard() { iSD_->end(); +#ifdef BUILD_SDSPI if(newInstance_) { ispi_->end(); delete ispi_; } +#endif // BUILD_SDSPI Serial.println("SDCard: Unmounted"); }