diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index f742791b5d..3c8eede386 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -24,7 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - I2S Parallel output driver for ESP32. (#2348, #2436) - Add an option to configure `WDT` action (#2330) - `DmaDescriptor` is now `Send` (#2456) -- `into_async` and `into_blocking` functions for most peripherals (#2430) +- `into_async` and `into_blocking` functions for most peripherals (#2430, #2461) - API mode type parameter (currently always `Blocking`) to `master::Spi` and `slave::Spi` (#2430) - `gpio::{GpioPin, AnyPin, Flex, Output, OutputOpenDrain}::split()` to obtain peripheral interconnect signals. (#2418) - `gpio::Input::{split(), into_peripheral_output()}` when used with output pins. (#2418) @@ -43,7 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Circular DMA transfers now correctly error, `available` returns `Result` now (#2409) - Interrupt listen/unlisten/clear functions now accept any type that converts into `EnumSet` (i.e. single interrupt flags). (#2442) - SPI interrupt listening is now only available in Blocking mode. The `set_interrupt_handler` is available via `InterruptConfigurable` (#2442) -- Allow users to create DMA `Preparation`s (#2455) +- Allow users to create DMA `Preparation`s (#2455) - The `rmt::asynch::RxChannelAsync` and `rmt::asynch::TxChannelAsync` traits have been moved to `rmt` (#2430) - Calling `AnyPin::output_signals` on an input-only pin (ESP32 GPIO 34-39) will now result in a panic. (#2418) diff --git a/esp-hal/src/parl_io.rs b/esp-hal/src/parl_io.rs index 89043b088a..c552a3c197 100644 --- a/esp-hal/src/parl_io.rs +++ b/esp-hal/src/parl_io.rs @@ -54,6 +54,7 @@ use crate::{ peripheral::{self, Peripheral}, peripherals::{self, Interrupt, PARL_IO}, system::PeripheralClockControl, + Async, Blocking, InterruptConfigurable, Mode, @@ -1017,12 +1018,9 @@ where pub rx: RxCreatorFullDuplex<'d, DM>, } -impl<'d, DM> ParlIoFullDuplex<'d, DM> -where - DM: Mode, -{ +impl<'d> ParlIoFullDuplex<'d, Blocking> { /// Create a new instance of [ParlIoFullDuplex] - pub fn new( + pub fn new( _parl_io: impl Peripheral

+ 'd, dma_channel: Channel<'d, CH, DM>, tx_descriptors: &'static mut [DmaDescriptor], @@ -1030,8 +1028,11 @@ where frequency: HertzU32, ) -> Result where + DM: Mode, CH: DmaChannelConvert<::Dma>, + Channel<'d, CH, Blocking>: From>, { + let dma_channel = Channel::<'d, CH, Blocking>::from(dma_channel); internal_init(frequency)?; Ok(Self { @@ -1047,9 +1048,29 @@ where }, }) } -} -impl ParlIoFullDuplex<'_, Blocking> { + /// Convert to an async version. + pub fn into_async(self) -> ParlIoFullDuplex<'d, Async> { + let channel = Channel { + tx: self.tx.tx_channel, + rx: self.rx.rx_channel, + phantom: PhantomData::, + }; + let channel = channel.into_async(); + ParlIoFullDuplex { + tx: TxCreatorFullDuplex { + tx_channel: channel.tx, + descriptors: self.tx.descriptors, + phantom: PhantomData, + }, + rx: RxCreatorFullDuplex { + rx_channel: channel.rx, + descriptors: self.rx.descriptors, + phantom: PhantomData, + }, + } + } + /// Sets the interrupt handler, enables it with /// [crate::interrupt::Priority::min()] /// @@ -1087,6 +1108,30 @@ impl InterruptConfigurable for ParlIoFullDuplex<'_, Blocking> { } } +impl<'d> ParlIoFullDuplex<'d, Async> { + /// Convert to a blocking version. + pub fn into_blocking(self) -> ParlIoFullDuplex<'d, Blocking> { + let channel = Channel { + tx: self.tx.tx_channel, + rx: self.rx.rx_channel, + phantom: PhantomData::, + }; + let channel = channel.into_blocking(); + ParlIoFullDuplex { + tx: TxCreatorFullDuplex { + tx_channel: channel.tx, + descriptors: self.tx.descriptors, + phantom: PhantomData, + }, + rx: RxCreatorFullDuplex { + rx_channel: channel.rx, + descriptors: self.rx.descriptors, + phantom: PhantomData, + }, + } + } +} + /// Parallel IO in half duplex / TX only mode pub struct ParlIoTxOnly<'d, DM> where