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 <dirbaio@dirbaio.net>
This commit is contained in:
bors[bot]
2022-02-12 00:30:47 +00:00
committed by GitHub
46 changed files with 988 additions and 848 deletions

View File

@ -4,6 +4,9 @@ edition = "2018"
name = "embassy-nrf-examples"
version = "0.1.0"
[features]
default = ["nightly"]
nightly = ["embassy-nrf/nightly"]
[dependencies]
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }

View File

@ -6,7 +6,7 @@
mod example_common;
use defmt::unwrap;
use embassy::blocking_mutex::kind::Noop;
use embassy::blocking_mutex::raw::NoopRawMutex;
use embassy::channel::mpsc::{self, Channel, Sender, TryRecvError};
use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
@ -19,10 +19,10 @@ enum LedState {
Off,
}
static CHANNEL: Forever<Channel<Noop, LedState, 1>> = Forever::new();
static CHANNEL: Forever<Channel<NoopRawMutex, LedState, 1>> = Forever::new();
#[embassy::task(pool_size = 1)]
async fn my_task(sender: Sender<'static, Noop, LedState, 1>) {
async fn my_task(sender: Sender<'static, NoopRawMutex, LedState, 1>) {
loop {
let _ = sender.send(LedState::On).await;
Timer::after(Duration::from_secs(1)).await;

View File

@ -6,7 +6,7 @@
mod example_common;
use example_common::*;
use embassy::blocking_mutex::kind::Noop;
use embassy::blocking_mutex::raw::NoopRawMutex;
use embassy::channel::mpsc::{self, Channel, Sender};
use embassy::executor::Spawner;
use embassy::util::Forever;
@ -14,7 +14,7 @@ use embassy_nrf::peripherals::UARTE0;
use embassy_nrf::uarte::UarteRx;
use embassy_nrf::{interrupt, uarte, Peripherals};
static CHANNEL: Forever<Channel<Noop, [u8; 8], 1>> = Forever::new();
static CHANNEL: Forever<Channel<NoopRawMutex, [u8; 8], 1>> = Forever::new();
#[embassy::main]
async fn main(spawner: Spawner, p: Peripherals) {
@ -56,7 +56,7 @@ async fn main(spawner: Spawner, p: Peripherals) {
}
#[embassy::task]
async fn reader(mut rx: UarteRx<'static, UARTE0>, s: Sender<'static, Noop, [u8; 8], 1>) {
async fn reader(mut rx: UarteRx<'static, UARTE0>, s: Sender<'static, NoopRawMutex, [u8; 8], 1>) {
let mut buf = [0; 8];
loop {
info!("reading...");