aboutsummaryrefslogtreecommitdiff
path: root/examples/nrf/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-08-05 19:25:12 +0200
committerGitHub <[email protected]>2021-08-05 19:25:12 +0200
commit8a65128cfed335e637ee80c91b1efc7b3c58ba10 (patch)
treef5b496e5ac141fb0914413ceed34c89d14d5d2c1 /examples/nrf/src
parenta4c0ee6df7cd54a3b31524e2c6aaf2b15b61a4d2 (diff)
parent05e50e1f4a2549a13491e8bb865c3e6d2038f875 (diff)
Merge pull request #338 from embassy-rs/time-driver
Remove dyn in time Clock/Alarm.
Diffstat (limited to 'examples/nrf/src')
-rw-r--r--examples/nrf/src/bin/blinky.rs1
-rw-r--r--examples/nrf/src/bin/executor_fairness_test.rs3
-rw-r--r--examples/nrf/src/bin/gpiote_channel.rs3
-rw-r--r--examples/nrf/src/bin/gpiote_port.rs2
-rw-r--r--examples/nrf/src/bin/mpsc.rs1
-rw-r--r--examples/nrf/src/bin/multiprio.rs18
-rw-r--r--examples/nrf/src/bin/ppi.rs3
-rw-r--r--examples/nrf/src/bin/pwm.rs4
-rw-r--r--examples/nrf/src/bin/raw_spawn.rs15
-rw-r--r--examples/nrf/src/bin/timer.rs1
10 files changed, 9 insertions, 42 deletions
diff --git a/examples/nrf/src/bin/blinky.rs b/examples/nrf/src/bin/blinky.rs
index 77b08b09b..6d4561beb 100644
--- a/examples/nrf/src/bin/blinky.rs
+++ b/examples/nrf/src/bin/blinky.rs
@@ -6,7 +6,6 @@
6#[path = "../example_common.rs"] 6#[path = "../example_common.rs"]
7mod example_common; 7mod example_common;
8 8
9use defmt::panic;
10use embassy::executor::Spawner; 9use embassy::executor::Spawner;
11use embassy::time::{Duration, Timer}; 10use embassy::time::{Duration, Timer};
12use embassy_nrf::gpio::{Level, Output, OutputDrive}; 11use embassy_nrf::gpio::{Level, Output, OutputDrive};
diff --git a/examples/nrf/src/bin/executor_fairness_test.rs b/examples/nrf/src/bin/executor_fairness_test.rs
index d874013f6..2d81a7551 100644
--- a/examples/nrf/src/bin/executor_fairness_test.rs
+++ b/examples/nrf/src/bin/executor_fairness_test.rs
@@ -8,10 +8,9 @@ mod example_common;
8use example_common::*; 8use example_common::*;
9 9
10use core::task::Poll; 10use core::task::Poll;
11use defmt::panic;
12use embassy::executor::Spawner; 11use embassy::executor::Spawner;
13use embassy::time::{Duration, Instant, Timer}; 12use embassy::time::{Duration, Instant, Timer};
14use embassy_nrf::{interrupt, Peripherals}; 13use embassy_nrf::Peripherals;
15 14
16#[embassy::task] 15#[embassy::task]
17async fn run1() { 16async fn run1() {
diff --git a/examples/nrf/src/bin/gpiote_channel.rs b/examples/nrf/src/bin/gpiote_channel.rs
index a132f846e..a96523e65 100644
--- a/examples/nrf/src/bin/gpiote_channel.rs
+++ b/examples/nrf/src/bin/gpiote_channel.rs
@@ -7,11 +7,10 @@
7mod example_common; 7mod example_common;
8use example_common::*; 8use example_common::*;
9 9
10use defmt::panic;
11use embassy::executor::Spawner; 10use embassy::executor::Spawner;
12use embassy_nrf::gpio::{Input, Pull}; 11use embassy_nrf::gpio::{Input, Pull};
13use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity}; 12use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity};
14use embassy_nrf::{interrupt, Peripherals}; 13use embassy_nrf::Peripherals;
15 14
16#[embassy::main] 15#[embassy::main]
17async fn main(_spawner: Spawner, p: Peripherals) { 16async fn main(_spawner: Spawner, p: Peripherals) {
diff --git a/examples/nrf/src/bin/gpiote_port.rs b/examples/nrf/src/bin/gpiote_port.rs
index a782d8935..700247d37 100644
--- a/examples/nrf/src/bin/gpiote_port.rs
+++ b/examples/nrf/src/bin/gpiote_port.rs
@@ -6,12 +6,10 @@
6#[path = "../example_common.rs"] 6#[path = "../example_common.rs"]
7mod example_common; 7mod example_common;
8 8
9use defmt::panic;
10use embassy::executor::Spawner; 9use embassy::executor::Spawner;
11use embassy::traits::gpio::{WaitForHigh, WaitForLow}; 10use embassy::traits::gpio::{WaitForHigh, WaitForLow};
12use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull}; 11use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull};
13use embassy_nrf::gpiote::PortInput; 12use embassy_nrf::gpiote::PortInput;
14use embassy_nrf::interrupt;
15use embassy_nrf::Peripherals; 13use embassy_nrf::Peripherals;
16use example_common::*; 14use example_common::*;
17 15
diff --git a/examples/nrf/src/bin/mpsc.rs b/examples/nrf/src/bin/mpsc.rs
index c4c0572bd..e31754eb8 100644
--- a/examples/nrf/src/bin/mpsc.rs
+++ b/examples/nrf/src/bin/mpsc.rs
@@ -6,7 +6,6 @@
6#[path = "../example_common.rs"] 6#[path = "../example_common.rs"]
7mod example_common; 7mod example_common;
8 8
9use defmt::panic;
10use embassy::executor::Spawner; 9use embassy::executor::Spawner;
11use embassy::time::{Duration, Timer}; 10use embassy::time::{Duration, Timer};
12use embassy::util::mpsc::TryRecvError; 11use embassy::util::mpsc::TryRecvError;
diff --git a/examples/nrf/src/bin/multiprio.rs b/examples/nrf/src/bin/multiprio.rs
index 7ce79168b..b91bbb740 100644
--- a/examples/nrf/src/bin/multiprio.rs
+++ b/examples/nrf/src/bin/multiprio.rs
@@ -68,7 +68,7 @@ use embassy::executor::{Executor, InterruptExecutor};
68use embassy::interrupt::InterruptExt; 68use embassy::interrupt::InterruptExt;
69use embassy::time::{Duration, Instant, Timer}; 69use embassy::time::{Duration, Instant, Timer};
70use embassy::util::Forever; 70use embassy::util::Forever;
71use embassy_nrf::{interrupt, peripherals, rtc}; 71use embassy_nrf::interrupt;
72 72
73#[embassy::task] 73#[embassy::task]
74async fn run_high() { 74async fn run_high() {
@@ -112,30 +112,20 @@ async fn run_low() {
112 } 112 }
113} 113}
114 114
115static RTC: Forever<rtc::RTC<peripherals::RTC1>> = Forever::new();
116static ALARM_HIGH: Forever<rtc::Alarm<peripherals::RTC1>> = Forever::new();
117static EXECUTOR_HIGH: Forever<InterruptExecutor<interrupt::SWI1_EGU1>> = Forever::new(); 115static EXECUTOR_HIGH: Forever<InterruptExecutor<interrupt::SWI1_EGU1>> = Forever::new();
118static ALARM_MED: Forever<rtc::Alarm<peripherals::RTC1>> = Forever::new();
119static EXECUTOR_MED: Forever<InterruptExecutor<interrupt::SWI0_EGU0>> = Forever::new(); 116static EXECUTOR_MED: Forever<InterruptExecutor<interrupt::SWI0_EGU0>> = Forever::new();
120static ALARM_LOW: Forever<rtc::Alarm<peripherals::RTC1>> = Forever::new();
121static EXECUTOR_LOW: Forever<Executor> = Forever::new(); 117static EXECUTOR_LOW: Forever<Executor> = Forever::new();
122 118
123#[entry] 119#[entry]
124fn main() -> ! { 120fn main() -> ! {
125 info!("Hello World!"); 121 info!("Hello World!");
126 122
127 let p = embassy_nrf::init(Default::default()); 123 let _p = embassy_nrf::init(Default::default());
128
129 let rtc = RTC.put(rtc::RTC::new(p.RTC1, interrupt::take!(RTC1)));
130 rtc.start();
131 unsafe { embassy::time::set_clock(rtc) };
132 124
133 // High-priority executor: SWI1_EGU1, priority level 6 125 // High-priority executor: SWI1_EGU1, priority level 6
134 let irq = interrupt::take!(SWI1_EGU1); 126 let irq = interrupt::take!(SWI1_EGU1);
135 irq.set_priority(interrupt::Priority::P6); 127 irq.set_priority(interrupt::Priority::P6);
136 let alarm = ALARM_HIGH.put(rtc.alarm2());
137 let executor = EXECUTOR_HIGH.put(InterruptExecutor::new(irq)); 128 let executor = EXECUTOR_HIGH.put(InterruptExecutor::new(irq));
138 executor.set_alarm(alarm);
139 executor.start(|spawner| { 129 executor.start(|spawner| {
140 unwrap!(spawner.spawn(run_high())); 130 unwrap!(spawner.spawn(run_high()));
141 }); 131 });
@@ -143,17 +133,13 @@ fn main() -> ! {
143 // Medium-priority executor: SWI0_EGU0, priority level 7 133 // Medium-priority executor: SWI0_EGU0, priority level 7
144 let irq = interrupt::take!(SWI0_EGU0); 134 let irq = interrupt::take!(SWI0_EGU0);
145 irq.set_priority(interrupt::Priority::P7); 135 irq.set_priority(interrupt::Priority::P7);
146 let alarm = ALARM_MED.put(rtc.alarm1());
147 let executor = EXECUTOR_MED.put(InterruptExecutor::new(irq)); 136 let executor = EXECUTOR_MED.put(InterruptExecutor::new(irq));
148 executor.set_alarm(alarm);
149 executor.start(|spawner| { 137 executor.start(|spawner| {
150 unwrap!(spawner.spawn(run_med())); 138 unwrap!(spawner.spawn(run_med()));
151 }); 139 });
152 140
153 // Low priority executor: runs in thread mode, using WFE/SEV 141 // Low priority executor: runs in thread mode, using WFE/SEV
154 let alarm = ALARM_LOW.put(rtc.alarm0());
155 let executor = EXECUTOR_LOW.put(Executor::new()); 142 let executor = EXECUTOR_LOW.put(Executor::new());
156 executor.set_alarm(alarm);
157 executor.run(|spawner| { 143 executor.run(|spawner| {
158 unwrap!(spawner.spawn(run_low())); 144 unwrap!(spawner.spawn(run_low()));
159 }); 145 });
diff --git a/examples/nrf/src/bin/ppi.rs b/examples/nrf/src/bin/ppi.rs
index 0bac875bd..2dc3fe1b7 100644
--- a/examples/nrf/src/bin/ppi.rs
+++ b/examples/nrf/src/bin/ppi.rs
@@ -8,12 +8,11 @@ mod example_common;
8use example_common::*; 8use example_common::*;
9 9
10use core::future::pending; 10use core::future::pending;
11use defmt::panic;
12use embassy::executor::Spawner; 11use embassy::executor::Spawner;
13use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; 12use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull};
14use embassy_nrf::gpiote::{self, InputChannel, InputChannelPolarity}; 13use embassy_nrf::gpiote::{self, InputChannel, InputChannelPolarity};
15use embassy_nrf::ppi::Ppi; 14use embassy_nrf::ppi::Ppi;
16use embassy_nrf::{interrupt, Peripherals}; 15use embassy_nrf::Peripherals;
17use gpiote::{OutputChannel, OutputChannelPolarity}; 16use gpiote::{OutputChannel, OutputChannelPolarity};
18 17
19#[embassy::main] 18#[embassy::main]
diff --git a/examples/nrf/src/bin/pwm.rs b/examples/nrf/src/bin/pwm.rs
index d2bc81cea..f30ad8f52 100644
--- a/examples/nrf/src/bin/pwm.rs
+++ b/examples/nrf/src/bin/pwm.rs
@@ -5,11 +5,11 @@
5 5
6#[path = "../example_common.rs"] 6#[path = "../example_common.rs"]
7mod example_common; 7mod example_common;
8use defmt::{panic, *}; 8use defmt::*;
9use embassy::executor::Spawner; 9use embassy::executor::Spawner;
10use embassy::time::{Duration, Timer}; 10use embassy::time::{Duration, Timer};
11use embassy_nrf::pwm::{Prescaler, Pwm}; 11use embassy_nrf::pwm::{Prescaler, Pwm};
12use embassy_nrf::{interrupt, Peripherals}; 12use embassy_nrf::Peripherals;
13 13
14// for i in range(1024): print(int((math.sin(i/512*math.pi)*0.4+0.5)**2*32767), ', ', end='') 14// for i in range(1024): print(int((math.sin(i/512*math.pi)*0.4+0.5)**2*32767), ', ', end='')
15static DUTY: [u16; 1024] = [ 15static DUTY: [u16; 1024] = [
diff --git a/examples/nrf/src/bin/raw_spawn.rs b/examples/nrf/src/bin/raw_spawn.rs
index 78de7b100..326dd9aac 100644
--- a/examples/nrf/src/bin/raw_spawn.rs
+++ b/examples/nrf/src/bin/raw_spawn.rs
@@ -7,13 +7,11 @@ use example_common::*;
7 7
8use core::mem; 8use core::mem;
9use cortex_m_rt::entry; 9use cortex_m_rt::entry;
10use defmt::panic; 10
11use embassy::executor::raw::Task; 11use embassy::executor::raw::Task;
12use embassy::executor::Executor; 12use embassy::executor::Executor;
13use embassy::time::{Duration, Timer}; 13use embassy::time::{Duration, Timer};
14use embassy::util::Forever; 14use embassy::util::Forever;
15use embassy_nrf::peripherals;
16use embassy_nrf::{interrupt, rtc};
17 15
18async fn run1() { 16async fn run1() {
19 loop { 17 loop {
@@ -29,23 +27,14 @@ async fn run2() {
29 } 27 }
30} 28}
31 29
32static RTC: Forever<rtc::RTC<peripherals::RTC1>> = Forever::new();
33static ALARM: Forever<rtc::Alarm<peripherals::RTC1>> = Forever::new();
34static EXECUTOR: Forever<Executor> = Forever::new(); 30static EXECUTOR: Forever<Executor> = Forever::new();
35 31
36#[entry] 32#[entry]
37fn main() -> ! { 33fn main() -> ! {
38 info!("Hello World!"); 34 info!("Hello World!");
39 35
40 let p = embassy_nrf::init(Default::default()); 36 let _p = embassy_nrf::init(Default::default());
41
42 let rtc = RTC.put(rtc::RTC::new(p.RTC1, interrupt::take!(RTC1)));
43 rtc.start();
44 unsafe { embassy::time::set_clock(rtc) };
45
46 let alarm = ALARM.put(rtc.alarm0());
47 let executor = EXECUTOR.put(Executor::new()); 37 let executor = EXECUTOR.put(Executor::new());
48 executor.set_alarm(alarm);
49 38
50 let run1_task = Task::new(); 39 let run1_task = Task::new();
51 let run2_task = Task::new(); 40 let run2_task = Task::new();
diff --git a/examples/nrf/src/bin/timer.rs b/examples/nrf/src/bin/timer.rs
index 630ea87a5..60cbe5a0f 100644
--- a/examples/nrf/src/bin/timer.rs
+++ b/examples/nrf/src/bin/timer.rs
@@ -8,7 +8,6 @@ mod example_common;
8use embassy_nrf::Peripherals; 8use embassy_nrf::Peripherals;
9use example_common::*; 9use example_common::*;
10 10
11use defmt::panic;
12use embassy::executor::Spawner; 11use embassy::executor::Spawner;
13use embassy::time::{Duration, Timer}; 12use embassy::time::{Duration, Timer};
14 13