Skip to content

Commit 3940511

Browse files
committed
Adapt to embedded-hal 1.0.0-alpha.1
1 parent 0f23be5 commit 3940511

28 files changed

+278
-236
lines changed

Cargo.toml

+2-9
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,16 @@ 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
as-slice = "0.1"
24-
25-
[dependencies.void]
26-
default-features = false
27-
version = "1.0.2"
24+
embedded-hal = "=1.0.0-alpha.1"
2825

2926
[dependencies.cast]
3027
default-features = false
3128
version = "0.2.2"
3229

33-
[dependencies.embedded-hal]
34-
version = "0.2.3"
35-
features = ["unproven"]
36-
3730
[dependencies.stm32-usbd]
3831
version = "0.5.0"
3932
features = ["ram_access_1x16"]

examples/adc.rs

+2-2
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

+5-5
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

+5-5
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

+3-3
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_timer_irq.rs

+4-4
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

+5-5
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

+7-7
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

+1-1
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

+4-4
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

+3-3
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

+10-10
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

+3-3
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
}

examples/pwm.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -59,50 +59,50 @@ fn main() -> ! {
5959
//// Operations affecting all defined channels on the Timer
6060

6161
// Adjust period to 0.5 seconds
62-
pwm.set_period(500.ms());
62+
pwm.try_set_period(500.ms()).unwrap();
6363

6464
asm::bkpt();
6565

6666
// Return to the original frequency
67-
pwm.set_period(1.khz());
67+
pwm.try_set_period(1.khz()).unwrap();
6868

6969
asm::bkpt();
7070

71-
let max = pwm.get_max_duty();
71+
let max = pwm.try_get_max_duty().unwrap();
7272

7373
//// Operations affecting single channels can be accessed through
7474
//// the Pwm object or via dereferencing to the pin.
7575

7676
// Use the Pwm object to set C3 to full strength
77-
pwm.set_duty(Channel::C3, max);
77+
pwm.try_set_duty(Channel::C3, max).unwrap();
7878

7979
asm::bkpt();
8080

8181
// Use the Pwm object to set C3 to be dim
82-
pwm.set_duty(Channel::C3, max / 4);
82+
pwm.try_set_duty(Channel::C3, max / 4).unwrap();
8383

8484
asm::bkpt();
8585

8686
// Use the Pwm object to set C3 to be zero
87-
pwm.set_duty(Channel::C3, 0);
87+
pwm.try_set_duty(Channel::C3, 0).unwrap();
8888

8989
asm::bkpt();
9090

9191
// Extract the PwmChannel for C3
9292
let mut pwm_channel = pwm.split().2;
9393

9494
// Use the PwmChannel object to set C3 to be full strength
95-
pwm_channel.set_duty(max);
95+
pwm_channel.try_set_duty(max).unwrap();
9696

9797
asm::bkpt();
9898

9999
// Use the PwmChannel object to set C3 to be dim
100-
pwm_channel.set_duty(max / 4);
100+
pwm_channel.try_set_duty(max / 4).unwrap();
101101

102102
asm::bkpt();
103103

104104
// Use the PwmChannel object to set C3 to be zero
105-
pwm_channel.set_duty(0);
105+
pwm_channel.try_set_duty(0).unwrap();
106106

107107
asm::bkpt();
108108

0 commit comments

Comments
 (0)