Skip to content

Commit

Permalink
finished first interrupt example
Browse files Browse the repository at this point in the history
  • Loading branch information
BartMassey committed Oct 26, 2024
1 parent 43b9f45 commit 04e3ca9
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions mdbook/src/14-interrupts/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -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",
]
17 changes: 17 additions & 0 deletions mdbook/src/14-interrupts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
11 changes: 11 additions & 0 deletions mdbook/src/14-interrupts/Embed.toml
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions mdbook/src/14-interrupts/examples/poke.rs
Original file line number Diff line number Diff line change
@@ -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();
}
}
30 changes: 30 additions & 0 deletions mdbook/src/14-interrupts/examples/timer.rs
Original file line number Diff line number Diff line change
@@ -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<Mutex<RefCell

#[interrupt]
fn TIMER0() {
rprintln!("tick");
}

#[entry]
fn main() -> ! {

}

0 comments on commit 04e3ca9

Please sign in to comment.