Struct Spi

Source
pub struct Spi<SPI: Instance, const BIDI: bool = false, W = u8> { /* private fields */ }
Expand description

Spi in Master mode

Implementations§

Source§

impl<SPI: Instance, const BIDI: bool, W: FrameSize> Spi<SPI, BIDI, W>

Source

pub fn init(self) -> Self

Source§

impl<SPI: Instance, W: FrameSize> Spi<SPI, false, W>

Source

pub fn to_bidi_transfer_mode(self) -> Spi<SPI, true, W>

Source§

impl<SPI: Instance, W: FrameSize> Spi<SPI, true, W>

Source

pub fn to_normal_transfer_mode(self) -> Spi<SPI, false, W>

Source§

impl<SPI, const BIDI: bool> Spi<SPI, BIDI, u8>
where SPI: Instance,

Source

pub fn frame_size_16bit(self) -> Spi<SPI, BIDI, u16>

Converts from 8bit dataframe to 16bit.

Source§

impl<SPI, const BIDI: bool> Spi<SPI, BIDI, u16>
where SPI: Instance,

Source

pub fn frame_size_8bit(self) -> Spi<SPI, BIDI, u8>

Converts from 16bit dataframe to 8bit.

Source§

impl<SPI: Instance> Spi<SPI, false, u8>

Source

pub fn new( spi: SPI, pins: (impl Into<SPI::Sck>, impl Into<SPI::Miso>, impl Into<SPI::Mosi>), mode: impl Into<Mode>, freq: Hertz, clocks: &Clocks, ) -> Self

Enables the SPI clock, resets the peripheral, sets Alternate mode for pins and initialize the peripheral as SPI Master Normal mode.

§Note

Depending on freq you may need to set GPIO speed for pins (the Speed::Low is default for GPIO) before create Spi instance. Otherwise it may lead to the ‘wrong last bit in every received byte’ problem.

Source§

impl<SPI: Instance> Spi<SPI, true, u8>

Source

pub fn new_bidi( spi: SPI, pins: (impl Into<SPI::Sck>, impl Into<SPI::Mosi>), mode: impl Into<Mode>, freq: Hertz, clocks: &Clocks, ) -> Self
where NoPin: Into<SPI::Miso>,

Enables the SPI clock, resets the peripheral, sets Alternate mode for pins and initialize the peripheral as SPI Master BIDI mode.

§Note

Depending on freq you may need to set GPIO speed for pins (the Speed::Low is default for GPIO) before create Spi instance. Otherwise it may lead to the ‘wrong last bit in every received byte’ problem.

Source§

impl<SPI: Instance, const BIDI: bool, W> Spi<SPI, BIDI, W>

Source

pub fn release(self) -> (SPI, (SPI::Sck, SPI::Miso, SPI::Mosi))

Source§

impl<SPI: Instance, const BIDI: bool> Spi<SPI, BIDI, u8>

Source

pub fn use_dma(self) -> DmaBuilder<SPI>

Source§

impl<SPI: Instance, const BIDI: bool, W: FrameSize> Spi<SPI, BIDI, W>

Source

pub fn read_nonblocking(&mut self) -> Result<W, Error>

Source

pub fn write_nonblocking(&mut self, byte: W) -> Result<(), Error>

Source

pub fn transfer_in_place(&mut self, words: &mut [W]) -> Result<(), Error>

Source

pub fn transfer(&mut self, buff: &mut [W], data: &[W]) -> Result<(), Error>

Source

pub fn flush(&mut self) -> Result<(), Error>

Source

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

Source

pub fn write_iter( &mut self, words: impl IntoIterator<Item = W>, ) -> Result<(), Error>

Source

pub fn read(&mut self, words: &mut [W]) -> Result<(), Error>

Methods from Deref<Target = Inner<SPI>>§

Source

pub fn enable(&mut self, enable: bool)

Enable/disable spi

Source

pub fn bit_format(&mut self, format: BitFormat)

Select which frame format is used for data transfers

Source

pub fn is_tx_empty(&self) -> bool

Return true if the TXE flag is set, i.e. new data to transmit can be written to the SPI.

Source

pub fn is_rx_not_empty(&self) -> bool

Return true if the RXNE flag is set, i.e. new data has been received and can be read from the SPI.

Source

pub fn is_modf(&self) -> bool

Return true if the MODF flag is set, i.e. the SPI has experienced a Master Mode Fault. (see chapter 28.3.10 of the STM32F4 Reference Manual)

Source

pub fn is_busy(&self) -> bool

Returns true if the transfer is in progress

Source

pub fn is_overrun(&self) -> bool

Return true if the OVR flag is set, i.e. new data has been received while the receive data register was already filled.

Trait Implementations§

Source§

impl<SPI: Debug + Instance, const BIDI: bool, W: Debug> Debug for Spi<SPI, BIDI, W>
where SPI::Sck: Debug, SPI::Miso: Debug, SPI::Mosi: Debug,

Source§

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

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

impl<SPI: Instance, const BIDI: bool, W> Deref for Spi<SPI, BIDI, W>

Source§

type Target = Inner<SPI>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<SPI: Instance, const BIDI: bool, W> DerefMut for Spi<SPI, BIDI, W>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<SPI: Instance, const BIDI: bool, W> ErrorType for Spi<SPI, BIDI, W>

