|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
-
- #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
|