diff options
Diffstat (limited to 'embassy-boot/src/test_flash/asynch.rs')
| -rw-r--r-- | embassy-boot/src/test_flash/asynch.rs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/embassy-boot/src/test_flash/asynch.rs b/embassy-boot/src/test_flash/asynch.rs new file mode 100644 index 000000000..3ac9e71ab --- /dev/null +++ b/embassy-boot/src/test_flash/asynch.rs | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | use embassy_embedded_hal::flash::partition::Partition; | ||
| 2 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; | ||
| 3 | use embassy_sync::mutex::Mutex; | ||
| 4 | use embedded_storage_async::nor_flash::NorFlash; | ||
| 5 | |||
| 6 | use crate::BootLoaderConfig; | ||
| 7 | |||
| 8 | pub struct AsyncTestFlash<ACTIVE, DFU, STATE> | ||
| 9 | where | ||
| 10 | ACTIVE: NorFlash, | ||
| 11 | DFU: NorFlash, | ||
| 12 | STATE: NorFlash, | ||
| 13 | { | ||
| 14 | active: Mutex<NoopRawMutex, ACTIVE>, | ||
| 15 | dfu: Mutex<NoopRawMutex, DFU>, | ||
| 16 | state: Mutex<NoopRawMutex, STATE>, | ||
| 17 | } | ||
| 18 | |||
| 19 | impl<ACTIVE, DFU, STATE> AsyncTestFlash<ACTIVE, DFU, STATE> | ||
| 20 | where | ||
| 21 | ACTIVE: NorFlash, | ||
| 22 | DFU: NorFlash, | ||
| 23 | STATE: NorFlash, | ||
| 24 | { | ||
| 25 | pub fn new(config: BootLoaderConfig<ACTIVE, DFU, STATE>) -> Self { | ||
| 26 | Self { | ||
| 27 | active: Mutex::new(config.active), | ||
| 28 | dfu: Mutex::new(config.dfu), | ||
| 29 | state: Mutex::new(config.state), | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | pub fn active(&self) -> Partition<NoopRawMutex, ACTIVE> { | ||
| 34 | Self::create_partition(&self.active) | ||
| 35 | } | ||
| 36 | |||
| 37 | pub fn dfu(&self) -> Partition<NoopRawMutex, DFU> { | ||
| 38 | Self::create_partition(&self.dfu) | ||
| 39 | } | ||
| 40 | |||
| 41 | pub fn state(&self) -> Partition<NoopRawMutex, STATE> { | ||
| 42 | Self::create_partition(&self.state) | ||
| 43 | } | ||
| 44 | |||
| 45 | fn create_partition<T: NorFlash>(mutex: &Mutex<NoopRawMutex, T>) -> Partition<NoopRawMutex, T> { | ||
| 46 | Partition::new(mutex, 0, mutex.try_lock().unwrap().capacity() as u32) | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | impl<ACTIVE, DFU, STATE> AsyncTestFlash<ACTIVE, DFU, STATE> | ||
| 51 | where | ||
| 52 | ACTIVE: NorFlash + embedded_storage::nor_flash::NorFlash, | ||
| 53 | DFU: NorFlash + embedded_storage::nor_flash::NorFlash, | ||
| 54 | STATE: NorFlash + embedded_storage::nor_flash::NorFlash, | ||
| 55 | { | ||
| 56 | pub fn into_blocking(self) -> super::BlockingTestFlash<ACTIVE, DFU, STATE> { | ||
| 57 | let config = BootLoaderConfig { | ||
| 58 | active: self.active.into_inner(), | ||
| 59 | dfu: self.dfu.into_inner(), | ||
| 60 | state: self.state.into_inner(), | ||
| 61 | }; | ||
| 62 | super::BlockingTestFlash::new(config) | ||
| 63 | } | ||
| 64 | } | ||
