Skip to content

Commit a1935a3

Browse files
bors[bot]burrbull
andauthored
Merge #328
328: simplify alternate mode r=therealprof a=burrbull Co-authored-by: Andrey Zgarbul <zgarbul.andrey@gmail.com>
2 parents c7b4748 + 83534f0 commit a1935a3

File tree

14 files changed

+1014
-1098
lines changed

14 files changed

+1014
-1098
lines changed

CHANGELOG.md

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

1010
### Added
1111

12+
- Instead of `Alternate<AF1>` use just `Alternate<1>`.
1213
- `PinState` and `get/set_state`.
1314
- Inherent methods for infallible digital operations.
1415
- Generic `into_alternate` and `into_alternate_open_drain`. Non-generic ones are deprecated

examples/i2s-audio-out-dma.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@ type I2sDmaTransfer = Transfer<
216216
I2s<
217217
SPI3,
218218
(
219-
PA4<Alternate<stm32f4xx_hal::gpio::AF6>>,
220-
PC10<Alternate<stm32f4xx_hal::gpio::AF6>>,
221-
PC7<Alternate<stm32f4xx_hal::gpio::AF6>>,
222-
PC12<Alternate<stm32f4xx_hal::gpio::AF6>>,
219+
PA4<Alternate<6>>,
220+
PC10<Alternate<6>>,
221+
PC7<Alternate<6>>,
222+
PC12<Alternate<6>>,
223223
),
224224
>,
225225
TransmitMode<Data16Frame16>,

