Skip to content

Commit 215ad46

Browse files
bors[bot]burrbull
andauthored
Merge #477
477: restore DMA generics order r=therealprof a=burrbull Co-authored-by: Andrey Zgarbul <[email protected]>
2 parents d38e912 + c7005b1 commit 215ad46

File tree

7 files changed

+31
-37
lines changed

7 files changed

+31
-37
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Changed
1111

12+
- `DmaSet` & `Transfer` take channel after stream generic, then other [#477]
1213
- Depracate "rt" feature as enabled by-default in `pac` [#476]
1314
- Add `Pin::interrupt()` helper method [#476]
1415
- Add restriction for setting pins in alternate mode (`IntoAF`), add docs [#474]
@@ -45,6 +46,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
4546
[#473]: https://github.com/stm32-rs/stm32f4xx-hal/pull/473
4647
[#474]: https://github.com/stm32-rs/stm32f4xx-hal/pull/474
4748
[#476]: https://github.com/stm32-rs/stm32f4xx-hal/pull/476
49+
[#477]: https://github.com/stm32-rs/stm32f4xx-hal/pull/477
4850

4951
## [v0.12.0] - 2022-02-23
5052

examples/adc_dma_rtic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ mod app {
2525
type MyMono = DwtSystick<MONO_HZ>;
2626

2727
type DMATransfer =
28-
Transfer<Stream0<DMA2>, Adc<ADC1>, PeripheralToMemory, &'static mut [u16; 2], 0>;
28+
Transfer<Stream0<DMA2>, 0, Adc<ADC1>, PeripheralToMemory, &'static mut [u16; 2]>;
2929

3030
#[shared]
3131
struct Shared {

examples/i2s-audio-out-dma.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ use stm32_i2s_v12x::{MasterClock, MasterConfig, Polarity, TransmitMode};
5151
use stm32f4xx_hal::dma::config::DmaConfig;
5252
use stm32f4xx_hal::dma::MemoryToPeripheral;
5353
use stm32f4xx_hal::dma::{Stream5, StreamsTuple, Transfer};
54-
use stm32f4xx_hal::gpio::{Alternate, PA4, PC10, PC12, PC7};
54+
use stm32f4xx_hal::gpio::{AF6, PA4, PC10, PC12, PC7};
5555
use stm32f4xx_hal::i2c::I2c;
56-
use stm32f4xx_hal::i2s::I2s;
56+
use stm32f4xx_hal::i2s::I2s3;
57+
use stm32f4xx_hal::pac::DMA1;
5758
use stm32f4xx_hal::pac::{interrupt, Interrupt};
5859
use stm32f4xx_hal::pac::{CorePeripherals, Peripherals};
59-
use stm32f4xx_hal::pac::{DMA1, SPI3};
6060
use stm32f4xx_hal::prelude::*;
6161

6262
use cs43l22::{Cs43L22, Register};
@@ -210,21 +210,13 @@ fn main() -> ! {
210210

211211
type I2sDmaTransfer = Transfer<
212212
Stream5<DMA1>,
213+
0,
213214
stm32_i2s_v12x::I2s<
214-
I2s<
215-
SPI3,
216-
(
217-
PA4<Alternate<6>>,
218-
PC10<Alternate<6>>,
219-
PC7<Alternate<6>>,
220-
PC12<Alternate<6>>,
221-
),
222-
>,
215+
I2s3<(PA4<AF6>, PC10<AF6>, PC7<AF6>, PC12<AF6>)>,
223216
TransmitMode<Data16Frame16>,
224217
>,
225218
MemoryToPeripheral,
226219
&'static mut [u16; SINE_SAMPLES * 2],
227-
0,
228220
>;
229221

230222
/// DMA transfer handoff from main() to interrupt handler

examples/spi_dma.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ const ARRAY_SIZE: usize = 100;
2020

2121
type SpiDma = Transfer<
2222
Stream4<pac::DMA1>,
23+
0,
2324
Tx<pac::SPI2>,
2425
MemoryToPeripheral,
2526
&'static mut [u8; ARRAY_SIZE],
26-
0,
2727
>;
2828

2929
static G_TRANSFER: Mutex<RefCell<Option<SpiDma>>> = Mutex::new(RefCell::new(None));

src/dma/mod.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ pub mod config {
869869
}
870870

871871
/// DMA Transfer.
872-
pub struct Transfer<STREAM, PERIPHERAL, DIRECTION, BUF, const CHANNEL: u8>
872+
pub struct Transfer<STREAM, const CHANNEL: u8, PERIPHERAL, DIRECTION, BUF>
873873
where
874874
STREAM: Stream,
875875
PERIPHERAL: PeriAddress,
@@ -883,12 +883,12 @@ where
883883
transfer_length: u16,
884884
}
885885

886-
impl<STREAM, PERIPHERAL, BUF, const CHANNEL: u8>
887-
Transfer<STREAM, PERIPHERAL, MemoryToPeripheral, BUF, CHANNEL>
886+
impl<STREAM, const CHANNEL: u8, PERIPHERAL, BUF>
887+
Transfer<STREAM, CHANNEL, PERIPHERAL, MemoryToPeripheral, BUF>
888888
where
889889
STREAM: Stream,
890890
ChannelX<CHANNEL>: Channel,
891-
PERIPHERAL: PeriAddress + DMASet<STREAM, MemoryToPeripheral, CHANNEL>,
891+
PERIPHERAL: PeriAddress + DMASet<STREAM, CHANNEL, MemoryToPeripheral>,
892892
BUF: ReadBuffer<Word = <PERIPHERAL as PeriAddress>::MemSize>,
893893
{
894894
/// Configures the DMA stream to the correct channel for the peripheral, configures source and
@@ -1014,12 +1014,12 @@ where
10141014
}
10151015
}
10161016

1017-
impl<STREAM, PERIPHERAL, BUF, const CHANNEL: u8>
1018-
Transfer<STREAM, PERIPHERAL, PeripheralToMemory, BUF, CHANNEL>
1017+
impl<STREAM, const CHANNEL: u8, PERIPHERAL, BUF>
1018+
Transfer<STREAM, CHANNEL, PERIPHERAL, PeripheralToMemory, BUF>
10191019
where
10201020
STREAM: Stream,
10211021
ChannelX<CHANNEL>: Channel,
1022-
PERIPHERAL: PeriAddress + DMASet<STREAM, PeripheralToMemory, CHANNEL> + SafePeripheralRead,
1022+
PERIPHERAL: PeriAddress + DMASet<STREAM, CHANNEL, PeripheralToMemory> + SafePeripheralRead,
10231023
BUF: WriteBuffer<Word = <PERIPHERAL as PeriAddress>::MemSize>,
10241024
{
10251025
/// Access the owned peripheral for reading
@@ -1028,12 +1028,12 @@ where
10281028
}
10291029
}
10301030

1031-
impl<STREAM, PERIPHERAL, BUF, const CHANNEL: u8>
1032-
Transfer<STREAM, PERIPHERAL, PeripheralToMemory, BUF, CHANNEL>
1031+
impl<STREAM, const CHANNEL: u8, PERIPHERAL, BUF>
1032+
Transfer<STREAM, CHANNEL, PERIPHERAL, PeripheralToMemory, BUF>
10331033
where
10341034
STREAM: Stream,
10351035
ChannelX<CHANNEL>: Channel,
1036-
PERIPHERAL: PeriAddress + DMASet<STREAM, PeripheralToMemory, CHANNEL>,
1036+
PERIPHERAL: PeriAddress + DMASet<STREAM, CHANNEL, PeripheralToMemory>,
10371037
BUF: WriteBuffer<Word = <PERIPHERAL as PeriAddress>::MemSize>,
10381038
{
10391039
/// Configures the DMA stream to the correct channel for the peripheral, configures source and
@@ -1162,12 +1162,12 @@ where
11621162
}
11631163
}
11641164

1165-
impl<STREAM, PERIPHERAL, BUF, S, const CHANNEL: u8>
1166-
Transfer<STREAM, PERIPHERAL, MemoryToMemory<S>, BUF, CHANNEL>
1165+
impl<STREAM, const CHANNEL: u8, PERIPHERAL, BUF, S>
1166+
Transfer<STREAM, CHANNEL, PERIPHERAL, MemoryToMemory<S>, BUF>
11671167
where
11681168
STREAM: Stream,
11691169
ChannelX<CHANNEL>: Channel,
1170-
PERIPHERAL: PeriAddress + DMASet<STREAM, MemoryToMemory<S>, CHANNEL>,
1170+
PERIPHERAL: PeriAddress + DMASet<STREAM, CHANNEL, MemoryToMemory<S>>,
11711171
MemoryToMemory<S>: PeriAddress,
11721172
BUF: WriteBuffer<Word = <PERIPHERAL as PeriAddress>::MemSize>,
11731173
{
@@ -1261,13 +1261,13 @@ where
12611261
}
12621262
}
12631263

1264-
impl<STREAM, PERIPHERAL, DIR, BUF, const CHANNEL: u8>
1265-
Transfer<STREAM, PERIPHERAL, DIR, BUF, CHANNEL>
1264+
impl<STREAM, const CHANNEL: u8, PERIPHERAL, DIR, BUF>
1265+
Transfer<STREAM, CHANNEL, PERIPHERAL, DIR, BUF>
12661266
where
12671267
STREAM: Stream,
12681268
ChannelX<CHANNEL>: Channel,
12691269
DIR: Direction,
1270-
PERIPHERAL: PeriAddress + DMASet<STREAM, DIR, CHANNEL>,
1270+
PERIPHERAL: PeriAddress + DMASet<STREAM, CHANNEL, DIR>,
12711271
{
12721272
/// Starts the transfer, the closure will be executed right after enabling the stream.
12731273
pub fn start<F>(&mut self, f: F)
@@ -1589,8 +1589,8 @@ where
15891589
}
15901590
}
15911591

1592-
impl<STREAM, PERIPHERAL, DIR, BUF, const CHANNEL: u8> Drop
1593-
for Transfer<STREAM, PERIPHERAL, DIR, BUF, CHANNEL>
1592+
impl<STREAM, const CHANNEL: u8, PERIPHERAL, DIR, BUF> Drop
1593+
for Transfer<STREAM, CHANNEL, PERIPHERAL, DIR, BUF>
15941594
where
15951595
STREAM: Stream,
15961596
PERIPHERAL: PeriAddress,

src/dma/traits.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,14 @@ pub trait Channel {}
291291
/// # Safety
292292
///
293293
/// Memory corruption might occur if this trait is implemented for an invalid combination.
294-
pub unsafe trait DMASet<STREAM, DIRECTION, const CHANNEL: u8> {}
294+
pub unsafe trait DMASet<STREAM, const CHANNEL: u8, DIRECTION> {}
295295

296296
tim_channels!(CCR1, CCR2, CCR3, CCR4, DMAR, ARR);
297297

298298
macro_rules! dma_map {
299299
($(($Stream:ty, $C:literal, $Peripheral:ty, $Dir:ty)),+ $(,)*) => {
300300
$(
301-
unsafe impl DMASet<$Stream, $Dir, $C> for $Peripheral {}
301+
unsafe impl DMASet<$Stream, $C, $Dir> for $Peripheral {}
302302
)+
303303
};
304304
}

src/i2s.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,10 @@ mod dma {
275275
}
276276

277277
/// DMA is available for I2S based on the underlying implementations for SPI
278-
unsafe impl<SPI, PINS, MODE, STREAM, DIR, const CHANNEL: u8> DMASet<STREAM, DIR, CHANNEL>
278+
unsafe impl<SPI, PINS, MODE, STREAM, const CHANNEL: u8, DIR> DMASet<STREAM, CHANNEL, DIR>
279279
for stm32_i2s_v12x::I2s<I2s<SPI, PINS>, MODE>
280280
where
281-
SPI: DMASet<STREAM, DIR, CHANNEL>,
281+
SPI: DMASet<STREAM, CHANNEL, DIR>,
282282
{
283283
}
284284
}

0 commit comments

Comments
 (0)