KurtE
Senior Member+
Wondering if we should have some version(s) of LittleFS_SPIxxx wrappers and likewise LittleFS_QS... wrappers.
I was getting tired of playing around and trying to remember which chip is which, to then edit the code to match the littlefs class..
So I have played around with a set of classes, trying to figure out the right balance...
So far I sort of like the following: Keep It Simple Stupid (KISS) wrappers, I have in one of my MTP example sketches:
Note: this one does not have method to query which one flash, nand, Fram... But easily could.
I have also played with a version like this which the classes were derived from FS or FileImpl, in which case you can simply use it... And it forwards each of the calls
to the underlying FS. Which worked fine, but if you needed LittleFS other functions could be issue.
I have played with deriving from LittleFS, But more problems associated with this, as each would have their own copies of the data structures...
So just wondering if this is something that we maybe should be added somewhere? (LittleFS.h?) And wondering what level of support?
I was getting tired of playing around and trying to remember which chip is which, to then edit the code to match the littlefs class..
So I have played around with a set of classes, trying to figure out the right balance...
So far I sort of like the following: Keep It Simple Stupid (KISS) wrappers, I have in one of my MTP example sketches:
Code:
//----------------------------------------------------------------------------
// Experiment with LittleFS_SPI wrapper
//----------------------------------------------------------------------------
#ifdef ARDUINO_TEENSY41
class lfs_qspi {
public:
lfs_qspi(){}
bool begin();
inline FS * fs() { return plfs;}
inline const char * displayName() {return display_name;}
// You have full access to internals.
uint8_t csPin;
LittleFS_QSPIFlash flash;
LittleFS_QPINAND nand;
LittleFS *plfs = nullptr;
char display_name[10];
};
bool lfs_qspi::begin() {
//Serial.printf("Try QSPI");
if (flash.begin()) {
//Serial.println(" *** Flash ***");
strcpy(display_name, (const char *)F("QFlash"));
plfs = &flash;
return true;
} else if (nand.begin()) {
//Serial.println(" *** Nand ***");
strcpy(display_name, (const char *)F("QNAND"));
plfs = &nand;
return true;
}
//Serial.println(" ### Failed ###");
return false;
}
lfs_qspi lfsq;
#endif
//----------------------------------------------------------------------------
// Experiment with LittleFS_SPI wrapper
//----------------------------------------------------------------------------
class lfs_spi {
public:
lfs_spi(uint8_t pin) : csPin(pin) {}
bool begin();
inline FS * fs() { return plfs;}
inline const char * displayName() {return display_name;}
// You have full access to internals.
uint8_t csPin;
LittleFS_SPIFlash flash;
LittleFS_SPIFram fram;
LittleFS_SPINAND nand;
LittleFS *plfs = nullptr;
char display_name[10];
};
bool lfs_spi::begin() {
//Serial.printf("Try SPI Pin %u", csPin);
if (flash.begin(csPin)) {
//Serial.println(" *** Flash ***");
sprintf(display_name, (const char *)F("Flash_%u"), csPin);
plfs = &flash;
return true;
} else if (fram.begin(csPin)) {
//Serial.println(" *** Fram ***");
sprintf(display_name, (const char *)F("Fram_%u"), csPin);
plfs = &fram;
return true;
} else if (nand.begin(csPin)) {
//Serial.println(" *** Nand ***");
sprintf(display_name, (const char *)F("NAND_%u"), csPin);
plfs = &nand;
return true;
}
//Serial.println(" ### Failed ###");
return false;
}
Note: this one does not have method to query which one flash, nand, Fram... But easily could.
I have also played with a version like this which the classes were derived from FS or FileImpl, in which case you can simply use it... And it forwards each of the calls
to the underlying FS. Which worked fine, but if you needed LittleFS other functions could be issue.
I have played with deriving from LittleFS, But more problems associated with this, as each would have their own copies of the data structures...
So just wondering if this is something that we maybe should be added somewhere? (LittleFS.h?) And wondering what level of support?