Skip to content

Commit 98c1173

Browse files
committed
Adapt to embedded-hal 1.0.0-alpha.4
1 parent b3e2d75 commit 98c1173

30 files changed

+290
-246
lines changed

Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ default-target = "x86_64-unknown-linux-gnu"
1717

1818
[dependencies]
1919
cortex-m = "0.6.0"
20-
nb = "0.1.2"
20+
nb = "1"
2121
cortex-m-rt = "0.6.8"
2222
stm32f1 = "0.11.0"
2323
embedded-dma = "0.1.2"
24+
embedded-hal = "=1.0.0-alpha.4"
2425

2526
[dependencies.void]
2627
default-features = false
@@ -30,9 +31,6 @@ version = "1.0.2"
3031
default-features = false
3132
version = "0.2.2"
3233

33-
[dependencies.embedded-hal]
34-
version = "0.2.3"
35-
features = ["unproven"]
3634

3735
[dependencies.stm32-usbd]
3836
version = "0.5.0"

examples/adc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ fn main() -> ! {
4040
let mut ch1 = gpiob.pb1.into_analog(&mut gpiob.crl);
4141

4242
loop {
43-
let data: u16 = adc1.read(&mut ch0).unwrap();
43+
let data: u16 = adc1.try_read(&mut ch0).unwrap();
4444
hprintln!("adc1: {}", data).unwrap();
4545

4646
#[cfg(feature = "stm32f103")]
4747
{
48-
let data1: u16 = adc2.read(&mut ch1).unwrap();
48+
let data1: u16 = adc2.try_read(&mut ch1).unwrap();
4949
hprintln!("adc2: {}", data1).unwrap();
5050
}
5151
}

examples/blinky.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use panic_halt as _;
1414
use nb::block;
1515

1616
use cortex_m_rt::entry;
17-
use embedded_hal::digital::v2::OutputPin;
17+
use embedded_hal::digital::OutputPin;
1818
use stm32f1xx_hal::{pac, prelude::*, timer::Timer};
1919

2020
#[entry]
@@ -44,9 +44,9 @@ fn main() -> ! {
4444

4545
// Wait for the timer to trigger an update and change the state of the LED
4646
loop {
47-
block!(timer.wait()).unwrap();
48-
led.set_high().unwrap();
49-
block!(timer.wait()).unwrap();
50-
led.set_low().unwrap();
47+
block!(timer.try_wait()).unwrap();
48+
led.try_set_high().unwrap();
49+
block!(timer.try_wait()).unwrap();
50+
led.try_set_low().unwrap();
5151
}
5252
}

examples/blinky_generic.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use panic_halt as _;
99
use nb::block;
1010

1111
use cortex_m_rt::entry;
12-
use embedded_hal::digital::v2::OutputPin;
12+
use embedded_hal::digital::OutputPin;
1313
use stm32f1xx_hal::{pac, prelude::*, timer::Timer};
1414

1515
#[entry]
@@ -37,13 +37,13 @@ fn main() -> ! {
3737

3838
// Wait for the timer to trigger an update and change the state of the LED
3939
loop {
40-
block!(timer.wait()).unwrap();
40+
block!(timer.try_wait()).unwrap();
4141
for led in leds.iter_mut() {
42-
led.set_high().unwrap();
42+
led.try_set_high().unwrap();
4343
}
44-
block!(timer.wait()).unwrap();
44+
block!(timer.try_wait()).unwrap();
4545
for led in leds.iter_mut() {
46-
led.set_low().unwrap();
46+
led.try_set_low().unwrap();
4747
}
4848
}
4949
}

examples/blinky_rtc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use panic_halt as _;
1515
use stm32f1xx_hal::{pac, prelude::*, rtc::Rtc};
1616

1717
use cortex_m_rt::entry;
18-
use embedded_hal::digital::v2::OutputPin;
18+
use embedded_hal::digital::OutputPin;
1919
use nb::block;
2020

2121
#[entry]
@@ -43,10 +43,10 @@ fn main() -> ! {
4343
rtc.set_alarm(5);
4444
block!(rtc.wait_alarm()).unwrap();
4545
if led_on {
46-
led.set_low().unwrap();
46+
led.try_set_low().unwrap();
4747
led_on = false;
4848
} else {
49-
led.set_high().unwrap();
49+
led.try_set_high().unwrap();
5050
led_on = true;
5151
}
5252
}

examples/blinky_rtcalarm_irq.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::hal::{
2424
use core::cell::RefCell;
2525
use cortex_m::{asm::wfi, interrupt::Mutex};
2626
use cortex_m_rt::entry;
27-
use embedded_hal::digital::v2::OutputPin;
27+
use embedded_hal::digital::OutputPin;
2828

2929
// A type definition for the GPIO pin to be used for our LED
3030
type LEDPIN = gpioc::PC13<Output<PushPull>>;
@@ -68,7 +68,7 @@ fn RTCALARM() {
6868
exti.pr.write(|w| w.pr17().set_bit());
6969
rtc.set_alarm(rtc.current_time() + TOGGLE_INTERVAL_SECONDS);
7070

71-
let _ = led.toggle();
71+
let _ = led.try_toggle();
7272
}
7373

7474
#[cfg(not(feature = "stm32f101"))]
@@ -82,7 +82,7 @@ fn main() -> ! {
8282
// Set up the GPIO pin
8383
let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);
8484
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
85-
let _ = led.set_high(); // Turn off
85+
let _ = led.try_set_high(); // Turn off
8686

8787
cortex_m::interrupt::free(|cs| *G_LED.borrow(cs).borrow_mut() = Some(led));
8888

examples/blinky_timer_irq.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::hal::{
2424
use core::cell::RefCell;
2525
use cortex_m::{asm::wfi, interrupt::Mutex};
2626
use cortex_m_rt::entry;
27-
use embedded_hal::digital::v2::OutputPin;
27+
use embedded_hal::digital::OutputPin;
2828

2929
// NOTE You can uncomment 'hprintln' here and in the code below for a bit more
3030
// verbosity at runtime, at the cost of throwing off the timing of the blink
@@ -62,8 +62,8 @@ fn TIM2() {
6262
})
6363
});
6464

