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
embedded_hal::spi::FullDuplexfor asynchronous transfersembedded_hal::blocking::spi::Transferfor synchronous transfersembedded_hal::blocking::spi::Writefor synchronous writes
Implementations§
Source§impl<I> SPI<I, Disabled>where
I: Instance,
impl<I> SPI<I, Disabled>where
I: Instance,
Sourcepub 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,
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.
Sourcepub 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>,
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,
impl<I, Mode> SPI<I, Enabled<Mode>>where
I: Instance,
Sourcepub fn enable_interrupts(&mut self, interrupts: Interrupts)
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.
Sourcepub fn disable_interrupts(&mut self, interrupts: Interrupts)
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.
Sourcepub fn is_ready_to_receive(&self) -> bool
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.
Sourcepub fn is_ready_to_transmit(&self) -> bool
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.
Sourcepub fn is_slave_select_asserted(&self) -> bool
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.
Sourcepub fn is_slave_select_deasserted(&self) -> bool
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.
Sourcepub fn is_master_idle(&self) -> bool
pub fn is_master_idle(&self) -> bool
Indicates whether the master is currently idle
Corresponds to the MSTIDLE flag in the STAT register.
Source§impl<I> SPI<I, Enabled<Master>>where
I: Instance,
impl<I> SPI<I, Enabled<Master>>where
I: Instance,
Sourcepub fn transfer_all(
self,
buffer: &'static mut [u8],
rx_channel: Channel<I::RxChannel, Enabled>,
tx_channel: Channel<I::TxChannel, Enabled>,
) -> Transfer<Ready, I>
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, State> SPI<I, State>
impl<I, State> SPI<I, State>
Sourcepub fn free(self) -> I
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.