pub struct Spi<'d, T, M> { /* private fields */ }
Expand description
SPI peripheral driver
Implementations§
§impl<'d, T> Spi<'d, T, FullDuplexMode>where
T: Instance,
impl<'d, T> Spi<'d, T, FullDuplexMode>where
T: Instance,
pub fn new(
spi: impl Peripheral<P = T> + 'd,
frequency: Rate<u32, 1, 1>,
mode: SpiMode,
clocks: &Clocks<'_>
) -> Spi<'d, T, FullDuplexMode>
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.
pub fn with_sck<SCK>(
self,
sck: impl Peripheral<P = SCK> + 'd
) -> Spi<'d, T, FullDuplexMode>where
SCK: OutputPin,
pub fn with_mosi<MOSI>(
self,
mosi: impl Peripheral<P = MOSI> + 'd
) -> Spi<'d, T, FullDuplexMode>where
MOSI: OutputPin,
pub fn with_miso<MISO>(
self,
miso: impl Peripheral<P = MISO> + 'd
) -> Spi<'d, T, FullDuplexMode>where
MISO: InputPin,
pub fn with_cs<CS>(
self,
cs: impl Peripheral<P = CS> + 'd
) -> Spi<'d, T, FullDuplexMode>where
CS: OutputPin,
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>
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>
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: Rate<u32, 1, 1>, clocks: &Clocks<'_> )
§impl<'d, T> Spi<'d, T, HalfDuplexMode>where
T: ExtendedInstance,
impl<'d, T> Spi<'d, T, HalfDuplexMode>where
T: ExtendedInstance,
pub fn new_half_duplex(
spi: impl Peripheral<P = T> + 'd,
frequency: Rate<u32, 1, 1>,
mode: SpiMode,
clocks: &Clocks<'_>
) -> Spi<'d, T, HalfDuplexMode>
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.
pub fn with_sck<SCK>(
self,
sck: impl Peripheral<P = SCK> + 'd
) -> Spi<'d, T, HalfDuplexMode>where
SCK: OutputPin,
pub fn with_mosi<MOSI>( self, mosi: impl Peripheral<P = MOSI> + 'd ) -> Spi<'d, T, HalfDuplexMode>
pub fn with_miso<MISO>( self, miso: impl Peripheral<P = MISO> + 'd ) -> Spi<'d, T, HalfDuplexMode>
pub fn with_sio2<SIO2>( self, sio2: impl Peripheral<P = SIO2> + 'd ) -> Spi<'d, T, HalfDuplexMode>
pub fn with_sio3<SIO3>( self, sio3: impl Peripheral<P = SIO3> + 'd ) -> Spi<'d, T, HalfDuplexMode>
pub fn with_cs<CS>(
self,
cs: impl Peripheral<P = CS> + 'd
) -> Spi<'d, T, HalfDuplexMode>where
CS: OutputPin,
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>
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>
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: Rate<u32, 1, 1>, clocks: &Clocks<'_> )
Trait Implementations§
§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,
§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,
§fn read(
&mut self,
words: &mut [u8]
) -> Result<(), <Spi<'_, T, M> as ErrorType>::Error>
fn read( &mut self, words: &mut [u8] ) -> Result<(), <Spi<'_, T, M> as ErrorType>::Error>
Read
words
from the slave. Read more§fn write(
&mut self,
words: &[u8]
) -> Result<(), <Spi<'_, T, M> as ErrorType>::Error>
fn write( &mut self, words: &[u8] ) -> Result<(), <Spi<'_, T, M> as ErrorType>::Error>
Write
words
to the slave, ignoring all the incoming words. Read more§fn transfer(
&mut self,
read: &mut [u8],
write: &[u8]
) -> Result<(), <Spi<'_, T, M> as ErrorType>::Error>
fn transfer( &mut self, read: &mut [u8], write: &[u8] ) -> Result<(), <Spi<'_, T, M> as ErrorType>::Error>
Write and read simultaneously.
write
is written to the slave on MOSI and
words received on MISO are stored in read
. Read more§fn transfer_in_place(
&mut self,
words: &mut [u8]
) -> Result<(), <Spi<'_, T, M> as ErrorType>::Error>
fn transfer_in_place( &mut self, words: &mut [u8] ) -> Result<(), <Spi<'_, T, M> as ErrorType>::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 moreAuto 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
T: RefUnwindSafe,
M: RefUnwindSafe,
impl<'d, T, M> Send for Spi<'d, T, M>where
T: Send,
M: Send,
impl<'d, T, M> Sync for Spi<'d, T, M>where
T: Sync,
M: Sync,
impl<'d, T, M> Unpin for Spi<'d, T, M>where
T: Unpin,
M: Unpin,
impl<'d, T, M> !UnwindSafe for Spi<'d, T, M>
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
§impl<T, U> Into<U> for Twhere
U: From<T>,
impl<T, U> Into<U> for Twhere
U: From<T>,
source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
§impl<T, U> TryFrom<U> for Twhere
U: Into<T>,
impl<T, U> TryFrom<U> for Twhere
U: Into<T>,
§impl<T, U> TryInto<U> for Twhere
U: TryFrom<T>,
impl<T, U> TryInto<U> for Twhere
U: TryFrom<T>,
source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.