Skip to content

Commit afd8087

Browse files
bors[bot]Windfisch
andauthored
Merge #358
358: Allow pullup inputs and opendrain outputs r=burrbull a=Windfisch This fixes #321, #199 and extends on #118, and also fixes this issue for other peripherals that don't mind which pull-ups are configured for their inputs and whether their outputs are pushpull or open drain. This is a superset of #357 and #359. Prefer this PR. Co-authored-by: Florian Jung <flo@windfis.ch>
2 parents 82806e1 + a0e4f46 commit afd8087

File tree

6 files changed

+37
-37
lines changed

6 files changed

+37
-37
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1919
- `From<Bps>` for `serial::Config`
2020
- `From<Into<Hertz>>` for `i2c::Mode`
2121
- `exti_rtic` example
22-
- Support for OpenDrain pin configuration on SPI CLK and MOSI pins
22+
- Support for OpenDrain pin configuration on CAN, SPI, UART, PWM output pins
2323
- LSB/MSB bit format selection for `SPI`
2424
- Support for CAN peripherals with the `bxcan` crate
2525
- Add DAC, UART4, UART5 clock in RCC for the f103 high density line
@@ -29,6 +29,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2929
- Added DMA receive support for `SPI`
3030
- Added `release` functions to SPI DMA
3131
- Add GPIOF/GPIOG support for high/xl density lines
32+
- Allow using `Input<PullUp>` and `Input<PullDown>` for all alternate
33+
function inputs.
3234

3335
### Fixed
3436

src/can.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! ## Alternate function remapping
44
//!
55
//! TX: Alternate Push-Pull Output
6-
//! RX: Input Floating Input
6+
//! RX: Input
77
//!
88
//! ### CAN1
99
//!
@@ -25,7 +25,7 @@ use crate::gpio::gpiob::{PB12, PB13, PB5, PB6};
2525
use crate::gpio::{
2626
gpioa::{PA11, PA12},
2727
gpiob::{PB8, PB9},
28-
Alternate, Floating, Input, PushPull,
28+
Alternate, Input,
2929
};
3030
#[cfg(feature = "connectivity")]
3131
use crate::pac::CAN2;
@@ -38,8 +38,8 @@ pub trait Pins: crate::Sealed {
3838
fn remap(mapr: &mut MAPR);
3939
}
4040

