Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 0 additions & 16 deletions src/dma/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 0 additions & 8 deletions src/fmpi2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
};
}

Expand Down
7 changes: 0 additions & 7 deletions src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
};
}

Expand Down
20 changes: 18 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -202,14 +203,23 @@ pub trait Listen {
}
}

pub trait Ptr {
impl<RB, const A: usize> Sealed for Periph<RB, A> {}

pub trait Ptr: Sealed {
/// RegisterBlock structure
type RB;
/// Return the pointer to the register block
fn ptr() -> *const Self::RB;
}

pub trait Steal {
impl<RB, const A: usize> Ptr for Periph<RB, A> {
type RB = RB;
fn ptr() -> *const Self::RB {
Self::ptr()
}
}

pub trait Steal: Sealed {
/// Steal an instance of this peripheral
///
/// # Safety
Expand All @@ -226,6 +236,12 @@ pub trait Steal {
unsafe fn steal() -> Self;
}

impl<RB, const A: usize> Steal for Periph<RB, A> {
unsafe fn steal() -> Self {
Self::steal()
}
}

#[allow(unused)]
const fn max_u32(first: u32, second: u32) -> u32 {
if second > first {
Expand Down
9 changes: 0 additions & 9 deletions src/rcc/f4/enable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
13 changes: 0 additions & 13 deletions src/sai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
};
}

Expand Down
28 changes: 0 additions & 28 deletions src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,20 +395,6 @@ macro_rules! halUsart {
pub type $Rx<WORD = u8> = 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;
Expand All @@ -428,20 +414,6 @@ macro_rules! halUart {
pub type $Rx<WORD = u8> = 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()
}
}
};
}

Expand Down
7 changes: 0 additions & 7 deletions src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,6 @@ macro_rules! spi {
pub type $SpiSlave<const BIDI: bool = false, W = u8> = SpiSlave<$SPI, BIDI, W>;

impl Instance for $SPI {}

impl crate::Ptr for $SPI {
type RB = spi1::RegisterBlock;
fn ptr() -> *const Self::RB {
Self::ptr()
}
}
};
}

Expand Down
5 changes: 0 additions & 5 deletions src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down