Skip to content

Commit 1a3571b

Browse files
committed
Add new function to MultiwriteNorFlash, and bound on MultiwriteNorFlash rather than NorFlash
1 parent 363bce3 commit 1a3571b

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/nor_flash.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,26 @@ pub struct RmwMultiwriteNorFlashStorage<'a, S> {
162162
merge_buffer: &'a mut [u8],
163163
}
164164

165+
impl<'a, S> RmwNorFlashStorage<'a, S>
166+
where
167+
S: MultiwriteNorFlash,
168+
{
169+
/// Instantiate a new generic `Storage` from a `NorFlash` peripheral
170+
///
171+
/// **NOTE** This will panic if the provided merge buffer,
172+
/// is smaller than the erase size of the flash peripheral
173+
pub fn new(nor_flash: S, merge_buffer: &'a mut [u8]) -> Self {
174+
if merge_buffer.len() < S::ERASE_SIZE {
175+
panic!("Merge buffer is too small");
176+
}
177+
178+
Self {
179+
storage: nor_flash,
180+
merge_buffer,
181+
}
182+
}
183+
}
184+
165185
impl<'a, S> ReadStorage for RmwMultiwriteNorFlashStorage<'a, S>
166186
where
167187
S: ReadNorFlash,
@@ -180,7 +200,7 @@ where
180200

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

0 commit comments

Comments
 (0)