Replace SD card storage with on-board Flash filesystem (FFat), allocating 9MB internal storage partition for keepsakes

This commit is contained in:
drjones
2026-07-04 23:21:44 -07:00
parent e7f2f09819
commit 778a2f4bfe
5 changed files with 22 additions and 35 deletions

View File

@@ -16,28 +16,22 @@ int g_timezoneOffset = 0;
bool g_timeSynchronized = false;
int g_favoriteMemoryId = -1;
// ── SD Init ───────────────────────────────────────────────────────────────────
// ── SD Init (Now Internal Flash FFat Init) ───────────────────────────────────
void SD_Init() {
if (!SD_MMC.setPins(SD_CLK_PIN, SD_CMD_PIN, SD_D0_PIN, SD_D1_PIN, SD_D2_PIN, SD_D3_PIN)) {
printf("SD MMC: Pin change failed!\r\n");
if (!FFat.begin(true)) {
printf("Internal Flash (FFat) initialization failed!\r\n");
return;
}
if (!SD_MMC.begin("/sdcard", false, true)) {
printf("SD card initialization failed!\r\n");
return;
}
printf("SD card OK (4-bit mode)\r\n");
uint8_t cardType = SD_MMC.cardType();
if (cardType == CARD_NONE) { printf("No SD card attached\r\n"); return; }
printf("Internal Flash (FFat) mounted successfully!\r\n");
uint64_t total = SD_MMC.totalBytes();
uint64_t used = SD_MMC.usedBytes();
uint64_t total = FFat.totalBytes();
uint64_t used = FFat.usedBytes();
SDCard_Size = total / (1024 * 1024);
printf("SD: %llu MB total, %llu MB used\r\n", total/(1024*1024), used/(1024*1024));
printf("Internal Flash storage: %llu MB total, %llu MB used\r\n", total/(1024*1024), used/(1024*1024));
// Ensure required directories exist
if (!SD_MMC.exists("/photos")) SD_MMC.mkdir("/photos");
if (!SD_MMC.exists("/audio")) SD_MMC.mkdir("/audio");
if (!FFat.exists("/photos")) FFat.mkdir("/photos");
if (!FFat.exists("/audio")) FFat.mkdir("/audio");
}
void Flash_test() {
@@ -59,7 +53,7 @@ bool Config_Load() {
g_currentIndex = 0;
g_volume = 12;
File f = SD_MMC.open(CONFIG_PATH, "r");
File f = FFat.open(CONFIG_PATH, "r");
if (!f) {
printf("Config: no config file found, starting fresh\r\n");
return true; // not an error — first boot
@@ -137,7 +131,7 @@ bool Config_Load() {
}
bool Config_Save() {
File f = SD_MMC.open(CONFIG_PATH, "w");
File f = FFat.open(CONFIG_PATH, "w");
if (!f) {
printf("Config: failed to open for writing\r\n");
return false;
@@ -181,9 +175,9 @@ bool Config_Delete_Memory(int id) {
// Optionally delete the files from SD
char path[80];
snprintf(path, sizeof(path), "/photos/%s", g_memories[i].photo);
SD_MMC.remove(path);
FFat.remove(path);
snprintf(path, sizeof(path), "/audio/%s", g_memories[i].audio);
SD_MMC.remove(path);
FFat.remove(path);
// Shift array down
for (int j = i; j < g_memoryCount - 1; j++)
@@ -201,7 +195,7 @@ bool Config_Delete_Memory(int id) {
// ── Legacy helpers ─────────────────────────────────────────────────────────────
bool File_Search(const char* directory, const char* fileName) {
File dir = SD_MMC.open(directory);
File dir = FFat.open(directory);
if (!dir) return false;
File file = dir.openNextFile();
while (file) {
@@ -214,7 +208,7 @@ bool File_Search(const char* directory, const char* fileName) {
uint16_t Folder_retrieval(const char* directory, const char* fileExtension,
char File_Name[][100], uint16_t maxFiles) {
File dir = SD_MMC.open(directory);
File dir = FFat.open(directory);
if (!dir) { printf("Folder not found: %s\r\n", directory); return 0; }
uint16_t count = 0;