Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Nov 22, 2024
1 parent 64e6e4b commit 3e3869d
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 80 deletions.
2 changes: 1 addition & 1 deletion esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `set_priority` to the `DmaChannel` trait on GDMA devices (#2403, #2526)
- Added `into_async` and `into_blocking` functions for `ParlIoTxOnly`, `ParlIoRxOnly` (#2526)
- ESP32-C6, H2, S3: Added `split` function to the `DmaChannel` trait. (#2526, #2532)
- DMA: `CompatibleWith` traits and `ChannelFor` type aliasses to improve usability. (#2532)
- DMA: `PeripheralDmaChannel` type aliasses and `DmaChannelFor` traits to improve usability. (#2532)

### Changed

Expand Down
4 changes: 2 additions & 2 deletions esp-hal/MIGRATING-0.22.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn new_foo<'d, T, CH>(
)
where
T: SomePeripheralInstance,
CH: CompatibleWith<T>,
CH: DmaChannelFor<T>,
{
// Optionally: dma_channel.set_priority(DmaPriority::Priority2);

Expand All @@ -84,7 +84,7 @@ If you are writing a driver and need to store a channel in a structure, you can
```diff
struct Aes<'d> {
- channel: ChannelTx<'d, Blocking, <AES as DmaEligible>::Dma>,
+ channel: ChannelTx<'d, Blocking, TxChannelFor<AES>>,
+ channel: ChannelTx<'d, Blocking, PeripheralTxChannel<AES>>,
}
```

Expand Down
14 changes: 7 additions & 7 deletions esp-hal/src/aes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,17 @@ pub mod dma {
Channel,
ChannelRx,
ChannelTx,
CompatibleWith,
DescriptorChain,
DmaChannelFor,
DmaDescriptor,
DmaPeripheral,
DmaTransferRxTx,
PeripheralDmaChannel,
PeripheralRxChannel,
PeripheralTxChannel,
ReadBuffer,
Rx,
RxChannelFor,
Tx,
TxChannelFor,
WriteBuffer,
},
peripheral::Peripheral,
Expand Down Expand Up @@ -281,7 +281,7 @@ pub mod dma {
/// The underlying [`Aes`](super::Aes) driver
pub aes: super::Aes<'d>,

channel: Channel<'d, Blocking, DmaChannelFor<AES>>,
channel: Channel<'d, Blocking, PeripheralDmaChannel<AES>>,
rx_chain: DescriptorChain,
tx_chain: DescriptorChain,
}
Expand All @@ -295,7 +295,7 @@ pub mod dma {
tx_descriptors: &'static mut [DmaDescriptor],
) -> AesDma<'d>
where
CH: CompatibleWith<AES>,
CH: DmaChannelFor<AES>,
{
let channel = Channel::new(channel.map(|ch| ch.degrade()));
channel.runtime_ensure_compatible(&self.aes);
Expand Down Expand Up @@ -331,7 +331,7 @@ pub mod dma {
}

impl<'d> DmaSupportTx for AesDma<'d> {
type TX = ChannelTx<'d, Blocking, TxChannelFor<AES>>;
type TX = ChannelTx<'d, Blocking, PeripheralTxChannel<AES>>;

fn tx(&mut self) -> &mut Self::TX {
&mut self.channel.tx
Expand All @@ -343,7 +343,7 @@ pub mod dma {
}

impl<'d> DmaSupportRx for AesDma<'d> {
type RX = ChannelRx<'d, Blocking, RxChannelFor<AES>>;
type RX = ChannelRx<'d, Blocking, PeripheralRxChannel<AES>>;

fn rx(&mut self) -> &mut Self::RX {
&mut self.channel.rx
Expand Down
35 changes: 19 additions & 16 deletions esp-hal/src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1587,11 +1587,11 @@ macro_rules! impl_dma_eligible {
}

/// Helper type to get the DMA (Rx and Tx) channel for a peripheral.
pub type DmaChannelFor<T> = <T as DmaEligible>::Dma;
pub type PeripheralDmaChannel<T> = <T as DmaEligible>::Dma;
/// Helper type to get the DMA Rx channel for a peripheral.
pub type RxChannelFor<T> = <DmaChannelFor<T> as DmaChannel>::Rx;
pub type PeripheralRxChannel<T> = <PeripheralDmaChannel<T> as DmaChannel>::Rx;
/// Helper type to get the DMA Tx channel for a peripheral.
pub type TxChannelFor<T> = <DmaChannelFor<T> as DmaChannel>::Tx;
pub type PeripheralTxChannel<T> = <PeripheralDmaChannel<T> as DmaChannel>::Tx;

#[doc(hidden)]
pub trait DmaRxChannel:
Expand Down Expand Up @@ -1676,7 +1676,7 @@ impl<DEG: DmaChannel> DmaChannelConvert<DEG> for DEG {
/// ```rust,no_run
#[doc = crate::before_snippet!()]
/// use esp_hal::spi::master::{Spi, SpiDma, Config, Instance as SpiInstance};
/// use esp_hal::dma::CompatibleWith;
/// use esp_hal::dma::DmaChannelFor;
/// use esp_hal::peripheral::Peripheral;
/// use esp_hal::Blocking;
/// use esp_hal::dma::Dma;
Expand All @@ -1687,7 +1687,7 @@ impl<DEG: DmaChannel> DmaChannelConvert<DEG> for DEG {
/// ) -> SpiDma<'d, Blocking, S>
/// where
/// S: SpiInstance,
/// CH: CompatibleWith<S> + 'd,
/// CH: DmaChannelFor<S> + 'd,
/// {
/// spi.with_dma(channel)
/// }
Expand All @@ -1704,41 +1704,44 @@ impl<DEG: DmaChannel> DmaChannelConvert<DEG> for DEG {
/// let spi_dma = configures_spi_dma(spi, dma_channel);
/// # }
/// ```
pub trait CompatibleWith<P: DmaEligible>: DmaChannel + DmaChannelConvert<DmaChannelFor<P>> {}
impl<P, CH> CompatibleWith<P> for CH
pub trait DmaChannelFor<P: DmaEligible>:
DmaChannel + DmaChannelConvert<PeripheralDmaChannel<P>>
{
}
impl<P, CH> DmaChannelFor<P> for CH
where
P: DmaEligible,
CH: DmaChannel + DmaChannelConvert<DmaChannelFor<P>>,
CH: DmaChannel + DmaChannelConvert<PeripheralDmaChannel<P>>,
{
}

/// Trait implemented for the RX half of split DMA channels that are compatible
/// with a particular peripheral. Accepts complete DMA channels or split halves.
///
/// This trait is similar in use to [`CompatibleWith`].
/// This trait is similar in use to [`DmaChannelFor`].
///
/// You can use this in places where a peripheral driver would expect a
/// `DmaRxChannel` implementation.
pub trait RxCompatibleWith<P: DmaEligible>: DmaChannelConvert<RxChannelFor<P>> {}
impl<P, RX> RxCompatibleWith<P> for RX
pub trait RxChannelFor<P: DmaEligible>: DmaChannelConvert<PeripheralRxChannel<P>> {}
impl<P, RX> RxChannelFor<P> for RX
where
P: DmaEligible,
RX: DmaChannelConvert<RxChannelFor<P>>,
RX: DmaChannelConvert<PeripheralRxChannel<P>>,
{
}

/// Trait implemented for the TX half of split DMA channels that are compatible
/// with a particular peripheral. Accepts complete DMA channels or split halves.
///
/// This trait is similar in use to [`CompatibleWith`].
/// This trait is similar in use to [`DmaChannelFor`].
///
/// You can use this in places where a peripheral driver would expect a
/// `DmaTxChannel` implementation.
pub trait TxCompatibleWith<PER: DmaEligible>: DmaChannelConvert<TxChannelFor<PER>> {}
impl<P, TX> TxCompatibleWith<P> for TX
pub trait TxChannelFor<PER: DmaEligible>: DmaChannelConvert<PeripheralTxChannel<PER>> {}
impl<P, TX> TxChannelFor<P> for TX
where
P: DmaEligible,
TX: DmaChannelConvert<TxChannelFor<P>>,
TX: DmaChannelConvert<PeripheralTxChannel<P>>,
{
}

Expand Down
24 changes: 12 additions & 12 deletions esp-hal/src/i2s/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ use crate::{
Channel,
ChannelRx,
ChannelTx,
CompatibleWith,
DescriptorChain,
DmaChannelFor,
DmaDescriptor,
Expand All @@ -90,11 +89,12 @@ use crate::{
DmaTransferRxCircular,
DmaTransferTx,
DmaTransferTxCircular,
PeripheralDmaChannel,
PeripheralRxChannel,
PeripheralTxChannel,
ReadBuffer,
Rx,
RxChannelFor,
Tx,
TxChannelFor,
WriteBuffer,
},
gpio::interconnect::PeripheralOutput,
Expand Down Expand Up @@ -271,7 +271,7 @@ where
standard: Standard,
data_format: DataFormat,
sample_rate: impl Into<fugit::HertzU32>,
channel: PeripheralRef<'d, DmaChannelFor<T>>,
channel: PeripheralRef<'d, PeripheralDmaChannel<T>>,
rx_descriptors: &'static mut [DmaDescriptor],
tx_descriptors: &'static mut [DmaDescriptor],
) -> Self {
Expand Down Expand Up @@ -377,7 +377,7 @@ impl<'d> I2s<'d, Blocking> {
tx_descriptors: &'static mut [DmaDescriptor],
) -> Self
where
CH: CompatibleWith<AnyI2s>,
CH: DmaChannelFor<AnyI2s>,
{
Self::new_typed(
i2s.map_into(),
Expand Down Expand Up @@ -408,7 +408,7 @@ where
tx_descriptors: &'static mut [DmaDescriptor],
) -> Self
where
CH: CompatibleWith<T>,
CH: DmaChannelFor<T>,
{
crate::into_ref!(i2s);
Self::new_internal(
Expand Down Expand Up @@ -463,7 +463,7 @@ where
DmaMode: Mode,
{
i2s: PeripheralRef<'d, T>,
tx_channel: ChannelTx<'d, DmaMode, TxChannelFor<T>>,
tx_channel: ChannelTx<'d, DmaMode, PeripheralTxChannel<T>>,
tx_chain: DescriptorChain,
_guard: PeripheralGuard,
}
Expand Down Expand Up @@ -497,7 +497,7 @@ where
T: RegisterAccess,
DmaMode: Mode,
{
type TX = ChannelTx<'d, DmaMode, TxChannelFor<T>>;
type TX = ChannelTx<'d, DmaMode, PeripheralTxChannel<T>>;

fn tx(&mut self) -> &mut Self::TX {
&mut self.tx_channel
Expand Down Expand Up @@ -596,7 +596,7 @@ where
DmaMode: Mode,
{
i2s: PeripheralRef<'d, T>,
rx_channel: ChannelRx<'d, DmaMode, RxChannelFor<T>>,
rx_channel: ChannelRx<'d, DmaMode, PeripheralRxChannel<T>>,
rx_chain: DescriptorChain,
_guard: PeripheralGuard,
}
Expand Down Expand Up @@ -630,7 +630,7 @@ where
T: RegisterAccess,
DmaMode: Mode,
{
type RX = ChannelRx<'d, DmaMode, RxChannelFor<T>>;
type RX = ChannelRx<'d, DmaMode, PeripheralRxChannel<T>>;

fn rx(&mut self) -> &mut Self::RX {
&mut self.rx_channel
Expand Down Expand Up @@ -766,7 +766,7 @@ mod private {
M: Mode,
{
pub i2s: PeripheralRef<'d, T>,
pub tx_channel: ChannelTx<'d, M, TxChannelFor<T>>,
pub tx_channel: ChannelTx<'d, M, PeripheralTxChannel<T>>,
pub descriptors: &'static mut [DmaDescriptor],
pub(crate) guard: PeripheralGuard,
}
Expand Down Expand Up @@ -826,7 +826,7 @@ mod private {
M: Mode,
{
pub i2s: PeripheralRef<'d, T>,
pub rx_channel: ChannelRx<'d, M, RxChannelFor<T>>,
pub rx_channel: ChannelRx<'d, M, PeripheralRxChannel<T>>,
pub descriptors: &'static mut [DmaDescriptor],
pub(crate) guard: PeripheralGuard,
}
Expand Down
10 changes: 5 additions & 5 deletions esp-hal/src/i2s/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ use crate::{
asynch::DmaTxFuture,
Channel,
ChannelTx,
CompatibleWith,
DmaChannelFor,
DmaEligible,
DmaError,
DmaPeripheral,
DmaTxBuffer,
PeripheralTxChannel,
Tx,
TxChannelFor,
},
gpio::{
interconnect::{OutputConnection, PeripheralOutput},
Expand Down Expand Up @@ -178,7 +178,7 @@ where
I: Instance,
{
instance: PeripheralRef<'d, I>,
tx_channel: ChannelTx<'d, DM, TxChannelFor<I>>,
tx_channel: ChannelTx<'d, DM, PeripheralTxChannel<I>>,
_guard: PeripheralGuard,
}

Expand All @@ -192,7 +192,7 @@ impl<'d> I2sParallel<'d, Blocking> {
clock_pin: impl Peripheral<P = impl PeripheralOutput> + 'd,
) -> Self
where
CH: CompatibleWith<AnyI2s>,
CH: DmaChannelFor<AnyI2s>,
{
Self::new_typed(i2s.map_into(), channel, frequency, pins, clock_pin)
}
Expand All @@ -211,7 +211,7 @@ where
clock_pin: impl Peripheral<P = impl PeripheralOutput> + 'd,
) -> Self
where
CH: CompatibleWith<I>,
CH: DmaChannelFor<I>,
{
crate::into_ref!(i2s);
crate::into_mapped_ref!(clock_pin);
Expand Down
6 changes: 3 additions & 3 deletions esp-hal/src/lcd_cam/cam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ use fugit::HertzU32;

use crate::{
clock::Clocks,
dma::{ChannelRx, DmaError, DmaPeripheral, DmaRxBuffer, Rx, RxChannelFor, RxCompatibleWith},
dma::{ChannelRx, DmaError, DmaPeripheral, DmaRxBuffer, PeripheralRxChannel, Rx, RxChannelFor},
gpio::{
interconnect::{PeripheralInput, PeripheralOutput},
InputSignal,
Expand Down Expand Up @@ -123,7 +123,7 @@ pub struct Cam<'d> {
/// Represents the camera interface with DMA support.
pub struct Camera<'d> {
lcd_cam: PeripheralRef<'d, LCD_CAM>,
rx_channel: ChannelRx<'d, Blocking, RxChannelFor<LCD_CAM>>,
rx_channel: ChannelRx<'d, Blocking, PeripheralRxChannel<LCD_CAM>>,
_guard: GenericPeripheralGuard<{ system::Peripheral::LcdCam as u8 }>,
}

Expand All @@ -136,7 +136,7 @@ impl<'d> Camera<'d> {
frequency: HertzU32,
) -> Self
where
CH: RxCompatibleWith<LCD_CAM>,
CH: RxChannelFor<LCD_CAM>,
P: RxPins,
{
let rx_channel = ChannelRx::new(channel.map(|ch| ch.degrade()));
Expand Down
6 changes: 3 additions & 3 deletions esp-hal/src/lcd_cam/lcd/dpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ use fugit::HertzU32;

use crate::{
clock::Clocks,
dma::{ChannelTx, DmaError, DmaPeripheral, DmaTxBuffer, Tx, TxChannelFor, TxCompatibleWith},
dma::{ChannelTx, DmaError, DmaPeripheral, DmaTxBuffer, PeripheralTxChannel, Tx, TxChannelFor},
gpio::{interconnect::PeripheralOutput, Level, OutputSignal},
lcd_cam::{
calculate_clkm,
Expand All @@ -123,7 +123,7 @@ use crate::{
/// Represents the RGB LCD interface.
pub struct Dpi<'d, DM: Mode> {
lcd_cam: PeripheralRef<'d, LCD_CAM>,
tx_channel: ChannelTx<'d, Blocking, TxChannelFor<LCD_CAM>>,
tx_channel: ChannelTx<'d, Blocking, PeripheralTxChannel<LCD_CAM>>,
_mode: PhantomData<DM>,
}

Expand All @@ -139,7 +139,7 @@ where
config: Config,
) -> Self
where
CH: TxCompatibleWith<LCD_CAM>,
CH: TxChannelFor<LCD_CAM>,
{
let tx_channel = ChannelTx::new(channel.map(|ch| ch.degrade()));
let lcd_cam = lcd.lcd_cam;
Expand Down
Loading

0 comments on commit 3e3869d

Please sign in to comment.