Skip to content

Commit 122f987

Browse files
committed
Tidy peripheral_target_address macro, implement for I2C123
1 parent 0d2287b commit 122f987

File tree

3 files changed

+67
-39
lines changed

3 files changed

+67
-39
lines changed

src/dma/bdma.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,8 @@ peripheral_target_address!(
672672
DMAReq::SPI6_RX_DMA,
673673
DMAReq::SPI6_TX_DMA
674674
),
675-
(pac::I2C4, rxdr, u8, P2M, DMAReq::I2C4_RX_DMA),
676-
(pac::I2C4, txdr, u8, M2P, DMAReq::I2C4_TX_DMA),
677-
(INNER: I2c<pac::I2C4>, rxdr, u8, P2M, DMAReq::I2C4_RX_DMA),
678-
(INNER: I2c<pac::I2C4>, txdr, u8, M2P, DMAReq::I2C4_TX_DMA),
675+
(HAL: I2c<pac::I2C4>, rxdr, u8, P2M, DMAReq::I2C4_RX_DMA),
676+
(HAL: I2c<pac::I2C4>, txdr, u8, M2P, DMAReq::I2C4_TX_DMA),
679677
);
680678

681679
#[cfg(not(feature = "rm0455"))]

src/dma/dma.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use super::{
1010
use core::marker::PhantomData;
1111

1212
use crate::{
13+
i2c::I2c,
1314
pac::{self, DMA1, DMA2, DMAMUX1},
1415
rcc::{rec, rec::ResetEnable},
1516
serial, spi,
@@ -923,6 +924,15 @@ peripheral_target_address!(
923924
),
924925
);
925926

927+
peripheral_target_address!(
928+
(HAL: I2c<pac::I2C1>, rxdr, u8, P2M, DMAReq::I2C1_RX_DMA),
929+
(HAL: I2c<pac::I2C1>, txdr, u8, M2P, DMAReq::I2C1_TX_DMA),
930+
(HAL: I2c<pac::I2C2>, rxdr, u8, P2M, DMAReq::I2C2_RX_DMA),
931+
(HAL: I2c<pac::I2C2>, txdr, u8, M2P, DMAReq::I2C2_TX_DMA),
932+
(HAL: I2c<pac::I2C3>, rxdr, u8, P2M, DMAReq::I2C3_RX_DMA),
933+
(HAL: I2c<pac::I2C3>, txdr, u8, M2P, DMAReq::I2C3_TX_DMA),
934+
);
935+
926936
peripheral_target_address!(
927937
(pac::SAI1, cha.dr, u32, M2P, DMAReq::SAI1A_DMA),
928938
(pac::SAI1, chb.dr, u32, P2M, DMAReq::SAI1B_DMA),

src/dma/macros.rs

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ macro_rules! peripheral_target_address {
1111
};
1212
}
1313
macro_rules! peripheral_target_instance {
14+
// PAC target
1415
(($peripheral:ty, $register:ident, $size:ty,
1516
$dir:ty $(, $mux:expr)*)) => {
1617
unsafe impl TargetAddress<$dir> for $peripheral {
@@ -26,8 +27,59 @@ macro_rules! peripheral_target_instance {
2627
}
2728
};
2829

29-
((SPI: $peripheral:ty, $rxreg:ident, $txreg:ident, [$($size:ty),+], $rxmux:expr, $txmux:expr)) => {
30-
// Access via PAC peripheral structures implies u8 sizing, as the sizing is unknown.
30+
// PAC target where register is within a channel
31+
(($peripheral:ty, $channel:ident.$register:ident, $size:ty,
32+
$dir:ty $(, $mux:expr)*)) => {
33+
unsafe impl TargetAddress<$dir> for $peripheral {
34+
#[inline(always)]
35+
fn address(&self) -> usize {
36+
&self.$channel.$register as *const _ as usize
37+
}
38+
39+
type MemSize = $size;
40+
$(
41+
const REQUEST_LINE: Option<u8> = Some($mux as u8);
42+
)*
43+
}
44+
};
45+
46+
// PAC and HAL targets, generic
47+
((HAL: $hal:ident<$peripheral:ty>, $register:ident, $size:ty,
48+
$dir:ty $(, $mux:expr)*)) => {
49+
50+
// PAC implementation
51+
unsafe impl TargetAddress<$dir> for $peripheral {
52+
#[inline(always)]
53+
fn address(&self) -> usize {
54+
&self.$register as *const _ as usize
55+
}
56+
57+
type MemSize = $size;
58+
$(
59+
const REQUEST_LINE: Option<u8> = Some($mux as u8);
60+
)*
61+
}
62+
63+
// HAL implementation
64+
unsafe impl TargetAddress<$dir> for $hal<$peripheral> {
65+
#[inline(always)]
66+
fn address(&self) -> usize {
67+
&self.inner().$register as *const _ as usize
68+
}
69+
70+
type MemSize = $size;
71+
$(
72+
const REQUEST_LINE: Option<u8> = Some($mux as u8);
73+
)*
74+
}
75+
};
76+
77+
// PAC and HAL targets for SPI peripheral
78+
((SPI: $peripheral:ty, $rxreg:ident, $txreg:ident, [$($size:ty),+],
79+
$rxmux:expr, $txmux:expr)) => {
80+
81+
// Access via PAC peripheral structures implies u8 sizing, as the sizing
82+
// is unknown.
3183
unsafe impl TargetAddress<M2P> for $peripheral {
3284
#[inline(always)]
3385
fn address(&self) -> usize {
@@ -76,6 +128,7 @@ macro_rules! peripheral_target_instance {
76128
)+
77129
};
78130

131+
// PAC and HAL targets for Serial Peripherals
79132
((SERIAL: $peripheral:ty, $rxreg:ident, $txreg:ident, $rxmux:expr, $txmux:expr)) => {
80133
unsafe impl TargetAddress<M2P> for $peripheral {
81134
#[inline(always)]
@@ -151,37 +204,4 @@ macro_rules! peripheral_target_instance {
151204
const TRBUFF: bool = true;
152205
}
153206
};
154-
155-
((INNER: $peripheral:ty, $register:ident $(($TRBUFF:ident))*, $size:ty,
156-
$dir:ty $(, $mux:expr)*)) => {
157-
unsafe impl TargetAddress<$dir> for $peripheral {
158-
#[inline(always)]
159-
fn address(&self) -> usize {
160-
&self.inner().$register as *const _ as usize
161-
}
162-
163-
type MemSize = $size;
164-
$(
165-
const REQUEST_LINE: Option<u8> = Some($mux as u8);
166-
)*
167-
$(
168-
const $TRBUFF: bool = true;
169-
)*
170-
}
171-
};
172-
173-
(($peripheral:ty, $channel:ident.$register:ident, $size:ty,
174-
$dir:ty $(, $mux:expr)*)) => {
175-
unsafe impl TargetAddress<$dir> for $peripheral {
176-
#[inline(always)]
177-
fn address(&self) -> usize {
178-
&self.$channel.$register as *const _ as usize
179-
}
180-
181-
type MemSize = $size;
182-
$(
183-
const REQUEST_LINE: Option<u8> = Some($mux as u8);
184-
)*
185-
}
186-
};
187207
}

0 commit comments

Comments
 (0)