From e8ee3b80c2856aea2d03f5e044e0a09a8c559ebe Mon Sep 17 00:00:00 2001 From: cosmicpsyop Date: Wed, 29 May 2024 14:29:49 -0700 Subject: [PATCH] t-hmi fixed sdcard class for 1bit; lower freq for card detection --- src/NerdMinerV2.ino.cpp | 4 +- src/drivers/displays/t_hmiDisplayDriver.cpp | 82 --------------------- src/drivers/storage/SDCard.cpp | 4 +- src/drivers/storage/SDCard.h | 5 ++ 4 files changed, 8 insertions(+), 87 deletions(-) diff --git a/src/NerdMinerV2.ino.cpp b/src/NerdMinerV2.ino.cpp index b9f2f91..984d21f 100644 --- a/src/NerdMinerV2.ino.cpp +++ b/src/NerdMinerV2.ino.cpp @@ -103,9 +103,9 @@ void setup() doLedStuff(0); #ifdef NERDMINER_T_HMI - extern void t_hmiCheckForSDCardAndMoveToNVM(void); - t_hmiCheckForSDCardAndMoveToNVM(); + SDCrd.initSDcard(); #endif + /******** INIT WIFI ************/ init_WifiManager(); diff --git a/src/drivers/displays/t_hmiDisplayDriver.cpp b/src/drivers/displays/t_hmiDisplayDriver.cpp index a5b5285..c10f1f5 100644 --- a/src/drivers/displays/t_hmiDisplayDriver.cpp +++ b/src/drivers/displays/t_hmiDisplayDriver.cpp @@ -37,88 +37,6 @@ extern monitor_data mMonitor; extern pool_data pData; extern DisplayDriver *currentDisplayDriver; -/*=============================================*/ -#include -#include -#include -#include "drivers/storage/nvMemory.h" -#include "drivers/storage/SDCard.h" -extern nvMemory nvMem; -extern TSettings Settings; - -void t_hmiCheckForSDCardAndMoveToNVM(void) -{ - // workaround removing use of class SDCard - // SCard SDCrd = SDCard() blows up in SDCard::initSDcard() - // Need to lower frequency to 20000 - SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0); - delay(500); - bool rlst = SD_MMC.begin("/sd", true, false, 20000); - if (!rlst) - { - Serial.println("SD init failed"); - Serial.println("➸ No detected SdCard"); - } - else - { - Serial.println("SD init success"); - Serial.printf("➸ Detected SdCard insert: %.2f GB\r\n", SD_MMC.cardSize() / 1024.0 / 1024.0 / 1024.0); - - // SDCrd.SD2nvMemory(&nvMem, &Settings); - - if (SD_MMC.exists(JSON_CONFIG_FILE)) - { - // The file exists, reading and loading - File configFile = SD_MMC.open(JSON_CONFIG_FILE, "r"); - if (configFile) - { - StaticJsonDocument<512> json; - DeserializationError error = deserializeJson(json, configFile); - configFile.close(); - Serial.println("SDCard: Loading config file"); - if (!error) - { - serializeJsonPretty(json, Serial); - Serial.print('\n'); - TSettings *pSettings = &Settings; - pSettings->WifiSSID = json[JSON_KEY_SSID] | pSettings->WifiSSID; - pSettings->WifiPW = json[JSON_KEY_PASW] | pSettings->WifiPW; - pSettings->PoolAddress = json[JSON_KEY_POOLURL] | pSettings->PoolAddress; - strcpy(pSettings->PoolPassword, json[JSON_KEY_POOLPASS] | pSettings->PoolPassword); - strcpy(pSettings->BtcWallet, json[JSON_KEY_WALLETID] | pSettings->BtcWallet); - if (json.containsKey(JSON_KEY_POOLPORT)) - pSettings->PoolPort = json[JSON_KEY_POOLPORT].as(); - if (json.containsKey(JSON_KEY_TIMEZONE)) - pSettings->Timezone = json[JSON_KEY_TIMEZONE].as(); - if (json.containsKey(JSON_KEY_STATS2NV)) - pSettings->saveStats = json[JSON_KEY_STATS2NV].as(); - nvMem.saveConfig(pSettings); - WiFi.begin(pSettings->WifiSSID, pSettings->WifiPW); - Serial.println("SDCard: Settings transfered to internal memory. Restarting now."); - ESP.restart(); - } - else - { - // Error loading JSON data - Serial.println("SDCard: Error parsing config file!"); - } - } - else - { - Serial.println("SDCard: Error opening config file!"); - } - } - else - { - Serial.println("SDCard: No config file available!"); - } - // delay(15000); - SD_MMC.end(); - Serial.println("SD close"); - } -} -/*=============================================*/ - uint32_t readAdcVoltage(int pin) { esp_adc_cal_characteristics_t adc_chars; diff --git a/src/drivers/storage/SDCard.cpp b/src/drivers/storage/SDCard.cpp index a1cda51..99f88e5 100644 --- a/src/drivers/storage/SDCard.cpp +++ b/src/drivers/storage/SDCard.cpp @@ -170,9 +170,7 @@ bool SDCard::initSDcard() #warning SDMMC : 1 - bit mode is not always working. If you experience issues, try other modes. iSD_->setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0); #ifdef NERDMINER_T_HMI - // Need to lower frequency to 20000 - // Should work but blows up in SDCard::initSDcard() - // see temporary workaround t_hmiCheckForSDCardAndMoveToNVM() + // Need to lower frequency to 20000 for proper detection cardInitialized_ = iSD_->begin("/sd", true, false, 20000); #else cardInitialized_ = iSD_->begin("/sd", true); diff --git a/src/drivers/storage/SDCard.h b/src/drivers/storage/SDCard.h index a90deb3..5727875 100644 --- a/src/drivers/storage/SDCard.h +++ b/src/drivers/storage/SDCard.h @@ -58,8 +58,13 @@ public: bool loadConfigFile(TSettings* Settings); bool cardAvailable(); bool cardBusy(); +#ifdef NERDMINER_T_HMI + bool initSDcard(); +private: +#else private: bool initSDcard(); +#endif bool cardInitialized_; bool cardBusy_; #if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4)