Skip to content

Commit 0895ce4

Browse files
committed
Add ReadNorFlash::read_if_not_empty
1 parent 95861f8 commit 0895ce4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/nor_flash.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ pub trait ReadNorFlash: ErrorType {
6868
/// can use the [`check_read`] helper function.
6969
fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error>;
7070

71+
/// Read a slice of data from the storage peripheral, starting the read
72+
/// operation at the given address offset, and reading `bytes.len()` bytes.
73+
///
74+
/// The function returns `Ok(true)` if the data is considered to be non-empty.
75+
/// The value of `bytes` should not be considered reliable if the function returns `Ok(false)`.
76+
///
77+
/// This function is useful for devices that offer transparent flash encryption,
78+
/// and for devices where the erased byte value is not `0xFF`.
79+
///
80+
/// # Errors
81+
///
82+
/// Returns an error if the arguments are not aligned or out of bounds. The implementation
83+
/// can use the [`check_read`] helper function.
84+
fn read_if_not_empty(&mut self, offset: u32, bytes: &mut [u8]) -> Result<bool, Self::Error> {
85+
self.read(offset, bytes)?;
86+
Ok(!bytes.iter().all(|&b| b == 0xFF))
87+
}
88+
7189
/// The capacity of the peripheral in bytes.
7290
fn capacity(&self) -> usize;
7391
}

0 commit comments

Comments
 (0)