refactor: move storage initialization to the start_config function

This commit is contained in:
2026-08-17 21:41:01 -05:00
parent d70b35dd92
commit 6a5bc24122
+15 -16
View File
@@ -6,7 +6,7 @@ use esp_hal::peripherals::FLASH;
use esp_storage::FlashStorage;
use int_enum::IntEnum;
use sequential_storage::{
cache::Cache,
cache::{Cache, Uncached},
map::{Key, MapConfig, MapStorage, SerializationError},
};
@@ -21,18 +21,18 @@ impl ConfigCommand {
pub static CONFIG_SERVICE: RpcService<CriticalSectionRawMutex, ConfigCommand, ()> =
RpcService::new();
pub fn start_config(spawner: Spawner, flash: FLASH<'static>) {
spawner.spawn(config_handler(flash).unwrap());
}
#[embassy_executor::task]
async fn config_handler(flash: FLASH<'static>) {
let mut storage = MapStorage::<ConfigKey, _, _>::new(
pub async fn start_config(spawner: Spawner, flash: FLASH<'static>) {
let storage = MapStorage::<ConfigKey, _, _>::new(
BlockingAsync::new(FlashStorage::new(flash)),
const { MapConfig::new(0x3F_0000..0x40_0000) },
Cache::new_uncached(),
);
spawner.spawn(config_handler(storage).unwrap());
}
#[embassy_executor::task]
async fn config_handler(mut storage: MapStorage<ConfigKey, BlockingAsync<FlashStorage<'static>>, Cache<Uncached, Uncached, Uncached, ConfigKey>>) {
let mut data_buffer = [0u8; 256];
loop {
@@ -40,14 +40,13 @@ async fn config_handler(flash: FLASH<'static>) {
match req {
ConfigCommand::SetStationCreds() => {
todo!()
// if storage
// .store_item(&mut data_buffer, &ConfigKey::Wifi, )
// .await
// .is_ok()
// {
// served.respond(());
// }
if storage
.store_item(&mut data_buffer, &ConfigKey::Wifi, &256)
.await
.is_ok()
{
served.respond(());
}
}
}
}