FlashAccess

Trait FlashAccess 

Source
pub trait FlashAccess {
    type Error;

    // Required method
    fn exchange(&mut self, data: &[u8]) -> Result<Vec<u8>, Self::Error>;

    // Provided methods
    fn write(&mut self, data: &[u8]) -> Result<(), Self::Error> { ... }
    fn delay(&mut self, duration: Duration) { ... }
}
Expand description

Trait for objects which provide access to SPI flash.

Providers only need to implement exchange(), which asserts CS, writes all the bytes in data, then returns all the received bytes. If it provides a performance optimisation, providers may also implement write(), which does not require the received data.

From<FlashAccess::Error> must be implemented for spi_flash::Error; for example in your implementation code, add:

impl From<MyError> for spi_flash::Error {
    fn from(err: MyError) -> spi_flash::Error {
        spi_flash::Error::Access(err.into())
    }
}

Required Associated Types§

Required Methods§

Source

fn exchange(&mut self, data: &[u8]) -> Result<Vec<u8>, Self::Error>

Assert CS, write all bytes in data while capturing received data, then de-assert CS.

Returns the received data.

Provided Methods§

Source

fn write(&mut self, data: &[u8]) -> Result<(), Self::Error>

Assert CS, write all bytes in data to the SPI bus, then de-assert CS.

Source

fn delay(&mut self, duration: Duration)

Wait for at least duration.

This delay is advisory and reduces polling traffic based on known typical flash instruction times, so may be left unimplemented.

The default implementation uses std::thread::delay on std, and is a no-op on no_std.

Implementors§