Go Down

Topic: SD and SDFat Compatibility? (Read 228 times) previous topic - next topic

vwlowen

Hi,

I'm using the Adafruit VS1053 MP3 Player library ( https://github.com/adafruit/Adafruit_VS1053_Library ) which includes <SD.h> in the .h and .cpp files.

I want to use SDFat in my Sketch in order to give myself long filename support.  The SDFat readme says that, to make SDFat compatible with SD, I should include the following to the Sketch:

//remove #include <SD.h>

#include <SDFat.h>
SDFat SD


If I add those lines to the Sketch,  VS1053.h  complains that "File" doesn't name a type.

If I add the lines to the Sketch and VS1503.cpp, then VS1503.h complains about Redefinition of 'SdFat SD'

If I change the 'constructor' in VS1503.h to 'SdFat SD1'  and change the references to SD within VS1503.cpp to SD1 it does compile without error BUT the Sketch obviously doesn't pass the "File" filename to VS1503.cpp as SD and SD1 are now two different things.

Any advice would be appreciated,

Thanks,

John.


fat16lib

#1
Dec 22, 2014, 03:53 pm Last Edit: Dec 22, 2014, 04:11 pm by fat16lib
There needs to be only one SD object.  In the SD.h library it is declared in SD.cpp and SD.h has an extern definition of SD.

You can achieve this by making the following changes.

In Adafruit_VS1053.h comment out SD.h and include SdFat.h.
Code: [Select]

//#include <SD.h>
#include <SdFat.h>


In Adafruit_VS1053.cpp comment out SD.h, include SdFat.h, and add an extern for SD.
Code: [Select]

//#include <SD.h>
#include <SdFat.h>
extern SdFat SD;


In your sketch comment out SD.h, include SdFat.h, and define SD.
Code: [Select]

//#include <SD.h>
#include <SdFat.h>
SdFat SD;


I am considering an option to define SD in the SdFat library.  This would need to be a configuration option since SdFat now has three classes that could define the SD object.  There is the standard SdFat class, the SdFatSoftSpi template for fast software SPI, and the SdFatLibSpi class that uses the standard Arduino SPI library.

I would add a symbol in SdFatConfig.h, say DEFINE_SD_OBJECT. When DEFINE_SD_OBJECT is defined nonzero like this, SD would be defined as in SD.h.
Code: [Select]

#define DEFINE_SD_OBJECT 1

You would only need to replace all SD.h includes with SdFat.h.

Unfortunately there is a huge amount of SdFat code and examples with a lower case sd.
Code: [Select]

SdFat sd;


Maybe I should just put the extern in SdFat.h and depend on the user to declare SD.  Then you would change all includes from SD.h to SdFat.h and declare SD in your sketch.

fat16lib

It appears that the VS1053 MP3 Player library may use SPI transactions.  You can enable SPI transactions in SdFat by editing SdFatConfig.h and setting ENABLE_SPI_TRANSACTION nonzero in this define.
Code: [Select]

#define ENABLE_SPI_TRANSACTION 1

vwlowen

Thank you :)

It was  'extern' that I was missing.


Perhaps just an addition to your Readme explaining how to handle libraries which use #include <SD.h> would be simplest for novices like me :)

I've also changed #define ENABLE_SPI_TRANSACTION 1 in SdFatConfig.h but I couldn't see SdFatConfig.h in SdFat.h or SdFat.cpp, do I need to #include it explicitly in my Sketch?   It compiles with or without it.

Thanks,

John.

fat16lib

#4
Dec 22, 2014, 06:28 pm Last Edit: Dec 22, 2014, 06:31 pm by fat16lib
SdFatConfig.h is included automatically, you don't need to included it from your program.

Quote
Perhaps just an addition to your Readme explaining how to handle libraries which use #include <SD.h> would be simplest for novices like me
I will add a section in the html documentation on moving from SD.h to SdFat.  Your experience helps me understand what I need to add in the section.

Too bad a newer SdFat can't replace the five year old version that is the base for SD.h.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy