summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nrf-softdevice/src/flash.rs34
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;