|
| 1 | +use core::future::Future; |
| 2 | +use embedded_storage::nor_flash::NorFlashError; |
| 3 | + |
| 4 | +/// Read only NOR flash trait. |
| 5 | +pub trait AsyncReadNorFlash { |
| 6 | + /// Errors returned by this NOR flash. |
| 7 | + type Error: NorFlashError; |
| 8 | + |
| 9 | + /// The minumum number of bytes the storage peripheral can read |
| 10 | + const READ_SIZE: usize; |
| 11 | + |
| 12 | + type ReadFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a |
| 13 | + where |
| 14 | + Self: 'a; |
| 15 | + |
| 16 | + /// Read a slice of data from the storage peripheral, starting the read |
| 17 | + /// operation at the given address offset, and reading `bytes.len()` bytes. |
| 18 | + /// |
| 19 | + /// # Errors |
| 20 | + /// |
| 21 | + /// Returns an error if the arguments are not aligned or out of bounds. The implementation |
| 22 | + /// can use the [`check_read`] helper function. |
| 23 | + fn read<'a>(&'a mut self, offset: u32, bytes: &'a mut [u8]) -> Self::ReadFuture<'a>; |
| 24 | + |
| 25 | + /// The capacity of the peripheral in bytes. |
| 26 | + fn capacity(&self) -> usize; |
| 27 | +} |
| 28 | + |
| 29 | +/// NOR flash trait. |
| 30 | +pub trait AsyncNorFlash: AsyncReadNorFlash { |
| 31 | + /// The minumum number of bytes the storage peripheral can write |
| 32 | + const WRITE_SIZE: usize; |
| 33 | + |
| 34 | + /// The minumum number of bytes the storage peripheral can erase |
| 35 | + const ERASE_SIZE: usize; |
| 36 | + |
| 37 | + /// Erase the given storage range, clearing all data within `[from..to]`. |
| 38 | + /// The given range will contain all 1s afterwards. |
| 39 | + /// |
| 40 | + /// If power is lost during erase, contents of the page are undefined. |
| 41 | + /// |
| 42 | + /// # Errors |
| 43 | + /// |
| 44 | + /// Returns an error if the arguments are not aligned or out of bounds (the case where `to > |
| 45 | + /// from` is considered out of bounds). The implementation can use the [`check_erase`] |
| 46 | + /// helper function. |
| 47 | + type EraseFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a |
| 48 | + where |
| 49 | + Self: 'a; |
| 50 | + fn erase<'a>(&'a mut self, from: u32, to: u32) -> Self::EraseFuture<'a>; |
| 51 | + |
| 52 | + /// If power is lost during write, the contents of the written words are undefined, |
| 53 | + /// but the rest of the page is guaranteed to be unchanged. |
| 54 | + /// It is not allowed to write to the same word twice. |
| 55 | + /// |
| 56 | + /// # Errors |
| 57 | + /// |
| 58 | + /// Returns an error if the arguments are not aligned or out of bounds. The implementation |
| 59 | + /// can use the [`check_write`] helper function. |
| 60 | + type WriteFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a |
| 61 | + where |
| 62 | + Self: 'a; |
| 63 | + fn write<'a>(&'a mut self, offset: u32, bytes: &'a [u8]) -> Self::WriteFuture<'a>; |
| 64 | +} |
0 commit comments