From ead68804ebe4f41e2b134a2cae3ca3a4424e1f19 Mon Sep 17 00:00:00 2001 From: alexmoon Date: Tue, 5 Jul 2022 14:53:03 -0400 Subject: Impl `ReadNorFlash` for `Flash` --- nrf-softdevice/src/flash.rs | 34 ++++++++++++++++++++++------------ 1 file 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> + '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> + 'a; + fn read<'a>(&'a mut self, address: u32, data: &'a mut [u8]) -> Self::ReadFuture<'a> { + async move { ::read(self, address, data) } + } + + fn capacity(&self) -> usize { + ::capacity(self) + } +} + impl AsyncNorFlash for Flash { const WRITE_SIZE: usize = 4; const ERASE_SIZE: usize = 4096; -- cgit v1.2.3