Skip to content

Commit 031c887

Browse files
committed
embedded-hal-1
1 parent d42f1dd commit 031c887

27 files changed

+150
-197
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1919
### Added
2020

2121
- Allow to set HSE bypass bit in `RCC` clock configuration register to use an external clock input on the `OSC_IN` pin
22+
- support `embedded-hal-1.0`
2223

2324
## [v0.10.0] - 2022-12-12
2425

@@ -29,7 +30,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2930
fix errata.
3031
- `PwmHz::get_period`: fix computation of return value, prevent division by zero
3132
- return `i2c::Error::Timeout` instead of `nb::WouldBlock` when time is out
32-
- support `embedded-hal-1.0-alpha`
3333

3434
### Breaking changes
3535

Cargo.toml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,27 @@ default-target = "x86_64-unknown-linux-gnu"
2020
[dependencies]
2121
cortex-m = "0.7.6"
2222
cortex-m-rt = "0.7.1"
23-
nb = "1"
23+
nb = "1.1"
2424
stm32f1 = "0.15.1"
2525
embedded-dma = "0.2.0"
2626
bxcan = "0.7"
2727
void = { default-features = false, version = "1.0.2" }
28-
embedded-hal = { features = ["unproven"], version = "0.2.7" }
2928
fugit = "0.3.6"
3029
fugit-timer = "0.1.3"
3130
rtic-monotonic = { version = "1.0", optional = true }
3231
bitflags = "1.3.2"
3332
vcell = "0.1.3"
3433

35-
[dependencies.embedded-hal-one]
36-
version = "=1.0.0-alpha.8"
34+
[dependencies.embedded-hal-02]
3735
package = "embedded-hal"
36+
version = "0.2.7"
37+
features = ["unproven"]
38+
39+
[dependencies.embedded-hal]
40+
version = "1.0"
41+
42+
[dependencies.embedded-hal-nb]
43+
version = "1.0"
3844

3945
[dependencies.stm32-usbd]
4046
version = "0.6.0"

