Expand description
§Overview
This library provides a power-fail safe savegame system for embedded devices with wear leveling. It manages data storage on flash memory (EEPROM or NOR flash) by distributing writes across multiple slots to prevent wear-out of specific memory locations.
§Flash Support
eeprom24xfeature: Support for AT24Cxx EEPROM chipsw25qfeature: Support for W25Q NOR flash chipsmockfeature: Mock flash implementations for testing
§Example
use embedded_savegame::storage::{Storage, Flash};
// Configure storage with 64-byte slots across 8 total slots
const SLOT_SIZE: usize = 64;
const SLOT_COUNT: usize = 8;
let mut storage = Storage::<_, SLOT_SIZE, SLOT_COUNT>::new(flash_device);
// Scan for existing savegame
if let Some(slot) = storage.scan()? {
let mut buf = [0u8; 256];
if let Some(data) = storage.read(slot.idx, &mut buf)? {
// Process loaded savegame
}
}
// Write new savegame
let mut save_data = b"game state data".to_vec();
storage.append(&mut save_data)?;§Architecture
Each slot contains a header with:
- Current savegame checksum
- Data length
- Previous savegame checksum (for chain verification)
The scanner finds the most recent valid savegame by following the checksum chain.
Modules§
- chksum
- Checksum implementation for savegame validation
- eeprom24x
- AT24Cxx EEPROM support
- mock
- Mock flash implementations for testing
- storage
- Flash storage abstraction and savegame management
Structs§
- Slot
- A savegame slot containing metadata about stored data