diff --git a/CHANGELOG.md b/CHANGELOG.md index db6be3c8..71e68a02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +- Implement `Ptr`, `Sealed`, `Steal` for generic `Periph` - Unmacro `Adc` - Use `write` instead of `modify` to clear flags - Bump `stm32f4-staging` to 0.18, update other dependencies diff --git a/src/dma/traits.rs b/src/dma/traits.rs index 1d74e5f6..a6b461a7 100644 --- a/src/dma/traits.rs +++ b/src/dma/traits.rs @@ -310,22 +310,6 @@ pub trait Instance: impl Instance for DMA1 {} impl Instance for DMA2 {} -impl crate::Ptr for DMA1 { - type RB = DMARegisterBlock; - #[inline(always)] - fn ptr() -> *const Self::RB { - Self::ptr() - } -} - -impl crate::Ptr for DMA2 { - type RB = DMARegisterBlock; - #[inline(always)] - fn ptr() -> *const Self::RB { - Self::ptr() - } -} - /// A trait for marker tha represent Channel of a DMA stream. pub trait Channel { const VALUE: DmaChannel; diff --git a/src/fmpi2c.rs b/src/fmpi2c.rs index c8a48b23..c581258d 100644 --- a/src/fmpi2c.rs +++ b/src/fmpi2c.rs @@ -35,14 +35,6 @@ macro_rules! i2c { rcc.dckcfgr2().modify(|_, w| w.$i2csel().hsi()); } } - - impl crate::Ptr for $I2C { - type RB = i2c1::RegisterBlock; - #[inline(always)] - fn ptr() -> *const Self::RB { - Self::ptr() - } - } }; } diff --git a/src/i2c.rs b/src/i2c.rs index 48273b45..eaa664d8 100644 --- a/src/i2c.rs +++ b/src/i2c.rs @@ -90,13 +90,6 @@ macro_rules! i2c { pub type $I2c = I2c<$I2C>; impl Instance for $I2C {} - - impl crate::Ptr for $I2C { - type RB = i2c1::RegisterBlock; - fn ptr() -> *const Self::RB { - Self::ptr() - } - } }; } diff --git a/src/lib.rs b/src/lib.rs index 75ddecb8..1f12937f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -80,6 +80,7 @@ pub use stm32f4::stm32f469 as pac; #[cfg(feature = "stm32f479")] /// Re-export of the [svd2rust](https://crates.io/crates/svd2rust) auto-generated API for the stm32f469 peripherals. pub use stm32f4::stm32f469 as pac; +use stm32f4::Periph; // Enable use of interrupt macro pub use crate::pac::interrupt; @@ -202,14 +203,23 @@ pub trait Listen { } } -pub trait Ptr { +impl Sealed for Periph {} + +pub trait Ptr: Sealed { /// RegisterBlock structure type RB; /// Return the pointer to the register block fn ptr() -> *const Self::RB; } -pub trait Steal { +impl Ptr for Periph { + type RB = RB; + fn ptr() -> *const Self::RB { + Self::ptr() + } +} + +pub trait Steal: Sealed { /// Steal an instance of this peripheral /// /// # Safety @@ -226,6 +236,12 @@ pub trait Steal { unsafe fn steal() -> Self; } +impl Steal for Periph { + unsafe fn steal() -> Self { + Self::steal() + } +} + #[allow(unused)] const fn max_u32(first: u32, second: u32) -> u32 { if second > first { diff --git a/src/rcc/f4/enable.rs b/src/rcc/f4/enable.rs index 2fb6000a..433f3cc8 100644 --- a/src/rcc/f4/enable.rs +++ b/src/rcc/f4/enable.rs @@ -68,7 +68,6 @@ macro_rules! bus_reset { macro_rules! bus { ($($PER:ident => ($busX:ty, $bit:literal),)+) => { $( - impl crate::Sealed for crate::pac::$PER {} impl RccBus for crate::pac::$PER { type Bus = $busX; } @@ -79,8 +78,6 @@ macro_rules! bus { } } -#[cfg(feature = "quadspi")] -impl crate::Sealed for crate::pac::QUADSPI {} #[cfg(feature = "quadspi")] impl RccBus for crate::pac::QUADSPI { type Bus = AHB3; @@ -148,8 +145,6 @@ bus! { // TODO: fix absent ahb3lpenr #[cfg(feature = "fsmc")] -impl crate::Sealed for crate::pac::FSMC {} -#[cfg(feature = "fsmc")] impl RccBus for crate::pac::FSMC { type Bus = AHB3; } @@ -250,8 +245,6 @@ bus! { ADC1 => (APB2, 8), } -#[cfg(feature = "adc2")] -impl crate::Sealed for crate::pac::ADC2 {} #[cfg(feature = "adc2")] impl RccBus for crate::pac::ADC2 { type Bus = APB2; @@ -263,8 +256,6 @@ bus_lpenable!(ADC2 => 9); #[cfg(feature = "adc2")] bus_reset!(ADC2 => 8); -#[cfg(feature = "adc3")] -impl crate::Sealed for crate::pac::ADC3 {} #[cfg(feature = "adc3")] impl RccBus for crate::pac::ADC3 { type Bus = APB2; diff --git a/src/sai.rs b/src/sai.rs index 7a6bfa21..343f7fb6 100644 --- a/src/sai.rs +++ b/src/sai.rs @@ -237,19 +237,6 @@ macro_rules! sai_impl { pub type $SAIB = SAIB<$SAI>; impl Instance for $SAI {} - - impl crate::Ptr for $SAI { - type RB = sai::RegisterBlock; - fn ptr() -> *const Self::RB { - Self::ptr() - } - } - - impl crate::Steal for $SAI { - unsafe fn steal() -> Self { - Self::steal() - } - } }; } diff --git a/src/serial.rs b/src/serial.rs index 0d8f62b0..d3b3f9a5 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -395,20 +395,6 @@ macro_rules! halUsart { pub type $Rx = Rx<$USART, WORD>; impl Instance for $USART {} - - impl crate::Ptr for $USART { - type RB = crate::pac::usart1::RegisterBlock; - - fn ptr() -> *const Self::RB { - Self::ptr() - } - } - - impl crate::Steal for $USART { - unsafe fn steal() -> Self { - Self::steal() - } - } }; } pub(crate) use halUsart; @@ -428,20 +414,6 @@ macro_rules! halUart { pub type $Rx = Rx<$UART, WORD>; impl Instance for $UART {} - - impl crate::Ptr for $UART { - type RB = crate::pac::uart4::RegisterBlock; - - fn ptr() -> *const Self::RB { - Self::ptr() - } - } - - impl crate::Steal for $UART { - unsafe fn steal() -> Self { - Self::steal() - } - } }; } diff --git a/src/spi.rs b/src/spi.rs index 6b3f52e7..99f8eae9 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -228,13 +228,6 @@ macro_rules! spi { pub type $SpiSlave = SpiSlave<$SPI, BIDI, W>; impl Instance for $SPI {} - - impl crate::Ptr for $SPI { - type RB = spi1::RegisterBlock; - fn ptr() -> *const Self::RB { - Self::ptr() - } - } }; } diff --git a/src/timer.rs b/src/timer.rs index f5b2e619..89c425dc 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -420,11 +420,6 @@ macro_rules! hal { $(m: $timbase:ident,)? ]) => { impl Instance for $TIM { } - impl crate::Steal for $TIM { - unsafe fn steal() -> Self { - Self::steal() - } - } pub type $Timer = Timer<$TIM>; impl General for $TIM {