diff options
author | alexmoon <alex.r.moon@gmail.com> | 2022-07-05 14:53:03 -0400 |
---|---|---|
committer | alexmoon <alex.r.moon@gmail.com> | 2022-07-05 23:34:53 -0400 |
commit | ead68804ebe4f41e2b134a2cae3ca3a4424e1f19 (patch) | |
tree | d6cdc8a6497d40c58fc6028f2de248fc5f358dc2 | |
parent | a5026485151138112b522a27c4a340614d7a7512 (diff) | |
download | nrf-softdevice-ead68804ebe4f41e2b134a2cae3ca3a4424e1f19.zip |
Impl `ReadNorFlash` for `Flash`
-rw-r--r-- | nrf-softdevice/src/flash.rs | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/nrf-softdevice/src/flash.rs b/nrf-softdevice/src/flash.rs index 530b4ea..afee483 100644 --- a/nrf-softdevice/src/flash.rs +++ b/nrf-softdevice/src/flash.rs @@ -1,7 +1,7 @@ use core::future::Future; use core::marker::PhantomData; use core::sync::atomic::{AtomicBool, Ordering}; -use embedded_storage::nor_flash::{ErrorType, NorFlashError, NorFlashErrorKind}; +use embedded_storage::nor_flash::{ErrorType, NorFlashError, NorFlashErrorKind, ReadNorFlash}; use embedded_storage_async::nor_flash::{AsyncNorFlash, AsyncReadNorFlash}; use crate::raw; @@ -71,21 +71,18 @@ impl ErrorType for Flash { type Error = FlashError; } -impl AsyncReadNorFlash for Flash { +impl ReadNorFlash for Flash { const READ_SIZE: usize = 1; - type ReadFuture<'a> = impl Future<Output = Result<(), FlashError>> + 'a; - fn read<'a>(&'a mut self, address: u32, data: &'a mut [u8]) -> Self::ReadFuture<'a> { - async move { - // Reading is simple since SoC flash is memory-mapped :) - // TODO check addr/len is in bounds. + fn read(&mut self, address: u32, data: &mut [u8]) -> Result<(), Self::Error> { + // Reading is simple since SoC flash is memory-mapped :) + // TODO check addr/len is in bounds. - data.copy_from_slice(unsafe { - core::slice::from_raw_parts(address as *const u8, data.len()) - }); + data.copy_from_slice(unsafe { + core::slice::from_raw_parts(address as *const u8, data.len()) + }); - Ok(()) - } + Ok(()) } fn capacity(&self) -> usize { @@ -93,6 +90,19 @@ impl AsyncReadNorFlash for Flash { } } +impl AsyncReadNorFlash for Flash { + const READ_SIZE: usize = 1; + + type ReadFuture<'a> = impl Future<Output = Result<(), FlashError>> + 'a; + fn read<'a>(&'a mut self, address: u32, data: &'a mut [u8]) -> Self::ReadFuture<'a> { + async move { <Self as ReadNorFlash>::read(self, address, data) } + } + + fn capacity(&self) -> usize { + <Self as ReadNorFlash>::capacity(self) + } +} + impl AsyncNorFlash for Flash { const WRITE_SIZE: usize = 4; const ERASE_SIZE: usize = 4096; |