Add SD card initialization

raytac-diy
lewishe 2022-11-12 15:14:13 +08:00
rodzic cd95d0865f
commit 61ebdb3367
3 zmienionych plików z 53 dodań i 0 usunięć

Wyświetl plik

@ -1,6 +1,18 @@
#include "configuration.h"
#include "FSCommon.h"
#ifdef HAS_SDCARD
#include <SPI.h>
#include <SD.h>
#ifdef SDCARD_USE_SPI1
SPIClass SPI1(HSPI);
#define SDHandler SPI1
#endif
#endif //HAS_SDCARD
bool copyFile(const char* from, const char* to)
{
@ -169,3 +181,39 @@ void fsInit()
listDir("/", 10);
#endif
}
void setupSDCard()
{
#ifdef HAS_SDCARD
SDHandler.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
if (!SD.begin(SDCARD_CS, SDHandler)) {
DEBUG_MSG("No SD_MMC card detected\n");
return ;
}
uint8_t cardType = SD.cardType();
if (cardType == CARD_NONE) {
DEBUG_MSG("No SD_MMC card attached\n");
return ;
}
DEBUG_MSG("SD_MMC Card Type: ");
if (cardType == CARD_MMC) {
DEBUG_MSG("MMC\n");
} else if (cardType == CARD_SD) {
DEBUG_MSG("SDSC\n");
} else if (cardType == CARD_SDHC) {
DEBUG_MSG("SDHC\n");
} else {
DEBUG_MSG("UNKNOWN\n");
}
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
DEBUG_MSG("SD Card Size: %lluMB\n", cardSize);
DEBUG_MSG("Total space: %llu MB\n", SD.totalBytes() / (1024 * 1024));
DEBUG_MSG("Used space: %llu MB\n", SD.usedBytes() / (1024 * 1024));
#endif
}

Wyświetl plik

@ -44,3 +44,4 @@ bool copyFile(const char* from, const char* to);
bool renameFile(const char* pathFrom, const char* pathTo);
void listDir(const char * dirname, uint8_t levels, boolean del);
void rmDir(const char * dirname);
void setupSDCard();

Wyświetl plik

@ -254,6 +254,10 @@ void setup()
DEBUG_MSG("PCF8563 RTC found\n");
}
}
#ifdef HAS_SDCARD
setupSDCard();
#endif
#ifdef RAK4630
// scanEInkDevice();