Trait DmaChannelFor

Source
pub trait DmaChannelFor<P: DmaEligible>: DmaChannel + DmaChannelConvert<PeripheralDmaChannel<P>> { }
Available on crate feature unstable only.
Expand description

Trait implemented for DMA channels that are compatible with a particular peripheral.

You can use this in places where a peripheral driver would expect a DmaChannel implementation.

§Example

The following example demonstrates how this trait can be used to only accept types compatible with a specific peripheral.

use esp_hal::spi::AnySpi;
use esp_hal::spi::master::{Spi, SpiDma, Config, Instance as SpiInstance};
use esp_hal::dma::DmaChannelFor;
use esp_hal::peripheral::Peripheral;
use esp_hal::Blocking;

fn configures_spi_dma<'d, CH>(
    spi: Spi<'d, Blocking>,
    channel: impl Peripheral<P = CH> + 'd,
) -> SpiDma<'d, Blocking>
where
    CH: DmaChannelFor<AnySpi> + 'd,
 {
    spi.with_dma(channel)
}
let dma_channel = peripherals.DMA_CH0;

let spi = Spi::new(
    peripherals.SPI2,
    Config::default(),
)?;

let spi_dma = configures_spi_dma(spi, dma_channel);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<P, CH> DmaChannelFor<P> for CH
where P: DmaEligible, CH: DmaChannel + DmaChannelConvert<PeripheralDmaChannel<P>>,