TB2026-YDS Firmware
Loading...
Searching...
No Matches
storage.h File Reference

Track enumeration over the microSD card: the index of playable files. More...

#include "esp_err.h"
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>

Go to the source code of this file.

Macros

#define STORAGE_MAX_TRACKS   512
 Largest number of tracks held in the in-memory index. Overflow fails loud.
#define STORAGE_PATH_MAX   320
 Size of one stored path buffer: "/sdcard/" + FATFS LFN (255) + nul, rounded up.

Functions

esp_err_t storage_init (void)
 Mount the SD card and scan its root for playable tracks.
esp_err_t storage_rescan (void)
 Re-scan the (already mounted) card root, rebuilding the track index.
esp_err_t storage_unmount (void)
 Unmount the card and invalidate the index, after a card removal.
bool storage_ready (void)
 Whether the card is mounted and a scan has completed.
size_t storage_count (void)
 Number of tracks in the index (0 before any successful scan).
esp_err_t storage_get_usage (uint64_t *total_bytes, uint64_t *used_bytes)
 Total and used size of the mounted FAT volume, in bytes.
const char * storage_track_path (size_t index)
 Full POSIX path of a track, ready for decoder_open().
const char * storage_track_name (size_t index)
 Display name of a track (file name, no directory prefix).
esp_err_t storage_scan_dir (const char *root)
 Scan an arbitrary directory for playable tracks, rebuilding the index.
esp_err_t storage_deinit (void)
 Unmount the card and free the index.

Detailed Description

Track enumeration over the microSD card: the index of playable files.

A thin layer above POSIX readdir and the microSD card (FATFS over SPI) driver. It owns the SD mount lifecycle (storage_init mounts, storage_deinit unmounts) so the playlist/player never touches the driver directly, then scans the card root once and serves the result from an in-memory list: no re-scan on access (power), nothing happens with no card.

The list holds only the audio files the decoder can open (.mp3 / .wav, case-insensitive), found by a recursive walk of the card (hidden entries skipped), sorted alphabetically (case-insensitive) so next/prev is deterministic. Each entry is a full POSIX path ready to hand to decoder_open(); the display name is the part after the last '/'. No metadata, no persistent cache: just the flat index.

Note
Développé avec l'assistance de Claude Opus 4.8 (Anthropic), sous la direction de Y. Dos Santos : spécification, revue et validation sur cible par l'auteur.