Skip to content

Commit c911651

Browse files
bors[bot]burrbull
andauthored
Merge #383
383: generic Alternate r=therealprof a=burrbull Co-authored-by: Andrey Zgarbul <[email protected]>
2 parents e3eb744 + 88204f5 commit c911651

File tree

15 files changed

+147
-143
lines changed

15 files changed

+147
-143
lines changed

CHANGELOG.md

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

88
## [Unreleased]
99

10+
### Changed
11+
12+
- [breaking-change] Make `Alternate` generic over `Otype` instead of separate `Alternate` and `AlternateOD` [#372]
13+
1014
### Added
1115

1216
- `count_down` constructor for `Timer` -> `CountDownTimer` without start [#382]

examples/i2s-audio-out-dma.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ use stm32f4xx_hal::delay::Delay;
5252
use stm32f4xx_hal::dma::config::DmaConfig;
5353
use stm32f4xx_hal::dma::MemoryToPeripheral;
5454
use stm32f4xx_hal::dma::{Stream5, StreamsTuple, Transfer};
55-
use stm32f4xx_hal::gpio::gpioa::PA4;
56-
use stm32f4xx_hal::gpio::gpioc::{PC10, PC12, PC7};
57-
use stm32f4xx_hal::gpio::Alternate;
58-
use stm32f4xx_hal::gpio::AF6;
55+
use stm32f4xx_hal::gpio::{
56+
gpioa::PA4,
57+
gpioc::{PC10, PC12, PC7},
58+
Alternate, PushPull,
59+
};
5960
use stm32f4xx_hal::i2c::I2c;
6061
use stm32f4xx_hal::i2s::I2s;
6162
use stm32f4xx_hal::pac::{interrupt, Interrupt};
@@ -216,10 +217,10 @@ type I2sDmaTransfer = Transfer<
216217
I2s<
217218
SPI3,
218219
(
219-
PA4<Alternate<AF6>>,
220-
PC10<Alternate<AF6>>,
221-
PC7<Alternate<AF6>>,
222-
PC12<Alternate<AF6>>,
220+
PA4<Alternate<PushPull, 6>>,
221+
PC10<Alternate<PushPull, 6>>,
222+
PC7<Alternate<PushPull, 6>>,
223+
PC12<Alternate<PushPull, 6>>,
223224
),
224225
>,
225226
TransmitMode<Data16Frame16>,

src/can.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ pub trait Pins: sealed::Sealed {
2020
macro_rules! pins {
2121
($($PER:ident => ($tx:ident<$txaf:literal>, $rx:ident<$rxaf:literal>),)+) => {
2222
$(
23-
impl crate::can::sealed::Sealed for ($tx<crate::gpio::Alternate<$txaf>>, $rx<crate::gpio::Alternate<$rxaf>>) {}
24-
impl crate::can::Pins for ($tx<crate::gpio::Alternate<$txaf>>, $rx<crate::gpio::Alternate<$rxaf>>) {
23+
impl crate::can::sealed::Sealed for ($tx<crate::gpio::Alternate<crate::gpio::PushPull, $txaf>>, $rx<crate::gpio::Alternate<crate::gpio::PushPull, $rxaf>>) {}
24+
impl crate::can::Pins for ($tx<crate::gpio::Alternate<crate::gpio::PushPull, $txaf>>, $rx<crate::gpio::Alternate<crate::gpio::PushPull, $rxaf>>) {
2525
type Instance = $PER;
2626
}
2727
)+

src/fmpi2c.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use core::ops::Deref;
22
use embedded_hal::blocking::i2c::{Read, Write, WriteRead};
33

4-
use crate::gpio::{gpiob, gpioc, gpiod, gpiof, Const, SetAlternateOD};
4+
use crate::gpio::{gpiob, gpioc, gpiod, gpiof, Const, OpenDrain, SetAlternate};
55
use crate::i2c::{Error, PinScl, PinSda};
66
use crate::pac::{fmpi2c1, FMPI2C1, RCC};
77
use crate::rcc::{Enable, Reset};
@@ -87,8 +87,8 @@ pin!(PinScl<FMPI2C1> for gpiof::PF15<4>);
8787

8888
impl<SCL, SDA, const SCLA: u8, const SDAA: u8> FMPI2c<FMPI2C1, (SCL, SDA)>
8989
where
90-
SCL: PinScl<FMPI2C1, A = Const<SCLA>> + SetAlternateOD<SCLA>,
91-
SDA: PinSda<FMPI2C1, A = Const<SDAA>> + SetAlternateOD<SDAA>,
90+
SCL: PinScl<FMPI2C1, A = Const<SCLA>> + SetAlternate<OpenDrain, SCLA>,
91+
SDA: PinSda<FMPI2C1, A = Const<SDAA>> + SetAlternate<OpenDrain, SDAA>,
9292
{
9393
pub fn new<M: Into<FmpMode>>(i2c: FMPI2C1, mut pins: (SCL, SDA), mode: M) -> Self {
9494
unsafe {

src/fsmc_lcd/pins.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -605,10 +605,10 @@ mod common_pins {
605605
};
606606
use crate::gpio::gpiof::{PF0, PF1, PF12, PF13, PF14, PF15, PF2, PF3, PF4, PF5};
607607
use crate::gpio::gpiog::{PG0, PG1, PG10, PG12, PG13, PG2, PG3, PG4, PG5, PG9};
608-
use crate::gpio::Alternate;
608+
use crate::gpio::{Alternate, PushPull};
609609

610610
// All FSMC/FMC pins use AF12
611-
type FmcAlternate = Alternate<12>;
611+
type FmcAlternate = Alternate<PushPull, 12>;
612612

613613
impl PinD2 for PD0<FmcAlternate> {}
614614
impl PinD3 for PD1<FmcAlternate> {}
@@ -725,39 +725,39 @@ mod extra_pins {
725725
use crate::gpio::gpiob::{PB12, PB14};
726726
use crate::gpio::gpioc::{PC11, PC12, PC2, PC3, PC4, PC5, PC6};
727727
use crate::gpio::gpiod::PD2;
728-
use crate::gpio::Alternate;
728+
use crate::gpio::{Alternate, PushPull};
729729

730730
// Most FSMC/FMC pins use AF12, but a few use AF10
731-
type FmcAlternate = Alternate<12>;
731+
type FmcAlternate = Alternate<PushPull, 12>;
732732

733733
impl PinD4 for PA2<FmcAlternate> {}
734734
impl PinD5 for PA3<FmcAlternate> {}
735735
impl PinD6 for PA4<FmcAlternate> {}
736736
impl PinD7 for PA5<FmcAlternate> {}
737737
impl PinD13 for PB12<FmcAlternate> {}
738-
impl PinD0 for PB14<Alternate<10>> {}
738+
impl PinD0 for PB14<Alternate<PushPull, 10>> {}
739739
impl PinWriteEnable for PC2<FmcAlternate> {}
740740
impl PinAddress for PC3<FmcAlternate> {}
741741
impl Sealed for PC3<FmcAlternate> {}
742742
impl PinChipSelect4 for PC4<FmcAlternate> {}
743743
impl Sealed for PC4<FmcAlternate> {}
744744
impl PinReadEnable for PC5<FmcAlternate> {}
745-
impl PinD1 for PC6<Alternate<10>> {}
746-
impl PinD2 for PC11<Alternate<10>> {}
747-
impl PinD3 for PC12<Alternate<10>> {}
748-
impl PinWriteEnable for PD2<Alternate<10>> {}
745+
impl PinD1 for PC6<Alternate<PushPull, 10>> {}
746+
impl PinD2 for PC11<Alternate<PushPull, 10>> {}
747+
impl PinD3 for PC12<Alternate<PushPull, 10>> {}
748+
impl PinWriteEnable for PD2<Alternate<PushPull, 10>> {}
749749

750750
// Sealed trait boilerplate
751751
impl Sealed for PA2<FmcAlternate> {}
752752
impl Sealed for PA3<FmcAlternate> {}
753753
impl Sealed for PA4<FmcAlternate> {}
754754
impl Sealed for PA5<FmcAlternate> {}
755755
impl Sealed for PB12<FmcAlternate> {}
756-
impl Sealed for PB14<Alternate<10>> {}
756+
impl Sealed for PB14<Alternate<PushPull, 10>> {}
757757
impl Sealed for PC2<FmcAlternate> {}
758758
impl Sealed for PC5<FmcAlternate> {}
759-
impl Sealed for PC6<Alternate<10>> {}
760-
impl Sealed for PC11<Alternate<10>> {}
761-
impl Sealed for PC12<Alternate<10>> {}
762-
impl Sealed for PD2<Alternate<10>> {}
759+
impl Sealed for PC6<Alternate<PushPull, 10>> {}
760+
impl Sealed for PC11<Alternate<PushPull, 10>> {}
761+
impl Sealed for PC12<Alternate<PushPull, 10>> {}
762+
impl Sealed for PD2<Alternate<PushPull, 10>> {}
763763
}

src/gpio.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
//! Each GPIO pin can be set to various modes:
2424
//!
2525
//! - **Alternate**: Pin mode required when the pin is driven by other peripherals
26-
//! - **AlternateOD**: Pin mode required when the pin is driven by other peripherals and has open drain
2726
//! - **Analog**: Analog input to be used with ADC.
2827
//! - Input
2928
//! - **PullUp**: Input connected to high with a weak pull up resistor. Will be high when nothing
@@ -56,7 +55,7 @@ use crate::pac::EXTI;
5655
use crate::syscfg::SysCfg;
5756

5857
mod convert;
59-
pub(crate) use convert::{Const, SetAlternate, SetAlternateOD};
58+
pub(crate) use convert::{Const, SetAlternate};
6059
mod partially_erased;
6160
pub use partially_erased::{PEPin, PartiallyErasedPin};
6261
mod erased;
@@ -83,10 +82,7 @@ pub trait PinExt {
8382
}
8483

8584
/// Some alternate mode (type state)
86-
pub struct Alternate<const A: u8>;
87-
88-
/// Some alternate mode in open drain configuration (type state)
89-
pub struct AlternateOD<const A: u8>;
85+
pub struct Alternate<Otype, const A: u8>(PhantomData<Otype>);
9086

9187
// Compatibility constants
9288
pub const AF0: u8 = 0;
@@ -313,7 +309,7 @@ impl<const P: char, const N: u8> Pin<Output<OpenDrain>, P, N> {
313309
}
314310
}
315311

316-
impl<const P: char, const N: u8, const A: u8> Pin<Alternate<A>, P, N> {
312+
impl<const P: char, const N: u8, const A: u8> Pin<Alternate<PushPull, A>, P, N> {
317313
/// Set pin speed
318314
pub fn set_speed(self, speed: Speed) -> Self {
319315
let offset = 2 * { N };
@@ -341,9 +337,9 @@ impl<const P: char, const N: u8, const A: u8> Pin<Alternate<A>, P, N> {
341337
}
342338
}
343339

344-
impl<const P: char, const N: u8, const A: u8> Pin<Alternate<A>, P, N> {
340+
impl<const P: char, const N: u8, const A: u8> Pin<Alternate<PushPull, A>, P, N> {
345341
/// Turns pin alternate configuration pin into open drain
346-
pub fn set_open_drain(self) -> Pin<AlternateOD<A>, P, N> {
342+
pub fn set_open_drain(self) -> Pin<Alternate<OpenDrain, A>, P, N> {
347343
let offset = { N };
348344
unsafe {
349345
(*Gpio::<P>::ptr())

0 commit comments

Comments
 (0)