use embassy_embedded_hal::flash::partition::Partition; use embassy_sync::blocking_mutex::raw::NoopRawMutex; use embassy_sync::mutex::Mutex; use embedded_storage_async::nor_flash::NorFlash; use crate::BootLoaderConfig; pub struct AsyncTestFlash where ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, { active: Mutex, dfu: Mutex, state: Mutex, } impl AsyncTestFlash where ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, { pub fn new(config: BootLoaderConfig) -> Self { Self { active: Mutex::new(config.active), dfu: Mutex::new(config.dfu), state: Mutex::new(config.state), } } pub fn active(&self) -> Partition { Self::create_partition(&self.active) } pub fn dfu(&self) -> Partition { Self::create_partition(&self.dfu) } pub fn state(&self) -> Partition { Self::create_partition(&self.state) } fn create_partition(mutex: &Mutex) -> Partition { Partition::new(mutex, 0, mutex.try_lock().unwrap().capacity() as u32) } } impl AsyncTestFlash where ACTIVE: NorFlash + embedded_storage::nor_flash::NorFlash, DFU: NorFlash + embedded_storage::nor_flash::NorFlash, STATE: NorFlash + embedded_storage::nor_flash::NorFlash, { pub fn into_blocking(self) -> super::BlockingTestFlash { let config = BootLoaderConfig { active: self.active.into_inner(), dfu: self.dfu.into_inner(), state: self.state.into_inner(), }; super::BlockingTestFlash::new(config) } }