src/can.rs

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub trait Pins: sealed::Sealed {
1818
/// The alternate function number can be specified after each pin name. If not specified, both
1919
/// default to AF9.
2020
macro_rules! pins {
21-
($($PER:ident => ($tx:ident<$txaf:ident>, $rx:ident<$rxaf:ident>),)+) => {
21+
($($PER:ident => ($tx:ident<$txaf:literal>, $rx:ident<$rxaf:literal>),)+) => {
2222
$(
2323
impl crate::can::sealed::Sealed for ($tx<crate::gpio::Alternate<$txaf>>, $rx<crate::gpio::Alternate<$rxaf>>) {}
2424
impl crate::can::Pins for ($tx<crate::gpio::Alternate<$txaf>>, $rx<crate::gpio::Alternate<$rxaf>>) {
@@ -27,7 +27,7 @@ macro_rules! pins {
2727
)+
2828
};
2929
($($PER:ident => ($tx:ident, $rx:ident),)+) => {
30-
pins! { $($PER => ($tx<crate::gpio::AF9>, $rx<crate::gpio::AF9>),)+ }
30+
pins! { $($PER => ($tx<9>, $rx<9>),)+ }
3131
}
3232
}
3333

@@ -36,56 +36,43 @@ mod common_pins {
3636
gpioa::{PA11, PA12},
3737
gpiob::{PB12, PB13, PB5, PB6},
3838
gpiod::{PD0, PD1},
39-
AF9,
4039
};
4140
use crate::pac::{CAN1, CAN2};
4241
// All STM32F4 models with CAN support these pins
4342
pins! {
44-
CAN1 => (PA12<AF9>, PA11<AF9>),
45-
CAN1 => (PD1<AF9>, PD0<AF9>),
46-
CAN2 => (PB13<AF9>, PB12<AF9>),
47-
CAN2 => (PB6<AF9>, PB5<AF9>),
43+
CAN1 => (PA12<9>, PA11<9>),
44+
CAN1 => (PD1<9>, PD0<9>),
45+
CAN2 => (PB13<9>, PB12<9>),
46+
CAN2 => (PB6<9>, PB5<9>),
4847
}
4948
}
5049

5150
#[cfg(any(feature = "stm32f412", feature = "stm32f413", feature = "stm32f423"))]
5251
mod pb9_pb8_af8 {
53-
use crate::gpio::{
54-
gpiob::{PB8, PB9},
55-
AF8,
56-
};
52+
use crate::gpio::gpiob::{PB8, PB9};
5753
use crate::pac::CAN1;
58-
pins! { CAN1 => (PB9<AF8>, PB8<AF8>), }
54+
pins! { CAN1 => (PB9<8>, PB8<8>), }
5955
}
6056

6157
#[cfg(any(feature = "can1", feature = "can2",))]
6258
mod pb9_pb8_af9 {
63-
use crate::gpio::{
64-
gpiob::{PB8, PB9},
65-
AF9,
66-
};
59+
use crate::gpio::gpiob::{PB8, PB9};
6760
use crate::pac::CAN1;
68-
pins! { CAN1 => (PB9<AF9>, PB8<AF9>), }
61+
pins! { CAN1 => (PB9<9>, PB8<9>), }
6962
}
7063

7164
#[cfg(any(feature = "stm32f412", feature = "stm32f413", feature = "stm32f423"))]
7265
mod pg1_pg0 {
73-
use crate::gpio::{
74-
gpiog::{PG0, PG1},
75-
AF9,
76-
};
66+
use crate::gpio::gpiog::{PG0, PG1};
7767
use crate::pac::CAN1;
78-
pins! { CAN1 => (PG1<AF9>, PG0<AF9>), }
68+
pins! { CAN1 => (PG1<9>, PG0<9>), }
7969
}
8070

8171
#[cfg(any(feature = "stm32f412", feature = "stm32f413", feature = "stm32f423"))]
8272
mod pg12_pg11 {
83-
use crate::gpio::{
84-
gpiog::{PG11, PG12},
85-
AF9,
86-
};
73+
use crate::gpio::gpiog::{PG11, PG12};
8774
use crate::pac::CAN2;
88-
pins! { CAN2 => (PG12<AF9>, PG11<AF9>), }
75+
pins! { CAN2 => (PG12<9>, PG11<9>), }
8976
}
9077

9178
#[cfg(any(
@@ -101,9 +88,9 @@ mod pg12_pg11 {
10188
feature = "stm32f479"
10289
))]
10390
mod ph13_pi9 {
104-
use crate::gpio::{gpioh::PH13, gpioi::PI9, AF9};
91+
use crate::gpio::{gpioh::PH13, gpioi::PI9};
10592
use crate::pac::CAN1;
106-
pins! { CAN1 => (PH13<AF9>, PI9<AF9>), }
93+
pins! { CAN1 => (PH13<9>, PI9<9>), }
10794
}
10895

10996
/// Pins and definitions for models with a third CAN peripheral
@@ -113,12 +100,11 @@ mod can3 {
113100
use crate::gpio::{
114101
gpioa::{PA15, PA8},
115102
gpiob::{PB3, PB4},
116-
AF11,
117103
};
118104
use crate::pac::CAN3;
119105
pins! {
120-
CAN3 => (PA15<AF11>, PA8<AF11>),
121-
CAN3 => (PB4<AF11>, PB3<AF11>),
106+
CAN3 => (PA15<11>, PA8<11>),
107+
CAN3 => (PB4<11>, PB3<11>),
122108
}
123109

124110
unsafe impl bxcan::Instance for Can<CAN3> {

src/fsmc_lcd/pins.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -281,15 +281,15 @@ impl sealed::Conjure for (Lcd<SubBank1>, Lcd<SubBank2>, Lcd<SubBank3>, Lcd<SubBa
281281
/// # Example types that implement `ChipSelectPins`
282282
///
283283
/// Wrapped single pins:
284-
/// * `ChipSelect1<PD7<Alternate<AF12>>>`
285-
/// * `ChipSelect2<PG9<Alternate<AF12>>>`
286-
/// * `ChipSelect3<PG10<Alternate<AF12>>>`
287-
/// * `ChipSelect4<PG12<Alternate<AF12>>>`
284+
/// * `ChipSelect1<PD7<Alternate<12>>>`
285+
/// * `ChipSelect2<PG9<Alternate<12>>>`
286+
/// * `ChipSelect3<PG10<Alternate<12>>>`
287+
/// * `ChipSelect4<PG12<Alternate<12>>>`
288288
///
289289
/// Tuples of wrapped pins:
290-
/// * `(ChipSelect1<PD7<Alternate<AF12>>>, ChipSelect2<PG9<Alternate<AF12>>>)`
291-
/// * `(ChipSelect1<PD7<Alternate<AF12>>>, ChipSelect4<PG4<Alternate<AF12>>>)`
292-
/// * `(ChipSelect1<PD7<Alternate<AF12>>>, ChipSelect2<PG9<Alternate<AF12>>>, ChipSelect3<PG10<Alternate<AF12>>>, ChipSelect4<PG12<Alternate<AF12>>>)`
290+
/// * `(ChipSelect1<PD7<Alternate<12>>>, ChipSelect2<PG9<Alternate<12>>>)`
291+
/// * `(ChipSelect1<PD7<Alternate<12>>>, ChipSelect4<PG4<Alternate<12>>>)`
292+
/// * `(ChipSelect1<PD7<Alternate<12>>>, ChipSelect2<PG9<Alternate<12>>>, ChipSelect3<PG10<Alternate<12>>>, ChipSelect4<PG12<Alternate<12>>>)`
293293
pub trait ChipSelectPins: sealed::Sealed {
294294
/// One, two, three, or four `Lcd<_>` objects associated with the sub-bank(s) that these pin(s)
295295
/// control
@@ -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, AF12};
608+
use crate::gpio::Alternate;
609609

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

613613
impl PinD2 for PD0<FmcAlternate> {}
614614
impl PinD3 for PD1<FmcAlternate> {}
@@ -687,7 +687,7 @@ mod common_pins {
687687
impl Sealed for PG12<FmcAlternate> {}
688688
impl PinAddress for PG13<FmcAlternate> {}
689689
impl Sealed for PG13<FmcAlternate> {}
690-
// PG14<Alternate<AF12> can be used as address 25 (A25), but that pin is not available here.
690+
// PG14<Alternate<12> can be used as address 25 (A25), but that pin is not available here.
691691
// Because external addresses are in units of 16 bits, external address line 25 can never
692692
// be high. The internal memory address would overflow into the next sub-bank.
693693

@@ -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, AF10, AF12};
728+
use crate::gpio::Alternate;
729729

730730
// Most FSMC/FMC pins use AF12, but a few use AF10
731-
type FmcAlternate = Alternate<AF12>;
731+
type FmcAlternate = Alternate<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<AF10>> {}
738+
impl PinD0 for PB14<Alternate<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<AF10>> {}
746-
impl PinD2 for PC11<Alternate<AF10>> {}
747-
impl PinD3 for PC12<Alternate<AF10>> {}
748-
impl PinWriteEnable for PD2<Alternate<AF10>> {}
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>> {}
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<AF10>> {}
756+
impl Sealed for PB14<Alternate<10>> {}
757757
impl Sealed for PC2<FmcAlternate> {}
758758
impl Sealed for PC5<FmcAlternate> {}
759-
impl Sealed for PC6<Alternate<AF10>> {}
760-
impl Sealed for PC11<Alternate<AF10>> {}
761-
impl Sealed for PC12<Alternate<AF10>> {}
762-
impl Sealed for PD2<Alternate<AF10>> {}
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>> {}
763763
}

0 commit comments

Comments
 (0)