65-
let _ = led.toggle();
66-
let _ = tim.wait();
65+
let _ = led.try_toggle();
66+
let _ = tim.try_wait();
6767
}
6868

6969
#[entry]
@@ -81,7 +81,7 @@ fn main() -> ! {
8181
// Configure PC13 pin to blink LED
8282
let mut gpioc = dp.GPIOC.split(&mut rcc.apb2);
8383
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
84-
let _ = led.set_high(); // Turn off
84+
let _ = led.try_set_high(); // Turn off
8585

8686
// Move the pin into our global storage
8787
cortex_m::interrupt::free(|cs| *G_LED.borrow(cs).borrow_mut() = Some(led));

examples/delay.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use panic_halt as _;
88

99
use cortex_m_rt::entry;
10-
use embedded_hal::digital::v2::OutputPin;
10+
use embedded_hal::digital::OutputPin;
1111
use stm32f1xx_hal::{delay::Delay, pac, prelude::*};
1212

1313
#[entry]
@@ -34,9 +34,9 @@ fn main() -> ! {
3434
let mut delay = Delay::new(cp.SYST, clocks);
3535

3636
loop {
37-
led.set_high().unwrap();
38-
delay.delay_ms(1_000_u16);
39-
led.set_low().unwrap();
40-
delay.delay_ms(1_000_u16);
37+
led.try_set_high().unwrap();
38+
delay.try_delay_ms(1_000_u16).unwrap();
39+
led.try_set_low().unwrap();
40+
delay.try_delay_ms(1_000_u16).unwrap();
4141
}
4242
}

examples/dynamic_gpio.rs

Lines changed: 7 additions & 7 deletions
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::digital::{InputPin, OutputPin};
1212
use stm32f1xx_hal::{pac, prelude::*, timer::Timer};
1313

1414
#[entry]
@@ -37,13 +37,13 @@ fn main() -> ! {
3737
// Wait for the timer to trigger an update and change the state of the LED
3838
loop {
3939
pin.make_floating_input(&mut gpioc.crh);
40-
block!(timer.wait()).unwrap();
41-
hprintln!("{}", pin.is_high().unwrap()).unwrap();
40+
block!(timer.try_wait()).unwrap();
41+
hprintln!("{}", pin.try_is_high().unwrap()).unwrap();
4242

4343
pin.make_push_pull_output(&mut gpioc.crh);
44-
pin.set_high().unwrap();
45-
block!(timer.wait()).unwrap();
46-
pin.set_low().unwrap();
47-
block!(timer.wait()).unwrap();
44+
pin.try_set_high().unwrap();
45+
block!(timer.try_wait()).unwrap();
46+
pin.try_set_low().unwrap();
47+
block!(timer.try_wait()).unwrap();
4848
}
4949
}

examples/exti.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn EXTI9_5() {
2929
let int_pin = unsafe { &mut *INT_PIN.as_mut_ptr() };
3030

3131
if int_pin.check_interrupt() {
32-
led.toggle().unwrap();
32+
led.try_toggle().unwrap();
3333

3434
// if we don't clear this bit, the ISR would trigger indefinitely
3535
int_pin.clear_interrupt_pending_bit();

examples/led.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use panic_halt as _;
1717

1818
use cortex_m_rt::entry;
19-
use embedded_hal::digital::v2::OutputPin;
19+
use embedded_hal::digital::OutputPin;
2020
use stm32f1xx_hal::{pac, prelude::*};
2121

2222
#[entry]
@@ -30,21 +30,21 @@ fn main() -> ! {
3030
gpioc
3131
.pc9
3232
.into_push_pull_output(&mut gpioc.crh)
33-
.set_high()
33+
.try_set_high()
3434
.unwrap();
3535

3636
#[cfg(feature = "stm32f101")]
3737
gpioc
3838
.pc9
3939
.into_push_pull_output(&mut gpioc.crh)
40-
.set_high()
40+
.try_set_high()
4141
.unwrap();
4242

4343
#[cfg(any(feature = "stm32f103", feature = "stm32f105", feature = "stm32f107"))]
4444
gpioc
4545
.pc13
4646
.into_push_pull_output(&mut gpioc.crh)
47-
.set_low()
47+
.try_set_low()
4848
.unwrap();
4949

5050
loop {}

examples/mfrc522.rs renamed to examples/mfrc522.rs.disabled

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

99
use cortex_m_rt::entry;
10-
use embedded_hal::digital::{v1_compat::OldOutputPin, v2::OutputPin};
10+
use embedded_hal::digital::OutputPin;
1111
use mfrc522::Mfrc522;
1212
use stm32f1xx_hal::{pac, prelude::*, spi::Spi};
1313

@@ -39,10 +39,10 @@ fn main() -> ! {
3939
);
4040

4141
let nss = gpioa.pa4.into_push_pull_output(&mut gpioa.crl);
42-
let mut mfrc522 = Mfrc522::new(spi, OldOutputPin::from(nss)).unwrap();
42+
let mut mfrc522 = Mfrc522::new(spi, nss).unwrap();
4343

4444
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
45-
led.set_high().unwrap();
45+
led.try_set_high().unwrap();
4646

4747
loop {
4848
if let Ok(atqa) = mfrc522.reqa() {

examples/multi_mode_gpio.rs

Lines changed: 10 additions & 10 deletions
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::digital::{InputPin, OutputPin};
1212
use stm32f1xx_hal::{gpio::State, pac, prelude::*, timer::Timer};
1313

1414
#[entry]
@@ -36,18 +36,18 @@ fn main() -> ! {
3636

3737
// Wait for the timer to trigger an update and change the state of the LED
3838
loop {
39-
block!(timer.wait()).unwrap();
40-
hprintln!("{}", pin.is_high().unwrap()).unwrap();
39+
block!(timer.try_wait()).unwrap();
40+
hprintln!("{}", pin.try_is_high().unwrap()).unwrap();
4141
pin.as_push_pull_output(&mut gpioc.crh, |out| {
42-
out.set_high().unwrap();
43-
block!(timer.wait()).unwrap();
44-
out.set_low().unwrap();
45-
block!(timer.wait()).unwrap();
42+
out.try_set_high().unwrap();
43+
block!(timer.try_wait()).unwrap();
44+
out.try_set_low().unwrap();
45+
block!(timer.try_wait()).unwrap();
4646
});
4747
pin.as_push_pull_output_with_state(&mut gpioc.crh, State::High, |out| {
48-
block!(timer.wait()).unwrap();
49-
out.set_low().unwrap();
50-
block!(timer.wait()).unwrap();
48+
block!(timer.try_wait()).unwrap();
49+
out.try_set_low().unwrap();
50+
block!(timer.try_wait()).unwrap();
5151
});
5252
}
5353
}

examples/nojtag.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ fn main() -> ! {
2525
let mut pb4 = pb4.into_push_pull_output(&mut gpiob.crl);
2626

2727
loop {
28-
pa15.toggle().unwrap();
29-
pb3.toggle().unwrap();
30-
pb4.toggle().unwrap();
28+
pa15.try_toggle().unwrap();
29+
pb3.try_toggle().unwrap();
30+
pb4.try_toggle().unwrap();
3131
cortex_m::asm::delay(8_000_000);
3232
}
3333
}

0 commit comments

Comments
 (0)