aboutsummaryrefslogtreecommitdiff
path: root/examples/nrf
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-02-12 00:30:47 +0000
committerGitHub <[email protected]>2022-02-12 00:30:47 +0000
commite728a32672d9cb108d73ba017a6a153dbc6c2d15 (patch)
tree25cdf290d138929ebf0ff292fc6934e0a266400a /examples/nrf
parentd708be7fe5e8fec8f2feea269fcb6964b6c73dcb (diff)
parent1904906b363d2bbe32e95546f53201a3179dcb60 (diff)
Merge #613
613: Rust stable support r=Dirbaio a=Dirbaio This PR adds (limited) stable Rust support! The drawbacks are: - No `#[embassy::task]`, `#[embassy::main]`. (requires `type_alias_impl_trait`). You have to manually allocate the tasks somewhere they'll live forever. See [example](https://github.com/embassy-rs/embassy/blob/master/examples/nrf/src/bin/raw_spawn.rs) - No async trait impls (requires GATs). Note that the full API surface of HALs is still available through inherent methods: #552 #581 - Some stuff is not constructible in const (requires `const_fn_trait_bound`), although there's an (ugly) workaround for the generic `Mutex`. So it's not that bad in the end, it's fully usable for shipping production-ready firmwares. We'll still recommend nightly as the default, until GATs and `type_alias_impl_trait` are stable. Co-authored-by: Dario Nieuwenhuis <[email protected]>
Diffstat (limited to 'examples/nrf')
-rw-r--r--examples/nrf/Cargo.toml3
-rw-r--r--examples/nrf/src/bin/mpsc.rs6
-rw-r--r--examples/nrf/src/bin/uart_split.rs6
3 files changed, 9 insertions, 6 deletions
diff --git a/examples/nrf/Cargo.toml b/examples/nrf/Cargo.toml
index da16bcbaf..2d9c99530 100644
--- a/examples/nrf/Cargo.toml
+++ b/examples/nrf/Cargo.toml
@@ -4,6 +4,9 @@ edition = "2018"
4name = "embassy-nrf-examples" 4name = "embassy-nrf-examples"
5version = "0.1.0" 5version = "0.1.0"
6 6
7[features]
8default = ["nightly"]
9nightly = ["embassy-nrf/nightly"]
7 10
8[dependencies] 11[dependencies]
9embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } 12embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
diff --git a/examples/nrf/src/bin/mpsc.rs b/examples/nrf/src/bin/mpsc.rs
index 454fb9541..d50736d82 100644
--- a/examples/nrf/src/bin/mpsc.rs
+++ b/examples/nrf/src/bin/mpsc.rs
@@ -6,7 +6,7 @@
6mod example_common; 6mod example_common;
7 7
8use defmt::unwrap; 8use defmt::unwrap;
9use embassy::blocking_mutex::kind::Noop; 9use embassy::blocking_mutex::raw::NoopRawMutex;
10use embassy::channel::mpsc::{self, Channel, Sender, TryRecvError}; 10use embassy::channel::mpsc::{self, Channel, Sender, TryRecvError};
11use embassy::executor::Spawner; 11use embassy::executor::Spawner;
12use embassy::time::{Duration, Timer}; 12use embassy::time::{Duration, Timer};
@@ -19,10 +19,10 @@ enum LedState {
19 Off, 19 Off,
20} 20}
21 21
22static CHANNEL: Forever<Channel<Noop, LedState, 1>> = Forever::new(); 22static CHANNEL: Forever<Channel<NoopRawMutex, LedState, 1>> = Forever::new();
23 23
24#[embassy::task(pool_size = 1)] 24#[embassy::task(pool_size = 1)]
25async fn my_task(sender: Sender<'static, Noop, LedState, 1>) { 25async fn my_task(sender: Sender<'static, NoopRawMutex, LedState, 1>) {
26 loop { 26 loop {
27 let _ = sender.send(LedState::On).await; 27 let _ = sender.send(LedState::On).await;
28 Timer::after(Duration::from_secs(1)).await; 28 Timer::after(Duration::from_secs(1)).await;
diff --git a/examples/nrf/src/bin/uart_split.rs b/examples/nrf/src/bin/uart_split.rs
index 750798378..19d438c40 100644
--- a/examples/nrf/src/bin/uart_split.rs
+++ b/examples/nrf/src/bin/uart_split.rs
@@ -6,7 +6,7 @@
6mod example_common; 6mod example_common;
7use example_common::*; 7use example_common::*;
8 8
9use embassy::blocking_mutex::kind::Noop; 9use embassy::blocking_mutex::raw::NoopRawMutex;
10use embassy::channel::mpsc::{self, Channel, Sender}; 10use embassy::channel::mpsc::{self, Channel, Sender};
11use embassy::executor::Spawner; 11use embassy::executor::Spawner;
12use embassy::util::Forever; 12use embassy::util::Forever;
@@ -14,7 +14,7 @@ use embassy_nrf::peripherals::UARTE0;
14use embassy_nrf::uarte::UarteRx; 14use embassy_nrf::uarte::UarteRx;
15use embassy_nrf::{interrupt, uarte, Peripherals}; 15use embassy_nrf::{interrupt, uarte, Peripherals};
16 16
17static CHANNEL: Forever<Channel<Noop, [u8; 8], 1>> = Forever::new(); 17static CHANNEL: Forever<Channel<NoopRawMutex, [u8; 8], 1>> = Forever::new();
18 18
19#[embassy::main] 19#[embassy::main]
20async fn main(spawner: Spawner, p: Peripherals) { 20async fn main(spawner: Spawner, p: Peripherals) {
@@ -56,7 +56,7 @@ async fn main(spawner: Spawner, p: Peripherals) {
56} 56}
57 57
58#[embassy::task] 58#[embassy::task]
59async fn reader(mut rx: UarteRx<'static, UARTE0>, s: Sender<'static, Noop, [u8; 8], 1>) { 59async fn reader(mut rx: UarteRx<'static, UARTE0>, s: Sender<'static, NoopRawMutex, [u8; 8], 1>) {
60 let mut buf = [0; 8]; 60 let mut buf = [0; 8];
61 loop { 61 loop {
62 info!("reading..."); 62 info!("reading...");