You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.6 KiB
74 lines
1.6 KiB
/*
|
|
* SD card
|
|
*
|
|
* https://github.com/espressif/arduino-esp32/blob/master/libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino
|
|
* https://github.com/espressif/esp-idf/tree/master/examples/storage/sd_card
|
|
*/
|
|
|
|
#include "Arduino.h"
|
|
#include "FS.h"
|
|
#include "SD.h"
|
|
#include "SPI.h"
|
|
|
|
#include "hardware.h"
|
|
#include "sdcard.h"
|
|
#include "sound.h"
|
|
#include "datasource.h"
|
|
|
|
using namespace std;
|
|
|
|
static const char* TAG = "SDCard";
|
|
|
|
SDCard::SDCard() {
|
|
}
|
|
|
|
void SDCard::mount() {
|
|
pinMode(PIN_SD_CD, INPUT);
|
|
if (!digitalRead(PIN_SD_CD)) {
|
|
Serial.println("No card detected!");
|
|
}
|
|
if(!SD.begin(PIN_SD_CS)){
|
|
Serial.println("Card Mount Failed");
|
|
return;
|
|
}
|
|
this->cardType = SD.cardType();
|
|
|
|
if(this->cardType == CARD_NONE){
|
|
Serial.println("No SD card attached");
|
|
return;
|
|
}
|
|
|
|
Serial.print("SD_MMC Card Type: ");
|
|
if(this->cardType == CARD_MMC){
|
|
Serial.println("MMC");
|
|
} else if(this->cardType == CARD_SD){
|
|
Serial.println("SDSC");
|
|
} else if(this->cardType == CARD_SDHC){
|
|
Serial.println("SDHC");
|
|
} else {
|
|
Serial.println("UNKNOWN");
|
|
}
|
|
|
|
this->cardSize = SD.cardSize() / (1024 * 1024);
|
|
Serial.printf("SD_MMC Card Size: %lluMB\n", this->cardSize);
|
|
}
|
|
|
|
void SDCard::umount() {
|
|
SD.end();
|
|
}
|
|
|
|
File SDCard::open(const char* path) {
|
|
return SD.open(path);
|
|
}
|
|
|
|
void SDCard::close(File file) {
|
|
file.close();
|
|
}
|
|
|
|
bool SDCard::available(File file) {
|
|
return file.available();
|
|
}
|
|
|
|
size_t SDCard::read(File file, unsigned char* buffer, int length){
|
|
return file.read((uint8_t *)buffer, length);
|
|
}
|
|
|