SPI

Struct SPI 

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

Interface to a SPI peripheral

Controls the SPI. Use Peripherals to gain access to an instance of this struct.

Please refer to the module documentation for more information.

§embedded-hal traits

Implementations§

Source§

impl<I> SPI<I, Disabled>
where I: Instance,

Source

pub fn enable_as_master<SckPin, MosiPin, MisoPin, CLOCK>( self, clock: &Clock<CLOCK>, syscon: &mut Handle, mode: Mode, _sck: Function<I::Sck, Assigned<SckPin>>, _mosi: Function<I::Mosi, Assigned<MosiPin>>, _miso: Function<I::Miso, Assigned<MisoPin>>, ) -> SPI<I, Enabled<Master>>
where CLOCK: ClockSource,

Enable the SPI peripheral in master mode

This method is only available, if SPI is in the Disabled state. Code that attempts to call this method when the peripheral is already enabled will not compile.

Consumes this instance of SPI and returns another instance that has its State type parameter set to Enabled.

§Examples

Please refer to the module documentation for a full example.

Source

pub fn enable_as_slave<C, SckPin, MosiPin, MisoPin, Ssel, SselPin>( self, _clock: &C, syscon: &mut Handle, mode: Mode, _sck: Function<I::Sck, Assigned<SckPin>>, _mosi: Function<I::Mosi, Assigned<MosiPin>>, _miso: Function<I::Miso, Assigned<MisoPin>>, _ssel: Function<Ssel, Assigned<SselPin>>, ) -> SPI<I, Enabled<Slave>>
where C: ClockSource, Ssel: SlaveSelect<I>,

Enable the SPI peripheral in slave mode

This method is only available, if SPI is in the Disabled state. Code that attempts to call this method when the peripheral is already enabled will not compile.

Consumes this instance of SPI and returns another instance that has its State type parameter set to Enabled.

Source§

impl<I, Mode> SPI<I, Enabled<Mode>>
where I: Instance,

Source

pub fn enable_interrupts(&mut self, interrupts: Interrupts)

Enable interrupts

Enables all interrupts set to true in interrupts. Interrupts set to false are not affected.

Source

pub fn disable_interrupts(&mut self, interrupts: Interrupts)

Disable interrupts

Disables all interrupts set to true in interrupts. Interrupts set to false are not affected.

Source

pub fn is_ready_to_receive(&self) -> bool

Indicates whether the SPI instance is ready to receive

Corresponds to the RXRDY flag in the STAT register.

Source

pub fn is_ready_to_transmit(&self) -> bool

Indicates whether the SPI instance is ready to transmit

Corresponds to the TXRDY flag in the STAT register.

Source

pub fn is_slave_select_asserted(&self) -> bool

Indicates whether a slave select signal has been asserted

Corresponds to the SSA flag in the STAT register. The flag is cleared before this method returns.

Source

pub fn is_slave_select_deasserted(&self) -> bool

Indicates whether a slave select signal has been deasserted

Corresponds to the SSD flag in the STAT register. The flag is cleared before this method returns.

Source

pub fn is_master_idle(&self) -> bool

Indicates whether the master is currently idle

Corresponds to the MSTIDLE flag in the STAT register.

Source

pub fn disable(self, syscon: &mut Handle) -> SPI<I, Disabled>

Disable the SPI peripheral

This method is only available, if SPI is in the Enabled state. Code that attempts to call this method when the peripheral is already disabled will not compile.

Consumes this instance of SPI and returns another instance that has its State type parameter set to Disabled.

Source§

impl<I> SPI<I, Enabled<Master>>
where I: Instance,

Source

pub fn transfer_all( self, buffer: &'static mut [u8], rx_channel: Channel<I::RxChannel, Enabled>, tx_channel: Channel<I::TxChannel, Enabled>, ) -> Transfer<Ready, I>

Start an SPI transfer using DMA

Sends all words in the provided buffer, writing the replies back into it.

§Panics

Panics, if the length of buffer is 0 or larger than 1024.

Source§

impl<I> SPI<I, Enabled<Slave>>
where I: Instance,

Source

pub fn receive(&mut self) -> Result<u8, RxOverrunError>

Receive a word

Source

pub fn transmit(&mut self, word: u8) -> Result<(), TxUnderrunError>

Transmit a word

Source§

impl<I, State> SPI<I, State>

Source

pub fn free(self) -> I

Return the raw peripheral

This method serves as an escape hatch from the HAL API. It returns the raw peripheral, allowing you to do whatever you want with it, without limitations imposed by the API.

If you are using this method because a feature you need is missing from the HAL API, please open an issue or, if an issue for your feature request already exists, comment on the existing issue, so we can prioritize it accordingly.

Trait Implementations§

Source§

impl<I: Instance> FullDuplex<u8> for SPI<I, Enabled<Master>>

Source§

type Error = Infallible

An enumeration of SPI errors
Source§

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

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

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

Sends a word to the slave
Source§

impl<I: Instance> Default<u8> for SPI<I, Enabled<Master>>

Source§

impl<I: Instance> Default<u8> for SPI<I, Enabled<Master>>

Auto Trait Implementations§

§

impl<I, State> Freeze for SPI<I, State>
where I: Freeze, State: Freeze,

§

impl<I, State> RefUnwindSafe for SPI<I, State>
where I: RefUnwindSafe, State: RefUnwindSafe,

§

impl<I, State> Send for SPI<I, State>
where I: Send, State: Send,

§

impl<I, State> Sync for SPI<I, State>
where I: Sync, State: Sync,

§

impl<I, State> Unpin for SPI<I, State>
where I: Unpin, State: Unpin,

§

impl<I, State> UnwindSafe for SPI<I, State>
where I: 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> 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