diff --git a/esp-hal/src/dma/gdma.rs b/esp-hal/src/dma/gdma.rs index 769b570e278..5ae56be4947 100644 --- a/esp-hal/src/dma/gdma.rs +++ b/esp-hal/src/dma/gdma.rs @@ -534,20 +534,23 @@ macro_rules! impl_channel { } } - impl ChannelCreator<$num> { - /// Configure the channel for use with blocking APIs - pub fn configure<'a>( - self, - burst_mode: bool, - priority: DmaPriority, - ) -> Channel<'a, [], Blocking> { + impl [] { + /// Unsafely constructs a new DMA channel. + /// + /// # Safety + /// + /// The caller must ensure that only a single instance is used. + pub unsafe fn steal<'a>() -> Channel<'a, Self, Blocking> { + let tx_impl = ChannelTxImpl(SpecificGdmaChannel::<$num> {}); + let rx_impl = ChannelRxImpl(SpecificGdmaChannel::<$num> {}); + let mut this = Channel { - tx: ChannelTx::new(ChannelTxImpl(SpecificGdmaChannel::<$num> {})), - rx: ChannelRx::new(ChannelRxImpl(SpecificGdmaChannel::<$num> {})), + tx: ChannelTx::new(tx_impl), + rx: ChannelRx::new(rx_impl), phantom: PhantomData, }; - this.configure(burst_mode, priority); + this.configure(false, DmaPriority::Priority0); this } @@ -643,19 +646,19 @@ crate::impl_dma_eligible! { pub struct Dma<'d> { _inner: PeripheralRef<'d, crate::peripherals::DMA>, /// Channel 0 - pub channel0: ChannelCreator<0>, + pub channel0: Channel<'d, DmaChannel0, Blocking>, /// Channel 1 #[cfg(not(esp32c2))] - pub channel1: ChannelCreator<1>, + pub channel1: Channel<'d, DmaChannel1, Blocking>, /// Channel 2 #[cfg(not(esp32c2))] - pub channel2: ChannelCreator<2>, + pub channel2: Channel<'d, DmaChannel2, Blocking>, /// Channel 3 #[cfg(esp32s3)] - pub channel3: ChannelCreator<3>, + pub channel3: Channel<'d, DmaChannel3, Blocking>, /// Channel 4 #[cfg(esp32s3)] - pub channel4: ChannelCreator<4>, + pub channel4: Channel<'d, DmaChannel4, Blocking>, } impl<'d> Dma<'d> { @@ -671,17 +674,19 @@ impl<'d> Dma<'d> { .modify(|_, w| w.ahbm_rst_inter().clear_bit()); dma.misc_conf().modify(|_, w| w.clk_en().set_bit()); - Dma { - _inner: dma, - channel0: ChannelCreator {}, - #[cfg(not(esp32c2))] - channel1: ChannelCreator {}, - #[cfg(not(esp32c2))] - channel2: ChannelCreator {}, - #[cfg(esp32s3)] - channel3: ChannelCreator {}, - #[cfg(esp32s3)] - channel4: ChannelCreator {}, + unsafe { + Dma { + _inner: dma, + channel0: DmaChannel0::steal(), + #[cfg(not(esp32c2))] + channel1: DmaChannel1::steal(), + #[cfg(not(esp32c2))] + channel2: DmaChannel2::steal(), + #[cfg(esp32s3)] + channel3: DmaChannel3::steal(), + #[cfg(esp32s3)] + channel4: DmaChannel4::steal(), + } } } } diff --git a/esp-hal/src/dma/mod.rs b/esp-hal/src/dma/mod.rs index df652f9ff2b..fcf2dca378e 100644 --- a/esp-hal/src/dma/mod.rs +++ b/esp-hal/src/dma/mod.rs @@ -20,7 +20,7 @@ //! # use esp_hal::dma_buffers; //! # use esp_hal::gpio::Io; //! # use esp_hal::spi::{master::Spi, SpiMode}; -//! # use esp_hal::dma::{Dma, DmaPriority}; +//! # use esp_hal::dma::Dma; //! let dma = Dma::new(peripherals.DMA); #![cfg_attr(any(esp32, esp32s2), doc = "let dma_channel = dma.spi2channel;")] #![cfg_attr(not(any(esp32, esp32s2)), doc = "let dma_channel = dma.channel0;")] @@ -39,10 +39,7 @@ //! .with_mosi(mosi) //! .with_miso(miso) //! .with_cs(cs) -//! .with_dma(dma_channel.configure( -//! false, -//! DmaPriority::Priority0, -//! )); +//! .with_dma(dma_channel); //! # } //! ``` //! diff --git a/esp-hal/src/dma/pdma.rs b/esp-hal/src/dma/pdma.rs index ab18f2387c0..39fb522c6c2 100644 --- a/esp-hal/src/dma/pdma.rs +++ b/esp-hal/src/dma/pdma.rs @@ -406,24 +406,23 @@ macro_rules! ImplSpiChannel { impl $crate::private::Sealed for [] {} - #[doc = concat!("Creates a channel for SPI", $num)] - #[non_exhaustive] - pub struct [] {} - - impl [] { - /// Configure the channel for use with blocking APIs - pub fn configure<'a>( - self, - burst_mode: bool, - priority: DmaPriority, - ) -> Channel<'a, [], Blocking> { + impl [] { + /// Unsafely constructs a new DMA channel. + /// + /// # Safety + /// + /// The caller must ensure that only a single instance is used. + pub unsafe fn steal<'a>() -> Channel<'a, Self, Blocking> { + let tx_impl = SpiDmaTxChannelImpl(Self {}); + let rx_impl = SpiDmaRxChannelImpl(Self {}); + let mut this = Channel { - tx: ChannelTx::new(SpiDmaTxChannelImpl([] {})), - rx: ChannelRx::new(SpiDmaRxChannelImpl([] {})), + tx: ChannelTx::new(tx_impl), + rx: ChannelRx::new(rx_impl), phantom: PhantomData, }; - this.configure(burst_mode, priority); + this.configure(false, DmaPriority::Priority0); this } @@ -816,23 +815,23 @@ macro_rules! ImplI2sChannel { } } - #[doc = concat!("Creates a channel for I2S", $num)] - pub struct [] {} + impl [] { + /// Unsafely constructs a new DMA channel. + /// + /// # Safety + /// + /// The caller must ensure that only a single instance is used. + pub unsafe fn steal<'a>() -> Channel<'a, Self, Blocking> { + let tx_impl = I2sDmaTxChannelImpl(Self {}); + let rx_impl = I2sDmaRxChannelImpl(Self {}); - impl [] { - /// Configure the channel for use with blocking APIs - pub fn configure<'a>( - self, - burst_mode: bool, - priority: DmaPriority, - ) -> Channel<'a, [], Blocking> { let mut this = Channel { - tx: ChannelTx::new(I2sDmaTxChannelImpl([] {})), - rx: ChannelRx::new(I2sDmaRxChannelImpl([] {})), + tx: ChannelTx::new(tx_impl), + rx: ChannelRx::new(rx_impl), phantom: PhantomData, }; - this.configure(burst_mode, priority); + this.configure(false, DmaPriority::Priority0); this } @@ -863,14 +862,14 @@ crate::impl_dma_eligible!([I2s1DmaChannel] I2S1 => I2s1); pub struct Dma<'d> { _inner: PeripheralRef<'d, crate::peripherals::DMA>, /// DMA channel for SPI2 - pub spi2channel: Spi2DmaChannelCreator, + pub spi2channel: Channel<'d, Spi2DmaChannel, Blocking>, /// DMA channel for SPI3 - pub spi3channel: Spi3DmaChannelCreator, + pub spi3channel: Channel<'d, Spi3DmaChannel, Blocking>, /// DMA channel for I2S0 - pub i2s0channel: I2s0DmaChannelCreator, + pub i2s0channel: Channel<'d, I2s0DmaChannel, Blocking>, /// DMA channel for I2S1 #[cfg(i2s1)] - pub i2s1channel: I2s1DmaChannelCreator, + pub i2s1channel: Channel<'d, I2s1DmaChannel, Blocking>, } impl<'d> Dma<'d> { @@ -893,13 +892,15 @@ impl<'d> Dma<'d> { }); } - Dma { - _inner: dma.into_ref(), - spi2channel: Spi2DmaChannelCreator {}, - spi3channel: Spi3DmaChannelCreator {}, - i2s0channel: I2s0DmaChannelCreator {}, - #[cfg(i2s1)] - i2s1channel: I2s1DmaChannelCreator {}, + unsafe { + Dma { + _inner: dma.into_ref(), + spi2channel: Spi2DmaChannel::steal(), + spi3channel: Spi3DmaChannel::steal(), + i2s0channel: I2s0DmaChannel::steal(), + #[cfg(i2s1)] + i2s1channel: I2s1DmaChannel::steal(), + } } } } diff --git a/esp-hal/src/i2s.rs b/esp-hal/src/i2s.rs index c5b2c1bbc34..3fe73f4f0d5 100644 --- a/esp-hal/src/i2s.rs +++ b/esp-hal/src/i2s.rs @@ -34,7 +34,7 @@ //! # use esp_hal::i2s::DataFormat; //! # use esp_hal::gpio::Io; //! # use esp_hal::dma_buffers; -//! # use esp_hal::dma::{Dma, DmaPriority}; +//! # use esp_hal::dma::Dma; //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! let dma = Dma::new(peripherals.DMA); #![cfg_attr(any(esp32, esp32s2), doc = "let dma_channel = dma.i2s0channel;")] @@ -47,10 +47,7 @@ //! Standard::Philips, //! DataFormat::Data16Channel16, //! 44100.Hz(), -//! dma_channel.configure( -//! false, -//! DmaPriority::Priority0, -//! ), +//! dma_channel, //! rx_descriptors, //! tx_descriptors, //! ); diff --git a/esp-hal/src/lcd_cam/cam.rs b/esp-hal/src/lcd_cam/cam.rs index dee3a375949..8b7dc121e7e 100644 --- a/esp-hal/src/lcd_cam/cam.rs +++ b/esp-hal/src/lcd_cam/cam.rs @@ -20,7 +20,7 @@ //! # use esp_hal::lcd_cam::{cam::{Camera, RxEightBits}, LcdCam}; //! # use fugit::RateExtU32; //! # use esp_hal::dma_rx_stream_buffer; -//! # use esp_hal::dma::{Dma, DmaPriority}; +//! # use esp_hal::dma::Dma; //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! //! # let dma = Dma::new(peripherals.DMA); @@ -28,11 +28,6 @@ //! //! # let dma_buf = dma_rx_stream_buffer!(20 * 1000, 1000); //! -//! # let channel = channel.configure( -//! # false, -//! # DmaPriority::Priority0, -//! # ); -//! //! let mclk_pin = io.pins.gpio15; //! let vsync_pin = io.pins.gpio6; //! let href_pin = io.pins.gpio7; diff --git a/esp-hal/src/lcd_cam/lcd/i8080.rs b/esp-hal/src/lcd_cam/lcd/i8080.rs index 2017f4d07cb..a6530082bce 100644 --- a/esp-hal/src/lcd_cam/lcd/i8080.rs +++ b/esp-hal/src/lcd_cam/lcd/i8080.rs @@ -18,7 +18,7 @@ //! # use esp_hal::gpio::Io; //! # use esp_hal::lcd_cam::{LcdCam, lcd::i8080::{Config, I8080, TxEightBits}}; //! # use esp_hal::dma_tx_buffer; -//! # use esp_hal::dma::{Dma, DmaPriority, DmaTxBuf}; +//! # use esp_hal::dma::{Dma, DmaTxBuf}; //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! //! # let dma = Dma::new(peripherals.DMA); @@ -26,11 +26,6 @@ //! //! # let mut dma_buf = dma_tx_buffer!(32678).unwrap(); //! -//! # let channel = channel.configure( -//! # false, -//! # DmaPriority::Priority0, -//! # ); -//! //! let tx_pins = TxEightBits::new( //! io.pins.gpio9, //! io.pins.gpio46, diff --git a/esp-hal/src/spi/master.rs b/esp-hal/src/spi/master.rs index cd906e3fabb..08ae22add38 100644 --- a/esp-hal/src/spi/master.rs +++ b/esp-hal/src/spi/master.rs @@ -846,6 +846,8 @@ mod dma { Rx, Tx, }, + Async, + Blocking, InterruptConfigurable, }; diff --git a/esp-hal/src/spi/slave.rs b/esp-hal/src/spi/slave.rs index 8bea967bda6..0e7a23a0127 100644 --- a/esp-hal/src/spi/slave.rs +++ b/esp-hal/src/spi/slave.rs @@ -15,7 +15,6 @@ //! //! ```rust, no_run #![doc = crate::before_snippet!()] -//! # use esp_hal::dma::DmaPriority; //! # use esp_hal::dma_buffers; //! # use esp_hal::spi::SpiMode; //! # use esp_hal::spi::slave::Spi; @@ -39,10 +38,7 @@ //! cs, //! SpiMode::Mode0, //! ) -//! .with_dma(dma_channel.configure( -//! false, -//! DmaPriority::Priority0, -//! ), rx_descriptors, tx_descriptors); +//! .with_dma(dma_channel, rx_descriptors, tx_descriptors); //! //! let mut receive = rx_buffer; //! let mut send = tx_buffer; diff --git a/examples/src/bin/dma_extmem2mem.rs b/examples/src/bin/dma_extmem2mem.rs index 063197a7f6e..4fab1087c77 100644 --- a/examples/src/bin/dma_extmem2mem.rs +++ b/examples/src/bin/dma_extmem2mem.rs @@ -11,7 +11,7 @@ use esp_alloc as _; use esp_backtrace as _; use esp_hal::{ delay::Delay, - dma::{Dma, DmaPriority, Mem2Mem}, + dma::{Dma, Mem2Mem}, dma_descriptors_chunk_size, prelude::*, }; @@ -68,11 +68,10 @@ fn main() -> ! { let (rx_descriptors, tx_descriptors) = dma_descriptors_chunk_size!(DATA_SIZE, CHUNK_SIZE); let dma = Dma::new(peripherals.DMA); - let channel = dma.channel0.configure(false, DmaPriority::Priority0); let dma_peripheral = peripherals.SPI2; let mut mem2mem = Mem2Mem::new_with_chunk_size( - channel, + dma.channel0, dma_peripheral, rx_descriptors, tx_descriptors, diff --git a/examples/src/bin/dma_mem2mem.rs b/examples/src/bin/dma_mem2mem.rs index 795e158d290..23dda706764 100644 --- a/examples/src/bin/dma_mem2mem.rs +++ b/examples/src/bin/dma_mem2mem.rs @@ -9,7 +9,7 @@ use esp_backtrace as _; use esp_hal::{ delay::Delay, - dma::{Dma, DmaPriority, Mem2Mem}, + dma::{Dma, Mem2Mem}, dma_buffers, prelude::*, }; @@ -28,14 +28,13 @@ fn main() -> ! { let (mut rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) = dma_buffers!(DATA_SIZE); let dma = Dma::new(peripherals.DMA); - let channel = dma.channel0.configure(false, DmaPriority::Priority0); #[cfg(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3"))] let dma_peripheral = peripherals.SPI2; #[cfg(not(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3")))] let dma_peripheral = peripherals.MEM2MEM1; let mut mem2mem = - Mem2Mem::new(channel, dma_peripheral, rx_descriptors, tx_descriptors).unwrap(); + Mem2Mem::new(dma.channel0, dma_peripheral, rx_descriptors, tx_descriptors).unwrap(); for i in 0..core::mem::size_of_val(tx_buffer) { tx_buffer[i] = (i % 256) as u8; diff --git a/examples/src/bin/embassy_i2s_read.rs b/examples/src/bin/embassy_i2s_read.rs index afb796c1c42..b4c919a465d 100644 --- a/examples/src/bin/embassy_i2s_read.rs +++ b/examples/src/bin/embassy_i2s_read.rs @@ -20,7 +20,7 @@ use embassy_executor::Spawner; use esp_backtrace as _; use esp_hal::{ - dma::{Dma, DmaPriority}, + dma::Dma, dma_buffers, gpio::Io, i2s::{DataFormat, I2s, Standard}, @@ -52,7 +52,7 @@ async fn main(_spawner: Spawner) { Standard::Philips, DataFormat::Data16Channel16, 44100u32.Hz(), - dma_channel.configure(false, DmaPriority::Priority0), + dma_channel, rx_descriptors, tx_descriptors, ) diff --git a/examples/src/bin/embassy_i2s_sound.rs b/examples/src/bin/embassy_i2s_sound.rs index 2c807a4755c..203201831b8 100644 --- a/examples/src/bin/embassy_i2s_sound.rs +++ b/examples/src/bin/embassy_i2s_sound.rs @@ -34,7 +34,7 @@ use embassy_executor::Spawner; use esp_backtrace as _; use esp_hal::{ - dma::{Dma, DmaPriority}, + dma::Dma, dma_buffers, gpio::Io, i2s::{DataFormat, I2s, Standard}, @@ -74,7 +74,7 @@ async fn main(_spawner: Spawner) { Standard::Philips, DataFormat::Data16Channel16, 44100u32.Hz(), - dma_channel.configure(false, DmaPriority::Priority0), + dma_channel, rx_descriptors, tx_descriptors, ) diff --git a/examples/src/bin/embassy_parl_io_rx.rs b/examples/src/bin/embassy_parl_io_rx.rs index 95e28f696ee..5fef3168eba 100644 --- a/examples/src/bin/embassy_parl_io_rx.rs +++ b/examples/src/bin/embassy_parl_io_rx.rs @@ -14,7 +14,7 @@ use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ - dma::{Dma, DmaPriority}, + dma::Dma, dma_buffers, gpio::Io, parl_io::{no_clk_pin, BitPackOrder, ParlIoRxOnly, RxFourBits}, @@ -36,15 +36,12 @@ async fn main(_spawner: Spawner) { let (rx_buffer, rx_descriptors, _, _) = dma_buffers!(32000, 0); let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; let mut rx_pins = RxFourBits::new(io.pins.gpio1, io.pins.gpio2, io.pins.gpio3, io.pins.gpio4); let parl_io = ParlIoRxOnly::new( peripherals.PARL_IO, - dma_channel - .configure(false, DmaPriority::Priority0) - .into_async(), + dma.channel0.into_async(), rx_descriptors, 1.MHz(), ) diff --git a/examples/src/bin/embassy_parl_io_tx.rs b/examples/src/bin/embassy_parl_io_tx.rs index e177ad506d9..aabf083357c 100644 --- a/examples/src/bin/embassy_parl_io_tx.rs +++ b/examples/src/bin/embassy_parl_io_tx.rs @@ -18,7 +18,7 @@ use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; use esp_backtrace as _; use esp_hal::{ - dma::{Dma, DmaPriority}, + dma::Dma, dma_buffers, gpio::Io, parl_io::{ @@ -47,7 +47,6 @@ async fn main(_spawner: Spawner) { let (_, _, tx_buffer, tx_descriptors) = dma_buffers!(0, 32000); let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; let tx_pins = TxFourBits::new(io.pins.gpio1, io.pins.gpio2, io.pins.gpio3, io.pins.gpio4); @@ -55,9 +54,7 @@ async fn main(_spawner: Spawner) { let parl_io = ParlIoTxOnly::new( peripherals.PARL_IO, - dma_channel - .configure(false, DmaPriority::Priority0) - .into_async(), + dma.channel0.into_async(), tx_descriptors, 1.MHz(), ) diff --git a/examples/src/bin/embassy_spi.rs b/examples/src/bin/embassy_spi.rs index 2ae0afe977a..f5162c0b2ad 100644 --- a/examples/src/bin/embassy_spi.rs +++ b/examples/src/bin/embassy_spi.rs @@ -63,7 +63,7 @@ async fn main(_spawner: Spawner) { .with_mosi(mosi) .with_miso(miso) .with_cs(cs) - .with_dma(dma_channel.configure(false, DmaPriority::Priority0)) + .with_dma(dma_channel) .with_buffers(dma_rx_buf, dma_tx_buf) .into_async(); diff --git a/examples/src/bin/i2s_read.rs b/examples/src/bin/i2s_read.rs index 8274fb69d71..073fcb10b81 100644 --- a/examples/src/bin/i2s_read.rs +++ b/examples/src/bin/i2s_read.rs @@ -18,7 +18,7 @@ use esp_backtrace as _; use esp_hal::{ - dma::{Dma, DmaPriority}, + dma::Dma, dma_buffers, gpio::Io, i2s::{DataFormat, I2s, Standard}, @@ -49,7 +49,7 @@ fn main() -> ! { Standard::Philips, DataFormat::Data16Channel16, 44100.Hz(), - dma_channel.configure(false, DmaPriority::Priority0), + dma_channel, rx_descriptors, tx_descriptors, ); diff --git a/examples/src/bin/i2s_sound.rs b/examples/src/bin/i2s_sound.rs index 72e2d7b8e12..6eaaa7bfb50 100644 --- a/examples/src/bin/i2s_sound.rs +++ b/examples/src/bin/i2s_sound.rs @@ -32,7 +32,7 @@ use esp_backtrace as _; use esp_hal::{ - dma::{Dma, DmaPriority}, + dma::Dma, dma_buffers, gpio::Io, i2s::{DataFormat, I2s, Standard}, @@ -66,7 +66,7 @@ fn main() -> ! { Standard::Philips, DataFormat::Data16Channel16, 44100.Hz(), - dma_channel.configure(false, DmaPriority::Priority0), + dma_channel, rx_descriptors, tx_descriptors, ); diff --git a/examples/src/bin/lcd_cam_ov2640.rs b/examples/src/bin/lcd_cam_ov2640.rs index cdc6d64c1b2..16cf1c91427 100644 --- a/examples/src/bin/lcd_cam_ov2640.rs +++ b/examples/src/bin/lcd_cam_ov2640.rs @@ -26,7 +26,7 @@ use esp_backtrace as _; use esp_hal::{ delay::Delay, - dma::{Dma, DmaPriority}, + dma::Dma, dma_rx_stream_buffer, gpio::Io, i2c, @@ -47,12 +47,9 @@ fn main() -> ! { let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let dma = Dma::new(peripherals.DMA); - let channel = dma.channel0; let dma_rx_buf = dma_rx_stream_buffer!(20 * 1000, 1000); - let channel = channel.configure(false, DmaPriority::Priority0); - let cam_siod = io.pins.gpio4; let cam_sioc = io.pins.gpio5; let cam_xclk = io.pins.gpio15; @@ -71,7 +68,7 @@ fn main() -> ! { ); let lcd_cam = LcdCam::new(peripherals.LCD_CAM); - let camera = Camera::new(lcd_cam.cam, channel.rx, cam_data_pins, 20u32.MHz()) + let camera = Camera::new(lcd_cam.cam, dma.channel0.rx, cam_data_pins, 20u32.MHz()) .with_master_clock(cam_xclk) .with_pixel_clock(cam_pclk) .with_ctrl_pins(cam_vsync, cam_href); diff --git a/examples/src/bin/lcd_i8080.rs b/examples/src/bin/lcd_i8080.rs index 2937f427cae..741e1cc47d7 100644 --- a/examples/src/bin/lcd_i8080.rs +++ b/examples/src/bin/lcd_i8080.rs @@ -25,7 +25,7 @@ use esp_backtrace as _; use esp_hal::{ delay::Delay, - dma::{Dma, DmaPriority, DmaTxBuf}, + dma::{Dma, DmaTxBuf}, dma_tx_buffer, gpio::{Input, Io, Level, Output, Pull}, lcd_cam::{ @@ -50,12 +50,9 @@ fn main() -> ! { let lcd_te = io.pins.gpio48; // Frame sync let dma = Dma::new(peripherals.DMA); - let channel = dma.channel0; let dma_tx_buf = dma_tx_buffer!(4000).unwrap(); - let channel = channel.configure(false, DmaPriority::Priority0); - let delay = Delay::new(); let mut backlight = Output::new(lcd_backlight, Level::Low); @@ -76,7 +73,7 @@ fn main() -> ! { let lcd_cam = LcdCam::new(peripherals.LCD_CAM); let i8080 = I8080::new( lcd_cam.lcd, - channel.tx, + dma.channel0.tx, tx_pins, 20.MHz(), Config::default(), diff --git a/examples/src/bin/parl_io_rx.rs b/examples/src/bin/parl_io_rx.rs index 8f66c376ea4..7ff13a96b90 100644 --- a/examples/src/bin/parl_io_rx.rs +++ b/examples/src/bin/parl_io_rx.rs @@ -12,7 +12,7 @@ use esp_backtrace as _; use esp_hal::{ delay::Delay, - dma::{Dma, DmaPriority}, + dma::Dma, dma_buffers, gpio::Io, parl_io::{no_clk_pin, BitPackOrder, ParlIoRxOnly, RxFourBits}, @@ -33,13 +33,8 @@ fn main() -> ! { let mut rx_pins = RxFourBits::new(io.pins.gpio1, io.pins.gpio2, io.pins.gpio3, io.pins.gpio4); - let parl_io = ParlIoRxOnly::new( - peripherals.PARL_IO, - dma_channel.configure(false, DmaPriority::Priority0), - rx_descriptors, - 1.MHz(), - ) - .unwrap(); + let parl_io = + ParlIoRxOnly::new(peripherals.PARL_IO, dma_channel, rx_descriptors, 1.MHz()).unwrap(); let mut parl_io_rx = parl_io .rx diff --git a/examples/src/bin/parl_io_tx.rs b/examples/src/bin/parl_io_tx.rs index 0df17ad398e..287e94867d5 100644 --- a/examples/src/bin/parl_io_tx.rs +++ b/examples/src/bin/parl_io_tx.rs @@ -16,7 +16,7 @@ use esp_backtrace as _; use esp_hal::{ delay::Delay, - dma::{Dma, DmaPriority}, + dma::Dma, dma_buffers, gpio::Io, parl_io::{ @@ -46,13 +46,8 @@ fn main() -> ! { let mut pin_conf = TxPinConfigWithValidPin::new(tx_pins, io.pins.gpio5); - let parl_io = ParlIoTxOnly::new( - peripherals.PARL_IO, - dma_channel.configure(false, DmaPriority::Priority0), - tx_descriptors, - 1.MHz(), - ) - .unwrap(); + let parl_io = + ParlIoTxOnly::new(peripherals.PARL_IO, dma_channel, tx_descriptors, 1.MHz()).unwrap(); let mut clock_pin = ClkOutPin::new(io.pins.gpio6); diff --git a/examples/src/bin/qspi_flash.rs b/examples/src/bin/qspi_flash.rs index 687b28ba18f..216727ea237 100644 --- a/examples/src/bin/qspi_flash.rs +++ b/examples/src/bin/qspi_flash.rs @@ -30,7 +30,7 @@ use esp_backtrace as _; use esp_hal::{ delay::Delay, - dma::{Dma, DmaPriority, DmaRxBuf, DmaTxBuf}, + dma::{Dma, DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::Io, prelude::*, @@ -86,7 +86,7 @@ fn main() -> ! { .with_sio2(sio2) .with_sio3(sio3) .with_cs(cs) - .with_dma(dma_channel.configure(false, DmaPriority::Priority0)); + .with_dma(dma_channel); let delay = Delay::new(); diff --git a/examples/src/bin/spi_loopback_dma.rs b/examples/src/bin/spi_loopback_dma.rs index f081478da36..239dfc5f3b6 100644 --- a/examples/src/bin/spi_loopback_dma.rs +++ b/examples/src/bin/spi_loopback_dma.rs @@ -21,7 +21,7 @@ use esp_backtrace as _; use esp_hal::{ delay::Delay, - dma::{Dma, DmaPriority, DmaRxBuf, DmaTxBuf}, + dma::{Dma, DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::Io, prelude::*, @@ -58,7 +58,7 @@ fn main() -> ! { .with_mosi(mosi) .with_miso(miso) .with_cs(cs) - .with_dma(dma_channel.configure(false, DmaPriority::Priority0)); + .with_dma(dma_channel); let delay = Delay::new(); diff --git a/examples/src/bin/spi_loopback_dma_psram.rs b/examples/src/bin/spi_loopback_dma_psram.rs index 1ae30408518..dd03c696ed7 100644 --- a/examples/src/bin/spi_loopback_dma_psram.rs +++ b/examples/src/bin/spi_loopback_dma_psram.rs @@ -25,7 +25,7 @@ use esp_backtrace as _; use esp_hal::{ delay::Delay, - dma::{Dma, DmaBufBlkSize, DmaPriority, DmaRxBuf, DmaTxBuf}, + dma::{Dma, DmaBufBlkSize, DmaRxBuf, DmaTxBuf}, gpio::Io, peripheral::Peripheral, prelude::*, @@ -95,7 +95,7 @@ fn main() -> ! { .with_miso(miso) .with_mosi(mosi) .with_cs(cs) - .with_dma(dma_channel.configure(false, DmaPriority::Priority0)); + .with_dma(dma_channel); delay.delay_millis(100); // delay to let the above messages display diff --git a/examples/src/bin/spi_slave_dma.rs b/examples/src/bin/spi_slave_dma.rs index 5352c71db8b..caaee2fb29a 100644 --- a/examples/src/bin/spi_slave_dma.rs +++ b/examples/src/bin/spi_slave_dma.rs @@ -32,7 +32,7 @@ use esp_backtrace as _; use esp_hal::{ delay::Delay, - dma::{Dma, DmaPriority}, + dma::Dma, dma_buffers, gpio::{Input, Io, Level, Output, Pull}, prelude::*, @@ -75,11 +75,7 @@ fn main() -> ! { slave_cs, SpiMode::Mode0, ) - .with_dma( - dma_channel.configure(false, DmaPriority::Priority0), - tx_descriptors, - rx_descriptors, - ); + .with_dma(dma_channel, tx_descriptors, rx_descriptors); let delay = Delay::new(); diff --git a/hil-test/tests/aes_dma.rs b/hil-test/tests/aes_dma.rs index 3fdb98db1ff..e560e041dd3 100644 --- a/hil-test/tests/aes_dma.rs +++ b/hil-test/tests/aes_dma.rs @@ -7,7 +7,7 @@ use esp_hal::{ aes::{dma::CipherMode, Aes, Mode}, - dma::{Dma, DmaPriority}, + dma::Dma, dma_buffers, peripherals::Peripherals, }; @@ -32,11 +32,8 @@ mod tests { let (mut output, rx_descriptors, input, tx_descriptors) = dma_buffers!(DMA_BUFFER_SIZE); - let mut aes = Aes::new(peripherals.AES).with_dma( - dma_channel.configure(false, DmaPriority::Priority0), - rx_descriptors, - tx_descriptors, - ); + let mut aes = + Aes::new(peripherals.AES).with_dma(dma_channel, rx_descriptors, tx_descriptors); let keytext = b"SUp4SeCp@sSw0rd"; let mut keybuf = [0_u8; 16]; @@ -74,11 +71,8 @@ mod tests { let (mut output, rx_descriptors, input, tx_descriptors) = dma_buffers!(DMA_BUFFER_SIZE); - let mut aes = Aes::new(peripherals.AES).with_dma( - dma_channel.configure(false, DmaPriority::Priority0), - rx_descriptors, - tx_descriptors, - ); + let mut aes = + Aes::new(peripherals.AES).with_dma(dma_channel, rx_descriptors, tx_descriptors); let keytext = b"SUp4SeCp@sSw0rd"; let mut keybuf = [0_u8; 16]; @@ -115,11 +109,8 @@ mod tests { let (mut output, rx_descriptors, input, tx_descriptors) = dma_buffers!(DMA_BUFFER_SIZE); - let mut aes = Aes::new(peripherals.AES).with_dma( - dma_channel.configure(false, DmaPriority::Priority0), - rx_descriptors, - tx_descriptors, - ); + let mut aes = + Aes::new(peripherals.AES).with_dma(dma_channel, rx_descriptors, tx_descriptors); let keytext = b"SUp4SeCp@sSw0rd"; let mut keybuf = [0_u8; 16]; @@ -157,11 +148,8 @@ mod tests { let (mut output, rx_descriptors, input, tx_descriptors) = dma_buffers!(DMA_BUFFER_SIZE); - let mut aes = Aes::new(peripherals.AES).with_dma( - dma_channel.configure(false, DmaPriority::Priority0), - rx_descriptors, - tx_descriptors, - ); + let mut aes = + Aes::new(peripherals.AES).with_dma(dma_channel, rx_descriptors, tx_descriptors); let keytext = b"SUp4SeCp@sSw0rd"; let mut keybuf = [0_u8; 16]; diff --git a/hil-test/tests/dma_mem2mem.rs b/hil-test/tests/dma_mem2mem.rs index f65873ae6c5..22555bd8b56 100644 --- a/hil-test/tests/dma_mem2mem.rs +++ b/hil-test/tests/dma_mem2mem.rs @@ -6,7 +6,7 @@ #![no_main] use esp_hal::{ - dma::{AnyGdmaChannel, Channel, Dma, DmaError, DmaPriority, Mem2Mem}, + dma::{AnyGdmaChannel, Channel, Dma, DmaError, Mem2Mem}, dma_buffers, dma_buffers_chunk_size, dma_descriptors, @@ -50,9 +50,7 @@ mod tests { } Context { - channel: dma_channel - .configure(false, DmaPriority::Priority0) - .degrade(), + channel: dma_channel.degrade(), dma_peripheral, } } diff --git a/hil-test/tests/embassy_interrupt_spi_dma.rs b/hil-test/tests/embassy_interrupt_spi_dma.rs index fc6580a12f8..f86d9385cfd 100644 --- a/hil-test/tests/embassy_interrupt_spi_dma.rs +++ b/hil-test/tests/embassy_interrupt_spi_dma.rs @@ -9,7 +9,7 @@ use embassy_time::{Duration, Instant, Ticker}; use esp_hal::{ - dma::{Dma, DmaPriority, DmaRxBuf, DmaTxBuf}, + dma::{Channel, Dma, DmaRxBuf, DmaTxBuf}, dma_buffers, interrupt::{software::SoftwareInterruptControl, Priority}, prelude::*, @@ -19,6 +19,7 @@ use esp_hal::{ }, timer::AnyTimer, Async, + Blocking, }; use esp_hal_embassy::InterruptExecutor; use hil_test as _; @@ -95,12 +96,12 @@ mod test { let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(); let mut spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0) - .with_dma(dma_channel1.configure(false, DmaPriority::Priority0)) + .with_dma(dma_channel1) .with_buffers(dma_rx_buf, dma_tx_buf) .into_async(); let spi2 = Spi::new(peripherals.SPI3, 100.kHz(), SpiMode::Mode0) - .with_dma(dma_channel2.configure(false, DmaPriority::Priority0)) + .with_dma(dma_channel2) .into_async(); let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); @@ -136,9 +137,9 @@ mod test { cfg_if::cfg_if! { if #[cfg(pdma)] { - use esp_hal::dma::Spi2DmaChannelCreator as DmaChannelCreator; + use esp_hal::dma::Spi2DmaChannel as DmaChannel; } else { - type DmaChannelCreator = esp_hal::dma::ChannelCreator<0>; + type DmaChannel = esp_hal::dma::DmaChannel0; } } @@ -147,7 +148,7 @@ mod test { pub struct SpiPeripherals { pub spi: SPI2, - pub dma_channel: DmaChannelCreator, + pub dma_channel: Channel<'static, DmaChannel, Blocking>, } #[embassy_executor::task] @@ -157,11 +158,7 @@ mod test { let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(); let mut spi = Spi::new(peripherals.spi, 100.kHz(), SpiMode::Mode0) - .with_dma( - peripherals - .dma_channel - .configure(false, DmaPriority::Priority0), - ) + .with_dma(peripherals.dma_channel) .with_buffers(dma_rx_buf, dma_tx_buf) .into_async(); diff --git a/hil-test/tests/i2s.rs b/hil-test/tests/i2s.rs index 0156c26b88d..6dc4c317806 100644 --- a/hil-test/tests/i2s.rs +++ b/hil-test/tests/i2s.rs @@ -12,21 +12,22 @@ use esp_hal::{ delay::Delay, - dma::{Dma, DmaPriority}, + dma::{Channel, Dma}, dma_buffers, gpio::{Io, NoPin}, i2s::{DataFormat, I2s, I2sTx, Standard}, peripherals::I2S0, prelude::*, Async, + Blocking, }; use hil_test as _; cfg_if::cfg_if! { if #[cfg(any(esp32, esp32s2))] { - type DmaChannel0Creator = esp_hal::dma::I2s0DmaChannelCreator; + type DmaChannel0 = esp_hal::dma::I2s0DmaChannel; } else { - type DmaChannel0Creator = esp_hal::dma::ChannelCreator<0>; + type DmaChannel0 = esp_hal::dma::DmaChannel0; } } @@ -104,7 +105,7 @@ mod tests { struct Context { io: Io, - dma_channel: DmaChannel0Creator, + dma_channel: Channel<'static, DmaChannel0, Blocking>, i2s: I2S0, } @@ -143,7 +144,7 @@ mod tests { Standard::Philips, DataFormat::Data16Channel16, 16000.Hz(), - ctx.dma_channel.configure(false, DmaPriority::Priority0), + ctx.dma_channel, rx_descriptors, tx_descriptors, ) @@ -198,7 +199,7 @@ mod tests { Standard::Philips, DataFormat::Data16Channel16, 16000.Hz(), - ctx.dma_channel.configure(false, DmaPriority::Priority0), + ctx.dma_channel, rx_descriptors, tx_descriptors, ); diff --git a/hil-test/tests/lcd_cam_i8080.rs b/hil-test/tests/lcd_cam_i8080.rs index 1d4555bfa52..b698d49d90b 100644 --- a/hil-test/tests/lcd_cam_i8080.rs +++ b/hil-test/tests/lcd_cam_i8080.rs @@ -6,7 +6,7 @@ #![no_main] use esp_hal::{ - dma::{Dma, DmaPriority, DmaTxBuf}, + dma::{Dma, DmaTxBuf}, dma_buffers, gpio::{Io, NoPin}, lcd_cam::{ @@ -59,13 +59,11 @@ mod tests { #[test] fn test_i8080_8bit(ctx: Context<'static>) { - let channel = ctx.dma.channel0.configure(false, DmaPriority::Priority0); - let pins = TxEightBits::new(NoPin, NoPin, NoPin, NoPin, NoPin, NoPin, NoPin, NoPin); let i8080 = I8080::new( ctx.lcd_cam.lcd, - channel.tx, + ctx.dma.channel0.tx, pins, 20.MHz(), Config::default(), @@ -77,16 +75,11 @@ mod tests { #[test] fn test_i8080_8bit_async_channel(ctx: Context<'static>) { - let channel = ctx - .dma - .channel0 - .configure(false, DmaPriority::Priority0) - .into_async(); let pins = TxEightBits::new(NoPin, NoPin, NoPin, NoPin, NoPin, NoPin, NoPin, NoPin); let i8080 = I8080::new( ctx.lcd_cam.lcd, - channel.tx, + ctx.dma.channel0.tx, pins, 20.MHz(), Config::default(), @@ -136,7 +129,6 @@ mod tests { .channel0 .set_input_mode(EdgeMode::Hold, EdgeMode::Increment); - let channel = ctx.dma.channel0.configure(false, DmaPriority::Priority0); let pins = TxEightBits::new( unit0_signal, unit1_signal, @@ -150,7 +142,7 @@ mod tests { let mut i8080 = I8080::new( ctx.lcd_cam.lcd, - channel.tx, + ctx.dma.channel0.tx, pins, 20.MHz(), Config::default(), @@ -247,7 +239,7 @@ mod tests { .channel0 .set_input_mode(EdgeMode::Hold, EdgeMode::Increment); - let channel = ctx.dma.channel0.configure(false, DmaPriority::Priority0); + let channel = ctx.dma.channel0; let pins = TxSixteenBits::new( NoPin, NoPin, diff --git a/hil-test/tests/lcd_cam_i8080_async.rs b/hil-test/tests/lcd_cam_i8080_async.rs index df44d002289..d4f0be94f4a 100644 --- a/hil-test/tests/lcd_cam_i8080_async.rs +++ b/hil-test/tests/lcd_cam_i8080_async.rs @@ -7,7 +7,7 @@ #![no_main] use esp_hal::{ - dma::{Dma, DmaPriority, DmaTxBuf}, + dma::{Dma, DmaTxBuf}, dma_buffers, gpio::NoPin, lcd_cam::{ @@ -50,12 +50,11 @@ mod tests { #[test] async fn test_i8080_8bit(ctx: Context<'static>) { - let channel = ctx.dma.channel0.configure(false, DmaPriority::Priority0); let pins = TxEightBits::new(NoPin, NoPin, NoPin, NoPin, NoPin, NoPin, NoPin, NoPin); let i8080 = I8080::new( ctx.lcd_cam.lcd, - channel.tx, + ctx.dma.channel0.tx, pins, 20.MHz(), Config::default(), @@ -73,16 +72,11 @@ mod tests { #[test] async fn test_i8080_8bit_async_channel(ctx: Context<'static>) { - let channel = ctx - .dma - .channel0 - .configure(false, DmaPriority::Priority0) - .into_async(); let pins = TxEightBits::new(NoPin, NoPin, NoPin, NoPin, NoPin, NoPin, NoPin, NoPin); let i8080 = I8080::new( ctx.lcd_cam.lcd, - channel.tx, + ctx.dma.channel0.tx, pins, 20.MHz(), Config::default(), diff --git a/hil-test/tests/parl_io_tx.rs b/hil-test/tests/parl_io_tx.rs index f2b2cceb559..79f540ba6da 100644 --- a/hil-test/tests/parl_io_tx.rs +++ b/hil-test/tests/parl_io_tx.rs @@ -7,12 +7,8 @@ #[cfg(esp32c6)] use esp_hal::parl_io::{TxPinConfigWithValidPin, TxSixteenBits}; use esp_hal::{ - dma::{ChannelCreator, Dma, DmaPriority}, - gpio::{ - interconnect::{InputSignal, OutputSignal}, - Io, - NoPin, - }, + dma::{Channel, Dma, DmaChannel0}, + gpio::{interconnect::InputSignal, AnyPin, Io, NoPin}, parl_io::{ BitPackOrder, ClkOutPin, @@ -28,14 +24,15 @@ use esp_hal::{ }, peripherals::PARL_IO, prelude::*, + Blocking, }; use hil_test as _; struct Context { parl_io: PARL_IO, - dma_channel: ChannelCreator<0>, - clock: OutputSignal, - valid: OutputSignal, + dma_channel: Channel<'static, DmaChannel0, Blocking>, + clock: AnyPin, + valid: AnyPin, clock_loopback: InputSignal, valid_loopback: InputSignal, pcnt_unit: Unit<'static, 0>, @@ -90,13 +87,8 @@ mod tests { let mut pins = TxPinConfigIncludingValidPin::new(pins); let mut clock_pin = ClkOutPin::new(ctx.clock); - let pio = ParlIoTxOnly::new( - ctx.parl_io, - ctx.dma_channel.configure(false, DmaPriority::Priority0), - tx_descriptors, - 10.MHz(), - ) - .unwrap(); + let pio = + ParlIoTxOnly::new(ctx.parl_io, ctx.dma_channel, tx_descriptors, 10.MHz()).unwrap(); let mut pio = pio .tx @@ -157,13 +149,8 @@ mod tests { let mut clock_pin = ClkOutPin::new(ctx.clock); - let pio = ParlIoTxOnly::new( - ctx.parl_io, - ctx.dma_channel.configure(false, DmaPriority::Priority0), - tx_descriptors, - 10.MHz(), - ) - .unwrap(); + let pio = + ParlIoTxOnly::new(ctx.parl_io, ctx.dma_channel, tx_descriptors, 10.MHz()).unwrap(); let mut pio = pio .tx diff --git a/hil-test/tests/parl_io_tx_async.rs b/hil-test/tests/parl_io_tx_async.rs index 2c4522f02cf..a157e51138b 100644 --- a/hil-test/tests/parl_io_tx_async.rs +++ b/hil-test/tests/parl_io_tx_async.rs @@ -9,12 +9,8 @@ #[cfg(esp32c6)] use esp_hal::parl_io::{TxPinConfigWithValidPin, TxSixteenBits}; use esp_hal::{ - dma::{ChannelCreator, Dma, DmaPriority}, - gpio::{ - interconnect::{InputSignal, OutputSignal}, - Io, - NoPin, - }, + dma::{Channel, Dma, DmaChannel0}, + gpio::{interconnect::InputSignal, AnyPin, Io, NoPin}, parl_io::{ BitPackOrder, ClkOutPin, @@ -30,14 +26,15 @@ use esp_hal::{ }, peripherals::PARL_IO, prelude::*, + Async, }; use hil_test as _; struct Context { parl_io: PARL_IO, - dma_channel: ChannelCreator<0>, - clock: OutputSignal, - valid: OutputSignal, + dma_channel: Channel<'static, DmaChannel0, Async>, + clock: AnyPin, + valid: AnyPin, clock_loopback: InputSignal, valid_loopback: InputSignal, pcnt_unit: Unit<'static, 0>, @@ -62,7 +59,7 @@ mod tests { let pcnt = Pcnt::new(peripherals.PCNT); let pcnt_unit = pcnt.unit0; let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; + let dma_channel = dma.channel0.into_async(); let parl_io = peripherals.PARL_IO; @@ -92,15 +89,8 @@ mod tests { let mut pins = TxPinConfigIncludingValidPin::new(pins); let mut clock_pin = ClkOutPin::new(ctx.clock); - let pio = ParlIoTxOnly::new( - ctx.parl_io, - ctx.dma_channel - .configure(false, DmaPriority::Priority0) - .into_async(), - tx_descriptors, - 10.MHz(), - ) - .unwrap(); + let pio = + ParlIoTxOnly::new(ctx.parl_io, ctx.dma_channel, tx_descriptors, 10.MHz()).unwrap(); let mut pio = pio .tx @@ -160,15 +150,8 @@ mod tests { let mut clock_pin = ClkOutPin::new(ctx.clock); - let pio = ParlIoTxOnly::new( - ctx.parl_io, - ctx.dma_channel - .configure(false, DmaPriority::Priority0) - .into_async(), - tx_descriptors, - 10.MHz(), - ) - .unwrap(); + let pio = + ParlIoTxOnly::new(ctx.parl_io, ctx.dma_channel, tx_descriptors, 10.MHz()).unwrap(); let mut pio = pio .tx diff --git a/hil-test/tests/qspi.rs b/hil-test/tests/qspi.rs index 9322a7b052d..10ca8cb5ea0 100644 --- a/hil-test/tests/qspi.rs +++ b/hil-test/tests/qspi.rs @@ -8,7 +8,7 @@ #[cfg(pcnt)] use esp_hal::pcnt::{channel::EdgeMode, unit::Unit, Pcnt}; use esp_hal::{ - dma::{Channel, Dma, DmaPriority, DmaRxBuf, DmaTxBuf}, + dma::{Channel, Dma, DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::{AnyPin, Input, Io, Level, Output, Pull}, prelude::*, @@ -204,8 +204,6 @@ mod tests { } } - let dma_channel = dma_channel.configure(false, DmaPriority::Priority0); - Context { spi: peripherals.SPI2, #[cfg(pcnt)] diff --git a/hil-test/tests/spi_full_duplex.rs b/hil-test/tests/spi_full_duplex.rs index 2d465a25b86..3fb9ca8bed0 100644 --- a/hil-test/tests/spi_full_duplex.rs +++ b/hil-test/tests/spi_full_duplex.rs @@ -12,7 +12,7 @@ use embedded_hal::spi::SpiBus; #[cfg(pcnt)] use embedded_hal_async::spi::SpiBus as SpiBusAsync; use esp_hal::{ - dma::{Dma, DmaDescriptor, DmaPriority, DmaRxBuf, DmaTxBuf}, + dma::{Channel, Dma, DmaDescriptor, DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::{Io, Level, NoPin}, peripheral::Peripheral, @@ -29,15 +29,15 @@ use hil_test as _; cfg_if::cfg_if! { if #[cfg(any(esp32, esp32s2))] { - type DmaChannelCreator = esp_hal::dma::Spi2DmaChannelCreator; + type DmaChannel = esp_hal::dma::Spi2DmaChannel; } else { - type DmaChannelCreator = esp_hal::dma::ChannelCreator<0>; + type DmaChannel = esp_hal::dma::DmaChannel0; } } struct Context { spi: Spi<'static, Blocking>, - dma_channel: DmaChannelCreator, + dma_channel: Channel<'static, DmaChannel, Blocking>, // Reuse the really large buffer so we don't run out of DRAM with many tests rx_buffer: &'static mut [u8], rx_descriptors: &'static mut [DmaDescriptor], @@ -199,9 +199,7 @@ mod tests { let mut dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(); let unit = ctx.pcnt_unit; - let mut spi = ctx - .spi - .with_dma(ctx.dma_channel.configure(false, DmaPriority::Priority0)); + let mut spi = ctx.spi.with_dma(ctx.dma_channel); unit.channel0.set_edge_signal(ctx.pcnt_source); unit.channel0 @@ -232,9 +230,7 @@ mod tests { let mut dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(); let unit = ctx.pcnt_unit; - let mut spi = ctx - .spi - .with_dma(ctx.dma_channel.configure(false, DmaPriority::Priority0)); + let mut spi = ctx.spi.with_dma(ctx.dma_channel); unit.channel0.set_edge_signal(ctx.pcnt_source); unit.channel0 @@ -269,9 +265,7 @@ mod tests { *v = (i % 255) as u8; } - let mut spi = ctx - .spi - .with_dma(ctx.dma_channel.configure(false, DmaPriority::Priority0)); + let mut spi = ctx.spi.with_dma(ctx.dma_channel); for i in 0..4 { dma_tx_buf.as_mut_slice()[0] = i as u8; @@ -299,9 +293,7 @@ mod tests { dma_tx_buf.fill(&[0xde, 0xad, 0xbe, 0xef]); - let spi = ctx - .spi - .with_dma(ctx.dma_channel.configure(false, DmaPriority::Priority0)); + let spi = ctx.spi.with_dma(ctx.dma_channel); let transfer = spi .transfer(dma_rx_buf, dma_tx_buf) .map_err(|e| e.0) @@ -330,7 +322,7 @@ mod tests { let mut spi = ctx .spi - .with_dma(ctx.dma_channel.configure(false, DmaPriority::Priority0)) + .with_dma(ctx.dma_channel) .with_buffers(dma_rx_buf, dma_tx_buf); let tx_buf = [0xde, 0xad, 0xbe, 0xef]; @@ -350,7 +342,7 @@ mod tests { let mut spi = ctx .spi - .with_dma(ctx.dma_channel.configure(false, DmaPriority::Priority0)) + .with_dma(ctx.dma_channel) .with_buffers(dma_rx_buf, dma_tx_buf); let tx_buf = [0xde, 0xad, 0xbe, 0xef]; @@ -372,7 +364,7 @@ mod tests { let mut spi = ctx .spi - .with_dma(ctx.dma_channel.configure(false, DmaPriority::Priority0)) + .with_dma(ctx.dma_channel) .with_buffers(dma_rx_buf, dma_tx_buf); let tx_buf = core::array::from_fn(|i| i as _); @@ -393,7 +385,7 @@ mod tests { let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(); let mut spi = ctx .spi - .with_dma(ctx.dma_channel.configure(false, DmaPriority::Priority0)) + .with_dma(ctx.dma_channel) .with_buffers(dma_rx_buf, dma_tx_buf) .into_async(); @@ -427,9 +419,9 @@ mod tests { let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(); let mut spi = ctx .spi - .with_dma(ctx.dma_channel.configure(false, DmaPriority::Priority0)) - .with_buffers(dma_rx_buf, dma_tx_buf) - .into_async(); + .into_async() + .with_dma(ctx.dma_channel) + .with_buffers(dma_rx_buf, dma_tx_buf); ctx.pcnt_unit.channel0.set_edge_signal(ctx.pcnt_source); ctx.pcnt_unit @@ -460,7 +452,7 @@ mod tests { .spi .with_mosi(NoPin) .with_miso(Level::High) - .with_dma(ctx.dma_channel.configure(false, DmaPriority::Priority0)); + .with_dma(ctx.dma_channel); let (rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) = dma_buffers!(4); let mut dma_rx_buf = DmaRxBuf::new(rx_descriptors, rx_buffer).unwrap(); @@ -497,9 +489,7 @@ mod tests { let dma_rx_buf = DmaRxBuf::new(ctx.rx_descriptors, ctx.rx_buffer).unwrap(); let dma_tx_buf = DmaTxBuf::new(ctx.tx_descriptors, ctx.tx_buffer).unwrap(); - let spi = ctx - .spi - .with_dma(ctx.dma_channel.configure(false, DmaPriority::Priority0)); + let spi = ctx.spi.with_dma(ctx.dma_channel); let mut transfer = spi .transfer(dma_rx_buf, dma_tx_buf) @@ -520,9 +510,7 @@ mod tests { let mut dma_rx_buf = DmaRxBuf::new(ctx.rx_descriptors, ctx.rx_buffer).unwrap(); let mut dma_tx_buf = DmaTxBuf::new(ctx.tx_descriptors, ctx.tx_buffer).unwrap(); - let mut spi = ctx - .spi - .with_dma(ctx.dma_channel.configure(false, DmaPriority::Priority0)); + let mut spi = ctx.spi.with_dma(ctx.dma_channel); let mut transfer = spi .transfer(dma_rx_buf, dma_tx_buf) @@ -554,10 +542,7 @@ mod tests { let dma_rx_buf = DmaRxBuf::new(ctx.rx_descriptors, ctx.rx_buffer).unwrap(); let dma_tx_buf = DmaTxBuf::new(ctx.tx_descriptors, ctx.tx_buffer).unwrap(); - let spi = ctx - .spi - .with_dma(ctx.dma_channel.configure(false, DmaPriority::Priority0)) - .into_async(); + let spi = ctx.spi.with_dma(ctx.dma_channel).into_async(); let mut transfer = spi .transfer(dma_rx_buf, dma_tx_buf) diff --git a/hil-test/tests/spi_half_duplex_read.rs b/hil-test/tests/spi_half_duplex_read.rs index a50fa0dc807..6970c6d485f 100644 --- a/hil-test/tests/spi_half_duplex_read.rs +++ b/hil-test/tests/spi_half_duplex_read.rs @@ -6,7 +6,7 @@ #![no_main] use esp_hal::{ - dma::{Dma, DmaPriority, DmaRxBuf, DmaTxBuf}, + dma::{Dma, DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::{Io, Level, Output}, prelude::*, @@ -52,7 +52,7 @@ mod tests { let spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0) .with_sck(sclk) .with_miso(miso) - .with_dma(dma_channel.configure(false, DmaPriority::Priority0)); + .with_dma(dma_channel); Context { spi, miso_mirror } } diff --git a/hil-test/tests/spi_half_duplex_write.rs b/hil-test/tests/spi_half_duplex_write.rs index f06a80f3eaf..2d3268abbc5 100644 --- a/hil-test/tests/spi_half_duplex_write.rs +++ b/hil-test/tests/spi_half_duplex_write.rs @@ -6,7 +6,7 @@ #![no_main] use esp_hal::{ - dma::{Dma, DmaPriority, DmaRxBuf, DmaTxBuf}, + dma::{Dma, DmaRxBuf, DmaTxBuf}, dma_buffers, gpio::{interconnect::InputSignal, Io}, pcnt::{channel::EdgeMode, unit::Unit, Pcnt}, @@ -55,7 +55,7 @@ mod tests { let spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0) .with_sck(sclk) .with_mosi(mosi) - .with_dma(dma_channel.configure(false, DmaPriority::Priority0)); + .with_dma(dma_channel); Context { spi, diff --git a/hil-test/tests/spi_half_duplex_write_psram.rs b/hil-test/tests/spi_half_duplex_write_psram.rs index f40f81dc2db..41116633ec1 100644 --- a/hil-test/tests/spi_half_duplex_write_psram.rs +++ b/hil-test/tests/spi_half_duplex_write_psram.rs @@ -7,7 +7,7 @@ use defmt::error; use esp_alloc as _; use esp_hal::{ - dma::{Dma, DmaBufBlkSize, DmaPriority, DmaRxBuf, DmaTxBuf}, + dma::{Dma, DmaBufBlkSize, DmaRxBuf, DmaTxBuf}, dma_buffers, dma_descriptors_chunk_size, gpio::{interconnect::InputSignal, Io}, @@ -67,7 +67,7 @@ mod tests { let spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0) .with_sck(sclk) .with_mosi(mosi) - .with_dma(dma_channel.configure(false, DmaPriority::Priority0)); + .with_dma(dma_channel); Context { spi, diff --git a/hil-test/tests/spi_slave.rs b/hil-test/tests/spi_slave.rs index 4d60f3b79cb..11d83117d8b 100644 --- a/hil-test/tests/spi_slave.rs +++ b/hil-test/tests/spi_slave.rs @@ -9,7 +9,7 @@ #![no_main] use esp_hal::{ - dma::{Dma, DmaPriority}, + dma::{Channel, Dma}, dma_buffers, gpio::{ interconnect::{InputSignal, OutputSignal}, @@ -22,15 +22,15 @@ use hil_test as _; cfg_if::cfg_if! { if #[cfg(any(esp32, esp32s2))] { - type DmaChannelCreator = esp_hal::dma::Spi2DmaChannelCreator; + type DmaChannel = esp_hal::dma::Spi2DmaChannel; } else { - type DmaChannelCreator = esp_hal::dma::ChannelCreator<0>; + type DmaChannel = esp_hal::dma::DmaChannel0; } } struct Context { spi: Spi<'static, Blocking>, - dma_channel: DmaChannelCreator, + dma_channel: Channel<'static, DmaChannel, Blocking>, bitbang_spi: BitbangSpi, } @@ -165,11 +165,9 @@ mod tests { fn test_basic(mut ctx: Context) { const DMA_SIZE: usize = 32; let (rx_buffer, rx_descriptors, tx_buffer, tx_descriptors) = dma_buffers!(DMA_SIZE); - let mut spi = ctx.spi.with_dma( - ctx.dma_channel.configure(false, DmaPriority::Priority0), - rx_descriptors, - tx_descriptors, - ); + let mut spi = ctx + .spi + .with_dma(ctx.dma_channel, rx_descriptors, tx_descriptors); let slave_send = tx_buffer; let slave_receive = rx_buffer;