CHGame 0.3.0
Libraries for the CHGame handheld
Loading...
Searching...
No Matches
CHSd library

Read-only microSD: an SPI-mode block driver and a FAT16/FAT32 reader that turns a file name into runs of card blocks. More...

Modules

 FAT16/FAT32 files
 A read-only FAT16/FAT32 reader on top of sd::read(): a file name in, the file's runs of card blocks out.
 
 SD card blocks
 A read-only SPI-mode microSD block driver: sd::init(), sd::read() and sd::stream().
 

Detailed Description

Read-only microSD: an SPI-mode block driver and a FAT16/FAT32 reader that turns a file name into runs of card blocks.

#include <SdSpi.h>
#include <Fat.h>
FAT16/FAT32 files on the SD card: find a file by its 8.3 name and read its blocks.
The SD card's blocks: identify the card, read one 512-byte block or stream a run of them.

About 1.7 KB of flash and 24 B of RAM. The card shares SPI1 with the panel, so every call goes between gfx_wait() and the next flush, and every call borrows a 512-byte, 4-byte-aligned buffer (CHGfx's gfx_chunkScratch() is idle at exactly that time).

// Once, after gfx_wait():
fat::Run run[4];
uint8_t nRuns = fat::open("WORDS DIC", run, 4, gfx_chunkScratch());
// ... then any block of the file, any time after gfx_wait():
if (!fat::read(run, nRuns, k, gfx_chunkScratch())) { /* the card has gone */ }
uint8_t * gfx_chunkScratch(void)
1 KB of word-aligned scratch memory: the flush's chunk buffers.
uint8_t open(const char *name, Run *out, uint8_t maxRuns, uint8_t *buf)
The usual way in: sd::init(), mount(), find() and runs() in one go.
bool read(const Run *run, uint32_t nRuns, uint32_t k, uint8_t *dst)
Reads block k of a file through its runs.
A run of consecutive card blocks holding part of a file (see runs()).
Definition Fat.h:62

Cards must be FAT16 or FAT32 (how cards up to 32 GB come); exFAT is reported as fat::E_EXFAT so a game can ask for a reformat.

See also
The library's README, SD card notes