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,
impl<'d, T> Spi<'d, T, FullDuplexMode>where
T: Instance,
sourcepub fn new(
spi: impl Peripheral<P = T> + 'd,
frequency: HertzU32,
mode: SpiMode,
clocks: &Clocks<'_>
) -> Spi<'d, T, FullDuplexMode>
pub fn new( spi: impl Peripheral<P = T> + 'd, frequency: HertzU32, 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.
pub fn with_sck<SCK: OutputPin>( self, sck: impl Peripheral<P = SCK> + 'd ) -> Self
pub fn with_mosi<MOSI: OutputPin>( self, mosi: impl Peripheral<P = MOSI> + 'd ) -> Self
pub fn with_miso<MISO: InputPin>( self, miso: impl Peripheral<P = MISO> + 'd ) -> Self
pub fn with_cs<CS: OutputPin>(self, cs: impl Peripheral<P = CS> + 'd) -> Self
sourcepub fn with_pins<SCK: OutputPin, MOSI: OutputPin, MISO: InputPin, CS: OutputPin>(
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>
) -> Self
pub fn with_pins<SCK: OutputPin, MOSI: OutputPin, MISO: InputPin, CS: OutputPin>( 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> ) -> Self
Setup pins for this SPI instance.
All pins are optional. Pass crate::gpio::NO_PIN if you don’t need the given pin.
pub fn change_bus_frequency(&mut self, frequency: HertzU32, clocks: &Clocks<'_>)
source§impl<'d, T> Spi<'d, T, HalfDuplexMode>where
T: ExtendedInstance,
impl<'d, T> Spi<'d, T, HalfDuplexMode>where
T: ExtendedInstance,
sourcepub fn new_half_duplex(
spi: impl Peripheral<P = T> + 'd,
frequency: HertzU32,
mode: SpiMode,
clocks: &Clocks<'_>
) -> Spi<'d, T, HalfDuplexMode>
pub fn new_half_duplex( spi: impl Peripheral<P = T> + 'd, frequency: HertzU32, 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.
pub fn with_sck<SCK: OutputPin>( self, sck: impl Peripheral<P = SCK> + 'd ) -> Self
pub fn with_mosi<MOSI: OutputPin + InputPin>( self, mosi: impl Peripheral<P = MOSI> + 'd ) -> Self
pub fn with_miso<MISO: OutputPin + InputPin>( self, miso: impl Peripheral<P = MISO> + 'd ) -> Self
pub fn with_sio2<SIO2: OutputPin + InputPin>( self, sio2: impl Peripheral<P = SIO2> + 'd ) -> Self
pub fn with_sio3<SIO3: OutputPin + InputPin>( self, sio3: impl Peripheral<P = SIO3> + 'd ) -> Self
pub fn with_cs<CS: OutputPin>(self, cs: impl Peripheral<P = CS> + 'd) -> Self
sourcepub fn with_pins<SCK: OutputPin, MOSI: OutputPin + InputPin, MISO: OutputPin + InputPin, SIO2: OutputPin + InputPin, SIO3: OutputPin + InputPin, CS: OutputPin>(
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>
) -> Self
pub fn with_pins<SCK: OutputPin, MOSI: OutputPin + InputPin, MISO: OutputPin + InputPin, SIO2: OutputPin + InputPin, SIO3: OutputPin + InputPin, CS: OutputPin>( 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> ) -> Self
Setup pins for this SPI instance.
All pins are optional. Pass crate::gpio::NO_PIN if you don’t need the given pin.
pub fn change_bus_frequency(&mut self, frequency: HertzU32, clocks: &Clocks<'_>)
Trait Implementations§
source§impl<T, M> FullDuplex for Spi<'_, T, M>where
T: Instance,
M: IsFullDuplex,
impl<T, M> FullDuplex for Spi<'_, T, M>where
T: Instance,
M: IsFullDuplex,
source§impl<T, M> HalfDuplexReadWrite for Spi<'_, T, M>where
T: Instance,
M: IsHalfDuplex,
impl<T, M> HalfDuplexReadWrite for Spi<'_, T, M>where
T: Instance,
M: IsHalfDuplex,
source§impl<T, M> SpiBus for Spi<'_, T, M>where
T: Instance,
M: IsFullDuplex,
impl<T, M> SpiBus for Spi<'_, T, M>where
T: Instance,
M: IsFullDuplex,
source§fn read(&mut self, words: &mut [u8]) -> Result<(), Self::Error>
fn read(&mut self, words: &mut [u8]) -> Result<(), Self::Error>
Read
words from the slave. Read moresource§fn write(&mut self, words: &[u8]) -> Result<(), Self::Error>
fn write(&mut self, words: &[u8]) -> Result<(), Self::Error>
Write
words to the slave, ignoring all the incoming words. Read moresource§fn transfer(&mut self, read: &mut [u8], write: &[u8]) -> Result<(), Self::Error>
fn transfer(&mut self, read: &mut [u8], write: &[u8]) -> 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 moresource§impl<'d, C, M> WithDmaSpi2<'d, C, M> for Spi<'d, SPI2, M>
impl<'d, C, M> WithDmaSpi2<'d, C, M> for Spi<'d, SPI2, M>
source§impl<T, M> FullDuplex<u8> for Spi<'_, T, M>where
T: Instance,
M: IsFullDuplex,
impl<T, M> FullDuplex<u8> for Spi<'_, T, M>where
T: Instance,
M: IsFullDuplex,
Auto Trait Implementations§
impl<'d, T, M> Freeze for Spi<'d, T, M>where
T: Freeze,
impl<'d, T, M> RefUnwindSafe for Spi<'d, T, M>where
M: RefUnwindSafe,
T: RefUnwindSafe,
impl<'d, T, M> Send for Spi<'d, T, M>
impl<'d, T, M> Sync for Spi<'d, T, M>
impl<'d, T, M> Unpin for Spi<'d, T, M>
impl<'d, T, M> !UnwindSafe for Spi<'d, T, M>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more