summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <dirbaio@dirbaio.net>2022-07-06 16:19:16 +0200
committerGitHub <noreply@github.com>2022-07-06 16:19:16 +0200
commit92139b7c647b6ca2242b0b304b6685e0b2b0dba2 (patch)
tree1cbc4466cd7bcd1c274e88de5b0c10656e94c98c
parent60655f023612131ee7a44cf5c9415b4b9b11e4c0 (diff)
parentead68804ebe4f41e2b134a2cae3ca3a4424e1f19 (diff)
downloadnrf-softdevice-92139b7c647b6ca2242b0b304b6685e0b2b0dba2.zip
Merge pull request #120 from alexmoon/sync-read-flash
Impl `ReadNorFlash` for `Flash`
-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;