examples/delay-timer-blinky.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn main() -> ! {
4141
loop {
4242
// On for 1s, off for 3s.
4343
led.set_high();
44-
// Use `embedded_hal::DelayMs` trait
44+
// Use `embedded_hal_02::DelayMs` trait
4545
delay.delay_ms(1000_u32);
4646
led.set_low();
4747
// or use `fugit` duration units

examples/delay.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn main() -> ! {
3636

3737
loop {
3838
led.set_high();
39-
// Use `embedded_hal::DelayMs` trait
39+
// Use `embedded_hal_02::DelayMs` trait
4040
delay.delay_ms(1_000_u16);
4141
led.set_low();
4242
// or use `fugit` duration units

examples/dynamic_gpio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use nb::block;
88

99
use cortex_m_rt::entry;
1010
use cortex_m_semihosting::hprintln;
11-
use embedded_hal::digital::v2::{InputPin, OutputPin};
11+
use embedded_hal_02::digital::v2::{InputPin, OutputPin};
1212
use stm32f1xx_hal::{pac, prelude::*};
1313

1414
#[entry]

examples/mfrc522.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use panic_itm as _;
77
use cortex_m::iprintln;
88

99
use cortex_m_rt::entry;
10-
use embedded_hal::digital::v1_compat::OldOutputPin;
11-
use embedded_hal::spi::{Mode, Phase, Polarity};
10+
use embedded_hal_02::digital::v1_compat::OldOutputPin;
11+
use embedded_hal_02::spi::{Mode, Phase, Polarity};
1212
use mfrc522::Mfrc522;
1313
use stm32f1xx_hal::{pac, prelude::*, spi::Spi};
1414
pub const MODE: Mode = Mode {

examples/serial_9bits.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const MSG_MAX_LEN: usize = u8::MAX as usize;
2929
// Receives a message addressed to the slave device. Returns the size of the received message.
3030
fn receive_msg<RX>(serial_rx: &mut RX, buf: &mut [u8; MSG_MAX_LEN]) -> usize
3131
where
32-
RX: embedded_hal::serial::Read<u16, Error = serial::Error>,
32+
RX: embedded_hal_02::serial::Read<u16, Error = serial::Error>,
3333
{
3434
enum RxPhase {
3535
Start,
@@ -79,8 +79,8 @@ where
7979
// Send message.
8080
fn send_msg<TX>(serial_tx: &mut TX, msg: &[u8])
8181
where
82-
TX: embedded_hal::serial::Write<u8, Error = Infallible>
83-
+ embedded_hal::serial::Write<u16, Error = Infallible>,
82+
TX: embedded_hal_02::serial::Write<u8, Error = Infallible>
83+
+ embedded_hal_02::serial::Write<u16, Error = Infallible>,
8484
{
8585
// Send address.
8686
block!(serial_tx.write(SLAVE_ADDR as u16 | 0x100)).unwrap_infallible();

examples/spi-slave.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use cortex_m_rt::entry;
1313
use panic_halt as _;
1414

1515
use cortex_m::{asm, singleton};
16-
use embedded_hal::spi::{Mode, Phase, Polarity};
16+
use embedded_hal_02::spi::{Mode, Phase, Polarity};
1717
pub const MODE: Mode = Mode {
1818
phase: Phase::CaptureOnSecondTransition,
1919
polarity: Polarity::IdleHigh,

examples/spi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use cortex_m_rt::entry;
77
use panic_halt as _;
88

9-
use embedded_hal::spi::{Mode, Phase, Polarity};
9+
use embedded_hal_02::spi::{Mode, Phase, Polarity};
1010
pub const MODE: Mode = Mode {
1111
phase: Phase::CaptureOnSecondTransition,
1212
polarity: Polarity::IdleHigh,

src/adc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! # API for the Analog to Digital converter
22
33
use core::marker::PhantomData;
4-
use embedded_hal::adc::{Channel, OneShot};
4+
use embedded_hal_02::adc::{Channel, OneShot};
55

66
#[cfg(all(feature = "stm32f103", any(feature = "high", feature = "xl",),))]
77
use crate::dma::dma2;

src/gpio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub struct Alternate<MODE = PushPull> {
191191
impl<MODE> Active for Alternate<MODE> {}
192192

193193
/// Digital output pin state
194-
pub use embedded_hal::digital::v2::PinState;
194+
pub use embedded_hal_02::digital::v2::PinState;
195195

196196
// Using SCREAMING_SNAKE_CASE to be consistent with other HALs
197197
// see 59b2740 and #125 for motivation

src/gpio/hal_02.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::*;
2-
use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin};
2+
use embedded_hal_02::digital::v2::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin};
33

44
// Pin
55

src/gpio/hal_1.rs

Lines changed: 48 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ use core::convert::Infallible;
22

33
use super::{Dynamic, ErasedPin, Input, OpenDrain, Output, PartiallyErasedPin, Pin, PinModeError};
44

5-
pub use embedded_hal_one::digital::PinState;
6-
use embedded_hal_one::digital::{
7-
blocking::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin},
8-
ErrorType,
9-
};
5+
pub use embedded_hal::digital::PinState;
6+
use embedded_hal::digital::{ErrorType, InputPin, OutputPin, StatefulOutputPin};
107

118
fn into_state(state: PinState) -> super::PinState {
129
match state {
@@ -23,6 +20,14 @@ impl<const P: char, const N: u8, MODE> ErrorType for Pin<P, N, Input<MODE>> {
2320
type Error = Infallible;
2421
}
2522

23+
impl embedded_hal::digital::Error for PinModeError {
24+
fn kind(&self) -> embedded_hal::digital::ErrorKind {
25+
match self {
26+
PinModeError::IncorrectMode => embedded_hal::digital::ErrorKind::Other,
27+
}
28+
}
29+
}
30+
2631
impl<const P: char, const N: u8> ErrorType for Pin<P, N, Dynamic> {
2732
type Error = PinModeError;
2833
}
@@ -47,10 +52,10 @@ impl<const P: char, const N: u8> OutputPin for Pin<P, N, Dynamic> {
4752
}
4853

4954
impl<const P: char, const N: u8> InputPin for Pin<P, N, Dynamic> {
50-
fn is_high(&self) -> Result<bool, Self::Error> {
55+
fn is_high(&mut self) -> Result<bool, Self::Error> {
5156
self.is_low().map(|b| !b)
5257
}
53-
fn is_low(&self) -> Result<bool, Self::Error> {
58+
fn is_low(&mut self) -> Result<bool, Self::Error> {
5459
if self.mode.is_input() {
5560
Ok(self._is_low())
5661
} else {
@@ -74,44 +79,36 @@ impl<const P: char, const N: u8, MODE> OutputPin for Pin<P, N, Output<MODE>> {
7479

7580
impl<const P: char, const N: u8, MODE> StatefulOutputPin for Pin<P, N, Output<MODE>> {
7681
#[inline]
77-
fn is_set_high(&self) -> Result<bool, Self::Error> {
78-
Ok(self.is_set_high())
82+
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
83+
Ok((*self).is_set_high())
7984
}
8085
#[inline]
81-
fn is_set_low(&self) -> Result<bool, Self::Error> {
82-
Ok(self.is_set_low())
83-
}
84-
}
85-
86-
impl<const P: char, const N: u8, MODE> ToggleableOutputPin for Pin<P, N, Output<MODE>> {
87-
#[inline(always)]
88-
fn toggle(&mut self) -> Result<(), Self::Error> {
89-
self.toggle();
90-
Ok(())
86+
fn is_set_low(&mut self) -> Result<bool, Self::Error> {
87+
Ok((*self).is_set_low())
9188
}
9289
}
9390

9491
impl<const P: char, const N: u8, MODE> InputPin for Pin<P, N, Input<MODE>> {
9592
#[inline]
96-
fn is_high(&self) -> Result<bool, Self::Error> {
97-
Ok(self.is_high())
93+
fn is_high(&mut self) -> Result<bool, Self::Error> {
94+
Ok((*self).is_high())
9895
}
9996

10097
#[inline]
101-
fn is_low(&self) -> Result<bool, Self::Error> {
102-
Ok(self.is_low())
98+
fn is_low(&mut self) -> Result<bool, Self::Error> {
99+
Ok((*self).is_low())
103100
}
104101
}
105102

106103
impl<const P: char, const N: u8> InputPin for Pin<P, N, Output<OpenDrain>> {
107104
#[inline]
108-
fn is_high(&self) -> Result<bool, Self::Error> {
109-
Ok(self.is_high())
105+
fn is_high(&mut self) -> Result<bool, Self::Error> {
106+
Ok((*self).is_high())
110107
}
111108

112109
#[inline]
113-
fn is_low(&self) -> Result<bool, Self::Error> {
114-
Ok(self.is_low())
110+
fn is_low(&mut self) -> Result<bool, Self::Error> {
111+
Ok((*self).is_low())
115112
}
116113
}
117114

@@ -137,45 +134,37 @@ impl<const P: char, MODE> OutputPin for PartiallyErasedPin<P, Output<MODE>> {
137134

138135
impl<const P: char, MODE> StatefulOutputPin for PartiallyErasedPin<P, Output<MODE>> {
139136
#[inline(always)]
140-
fn is_set_high(&self) -> Result<bool, Self::Error> {
141-
Ok(self.is_set_high())
137+
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
138+
Ok((*self).is_set_high())
142139
}
143140

144141
#[inline(always)]
145-
fn is_set_low(&self) -> Result<bool, Self::Error> {
146-
Ok(self.is_set_low())
147-
}
148-
}
149-
150-
impl<const P: char, MODE> ToggleableOutputPin for PartiallyErasedPin<P, Output<MODE>> {
151-
#[inline(always)]
152-
fn toggle(&mut self) -> Result<(), Self::Error> {
153-
self.toggle();
154-
Ok(())
142+
fn is_set_low(&mut self) -> Result<bool, Self::Error> {
143+
Ok((*self).is_set_low())
155144
}
156145
}
157146

158147
impl<const P: char> InputPin for PartiallyErasedPin<P, Output<OpenDrain>> {
159148
#[inline(always)]
160-
fn is_high(&self) -> Result<bool, Self::Error> {
161-
Ok(self.is_high())
149+
fn is_high(&mut self) -> Result<bool, Self::Error> {
150+
Ok((*self).is_high())
162151
}
163152

164153
#[inline(always)]
165-
fn is_low(&self) -> Result<bool, Self::Error> {
166-
Ok(self.is_low())
154+
fn is_low(&mut self) -> Result<bool, Self::Error> {
155+
Ok((*self).is_low())
167156
}
168157
}
169158

170159
impl<const P: char, MODE> InputPin for PartiallyErasedPin<P, Input<MODE>> {
171160
#[inline(always)]
172-
fn is_high(&self) -> Result<bool, Self::Error> {
173-
Ok(self.is_high())
161+
fn is_high(&mut self) -> Result<bool, Self::Error> {
162+
Ok((*self).is_high())
174163
}
175164

176165
#[inline(always)]
177-
fn is_low(&self) -> Result<bool, Self::Error> {
178-
Ok(self.is_low())
166+
fn is_low(&mut self) -> Result<bool, Self::Error> {
167+
Ok((*self).is_low())
179168
}
180169
}
181170

@@ -198,31 +187,31 @@ impl<MODE> OutputPin for ErasedPin<Output<MODE>> {
198187
}
199188

200189
impl<MODE> StatefulOutputPin for ErasedPin<Output<MODE>> {
201-
fn is_set_high(&self) -> Result<bool, Self::Error> {
202-
Ok(self.is_set_high())
190+
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
191+
Ok((*self).is_set_high())
203192
}
204193

205-
fn is_set_low(&self) -> Result<bool, Self::Error> {
206-
Ok(self.is_set_low())
194+
fn is_set_low(&mut self) -> Result<bool, Self::Error> {
195+
Ok((*self).is_set_low())
207196
}
208197
}
209198

210199
impl<MODE> InputPin for ErasedPin<Input<MODE>> {
211-
fn is_high(&self) -> Result<bool, Infallible> {
212-
Ok(self.is_high())
200+
fn is_high(&mut self) -> Result<bool, Infallible> {
201+
Ok((*self).is_high())
213202
}
214203

215-
fn is_low(&self) -> Result<bool, Infallible> {
216-
Ok(self.is_low())
204+
fn is_low(&mut self) -> Result<bool, Infallible> {
205+
Ok((*self).is_low())
217206
}
218207
}
219208

220209
impl InputPin for ErasedPin<Output<OpenDrain>> {
221-
fn is_high(&self) -> Result<bool, Infallible> {
222-
Ok(self.is_high())
210+
fn is_high(&mut self) -> Result<bool, Infallible> {
211+
Ok((*self).is_high())
223212
}
224213

225-
fn is_low(&self) -> Result<bool, Infallible> {
226-
Ok(self.is_low())
214+
fn is_low(&mut self) -> Result<bool, Infallible> {
215+
Ok((*self).is_low())
227216
}
228217
}

src/i2c/hal_02.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::*;
2-
use embedded_hal::blocking::i2c::{Read, Write, WriteRead};
2+
use embedded_hal_02::blocking::i2c::{Read, Write, WriteRead};
33

44
impl<I2C: Instance, PINS> Write for BlockingI2c<I2C, PINS> {
55
type Error = Error;

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ compile_error!(
114114
);
115115

116116
#[cfg(feature = "device-selected")]
117-
use embedded_hal as hal;
117+
pub use embedded_hal as hal;
118+
#[cfg(feature = "device-selected")]
119+
pub use embedded_hal_02 as hal_02;
118120

119121
#[cfg(feature = "stm32f100")]
120122
pub use stm32f1::stm32f100 as pac;

src/prelude.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ pub use crate::dma::ReadWriteDma as _stm32_hal_dma_ReadWriteDma;
88
pub use crate::dma::WriteDma as _stm32_hal_dma_WriteDma;
99
pub use crate::flash::FlashExt as _stm32_hal_flash_FlashExt;
1010
pub use crate::gpio::GpioExt as _stm32_hal_gpio_GpioExt;
11-
pub use crate::hal::adc::OneShot as _embedded_hal_adc_OneShot;
12-
pub use crate::hal::digital::v2::StatefulOutputPin as _embedded_hal_digital_StatefulOutputPin;
13-
pub use crate::hal::digital::v2::ToggleableOutputPin as _embedded_hal_digital_ToggleableOutputPin;
14-
pub use crate::hal::prelude::*;
11+
pub use crate::hal_02::adc::OneShot as _embedded_hal_adc_OneShot;
12+
pub use crate::hal_02::prelude::*;
1513
pub use crate::rcc::RccExt as _stm32_hal_rcc_RccExt;
1614
pub use crate::time::U32Ext as _stm32_hal_time_U32Ext;
1715
#[cfg(feature = "rtic")]

src/qei.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use core::u16;
88

99
use core::marker::PhantomData;
1010

11-
use crate::hal;
12-
pub use crate::hal::Direction;
11+
use embedded_hal_02 as hal;
12+
pub use hal::Direction;
1313
#[cfg(any(feature = "stm32f100", feature = "stm32f103", feature = "connectivity",))]
1414
use crate::pac::TIM1;
1515
#[cfg(feature = "medium")]

0 commit comments

Comments
 (0)