diff --git a/Cargo.toml b/Cargo.toml index 1bc81f8..548ef71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ members = [ "mdbook/src/11-i2c", "mdbook/src/12-led-compass", "mdbook/src/13-punch-o-meter", + "mdbook/src/14-interrupts", "mdbook/src/14-snake-game", "mdbook/src/appendix/3-mag-calibration", "mdbook/src/serial-setup", diff --git a/mdbook/src/14-interrupts/.cargo/config.toml b/mdbook/src/14-interrupts/.cargo/config.toml new file mode 100644 index 0000000..e4ad7f5 --- /dev/null +++ b/mdbook/src/14-interrupts/.cargo/config.toml @@ -0,0 +1,8 @@ +[build] +target = "thumbv7em-none-eabihf" + +[target.thumbv7em-none-eabihf] +runner = "probe-rs run --chip nRF52833_xxAA" +rustflags = [ + "-C", "linker=rust-lld", +] diff --git a/mdbook/src/14-interrupts/Cargo.toml b/mdbook/src/14-interrupts/Cargo.toml new file mode 100644 index 0000000..520c46c --- /dev/null +++ b/mdbook/src/14-interrupts/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "interrupts" +version = "0.1.0" +edition = "2021" + +[dependencies] +microbit-v2 = "0.15" +cortex-m-rt = "0.7" +rtt-target = "0.5" +panic-rtt-target = "0.1" +heapless = "0.8" +tiny-led-matrix = "1.0" +embedded-hal = "1.0" + +[dependencies.cortex-m] +version = "0.7" +features = ["critical-section-single-core"] diff --git a/mdbook/src/14-interrupts/Embed.toml b/mdbook/src/14-interrupts/Embed.toml new file mode 100644 index 0000000..2195013 --- /dev/null +++ b/mdbook/src/14-interrupts/Embed.toml @@ -0,0 +1,11 @@ +[default.general] +chip = "nrf52833_xxAA" # micro:bit V2 + +[default.reset] +halt_afterwards = false + +[default.rtt] +enabled = true + +[default.gdb] +enabled = false diff --git a/mdbook/src/14-interrupts/examples/poke.rs b/mdbook/src/14-interrupts/examples/poke.rs new file mode 100644 index 0000000..5e452dd --- /dev/null +++ b/mdbook/src/14-interrupts/examples/poke.rs @@ -0,0 +1,40 @@ +#![no_main] +#![no_std] + +use cortex_m::asm; +use cortex_m_rt::entry; +use panic_rtt_target as _; +use rtt_target::{rprintln, rtt_init_print}; + +use microbit::{ + Board, + hal::{ + gpiote, + pac::{self, interrupt}, + }, +}; + +#[interrupt] +fn GPIOTE() { + rprintln!("ouch"); + asm::bkpt(); +} + +#[entry] +fn main() -> ! { + rtt_init_print!(); + let board = Board::take().unwrap(); + let button_a = board.buttons.button_a.into_floating_input(); + let gpiote = gpiote::Gpiote::new(board.GPIOTE); + let channel = gpiote.channel0(); + channel + .input_pin(&button_a.degrade()) + .lo_to_hi() + .enable_interrupt(); + channel.reset_events(); + unsafe { pac::NVIC::unmask(pac::Interrupt::GPIOTE) }; + pac::NVIC::unpend(pac::Interrupt::GPIOTE); + loop { + asm::wfe(); + } +} diff --git a/mdbook/src/14-interrupts/examples/timer.rs b/mdbook/src/14-interrupts/examples/timer.rs new file mode 100644 index 0000000..ed5b1dc --- /dev/null +++ b/mdbook/src/14-interrupts/examples/timer.rs @@ -0,0 +1,30 @@ +#![no_main] +#![no_std] + +use cortex_m::asm; +use cortex_m_rt::entry; +use panic_rtt_target as _; +use rtt_target::{rprintln, rtt_init_print}; + +use microbit::hal::{ + gpio, + gpiote, + pac::{self, interrupt}, + timer, +}; + +struct Blinker { + period: u32, + timer: timer::Timer<> + +static BLINKER: Option ! { + +}