From 778a2f4bfeea364f7a42c69be4795a950e503b7b Mon Sep 17 00:00:00 2001 From: drjones Date: Sat, 4 Jul 2026 23:21:44 -0700 Subject: [PATCH] Replace SD card storage with on-board Flash filesystem (FFat), allocating 9MB internal storage partition for keepsakes --- sound_picture_app/Audio_Player.cpp | 3 ++- sound_picture_app/Display_PNG.cpp | 2 +- sound_picture_app/SD_Card.cpp | 36 +++++++++++++----------------- sound_picture_app/SD_Card.h | 10 +-------- sound_picture_app/Web_Server.cpp | 6 ++--- 5 files changed, 22 insertions(+), 35 deletions(-) diff --git a/sound_picture_app/Audio_Player.cpp b/sound_picture_app/Audio_Player.cpp index 60cc7e1..cb00a60 100644 --- a/sound_picture_app/Audio_Player.cpp +++ b/sound_picture_app/Audio_Player.cpp @@ -1,5 +1,6 @@ #include "Audio_Player.h" #include "Audio.h" +#include "FFat.h" static Audio audio; static TaskHandle_t audioTaskHandle = NULL; @@ -27,7 +28,7 @@ void initAudioPlayer() { // ── Public controls ─────────────────────────────────────────────────────────── void playAudio(const char* fullPath) { printf("Audio: playing %s\r\n", fullPath); - audio.connecttoFS(SD_MMC, fullPath); + audio.connecttoFS(FFat, fullPath); } void playMemoryAudio(int memoryIndex) { diff --git a/sound_picture_app/Display_PNG.cpp b/sound_picture_app/Display_PNG.cpp index b80f4b3..a3a64b0 100644 --- a/sound_picture_app/Display_PNG.cpp +++ b/sound_picture_app/Display_PNG.cpp @@ -7,7 +7,7 @@ static int16_t ypos = 0; // ── PNG callbacks ───────────────────────────────────────────────────────────── static void* pngOpen(const char* filePath, int32_t* size) { - Image_file = SD_MMC.open(filePath); + Image_file = FFat.open(filePath); if (!Image_file) { printf("PNG: failed to open %s\r\n", filePath); return nullptr; } *size = Image_file.size(); return &Image_file; diff --git a/sound_picture_app/SD_Card.cpp b/sound_picture_app/SD_Card.cpp index 4be2381..341da42 100644 --- a/sound_picture_app/SD_Card.cpp +++ b/sound_picture_app/SD_Card.cpp @@ -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; diff --git a/sound_picture_app/SD_Card.h b/sound_picture_app/SD_Card.h index c6796b3..680889d 100644 --- a/sound_picture_app/SD_Card.h +++ b/sound_picture_app/SD_Card.h @@ -2,15 +2,7 @@ #include "Arduino.h" #include #include "FS.h" -#include "SD_MMC.h" - -// SD card MMC pins (4-bit mode, fully compatible now LCD_CS is on GPIO 42) -#define SD_CLK_PIN 14 -#define SD_CMD_PIN 15 -#define SD_D0_PIN 16 -#define SD_D1_PIN 18 -#define SD_D2_PIN 17 -#define SD_D3_PIN 21 +#include "FFat.h" #define MAX_MEMORIES 50 #define MAX_NAME_LEN 64 diff --git a/sound_picture_app/Web_Server.cpp b/sound_picture_app/Web_Server.cpp index 4bf63fd..acff29e 100644 --- a/sound_picture_app/Web_Server.cpp +++ b/sound_picture_app/Web_Server.cpp @@ -989,7 +989,7 @@ static void handleUploadFile(const String& subdir, bool (*validator)(const Strin return; } pendingUploadPath = "/" + subdir + "/" + fname; - uploadFile = SD_MMC.open(pendingUploadPath, "w"); + uploadFile = FFat.open(pendingUploadPath, "w"); uploadSuccess = (bool)uploadFile; if (uploadSuccess) uploadedFilename = fname; printf("Upload: writing to %s\r\n", pendingUploadPath.c_str()); @@ -1170,7 +1170,7 @@ void initWebServer() { } if (name.isEmpty()) { server.send(404, "text/plain", "Not found"); return; } String path = "/photos/" + name; - File f = SD_MMC.open(path, "r"); + File f = FFat.open(path, "r"); if (!f) { server.send(404, "text/plain", "Not found"); return; } server.streamFile(f, "image/png"); f.close(); @@ -1181,7 +1181,7 @@ void initWebServer() { if (uri.startsWith("/photo/")) { String name = uri.substring(7); String path = "/photos/" + name; - File f = SD_MMC.open(path, "r"); + File f = FFat.open(path, "r"); if (f) { String ct = name.endsWith(".png") ? "image/png" : "image/jpeg"; server.streamFile(f, ct);