Struct Spi

Source
pub struct Spi<SPI, Pins, Word = u8> { /* private fields */ }
Expand description

SPI peripheral operating in full duplex master mode

Implementations§

Source§

impl<SPI, Sck, Miso, Mosi, WORD> Spi<SPI, (Sck, Miso, Mosi), WORD>

Source

pub fn new<Config>( spi: SPI, pins: (Sck, Miso, Mosi), config: Config, clocks: Clocks, apb: &mut <SPI as RccBus>::Bus, ) -> Self
where SPI: Instance, Sck: SckPin<SPI>, Miso: MisoPin<SPI>, Mosi: MosiPin<SPI>, WORD: Word, Config: Into<Config>,

Configures the SPI peripheral to operate in full duplex master mode.

The most convinient way to get a device is like that:

use stm32f3xx_hal::prelude::*;
use stm32f3xx_hal::spi::Spi;

// ...

let spi = Spi::new(dp.SPI1, (sck_pin, mosi_pin, miso_pin), 1.MHz, clocks, &mut dp.abp1);

To get a better example, look here.

Source

pub unsafe fn peripheral(&mut self) -> &mut SPI

Get access to the underlying register block.

§Safety

This function is not memory unsafe per se, but does not guarantee anything about assumptions of invariants made in this implementation.

Changing specific options can lead to un-expected behavior and nothing is guaranteed.

Source

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

Releases the SPI peripheral and associated pins

Source§

impl<SPI, Pins, Word> Spi<SPI, Pins, Word>
where SPI: Instance,

Source

pub fn reclock(&mut self, freq: impl Into<Generic<u32>>, clocks: Clocks)

Change the baud rate of the SPI

Source

pub fn interrupt(&self) -> <SPI as InterruptNumber>::Interrupt

Obtain the associated interrupt number for the serial peripheral.

Used to unmask / enable the interrupt with cortex_m::peripheral::NVIC::unmask(). This is useful for all cortex_m::peripheral::INTERRUPT functions.

Trait Implementations§

Source§

impl<Pins> Debug for Spi<SPI1, Pins>

Source§

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

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

impl<Pins> Debug for Spi<SPI2, Pins>

Source§

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

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

impl<Pins> Debug for Spi<SPI3, Pins>

Source§

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

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

impl<SPI, Sck, Miso, Mosi, Word> FullDuplex<Word> for Spi<SPI, (Sck, Miso, Mosi), Word>
where SPI: Instance, Miso: MisoPin<SPI>, Mosi: MosiPin<SPI>, Word: PrimInt + Into<u32> + 'static, u32: AsPrimitive<Word>,

Source§

type Error = Error

An enumeration of SPI errors
Source§

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

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

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

Sends a word to the slave
Source§

impl<SPI, Sck, Miso, Mosi, Word> Default<Word> for Spi<SPI, (Sck, Miso, Mosi), Word>
where SPI: Instance, Miso: MisoPin<SPI>, Mosi: MosiPin<SPI>, Word: PrimInt + Into<u32> + 'static, u32: AsPrimitive<Word>,

Source§

impl<SPI, Sck, Miso, Mosi, Word> Default<Word> for Spi<SPI, (Sck, Miso, Mosi), Word>
where SPI: Instance, Miso: MisoPin<SPI>, Mosi: MosiPin<SPI>, Word: PrimInt + Into<u32> + 'static, u32: AsPrimitive<Word>,

Auto Trait Implementations§

§

impl<SPI, Pins, Word> Freeze for Spi<SPI, Pins, Word>
where SPI: Freeze, Pins: Freeze,

§

impl<SPI, Pins, Word> RefUnwindSafe for Spi<SPI, Pins, Word>
where SPI: RefUnwindSafe, Pins: RefUnwindSafe, Word: RefUnwindSafe,

§

impl<SPI, Pins, Word> Send for Spi<SPI, Pins, Word>
where SPI: Send, Pins: Send, Word: Send,

§

impl<SPI, Pins, Word> Sync for Spi<SPI, Pins, Word>
where SPI: Sync, Pins: Sync, Word: Sync,

§

impl<SPI, Pins, Word> Unpin for Spi<SPI, Pins, Word>
where SPI: Unpin, Pins: Unpin, Word: Unpin,

§

impl<SPI, Pins, Word> UnwindSafe for Spi<SPI, Pins, Word>
where SPI: UnwindSafe, Pins: UnwindSafe, Word: 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