Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further EXTI cleanups/enhancements #72

Merged
merged 6 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/button_irq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use cortex_m::interrupt::Mutex;
use cortex_m::peripheral::NVIC;
use cortex_m_rt::entry;
use stm32l0xx_hal::{
exti::{TriggerEdge, line::{GpioLine, ExtiLine}},
exti::{TriggerEdge, GpioLine, ExtiLine, Exti},
gpio::*,
pac::{self, interrupt, Interrupt, EXTI},
pac::{self, interrupt, Interrupt},
prelude::*,
rcc::Config,
syscfg::SYSCFG,
Expand All @@ -39,10 +39,10 @@ fn main() -> ! {
let button = gpiob.pb2.into_pull_up_input();

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

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

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

cortex_m::interrupt::free(|cs| {
// Clear the interrupt flag.
EXTI::unpend(GpioLine::from_raw_line(2).unwrap());
Exti::unpend(GpioLine::from_raw_line(2).unwrap());

// Change the LED state on each interrupt.
if let Some(ref mut led) = LED.borrow(cs).borrow_mut().deref_mut() {
Expand Down
9 changes: 4 additions & 5 deletions examples/button_irq_rtfm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ extern crate panic_halt;

use rtfm::app;
use stm32l0xx_hal::{
exti::{TriggerEdge, EXTI, line::{GpioLine, ExtiLine}},
exti::{TriggerEdge, Exti, GpioLine, ExtiLine},
gpio::*,
pac,
prelude::*,
rcc::Config,
syscfg::SYSCFG,
Expand All @@ -18,7 +17,7 @@ use stm32l0xx_hal::{
#[app(device = stm32l0xx_hal::pac)]
const APP: () = {
static mut LED: gpiob::PB6<Output<PushPull>> = ();
static mut INT: pac::EXTI = ();
static mut INT: Exti = ();

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

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

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

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

// Clear the interrupt flag.
EXTI::unpend(GpioLine::from_raw_line(0).unwrap());
Exti::unpend(GpioLine::from_raw_line(0).unwrap());

// Change the LED state on each interrupt.
if *STATE {
Expand Down
6 changes: 3 additions & 3 deletions examples/exti_wakeup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extern crate panic_halt;

use cortex_m_rt::entry;
use stm32l0xx_hal::{
exti::{self, line::{GpioLine, ExtiLine}}, pac,
exti::{Exti, TriggerEdge, GpioLine, ExtiLine}, pac,
prelude::*,
pwr::{self, PWR},
rcc::Config,
Expand All @@ -19,7 +19,7 @@ fn main() -> ! {

let mut rcc = dp.RCC.freeze(Config::hsi16());
let gpiob = dp.GPIOB.split(&mut rcc);
let mut exti = dp.EXTI;
let mut exti = Exti::new(dp.EXTI);
let mut pwr = PWR::new(dp.PWR, &mut rcc);
let mut delay = cp.SYST.delay(rcc.clocks);
let mut scb = cp.SCB;
Expand All @@ -37,7 +37,7 @@ fn main() -> ! {
&mut syscfg,
button.port(),
line,
exti::TriggerEdge::Falling,
TriggerEdge::Falling,
);

loop {
Expand Down
19 changes: 7 additions & 12 deletions examples/lptim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use cortex_m::{asm, peripheral::NVIC};
use cortex_m_rt::entry;
use stm32l0xx_hal::{
prelude::*,
exti::{
line::DirectLine,
},
exti::{Exti, DirectLine},
gpio::{
Output,
PushPull,
Expand All @@ -24,10 +22,7 @@ use stm32l0xx_hal::{
LpTimer,
ClockSrc,
},
pac::{
self,
EXTI,
},
pac,
pwr::{
self,
PWR,
Expand All @@ -43,7 +38,7 @@ fn main() -> ! {

let mut scb = cp.SCB;
let mut rcc = dp.RCC.freeze(rcc::Config::msi(rcc::MSIRange::Range0));
let mut exti = dp.EXTI;
let mut exti = Exti::new(dp.EXTI);
let mut pwr = PWR::new(dp.PWR, &mut rcc);
let gpiob = dp.GPIOB.split(&mut rcc);

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

EXTI::unpend(exti_line);
Exti::unpend(exti_line);
NVIC::unpend(pac::Interrupt::LPTIM1);

blink(&mut led);
Expand All @@ -76,7 +71,7 @@ fn main() -> ! {
pwr.enter_low_power_run_mode(rcc.clocks);
block!(lptim.wait()).unwrap();
pwr.exit_low_power_run_mode();
EXTI::unpend(exti_line);
Exti::unpend(exti_line);
NVIC::unpend(pac::Interrupt::LPTIM1);

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

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

blink(&mut led);
Expand Down
18 changes: 8 additions & 10 deletions examples/pwr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ use cortex_m_rt::entry;
use stm32l0xx_hal::{
prelude::*,
exti::{
self,
line::ConfigurableLine,
Exti,
ConfigurableLine,
TriggerEdge,
},
gpio::{
Output,
PushPull,
gpiob::PB,
},
pac::{
self,
EXTI,
},
pac,
pwr::{
self,
PWR,
Expand All @@ -42,7 +40,7 @@ fn main() -> ! {

let mut scb = cp.SCB;
let mut rcc = dp.RCC.freeze(rcc::Config::msi(rcc::MSIRange::Range0));
let mut exti = dp.EXTI;
let mut exti = Exti::new(dp.EXTI);
let mut pwr = PWR::new(dp.PWR, &mut rcc);
let gpiob = dp.GPIOB.split(&mut rcc);

Expand All @@ -66,7 +64,7 @@ fn main() -> ! {
});
exti.listen_configurable(
exti_line,
exti::TriggerEdge::Rising,
TriggerEdge::Rising,
);

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

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

blink(&mut led);
Expand Down
7 changes: 4 additions & 3 deletions examples/rtc_wakeup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ extern crate panic_halt;

use cortex_m_rt::entry;
use stm32l0xx_hal::{
exti::{self, line::ConfigurableLine}, pac,
exti::{Exti, ConfigurableLine, TriggerEdge},
pac,
prelude::*,
pwr::PWR,
rcc,
Expand All @@ -28,7 +29,7 @@ fn main() -> ! {
led.set_high().unwrap();

let mut scb = cp.SCB;
let mut exti = dp.EXTI;
let mut exti = Exti::new(dp.EXTI);
let mut pwr = PWR::new(dp.PWR, &mut rcc);

let instant = Instant::new()
Expand All @@ -49,7 +50,7 @@ fn main() -> ! {
});
exti.listen_configurable(
exti_line,
exti::TriggerEdge::Rising,
TriggerEdge::Rising,
);

while button.is_low().unwrap() {}
Expand Down
Loading