Skip to content

Commit

Permalink
Add test for littlefs macros
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Jan 17, 2025
1 parent 4c28752 commit 4f1c820
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions examples/flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,6 @@ fn main() -> ! {
continue;
}
}

#[cfg(feature = "littlefs")]
lpc55_hal::littlefs2_filesystem!(InternalFilesystem: (0, 10));
12 changes: 6 additions & 6 deletions src/drivers/flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,21 +439,21 @@ macro_rules! littlefs2_filesystem {
type LOOKAHEAD_SIZE = $crate::drivers::flash::littlefs_params::LOOKAHEAD_SIZE;


fn read(&mut self, off: usize, buf: &mut [u8]) -> LfsResult<usize> {
fn read(&mut self, off: usize, buf: &mut [u8]) -> littlefs2::io::Result<usize> {
<$crate::drivers::flash::FlashGordon as $crate::traits::flash::Read<$crate::drivers::flash::U16>>
::read(&self.flash_gordon, Self::BASE_OFFSET + off, buf);
Ok(buf.len())
}

fn write(&mut self, off: usize, data: &[u8]) -> LfsResult<usize> {
fn write(&mut self, off: usize, data: &[u8]) -> littlefs2::io::Result<usize> {
let ret = <$crate::drivers::flash::FlashGordon as $crate::traits::flash::WriteErase<$crate::drivers::flash::U512, $crate::drivers::flash::U512>>
::write(&mut self.flash_gordon, Self::BASE_OFFSET + off, data);
ret
.map(|_| data.len())
.map_err(|_| littlefs2::io::Error::IO)
}

fn erase(&mut self, off: usize, len: usize) -> LfsResult<usize> {
fn erase(&mut self, off: usize, len: usize) -> littlefs2::io::Result<usize> {
let first_page = (Self::BASE_OFFSET + off) / 512;
let pages = len / 512;
for i in 0..pages {
Expand Down Expand Up @@ -523,7 +523,7 @@ macro_rules! littlefs2_prince_filesystem {
type LOOKAHEAD_SIZE = $crate::drivers::flash::littlefs_params::LOOKAHEAD_SIZE;


fn read(&mut self, off: usize, buf: &mut [u8]) -> LfsResult<usize> {
fn read(&mut self, off: usize, buf: &mut [u8]) -> littlefs2::io::Result<usize> {
self.prince.enable_region_2_for(||{
let flash: *const u8 = (Self::BASE_OFFSET + off) as *const u8;
for i in 0 .. buf.len() {
Expand All @@ -533,7 +533,7 @@ macro_rules! littlefs2_prince_filesystem {
Ok(buf.len())
}

fn write(&mut self, off: usize, data: &[u8]) -> LfsResult<usize> {
fn write(&mut self, off: usize, data: &[u8]) -> littlefs2::io::Result<usize> {
let prince = &mut self.prince;
let flash_gordon = &mut self.flash_gordon;
let ret = prince.write_encrypted(|prince| {
Expand All @@ -548,7 +548,7 @@ macro_rules! littlefs2_prince_filesystem {
.map_err(|_| littlefs2::io::Error::IO)
}

fn erase(&mut self, off: usize, len: usize) -> LfsResult<usize> {
fn erase(&mut self, off: usize, len: usize) -> littlefs2::io::Result<usize> {
let first_page = (Self::BASE_OFFSET + off) / 512;
let pages = len / 512;
for i in 0..pages {
Expand Down

0 comments on commit 4f1c820

Please sign in to comment.