Skip to content

Instantly share code, notes, and snippets.

@trimoq
Created December 24, 2021 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trimoq/73f9fb23b4efcb280d351721e830d7f4 to your computer and use it in GitHub Desktop.
Save trimoq/73f9fb23b4efcb280d351721e830d7f4 to your computer and use it in GitHub Desktop.
// ...
static G_LED: Mutex<RefCell<Option<LedPin>>> = Mutex::new(RefCell::new(None));
#[entry]
fn main() -> ! {
// ...
let mut led = setup.gpioa.pa5.into_push_pull_output();
cortex_m::interrupt::free(|cs| {
*G_LED.borrow(cs).borrow_mut() = Some(led);
});
unsafe {
cortex_m::peripheral::NVIC::unmask(pac::Interrupt::EXTI15_10);
}
loop {
wfi(); // do nothing
}
}
#[interrupt]
fn EXTI15_10() {
cortex_m::interrupt::free(|cs| {
G_LED
.borrow(cs)
.borrow_mut()
.as_mut()
.unwrap()
.toggle();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment