Skip to content

Commit a3f100e

Browse files
authored
Merge pull request #834 from stm32-rs/periph
generic Periph
2 parents 4e96a6b + 4215a5a commit a3f100e

File tree

10 files changed

+19
-95
lines changed

10 files changed

+19
-95
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
- Implement `Ptr`, `Sealed`, `Steal` for generic `Periph`
1011
- Unmacro `Adc`
1112
- Use `write` instead of `modify` to clear flags
1213
- Bump `stm32f4-staging` to 0.18, update other dependencies

src/dma/traits.rs

-16
Original file line numberDiff line numberDiff line change
@@ -310,22 +310,6 @@ pub trait Instance:
310310
impl Instance for DMA1 {}
311311
impl Instance for DMA2 {}
312312

313-
impl crate::Ptr for DMA1 {
314-
type RB = DMARegisterBlock;
315-
#[inline(always)]
316-
fn ptr() -> *const Self::RB {
317-
Self::ptr()
318-
}
319-
}
320-
321-
impl crate::Ptr for DMA2 {
322-
type RB = DMARegisterBlock;
323-
#[inline(always)]
324-
fn ptr() -> *const Self::RB {
325-
Self::ptr()
326-
}
327-
}
328-
329313
/// A trait for marker tha represent Channel of a DMA stream.
330314
pub trait Channel {
331315
const VALUE: DmaChannel;

src/fmpi2c.rs

-8
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ macro_rules! i2c {
3535
rcc.dckcfgr2().modify(|_, w| w.$i2csel().hsi());
3636
}
3737
}
38-
39-
impl crate::Ptr for $I2C {
40-
type RB = i2c1::RegisterBlock;
41-
#[inline(always)]
42-
fn ptr() -> *const Self::RB {
43-
Self::ptr()
44-
}
45-
}
4638
};
4739
}
4840

src/i2c.rs

-7
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,6 @@ macro_rules! i2c {
9090
pub type $I2c = I2c<$I2C>;
9191

9292
impl Instance for $I2C {}
93-
94-
impl crate::Ptr for $I2C {
95-
type RB = i2c1::RegisterBlock;
96-
fn ptr() -> *const Self::RB {
97-
Self::ptr()
98-
}
99-
}
10093
};
10194
}
10295

src/lib.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub use stm32f4::stm32f469 as pac;
8080
#[cfg(feature = "stm32f479")]
8181
/// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the stm32f469 peripherals.
8282
pub use stm32f4::stm32f469 as pac;
83+
use stm32f4::Periph;
8384

8485
// Enable use of interrupt macro
8586
pub use crate::pac::interrupt;
@@ -202,14 +203,23 @@ pub trait Listen {
202203
}
203204
}
204205

205-
pub trait Ptr {
206+
impl<RB, const A: usize> Sealed for Periph<RB, A> {}
207+
208+
pub trait Ptr: Sealed {
206209
/// RegisterBlock structure
207210
type RB;
208211
/// Return the pointer to the register block
209212
fn ptr() -> *const Self::RB;
210213
}
211214

212-
pub trait Steal {
215+
impl<RB, const A: usize> Ptr for Periph<RB, A> {
216+
type RB = RB;
217+
fn ptr() -> *const Self::RB {
218+
Self::ptr()
219+
}
220+
}
221+
222+
pub trait Steal: Sealed {
213223
/// Steal an instance of this peripheral
214224
///
215225
/// # Safety
@@ -226,6 +236,12 @@ pub trait Steal {
226236
unsafe fn steal() -> Self;
227237
}
228238

239+
impl<RB, const A: usize> Steal for Periph<RB, A> {
240+
unsafe fn steal() -> Self {
241+
Self::steal()
242+
}
243+
}
244+
229245
#[allow(unused)]
230246
const fn max_u32(first: u32, second: u32) -> u32 {
231247
if second > first {

src/rcc/f4/enable.rs

-9
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ macro_rules! bus_reset {
6868
macro_rules! bus {
6969
($($PER:ident => ($busX:ty, $bit:literal),)+) => {
7070
$(
71-
impl crate::Sealed for crate::pac::$PER {}
7271
impl RccBus for crate::pac::$PER {
7372
type Bus = $busX;
7473
}
@@ -79,8 +78,6 @@ macro_rules! bus {
7978
}
8079
}
8180

82-
#[cfg(feature = "quadspi")]
83-
impl crate::Sealed for crate::pac::QUADSPI {}
8481
#[cfg(feature = "quadspi")]
8582
impl RccBus for crate::pac::QUADSPI {
8683
type Bus = AHB3;
@@ -148,8 +145,6 @@ bus! {
148145

149146
// TODO: fix absent ahb3lpenr
150147
#[cfg(feature = "fsmc")]
151-
impl crate::Sealed for crate::pac::FSMC {}
152-
#[cfg(feature = "fsmc")]
153148
impl RccBus for crate::pac::FSMC {
154149
type Bus = AHB3;
155150
}
@@ -250,8 +245,6 @@ bus! {
250245
ADC1 => (APB2, 8),
251246
}
252247

253-
#[cfg(feature = "adc2")]
254-
impl crate::Sealed for crate::pac::ADC2 {}
255248
#[cfg(feature = "adc2")]
256249
impl RccBus for crate::pac::ADC2 {
257250
type Bus = APB2;
@@ -263,8 +256,6 @@ bus_lpenable!(ADC2 => 9);
263256
#[cfg(feature = "adc2")]
264257
bus_reset!(ADC2 => 8);
265258

266-
#[cfg(feature = "adc3")]
267-
impl crate::Sealed for crate::pac::ADC3 {}
268259
#[cfg(feature = "adc3")]
269260
impl RccBus for crate::pac::ADC3 {
270261
type Bus = APB2;

src/sai.rs

-13
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,6 @@ macro_rules! sai_impl {
237237
pub type $SAIB = SAIB<$SAI>;
238238

239239
impl Instance for $SAI {}
240-
241-
impl crate::Ptr for $SAI {
242-
type RB = sai::RegisterBlock;
243-
fn ptr() -> *const Self::RB {
244-
Self::ptr()
245-
}
246-
}
247-
248-
impl crate::Steal for $SAI {
249-
unsafe fn steal() -> Self {
250-
Self::steal()
251-
}
252-
}
253240
};
254241
}
255242

src/serial.rs

-28
Original file line numberDiff line numberDiff line change
@@ -395,20 +395,6 @@ macro_rules! halUsart {
395395
pub type $Rx<WORD = u8> = Rx<$USART, WORD>;
396396

397397
impl Instance for $USART {}
398-
399-
impl crate::Ptr for $USART {
400-
type RB = crate::pac::usart1::RegisterBlock;
401-
402-
fn ptr() -> *const Self::RB {
403-
Self::ptr()
404-
}
405-
}
406-
407-
impl crate::Steal for $USART {
408-
unsafe fn steal() -> Self {
409-
Self::steal()
410-
}
411-
}
412398
};
413399
}
414400
pub(crate) use halUsart;
@@ -428,20 +414,6 @@ macro_rules! halUart {
428414
pub type $Rx<WORD = u8> = Rx<$UART, WORD>;
429415

430416
impl Instance for $UART {}
431-
432-
impl crate::Ptr for $UART {
433-
type RB = crate::pac::uart4::RegisterBlock;
434-
435-
fn ptr() -> *const Self::RB {
436-
Self::ptr()
437-
}
438-
}
439-
440-
impl crate::Steal for $UART {
441-
unsafe fn steal() -> Self {
442-
Self::steal()
443-
}
444-
}
445417
};
446418
}
447419

src/spi.rs

-7
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,6 @@ macro_rules! spi {
228228
pub type $SpiSlave<const BIDI: bool = false, W = u8> = SpiSlave<$SPI, BIDI, W>;
229229

230230
impl Instance for $SPI {}
231-
232-
impl crate::Ptr for $SPI {
233-
type RB = spi1::RegisterBlock;
234-
fn ptr() -> *const Self::RB {
235-
Self::ptr()
236-
}
237-
}
238231
};
239232
}
240233

src/timer.rs

-5
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,6 @@ macro_rules! hal {
420420
$(m: $timbase:ident,)?
421421
]) => {
422422
impl Instance for $TIM { }
423-
impl crate::Steal for $TIM {
424-
unsafe fn steal() -> Self {
425-
Self::steal()
426-
}
427-
}
428423
pub type $Timer = Timer<$TIM>;
429424

430425
impl General for $TIM {

0 commit comments

Comments
 (0)