Skip to content

Commit 7f171d2

Browse files
committed
remove PULL generic from Input
1 parent 6a8d6f4 commit 7f171d2

19 files changed

+298
-335
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1515
- Use independent `Spi` and `SpiSlave` structures instead of `OP` generic [#462]
1616
- Take `&Clocks` instead of `Clocks` [#498]
1717
- Temporary replace `stm32f1` with `stm32f1-staging` [#503]
18+
- Remove `PULL` generic from `Input` mode,
19+
temporary disable `as_(mode)` [#512]
1820

1921
### Changed
2022

@@ -62,6 +64,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
6264
[#509]: https://github.com/stm32-rs/stm32f1xx-hal/pull/509
6365
[#510]: https://github.com/stm32-rs/stm32f1xx-hal/pull/510
6466
[#511]: https://github.com/stm32-rs/stm32f1xx-hal/pull/511
67+
[#512]: https://github.com/stm32-rs/stm32f1xx-hal/pull/512
6568

6669
## [v0.10.0] - 2022-12-12
6770

examples/can-loopback.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use panic_halt as _;
1212

1313
use cortex_m_rt::entry;
1414
use nb::block;
15-
use stm32f1xx_hal::{can::Can, gpio::Floating, pac, prelude::*};
15+
use stm32f1xx_hal::{can::Can, pac, prelude::*};
1616

1717
#[entry]
1818
fn main() -> ! {
@@ -25,7 +25,7 @@ fn main() -> ! {
2525
// resonator must be used.
2626
rcc.cfgr.use_hse(8.MHz()).freeze(&mut flash.acr);
2727

28-
let can = Can::<_, Floating>::new_loopback(
28+
let can = Can::new_loopback(
2929
dp.CAN1,
3030
#[cfg(not(feature = "connectivity"))]
3131
dp.USB,

examples/can-rtic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ mod app {
5555
use super::{enqueue_frame, PriorityFrame};
5656
use bxcan::{filter::Mask32, ExtendedId, Fifo, Frame, Interrupts, Rx0, StandardId, Tx};
5757
use heapless::binary_heap::{BinaryHeap, Max};
58-
use stm32f1xx_hal::{can::Can, gpio::Floating, pac::CAN1, prelude::*};
58+
use stm32f1xx_hal::{can::Can, pac::CAN1, prelude::*};
5959

6060
#[local]
6161
struct Local {
@@ -89,14 +89,14 @@ mod app {
8989
let mut afio = cx.device.AFIO.constrain();
9090

9191
#[cfg(not(feature = "connectivity"))]
92-
let can = Can::<_, Floating>::new(
92+
let can = Can::new(
9393
cx.device.CAN1,
9494
cx.device.USB,
9595
(can_tx_pin, can_rx_pin, &mut afio.mapr),
9696
);
9797

9898
#[cfg(feature = "connectivity")]
99-
let can = Can::<_, Floating>::new(cx.device.CAN1, (can_tx_pin, can_rx_pin, &mut afio.mapr));
99+
let can = Can::new(cx.device.CAN1, (can_tx_pin, can_rx_pin, &mut afio.mapr));
100100

101101
// APB1 (PCLK1): 16MHz, Bit rate: 1000kBit/s, Sample Point 87.5%
102102
// Value was calculated with http://www.bittiming.can-wiki.info/

examples/exti.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ use stm32f1xx_hal::{pac, prelude::*};
1919
// where the interrupt is not yet enabled (i.e. no concurrent accesses can occur).
2020
// After enabling the interrupt, main() may not have any references to these objects any more.
2121
// For the sake of minimalism, we do not use RTIC here, which would be the better way.
22-
static mut LED: MaybeUninit<stm32f1xx_hal::gpio::gpioc::PC13<Output<PushPull>>> =
23-
MaybeUninit::uninit();
24-
static mut INT_PIN: MaybeUninit<stm32f1xx_hal::gpio::gpioa::PA7<Input<Floating>>> =
25-
MaybeUninit::uninit();
22+
static mut LED: MaybeUninit<stm32f1xx_hal::gpio::gpioc::PC13<Output>> = MaybeUninit::uninit();
23+
static mut INT_PIN: MaybeUninit<stm32f1xx_hal::gpio::gpioa::PA7<Input>> = MaybeUninit::uninit();
2624

2725
#[interrupt]
2826
fn EXTI9_5() {

examples/exti_rtic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use panic_halt as _;
88
#[rtic::app(device = stm32f1xx_hal::pac)]
99
mod app {
1010
use stm32f1xx_hal::{
11-
gpio::{gpioa::PA0, gpioc::PC13, Edge, ExtiPin, Input, Output, PullDown, PushPull},
11+
gpio::{gpioa::PA0, gpioc::PC13, Edge, ExtiPin, Input, Output},
1212
prelude::*,
1313
};
1414

@@ -17,8 +17,8 @@ mod app {
1717

1818
#[local]
1919
struct Local {
20-
button: PA0<Input<PullDown>>,
21-
led: PC13<Output<PushPull>>,
20+
button: PA0<Input>,
21+
led: PC13<Output>,
2222
}
2323

2424
#[init]
File renamed without changes.

src/afio.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::pac::{self, afio, AFIO, RCC};
44
use crate::rcc::{Enable, Reset};
55

66
use crate::gpio::{
7-
Debugger, Floating, Input, PA15, {PB3, PB4},
7+
Debugger, Input, PA15, {PB3, PB4},
88
};
99
use crate::sealed::Sealed;
1010

@@ -94,11 +94,7 @@ impl MAPR {
9494
pa15: PA15<Debugger>,
9595
pb3: PB3<Debugger>,
9696
pb4: PB4<Debugger>,
97-
) -> (
98-
PA15<Input<Floating>>,
99-
PB3<Input<Floating>>,
100-
PB4<Input<Floating>>,
101-
) {
97+
) -> (PA15<Input>, PB3<Input>, PB4<Input>) {
10298
self.jtag_enabled = false;
10399
// Avoid duplicating swj_cfg write code
104100
self.modify_mapr(|_, w| w);

src/can.rs

+30-48
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,9 @@
2020
//! | RX | PB5 | PB12 |
2121
2222
use crate::afio::Remap;
23-
use crate::gpio::{self, Alternate, Cr, Floating, Input, NoPin, PinMode, PullUp, PushPull};
23+
use crate::gpio::{self, Alternate, Cr, Input, NoPin, PushPull};
2424
use crate::pac::{self, RCC};
2525

26-
pub trait InMode {}
27-
impl InMode for Floating {}
28-
impl InMode for PullUp {}
29-
3026
pub struct Pins<TX, RX> {
3127
pub tx: TX,
3228
pub rx: RX,
@@ -72,50 +68,42 @@ macro_rules! remap {
7268
)+
7369
None(NoPin<PushPull>),
7470
}
75-
pub enum Rx<PULL> {
71+
pub enum Rx {
7672
$(
77-
$RX(gpio::$RX<Input<PULL>>),
73+
$RX(gpio::$RX<Input>),
7874
)+
79-
None(NoPin<PULL>),
75+
None(NoPin<PushPull>),
8076
}
8177

8278
$(
83-
impl<PULL: InMode> From<(gpio::$TX<Alternate>, gpio::$RX<Input<PULL>>, &mut <$PER as Remap>::Mapr)> for Pins<Tx, Rx<PULL>> {
84-
fn from(p: (gpio::$TX<Alternate>, gpio::$RX<Input<PULL>>, &mut <$PER as Remap>::Mapr)) -> Self {
79+
impl From<(gpio::$TX<Alternate>, gpio::$RX, &mut <$PER as Remap>::Mapr)> for Pins<Tx, Rx> {
80+
fn from(p: (gpio::$TX<Alternate>, gpio::$RX, &mut <$PER as Remap>::Mapr)) -> Self {
8581
<$PER>::remap(p.2, $remap);
8682
Self { tx: Tx::$TX(p.0), rx: Rx::$RX(p.1) }
8783
}
8884
}
8985

90-
impl<PULL> From<(gpio::$TX, gpio::$RX, &mut <$PER as Remap>::Mapr)> for Pins<Tx, Rx<PULL>>
91-
where
92-
Input<PULL>: PinMode,
93-
PULL: InMode,
94-
{
86+
impl From<(gpio::$TX, gpio::$RX, &mut <$PER as Remap>::Mapr)> for Pins<Tx, Rx> {
9587
fn from(p: (gpio::$TX, gpio::$RX, &mut <$PER as Remap>::Mapr)) -> Self {
9688
let mut cr = Cr;
9789
let tx = p.0.into_mode(&mut cr);
98-
let rx = p.1.into_mode(&mut cr);
90+
let rx = p.1;
9991
<$PER>::remap(p.2, $remap);
10092
Self { tx: Tx::$TX(tx), rx: Rx::$RX(rx) }
10193
}
10294
}
10395

104-
impl From<(gpio::$TX, &mut <$PER as Remap>::Mapr)> for Pins<Tx, Rx<Floating>> {
96+
impl From<(gpio::$TX, &mut <$PER as Remap>::Mapr)> for Pins<Tx, Rx> {
10597
fn from(p: (gpio::$TX, &mut <$PER as Remap>::Mapr)) -> Self {
10698
let tx = p.0.into_mode(&mut Cr);
10799
<$PER>::remap(p.1, $remap);
108100
Self { tx: Tx::$TX(tx), rx: Rx::None(NoPin::new()) }
109101
}
110102
}
111103

112-
impl<PULL> From<(gpio::$RX, &mut <$PER as Remap>::Mapr)> for Pins<Tx, Rx<PULL>>
113-
where
114-
Input<PULL>: PinMode,
115-
PULL: InMode,
116-
{
104+
impl From<(gpio::$RX, &mut <$PER as Remap>::Mapr)> for Pins<Tx, Rx> {
117105
fn from(p: (gpio::$RX, &mut <$PER as Remap>::Mapr)) -> Self {
118-
let rx = p.0.into_mode(&mut Cr);
106+
let rx = p.0;
119107
<$PER>::remap(p.1, $remap);
120108
Self { tx: Tx::None(NoPin::new()), rx: Rx::$RX(rx) }
121109
}
@@ -129,31 +117,25 @@ pub trait CanExt: Sized + Instance {
129117
fn can(
130118
self,
131119
#[cfg(not(feature = "connectivity"))] usb: pac::USB,
132-
pins: impl Into<Pins<Self::Tx, Self::Rx<Floating>>>,
133-
) -> Can<Self, Floating>;
134-
fn can_loopback(
135-
self,
136-
#[cfg(not(feature = "connectivity"))] usb: pac::USB,
137-
) -> Can<Self, Floating>;
120+
pins: impl Into<Pins<Self::Tx, Self::Rx>>,
121+
) -> Can<Self>;
122+
fn can_loopback(self, #[cfg(not(feature = "connectivity"))] usb: pac::USB) -> Can<Self>;
138123
}
139124

140125
impl<CAN: Instance> CanExt for CAN {
141126
fn can(
142127
self,
143128
#[cfg(not(feature = "connectivity"))] usb: pac::USB,
144-
pins: impl Into<Pins<Self::Tx, Self::Rx<Floating>>>,
145-
) -> Can<Self, Floating> {
129+
pins: impl Into<Pins<Self::Tx, Self::Rx>>,
130+
) -> Can<Self> {
146131
Can::new(
147132
self,
148133
#[cfg(not(feature = "connectivity"))]
149134
usb,
150135
pins,
151136
)
152137
}
153-
fn can_loopback(
154-
self,
155-
#[cfg(not(feature = "connectivity"))] usb: pac::USB,
156-
) -> Can<Self, Floating> {
138+
fn can_loopback(self, #[cfg(not(feature = "connectivity"))] usb: pac::USB) -> Can<Self> {
157139
Can::new_loopback(
158140
self,
159141
#[cfg(not(feature = "connectivity"))]
@@ -164,35 +146,35 @@ impl<CAN: Instance> CanExt for CAN {
164146

165147
pub trait Instance: crate::rcc::Enable {
166148
type Tx;
167-
type Rx<PULL>;
149+
type Rx;
168150
}
169151
impl Instance for pac::CAN1 {
170152
type Tx = can1::Tx;
171-
type Rx<PULL> = can1::Rx<PULL>;
153+
type Rx = can1::Rx;
172154
}
173155
#[cfg(feature = "connectivity")]
174156
impl Instance for pac::CAN2 {
175157
type Tx = can2::Tx;
176-
type Rx<PULL> = can2::Rx<PULL>;
158+
type Rx = can2::Rx;
177159
}
178160

179161
/// Interface to the CAN peripheral.
180162
#[allow(unused)]
181-
pub struct Can<CAN: Instance, PULL = Floating> {
163+
pub struct Can<CAN: Instance> {
182164
can: CAN,
183-
pins: Option<Pins<CAN::Tx, CAN::Rx<PULL>>>,
165+
pins: Option<Pins<CAN::Tx, CAN::Rx>>,
184166
}
185167

186-
impl<CAN: Instance, PULL> Can<CAN, PULL> {
168+
impl<CAN: Instance> Can<CAN> {
187169
/// Creates a CAN interface.
188170
///
189171
/// CAN shares SRAM with the USB peripheral. Take ownership of USB to
190172
/// prevent accidental shared usage.
191173
pub fn new(
192174
can: CAN,
193175
#[cfg(not(feature = "connectivity"))] _usb: pac::USB,
194-
pins: impl Into<Pins<CAN::Tx, CAN::Rx<PULL>>>,
195-
) -> Can<CAN, PULL> {
176+
pins: impl Into<Pins<CAN::Tx, CAN::Rx>>,
177+
) -> Can<CAN> {
196178
let rcc = unsafe { &(*RCC::ptr()) };
197179
CAN::enable(rcc);
198180

@@ -204,26 +186,26 @@ impl<CAN: Instance, PULL> Can<CAN, PULL> {
204186
pub fn new_loopback(
205187
can: CAN,
206188
#[cfg(not(feature = "connectivity"))] _usb: pac::USB,
207-
) -> Can<CAN, PULL> {
189+
) -> Can<CAN> {
208190
let rcc = unsafe { &(*RCC::ptr()) };
209191
CAN::enable(rcc);
210192

211193
Can { can, pins: None }
212194
}
213195
}
214196

215-
unsafe impl<PULL> bxcan::Instance for Can<pac::CAN1, PULL> {
197+
unsafe impl bxcan::Instance for Can<pac::CAN1> {
216198
const REGISTERS: *mut bxcan::RegisterBlock = pac::CAN1::ptr() as *mut _;
217199
}
218200

219201
#[cfg(feature = "connectivity")]
220-
unsafe impl<PULL> bxcan::Instance for Can<pac::CAN2, PULL> {
202+
unsafe impl bxcan::Instance for Can<pac::CAN2> {
221203
const REGISTERS: *mut bxcan::RegisterBlock = pac::CAN2::ptr() as *mut _;
222204
}
223205

224-
unsafe impl<PULL> bxcan::FilterOwner for Can<pac::CAN1, PULL> {
206+
unsafe impl bxcan::FilterOwner for Can<pac::CAN1> {
225207
const NUM_FILTER_BANKS: u8 = 28;
226208
}
227209

228210
#[cfg(feature = "connectivity")]
229-
unsafe impl<PULL> bxcan::MasterInstance for Can<pac::CAN1, PULL> {}
211+
unsafe impl bxcan::MasterInstance for Can<pac::CAN1> {}

0 commit comments

Comments
 (0)