Skip to content

Commit 1892463

Browse files
committed
prepare for edding embedded_hal 1.0
1 parent 6c6c8c5 commit 1892463

File tree

14 files changed

+514
-506
lines changed

14 files changed

+514
-506
lines changed

examples/serial-interrupt-idle.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use stm32f1xx_hal::{
1313
pac::interrupt,
1414
pac::USART1,
1515
prelude::*,
16-
serial::{Config, Rx, Serial, Tx},
16+
serial::{Rx, Serial, Tx},
1717
};
1818

1919
static mut RX: Option<Rx<USART1>> = None;
@@ -44,14 +44,8 @@ fn main() -> ! {
4444

4545
// Set up the usart device. Takes ownership over the USART register and tx/rx pins. The rest of
4646
// the registers are used to enable and configure the device.
47-
let (mut tx, mut rx) = Serial::usart1(
48-
p.USART1,
49-
(tx, rx),
50-
&mut afio.mapr,
51-
Config::default().baudrate(115200.bps()),
52-
clocks,
53-
)
54-
.split();
47+
let (mut tx, mut rx) =
48+
Serial::new(p.USART1, (tx, rx), &mut afio.mapr, 115_200.bps(), &clocks).split();
5549
tx.listen();
5650
rx.listen();
5751
rx.listen_idle();

src/adc.rs

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl From<Align> for bool {
101101
}
102102

103103
macro_rules! adc_pins {
104-
($ADC:ty, $($pin:ty => $chan:expr),+ $(,)*) => {
104+
($ADC:ty, $($pin:ty => $chan:literal),+ $(,)*) => {
105105
$(
106106
impl Channel<$ADC> for $pin {
107107
type ID = u8;
@@ -113,59 +113,59 @@ macro_rules! adc_pins {
113113
}
114114

115115
adc_pins!(pac::ADC1,
116-
gpio::PA0<Analog> => 0_u8,
117-
gpio::PA1<Analog> => 1_u8,
118-
gpio::PA2<Analog> => 2_u8,
119-
gpio::PA3<Analog> => 3_u8,
120-
gpio::PA4<Analog> => 4_u8,
121-
gpio::PA5<Analog> => 5_u8,
122-
gpio::PA6<Analog> => 6_u8,
123-
gpio::PA7<Analog> => 7_u8,
124-
gpio::PB0<Analog> => 8_u8,
125-
gpio::PB1<Analog> => 9_u8,
126-
gpio::PC0<Analog> => 10_u8,
127-
gpio::PC1<Analog> => 11_u8,
128-
gpio::PC2<Analog> => 12_u8,
129-
gpio::PC3<Analog> => 13_u8,
130-
gpio::PC4<Analog> => 14_u8,
131-
gpio::PC5<Analog> => 15_u8,
116+
gpio::PA0<Analog> => 0,
117+
gpio::PA1<Analog> => 1,
118+
gpio::PA2<Analog> => 2,
119+
gpio::PA3<Analog> => 3,
120+
gpio::PA4<Analog> => 4,
121+
gpio::PA5<Analog> => 5,
122+
gpio::PA6<Analog> => 6,
123+
gpio::PA7<Analog> => 7,
124+
gpio::PB0<Analog> => 8,
125+
gpio::PB1<Analog> => 9,
126+
gpio::PC0<Analog> => 10,
127+
gpio::PC1<Analog> => 11,
128+
gpio::PC2<Analog> => 12,
129+
gpio::PC3<Analog> => 13,
130+
gpio::PC4<Analog> => 14,
131+
gpio::PC5<Analog> => 15,
132132
);
133133

134134
#[cfg(any(feature = "stm32f103", feature = "connectivity"))]
135135
adc_pins!(pac::ADC2,
136-
gpio::PA0<Analog> => 0_u8,
137-
gpio::PA1<Analog> => 1_u8,
138-
gpio::PA2<Analog> => 2_u8,
139-
gpio::PA3<Analog> => 3_u8,
140-
gpio::PA4<Analog> => 4_u8,
141-
gpio::PA5<Analog> => 5_u8,
142-
gpio::PA6<Analog> => 6_u8,
143-
gpio::PA7<Analog> => 7_u8,
144-
gpio::PB0<Analog> => 8_u8,
145-
gpio::PB1<Analog> => 9_u8,
146-
gpio::PC0<Analog> => 10_u8,
147-
gpio::PC1<Analog> => 11_u8,
148-
gpio::PC2<Analog> => 12_u8,
149-
gpio::PC3<Analog> => 13_u8,
150-
gpio::PC4<Analog> => 14_u8,
151-
gpio::PC5<Analog> => 15_u8,
136+
gpio::PA0<Analog> => 0,
137+
gpio::PA1<Analog> => 1,
138+
gpio::PA2<Analog> => 2,
139+
gpio::PA3<Analog> => 3,
140+
gpio::PA4<Analog> => 4,
141+
gpio::PA5<Analog> => 5,
142+
gpio::PA6<Analog> => 6,
143+
gpio::PA7<Analog> => 7,
144+
gpio::PB0<Analog> => 8,
145+
gpio::PB1<Analog> => 9,
146+
gpio::PC0<Analog> => 10,
147+
gpio::PC1<Analog> => 11,
148+
gpio::PC2<Analog> => 12,
149+
gpio::PC3<Analog> => 13,
150+
gpio::PC4<Analog> => 14,
151+
gpio::PC5<Analog> => 15,
152152
);
153153

154154
#[cfg(all(feature = "stm32f103", any(feature = "high", feature = "xl",),))]
155155
adc_pins!(pac::ADC3,
156-
gpio::PA0<Analog> => 0_u8,
157-
gpio::PA1<Analog> => 1_u8,
158-
gpio::PA2<Analog> => 2_u8,
159-
gpio::PA3<Analog> => 3_u8,
160-
gpio::PF6<Analog> => 4_u8,
161-
gpio::PF7<Analog> => 5_u8,
162-
gpio::PF8<Analog> => 6_u8,
163-
gpio::PF9<Analog> => 7_u8,
164-
gpio::PF10<Analog> => 8_u8,
165-
gpio::PC0<Analog> => 10_u8,
166-
gpio::PC1<Analog> => 11_u8,
167-
gpio::PC2<Analog> => 12_u8,
168-
gpio::PC3<Analog> => 13_u8,
156+
gpio::PA0<Analog> => 0,
157+
gpio::PA1<Analog> => 1,
158+
gpio::PA2<Analog> => 2,
159+
gpio::PA3<Analog> => 3,
160+
gpio::PF6<Analog> => 4,
161+
gpio::PF7<Analog> => 5,
162+
gpio::PF8<Analog> => 6,
163+
gpio::PF9<Analog> => 7,
164+
gpio::PF10<Analog> => 8,
165+
gpio::PC0<Analog> => 10,
166+
gpio::PC1<Analog> => 11,
167+
gpio::PC2<Analog> => 12,
168+
gpio::PC3<Analog> => 13,
169169
);
170170

171171
/// Stored ADC config can be restored using the `Adc::restore_cfg` method

src/gpio.rs

Lines changed: 2 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,15 @@ use core::convert::Infallible;
7777
use core::marker::PhantomData;
7878

7979
use crate::afio;
80-
use crate::hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin};
8180
use crate::pac::EXTI;
8281

8382
mod partially_erased;
8483
pub use partially_erased::{PEPin, PartiallyErasedPin};
8584
mod erased;
8685
pub use erased::{EPin, ErasedPin};
8786

87+
mod hal_02;
88+
8889
/// Slew rates available for Output and relevant AlternateMode Pins
8990
///
9091
/// See Table 21 "Output MODE bits" in the reference
@@ -467,40 +468,6 @@ impl<const P: char, const N: u8> Pin<P, N, Debugger> {
467468
}
468469
}
469470

470-
impl<const P: char, const N: u8> OutputPin for Pin<P, N, Dynamic> {
471-
type Error = PinModeError;
472-
fn set_high(&mut self) -> Result<(), Self::Error> {
473-
if self.mode.is_output() {
474-
self._set_state(PinState::High);
475-
Ok(())
476-
} else {
477-
Err(PinModeError::IncorrectMode)
478-
}
479-
}
480-
fn set_low(&mut self) -> Result<(), Self::Error> {
481-
if self.mode.is_output() {
482-
self._set_state(PinState::Low);
483-
Ok(())
484-
} else {
485-
Err(PinModeError::IncorrectMode)
486-
}
487-
}
488-
}
489-
490-
impl<const P: char, const N: u8> InputPin for Pin<P, N, Dynamic> {
491-
type Error = PinModeError;
492-
fn is_high(&self) -> Result<bool, Self::Error> {
493-
self.is_low().map(|b| !b)
494-
}
495-
fn is_low(&self) -> Result<bool, Self::Error> {
496-
if self.mode.is_input() {
497-
Ok(self._is_low())
498-
} else {
499-
Err(PinModeError::IncorrectMode)
500-
}
501-
}
502-
}
503-
504471
// Internal helper functions
505472

506473
// NOTE: The functions in this impl block are "safe", but they
@@ -596,41 +563,6 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, Output<MODE>> {
596563
}
597564
}
598565

599-
impl<const P: char, const N: u8, MODE> OutputPin for Pin<P, N, Output<MODE>> {
600-
type Error = Infallible;
601-
#[inline]
602-
fn set_high(&mut self) -> Result<(), Self::Error> {
603-
self.set_high();
604-
Ok(())
605-
}
606-
#[inline]
607-
fn set_low(&mut self) -> Result<(), Self::Error> {
608-
self.set_low();
609-
Ok(())
610-
}
611-
}
612-
613-
impl<const P: char, const N: u8, MODE> StatefulOutputPin for Pin<P, N, Output<MODE>> {
614-
#[inline]
615-
fn is_set_high(&self) -> Result<bool, Self::Error> {
616-
Ok(self.is_set_high())
617-
}
618-
#[inline]
619-
fn is_set_low(&self) -> Result<bool, Self::Error> {
620-
Ok(self.is_set_low())
621-
}
622-
}
623-
624-
impl<const P: char, const N: u8, MODE> ToggleableOutputPin for Pin<P, N, Output<MODE>> {
625-
type Error = Infallible;
626-
627-
#[inline(always)]
628-
fn toggle(&mut self) -> Result<(), Self::Error> {
629-
self.toggle();
630-
Ok(())
631-
}
632-
}
633-
634566
impl<const P: char, const N: u8, MODE> Pin<P, N, Input<MODE>> {
635567
#[inline]
636568
pub fn is_high(&self) -> bool {
@@ -642,19 +574,6 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, Input<MODE>> {
642574
}
643575
}
644576

645-
impl<const P: char, const N: u8, MODE> InputPin for Pin<P, N, Input<MODE>> {
646-
type Error = Infallible;
647-
#[inline]
648-
fn is_high(&self) -> Result<bool, Self::Error> {
649-
Ok(self.is_high())
650-
}
651-
652-
#[inline]
653-
fn is_low(&self) -> Result<bool, Self::Error> {
654-
Ok(self.is_low())
655-
}
656-
}
657-
658577
impl<const P: char, const N: u8> Pin<P, N, Output<OpenDrain>> {
659578
#[inline]
660579
pub fn is_high(&self) -> bool {
@@ -666,19 +585,6 @@ impl<const P: char, const N: u8> Pin<P, N, Output<OpenDrain>> {
666585
}
667586
}
668587

669-
impl<const P: char, const N: u8> InputPin for Pin<P, N, Output<OpenDrain>> {
670-
type Error = Infallible;
671-
#[inline]
672-
fn is_high(&self) -> Result<bool, Self::Error> {
673-
Ok(self.is_high())
674-
}
675-
676-
#[inline]
677-
fn is_low(&self) -> Result<bool, Self::Error> {
678-
Ok(self.is_low())
679-
}
680-
}
681-
682588
/// Opaque CR register
683589
pub struct Cr<const P: char, const H: bool>(());
684590

src/gpio/erased.rs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -114,51 +114,6 @@ impl<MODE> ErasedPin<Output<MODE>> {
114114
}
115115
}
116116

117-
impl<MODE> OutputPin for ErasedPin<Output<MODE>> {
118-
type Error = Infallible;
119-
fn set_high(&mut self) -> Result<(), Infallible> {
120-
self.set_high();
121-
Ok(())
122-
}
123-
124-
fn set_low(&mut self) -> Result<(), Infallible> {
125-
self.set_low();
126-
Ok(())
127-
}
128-
}
129-
130-
impl<MODE> StatefulOutputPin for ErasedPin<Output<MODE>> {
131-
fn is_set_high(&self) -> Result<bool, Self::Error> {
132-
Ok(self.is_set_high())
133-
}
134-
135-
fn is_set_low(&self) -> Result<bool, Self::Error> {
136-
Ok(self.is_set_low())
137-
}
138-
}
139-
140-
impl<MODE> InputPin for ErasedPin<Input<MODE>> {
141-
type Error = Infallible;
142-
fn is_high(&self) -> Result<bool, Infallible> {
143-
Ok(self.is_high())
144-
}
145-
146-
fn is_low(&self) -> Result<bool, Infallible> {
147-
Ok(self.is_low())
148-
}
149-
}
150-
151-
impl InputPin for ErasedPin<Output<OpenDrain>> {
152-
type Error = Infallible;
153-
fn is_high(&self) -> Result<bool, Infallible> {
154-
Ok(self.is_high())
155-
}
156-
157-
fn is_low(&self) -> Result<bool, Infallible> {
158-
Ok(self.is_low())
159-
}
160-
}
161-
162117
#[cfg(not(any(feature = "xl", feature = "high")))]
163118
impl_pxx! {
164119
('A'::PAx),

0 commit comments

Comments
 (0)