t-hmi fixed sdcard class for 1bit; lower freq for card detection

This commit is contained in:
cosmicpsyop 2024-05-29 14:29:49 -07:00
parent bc2dba69b1
commit e8ee3b80c2
4 changed files with 8 additions and 87 deletions

View File

@ -103,9 +103,9 @@ void setup()
doLedStuff(0); doLedStuff(0);
#ifdef NERDMINER_T_HMI #ifdef NERDMINER_T_HMI
extern void t_hmiCheckForSDCardAndMoveToNVM(void); SDCrd.initSDcard();
t_hmiCheckForSDCardAndMoveToNVM();
#endif #endif
/******** INIT WIFI ************/ /******** INIT WIFI ************/
init_WifiManager(); init_WifiManager();

View File

@ -37,88 +37,6 @@ extern monitor_data mMonitor;
extern pool_data pData; extern pool_data pData;
extern DisplayDriver *currentDisplayDriver; extern DisplayDriver *currentDisplayDriver;
/*=============================================*/
#include <FS.h>
#include <ArduinoJson.h>
#include <WiFi.h>
#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<int>();
if (json.containsKey(JSON_KEY_TIMEZONE))
pSettings->Timezone = json[JSON_KEY_TIMEZONE].as<int>();
if (json.containsKey(JSON_KEY_STATS2NV))
pSettings->saveStats = json[JSON_KEY_STATS2NV].as<bool>();
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) { uint32_t readAdcVoltage(int pin) {
esp_adc_cal_characteristics_t adc_chars; esp_adc_cal_characteristics_t adc_chars;

View File

@ -170,9 +170,7 @@ bool SDCard::initSDcard()
#warning SDMMC : 1 - bit mode is not always working. If you experience issues, try other modes. #warning SDMMC : 1 - bit mode is not always working. If you experience issues, try other modes.
iSD_->setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0); iSD_->setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0);
#ifdef NERDMINER_T_HMI #ifdef NERDMINER_T_HMI
// Need to lower frequency to 20000 // Need to lower frequency to 20000 for proper detection
// Should work but blows up in SDCard::initSDcard()
// see temporary workaround t_hmiCheckForSDCardAndMoveToNVM()
cardInitialized_ = iSD_->begin("/sd", true, false, 20000); cardInitialized_ = iSD_->begin("/sd", true, false, 20000);
#else #else
cardInitialized_ = iSD_->begin("/sd", true); cardInitialized_ = iSD_->begin("/sd", true);

View File

@ -58,8 +58,13 @@ public:
bool loadConfigFile(TSettings* Settings); bool loadConfigFile(TSettings* Settings);
bool cardAvailable(); bool cardAvailable();
bool cardBusy(); bool cardBusy();
#ifdef NERDMINER_T_HMI
bool initSDcard();
private:
#else
private: private:
bool initSDcard(); bool initSDcard();
#endif
bool cardInitialized_; bool cardInitialized_;
bool cardBusy_; bool cardBusy_;
#if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4) #if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4)