Struct Spi

Source
pub struct Spi<I, P, State> { /* private fields */ }
Expand description

Entry point to the SPI API

Implementations§

Source§

impl<I, P> Spi<I, P, Disabled>
where I: Instance + Enable + BusClock, P: Pins<I>,

Source

pub fn new(instance: I, pins: P) -> Self

Create a new instance of the SPI API

Source

pub fn enable<Word>( self, mode: Mode, freq: Hertz, clocks: &Clocks, apb: &mut <I as RccBus>::Bus, ) -> Spi<I, P, Enabled<Word>>
where Word: SupportedWordSize,

Initialize the SPI peripheral

Source§

impl<I, P, Word> Spi<I, P, Enabled<Word>>
where I: Instance, P: Pins<I>, Word: SupportedWordSize,

Source

pub fn transfer_all<B>( self, buffer: Pin<B>, dma_rx: &Handle<<Rx<I> as Target>::Instance, Enabled>, dma_tx: &Handle<<Tx<I> as Target>::Instance, Enabled>, rx: <Rx<I> as Target>::Stream, tx: <Tx<I> as Target>::Stream, ) -> Transfer<Word, I, P, B, Rx<I>, Tx<I>, Ready>
where Rx<I>: Target, Tx<I>: Target, B: DerefMut + 'static, B::Target: AsMutSlice<Element = Word>,

Start an SPI transfer using DMA

Sends the data in buffer and writes the received data into buffer right after. Returns a Transfer, to represent the ongoing SPI transfer.

Please note that the word “transfer” is used with two different meanings here:

  • An SPI transfer, as in an SPI transaction that involves both sending and receiving data. The method name refers to this kind of transfer.
  • A DMA transfer, as in an ongoing DMA operation. The name of the return type refers to this kind of transfer.

This method, as well as all other DMA-related methods in this module, requires references to two DMA handles, one each for the RX and TX streams. This will actually always be the same handle, as each SPI instance uses the same DMA instance for both sending and receiving. It would be nice to simplify that, but I believe that requires an equality constraint in the where clause, which is not supported yet by the compiler.

Source§

impl<I, P, State> Spi<I, P, State>
where I: Instance, P: Pins<I>,

Source

pub fn free(self) -> (I, P)

Destroy the peripheral API and return a raw SPI peripheral instance

Trait Implementations§

Source§

impl<I, P, Word> FullDuplex<Word> for Spi<I, P, Enabled<Word>>
where I: Instance, P: Pins<I>, Word: SupportedWordSize,

Source§

type Error = Error

An enumeration of SPI errors
Source§

fn read(&mut self) -> Result<Word, Self::Error>

Reads the word stored in the shift register Read more
Source§

fn send(&mut self, word: Word) -> Result<(), Self::Error>

Sends a word to the slave
Source§

impl<I, P, Word> Default<Word> for Spi<I, P, Enabled<Word>>
where I: Instance, P: Pins<I>, Word: SupportedWordSize,

Source§

impl<I, P, Word> Default<Word> for Spi<I, P, Enabled<Word>>
where I: Instance, P: Pins<I>, Word: SupportedWordSize,

Source§

impl<I, P, Word> Default<Word> for Spi<I, P, Enabled<Word>>
where I: Instance, P: Pins<I>, Word: SupportedWordSize,

Auto Trait Implementations§

§

impl<I, P, State> Freeze for Spi<I, P, State>
where I: Freeze, P: Freeze, State: Freeze,

§

impl<I, P, State> RefUnwindSafe for Spi<I, P, State>

§

impl<I, P, State> Send for Spi<I, P, State>
where I: Send, P: Send, State: Send,

§

impl<I, P, State> Sync for Spi<I, P, State>
where I: Sync, P: Sync, State: Sync,

§

impl<I, P, State> Unpin for Spi<I, P, State>
where I: Unpin, P: Unpin, State: Unpin,

§

impl<I, P, State> UnwindSafe for Spi<I, P, State>
where I: UnwindSafe, P: UnwindSafe, State: 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.
Source§

impl<W, S> WriteIter<W> for S
where S: Default<W>, W: Clone,

Source§

type Error = <S as FullDuplex<W>>::Error

Error type
Source§

fn write_iter<WI>( &mut self, words: WI, ) -> Result<(), <S as FullDuplex<W>>::Error>
where WI: IntoIterator<Item = W>,

Sends words to the slave, ignoring all the incoming words
Source§

impl<W, S> Transfer<W> for S
where S: Default<W>, W: Clone,

Source§

type Error = <S as FullDuplex<W>>::Error

Error type
Source§

fn transfer<'w>( &mut self, words: &'w mut [W], ) -> Result<&'w [W], <S as FullDuplex<W>>::Error>

Sends words to the slave. Returns the words received from the slave
Source§

impl<W, S> Write<W> for S
where S: Default<W>, W: Clone,

Source§

type Error = <S as FullDuplex<W>>::Error

Error type
Source§

fn write(&mut self, words: &[W]) -> Result<(), <S as FullDuplex<W>>::Error>

Sends words to the slave, ignoring all the incoming words