I am writing a new FAT12/FAT16/FAT32 library. I need suggestions for class naming conventions.
Please read the following and post any suggestions.
This library will support FAT file systems on any block device derived from the following class.
class FatBlockDevice {
public:
virtual bool readBlock(uint32_t block, uint8_t* dst) = 0;
virtual bool writeBlock(uint32_t block, const uint8_t* dst) = 0;
virtual bool readBlocks(uint32_t block, uint16_t count, uint8_t* dst) = 0;
virtual bool writeBlocks(uint32_t block, uint16_t count, const uint8_t* dst) = 0;
};
I plan to support SD on SPI, SD on 4-bit SDIO, USB mass storage devices such as USB flash drives, RAM disks, and other devices.
I have completed SD SPI and realize I need naming conventions for file system classes.
For SD SPI I implemented three classes in place of the single class in SdFat.
// Like SdFat, uses an optimized SPI implementation.
FatSdSpiNative sd;
// This class uses the Arduino SPI library for SPI I/O.
FatSdSpiLib sd;
// This class uses bit-bang SPI on any pins.
FatSdSpiSoft<MISO_PIN, MOSI_PIN, SCK_PIN> sd;
My convention is "Fat" for FAT filesystem, "SdSpi" for device (SD in SPI mode), followed by "Native", "Lib", or "Soft" for SPI implementation.
I plan to use "FatSdio" for a class that supports the 4-bit SD SDIO bus. Most likely the first implementation will be on STM32 for ChibiOS.
I plan to use "FatUsb" for a class that supports USB mass storage. I hope to implement this class on Due.
I currently define two file classes. FatFile and FatPrintFile. FatFile can be used on Arduino or in standalone RTOSs like ChibiOS. FatPrintFile is derived from Print and FatFile like this:
class FatPrintFile : public FatFile, public Print {
// ...
};
Here is a simple test sketch. I plan to include some typedefs for better compatibility with SdFat.
/*
* Sketch to compare size of SdFat with FatLib.
*/
#include <FatLib.h>
#include <FatSdSpi.h>
// Fastest optimized SPI version.
FatSdSpiNative sd;
// Remove comment to test Arduino SPI library version.
// FatSdSpiLib sd;
// Remove comment to test bit-bang version.
// FatSdSpiSoft<MISO, MOSI, SCK> sd;
FatPrintFile file;
//------------------------------------------------------------------------------
void setup() {
Serial.begin(9600);
while (!Serial) {} // wait for Leonardo
if (!sd.begin()) {
Serial.println("begin failed");
return;
}
file.open("SIZE_TST.TXT", O_RDWR | O_CREAT | O_AT_END);
file.println("Hello");
file.close();
Serial.println("Done");
}
//------------------------------------------------------------------------------
void loop() {}