Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add into_async for ParlIO #2461

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<usize,DmaError>` 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)

Expand Down
59 changes: 52 additions & 7 deletions esp-hal/src/parl_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ use crate::{
peripheral::{self, Peripheral},
peripherals::{self, Interrupt, PARL_IO},
system::PeripheralClockControl,
Async,
Blocking,
InterruptConfigurable,
Mode,
Expand Down Expand Up @@ -1017,21 +1018,21 @@ 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<CH>(
pub fn new<CH, DM>(
_parl_io: impl Peripheral<P = peripherals::PARL_IO> + 'd,
dma_channel: Channel<'d, CH, DM>,
tx_descriptors: &'static mut [DmaDescriptor],
rx_descriptors: &'static mut [DmaDescriptor],
frequency: HertzU32,
) -> Result<Self, Error>
where
DM: Mode,
CH: DmaChannelConvert<<PARL_IO as DmaEligible>::Dma>,
Channel<'d, CH, Blocking>: From<Channel<'d, CH, DM>>,
{
let dma_channel = Channel::<'d, CH, Blocking>::from(dma_channel);
internal_init(frequency)?;

Ok(Self {
Expand All @@ -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::<Blocking>,
};
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()]
///
Expand Down Expand Up @@ -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::<Async>,
};
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
Expand Down