Replace SD card storage with on-board Flash filesystem (FFat), allocating 9MB internal storage partition for keepsakes
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#include "Audio_Player.h"
|
#include "Audio_Player.h"
|
||||||
#include "Audio.h"
|
#include "Audio.h"
|
||||||
|
#include "FFat.h"
|
||||||
|
|
||||||
static Audio audio;
|
static Audio audio;
|
||||||
static TaskHandle_t audioTaskHandle = NULL;
|
static TaskHandle_t audioTaskHandle = NULL;
|
||||||
@@ -27,7 +28,7 @@ void initAudioPlayer() {
|
|||||||
// ── Public controls ───────────────────────────────────────────────────────────
|
// ── Public controls ───────────────────────────────────────────────────────────
|
||||||
void playAudio(const char* fullPath) {
|
void playAudio(const char* fullPath) {
|
||||||
printf("Audio: playing %s\r\n", fullPath);
|
printf("Audio: playing %s\r\n", fullPath);
|
||||||
audio.connecttoFS(SD_MMC, fullPath);
|
audio.connecttoFS(FFat, fullPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void playMemoryAudio(int memoryIndex) {
|
void playMemoryAudio(int memoryIndex) {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ static int16_t ypos = 0;
|
|||||||
|
|
||||||
// ── PNG callbacks ─────────────────────────────────────────────────────────────
|
// ── PNG callbacks ─────────────────────────────────────────────────────────────
|
||||||
static void* pngOpen(const char* filePath, int32_t* size) {
|
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; }
|
if (!Image_file) { printf("PNG: failed to open %s\r\n", filePath); return nullptr; }
|
||||||
*size = Image_file.size();
|
*size = Image_file.size();
|
||||||
return &Image_file;
|
return &Image_file;
|
||||||
|
|||||||
@@ -16,28 +16,22 @@ int g_timezoneOffset = 0;
|
|||||||
bool g_timeSynchronized = false;
|
bool g_timeSynchronized = false;
|
||||||
int g_favoriteMemoryId = -1;
|
int g_favoriteMemoryId = -1;
|
||||||
|
|
||||||
// ── SD Init ───────────────────────────────────────────────────────────────────
|
// ── SD Init (Now Internal Flash FFat Init) ───────────────────────────────────
|
||||||
void SD_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)) {
|
if (!FFat.begin(true)) {
|
||||||
printf("SD MMC: Pin change failed!\r\n");
|
printf("Internal Flash (FFat) initialization failed!\r\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!SD_MMC.begin("/sdcard", false, true)) {
|
printf("Internal Flash (FFat) mounted successfully!\r\n");
|
||||||
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; }
|
|
||||||
|
|
||||||
uint64_t total = SD_MMC.totalBytes();
|
uint64_t total = FFat.totalBytes();
|
||||||
uint64_t used = SD_MMC.usedBytes();
|
uint64_t used = FFat.usedBytes();
|
||||||
SDCard_Size = total / (1024 * 1024);
|
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
|
// Ensure required directories exist
|
||||||
if (!SD_MMC.exists("/photos")) SD_MMC.mkdir("/photos");
|
if (!FFat.exists("/photos")) FFat.mkdir("/photos");
|
||||||
if (!SD_MMC.exists("/audio")) SD_MMC.mkdir("/audio");
|
if (!FFat.exists("/audio")) FFat.mkdir("/audio");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Flash_test() {
|
void Flash_test() {
|
||||||
@@ -59,7 +53,7 @@ bool Config_Load() {
|
|||||||
g_currentIndex = 0;
|
g_currentIndex = 0;
|
||||||
g_volume = 12;
|
g_volume = 12;
|
||||||
|
|
||||||
File f = SD_MMC.open(CONFIG_PATH, "r");
|
File f = FFat.open(CONFIG_PATH, "r");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
printf("Config: no config file found, starting fresh\r\n");
|
printf("Config: no config file found, starting fresh\r\n");
|
||||||
return true; // not an error — first boot
|
return true; // not an error — first boot
|
||||||
@@ -137,7 +131,7 @@ bool Config_Load() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Config_Save() {
|
bool Config_Save() {
|
||||||
File f = SD_MMC.open(CONFIG_PATH, "w");
|
File f = FFat.open(CONFIG_PATH, "w");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
printf("Config: failed to open for writing\r\n");
|
printf("Config: failed to open for writing\r\n");
|
||||||
return false;
|
return false;
|
||||||
@@ -181,9 +175,9 @@ bool Config_Delete_Memory(int id) {
|
|||||||
// Optionally delete the files from SD
|
// Optionally delete the files from SD
|
||||||
char path[80];
|
char path[80];
|
||||||
snprintf(path, sizeof(path), "/photos/%s", g_memories[i].photo);
|
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);
|
snprintf(path, sizeof(path), "/audio/%s", g_memories[i].audio);
|
||||||
SD_MMC.remove(path);
|
FFat.remove(path);
|
||||||
|
|
||||||
// Shift array down
|
// Shift array down
|
||||||
for (int j = i; j < g_memoryCount - 1; j++)
|
for (int j = i; j < g_memoryCount - 1; j++)
|
||||||
@@ -201,7 +195,7 @@ bool Config_Delete_Memory(int id) {
|
|||||||
|
|
||||||
// ── Legacy helpers ─────────────────────────────────────────────────────────────
|
// ── Legacy helpers ─────────────────────────────────────────────────────────────
|
||||||
bool File_Search(const char* directory, const char* fileName) {
|
bool File_Search(const char* directory, const char* fileName) {
|
||||||
File dir = SD_MMC.open(directory);
|
File dir = FFat.open(directory);
|
||||||
if (!dir) return false;
|
if (!dir) return false;
|
||||||
File file = dir.openNextFile();
|
File file = dir.openNextFile();
|
||||||
while (file) {
|
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,
|
uint16_t Folder_retrieval(const char* directory, const char* fileExtension,
|
||||||
char File_Name[][100], uint16_t maxFiles) {
|
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; }
|
if (!dir) { printf("Folder not found: %s\r\n", directory); return 0; }
|
||||||
|
|
||||||
uint16_t count = 0;
|
uint16_t count = 0;
|
||||||
|
|||||||
@@ -2,15 +2,7 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "FS.h"
|
#include "FS.h"
|
||||||
#include "SD_MMC.h"
|
#include "FFat.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
|
|
||||||
|
|
||||||
#define MAX_MEMORIES 50
|
#define MAX_MEMORIES 50
|
||||||
#define MAX_NAME_LEN 64
|
#define MAX_NAME_LEN 64
|
||||||
|
|||||||
@@ -989,7 +989,7 @@ static void handleUploadFile(const String& subdir, bool (*validator)(const Strin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pendingUploadPath = "/" + subdir + "/" + fname;
|
pendingUploadPath = "/" + subdir + "/" + fname;
|
||||||
uploadFile = SD_MMC.open(pendingUploadPath, "w");
|
uploadFile = FFat.open(pendingUploadPath, "w");
|
||||||
uploadSuccess = (bool)uploadFile;
|
uploadSuccess = (bool)uploadFile;
|
||||||
if (uploadSuccess) uploadedFilename = fname;
|
if (uploadSuccess) uploadedFilename = fname;
|
||||||
printf("Upload: writing to %s\r\n", pendingUploadPath.c_str());
|
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; }
|
if (name.isEmpty()) { server.send(404, "text/plain", "Not found"); return; }
|
||||||
String path = "/photos/" + name;
|
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; }
|
if (!f) { server.send(404, "text/plain", "Not found"); return; }
|
||||||
server.streamFile(f, "image/png");
|
server.streamFile(f, "image/png");
|
||||||
f.close();
|
f.close();
|
||||||
@@ -1181,7 +1181,7 @@ void initWebServer() {
|
|||||||
if (uri.startsWith("/photo/")) {
|
if (uri.startsWith("/photo/")) {
|
||||||
String name = uri.substring(7);
|
String name = uri.substring(7);
|
||||||
String path = "/photos/" + name;
|
String path = "/photos/" + name;
|
||||||
File f = SD_MMC.open(path, "r");
|
File f = FFat.open(path, "r");
|
||||||
if (f) {
|
if (f) {
|
||||||
String ct = name.endsWith(".png") ? "image/png" : "image/jpeg";
|
String ct = name.endsWith(".png") ? "image/png" : "image/jpeg";
|
||||||
server.streamFile(f, ct);
|
server.streamFile(f, ct);
|
||||||
|
|||||||
Reference in New Issue
Block a user