|
-
- #ifndef SdFat_h
- #define SdFat_h
-
- #include "SdSpiCard.h"
- #include "utility/FatLib.h"
-
-
- #define SD_FAT_VERSION 20150201
-
-
- class SdBaseFile : public FatFile {
- public:
- SdBaseFile() {}
-
-
- SdBaseFile(const char* path, uint8_t oflag) : FatFile(path, oflag) {}
- };
- #if ENABLE_ARDUINO_FEATURES
-
-
- class SdFile : public PrintFile {
- public:
- SdFile() {}
-
-
- SdFile(const char* path, uint8_t oflag) : PrintFile(path, oflag) {}
- };
- #endif
-
- class SdFatBase : public FatFileSystem {
- public:
-
-
- bool begin(SdSpiCard::m_spi_t* spi, uint8_t csPin = SS, uint8_t divisor = 2) {
- return m_sdCard.begin(spi, csPin, divisor) &&
- FatFileSystem::begin();
- }
-
- SdSpiCard *card() {
- return &m_sdCard;
- }
-
- void errorHalt() {
- errorHalt(&Serial);
- }
-
-
- void errorHalt(Print* pr);
-
-
- void errorHalt(char const* msg) {
- errorHalt(&Serial, msg);
- }
-
-
- void errorHalt(Print* pr, char const* msg);
-
-
- void errorHalt(const __FlashStringHelper* msg) {
- errorHalt(&Serial, msg);
- }
-
-
- void errorHalt(Print* pr, const __FlashStringHelper* msg);
-
- void errorPrint() {
- errorPrint(&Serial);
- }
-
-
- void errorPrint(Print* pr);
-
-
- void errorPrint(const char* msg) {
- errorPrint(&Serial, msg);
- }
-
-
- void errorPrint(Print* pr, char const* msg);
-
-
- void errorPrint(const __FlashStringHelper* msg) {
- errorPrint(&Serial, msg);
- }
-
-
- void errorPrint(Print* pr, const __FlashStringHelper* msg);
-
-
- bool fsBegin() {
- return FatFileSystem::begin();
- }
-
- void initErrorHalt() {
- initErrorHalt(&Serial);
- }
-
-
- void initErrorHalt(Print* pr);
-
-
- void initErrorHalt(char const *msg) {
- initErrorHalt(&Serial, msg);
- }
-
-
- void initErrorHalt(Print* pr, char const *msg);
-
-
- void initErrorHalt(const __FlashStringHelper* msg) {
- initErrorHalt(&Serial, msg);
- }
-
-
- void initErrorHalt(Print* pr, const __FlashStringHelper* msg);
-
- void initErrorPrint() {
- initErrorPrint(&Serial);
- }
-
-
- void initErrorPrint(Print* pr);
-
-
- void initErrorPrint(char const *msg) {
- initErrorPrint(&Serial, msg);
- }
-
-
- void initErrorPrint(Print* pr, char const *msg);
-
-
- void initErrorPrint(const __FlashStringHelper* msg) {
- initErrorPrint(&Serial, msg);
- }
-
-
- void initErrorPrint(Print* pr, const __FlashStringHelper* msg);
-
- private:
- uint8_t cardErrorCode() {
- return m_sdCard.errorCode();
- }
- uint8_t cardErrorData() {
- return m_sdCard.errorData();
- }
- bool readBlock(uint32_t block, uint8_t* dst) {
- return m_sdCard.readBlock(block, dst);
- }
- bool writeBlock(uint32_t block, const uint8_t* src) {
- return m_sdCard.writeBlock(block, src);
- }
- bool readBlocks(uint32_t block, uint8_t* dst, size_t n) {
- return m_sdCard.readBlocks(block, dst, n);
- }
- bool writeBlocks(uint32_t block, const uint8_t* src, size_t n) {
- return m_sdCard.writeBlocks(block, src, n);
- }
- SdSpiCard m_sdCard;
- };
-
-
- class SdFat : public SdFatBase {
- public:
-
-
- bool begin(uint8_t csPin = SS, uint8_t divisor = 2) {
- return SdFatBase::begin(&m_spi, csPin, divisor);
- }
-
-
- bool cardBegin(uint8_t csPin = SS, uint8_t divisor = 2) {
- return card()->begin(&m_spi, csPin, divisor);
- }
- private:
- SpiDefault_t m_spi;
- };
-
- #if SD_SPI_CONFIGURATION >= 3 || defined(DOXYGEN)
-
- class SdFatLibSpi: public SdFatBase {
- public:
-
-
- bool begin(uint8_t csPin = SS, uint8_t divisor = 2) {
- return SdFatBase::begin(&m_spi, csPin, divisor);
- }
-
-
- bool cardBegin(uint8_t csPin = SS, uint8_t divisor = 2) {
- return card()->begin(&m_spi, csPin, divisor);
- }
-
- private:
- SdSpiLib m_spi;
- };
-
-
- template<uint8_t MisoPin, uint8_t MosiPin, uint8_t SckPin>
- class SdFatSoftSpi : public SdFatBase {
- public:
-
-
- bool begin(uint8_t csPin = SS, uint8_t divisor = 2) {
- return SdFatBase::begin(&m_spi, csPin, divisor);
- }
-
-
- bool cardBegin(uint8_t csPin = SS, uint8_t divisor = 2) {
- return card()->begin(&m_spi, csPin, divisor);
- }
-
- private:
- SdSpiSoft<MisoPin, MosiPin, SckPin> m_spi;
- };
- #endif
- #endif
|