A simple example I can not give you. Note that I imported the librarys as an "create shared projects when included librarys" in one visual studio that was open. But I had two times visual studio open with an other project. In that visual studio I have imported the library without check marks in "add library. I was switching between those two. Because I saw that something was wrong before it stops working. When I start a new project it doesn't find the right toolchains anymore. So I can not help you anymore. I am sorry.
I was working in a class in a lib that inherited to the lib SdFat.h. the languages are C and C++. I can not give you a simple shetch because it happens after days trying to make it work, where I worked over a year now. It contains thousands of lines. But where it starts to fail was in adjusting the filesystem in here [https://github.com/schreibfaul1/ESP32-audioI2S][classe fs]
I had it with an other lib that also was using SdFat.h by a class on top of it. So it's not the lib that is the problem. I really think that it's the has to do with namespaces, definitions and filetypes in lib that are using filesystem libs. This is the classe what I was adapting. I commented the definitions and namespaces before.
#ifdef SDFATFS_USED
#include <SdFat.h> // https://github.com/greiman/SdFat
#else
#include <SD.h>
#include <SD_MMC.h>
#include <SPIFFS.h>
#include <FS.h>
#include <FFat.h>
#endif // SDFATFS_USED
#ifdef SDFATFS_USED
//typedef File32 File;
typedef FsFile File;
namespace fs {
class FS : public SdFat {
public:
bool begin(SdCsPin_t csPin = SS, uint32_t maxSck = SD_SCK_MHZ(25)) { return SdFat::begin(csPin, maxSck); }
};
class SDFATFS : public fs::FS {
public:
// sdcard_type_t cardType();
uint64_t cardSize() {
return totalBytes();
}
uint64_t usedBytes() {
// set SdFatConfig MAINTAIN_FREE_CLUSTER_COUNT non-zero. Then only the first call will take time.
return (uint64_t)(clusterCount() - freeClusterCount()) * (uint64_t)bytesPerCluster();
}
uint64_t totalBytes() {
return (uint64_t)clusterCount() * (uint64_t)bytesPerCluster();
}
};
}
extern fs::SDFATFS SD_SDFAT;
using namespace fs;
#define SD SD_SDFAT
#endif //SDFATFS_USED
offcoarse the filetype/namespace/lib is also been used in the cpp.
This is the code I was adjusting in my shetch.
#define SPI_SPEED SD_SCK_MHZ(4)
SPIClass Myspi(VSPI);
void SDconfig() {
#ifdef SDFATFS_USED
if (!SD.begin(SD_CS, SPI_SPEED)) {
if (SD.card()->errorCode()) {
Serial.println("SD initialization failed.");
}
else if (SD.vol()->fatType() == 0) {
Serial.println("Can't find a valid FAT16/FAT32 partition.");
}
else {
Serial.println("Can't determine error type");
}
return;
}
#else
//pinMode(SD_CS, OUTPUT);//SS pin not set as output in the spi library(sd card reader)//zit in sd.h library
//pinMode(MISO, INPUT_PULLUP);//miso needs a pullup (sd card reader)
//digitalWrite(SD_CS, HIGH);//zit in sd.h library
//Myspi.begin(SCK, MISO, MOSI, SD_CS);
//SPI.setFrequency(1000000);
//Myspi.setFrequency(4000000);
// SD.begin(SD_CS, Myspi);
if (!SD.begin(SD_CS)) {
Serial.println("SD card error!");
//sd32.initErrorHalt(&Serial);
while (true) {
delay(1000);
}
}
// print the type of card
Serial.println();
Serial.print("Card type: ");
switch (SD.cardType()) {
case CARD_NONE:
Serial.println("NONE");
break;
case CARD_MMC:
Serial.println("MMC");
break;
case CARD_SD:
Serial.println("SD");
break;
case CARD_SDHC:
Serial.println("SDHC");
break;
default:
Serial.println("Unknown");
}
Serial.print("Card size: ");
Serial.println((float)SD.cardSize() / 1000);
Serial.print("Total bytes: ");
Serial.println(SD.totalBytes());
Serial.print("Used bytes: ");
Serial.println(SD.usedBytes());
#endif
I hope you are something with it. Let me know if you have some questions.
Oh I forgot something. I was also adjusting this...
#if SDFAT_FILE_TYPE == 1
/** Select type for SdFat. */
typedef SdFat32 SdFat;
/** Select type for SdBaseFile. */
typedef FatFile SdBaseFile;
#elif SDFAT_FILE_TYPE == 2
typedef SdExFat SdFat;
typedef ExFatFile SdBaseFile;
#elif SDFAT_FILE_TYPE == 3
typedef SdFs SdFat;
typedef FsBaseFile SdBaseFile;
#else // SDFAT_FILE_TYPE
#error Invalid SDFAT_FILE_TYPE
#endif // SDFAT_FILE_TYPE
//
// Only define File if FS.h is not included.
// Line with test for __has_include must not have operators or parentheses.
#if defined __has_include
#if __has_include(<FS.h>)
#define HAS_INCLUDE_FS_H
#warning File not defined because __has__include(FS.h)
#endif // __has_include(<FS.h>)
#endif // defined __has_include
#ifndef HAS_INCLUDE_FS_H
#if SDFAT_FILE_TYPE == 1
/** Select type for File. */
typedef File32 File;
#elif SDFAT_FILE_TYPE == 2
typedef ExFile File;
#elif SDFAT_FILE_TYPE == 3
typedef FsFile File;
#endif // SDFAT_FILE_TYPE
#endif // HAS_INCLUDE_FS_H
In SdFat.h
And this in SdFatConfig.h
#ifndef SDFAT_FILE_TYPE
#if defined(__AVR__) && FLASHEND < 0X8000
// 32K AVR boards.
#define SDFAT_FILE_TYPE 1
#elif defined(__arm__)
// ARM boards usually have plenty of memory
#define SDFAT_FILE_TYPE 1
#else // defined(__AVR__) && FLASHEND < 0X8000
// All other boards.
#define SDFAT_FILE_TYPE 1
#endif // defined(__AVR__) && FLASHEND < 0X8000
#endif // SDFAT_FILE_TYPE
voila!