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

@@ -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) {

View File

@@ -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;

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;

View File

@@ -2,15 +2,7 @@
#include "Arduino.h"
#include <cstring>
#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

View File

@@ -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);