SD card enable flag

This commit is contained in:
elmo128 2023-09-14 23:16:56 +02:00
parent ab48dbf5e3
commit 80618d3cdc
2 changed files with 130 additions and 110 deletions

View File

@ -6,6 +6,8 @@
#define NO_DISPLAY #define NO_DISPLAY
#define BUILD_SDMMC
#define SDMMC_CLK 14 #define SDMMC_CLK 14
#define SDMMC_CMD 15 #define SDMMC_CMD 15
#define SDMMC_D0 2 #define SDMMC_D0 2

View File

@ -1,34 +1,44 @@
#ifndef _SDCARD_H_ #ifndef _SDCARD_H_
#define _SDCARD_H_ #define _SDCARD_H_
#include <FS.h>
#include <SD_MMC.h>
#include <SD.h>
#include <ArduinoJson.h>
#include "..\drivers.h" #include "..\drivers.h"
#include "storage.h" #include "storage.h"
#include "SPIStorage.h" #include "SPIStorage.h"
class SDCard class SDCard
{ {
private:
bool cardInitialized_;
public: public:
SDCard() SDCard();
{ ~SDCard();
cardInitialized_ = false; void SD2SPIStorage(SPIStorage* spifs);
} bool loadConfigFile(TSettings* Settings);
private:
bool initSDcard();
~SDCard() bool cardInitialized_;
{ };
#ifdef BUILD_SDMMC
#include <FS.h>
#include <SD_MMC.h>
#include <ArduinoJson.h>
SDCard::SDCard()
{
cardInitialized_ = false;
}
SDCard::~SDCard()
{
if (cardInitialized_) if (cardInitialized_)
SD_MMC.end(); SD_MMC.end();
} }
void SD2SPIStorage(SPIStorage* spifs) void SDCard::SD2SPIStorage(SPIStorage* spifs)
{ {
TSettings Settings; TSettings Settings;
if (loadConfigFile(&Settings)) if (loadConfigFile(&Settings))
{ {
@ -37,10 +47,10 @@ public:
Serial.println("SDCard: Settings transfered to internal memory. Restarting now."); Serial.println("SDCard: Settings transfered to internal memory. Restarting now.");
ESP.restart(); ESP.restart();
} }
} }
bool loadConfigFile(TSettings* Settings) bool SDCard::loadConfigFile(TSettings* Settings)
{ {
// Load existing configuration file // Load existing configuration file
// Read configuration from FS json // Read configuration from FS json
Serial.println("SDCard: Mounting File System..."); Serial.println("SDCard: Mounting File System...");
@ -88,12 +98,10 @@ public:
SD_MMC.end(); SD_MMC.end();
} }
return false; return false;
} }
private: bool SDCard::initSDcard()
{
bool initSDcard()
{
if((cardInitialized_)&&(SD_MMC.cardType() != CARD_NONE)) if((cardInitialized_)&&(SD_MMC.cardType() != CARD_NONE))
{ {
Serial.println("SDCard: Already mounted."); Serial.println("SDCard: Already mounted.");
@ -129,7 +137,17 @@ private:
Serial.println("SDCard: No card found."); Serial.println("SDCard: No card found.");
return false; return false;
} }
} }
};
#else
SDCard::SDCard() {}
SDCard::~SDCard() {}
void SDCard::SD2SPIStorage(SPIStorage* spifs) {};
bool SDCard::loadConfigFile(TSettings* Settings) { return false; }
bool SDCard::initSDcard() { return false; }
#endif //BUILD_SDMMC
#endif // _SDCARD_H_ #endif // _SDCARD_H_