Skip to content

Commit 3d7a303

Browse files
author
Jonas Schievink
committed
Update PACs and example dependencies
1 parent edce43c commit 3d7a303

File tree

46 files changed

+723
-764
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+723
-764
lines changed

examples/blinky-button-demo/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ edition = "2018"
99
[dependencies]
1010
cortex-m = "0.7.3"
1111
cortex-m-rt = "0.7.0"
12-
rtt-target = {version = "0.2.0", features = ["cortex-m"] }
12+
rtt-target = { version = "0.3.1", features = ["cortex-m"] }
1313
nrf52832-hal = { features = ["rt"], path = "../../nrf52832-hal" }
1414

1515
[dependencies.embedded-hal]

examples/ccm-demo/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ publish = false
88
[dependencies]
99
cortex-m = "0.7.3"
1010
cortex-m-rt = "0.7.0"
11-
rtt-target = {version = "0.2.0", features = ["cortex-m"] }
11+
rtt-target = { version = "0.3.1", features = ["cortex-m"] }
1212
rand_core = "0.6.3"
1313

1414
nrf52810-hal = { path = "../../nrf52810-hal", features = ["rt"], optional = true }

examples/comp-demo/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ publish = false
1010
[dependencies]
1111
cortex-m = "0.7.3"
1212
cortex-m-rt = { version = "0.7.0", features = ["device"] }
13-
cortex-m-rtic = { version = "0.5.9", features = ["cortex-m-7"], default-features = false }
13+
cortex-m-rtic = { version = "1.0.0", default-features = false }
1414
rtt-target = { version = "0.3.1", features = ["cortex-m"] }
1515
nrf52840-hal = { features = ["rt"], path = "../../nrf52840-hal" }
1616

examples/comp-demo/src/main.rs

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
11
#![no_std]
22
#![no_main]
33

4-
use embedded_hal::digital::v2::OutputPin;
5-
use {
6-
core::{
7-
panic::PanicInfo,
8-
sync::atomic::{compiler_fence, Ordering},
9-
},
10-
hal::{
11-
comp::*,
12-
gpio::{Level, Output, Pin, PushPull},
13-
},
14-
nrf52840_hal as hal,
15-
rtt_target::{rprintln, rtt_init_print},
16-
};
4+
use {core::panic::PanicInfo, rtt_target::rprintln};
175

