Struct SpiDma

Source
pub struct SpiDma<'d, Dm>
where Dm: DriverMode,
{ /* private fields */ }
Available on crate feature unstable only.
Expand description

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time. A DMA capable SPI instance.

Using SpiDma is not recommended unless you wish to manage buffers yourself. It’s recommended to use SpiDmaBus via with_buffers to get access to a DMA capable SPI bus that implements the embedded-hal traits.

let dma_channel = peripherals.DMA_CH0;
let (rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) =
    dma_buffers!(32000);

let dma_rx_buf = DmaRxBuf::new(
    rx_descriptors,
    rx_buffer
)?;

let dma_tx_buf = DmaTxBuf::new(
    tx_descriptors,
    tx_buffer
)?;

let mut spi = Spi::new(
    peripherals.SPI2,
    Config::default().with_frequency(Rate::from_khz(100)).
with_mode(Mode::_0) )?
.with_dma(dma_channel)
.with_buffers(dma_rx_buf, dma_tx_buf);

Implementations§

Source§

impl<'d> SpiDma<'d, Blocking>

Source

pub fn into_async(self) -> SpiDma<'d, Async>

Converts the SPI instance into async mode.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source§

impl<'d> SpiDma<'d, Async>

Source

pub fn into_blocking(self) -> SpiDma<'d, Blocking>

Converts the SPI instance into async mode.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source§

impl SpiDma<'_, Blocking>

Source

pub fn listen(&mut self, interrupts: impl Into<EnumSet<SpiInterrupt>>)

Listen for the given interrupts

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn unlisten(&mut self, interrupts: impl Into<EnumSet<SpiInterrupt>>)

Unlisten the given interrupts

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn interrupts(&mut self) -> EnumSet<SpiInterrupt>

Gets asserted interrupts

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn clear_interrupts(&mut self, interrupts: impl Into<EnumSet<SpiInterrupt>>)

Resets asserted interrupts

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source§

impl<'d, Dm> SpiDma<'d, Dm>
where Dm: DriverMode,

Source

pub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError>

Change the bus configuration.

§Errors

If frequency passed in config exceeds 80MHz or is below 70kHz, ConfigError::UnsupportedFrequency error will be returned.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn with_buffers( self, dma_rx_buf: DmaRxBuf, dma_tx_buf: DmaTxBuf, ) -> SpiDmaBus<'d, Dm>

Configures the DMA buffers for the SPI instance.

This method sets up both RX and TX buffers for DMA transfers. It returns an instance of SpiDmaBus that can be used for SPI communication.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source§

impl<'d, Dm> SpiDma<'d, Dm>
where Dm: DriverMode,

Source

pub fn write<TX: DmaTxBuffer>( self, bytes_to_write: usize, buffer: TX, ) -> Result<SpiDmaTransfer<'d, Dm, TX>, (Error, Self, TX)>

Perform a DMA write.

This will return a SpiDmaTransfer owning the buffer and the SPI instance. The maximum amount of data to be sent is 32736 bytes.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn read<RX: DmaRxBuffer>( self, bytes_to_read: usize, buffer: RX, ) -> Result<SpiDmaTransfer<'d, Dm, RX>, (Error, Self, RX)>

Perform a DMA read.

This will return a SpiDmaTransfer owning the buffer and the SPI instance. The maximum amount of data to be received is 32736 bytes.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn transfer<RX: DmaRxBuffer, TX: DmaTxBuffer>( self, bytes_to_read: usize, rx_buffer: RX, bytes_to_write: usize, tx_buffer: TX, ) -> Result<SpiDmaTransfer<'d, Dm, (RX, TX)>, (Error, Self, RX, TX)>

Perform a DMA transfer

This will return a SpiDmaTransfer owning the buffers and the SPI instance. The maximum amount of data to be sent/received is 32736 bytes.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn half_duplex_read<RX: DmaRxBuffer>( self, data_mode: DataMode, cmd: Command, address: Address, dummy: u8, bytes_to_read: usize, buffer: RX, ) -> Result<SpiDmaTransfer<'d, Dm, RX>, (Error, Self, RX)>

Perform a half-duplex read operation using DMA.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn half_duplex_write<TX: DmaTxBuffer>( self, data_mode: DataMode, cmd: Command, address: Address, dummy: u8, bytes_to_write: usize, buffer: TX, ) -> Result<SpiDmaTransfer<'d, Dm, TX>, (Error, Self, TX)>

Perform a half-duplex write operation using DMA.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Trait Implementations§

Source§

impl<Dm> Debug for SpiDma<'_, Dm>
where Dm: DriverMode,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the SpiDma instance for debugging purposes.

This method returns a debug struct with the name “SpiDma” without exposing internal details.

Source§

impl<'d, Dm> Format for SpiDma<'d, Dm>
where Dm: DriverMode, PeripheralRef<'d, AnySpi>: Format, Channel<'d, Dm, PeripheralDmaChannel<AnySpi>>: Format, PeripheralGuard: Format, SpiPinGuard: Format,

Source§

fn format(&self, f: Formatter<'_>)

Writes the defmt representation of self to fmt.
Source§

impl InterruptConfigurable for SpiDma<'_, Blocking>

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source§

fn set_interrupt_handler(&mut self, handler: InterruptHandler)

Sets the interrupt handler

Interrupts are not enabled at the peripheral level here.

Source§

impl<Dm> SetConfig for SpiDma<'_, Dm>
where Dm: DriverMode,

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source§

type Config = Config

The configuration type used by this driver.
Source§

type ConfigError = ConfigError

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

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

Set the configuration of the driver.

Auto Trait Implementations§

§

impl<'d, Dm> Freeze for SpiDma<'d, Dm>

§

impl<'d, Dm> RefUnwindSafe for SpiDma<'d, Dm>
where Dm: RefUnwindSafe,

§

impl<'d, Dm> Send for SpiDma<'d, Dm>
where Dm: Send,

§

impl<'d, Dm> Sync for SpiDma<'d, Dm>
where Dm: Sync,

§

impl<'d, Dm> Unpin for SpiDma<'d, Dm>
where Dm: Unpin,

§

impl<'d, Dm> !UnwindSafe for SpiDma<'d, Dm>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.