Skip to content

Commit fea4bb0

Browse files
authored
Merge pull request #416 from stm32-rs/ehal
support both e-hal 0.2 & 1.0
2 parents 7c43bfe + 3a0a3d0 commit fea4bb0

39 files changed

+1362
-761
lines changed
File renamed without changes.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
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

Cargo.toml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,30 @@ 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" }
29-
fugit = "0.3.6"
28+
fugit = "0.3.7"
3029
fugit-timer = "0.1.3"
3130
rtic-monotonic = { version = "1.0", optional = true }
3231
bitflags = "1.3.2"
32+
vcell = "0.1.3"
33+
34+
[dependencies.embedded-hal-02]
35+
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"
44+
45+
[dependencies.embedded-io]
46+
version = "0.6.1"
3347

3448
[dependencies.stm32-usbd]
3549
version = "0.6.0"
@@ -45,7 +59,6 @@ heapless = "0.7.16"
4559
mfrc522 = "0.3.0"
4660
usb-device = "0.2.8"
4761
usbd-serial = "0.1.1"
48-
unwrap-infallible = "0.1.5"
4962

5063
[features]
5164
device-selected = []

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-interrupt-idle.rs

Lines changed: 2 additions & 2 deletions
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();
@@ -69,7 +69,7 @@ static mut WIDX: usize = 0;
6969
unsafe fn write(buf: &[u8]) {
7070
if let Some(tx) = TX.as_mut() {
7171
buf.iter()
72-
.for_each(|w| if let Err(_err) = nb::block!(tx.write(*w)) {})
72+
.for_each(|w| if let Err(_err) = nb::block!(tx.write_u8(*w)) {})
7373
}
7474
}
7575
#[interrupt]

examples/serial.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use stm32f1xx_hal::{
1919
prelude::*,
2020
serial::{Config, Serial},
2121
};
22-
use unwrap_infallible::UnwrapInfallible;
2322

2423
#[entry]
2524
fn main() -> ! {
@@ -71,7 +70,7 @@ fn main() -> ! {
7170

7271
// Loopback test. Write `X` and wait until the write is successful.
7372
let sent = b'X';
74-
block!(serial.tx.write(sent)).unwrap_infallible();
73+
block!(serial.tx.write_u8(sent)).unwrap();
7574

7675
// Read the byte that was just sent. Blocks until the read is complete
7776
let received = block!(serial.rx.read()).unwrap();
@@ -85,7 +84,7 @@ fn main() -> ! {
8584
// You can also split the serial struct into a receiving and a transmitting part
8685
let (mut tx, mut rx) = serial.split();
8786
let sent = b'Y';
88-
block!(tx.write(sent)).unwrap_infallible();
87+
block!(tx.write_u8(sent)).unwrap();
8988
let received = block!(rx.read()).unwrap();
9089
assert_eq!(received, sent);
9190
asm::bkpt();

examples/serial_9bits.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@
99
#![no_main]
1010
#![no_std]
1111

12-
use core::convert::Infallible;
1312
use cortex_m_rt::entry;
1413
use nb::block;
1514
use panic_halt as _;
1615
use stm32f1xx_hal::{
1716
pac,
1817
prelude::*,
19-
serial::{self, Config, Serial},
18+
serial::{self, Config, Error, Serial},
2019
};
21-
use unwrap_infallible::UnwrapInfallible;
2220

2321
// The address of the slave device.
2422
const SLAVE_ADDR: u8 = 123;
@@ -29,7 +27,7 @@ const MSG_MAX_LEN: usize = u8::MAX as usize;
2927
// Receives a message addressed to the slave device. Returns the size of the received message.
3028
fn receive_msg<RX>(serial_rx: &mut RX, buf: &mut [u8; MSG_MAX_LEN]) -> usize
3129
where
32-
RX: embedded_hal::serial::Read<u16, Error = serial::Error>,
30+
RX: embedded_hal_02::serial::Read<u16, Error = serial::Error>,
3331
{
3432
enum RxPhase {
3533
Start,
@@ -79,19 +77,19 @@ where
7977
// Send message.
8078
fn send_msg<TX>(serial_tx: &mut TX, msg: &[u8])
8179
where
82-
TX: embedded_hal::serial::Write<u8, Error = Infallible>
83-
+ embedded_hal::serial::Write<u16, Error = Infallible>,
80+
TX: embedded_hal_02::serial::Write<u8, Error = Error>
81+
+ embedded_hal_02::serial::Write<u16, Error = Error>,
8482
{
8583
// Send address.
86-
block!(serial_tx.write(SLAVE_ADDR as u16 | 0x100)).unwrap_infallible();
84+
block!(serial_tx.write(SLAVE_ADDR as u16 | 0x100)).unwrap();
8785

8886
// Send message len.
8987
assert!(msg.len() <= MSG_MAX_LEN);
90-
block!(serial_tx.write(msg.len() as u8)).unwrap_infallible();
88+
block!(serial_tx.write(msg.len() as u8)).unwrap();
9189

9290
// Send message.
9391
for &b in msg {
94-
block!(serial_tx.write(b)).unwrap_infallible();
92+
block!(serial_tx.write(b)).unwrap();
9593
}
9694
}
9795

0 commit comments

Comments
 (0)