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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Changed

- [breaking-change] Make `Alternate` generic over `Otype` instead of separate `Alternate` and `AlternateOD` [#372]

### Added

- `count_down` constructor for `Timer` -> `CountDownTimer` without start [#382]
Expand Down
17 changes: 9 additions & 8 deletions examples/i2s-audio-out-dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ use stm32f4xx_hal::delay::Delay;
use stm32f4xx_hal::dma::config::DmaConfig;
use stm32f4xx_hal::dma::MemoryToPeripheral;
use stm32f4xx_hal::dma::{Stream5, StreamsTuple, Transfer};
use stm32f4xx_hal::gpio::gpioa::PA4;
use stm32f4xx_hal::gpio::gpioc::{PC10, PC12, PC7};
use stm32f4xx_hal::gpio::Alternate;
use stm32f4xx_hal::gpio::AF6;
use stm32f4xx_hal::gpio::{
gpioa::PA4,
gpioc::{PC10, PC12, PC7},
Alternate, PushPull,
};
use stm32f4xx_hal::i2c::I2c;
use stm32f4xx_hal::i2s::I2s;
use stm32f4xx_hal::pac::{interrupt, Interrupt};
Expand Down Expand Up @@ -216,10 +217,10 @@ type I2sDmaTransfer = Transfer<
I2s<
SPI3,
(
PA4<Alternate<AF6>>,
PC10<Alternate<AF6>>,
PC7<Alternate<AF6>>,
PC12<Alternate<AF6>>,
PA4<Alternate<PushPull, 6>>,
PC10<Alternate<PushPull, 6>>,
PC7<Alternate<PushPull, 6>>,
PC12<Alternate<PushPull, 6>>,
),
>,
TransmitMode<Data16Frame16>,
Expand Down
4 changes: 2 additions & 2 deletions src/can.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub trait Pins: sealed::Sealed {
macro_rules! pins {
($($PER:ident => ($tx:ident<$txaf:literal>, $rx:ident<$rxaf:literal>),)+) => {
$(
impl crate::can::sealed::Sealed for ($tx<crate::gpio::Alternate<$txaf>>, $rx<crate::gpio::Alternate<$rxaf>>) {}
impl crate::can::Pins for ($tx<crate::gpio::Alternate<$txaf>>, $rx<crate::gpio::Alternate<$rxaf>>) {
impl crate::can::sealed::Sealed for ($tx<crate::gpio::Alternate<crate::gpio::PushPull, $txaf>>, $rx<crate::gpio::Alternate<crate::gpio::PushPull, $rxaf>>) {}
impl crate::can::Pins for ($tx<crate::gpio::Alternate<crate::gpio::PushPull, $txaf>>, $rx<crate::gpio::Alternate<crate::gpio::PushPull, $rxaf>>) {
type Instance = $PER;
}
)+
Expand Down
6 changes: 3 additions & 3 deletions src/fmpi2c.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::ops::Deref;
use embedded_hal::blocking::i2c::{Read, Write, WriteRead};

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

impl<SCL, SDA, const SCLA: u8, const SDAA: u8> FMPI2c<FMPI2C1, (SCL, SDA)>
where
SCL: PinScl<FMPI2C1, A = Const<SCLA>> + SetAlternateOD<SCLA>,
SDA: PinSda<FMPI2C1, A = Const<SDAA>> + SetAlternateOD<SDAA>,
SCL: PinScl<FMPI2C1, A = Const<SCLA>> + SetAlternate<OpenDrain, SCLA>,
SDA: PinSda<FMPI2C1, A = Const<SDAA>> + SetAlternate<OpenDrain, SDAA>,
{
pub fn new<M: Into<FmpMode>>(i2c: FMPI2C1, mut pins: (SCL, SDA), mode: M) -> Self {
unsafe {
Expand Down
28 changes: 14 additions & 14 deletions src/fsmc_lcd/pins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,10 @@ mod common_pins {
};
use crate::gpio::gpiof::{PF0, PF1, PF12, PF13, PF14, PF15, PF2, PF3, PF4, PF5};
use crate::gpio::gpiog::{PG0, PG1, PG10, PG12, PG13, PG2, PG3, PG4, PG5, PG9};
use crate::gpio::Alternate;
use crate::gpio::{Alternate, PushPull};

// All FSMC/FMC pins use AF12
type FmcAlternate = Alternate<12>;
type FmcAlternate = Alternate<PushPull, 12>;

impl PinD2 for PD0<FmcAlternate> {}
impl PinD3 for PD1<FmcAlternate> {}
Expand Down Expand Up @@ -725,39 +725,39 @@ mod extra_pins {
use crate::gpio::gpiob::{PB12, PB14};
use crate::gpio::gpioc::{PC11, PC12, PC2, PC3, PC4, PC5, PC6};
use crate::gpio::gpiod::PD2;
use crate::gpio::Alternate;
use crate::gpio::{Alternate, PushPull};

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

impl PinD4 for PA2<FmcAlternate> {}
impl PinD5 for PA3<FmcAlternate> {}
impl PinD6 for PA4<FmcAlternate> {}
impl PinD7 for PA5<FmcAlternate> {}
impl PinD13 for PB12<FmcAlternate> {}
impl PinD0 for PB14<Alternate<10>> {}
impl PinD0 for PB14<Alternate<PushPull, 10>> {}
impl PinWriteEnable for PC2<FmcAlternate> {}
impl PinAddress for PC3<FmcAlternate> {}
impl Sealed for PC3<FmcAlternate> {}
impl PinChipSelect4 for PC4<FmcAlternate> {}
impl Sealed for PC4<FmcAlternate> {}
impl PinReadEnable for PC5<FmcAlternate> {}
impl PinD1 for PC6<Alternate<10>> {}
impl PinD2 for PC11<Alternate<10>> {}
impl PinD3 for PC12<Alternate<10>> {}
impl PinWriteEnable for PD2<Alternate<10>> {}
impl PinD1 for PC6<Alternate<PushPull, 10>> {}
impl PinD2 for PC11<Alternate<PushPull, 10>> {}
impl PinD3 for PC12<Alternate<PushPull, 10>> {}
impl PinWriteEnable for PD2<Alternate<PushPull, 10>> {}

// Sealed trait boilerplate
impl Sealed for PA2<FmcAlternate> {}
impl Sealed for PA3<FmcAlternate> {}
impl Sealed for PA4<FmcAlternate> {}
impl Sealed for PA5<FmcAlternate> {}
impl Sealed for PB12<FmcAlternate> {}
impl Sealed for PB14<Alternate<10>> {}
impl Sealed for PB14<Alternate<PushPull, 10>> {}
impl Sealed for PC2<FmcAlternate> {}
impl Sealed for PC5<FmcAlternate> {}
impl Sealed for PC6<Alternate<10>> {}
impl Sealed for PC11<Alternate<10>> {}
impl Sealed for PC12<Alternate<10>> {}
impl Sealed for PD2<Alternate<10>> {}
impl Sealed for PC6<Alternate<PushPull, 10>> {}
impl Sealed for PC11<Alternate<PushPull, 10>> {}
impl Sealed for PC12<Alternate<PushPull, 10>> {}
impl Sealed for PD2<Alternate<PushPull, 10>> {}
}
14 changes: 5 additions & 9 deletions src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
//! Each GPIO pin can be set to various modes:
//!
//! - **Alternate**: Pin mode required when the pin is driven by other peripherals
//! - **AlternateOD**: Pin mode required when the pin is driven by other peripherals and has open drain
//! - **Analog**: Analog input to be used with ADC.
//! - Input
//! - **PullUp**: Input connected to high with a weak pull up resistor. Will be high when nothing
Expand Down Expand Up @@ -56,7 +55,7 @@ use crate::pac::EXTI;
use crate::syscfg::SysCfg;

mod convert;
pub(crate) use convert::{Const, SetAlternate, SetAlternateOD};
pub(crate) use convert::{Const, SetAlternate};
mod partially_erased;
pub use partially_erased::{PEPin, PartiallyErasedPin};
mod erased;
Expand All @@ -83,10 +82,7 @@ pub trait PinExt {
}

/// Some alternate mode (type state)
pub struct Alternate<const A: u8>;

/// Some alternate mode in open drain configuration (type state)
pub struct AlternateOD<const A: u8>;
pub struct Alternate<Otype, const A: u8>(PhantomData<Otype>);

// Compatibility constants
pub const AF0: u8 = 0;
Expand Down Expand Up @@ -313,7 +309,7 @@ impl<const P: char, const N: u8> Pin<Output<OpenDrain>, P, N> {
}
}

impl<const P: char, const N: u8, const A: u8> Pin<Alternate<A>, P, N> {
impl<const P: char, const N: u8, const A: u8> Pin<Alternate<PushPull, A>, P, N> {
/// Set pin speed
pub fn set_speed(self, speed: Speed) -> Self {
let offset = 2 * { N };
Expand Down Expand Up @@ -341,9 +337,9 @@ impl<const P: char, const N: u8, const A: u8> Pin<Alternate<A>, P, N> {
}
}

impl<const P: char, const N: u8, const A: u8> Pin<Alternate<A>, P, N> {
impl<const P: char, const N: u8, const A: u8> Pin<Alternate<PushPull, A>, P, N> {
/// Turns pin alternate configuration pin into open drain
pub fn set_open_drain(self) -> Pin<AlternateOD<A>, P, N> {
pub fn set_open_drain(self) -> Pin<Alternate<OpenDrain, A>, P, N> {
let offset = { N };
unsafe {
(*Gpio::<P>::ptr())
Expand Down
Loading