Struct Flash

Source
pub struct Flash<SPI: Transfer<u8>, CS: OutputPin> { /* private fields */ }
Expand description

Driver for 25-series SPI Flash chips.

§Type Parameters

  • SPI: The SPI master to which the flash chip is attached.
  • CS: The Chip-Select line attached to the \CS/\CE pin of the flash chip.

Implementations§

Source§

impl<SPI: Transfer<u8>, CS: OutputPin> Flash<SPI, CS>

Source

pub fn init(spi: SPI, cs: CS) -> Result<Self, Error<SPI, CS>>

Creates a new 25-series flash driver.

§Parameters
  • spi: An SPI master. Must be configured to operate in the correct mode for the device.
  • cs: The Chip-Select Pin connected to the \CS/\CE pin of the flash chip. Will be driven low when accessing the device.
Source

pub fn read_jedec_id(&mut self) -> Result<Identification, Error<SPI, CS>>

Reads the JEDEC manufacturer/device identification.

Source

pub fn read_status(&mut self) -> Result<Status, Error<SPI, CS>>

Reads the status register.

Trait Implementations§

Source§

impl<SPI: Transfer<u8>, CS: OutputPin> BlockDevice<u32, SPI, CS> for Flash<SPI, CS>

Source§

fn erase_sectors( &mut self, addr: u32, amount: usize, ) -> Result<(), Error<SPI, CS>>

Erases sectors from the memory chip. Read more
Source§

fn write_bytes( &mut self, addr: u32, data: &mut [u8], ) -> Result<(), Error<SPI, CS>>

Writes bytes onto the memory chip. This method is supposed to assume that the sectors it is writing to have already been erased and should not do any erasing themselves. Read more
Source§

fn erase_all(&mut self) -> Result<(), Error<SPI, CS>>

Erases the memory chip fully. Read more
Source§

impl<SPI: Debug + Transfer<u8>, CS: Debug + OutputPin> Debug for Flash<SPI, CS>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<SPI: Transfer<u8>, CS: OutputPin> Read<u32, SPI, CS> for Flash<SPI, CS>

Source§

fn read(&mut self, addr: u32, buf: &mut [u8]) -> Result<(), Error<SPI, CS>>

Reads flash contents into buf, starting at addr.

Note that addr is not fully decoded: Flash chips will typically only look at the lowest N bits needed to encode their size, which means that the contents are “mirrored” to addresses that are a multiple of the flash size. Only 24 bits of addr are transferred to the device in any case, limiting the maximum size of 25-series SPI flash chips to 16 MiB.

§Parameters
  • addr: 24-bit address to start reading at.
  • buf: Destination buffer to fill.

Auto Trait Implementations§

§

impl<SPI, CS> Freeze for Flash<SPI, CS>
where SPI: Freeze, CS: Freeze,

§

impl<SPI, CS> RefUnwindSafe for Flash<SPI, CS>
where SPI: RefUnwindSafe, CS: RefUnwindSafe,

§

impl<SPI, CS> Send for Flash<SPI, CS>
where SPI: Send, CS: Send,

§

impl<SPI, CS> Sync for Flash<SPI, CS>
where SPI: Sync, CS: Sync,

§

impl<SPI, CS> Unpin for Flash<SPI, CS>
where SPI: Unpin, CS: Unpin,

§

impl<SPI, CS> UnwindSafe for Flash<SPI, CS>
where SPI: UnwindSafe, CS: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.