41-
impl crate::Sealed for (PA12<Alternate<PushPull>>, PA11<Input<Floating>>) {}
42-
impl Pins for (PA12<Alternate<PushPull>>, PA11<Input<Floating>>) {
41+
impl<INMODE, OUTMODE> crate::Sealed for (PA12<Alternate<OUTMODE>>, PA11<Input<INMODE>>) {}
42+
impl<INMODE, OUTMODE> Pins for (PA12<Alternate<OUTMODE>>, PA11<Input<INMODE>>) {
4343
type Instance = CAN1;
4444

4545
fn remap(mapr: &mut MAPR) {
@@ -50,8 +50,8 @@ impl Pins for (PA12<Alternate<PushPull>>, PA11<Input<Floating>>) {
5050
}
5151
}
5252

53-
impl crate::Sealed for (PB9<Alternate<PushPull>>, PB8<Input<Floating>>) {}
54-
impl Pins for (PB9<Alternate<PushPull>>, PB8<Input<Floating>>) {
53+
impl<INMODE, OUTMODE> crate::Sealed for (PB9<Alternate<OUTMODE>>, PB8<Input<INMODE>>) {}
54+
impl<INMODE, OUTMODE> Pins for (PB9<Alternate<OUTMODE>>, PB8<Input<INMODE>>) {
5555
type Instance = CAN1;
5656

5757
fn remap(mapr: &mut MAPR) {
@@ -63,9 +63,9 @@ impl Pins for (PB9<Alternate<PushPull>>, PB8<Input<Floating>>) {
6363
}
6464

6565
#[cfg(feature = "connectivity")]
66-
impl crate::Sealed for (PB13<Alternate<PushPull>>, PB12<Input<Floating>>) {}
66+
impl<INMODE, OUTMODE> crate::Sealed for (PB13<Alternate<OUTMODE>>, PB12<Input<INMODE>>) {}
6767
#[cfg(feature = "connectivity")]
68-
impl Pins for (PB13<Alternate<PushPull>>, PB12<Input<Floating>>) {
68+
impl<INMODE, OUTMODE> Pins for (PB13<Alternate<OUTMODE>>, PB12<Input<INMODE>>) {
6969
type Instance = CAN2;
7070

7171
fn remap(mapr: &mut MAPR) {
@@ -74,9 +74,9 @@ impl Pins for (PB13<Alternate<PushPull>>, PB12<Input<Floating>>) {
7474
}
7575

7676
#[cfg(feature = "connectivity")]
77-
impl crate::Sealed for (PB6<Alternate<PushPull>>, PB5<Input<Floating>>) {}
77+
impl<INMODE, OUTMODE> crate::Sealed for (PB6<Alternate<OUTMODE>>, PB5<Input<INMODE>>) {}
7878
#[cfg(feature = "connectivity")]
79-
impl Pins for (PB6<Alternate<PushPull>>, PB5<Input<Floating>>) {
79+
impl<INMODE, OUTMODE> Pins for (PB6<Alternate<OUTMODE>>, PB5<Input<INMODE>>) {
8080
type Instance = CAN2;
8181

8282
fn remap(mapr: &mut MAPR) {

src/pwm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use cast::{u16, u32};
6666

6767
use crate::afio::MAPR;
6868
use crate::bb;
69-
use crate::gpio::{self, Alternate, PushPull};
69+
use crate::gpio::{self, Alternate};
7070
use crate::time::Hertz;
7171
use crate::time::U32Ext;
7272
use crate::timer::Timer;
@@ -106,10 +106,10 @@ macro_rules! pins_impl {
106106
( $( ( $($PINX:ident),+ ), ( $($TRAIT:ident),+ ), ( $($ENCHX:ident),+ ); )+ ) => {
107107
$(
108108
#[allow(unused_parens)]
109-
impl<TIM, REMAP, $($PINX,)+> Pins<REMAP, ($($ENCHX),+)> for ($($PINX),+)
109+
impl<TIM, REMAP, OUTMODE, $($PINX,)+> Pins<REMAP, ($($ENCHX),+)> for ($($PINX),+)
110110
where
111111
REMAP: Remap<Periph = TIM>,
112-
$($PINX: $TRAIT<REMAP> + gpio::PinExt<Mode=Alternate<PushPull>>,)+
112+
$($PINX: $TRAIT<REMAP> + gpio::PinExt<Mode=Alternate<OUTMODE>>,)+
113113
{
114114
$(const $ENCHX: bool = true;)+
115115
type Channels = ($(PwmChannel<TIM, $ENCHX>),+);

src/pwm_input.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::pac::TIM4;
1212
use crate::pac::{TIM2, TIM3};
1313

1414
use crate::afio::MAPR;
15-
use crate::gpio::{self, Floating, Input};
15+
use crate::gpio::{self, Input};
1616
use crate::rcc::{Clocks, GetBusFreq, RccBus};
1717
use crate::time::Hertz;
1818
use crate::timer::Timer;
@@ -21,11 +21,11 @@ pub trait Pins<REMAP> {}
2121

2222
use crate::timer::sealed::{Ch1, Ch2, Remap};
2323

24-
impl<TIM, REMAP, P1, P2> Pins<REMAP> for (P1, P2)
24+
impl<TIM, REMAP, P1, P2, MODE1, MODE2> Pins<REMAP> for (P1, P2)
2525
where
2626
REMAP: Remap<Periph = TIM>,
27-
P1: Ch1<REMAP> + gpio::PinExt<Mode = Input<Floating>>,
28-
P2: Ch2<REMAP> + gpio::PinExt<Mode = Input<Floating>>,
27+
P1: Ch1<REMAP> + gpio::PinExt<Mode = Input<MODE1>>,
28+
P2: Ch2<REMAP> + gpio::PinExt<Mode = Input<MODE2>>,
2929
{
3030
}
3131

src/serial.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use crate::gpio::gpioa::{PA10, PA2, PA3, PA9};
5252
use crate::gpio::gpiob::{PB10, PB11, PB6, PB7};
5353
use crate::gpio::gpioc::{PC10, PC11};
5454
use crate::gpio::gpiod::{PD5, PD6, PD8, PD9};
55-
use crate::gpio::{Alternate, Floating, Input, PushPull};
55+
use crate::gpio::{Alternate, Input};
5656
use crate::rcc::{Clocks, Enable, GetBusFreq, Reset};
5757
use crate::time::{Bps, U32Ext};
5858

@@ -86,31 +86,31 @@ pub trait Pins<USART> {
8686
const REMAP: u8;
8787
}
8888

89-
impl Pins<USART1> for (PA9<Alternate<PushPull>>, PA10<Input<Floating>>) {
89+
impl<INMODE, OUTMODE> Pins<USART1> for (PA9<Alternate<OUTMODE>>, PA10<Input<INMODE>>) {
9090
const REMAP: u8 = 0;
9191
}
9292

93-
impl Pins<USART1> for (PB6<Alternate<PushPull>>, PB7<Input<Floating>>) {
93+
impl<INMODE, OUTMODE> Pins<USART1> for (PB6<Alternate<OUTMODE>>, PB7<Input<INMODE>>) {
9494
const REMAP: u8 = 1;
9595
}
9696

97-
impl Pins<USART2> for (PA2<Alternate<PushPull>>, PA3<Input<Floating>>) {
97+
impl<INMODE, OUTMODE> Pins<USART2> for (PA2<Alternate<OUTMODE>>, PA3<Input<INMODE>>) {
9898
const REMAP: u8 = 0;
9999
}
100100

101-
impl Pins<USART2> for (PD5<Alternate<PushPull>>, PD6<Input<Floating>>) {
101+
impl<INMODE, OUTMODE> Pins<USART2> for (PD5<Alternate<OUTMODE>>, PD6<Input<INMODE>>) {
102102
const REMAP: u8 = 1;
103103
}
104104

105-
impl Pins<USART3> for (PB10<Alternate<PushPull>>, PB11<Input<Floating>>) {
105+
impl<INMODE, OUTMODE> Pins<USART3> for (PB10<Alternate<OUTMODE>>, PB11<Input<INMODE>>) {
106106
const REMAP: u8 = 0;
107107
}
108108

109-
impl Pins<USART3> for (PC10<Alternate<PushPull>>, PC11<Input<Floating>>) {
109+
impl<INMODE, OUTMODE> Pins<USART3> for (PC10<Alternate<OUTMODE>>, PC11<Input<INMODE>>) {
110110
const REMAP: u8 = 1;
111111
}
112112

113-
impl Pins<USART3> for (PD8<Alternate<PushPull>>, PD9<Input<Floating>>) {
113+
impl<INMODE, OUTMODE> Pins<USART3> for (PD8<Alternate<OUTMODE>>, PD9<Input<INMODE>>) {
114114
const REMAP: u8 = 0b11;
115115
}
116116

src/spi.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Serial Peripheral Interface
33
To construct the SPI instances, use the `Spi::spiX` functions.
44
5-
The pin parameter is a tuple containing `(sck, miso, mosi)` which should be configured as `(Alternate<PushPull>, Input<Floating>, Alternate<PushPull>)`.
5+
The pin parameter is a tuple containing `(sck, miso, mosi)` which should be configured as `(Alternate<...>, Input<...>, Alternate<...>)`.
66
As some STM32F1xx chips have 5V tolerant SPI pins, it is also possible to configure Sck and Mosi outputs as `Alternate<PushPull>`. Then
77
a simple Pull-Up to 5V can be used to use SPI on a 5V bus without a level shifter.
88
@@ -50,7 +50,7 @@ use crate::gpio::gpioa::{PA5, PA6, PA7};
5050
use crate::gpio::gpiob::{PB13, PB14, PB15, PB3, PB4, PB5};
5151
#[cfg(feature = "connectivity")]
5252
use crate::gpio::gpioc::{PC10, PC11, PC12};
53-
use crate::gpio::{Alternate, Floating, Input, OpenDrain, PushPull};
53+
use crate::gpio::{Alternate, Input};
5454
use crate::rcc::{Clocks, Enable, GetBusFreq, Reset};
5555
use crate::time::Hertz;
5656

@@ -127,11 +127,9 @@ macro_rules! remap {
127127
type Periph = $SPIX;
128128
const REMAP: bool = $state;
129129
}
130-
impl Sck<$name> for $SCK<Alternate<PushPull>> {}
131-
impl Sck<$name> for $SCK<Alternate<OpenDrain>> {}
132-
impl Miso<$name> for $MISO<Input<Floating>> {}
133-
impl Mosi<$name> for $MOSI<Alternate<PushPull>> {}
134-
impl Mosi<$name> for $MOSI<Alternate<OpenDrain>> {}
130+
impl<MODE> Sck<$name> for $SCK<Alternate<MODE>> {}
131+
impl<MODE> Miso<$name> for $MISO<Input<MODE>> {}
132+
impl<MODE> Mosi<$name> for $MOSI<Alternate<MODE>> {}
135133
};
136134
}
137135

@@ -157,7 +155,7 @@ impl<REMAP, PINS> Spi<SPI1, REMAP, PINS, u8> {
157155
/**
158156
Constructs an SPI instance using SPI1 in 8bit dataframe mode.
159157
160-
The pin parameter tuple (sck, miso, mosi) should be `(PA5, PA6, PA7)` or `(PB3, PB4, PB5)` configured as `(Alternate<PushPull>, Input<Floating>, Alternate<PushPull>)`.
158+
The pin parameter tuple (sck, miso, mosi) should be `(PA5, PA6, PA7)` or `(PB3, PB4, PB5)` configured as `(Alternate<...>, Input<...>, Alternate<...>)`.
161159
162160
You can also use `NoSck`, `NoMiso` or `NoMosi` if you don't want to use the pins
163161
*/
@@ -183,7 +181,7 @@ impl<REMAP, PINS> Spi<SPI2, REMAP, PINS, u8> {
183181
/**
184182
Constructs an SPI instance using SPI2 in 8bit dataframe mode.
185183
186-
The pin parameter tuple (sck, miso, mosi) should be `(PB13, PB14, PB15)` configured as `(Alternate<PushPull>, Input<Floating>, Alternate<PushPull>)`.
184+
The pin parameter tuple (sck, miso, mosi) should be `(PB13, PB14, PB15)` configured as `(Alternate<...>, Input<...>, Alternate<...>)`.
187185
188186
You can also use `NoSck`, `NoMiso` or `NoMosi` if you don't want to use the pins
189187
*/
@@ -202,7 +200,7 @@ impl<REMAP, PINS> Spi<SPI3, REMAP, PINS, u8> {
202200
/**
203201
Constructs an SPI instance using SPI3 in 8bit dataframe mode.
204202
205-
The pin parameter tuple (sck, miso, mosi) should be `(PB3, PB4, PB5)` configured as `(Alternate<PushPull>, Input<Floating>, Alternate<PushPull>)`.
203+
The pin parameter tuple (sck, miso, mosi) should be `(PB3, PB4, PB5)` configured as `(Alternate<...>, Input<...>, Alternate<...>)`.
206204
207205
You can also use `NoSck`, `NoMiso` or `NoMosi` if you don't want to use the pins
208206
*/
@@ -219,7 +217,7 @@ impl<REMAP, PINS> Spi<SPI3, REMAP, PINS, u8> {
219217
/**
220218
Constructs an SPI instance using SPI3 in 8bit dataframe mode.
221219
222-
The pin parameter tuple (sck, miso, mosi) should be `(PB3, PB4, PB5)` or `(PC10, PC11, PC12)` configured as `(Alternate<PushPull>, Input<Floating>, Alternate<PushPull>)`.
220+
The pin parameter tuple (sck, miso, mosi) should be `(PB3, PB4, PB5)` or `(PC10, PC11, PC12)` configured as `(Alternate<...>, Input<...>, Alternate<...>)`.
223221
224222
You can also use `NoSck`, `NoMiso` or `NoMosi` if you don't want to use the pins
225223
*/

0 commit comments

Comments
 (0)