embassy-rp

Crates

git

Versions

rp235xb

Flavors

Struct Spi

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

Source

pub fn blocking_read(&mut self, data: &mut [u8]) -> Result<(), Error>

Read data from SPI blocking execution until done.

Source

pub fn blocking_write(&mut self, data: &[u8]) -> Result<(), Error>

Write data to SPI blocking execution until done.

Source

pub fn blocking_transfer( &mut self, read: &mut [u8], write: &[u8], ) -> Result<(), Error>

Transfer data to SPI blocking execution until done.

Source

pub fn blocking_transfer_in_place( &mut self, data: &mut [u8], ) -> Result<(), Error>

Transfer data in place to SPI blocking execution until done.

Source

pub fn flush(&mut self) -> Result<(), Error>

Block execution until SPI is done.

Source

pub fn set_frequency(&mut self, freq: u32)

Set SPI frequency.

Source

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

Source

pub fn new_blocking( 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>, config: Config, ) -> Self

Create an SPI driver in blocking mode.

Source§

impl<'d, PIO: Instance, const SM: usize> Spi<'d, PIO, SM, Async>

Source

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.

Source

pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error>

Read data from SPI using DMA.

Source

pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error>

Write data to SPI using DMA.

Source

pub async fn transfer( &mut self, rx_buffer: &mut [u8], tx_buffer: &[u8], ) -> Result<(), Error>

Transfer data to SPI using DMA.

Source

pub async fn transfer_in_place(&mut self, words: &mut [u8]) -> Result<(), Error>

Transfer data in place to SPI using DMA.

Trait Implementations§

Source§

impl<'d, PIO: Instance, const SM: usize, M: Mode> ErrorType for Spi<'d, PIO, SM, M>

Source§

type Error = Error

Error type.
Source§

impl<'d, PIO: Instance, const SM: usize> SpiBus for Spi<'d, PIO, SM, Async>

Source§

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>

Write words to the slave, ignoring all the incoming words. Read more
Source§

async fn read(&mut self, words: &mut [u8]) -> Result<(), Self::Error>

Read words from the slave. Read more
Source§

async 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 more
Source§

async fn transfer_in_place( &mut self, words: &mut [u8], ) -> Result<(), Self::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 more
Source§

impl<'d, PIO: Instance, const SM: usize, M: Mode> SpiBus for Spi<'d, PIO, SM, M>

Source§

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>

Read words from the slave. Read more
Source§

fn write(&mut self, words: &[u8]) -> Result<(), Self::Error>

Write words to the slave, ignoring all the incoming words. Read more
Source§

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 more
Source§

fn transfer_in_place(&mut self, words: &mut [u8]) -> Result<(), Self::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 more
Source§

impl<'d, PIO: Instance, const SM: usize, M: Mode> Transfer<u8> for Spi<'d, PIO, SM, M>

Source§

type Error = Error

Error type
Source§

fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error>

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

impl<'d, PIO: Instance, const SM: usize, M: Mode> Write<u8> for Spi<'d, PIO, SM, M>

Source§

type Error = Error

Error type
Source§

fn write(&mut self, words: &[u8]) -> Result<(), Self::Error>

Sends words to the slave, ignoring all the incoming words

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

§

impl<'d, PIO, const SM: usize, M> Send for Spi<'d, PIO, SM, M>
where M: Send, PIO: Send,

§

impl<'d, PIO, const SM: usize, M> Sync for Spi<'d, PIO, SM, M>
where M: Sync, PIO: Sync,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.