Skip to content

Commit 4301d80

Browse files
Fix remaining examples
1 parent 1df5dac commit 4301d80

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

examples/button_irq.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ use cortex_m::interrupt::Mutex;
1111
use cortex_m::peripheral::NVIC;
1212
use cortex_m_rt::entry;
1313
use stm32l0xx_hal::{
14-
exti::TriggerEdge,
14+
exti::{TriggerEdge, line::{GpioLine, ExtiLine}},
1515
gpio::*,
1616
pac::{self, interrupt, Interrupt, EXTI},
1717
prelude::*,
1818
rcc::Config,
1919
syscfg::SYSCFG,
2020
};
2121

22-
static INT: Mutex<RefCell<Option<EXTI>>> = Mutex::new(RefCell::new(None));
2322
static LED: Mutex<RefCell<Option<gpiob::PB6<Output<PushPull>>>>> = Mutex::new(RefCell::new(None));
2423

2524
#[entry]
@@ -42,13 +41,13 @@ fn main() -> ! {
4241
let mut syscfg = SYSCFG::new(dp.SYSCFG, &mut rcc);
4342

4443
// Configure the external interrupt on the falling edge for the pin 0.
45-
let exti = dp.EXTI;
46-
exti.listen(&mut syscfg, button.port(), button.pin_number(), TriggerEdge::Falling);
44+
let line = GpioLine::from_raw_line(button.pin_number()).unwrap();
45+
let mut exti = dp.EXTI;
46+
exti.listen_gpio(&mut syscfg, button.port(), line, TriggerEdge::Falling);
4747

4848
// Store the external interrupt and LED in mutex reffcells to make them
4949
// available from the interrupt.
5050
cortex_m::interrupt::free(|cs| {
51-
*INT.borrow(cs).borrow_mut() = Some(exti);
5251
*LED.borrow(cs).borrow_mut() = Some(led);
5352
});
5453

@@ -66,19 +65,17 @@ fn EXTI2_3() {
6665
static mut STATE: bool = false;
6766

6867
cortex_m::interrupt::free(|cs| {
69-
if let Some(ref mut exti) = INT.borrow(cs).borrow_mut().deref_mut() {
70-
// Clear the interrupt flag.
71-
exti.clear_irq(2);
72-
73-
// Change the LED state on each interrupt.
74-
if let Some(ref mut led) = LED.borrow(cs).borrow_mut().deref_mut() {
75-
if *STATE {
76-
led.set_low().unwrap();
77-
*STATE = false;
78-
} else {
79-
led.set_high().unwrap();
80-
*STATE = true;
81-
}
68+
// Clear the interrupt flag.
69+
EXTI::unpend(GpioLine::from_raw_line(2).unwrap());
70+
71+
// Change the LED state on each interrupt.
72+
if let Some(ref mut led) = LED.borrow(cs).borrow_mut().deref_mut() {
73+
if *STATE {
74+
led.set_low().unwrap();
75+
*STATE = false;
76+
} else {
77+
led.set_high().unwrap();
78+
*STATE = true;
8279
}
8380
}
8481
});

examples/button_irq_rtfm.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
extern crate panic_halt;
77

88
use rtfm::app;
9-
use stm32l0xx_hal::{exti::TriggerEdge, gpio::*, pac, prelude::*, rcc::Config, syscfg::SYSCFG};
9+
use stm32l0xx_hal::{
10+
exti::{TriggerEdge, EXTI, line::{GpioLine, ExtiLine}},
11+
gpio::*,
12+
pac,
13+
prelude::*,
14+
rcc::Config,
15+
syscfg::SYSCFG,
16+
};
1017

1118
#[app(device = stm32l0xx_hal::pac)]
1219
const APP: () = {
@@ -31,8 +38,9 @@ const APP: () = {
3138
let mut syscfg = SYSCFG::new(device.SYSCFG, &mut rcc);
3239

3340
// Configure the external interrupt on the falling edge for the pin 0.
34-
let exti = device.EXTI;
35-
exti.listen(&mut syscfg, button.port(), button.pin_number(), TriggerEdge::Falling);
41+
let line = GpioLine::from_raw_line(button.pin_number()).unwrap();
42+
let mut exti = device.EXTI;
43+
exti.listen_gpio(&mut syscfg, button.port(), line, TriggerEdge::Falling);
3644

3745
// Return the initialised resources.
3846
init::LateResources {
@@ -46,7 +54,7 @@ const APP: () = {
4654
static mut STATE: bool = false;
4755

4856
// Clear the interrupt flag.
49-
resources.INT.clear_irq(0);
57+
EXTI::unpend(GpioLine::from_raw_line(0).unwrap());
5058

5159
// Change the LED state on each interrupt.
5260
if *STATE {

0 commit comments

Comments
 (0)