Merge pull request #10462 from gemu2015/filesystem

sdcard optional ufs
This commit is contained in:
Theo Arends 2021-01-08 20:27:31 +01:00 committed by GitHub
commit 9a5f44fc7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 58 additions and 54 deletions

View File

@ -88,17 +88,57 @@ uint8_t ffs_type;
/*********************************************************************************************/ /*********************************************************************************************/
// init flash file system
void UfsInitOnce(void) { void UfsInitOnce(void) {
ufs_type = 0; ufs_type = 0;
ffsp = 0; ffsp = 0;
ufs_dir = 0; ufs_dir = 0;
// check for fs options,
// 1. check for SD card #ifdef ESP8266
// 2. check for littlefs or FAT ffsp = &LittleFS;
if (!LittleFS.begin()) {
return;
}
#endif // ESP8266
#ifdef ESP32
// try lfs first
ffsp = &LITTLEFS;
if (!LITTLEFS.begin(true)) {
// ffat is second
ffsp = &FFat;
if (!FFat.begin(true)) {
return;
}
ffs_type = UFS_TFAT;
ufs_type = ffs_type;
ufsp = ffsp;
dfsp = ffsp;
return;
}
#endif // ESP32
ffs_type = UFS_TLFS;
ufs_type = ffs_type;
ufsp = ffsp;
dfsp = ffsp;
}
// actually this inits flash file only
void UfsInit(void) {
UfsInitOnce();
if (ufs_type) {
AddLog_P(LOG_LEVEL_INFO, PSTR("UFS: Type %d mounted with %d kB free"), ufs_type, UfsInfo(1, 0));
}
}
#ifdef USE_SDCARD #ifdef USE_SDCARD
void UfsCheckSDCardInit(void) {
if (TasmotaGlobal.spi_enabled) { if (TasmotaGlobal.spi_enabled) {
// if (1) { // if (1) {
int8_t cs = SDCARD_CS_PIN; int8_t cs = SDCARD_CS_PIN;
if (PinUsed(GPIO_SDCARD_CS)) { if (PinUsed(GPIO_SDCARD_CS)) {
cs = Pin(GPIO_SDCARD_CS); cs = Pin(GPIO_SDCARD_CS);
@ -108,66 +148,25 @@ void UfsInitOnce(void) {
#ifdef ESP8266 #ifdef ESP8266
ufsp = &SDFS; ufsp = &SDFS;
#endif // ESP8266 #endif // ESP8266
#ifdef ESP32 #ifdef ESP32
ufsp = &SD; ufsp = &SD;
#endif // ESP32 #endif // ESP32
ufs_type = UFS_TSDC; ufs_type = UFS_TSDC;
dfsp = ufsp; dfsp = ufsp;
#ifdef FFS_2
// now detect ffs
ffsp = &LITTLEFS;
if (!LITTLEFS.begin()) {
// ffat is second
ffsp = &FFat;
if (!FFat.begin(true)) {
ffsp = 0;
return;
}
ffs_type = UFS_TFAT;
ufs_dir = 1;
return;
}
ffs_type = UFS_TLFS;
ufs_dir = 1; ufs_dir = 1;
#endif // FFS_2 // make sd card the global filesystem
return;
}
}
#endif // USE_SDCARD
// if no success with sd card try flash fs
#ifdef ESP8266 #ifdef ESP8266
ufsp = &LittleFS; // on esp8266 sdcard info takes several seconds !!!, so we ommit it here
if (!LittleFS.begin()) { AddLog_P(LOG_LEVEL_INFO, PSTR("UFS: SDCARD mounted"));
return; #endif // ESP8266
}
#endif // ESP8266
#ifdef ESP32 #ifdef ESP32
// try lfs first AddLog_P(LOG_LEVEL_INFO, PSTR("UFS: SDCARD mounted with %d kB free"), UfsInfo(1, 0));
ufsp = &LITTLEFS;
if (!LITTLEFS.begin(true)) {
// ffat is second
ufsp = &FFat;
if (!FFat.begin(true)) {
return;
}
ufs_type = UFS_TFAT;
ffsp = ufsp;
dfsp = ufsp;
return;
}
#endif // ESP32 #endif // ESP32
ufs_type = UFS_TLFS; }
ffsp = ufsp;
dfsp = ufsp;
}
void UfsInit(void) {
UfsInitOnce();
if (ufs_type) {
AddLog_P(LOG_LEVEL_INFO, PSTR("UFS: Type %d mounted with %dkB free"), ufs_type, UfsInfo(1, 0));
} }
} }
#endif // USE_SDCARD
uint32_t UfsInfo(uint32_t sel, uint32_t type) { uint32_t UfsInfo(uint32_t sel, uint32_t type) {
uint32_t result = 0; uint32_t result = 0;
@ -472,7 +471,7 @@ void UfsDirectory(void) {
WSContentSend_P(UFS_FORM_FILE_UPGc, WebColor(COL_TEXT), ts, fs); WSContentSend_P(UFS_FORM_FILE_UPGc, WebColor(COL_TEXT), ts, fs);
if (ufs_dir) { if (ufs_dir) {
WSContentSend_P(UFS_FORM_FILE_UPGc1, WiFi.localIP().toString().c_str(),ufs_dir == 1 ? 2:1, ufs_dir == 1 ? "UFS":"FFS"); WSContentSend_P(UFS_FORM_FILE_UPGc1, WiFi.localIP().toString().c_str(),ufs_dir == 1 ? 2:1, ufs_dir == 1 ? "SDCard":"FlashFS");
} }
WSContentSend_P(UFS_FORM_FILE_UPGc2); WSContentSend_P(UFS_FORM_FILE_UPGc2);
@ -677,6 +676,11 @@ bool Xdrv50(uint8_t function) {
bool result = false; bool result = false;
switch (function) { switch (function) {
#ifdef USE_SDCARD
case FUNC_PRE_INIT:
UfsCheckSDCardInit();
break;
#endif // USE_SDCARD
case FUNC_COMMAND: case FUNC_COMMAND:
result = DecodeCommand(kUFSCommands, kUFSCommand); result = DecodeCommand(kUFSCommands, kUFSCommand);
break; break;