Skip to content

Commit 1f90a0b

Browse files
committed
Use PeripheralDmaChannel on constructors only
1 parent 5c4fc95 commit 1f90a0b

File tree

5 files changed

+81
-41
lines changed

5 files changed

+81
-41
lines changed

esp-hal/src/aes/mod.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ pub mod dma {
236236
dma::{
237237
dma_private::{DmaSupport, DmaSupportRx, DmaSupportTx},
238238
AesPeripheral,
239+
AnyDmaChannel,
239240
Channel,
240241
ChannelRx,
241242
ChannelTx,
@@ -252,8 +253,6 @@ pub mod dma {
252253
},
253254
};
254255

255-
type DefaultChannel = crate::dma::AnyDmaChannel;
256-
257256
const ALIGN_SIZE: usize = core::mem::size_of::<u32>();
258257

259258
/// Specifies the block cipher modes available for AES operations.
@@ -273,7 +272,7 @@ pub mod dma {
273272
}
274273

275274
/// A DMA capable AES instance.
276-
pub struct AesDma<'d, C = DefaultChannel>
275+
pub struct AesDma<'d, C = AnyDmaChannel>
277276
where
278277
C: DmaChannel,
279278
{
@@ -285,32 +284,33 @@ pub mod dma {
285284
tx_chain: DescriptorChain,
286285
}
287286

288-
/// Functionality for using AES with DMA.
289-
pub trait WithDmaAes<'d, C>
290-
where
291-
C: PeripheralDmaChannel,
292-
C::P: AesPeripheral,
293-
{
287+
impl<'d> crate::aes::Aes<'d> {
294288
/// Enable DMA for the current instance of the AES driver
295-
fn with_dma(
289+
pub fn with_dma<C>(
296290
self,
297291
channel: Channel<'d, C, crate::Blocking>,
298292
rx_descriptors: &'static mut [DmaDescriptor],
299293
tx_descriptors: &'static mut [DmaDescriptor],
300-
) -> AesDma<'d, C>;
301-
}
294+
) -> AesDma<'d>
295+
where
296+
Self: Sized,
297+
C: PeripheralDmaChannel,
298+
C::P: AesPeripheral,
299+
{
300+
self.with_dma_typed(channel.degrade(), rx_descriptors, tx_descriptors)
301+
}
302302

303-
impl<'d, C> WithDmaAes<'d, C> for crate::aes::Aes<'d>
304-
where
305-
C: PeripheralDmaChannel,
306-
C::P: AesPeripheral,
307-
{
308-
fn with_dma(
303+
/// Enable DMA for the current instance of the AES driver
304+
pub fn with_dma_typed<C>(
309305
self,
310306
channel: Channel<'d, C, crate::Blocking>,
311307
rx_descriptors: &'static mut [DmaDescriptor],
312308
tx_descriptors: &'static mut [DmaDescriptor],
313-
) -> AesDma<'d, C> {
309+
) -> AesDma<'d, C>
310+
where
311+
C: PeripheralDmaChannel,
312+
C::P: AesPeripheral,
313+
{
314314
AesDma {
315315
aes: self,
316316
channel,

esp-hal/src/i2s.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ where
435435
impl<'d, I, CH, DmaMode> I2s<'d, I, CH, DmaMode>
436436
where
437437
I: RegisterAccess,
438-
CH: PeripheralDmaChannel,
438+
CH: DmaChannel,
439439
DmaMode: Mode,
440440
{
441441
/// Construct a new I2S peripheral driver instance for the first I2S
@@ -452,6 +452,7 @@ where
452452
) -> Self
453453
where
454454
I: I2s0Instance,
455+
CH: PeripheralDmaChannel,
455456
CH::P: I2sPeripheral + I2s0Peripheral,
456457
DmaMode: Mode,
457458
{
@@ -481,6 +482,7 @@ where
481482
) -> Self
482483
where
483484
I: I2s1Instance,
485+
CH: PeripheralDmaChannel,
484486
CH::P: I2sPeripheral + I2s1Peripheral,
485487
{
486488
Self::new_internal(

esp-hal/src/lcd_cam/cam.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ use crate::{
8282
DmaPeripheral,
8383
DmaRxBuffer,
8484
LcdCamPeripheral,
85+
PeripheralDmaChannel,
8586
Rx,
8687
},
8788
gpio::{InputPin, InputSignal, OutputPin, OutputSignal, Pull},
@@ -134,17 +135,35 @@ pub struct Camera<'d, CH: DmaChannel = AnyDmaChannel> {
134135
rx_channel: ChannelRx<'d, CH>,
135136
}
136137

137-
impl<'d, CH: DmaChannel> Camera<'d, CH>
138-
where
139-
CH::P: LcdCamPeripheral,
140-
{
138+
impl<'d> Camera<'d> {
141139
/// Creates a new `Camera` instance with DMA support.
142-
pub fn new<P: RxPins>(
140+
pub fn new<P: RxPins, CH>(
141+
cam: Cam<'d>,
142+
channel: ChannelRx<'d, CH>,
143+
descriptors: &'static mut [DmaDescriptor],
144+
pins: P,
145+
frequency: HertzU32,
146+
) -> Self
147+
where
148+
CH: PeripheralDmaChannel,
149+
CH::P: LcdCamPeripheral,
150+
{
151+
Self::new_typed(cam, channel.degrade(), descriptors, pins, frequency)
152+
}
153+
}
154+
155+
impl<'d, CH: DmaChannel> Camera<'d, CH> {
156+
/// Creates a new `Camera` instance with DMA support.
157+
pub fn new_typed<P: RxPins>(
143158
cam: Cam<'d>,
144159
channel: ChannelRx<'d, CH>,
145160
_pins: P,
146161
frequency: HertzU32,
147-
) -> Self {
162+
) -> Self
163+
where
164+
CH: PeripheralDmaChannel,
165+
CH::P: LcdCamPeripheral,
166+
{
148167
let lcd_cam = cam.lcd_cam;
149168

150169
let clocks = Clocks::get();

esp-hal/src/lcd_cam/lcd/i8080.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,16 @@ use fugit::HertzU32;
6868

6969
use crate::{
7070
clock::Clocks,
71-
dma::{ChannelTx, DmaChannel, DmaError, DmaPeripheral, DmaTxBuffer, LcdCamPeripheral, Tx},
71+
dma::{
72+
ChannelTx,
73+
DmaChannel,
74+
DmaError,
75+
DmaPeripheral,
76+
DmaTxBuffer,
77+
LcdCamPeripheral,
78+
PeripheralDmaChannel,
79+
Tx,
80+
},
7281
gpio::{OutputSignal, PeripheralOutput},
7382
lcd_cam::{
7483
asynch::LCD_DONE_WAKER,
@@ -90,18 +99,19 @@ pub struct I8080<'d, CH: DmaChannel, DM: Mode> {
9099
_phantom: PhantomData<DM>,
91100
}
92101

93-
impl<'d, CH: DmaChannel, DM: Mode> I8080<'d, CH, DM>
94-
where
95-
CH::P: LcdCamPeripheral,
96-
{
102+
impl<'d, CH: DmaChannel, DM: Mode> I8080<'d, CH, DM> {
97103
/// Creates a new instance of the I8080 LCD interface.
98104
pub fn new<P: TxPins>(
99105
lcd: Lcd<'d, DM>,
100106
channel: ChannelTx<'d, CH>,
101107
mut pins: P,
102108
frequency: HertzU32,
103109
config: Config,
104-
) -> Self {
110+
) -> Self
111+
where
112+
CH: PeripheralDmaChannel,
113+
CH::P: LcdCamPeripheral,
114+
{
105115
let lcd_cam = lcd.lcd_cam;
106116

107117
let clocks = Clocks::get();

esp-hal/src/parl_io.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,8 +1114,7 @@ where
11141114

11151115
impl<'d, CH, DM> ParlIoFullDuplex<'d, CH, DM>
11161116
where
1117-
CH: PeripheralDmaChannel,
1118-
CH::P: ParlIoPeripheral,
1117+
CH: DmaChannel,
11191118
DM: Mode,
11201119
{
11211120
/// Create a new instance of [ParlIoFullDuplex]
@@ -1125,7 +1124,11 @@ where
11251124
tx_descriptors: &'static mut [DmaDescriptor],
11261125
rx_descriptors: &'static mut [DmaDescriptor],
11271126
frequency: HertzU32,
1128-
) -> Result<Self, Error> {
1127+
) -> Result<Self, Error>
1128+
where
1129+
CH: PeripheralDmaChannel,
1130+
CH::P: ParlIoPeripheral,
1131+
{
11291132
internal_init(frequency)?;
11301133

11311134
Ok(Self {
@@ -1200,8 +1203,7 @@ where
12001203

12011204
impl<'d, CH, DM> ParlIoTxOnly<'d, CH, DM>
12021205
where
1203-
CH: PeripheralDmaChannel,
1204-
CH::P: ParlIoPeripheral,
1206+
CH: DmaChannel,
12051207
DM: Mode,
12061208
{
12071209
/// Create a new [ParlIoTxOnly]
@@ -1210,7 +1212,11 @@ where
12101212
dma_channel: Channel<'d, CH, DM>,
12111213
descriptors: &'static mut [DmaDescriptor],
12121214
frequency: HertzU32,
1213-
) -> Result<Self, Error> {
1215+
) -> Result<Self, Error>
1216+
where
1217+
CH: PeripheralDmaChannel,
1218+
CH::P: ParlIoPeripheral,
1219+
{
12141220
internal_init(frequency)?;
12151221

12161222
Ok(Self {
@@ -1280,8 +1286,7 @@ where
12801286

12811287
impl<'d, CH, DM> ParlIoRxOnly<'d, CH, DM>
12821288
where
1283-
CH: PeripheralDmaChannel,
1284-
CH::P: ParlIoPeripheral,
1289+
CH: DmaChannel,
12851290
DM: Mode,
12861291
{
12871292
/// Create a new [ParlIoRxOnly] instance
@@ -1290,7 +1295,11 @@ where
12901295
dma_channel: Channel<'d, CH, DM>,
12911296
descriptors: &'static mut [DmaDescriptor],
12921297
frequency: HertzU32,
1293-
) -> Result<Self, Error> {
1298+
) -> Result<Self, Error>
1299+
where
1300+
CH: PeripheralDmaChannel,
1301+
CH::P: ParlIoPeripheral,
1302+
{
12941303
internal_init(frequency)?;
12951304

12961305
Ok(Self {

0 commit comments

Comments
 (0)