Let Flash<Async/Blocking> be a thing

This commit is contained in:
Rasmus Melchior Jacobsen
2023-05-25 21:40:54 +02:00
parent 18d14dff48
commit 860b519f99
19 changed files with 63 additions and 43 deletions

View File

@ -107,10 +107,16 @@ mod alt_regions {
macro_rules! foreach_altflash_region {
($type_name:ident, $region:ident) => {
impl<MODE> $type_name<'_, MODE> {
pub fn read_blocking(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> {
crate::flash::common::read_blocking(self.0.base, self.0.size, offset, bytes)
}
}
#[cfg(feature = "nightly")]
impl $type_name<'_, Async> {
pub async fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> {
crate::flash::common::read_blocking(self.0.base, self.0.size, offset, bytes)
self.read_blocking(offset, bytes)
}
pub async fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Error> {
@ -124,10 +130,22 @@ mod alt_regions {
}
}
impl embedded_storage::nor_flash::ErrorType for $type_name<'_, Async> {
impl<MODE> embedded_storage::nor_flash::ErrorType for $type_name<'_, MODE> {
type Error = Error;
}
impl<MODE> embedded_storage::nor_flash::ReadNorFlash for $type_name<'_, MODE> {
const READ_SIZE: usize = crate::flash::READ_SIZE;
fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> {
self.read_blocking(offset, bytes)
}
fn capacity(&self) -> usize {
self.0.size as usize
}
}
#[cfg(feature = "nightly")]
impl embedded_storage_async::nor_flash::ReadNorFlash for $type_name<'_, Async> {
const READ_SIZE: usize = crate::flash::READ_SIZE;