Struct stm32_hal2::spi::Spi

source ·
pub struct Spi<R> {
    pub regs: R,
    pub cfg: SpiConfig,
}
Expand description

Represents a Serial Peripheral Interface (SPI) peripheral.

Fields§

§regs: R§cfg: SpiConfig

Implementations§

source§

impl<R> Spi<R>where
R: Deref<Target = RegisterBlock> + RccPeriph,

source

pub fn new(regs: R, cfg: SpiConfig, baud_rate: BaudRate) -> Self

Initialize an SPI peripheral, including configuration register writes, and enabling and resetting its RCC peripheral clock.

source

pub fn reclock(&mut self, baud_rate: BaudRate)

Change the SPI baud rate.

source

pub fn disable(&mut self)

L44 RM, section 40.4.9: “Procedure for disabling the SPI” When SPI is disabled, it is mandatory to follow the disable procedures described in this paragraph. It is important to do this before the system enters a low-power mode when the peripheral clock is stopped. Ongoing transactions can be corrupted in this case. In some modes the disable procedure is the only way to stop continuous communication running.

source

pub fn write<'w>(&mut self, write_words: &'w [u8]) -> Result<(), SpiError>

source

pub fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<(), SpiError>

source

pub unsafe fn write_dma<D>(
&mut self,
buf: &[u8],
channel: DmaChannel,
channel_cfg: ChannelCfg,
dma: &mut Dma<D>
)where
D: Deref<Target = RegisterBlock>,

Transmit data using DMA. See L44 RM, section 40.4.9: Communication using DMA. Note that the channel argument is unused on F3 and L4, since it is hard-coded, and can’t be configured using the DMAMUX peripheral. (dma::mux() fn).

source

pub unsafe fn read_dma(
&mut self,
buf: &mut [u8],
channel: DmaChannel,
channel_cfg: ChannelCfg,
dma_periph: DmaPeriph
)

Receive data using DMA. See L44 RM, section 40.4.9: Communication using DMA. Note that the channel argument is unused on F3 and L4, since it is hard-coded, and can’t be configured using the DMAMUX peripheral. (dma::mux() fn).

source

pub unsafe fn transfer_dma(
&mut self,
buf_write: &[u8],
buf_read: &mut [u8],
channel_write: DmaChannel,
channel_read: DmaChannel,
channel_cfg_write: ChannelCfg,
channel_cfg_read: ChannelCfg,
dma_periph: DmaPeriph
)

Transfer data from DMA; this is the basic reading API, using both write and read transfers: It performs a write with register data, and reads to a buffer.

source

pub fn stop_dma(
&mut self,
channel: DmaChannel,
channel2: Option<DmaChannel>,
dma_periph: DmaPeriph
)

Stop a DMA transfer. Stops the channel, and disables the txdmaen and rxdmaen bits. Run this after each transfer completes - you may wish to do this in an interrupt (eg DMA transfer complete) instead of blocking. channel2 is an optional second channel to stop; eg if you have both a tx and rx channel.

source

pub fn enable_interrupt(&mut self, interrupt_type: SpiInterrupt)

Enable an interrupt.

source

pub fn clear_interrupt(&mut self, interrupt_type: SpiInterrupt)

Clear an interrupt.

Trait Implementations§

source§

impl<R> FullDuplex<u8> for Spi<R>where
R: Deref<Target = RegisterBlock> + RccPeriph,

§

type Error = SpiError

An enumeration of SPI errors
source§

fn read(&mut self) -> Result<u8, SpiError>

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

fn send(&mut self, byte: u8) -> Result<(), SpiError>

Sends a word to the slave
source§

impl<R> Default<u8> for Spi<R>where
R: Deref<Target = RegisterBlock> + RccPeriph,

source§

impl<R> Default<u8> for Spi<R>where
R: Deref<Target = RegisterBlock> + RccPeriph,

Auto Trait Implementations§

§

impl<R> RefUnwindSafe for Spi<R>where
R: RefUnwindSafe,

§

impl<R> Send for Spi<R>where
R: Send,

§

impl<R> Sync for Spi<R>where
R: Sync,

§

impl<R> Unpin for Spi<R>where
R: Unpin,

§

impl<R> UnwindSafe for Spi<R>where
R: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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<W, S> Transfer<W> for Swhere
S: Default<W>,
W: Clone,

§

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<T, U> TryFrom<U> for Twhere
U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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