-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0cae3e
commit d285aca
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#![no_main] | ||
#![no_std] | ||
|
||
use core::cell::RefCell; | ||
|
||
use cortex_m::asm; | ||
use cortex_m_rt::entry; | ||
use critical_section::Mutex; | ||
use panic_rtt_target as _; | ||
use rtt_target::{rprintln, rtt_init_print}; | ||
|
||
use microbit::{ | ||
Board, | ||
hal::{ | ||
gpiote, | ||
pac::{self, interrupt}, | ||
}, | ||
}; | ||
|
||
static COUNTER: AtomicUsize = AtomicUsize::new(0); | ||
static GPIOTE_Peripheral: LockMut<gpiote::Gpiote> = LockMut::new(); | ||
|
||
/// This "function" will be called when an interrupt is received. For now, just | ||
/// report and panic. | ||
#[interrupt] | ||
fn GPIOTE() { | ||
let mut count = COUNTER.fetch_add(1, AcqRel); | ||
rprintln!("ouch {}", count + 1); | ||
GPIOTE_Peripheral.with(|gpiote| { | ||
// TODO | ||
}); | ||
panic!(); | ||
} | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
rtt_init_print!(); | ||
let board = Board::take().unwrap(); | ||
let button_a = board.buttons.button_a.into_floating_input(); | ||
|
||
// Set up the GPIOTE to generate an interrupt when Button A is pressed (GPIO | ||
// wire goes low). | ||
let gpiote = gpiote::Gpiote::new(board.GPIOTE); | ||
let channel = gpiote.channel0(); | ||
channel | ||
.input_pin(&button_a.degrade()) | ||
.hi_to_lo() | ||
.enable_interrupt(); | ||
channel.reset_events(); | ||
|
||
// Set up the NVIC to handle GPIO interrupts. | ||
unsafe { pac::NVIC::unmask(pac::Interrupt::GPIOTE) }; | ||
pac::NVIC::unpend(pac::Interrupt::GPIOTE); | ||
|
||
loop { | ||
// "wait for interrupt": CPU goes to sleep until an interrupt. | ||
asm::wfi(); | ||
} | ||
} |