Skip to content

Commit

Permalink
Add new function to MultiwriteNorFlash, and bound on MultiwriteNorFla…
Browse files Browse the repository at this point in the history
…sh rather than NorFlash
  • Loading branch information
MathiasKoch committed Mar 24, 2021
1 parent 363bce3 commit 1a3571b
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/nor_flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,26 @@ pub struct RmwMultiwriteNorFlashStorage<'a, S> {
merge_buffer: &'a mut [u8],
}

impl<'a, S> RmwNorFlashStorage<'a, S>
where
S: MultiwriteNorFlash,
{
/// Instantiate a new generic `Storage` from a `NorFlash` peripheral
///
/// **NOTE** This will panic if the provided merge buffer,
/// is smaller than the erase size of the flash peripheral
pub fn new(nor_flash: S, merge_buffer: &'a mut [u8]) -> Self {
if merge_buffer.len() < S::ERASE_SIZE {
panic!("Merge buffer is too small");
}

Self {
storage: nor_flash,
merge_buffer,
}
}
}

impl<'a, S> ReadStorage for RmwMultiwriteNorFlashStorage<'a, S>
where
S: ReadNorFlash,
Expand All @@ -180,7 +200,7 @@ where

impl<'a, S> Storage for RmwMultiwriteNorFlashStorage<'a, S>
where
S: NorFlash,
S: MultiwriteNorFlash,
{
fn try_write(&mut self, address: u32, bytes: &[u8]) -> Result<(), Self::Error> {
// Perform read/modify/write operations on the byte slice.
Expand Down

0 comments on commit 1a3571b

Please sign in to comment.