remove: eliminate file management and LittleFS-based filesystem, implement savegame management for JSON config slots with wear-leveling

This commit is contained in:
2026-04-08 22:12:55 +02:00
parent 1da6d54d7a
commit 301298522b
17 changed files with 318 additions and 622 deletions

View File

@@ -3,7 +3,7 @@ use lib_bms_protocol::BmsReadable;
pub(crate) mod battery;
// mod can_api; // replaced by external canapi crate
pub mod esp;
mod little_fs2storage_adapter;
pub(crate) mod savegame_manager;
pub(crate) mod rtc;
mod shared_flash;
mod v4_hal;
@@ -75,7 +75,7 @@ use measurements::{Current, Voltage};
use crate::fat_error::{ContextExt, FatError, FatResult};
use crate::hal::battery::WCHI2CSlave;
use crate::hal::little_fs2storage_adapter::LittleFs2Filesystem;
use crate::hal::savegame_manager::SavegameManager;
use crate::hal::water::TankSensor;
use crate::log::LOG_ACCESS;
use embassy_sync::mutex::Mutex;
@@ -99,9 +99,7 @@ use esp_hal::uart::Uart;
use esp_hal::Blocking;
use esp_radio::{init, Controller};
use esp_storage::FlashStorage;
use littlefs2::fs::{Allocation, Filesystem as lfs2Filesystem};
use littlefs2::object_safe::DynStorage;
use log::{error, info, warn};
use log::{info, warn};
use portable_atomic::AtomicBool;
use serde::{Deserialize, Serialize};
use shared_flash::MutexFlashStorage;
@@ -379,33 +377,16 @@ impl PlantHal {
.find_partition(esp_bootloader_esp_idf::partitions::PartitionType::Data(
DataPartitionSubType::LittleFs,
))?
.context("Data partition with littlefs not found")?;
.context("Storage data partition not found")?;
let data_partition = mk_static!(PartitionEntry, data_partition);
let data = mk_static!(
FlashRegion<MutexFlashStorage>,
FlashRegion<'static, MutexFlashStorage>,
data_partition.as_embedded_storage(flash_storage_3)
);
let lfs2filesystem = mk_static!(LittleFs2Filesystem, LittleFs2Filesystem { storage: data });
let alloc = mk_static!(Allocation<LittleFs2Filesystem>, lfs2Filesystem::allocate());
if lfs2filesystem.is_mountable() {
info!("Littlefs2 filesystem is mountable");
} else {
match lfs2filesystem.format() {
Ok(..) => {
info!("Littlefs2 filesystem is formatted");
}
Err(err) => {
error!("Littlefs2 filesystem could not be formatted: {err:?}");
}
}
}
#[allow(clippy::arc_with_non_send_sync)]
let fs = Arc::new(Mutex::new(
lfs2Filesystem::mount(alloc, lfs2filesystem)
.context("Could not mount lfs2 filesystem")?,
));
let savegame = SavegameManager::new(data);
info!("Savegame storage initialized ({} slots × {} KB)", savegame_manager::SAVEGAME_SLOT_COUNT, savegame_manager::SAVEGAME_SLOT_SIZE / 1024);
let uart0 =
Uart::new(peripherals.UART0, UartConfig::default()).map_err(|_| FatError::String {
@@ -415,7 +396,7 @@ impl PlantHal {
let ap = interfaces.ap;
let sta = interfaces.sta;
let mut esp = Esp {
fs,
savegame,
rng,
controller: Arc::new(Mutex::new(controller)),
interface_sta: Some(sta),