Skip to content

Commit e086879

Browse files
authored
Merge pull request #72 from jonas-schievink/exti-cleanup
Further EXTI cleanups/enhancements
2 parents fb1f6a6 + a2f8a28 commit e086879

File tree

9 files changed

+240
-248
lines changed

9 files changed

+240
-248
lines changed

examples/button_irq.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ use cortex_m::interrupt::Mutex;
1111
use cortex_m::peripheral::NVIC;
1212
use cortex_m_rt::entry;
1313
use stm32l0xx_hal::{
14-
exti::{TriggerEdge, line::{GpioLine, ExtiLine}},
14+
exti::{TriggerEdge, GpioLine, ExtiLine, Exti},
1515
gpio::*,
16-
pac::{self, interrupt, Interrupt, EXTI},
16+
pac::{self, interrupt, Interrupt},
1717
prelude::*,
1818
rcc::Config,
1919
syscfg::SYSCFG,
@@ -39,10 +39,10 @@ fn main() -> ! {
3939
let button = gpiob.pb2.into_pull_up_input();
4040

4141
let mut syscfg = SYSCFG::new(dp.SYSCFG, &mut rcc);
42+
let mut exti = Exti::new(dp.EXTI);
4243

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

4848
// Store the external interrupt and LED in mutex reffcells to make them
@@ -66,7 +66,7 @@ fn EXTI2_3() {
6666

6767
cortex_m::interrupt::free(|cs| {
6868
// Clear the interrupt flag.
69-
EXTI::unpend(GpioLine::from_raw_line(2).unwrap());
69+
Exti::unpend(GpioLine::from_raw_line(2).unwrap());
7070

7171
// Change the LED state on each interrupt.
7272
if let Some(ref mut led) = LED.borrow(cs).borrow_mut().deref_mut() {

examples/button_irq_rtfm.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ extern crate panic_halt;
77

88
use rtfm::app;
99
use stm32l0xx_hal::{
10-
exti::{TriggerEdge, EXTI, line::{GpioLine, ExtiLine}},
10+
exti::{TriggerEdge, Exti, GpioLine, ExtiLine},
1111
gpio::*,
12-
pac,
1312
prelude::*,
1413
rcc::Config,
1514
syscfg::SYSCFG,
@@ -18,7 +17,7 @@ use stm32l0xx_hal::{
1817
#[app(device = stm32l0xx_hal::pac)]
1918
const APP: () = {
2019
static mut LED: gpiob::PB6<Output<PushPull>> = ();
21-
static mut INT: pac::EXTI = ();
20+
static mut INT: Exti = ();
2221

2322
#[init]
2423
fn init() -> init::LateResources {
@@ -36,10 +35,10 @@ const APP: () = {
3635
let button = gpiob.pb2.into_pull_up_input();
3736

3837
let mut syscfg = SYSCFG::new(device.SYSCFG, &mut rcc);
38+
let mut exti = Exti::new(device.EXTI);
3939

4040
// Configure the external interrupt on the falling edge for the pin 0.
4141
let line = GpioLine::from_raw_line(button.pin_number()).unwrap();
42-
let mut exti = device.EXTI;
4342
exti.listen_gpio(&mut syscfg, button.port(), line, TriggerEdge::Falling);
4443

4544
// Return the initialised resources.
@@ -54,7 +53,7 @@ const APP: () = {
5453
static mut STATE: bool = false;
5554

5655
// Clear the interrupt flag.
57-
EXTI::unpend(GpioLine::from_raw_line(0).unwrap());
56+
Exti::unpend(GpioLine::from_raw_line(0).unwrap());
5857

5958
// Change the LED state on each interrupt.
6059
if *STATE {

examples/exti_wakeup.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate panic_halt;
55

66
use cortex_m_rt::entry;
77
use stm32l0xx_hal::{
8-
exti::{self, line::{GpioLine, ExtiLine}}, pac,
8+
exti::{Exti, TriggerEdge, GpioLine, ExtiLine}, pac,
99
prelude::*,
1010
pwr::{self, PWR},
1111
rcc::Config,
@@ -19,7 +19,7 @@ fn main() -> ! {
1919

2020
let mut rcc = dp.RCC.freeze(Config::hsi16());
2121
let gpiob = dp.GPIOB.split(&mut rcc);
22-
let mut exti = dp.EXTI;
22+
let mut exti = Exti::new(dp.EXTI);
2323
let mut pwr = PWR::new(dp.PWR, &mut rcc);
2424
let mut delay = cp.SYST.delay(rcc.clocks);
2525
let mut scb = cp.SCB;
@@ -37,7 +37,7 @@ fn main() -> ! {
3737
&mut syscfg,
3838
button.port(),
3939
line,
40-
exti::TriggerEdge::Falling,
40+
TriggerEdge::Falling,
4141
);
4242

4343
loop {

examples/lptim.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ use cortex_m::{asm, peripheral::NVIC};
1111
use cortex_m_rt::entry;
1212
use stm32l0xx_hal::{
1313
prelude::*,
14-
exti::{
15-
line::DirectLine,
16-
},
14+
exti::{Exti, DirectLine},
1715
gpio::{
1816
Output,
1917
PushPull,
@@ -24,10 +22,7 @@ use stm32l0xx_hal::{
2422
LpTimer,
2523
ClockSrc,
2624
},
27-
pac::{
28-
self,
29-
EXTI,
30-
},
25+
pac,
3126
pwr::{
3227
self,
3328
PWR,
@@ -43,7 +38,7 @@ fn main() -> ! {
4338

4439
let mut scb = cp.SCB;
4540
let mut rcc = dp.RCC.freeze(rcc::Config::msi(rcc::MSIRange::Range0));
46-
let mut exti = dp.EXTI;
41+
let mut exti = Exti::new(dp.EXTI);
4742
let mut pwr = PWR::new(dp.PWR, &mut rcc);
4843
let gpiob = dp.GPIOB.split(&mut rcc);
4944

@@ -67,7 +62,7 @@ fn main() -> ! {
6762
lptim.start(1.hz());
6863
block!(lptim.wait()).unwrap();
6964

70-
EXTI::unpend(exti_line);
65+
Exti::unpend(exti_line);
7166
NVIC::unpend(pac::Interrupt::LPTIM1);
7267

7368
blink(&mut led);
@@ -76,7 +71,7 @@ fn main() -> ! {
7671
pwr.enter_low_power_run_mode(rcc.clocks);
7772
block!(lptim.wait()).unwrap();
7873
pwr.exit_low_power_run_mode();
79-
EXTI::unpend(exti_line);
74+
Exti::unpend(exti_line);
8075
NVIC::unpend(pac::Interrupt::LPTIM1);
8176

8277
blink(&mut led);
@@ -87,7 +82,7 @@ fn main() -> ! {
8782
pwr.sleep_mode(&mut scb),
8883
);
8984
lptim.wait().unwrap(); // returns immediately; we just got the interrupt
90-
EXTI::unpend(exti_line);
85+
Exti::unpend(exti_line);
9186
NVIC::unpend(pac::Interrupt::LPTIM1);
9287

9388
blink(&mut led);
@@ -98,7 +93,7 @@ fn main() -> ! {
9893
pwr.low_power_sleep_mode(&mut scb, &mut rcc),
9994
);
10095
lptim.wait().unwrap(); // returns immediately; we just got the interrupt
101-
EXTI::unpend(exti_line);
96+
Exti::unpend(exti_line);
10297
NVIC::unpend(pac::Interrupt::LPTIM1);
10398

10499
blink(&mut led);

examples/pwr.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,16 @@ use cortex_m_rt::entry;
1010
use stm32l0xx_hal::{
1111
prelude::*,
1212
exti::{
13-
self,
14-
line::ConfigurableLine,
13+
Exti,
14+
ConfigurableLine,
15+
TriggerEdge,
1516
},
1617
gpio::{
1718
Output,
1819
PushPull,
1920
gpiob::PB,
2021
},
21-
pac::{
22-
self,
23-
EXTI,
24-
},
22+
pac,
2523
pwr::{
2624
self,
2725
PWR,
@@ -42,7 +40,7 @@ fn main() -> ! {
4240

4341
let mut scb = cp.SCB;
4442
let mut rcc = dp.RCC.freeze(rcc::Config::msi(rcc::MSIRange::Range0));
45-
let mut exti = dp.EXTI;
43+
let mut exti = Exti::new(dp.EXTI);
4644
let mut pwr = PWR::new(dp.PWR, &mut rcc);
4745
let gpiob = dp.GPIOB.split(&mut rcc);
4846

@@ -66,7 +64,7 @@ fn main() -> ! {
6664
});
6765
exti.listen_configurable(
6866
exti_line,
69-
exti::TriggerEdge::Rising,
67+
TriggerEdge::Rising,
7068
);
7169

7270
let mut timer = rtc.wakeup_timer();
@@ -78,7 +76,7 @@ fn main() -> ! {
7876
// 5 seconds of regular run mode
7977
timer.start(5u32);
8078
while let Err(nb::Error::WouldBlock) = timer.wait() {}
81-
EXTI::unpend(exti_line);
79+
Exti::unpend(exti_line);
8280
NVIC::unpend(pac::Interrupt::RTC);
8381

8482
blink(&mut led);
@@ -87,7 +85,7 @@ fn main() -> ! {
8785
pwr.enter_low_power_run_mode(rcc.clocks);
8886
while let Err(nb::Error::WouldBlock) = timer.wait() {}
8987
pwr.exit_low_power_run_mode();
90-
EXTI::unpend(exti_line);
88+
Exti::unpend(exti_line);
9189
NVIC::unpend(pac::Interrupt::RTC);
9290

9391
blink(&mut led);

examples/rtc_wakeup.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ extern crate panic_halt;
55

66
use cortex_m_rt::entry;
77
use stm32l0xx_hal::{
8-
exti::{self, line::ConfigurableLine}, pac,
8+
exti::{Exti, ConfigurableLine, TriggerEdge},
9+
pac,
910
prelude::*,
1011
pwr::PWR,
1112
rcc,
@@ -28,7 +29,7 @@ fn main() -> ! {
2829
led.set_high().unwrap();
2930

3031
let mut scb = cp.SCB;
31-
let mut exti = dp.EXTI;
32+
let mut exti = Exti::new(dp.EXTI);
3233
let mut pwr = PWR::new(dp.PWR, &mut rcc);
3334

3435
let instant = Instant::new()
@@ -49,7 +50,7 @@ fn main() -> ! {
4950
});
5051
exti.listen_configurable(
5152
exti_line,
52-
exti::TriggerEdge::Rising,
53+
TriggerEdge::Rising,
5354
);
5455

5556
while button.is_low().unwrap() {}

0 commit comments

Comments
 (0)