Embassy
ekv

Crates

git

Versions

default

Flavors

Trait ekv::flash::Flash

source ·
pub trait Flash {
    type Error: Debug;

    // Required methods
    fn page_count(&self) -> usize;
    async fn erase(&mut self, page_id: PageID) -> Result<(), Self::Error>;
    async fn read(
        &mut self,
        page_id: PageID,
        offset: usize,
        data: &mut [u8]
    ) -> Result<(), Self::Error>;
    async fn write(
        &mut self,
        page_id: PageID,
        offset: usize,
        data: &[u8]
    ) -> Result<(), Self::Error>;
}
Expand description

Flash storage trait

Required Associated Types§

source

type Error: Debug

Error type for the flash operations.

Required Methods§

source

fn page_count(&self) -> usize

Get the page count of the flash storage.

source

async fn erase(&mut self, page_id: PageID) -> Result<(), Self::Error>

Erase a page.

If power is lost during an erase, the resulting data is allowed to be anything, but data on other pages must stay unaffected.

After erasing, all bytes in the page must be equal to ERASE_VALUE.

source

async fn read( &mut self, page_id: PageID, offset: usize, data: &mut [u8] ) -> Result<(), Self::Error>

Read data.

offset and data.len() are guaranteed to be a multiple of ALIGN.

source

async fn write( &mut self, page_id: PageID, offset: usize, data: &[u8] ) -> Result<(), Self::Error>

Write data.

If power is lost during a write, the resulting data in the written bytes is allowed to be anything, but data on other bytes within the page must stay unaffected. This means it is NOT okay to implement this with underlying “read-erase-modify-write” strategies.

offset and data.len() are guaranteed to be a multiple of ALIGN.

It is guaranteed that each byte will be written only once after each erase. This ensures maximum compatibility with different flash hardware, in particular flash memory with ECC.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T: Flash> Flash for &mut T

§

type Error = <T as Flash>::Error

source§

fn page_count(&self) -> usize

source§

async fn erase(&mut self, page_id: PageID) -> Result<(), Self::Error>

source§

async fn read( &mut self, page_id: PageID, offset: usize, data: &mut [u8] ) -> Result<(), Self::Error>

source§

async fn write( &mut self, page_id: PageID, offset: usize, data: &[u8] ) -> Result<(), Self::Error>

Implementors§