Skip to content

Commit

Permalink
Merge pull request #38 from tweedegolf/erase-all
Browse files Browse the repository at this point in the history
Add erase all function
  • Loading branch information
diondokter authored Mar 28, 2024
2 parents 28e3391 + 3e75445 commit 152f862
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ pub mod mock_flash;
/// Many flashes have 4-byte or 1-byte words.
const MAX_WORD_SIZE: usize = 32;

/// Resets the flash in the entire given flash range.
///
/// This is just a thin helper function as it just calls the flash's erase function.
pub async fn erase_all<S: NorFlash>(
flash: &mut S,
flash_range: Range<u32>,
) -> Result<(), Error<S::Error>> {
flash
.erase(flash_range.start, flash_range.end)
.await
.map_err(|e| Error::Storage {
value: e,
#[cfg(feature = "_test")]
backtrace: std::backtrace::Backtrace::capture(),
})
}

// Type representing buffer aligned to 4 byte boundary.
#[repr(align(4))]
pub(crate) struct AlignedBuf<const SIZE: usize>(pub(crate) [u8; SIZE]);
Expand Down

0 comments on commit 152f862

Please sign in to comment.