aboutsummaryrefslogtreecommitdiff
path: root/examples/nrf/src
diff options
context:
space:
mode:
Diffstat (limited to 'examples/nrf/src')
-rw-r--r--examples/nrf/src/bin/channel.rs4
-rw-r--r--examples/nrf/src/bin/channel_sender_receiver.rs10
-rw-r--r--examples/nrf/src/bin/multiprio.rs14
-rw-r--r--examples/nrf/src/bin/mutex.rs4
-rw-r--r--examples/nrf/src/bin/pubsub.rs4
-rw-r--r--examples/nrf/src/bin/raw_spawn.rs6
-rw-r--r--examples/nrf/src/bin/uart_split.rs4
-rw-r--r--examples/nrf/src/bin/usb_ethernet.rs18
-rw-r--r--examples/nrf/src/bin/usb_hid_keyboard.rs4
-rw-r--r--examples/nrf/src/bin/usb_serial_multitask.rs6
10 files changed, 37 insertions, 37 deletions
diff --git a/examples/nrf/src/bin/channel.rs b/examples/nrf/src/bin/channel.rs
index 195200988..d782a79e7 100644
--- a/examples/nrf/src/bin/channel.rs
+++ b/examples/nrf/src/bin/channel.rs
@@ -5,9 +5,9 @@
5use defmt::unwrap; 5use defmt::unwrap;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_nrf::gpio::{Level, Output, OutputDrive}; 7use embassy_nrf::gpio::{Level, Output, OutputDrive};
8use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
9use embassy_sync::channel::Channel;
8use embassy_time::{Duration, Timer}; 10use embassy_time::{Duration, Timer};
9use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
10use embassy_util::channel::mpmc::Channel;
11use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
12 12
13enum LedState { 13enum LedState {
diff --git a/examples/nrf/src/bin/channel_sender_receiver.rs b/examples/nrf/src/bin/channel_sender_receiver.rs
index c9c458aec..fcccdaed5 100644
--- a/examples/nrf/src/bin/channel_sender_receiver.rs
+++ b/examples/nrf/src/bin/channel_sender_receiver.rs
@@ -5,10 +5,10 @@
5use defmt::unwrap; 5use defmt::unwrap;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin}; 7use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin};
8use embassy_sync::blocking_mutex::raw::NoopRawMutex;
9use embassy_sync::channel::{Channel, Receiver, Sender};
8use embassy_time::{Duration, Timer}; 10use embassy_time::{Duration, Timer};
9use embassy_util::blocking_mutex::raw::NoopRawMutex; 11use static_cell::StaticCell;
10use embassy_util::channel::mpmc::{Channel, Receiver, Sender};
11use embassy_util::Forever;
12use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
13 13
14enum LedState { 14enum LedState {
@@ -16,7 +16,7 @@ enum LedState {
16 Off, 16 Off,
17} 17}
18 18
19static CHANNEL: Forever<Channel<NoopRawMutex, LedState, 1>> = Forever::new(); 19static CHANNEL: StaticCell<Channel<NoopRawMutex, LedState, 1>> = StaticCell::new();
20 20
21#[embassy_executor::task] 21#[embassy_executor::task]
22async fn send_task(sender: Sender<'static, NoopRawMutex, LedState, 1>) { 22async fn send_task(sender: Sender<'static, NoopRawMutex, LedState, 1>) {
@@ -43,7 +43,7 @@ async fn recv_task(led: AnyPin, receiver: Receiver<'static, NoopRawMutex, LedSta
43#[embassy_executor::main] 43#[embassy_executor::main]
44async fn main(spawner: Spawner) { 44async fn main(spawner: Spawner) {
45 let p = embassy_nrf::init(Default::default()); 45 let p = embassy_nrf::init(Default::default());
46 let channel = CHANNEL.put(Channel::new()); 46 let channel = CHANNEL.init(Channel::new());
47 47
48 unwrap!(spawner.spawn(send_task(channel.sender()))); 48 unwrap!(spawner.spawn(send_task(channel.sender())));
49 unwrap!(spawner.spawn(recv_task(p.P0_13.degrade(), channel.receiver()))); 49 unwrap!(spawner.spawn(recv_task(p.P0_13.degrade(), channel.receiver())));
diff --git a/examples/nrf/src/bin/multiprio.rs b/examples/nrf/src/bin/multiprio.rs
index b653689a7..25806ae48 100644
--- a/examples/nrf/src/bin/multiprio.rs
+++ b/examples/nrf/src/bin/multiprio.rs
@@ -63,7 +63,7 @@ use embassy_nrf::executor::{Executor, InterruptExecutor};
63use embassy_nrf::interrupt; 63use embassy_nrf::interrupt;
64use embassy_nrf::interrupt::InterruptExt; 64use embassy_nrf::interrupt::InterruptExt;
65use embassy_time::{Duration, Instant, Timer}; 65use embassy_time::{Duration, Instant, Timer};
66use embassy_util::Forever; 66use static_cell::StaticCell;
67use {defmt_rtt as _, panic_probe as _}; 67use {defmt_rtt as _, panic_probe as _};
68 68
69#[embassy_executor::task] 69#[embassy_executor::task]
@@ -108,9 +108,9 @@ async fn run_low() {
108 } 108 }
109} 109}
110 110
111static EXECUTOR_HIGH: Forever<InterruptExecutor<interrupt::SWI1_EGU1>> = Forever::new(); 111static EXECUTOR_HIGH: StaticCell<InterruptExecutor<interrupt::SWI1_EGU1>> = StaticCell::new();
112static EXECUTOR_MED: Forever<InterruptExecutor<interrupt::SWI0_EGU0>> = Forever::new(); 112static EXECUTOR_MED: StaticCell<InterruptExecutor<interrupt::SWI0_EGU0>> = StaticCell::new();
113static EXECUTOR_LOW: Forever<Executor> = Forever::new(); 113static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new();
114 114
115#[entry] 115#[entry]
116fn main() -> ! { 116fn main() -> ! {
@@ -121,19 +121,19 @@ fn main() -> ! {
121 // High-priority executor: SWI1_EGU1, priority level 6 121 // High-priority executor: SWI1_EGU1, priority level 6
122 let irq = interrupt::take!(SWI1_EGU1); 122 let irq = interrupt::take!(SWI1_EGU1);
123 irq.set_priority(interrupt::Priority::P6); 123 irq.set_priority(interrupt::Priority::P6);
124 let executor = EXECUTOR_HIGH.put(InterruptExecutor::new(irq)); 124 let executor = EXECUTOR_HIGH.init(InterruptExecutor::new(irq));
125 let spawner = executor.start(); 125 let spawner = executor.start();
126 unwrap!(spawner.spawn(run_high())); 126 unwrap!(spawner.spawn(run_high()));
127 127
128 // Medium-priority executor: SWI0_EGU0, priority level 7 128 // Medium-priority executor: SWI0_EGU0, priority level 7
129 let irq = interrupt::take!(SWI0_EGU0); 129 let irq = interrupt::take!(SWI0_EGU0);
130 irq.set_priority(interrupt::Priority::P7); 130 irq.set_priority(interrupt::Priority::P7);
131 let executor = EXECUTOR_MED.put(InterruptExecutor::new(irq)); 131 let executor = EXECUTOR_MED.init(InterruptExecutor::new(irq));
132 let spawner = executor.start(); 132 let spawner = executor.start();
133 unwrap!(spawner.spawn(run_med())); 133 unwrap!(spawner.spawn(run_med()));
134 134
135 // Low priority executor: runs in thread mode, using WFE/SEV 135 // Low priority executor: runs in thread mode, using WFE/SEV
136 let executor = EXECUTOR_LOW.put(Executor::new()); 136 let executor = EXECUTOR_LOW.init(Executor::new());
137 executor.run(|spawner| { 137 executor.run(|spawner| {
138 unwrap!(spawner.spawn(run_low())); 138 unwrap!(spawner.spawn(run_low()));
139 }); 139 });
diff --git a/examples/nrf/src/bin/mutex.rs b/examples/nrf/src/bin/mutex.rs
index 876297883..c402c6ba1 100644
--- a/examples/nrf/src/bin/mutex.rs
+++ b/examples/nrf/src/bin/mutex.rs
@@ -4,9 +4,9 @@
4 4
5use defmt::{info, unwrap}; 5use defmt::{info, unwrap};
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
8use embassy_sync::mutex::Mutex;
7use embassy_time::{Duration, Timer}; 9use embassy_time::{Duration, Timer};
8use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
9use embassy_util::mutex::Mutex;
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12static MUTEX: Mutex<ThreadModeRawMutex, u32> = Mutex::new(0); 12static MUTEX: Mutex<ThreadModeRawMutex, u32> = Mutex::new(0);
diff --git a/examples/nrf/src/bin/pubsub.rs b/examples/nrf/src/bin/pubsub.rs
index 1d90217f2..688e6d075 100644
--- a/examples/nrf/src/bin/pubsub.rs
+++ b/examples/nrf/src/bin/pubsub.rs
@@ -4,9 +4,9 @@
4 4
5use defmt::unwrap; 5use defmt::unwrap;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
8use embassy_sync::pubsub::{DynSubscriber, PubSubChannel, Subscriber};
7use embassy_time::{Duration, Timer}; 9use embassy_time::{Duration, Timer};
8use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
9use embassy_util::channel::pubsub::{DynSubscriber, PubSubChannel, Subscriber};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
11 11
12/// Create the message bus. It has a queue of 4, supports 3 subscribers and 1 publisher 12/// Create the message bus. It has a queue of 4, supports 3 subscribers and 1 publisher
diff --git a/examples/nrf/src/bin/raw_spawn.rs b/examples/nrf/src/bin/raw_spawn.rs
index 415579be7..1b067f5e4 100644
--- a/examples/nrf/src/bin/raw_spawn.rs
+++ b/examples/nrf/src/bin/raw_spawn.rs
@@ -8,7 +8,7 @@ use defmt::{info, unwrap};
8use embassy_executor::raw::TaskStorage; 8use embassy_executor::raw::TaskStorage;
9use embassy_executor::Executor; 9use embassy_executor::Executor;
10use embassy_time::{Duration, Timer}; 10use embassy_time::{Duration, Timer};
11use embassy_util::Forever; 11use static_cell::StaticCell;
12use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
13 13
14async fn run1() { 14async fn run1() {
@@ -25,14 +25,14 @@ async fn run2() {
25 } 25 }
26} 26}
27 27
28static EXECUTOR: Forever<Executor> = Forever::new(); 28static EXECUTOR: StaticCell<Executor> = StaticCell::new();
29 29
30#[entry] 30#[entry]
31fn main() -> ! { 31fn main() -> ! {
32 info!("Hello World!"); 32 info!("Hello World!");
33 33
34 let _p = embassy_nrf::init(Default::default()); 34 let _p = embassy_nrf::init(Default::default());
35 let executor = EXECUTOR.put(Executor::new()); 35 let executor = EXECUTOR.init(Executor::new());
36 36
37 let run1_task = TaskStorage::new(); 37 let run1_task = TaskStorage::new();
38 let run2_task = TaskStorage::new(); 38 let run2_task = TaskStorage::new();
diff --git a/examples/nrf/src/bin/uart_split.rs b/examples/nrf/src/bin/uart_split.rs
index dab8e475d..1adaf53fd 100644
--- a/examples/nrf/src/bin/uart_split.rs
+++ b/examples/nrf/src/bin/uart_split.rs
@@ -7,8 +7,8 @@ use embassy_executor::Spawner;
7use embassy_nrf::peripherals::UARTE0; 7use embassy_nrf::peripherals::UARTE0;
8use embassy_nrf::uarte::UarteRx; 8use embassy_nrf::uarte::UarteRx;
9use embassy_nrf::{interrupt, uarte}; 9use embassy_nrf::{interrupt, uarte};
10use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; 10use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
11use embassy_util::channel::mpmc::Channel; 11use embassy_sync::channel::Channel;
12use {defmt_rtt as _, panic_probe as _}; 12use {defmt_rtt as _, panic_probe as _};
13 13
14static CHANNEL: Channel<ThreadModeRawMutex, [u8; 8], 1> = Channel::new(); 14static CHANNEL: Channel<ThreadModeRawMutex, [u8; 8], 1> = Channel::new();
diff --git a/examples/nrf/src/bin/usb_ethernet.rs b/examples/nrf/src/bin/usb_ethernet.rs
index f0a870317..ca6c7e0d1 100644
--- a/examples/nrf/src/bin/usb_ethernet.rs
+++ b/examples/nrf/src/bin/usb_ethernet.rs
@@ -14,21 +14,21 @@ use embassy_net::{PacketBox, PacketBoxExt, PacketBuf, Stack, StackResources};
14use embassy_nrf::rng::Rng; 14use embassy_nrf::rng::Rng;
15use embassy_nrf::usb::{Driver, PowerUsb}; 15use embassy_nrf::usb::{Driver, PowerUsb};
16use embassy_nrf::{interrupt, pac, peripherals}; 16use embassy_nrf::{interrupt, pac, peripherals};
17use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
18use embassy_sync::channel::Channel;
17use embassy_usb::{Builder, Config, UsbDevice}; 19use embassy_usb::{Builder, Config, UsbDevice};
18use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; 20use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State};
19use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
20use embassy_util::channel::mpmc::Channel;
21use embassy_util::Forever;
22use embedded_io::asynch::{Read, Write}; 21use embedded_io::asynch::{Read, Write};
22use static_cell::StaticCell;
23use {defmt_rtt as _, panic_probe as _}; 23use {defmt_rtt as _, panic_probe as _};
24 24
25type MyDriver = Driver<'static, peripherals::USBD, PowerUsb>; 25type MyDriver = Driver<'static, peripherals::USBD, PowerUsb>;
26 26
27macro_rules! forever { 27macro_rules! singleton {
28 ($val:expr) => {{ 28 ($val:expr) => {{
29 type T = impl Sized; 29 type T = impl Sized;
30 static FOREVER: Forever<T> = Forever::new(); 30 static STATIC_CELL: StaticCell<T> = StaticCell::new();
31 FOREVER.put_with(move || $val) 31 STATIC_CELL.init_with(move || $val)
32 }}; 32 }};
33} 33}
34 34
@@ -116,7 +116,7 @@ async fn main(spawner: Spawner) {
116 control_buf: [u8; 128], 116 control_buf: [u8; 128],
117 serial_state: State<'static>, 117 serial_state: State<'static>,
118 } 118 }
119 let res: &mut Resources = forever!(Resources { 119 let res: &mut Resources = singleton!(Resources {
120 device_descriptor: [0; 256], 120 device_descriptor: [0; 256],
121 config_descriptor: [0; 256], 121 config_descriptor: [0; 256],
122 bos_descriptor: [0; 256], 122 bos_descriptor: [0; 256],
@@ -174,10 +174,10 @@ async fn main(spawner: Spawner) {
174 174
175 // Init network stack 175 // Init network stack
176 let device = Device { mac_addr: our_mac_addr }; 176 let device = Device { mac_addr: our_mac_addr };
177 let stack = &*forever!(Stack::new( 177 let stack = &*singleton!(Stack::new(
178 device, 178 device,
179 config, 179 config,
180 forever!(StackResources::<1, 2, 8>::new()), 180 singleton!(StackResources::<1, 2, 8>::new()),
181 seed 181 seed
182 )); 182 ));
183 183
diff --git a/examples/nrf/src/bin/usb_hid_keyboard.rs b/examples/nrf/src/bin/usb_hid_keyboard.rs
index cf0078eec..ba2159c72 100644
--- a/examples/nrf/src/bin/usb_hid_keyboard.rs
+++ b/examples/nrf/src/bin/usb_hid_keyboard.rs
@@ -8,14 +8,14 @@ use core::sync::atomic::{AtomicBool, Ordering};
8 8
9use defmt::*; 9use defmt::*;
10use embassy_executor::Spawner; 10use embassy_executor::Spawner;
11use embassy_futures::{select, Either};
11use embassy_nrf::gpio::{Input, Pin, Pull}; 12use embassy_nrf::gpio::{Input, Pin, Pull};
12use embassy_nrf::usb::{Driver, PowerUsb}; 13use embassy_nrf::usb::{Driver, PowerUsb};
13use embassy_nrf::{interrupt, pac}; 14use embassy_nrf::{interrupt, pac};
15use embassy_sync::signal::Signal;
14use embassy_usb::control::OutResponse; 16use embassy_usb::control::OutResponse;
15use embassy_usb::{Builder, Config, DeviceStateHandler}; 17use embassy_usb::{Builder, Config, DeviceStateHandler};
16use embassy_usb_hid::{HidReaderWriter, ReportId, RequestHandler, State}; 18use embassy_usb_hid::{HidReaderWriter, ReportId, RequestHandler, State};
17use embassy_util::channel::signal::Signal;
18use embassy_util::{select, Either};
19use futures::future::join; 19use futures::future::join;
20use usbd_hid::descriptor::{KeyboardReport, SerializedDescriptor}; 20use usbd_hid::descriptor::{KeyboardReport, SerializedDescriptor};
21use {defmt_rtt as _, panic_probe as _}; 21use {defmt_rtt as _, panic_probe as _};
diff --git a/examples/nrf/src/bin/usb_serial_multitask.rs b/examples/nrf/src/bin/usb_serial_multitask.rs
index 4c1a93087..d62d7e520 100644
--- a/examples/nrf/src/bin/usb_serial_multitask.rs
+++ b/examples/nrf/src/bin/usb_serial_multitask.rs
@@ -12,7 +12,7 @@ use embassy_nrf::{interrupt, pac, peripherals};
12use embassy_usb::driver::EndpointError; 12use embassy_usb::driver::EndpointError;
13use embassy_usb::{Builder, Config, UsbDevice}; 13use embassy_usb::{Builder, Config, UsbDevice};
14use embassy_usb_serial::{CdcAcmClass, State}; 14use embassy_usb_serial::{CdcAcmClass, State};
15use embassy_util::Forever; 15use static_cell::StaticCell;
16use {defmt_rtt as _, panic_probe as _}; 16use {defmt_rtt as _, panic_probe as _};
17 17
18type MyDriver = Driver<'static, peripherals::USBD, PowerUsb>; 18type MyDriver = Driver<'static, peripherals::USBD, PowerUsb>;
@@ -67,8 +67,8 @@ async fn main(spawner: Spawner) {
67 control_buf: [u8; 64], 67 control_buf: [u8; 64],
68 serial_state: State<'static>, 68 serial_state: State<'static>,
69 } 69 }
70 static RESOURCES: Forever<Resources> = Forever::new(); 70 static RESOURCES: StaticCell<Resources> = StaticCell::new();
71 let res = RESOURCES.put(Resources { 71 let res = RESOURCES.init(Resources {
72 device_descriptor: [0; 256], 72 device_descriptor: [0; 256],
73 config_descriptor: [0; 256], 73 config_descriptor: [0; 256],
74 bos_descriptor: [0; 256], 74 bos_descriptor: [0; 256],