18-
#[rtic::app(device = crate::hal::pac, peripherals = true)]
19-
const APP: () = {
20-
struct Resources {
6+
#[rtic::app(device = nrf52840_hal::pac, peripherals = true)]
7+
mod app {
8+
use embedded_hal::digital::v2::OutputPin;
9+
use nrf52840_hal::clocks::Clocks;
10+
use nrf52840_hal::comp::*;
11+
use nrf52840_hal::gpio::{self, Level, Output, Pin, PushPull};
12+
use rtt_target::{rprintln, rtt_init_print};
13+
14+
#[shared]
15+
struct Shared {}
16+
17+
#[local]
18+
struct Local {
2119
comp: Comp,
2220
led1: Pin<Output<PushPull>>,
2321
}
2422

2523
#[init]
26-
fn init(ctx: init::Context) -> init::LateResources {
27-
let _clocks = hal::clocks::Clocks::new(ctx.device.CLOCK).enable_ext_hfosc();
24+
fn init(ctx: init::Context) -> (Shared, Local, init::Monotonics) {
25+
let _clocks = Clocks::new(ctx.device.CLOCK).enable_ext_hfosc();
2826
rtt_init_print!();
2927

30-
let p0 = hal::gpio::p0::Parts::new(ctx.device.P0);
28+
let p0 = gpio::p0::Parts::new(ctx.device.P0);
3129
let led1 = p0.p0_13.into_push_pull_output(Level::High).degrade();
3230
let in_pin = p0.p0_30.into_floating_input();
3331
let ref_pin = p0.p0_31.into_floating_input();
@@ -38,31 +36,29 @@ const APP: () = {
3836
.enable_interrupt(Transition::Cross)
3937
.enable();
4038

41-
init::LateResources { comp, led1 }
39+
(Shared {}, Local { comp, led1 }, init::Monotonics())
4240
}
4341

44-
#[task(binds = COMP_LPCOMP, resources = [comp, led1])]
42+
#[task(binds = COMP_LPCOMP, local = [comp, led1])]
4543
fn on_comp(ctx: on_comp::Context) {
46-
ctx.resources.comp.reset_event(Transition::Cross);
47-
match ctx.resources.comp.read() {
44+
ctx.local.comp.reset_event(Transition::Cross);
45+
match ctx.local.comp.read() {
4846
CompResult::Above => {
4947
rprintln!("Vin > Vref");
50-
ctx.resources.led1.set_low().ok();
48+
ctx.local.led1.set_low().ok();
5149
}
5250
CompResult::Below => {
5351
rprintln!("Vin < Vref");
54-
ctx.resources.led1.set_high().ok();
52+
ctx.local.led1.set_high().ok();
5553
}
5654
}
5755
}
58-
};
56+
}
5957

6058
#[inline(never)]
6159
#[panic_handler]
6260
fn panic(info: &PanicInfo) -> ! {
6361
cortex_m::interrupt::disable();
6462
rprintln!("{}", info);
65-
loop {
66-
compiler_fence(Ordering::SeqCst);
67-
}
63+
loop {}
6864
}

examples/gpiote-demo/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ edition = "2018"
99
[dependencies]
1010
cortex-m = "0.7.3"
1111
cortex-m-rt = { version = "0.7.0", features = ["device"] }
12-
cortex-m-rtic = { version = "0.5.9", features = ["cortex-m-7"], default-features = false }
12+
cortex-m-rtic = { version = "1.0.0", default-features = false }
13+
systick-monotonic = "1.0.0"
1314
rtt-target = { version = "0.3.1", features = ["cortex-m"] }
1415
nrf52840-hal = { features = ["rt"], path = "../../nrf52840-hal" }
1516

examples/gpiote-demo/src/main.rs

Lines changed: 71 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
11
#![no_std]
22
#![no_main]
33

4-
use embedded_hal::digital::v2::InputPin;
5-
use {
6-
core::{
7-
panic::PanicInfo,
8-
sync::atomic::{compiler_fence, Ordering},
9-
},
10-
hal::{
11-
gpio::{Input, Level, Pin, PullUp},
12-
gpiote::*,
13-
ppi::{self, ConfigurablePpi, Ppi},
14-
},
15-
nrf52840_hal as hal,
16-
rtic::cyccnt::U32Ext,
17-
rtt_target::{rprintln, rtt_init_print},
18-
};
19-
20-
#[rtic::app(device = crate::hal::pac, peripherals = true, monotonic = rtic::cyccnt::CYCCNT)]
21-
const APP: () = {
22-
struct Resources {
4+
use {core::panic::PanicInfo, nrf52840_hal as hal, rtt_target::rprintln};
5+
6+
#[rtic::app(device = crate::hal::pac, peripherals = true, dispatchers = [SWI0_EGU0])]
7+
mod app {
8+
use embedded_hal::digital::v2::InputPin;
9+
use systick_monotonic::*;
10+
use {
11+
hal::{
12+
gpio::{Input, Level, Pin, PullUp},
13+
gpiote::*,
14+
ppi::{self, ConfigurablePpi, Ppi},
15+
},
16+
nrf52840_hal as hal,
17+
rtt_target::{rprintln, rtt_init_print},
18+
};
19+
20+
#[monotonic(binds = SysTick, default = true)]
21+
type Timer = Systick<1_000_000>;
22+
23+
#[shared]
24+
struct Shared {
2325
gpiote: Gpiote,
26+
}
27+
28+
#[local]
29+
struct Local {
2430
btn1: Pin<Input<PullUp>>,
2531
btn3: Pin<Input<PullUp>>,
2632
btn4: Pin<Input<PullUp>>,
2733
}
2834

2935
#[init]
30-
fn init(mut ctx: init::Context) -> init::LateResources {
36+
fn init(ctx: init::Context) -> (Shared, Local, init::Monotonics) {
3137
let _clocks = hal::clocks::Clocks::new(ctx.device.CLOCK).enable_ext_hfosc();
3238
rtt_init_print!();
3339
let p0 = hal::gpio::p0::Parts::new(ctx.device.P0);
@@ -65,75 +71,63 @@ const APP: () = {
6571
ppi0.set_event_endpoint(gpiote.channel2().event());
6672
ppi0.enable();
6773

68-
// Enable the monotonic timer (CYCCNT)
69-
ctx.core.DCB.enable_trace();
70-
ctx.core.DWT.enable_cycle_counter();
74+
let mono = Systick::new(ctx.core.SYST, 64_000_000);
7175

7276
rprintln!("Press a button");
7377

74-
init::LateResources {
75-
gpiote,
76-
btn1,
77-
btn3,
78-
btn4,
79-
}
80-
}
81-
82-
#[idle]
83-
fn idle(_: idle::Context) -> ! {
84-
loop {
85-
cortex_m::asm::wfi();
86-
}
78+
(
79+
Shared { gpiote },
80+
Local { btn1, btn3, btn4 },
81+
init::Monotonics(mono),
82+
)
8783
}
8884

89-
#[task(binds = GPIOTE, resources = [gpiote], schedule = [debounce])]
90-
fn on_gpiote(ctx: on_gpiote::Context) {
91-
if ctx.resources.gpiote.channel0().is_event_triggered() {
92-
rprintln!("Interrupt from channel 0 event");
93-
}
94-
if ctx.resources.gpiote.port().is_event_triggered() {
95-
rprintln!("Interrupt from port event");
96-
}
97-
// Reset all events
98-
ctx.resources.gpiote.reset_events();
99-
// Debounce
100-
ctx.schedule.debounce(ctx.start + 3_000_000.cycles()).ok();
85+
#[task(binds = GPIOTE, shared = [gpiote])]
86+
fn on_gpiote(mut ctx: on_gpiote::Context) {
87+
ctx.shared.gpiote.lock(|gpiote| {
88+
if gpiote.channel0().is_event_triggered() {
89+
rprintln!("Interrupt from channel 0 event");
90+
}
91+
if gpiote.port().is_event_triggered() {
92+
rprintln!("Interrupt from port event");
93+
}
94+
// Reset all events
95+
gpiote.reset_events();
96+
// Debounce
97+
debounce::spawn_after(50.millis()).ok();
98+
});
10199
}
102100

103-
#[task(resources = [gpiote, btn1, btn3, btn4])]
104-
fn debounce(ctx: debounce::Context) {
105-
let btn1_pressed = ctx.resources.btn1.is_low().unwrap();
106-
let btn3_pressed = ctx.resources.btn3.is_low().unwrap();
107-
let btn4_pressed = ctx.resources.btn4.is_low().unwrap();
108-
109-
if btn1_pressed {
110-
rprintln!("Button 1 was pressed!");
111-
// Manually run "task out" operation (toggle) on channel 1 (toggles led1)
112-
ctx.resources.gpiote.channel1().out();
113-
}
114-
if btn3_pressed {
115-
rprintln!("Button 3 was pressed!");
116-
// Manually run "task clear" on channel 1 (led1 on)
117-
ctx.resources.gpiote.channel1().clear();
118-
}
119-
if btn4_pressed {
120-
rprintln!("Button 4 was pressed!");
121-
// Manually run "task set" on channel 1 (led1 off)
122-
ctx.resources.gpiote.channel1().set();
123-
}
101+
#[task(shared = [gpiote], local = [btn1, btn3, btn4])]
102+
fn debounce(mut ctx: debounce::Context) {
103+
let btn1_pressed = ctx.local.btn1.is_low().unwrap();
104+
let btn3_pressed = ctx.local.btn3.is_low().unwrap();
105+
let btn4_pressed = ctx.local.btn4.is_low().unwrap();
106+
107+
ctx.shared.gpiote.lock(|gpiote| {
108+
if btn1_pressed {
109+
rprintln!("Button 1 was pressed!");
110+
// Manually run "task out" operation (toggle) on channel 1 (toggles led1)
111+
gpiote.channel1().out();
112+
}
113+
if btn3_pressed {
114+
rprintln!("Button 3 was pressed!");
115+
// Manually run "task clear" on channel 1 (led1 on)
116+
gpiote.channel1().clear();
117+
}
118+
if btn4_pressed {
119+
rprintln!("Button 4 was pressed!");
120+
// Manually run "task set" on channel 1 (led1 off)
121+
gpiote.channel1().set();
122+
}
123+
});
124124
}
125-
126-
extern "C" {
127-
fn SWI0_EGU0();
128-
}
129-
};
125+
}
130126

131127
#[inline(never)]
132128
#[panic_handler]
133129
fn panic(info: &PanicInfo) -> ! {
134130
cortex_m::interrupt::disable();
135131
rprintln!("{}", info);
136-
loop {
137-
compiler_fence(Ordering::SeqCst);
138-
}
132+
loop {}
139133
}

examples/i2s-controller-demo/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ publish = false
1010
[dependencies]
1111
cortex-m = "0.7.3"
1212
cortex-m-rt = { version = "0.7.0", features = ["device"] }
13-
cortex-m-rtic = { version = "0.5.9", features = ["cortex-m-7"], default-features = false }
13+
cortex-m-rtic = { version = "1.0.0", default-features = false }
14+
systick-monotonic = "1.0.0"
1415
rtt-target = { version = "0.3.1", features = ["cortex-m"] }
1516
nrf52840-hal = { features = ["rt"], path = "../../nrf52840-hal" }
16-
heapless = "0.5.5"
17+
heapless = "0.7.10"
1718
small_morse = "0.1.0"
1819

1920
[dependencies.embedded-hal]

0 commit comments

Comments
 (0)