Struct esp32_hal::spi::master::Spi

source ·
pub struct Spi<'d, T, M> { /* private fields */ }
Expand description

SPI peripheral driver

Implementations§

source§

impl<'d, T> Spi<'d, T, FullDuplexMode>
where T: Instance,

source

pub fn new( spi: impl Peripheral<P = T> + 'd, frequency: Rate<u32, 1, 1>, mode: SpiMode, clocks: &Clocks<'_> ) -> Spi<'d, T, FullDuplexMode>

Constructs an SPI instance in 8bit dataframe mode.

All pins are optional. Setup these pins using with_pins or individual methods for each pin.

source

pub fn with_sck<SCK>( self, sck: impl Peripheral<P = SCK> + 'd ) -> Spi<'d, T, FullDuplexMode>
where SCK: OutputPin,

source

pub fn with_mosi<MOSI>( self, mosi: impl Peripheral<P = MOSI> + 'd ) -> Spi<'d, T, FullDuplexMode>
where MOSI: OutputPin,

source

pub fn with_miso<MISO>( self, miso: impl Peripheral<P = MISO> + 'd ) -> Spi<'d, T, FullDuplexMode>
where MISO: InputPin,

source

pub fn with_cs<CS>( self, cs: impl Peripheral<P = CS> + 'd ) -> Spi<'d, T, FullDuplexMode>
where CS: OutputPin,

source

pub fn with_pins<SCK, MOSI, MISO, CS>( self, sck: Option<impl Peripheral<P = SCK> + 'd>, mosi: Option<impl Peripheral<P = MOSI> + 'd>, miso: Option<impl Peripheral<P = MISO> + 'd>, cs: Option<impl Peripheral<P = CS> + 'd> ) -> Spi<'d, T, FullDuplexMode>
where SCK: OutputPin, MOSI: OutputPin, MISO: InputPin, CS: OutputPin,

Setup pins for this SPI instance.

All pins are optional. Pass crate::gpio::NO_PIN if you don’t need the given pin.

source

pub fn change_bus_frequency( &mut self, frequency: Rate<u32, 1, 1>, clocks: &Clocks<'_> )

source§

impl<'d, T> Spi<'d, T, HalfDuplexMode>

source

pub fn new_half_duplex( spi: impl Peripheral<P = T> + 'd, frequency: Rate<u32, 1, 1>, mode: SpiMode, clocks: &Clocks<'_> ) -> Spi<'d, T, HalfDuplexMode>

Constructs an SPI instance in half-duplex mode.

All pins are optional. Setup these pins using with_pins or individual methods for each pin.

source

pub fn with_sck<SCK>( self, sck: impl Peripheral<P = SCK> + 'd ) -> Spi<'d, T, HalfDuplexMode>
where SCK: OutputPin,

source

pub fn with_mosi<MOSI>( self, mosi: impl Peripheral<P = MOSI> + 'd ) -> Spi<'d, T, HalfDuplexMode>
where MOSI: OutputPin + InputPin,

source

pub fn with_miso<MISO>( self, miso: impl Peripheral<P = MISO> + 'd ) -> Spi<'d, T, HalfDuplexMode>
where MISO: OutputPin + InputPin,

source

pub fn with_sio2<SIO2>( self, sio2: impl Peripheral<P = SIO2> + 'd ) -> Spi<'d, T, HalfDuplexMode>
where SIO2: OutputPin + InputPin,

source

pub fn with_sio3<SIO3>( self, sio3: impl Peripheral<P = SIO3> + 'd ) -> Spi<'d, T, HalfDuplexMode>
where SIO3: OutputPin + InputPin,

source

pub fn with_cs<CS>( self, cs: impl Peripheral<P = CS> + 'd ) -> Spi<'d, T, HalfDuplexMode>
where CS: OutputPin,

source

pub fn with_pins<SCK, MOSI, MISO, SIO2, SIO3, CS>( self, sck: Option<impl Peripheral<P = SCK> + 'd>, mosi: Option<impl Peripheral<P = MOSI> + 'd>, miso: Option<impl Peripheral<P = MISO> + 'd>, sio2: Option<impl Peripheral<P = SIO2> + 'd>, sio3: Option<impl Peripheral<P = SIO3> + 'd>, cs: Option<impl Peripheral<P = CS> + 'd> ) -> Spi<'d, T, HalfDuplexMode>
where SCK: OutputPin, MOSI: OutputPin + InputPin, MISO: OutputPin + InputPin, SIO2: OutputPin + InputPin, SIO3: OutputPin + InputPin, CS: OutputPin,

Setup pins for this SPI instance.

All pins are optional. Pass crate::gpio::NO_PIN if you don’t need the given pin.

source

pub fn change_bus_frequency( &mut self, frequency: Rate<u32, 1, 1>, clocks: &Clocks<'_> )

Trait Implementations§

source§

impl<T, M> HalfDuplexReadWrite for Spi<'_, T, M>
where T: Instance, M: IsHalfDuplex,

§

type Error = Error

source§

fn read( &mut self, data_mode: SpiDataMode, cmd: Command, address: Address, dummy: u8, buffer: &mut [u8] ) -> Result<(), <Spi<'_, T, M> as HalfDuplexReadWrite>::Error>

Half-duplex read.
source§

fn write( &mut self, data_mode: SpiDataMode, cmd: Command, address: Address, dummy: u8, buffer: &[u8] ) -> Result<(), <Spi<'_, T, M> as HalfDuplexReadWrite>::Error>

Half-duplex write.
source§

impl<T, M> Transfer<u8> for Spi<'_, T, M>
where T: Instance, M: IsFullDuplex,

§

type Error = Error

Error type
source§

fn transfer<'w>( &mut self, words: &'w mut [u8] ) -> Result<&'w [u8], <Spi<'_, T, M> as Transfer<u8>>::Error>

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

impl<T, M> Write<u8> for Spi<'_, T, M>
where T: Instance, M: IsFullDuplex,

§

type Error = Error

Error type
source§

fn write( &mut self, words: &[u8] ) -> Result<(), <Spi<'_, T, M> as Write<u8>>::Error>

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

impl<T, M> FullDuplex<u8> for Spi<'_, T, M>
where T: Instance, M: IsFullDuplex,

§

type Error = Error

An enumeration of SPI errors
source§

fn read( &mut self ) -> Result<u8, Error<<Spi<'_, T, M> as FullDuplex<u8>>::Error>>

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

fn send( &mut self, word: u8 ) -> Result<(), Error<<Spi<'_, T, M> as FullDuplex<u8>>::Error>>

Sends a word to the slave
source§

impl<'d, C, M> WithDmaSpi2<'d, C, M> for Spi<'d, SPI2, M>

source§

fn with_dma(self, channel: Channel<'d, C>) -> SpiDma<'d, SPI2, C, M>

source§

impl<'d, C, M> WithDmaSpi3<'d, C, M> for Spi<'d, SPI3, M>

source§

fn with_dma(self, channel: Channel<'d, C>) -> SpiDma<'d, SPI3, C, M>

Auto Trait Implementations§

§

impl<'d, T, M> RefUnwindSafe for Spi<'d, T, M>

§

impl<'d, T, M> Send for Spi<'d, T, M>
where M: Send, T: Send,

§

impl<'d, T, M> Sync for Spi<'d, T, M>
where M: Sync, T: Sync,

§

impl<'d, T, M> Unpin for Spi<'d, T, M>
where M: Unpin, T: Unpin,

§

impl<'d, T, M> !UnwindSafe for Spi<'d, T, M>

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>,

§

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>,

§

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.