pub struct Spi<'d, PIO: Instance, const SM: usize, M: Mode> { /* private fields */ }
Expand description
PIO based Spi driver. Unlike other PIO programs, the PIO SPI driver owns and holds a reference to the PIO memory it uses. This is so that it can be reconfigured at runtime if desired.
Implementations§
Source§impl<'d, PIO: Instance, const SM: usize, M: Mode> Spi<'d, PIO, SM, M>
impl<'d, PIO: Instance, const SM: usize, M: Mode> Spi<'d, PIO, SM, M>
Sourcepub fn blocking_read(&mut self, data: &mut [u8]) -> Result<(), Error>
pub fn blocking_read(&mut self, data: &mut [u8]) -> Result<(), Error>
Read data from SPI blocking execution until done.
Sourcepub fn blocking_write(&mut self, data: &[u8]) -> Result<(), Error>
pub fn blocking_write(&mut self, data: &[u8]) -> Result<(), Error>
Write data to SPI blocking execution until done.
Sourcepub fn blocking_transfer(
&mut self,
read: &mut [u8],
write: &[u8],
) -> Result<(), Error>
pub fn blocking_transfer( &mut self, read: &mut [u8], write: &[u8], ) -> Result<(), Error>
Transfer data to SPI blocking execution until done.
Sourcepub fn blocking_transfer_in_place(
&mut self,
data: &mut [u8],
) -> Result<(), Error>
pub fn blocking_transfer_in_place( &mut self, data: &mut [u8], ) -> Result<(), Error>
Transfer data in place to SPI blocking execution until done.
Sourcepub fn set_frequency(&mut self, freq: u32)
pub fn set_frequency(&mut self, freq: u32)
Set SPI frequency.
Sourcepub fn set_config(&mut self, pio: &mut Common<'d, PIO>, config: &Config)
pub fn set_config(&mut self, pio: &mut Common<'d, PIO>, config: &Config)
Set SPI config.
This operation will panic if the PIO program needs to be reloaded and there is insufficient room. This is unlikely since the programs for each phase only differ in size by a single instruction.
Source§impl<'d, PIO: Instance, const SM: usize> Spi<'d, PIO, SM, Async>
impl<'d, PIO: Instance, const SM: usize> Spi<'d, PIO, SM, Async>
Sourcepub fn new(
pio: &mut Common<'d, PIO>,
sm: StateMachine<'d, PIO, SM>,
clk: Peri<'d, impl PioPin>,
mosi: Peri<'d, impl PioPin>,
miso: Peri<'d, impl PioPin>,
tx_dma: Peri<'d, impl Channel>,
rx_dma: Peri<'d, impl Channel>,
config: Config,
) -> Self
pub fn new( pio: &mut Common<'d, PIO>, sm: StateMachine<'d, PIO, SM>, clk: Peri<'d, impl PioPin>, mosi: Peri<'d, impl PioPin>, miso: Peri<'d, impl PioPin>, tx_dma: Peri<'d, impl Channel>, rx_dma: Peri<'d, impl Channel>, config: Config, ) -> Self
Create an SPI driver in async mode supporting DMA operations.
Sourcepub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error>
pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error>
Read data from SPI using DMA.
Trait Implementations§
Source§impl<'d, PIO: Instance, const SM: usize> SpiBus for Spi<'d, PIO, SM, Async>
impl<'d, PIO: Instance, const SM: usize> SpiBus for Spi<'d, PIO, SM, Async>
Source§async fn flush(&mut self) -> Result<(), Self::Error>
async fn flush(&mut self) -> Result<(), Self::Error>
Wait until all operations have completed and the bus is idle. Read more
Source§async fn write(&mut self, words: &[u8]) -> Result<(), Self::Error>
async fn write(&mut self, words: &[u8]) -> Result<(), Self::Error>
Write
words
to the slave, ignoring all the incoming words. Read moreSource§async fn read(&mut self, words: &mut [u8]) -> Result<(), Self::Error>
async fn read(&mut self, words: &mut [u8]) -> Result<(), Self::Error>
Read
words
from the slave. Read moreSource§impl<'d, PIO: Instance, const SM: usize, M: Mode> SpiBus for Spi<'d, PIO, SM, M>
impl<'d, PIO: Instance, const SM: usize, M: Mode> SpiBus for Spi<'d, PIO, SM, M>
Source§fn flush(&mut self) -> Result<(), Self::Error>
fn flush(&mut self) -> Result<(), Self::Error>
Wait until all operations have completed and the bus is idle. Read more
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 moreAuto Trait Implementations§
impl<'d, PIO, const SM: usize, M> Freeze for Spi<'d, PIO, SM, M>
impl<'d, PIO, const SM: usize, M> RefUnwindSafe for Spi<'d, PIO, SM, M>where
M: RefUnwindSafe,
PIO: RefUnwindSafe,
impl<'d, PIO, const SM: usize, M> Send for Spi<'d, PIO, SM, M>
impl<'d, PIO, const SM: usize, M> Sync for Spi<'d, PIO, SM, M>
impl<'d, PIO, const SM: usize, M> Unpin for Spi<'d, PIO, SM, M>where
M: Unpin,
impl<'d, PIO, const SM: usize, M> !UnwindSafe for Spi<'d, PIO, SM, 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
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.
Source§impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
Source§fn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Performs the conversion.
Source§impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
Source§fn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Performs the conversion.
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.
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.