use core::cell::RefCell; use embassy_embedded_hal::flash::partition::BlockingPartition; use embassy_sync::blocking_mutex::raw::NoopRawMutex; use embassy_sync::blocking_mutex::Mutex; use embedded_storage::nor_flash::NorFlash; use crate::BootLoaderConfig; pub struct BlockingTestFlash where ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, { active: Mutex>, dfu: Mutex>, state: Mutex>, } impl BlockingTestFlash where ACTIVE: NorFlash, DFU: NorFlash, STATE: NorFlash, { pub fn new(config: BootLoaderConfig) -> Self { Self { active: Mutex::new(RefCell::new(config.active)), dfu: Mutex::new(RefCell::new(config.dfu)), state: Mutex::new(RefCell::new(config.state)), } } pub fn active(&self) -> BlockingPartition { Self::create_partition(&self.active) } pub fn dfu(&self) -> BlockingPartition { Self::create_partition(&self.dfu) } pub fn state(&self) -> BlockingPartition { Self::create_partition(&self.state) } pub fn create_partition( mutex: &Mutex>, ) -> BlockingPartition { BlockingPartition::new(mutex, 0, mutex.lock(|f| f.borrow().capacity()) as u32) } } #[cfg(feature = "nightly")] impl BlockingTestFlash where ACTIVE: NorFlash + embedded_storage_async::nor_flash::NorFlash, DFU: NorFlash + embedded_storage_async::nor_flash::NorFlash, STATE: NorFlash + embedded_storage_async::nor_flash::NorFlash, { pub fn into_async(self) -> super::AsyncTestFlash { let config = BootLoaderConfig { active: self.active.into_inner().into_inner(), dfu: self.dfu.into_inner().into_inner(), state: self.state.into_inner().into_inner(), }; super::AsyncTestFlash::new(config) } }