Source§

type Error = Error

Error type.
Source§

impl<SPI, const BIDI: bool, W: FrameSize> FullDuplex<W> for Spi<SPI, BIDI, W>
where SPI: Instance,

Source§

fn read(&mut self) -> Result<W, Error>

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

fn write(&mut self, byte: W) -> Result<(), Error>

Writes a word to the slave
Source§

impl<SPI, const BIDI: bool, W: FrameSize + 'static> SpiBus<W> for Spi<SPI, BIDI, W>
where SPI: Instance,

Source§

fn transfer_in_place(&mut self, words: &mut [W]) -> Result<(), Self::Error>

Write and read simultaneously. The contents of words are written to the slave, and the received words are stored into the same words buffer, overwriting it. Read more
Source§

fn transfer(&mut self, buff: &mut [W], data: &[W]) -> Result<(), Self::Error>

Write and read simultaneously. write is written to the slave on MOSI and words received on MISO are stored in read. Read more
Source§

fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error>

Read words from the slave. Read more
Source§

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

Write words to the slave, ignoring all the incoming words. Read more
Source§

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

Wait until all operations have completed and the bus is idle. Read more
Source§

impl<SPI, const BIDI: bool, W: Copy + 'static> Transactional<W> for Spi<SPI, BIDI, W>
where Self: Transfer<W, Error = Error> + Write<W, Error = Error>, SPI: Instance,

Source§

type Error = Error

Associated error type
Source§

fn exec(&mut self, operations: &mut [Operation<'_, W>]) -> Result<(), Error>

Execute the provided transactions
Source§

impl<SPI, const BIDI: bool> WriteIter<u16> for Spi<SPI, BIDI, u16>
where SPI: Instance,

Source§

type Error = Error

Error type
Source§

fn write_iter<WI>(&mut self, words: WI) -> Result<(), Self::Error>
where WI: IntoIterator<Item = u16>,

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

impl<SPI, const BIDI: bool> WriteIter<u8> for Spi<SPI, BIDI, u8>
where SPI: Instance,

Source§

type Error = Error

Error type
Source§

fn write_iter<WI>(&mut self, words: WI) -> Result<(), Self::Error>
where WI: IntoIterator<Item = u8>,

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

impl<SPI> Transfer<u16> for Spi<SPI, false, u16>
where SPI: Instance,

Source§

type Error = Error

Error type
Source§

fn transfer<'w>( &mut self, words: &'w mut [u16], ) -> Result<&'w [u16], Self::Error>

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

impl<SPI> Transfer<u8> for Spi<SPI, false, u8>
where SPI: Instance,

Source§

type Error = Error

Error type
Source§

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

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

impl<SPI, const BIDI: bool> Write<u16> for Spi<SPI, BIDI, u16>
where SPI: Instance,

Source§

type Error = Error

Error type
Source§

fn write(&mut self, words: &[u16]) -> Result<(), Self::Error>

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

impl<SPI, const BIDI: bool> Write<u8> for Spi<SPI, BIDI, u8>
where SPI: Instance,

Source§

type Error = Error

Error type
Source§

fn write(&mut self, words: &[u8]) -> Result<(), Self::Error>

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

impl<SPI, const BIDI: bool, W: FrameSize> FullDuplex<W> for Spi<SPI, BIDI, W>
where SPI: Instance,

Source§

type Error = Error

An enumeration of SPI errors
Source§

fn read(&mut self) -> Result<W, Error>

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

fn send(&mut self, byte: W) -> Result<(), Error>

Sends a word to the slave

Auto Trait Implementations§

§

impl<SPI, const BIDI: bool, W> Freeze for Spi<SPI, BIDI, W>
where SPI: Freeze, <SPI as SpiCommon>::Sck: Freeze, <SPI as SpiCommon>::Miso: Freeze, <SPI as SpiCommon>::Mosi: Freeze,

§

impl<SPI, const BIDI: bool, W> RefUnwindSafe for Spi<SPI, BIDI, W>

§

impl<SPI, const BIDI: bool, W> Send for Spi<SPI, BIDI, W>
where SPI: Send, <SPI as SpiCommon>::Sck: Send, <SPI as SpiCommon>::Miso: Send, <SPI as SpiCommon>::Mosi: Send, W: Send,

§

impl<SPI, const BIDI: bool, W> Sync for Spi<SPI, BIDI, W>
where SPI: Sync, <SPI as SpiCommon>::Sck: Sync, <SPI as SpiCommon>::Miso: Sync, <SPI as SpiCommon>::Mosi: Sync, W: Sync,

§

impl<SPI, const BIDI: bool, W> Unpin for Spi<SPI, BIDI, W>
where SPI: Unpin, <SPI as SpiCommon>::Sck: Unpin, <SPI as SpiCommon>::Miso: Unpin, <SPI as SpiCommon>::Mosi: Unpin, W: Unpin,

§

impl<SPI, const BIDI: bool, W> UnwindSafe for Spi<SPI, BIDI, W>
where SPI: UnwindSafe, <SPI as SpiCommon>::Sck: UnwindSafe, <SPI as SpiCommon>::Miso: UnwindSafe, <SPI as SpiCommon>::Mosi: UnwindSafe, W: 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.