Skip to content

Commit d42f1dd

Browse files
committed
prepare for edding embedded_hal 1.0
1 parent 7c43bfe commit d42f1dd

File tree

18 files changed

+976
-713
lines changed

18 files changed

+976
-713
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2929
fix errata.
3030
- `PwmHz::get_period`: fix computation of return value, prevent division by zero
3131
- return `i2c::Error::Timeout` instead of `nb::WouldBlock` when time is out
32+
- support `embedded-hal-1.0-alpha`
3233

3334
### Breaking changes
3435

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ fugit = "0.3.6"
3030
fugit-timer = "0.1.3"
3131
rtic-monotonic = { version = "1.0", optional = true }
3232
bitflags = "1.3.2"
33+
vcell = "0.1.3"
34+
35+
[dependencies.embedded-hal-one]
36+
version = "=1.0.0-alpha.8"
37+
package = "embedded-hal"
3338

3439
[dependencies.stm32-usbd]
3540
version = "0.6.0"

examples/serial-interrupt-idle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn main() -> ! {
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.
4747
let (mut tx, mut rx) =
48-
Serial::new(p.USART1, (tx, rx), &mut afio.mapr, 115200.bps(), &clocks).split();
48+
Serial::new(p.USART1, (tx, rx), &mut afio.mapr, 115_200.bps(), &clocks).split();
4949
tx.listen();
5050
rx.listen();
5151
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: 4 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,16 @@ 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+
mod hal_1;
89+
8890
/// Slew rates available for Output and relevant AlternateMode Pins
8991
///
9092
/// See Table 21 "Output MODE bits" in the reference
@@ -189,11 +191,7 @@ pub struct Alternate<MODE = PushPull> {
189191
impl<MODE> Active for Alternate<MODE> {}
190192

191193
/// Digital output pin state
192-
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
193-
pub enum PinState {
194-
High,
195-
Low,
196-
}
194+
pub use embedded_hal::digital::v2::PinState;
197195

198196
// Using SCREAMING_SNAKE_CASE to be consistent with other HALs
199197
// see 59b2740 and #125 for motivation
@@ -502,44 +500,6 @@ impl<const P: char, const N: u8> Pin<P, N, Debugger> {
502500
}
503501
}
504502

505-
impl<const P: char, const N: u8> OutputPin for Pin<P, N, Dynamic> {
506-
type Error = PinModeError;
507-
508-
fn set_high(&mut self) -> Result<(), Self::Error> {
509-
if self.mode.is_output() {
510-
self._set_high();
511-
Ok(())
512-
} else {
513-
Err(PinModeError::IncorrectMode)
514-
}
515-
}
516-
517-
fn set_low(&mut self) -> Result<(), Self::Error> {
518-
if self.mode.is_output() {
519-
self._set_low();
520-
Ok(())
521-
} else {
522-
Err(PinModeError::IncorrectMode)
523-
}
524-
}
525-
}
526-
527-
impl<const P: char, const N: u8> InputPin for Pin<P, N, Dynamic> {
528-
type Error = PinModeError;
529-
530-
fn is_high(&self) -> Result<bool, Self::Error> {
531-
self.is_low().map(|b| !b)
532-
}
533-
534-
fn is_low(&self) -> Result<bool, Self::Error> {
535-
if self.mode.is_input() {
536-
Ok(self._is_low())
537-
} else {
538-
Err(PinModeError::IncorrectMode)
539-
}
540-
}
541-
}
542-
543503
// Internal helper functions
544504

545505
// NOTE: The functions in this impl block are "safe", but they
@@ -642,44 +602,6 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, Output<MODE>> {
642602
}
643603
}
644604

645-
impl<const P: char, const N: u8, MODE> OutputPin for Pin<P, N, Output<MODE>> {
646-
type Error = Infallible;
647-
648-
#[inline]
649-
fn set_high(&mut self) -> Result<(), Self::Error> {
650-
self.set_high();
651-
Ok(())
652-
}
653-
654-
#[inline]
655-
fn set_low(&mut self) -> Result<(), Self::Error> {
656-
self.set_low();
657-
Ok(())
658-
}
659-
}
660-
661-
impl<const P: char, const N: u8, MODE> StatefulOutputPin for Pin<P, N, Output<MODE>> {
662-
#[inline]
663-
fn is_set_high(&self) -> Result<bool, Self::Error> {
664-
Ok(self.is_set_high())
665-
}
666-
667-
#[inline]
668-
fn is_set_low(&self) -> Result<bool, Self::Error> {
669-
Ok(self.is_set_low())
670-
}
671-
}
672-
673-
impl<const P: char, const N: u8, MODE> ToggleableOutputPin for Pin<P, N, Output<MODE>> {
674-
type Error = Infallible;
675-
676-
#[inline(always)]
677-
fn toggle(&mut self) -> Result<(), Self::Error> {
678-
self.toggle();
679-
Ok(())
680-
}
681-
}
682-
683605
impl<const P: char, const N: u8, MODE> Pin<P, N, Input<MODE>> {
684606
#[inline]
685607
pub fn is_high(&self) -> bool {
@@ -692,20 +614,6 @@ impl<const P: char, const N: u8, MODE> Pin<P, N, Input<MODE>> {
692614
}
693615
}
694616

695-
impl<const P: char, const N: u8, MODE> InputPin for Pin<P, N, Input<MODE>> {
696-
type Error = Infallible;
697-
698-
#[inline]
699-
fn is_high(&self) -> Result<bool, Self::Error> {
700-
Ok(self.is_high())
701-
}
702-
703-
#[inline]
704-
fn is_low(&self) -> Result<bool, Self::Error> {
705-
Ok(self.is_low())
706-
}
707-
}
708-
709617
impl<const P: char, const N: u8> Pin<P, N, Output<OpenDrain>> {
710618
#[inline]
711619
pub fn is_high(&self) -> bool {
@@ -718,20 +626,6 @@ impl<const P: char, const N: u8> Pin<P, N, Output<OpenDrain>> {
718626
}
719627
}
720628

721-
impl<const P: char, const N: u8> InputPin for Pin<P, N, Output<OpenDrain>> {
722-
type Error = Infallible;
723-
724-
#[inline]
725-
fn is_high(&self) -> Result<bool, Self::Error> {
726-
Ok(self.is_high())
727-
}
728-
729-
#[inline]
730-
fn is_low(&self) -> Result<bool, Self::Error> {
731-
Ok(self.is_low())
732-
}
733-
}
734-
735629
/// Opaque CR register
736630
pub struct Cr<const P: char, const H: bool>(());
737631

src/gpio/erased.rs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -115,54 +115,6 @@ impl<MODE> ErasedPin<Output<MODE>> {
115115
}
116116
}
117117

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

0 commit comments

Comments
 (0)