embassy-rp

Crates

git

Versions

rp2040

Flavors

embassy_rp::spi

Struct Spi

Source
pub struct Spi<'d, T: Instance, M: Mode> { /* private fields */ }
Expand description

SPI driver.

Implementations§

Source§

impl<'d, T: Instance, M: Mode> Spi<'d, T, M>

Source

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

Write 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 blocking_read(&mut self, data: &mut [u8]) -> Result<(), Error>

Read data from 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 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, config: &Config)

Set SPI config.

Source§

impl<'d, T: Instance> Spi<'d, T, Blocking>

Source

pub fn new_blocking( inner: impl Peripheral<P = T> + 'd, clk: impl Peripheral<P = impl ClkPin<T> + 'd> + 'd, mosi: impl Peripheral<P = impl MosiPin<T> + 'd> + 'd, miso: impl Peripheral<P = impl MisoPin<T> + 'd> + 'd, config: Config, ) -> Self

Create an SPI driver in blocking mode.

Source

pub fn new_blocking_txonly( inner: impl Peripheral<P = T> + 'd, clk: impl Peripheral<P = impl ClkPin<T> + 'd> + 'd, mosi: impl Peripheral<P = impl MosiPin<T> + 'd> + 'd, config: Config, ) -> Self

Create an SPI driver in blocking mode supporting writes only.

Source

pub fn new_blocking_rxonly( inner: impl Peripheral<P = T> + 'd, clk: impl Peripheral<P = impl ClkPin<T> + 'd> + 'd, miso: impl Peripheral<P = impl MisoPin<T> + 'd> + 'd, config: Config, ) -> Self

Create an SPI driver in blocking mode supporting reads only.

Source§

impl<'d, T: Instance> Spi<'d, T, Async>

Source

pub fn new( inner: impl Peripheral<P = T> + 'd, clk: impl Peripheral<P = impl ClkPin<T> + 'd> + 'd, mosi: impl Peripheral<P = impl MosiPin<T> + 'd> + 'd, miso: impl Peripheral<P = impl MisoPin<T> + 'd> + 'd, tx_dma: impl Peripheral<P = impl Channel> + 'd, rx_dma: impl Peripheral<P = impl Channel> + 'd, config: Config, ) -> Self

Create an SPI driver in async mode supporting DMA operations.

Source

pub fn new_txonly( inner: impl Peripheral<P = T> + 'd, clk: impl Peripheral<P = impl ClkPin<T> + 'd> + 'd, mosi: impl Peripheral<P = impl MosiPin<T> + 'd> + 'd, tx_dma: impl Peripheral<P = impl Channel> + 'd, config: Config, ) -> Self

Create an SPI driver in async mode supporting DMA write operations only.

Source

pub fn new_rxonly( inner: impl Peripheral<P = T> + 'd, clk: impl Peripheral<P = impl ClkPin<T> + 'd> + 'd, miso: impl Peripheral<P = impl MisoPin<T> + 'd> + 'd, tx_dma: impl Peripheral<P = impl Channel> + 'd, rx_dma: impl Peripheral<P = impl Channel> + 'd, config: Config, ) -> Self

Create an SPI driver in async mode supporting DMA read operations only.

Source

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

Write data to SPI using DMA.

Source

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

Read data from 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, T: Instance, M: Mode> ErrorType for Spi<'d, T, M>

Source§

type Error = Error

Error type.
Source§

impl<'d, T: Instance, M: Mode> SetConfig for Spi<'d, T, M>

Source§

type Config = Config

The configuration type used by this driver.
Source§

type ConfigError = ()

The error type that can occur if set_config fails.
Source§

fn set_config(&mut self, config: &Self::Config) -> Result<(), ()>

Set the configuration of the driver.
Source§

impl<'d, T: Instance> SpiBus for Spi<'d, T, 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, T: Instance, M: Mode> SpiBus for Spi<'d, T, 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, T: Instance, M: Mode> Transfer<u8> for Spi<'d, T, 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, T: Instance, M: Mode> Write<u8> for Spi<'d, T, 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, T, M> Freeze for Spi<'d, T, M>
where T: Freeze,

§

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

§

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§

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.