diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-02-12 00:30:47 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-02-12 00:30:47 +0000 |
| commit | e728a32672d9cb108d73ba017a6a153dbc6c2d15 (patch) | |
| tree | 25cdf290d138929ebf0ff292fc6934e0a266400a /examples/stm32f3/src | |
| parent | d708be7fe5e8fec8f2feea269fcb6964b6c73dcb (diff) | |
| parent | 1904906b363d2bbe32e95546f53201a3179dcb60 (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/stm32f3/src')
| -rw-r--r-- | examples/stm32f3/src/bin/button_events.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/examples/stm32f3/src/bin/button_events.rs b/examples/stm32f3/src/bin/button_events.rs index 720ed9d11..1218edd2b 100644 --- a/examples/stm32f3/src/bin/button_events.rs +++ b/examples/stm32f3/src/bin/button_events.rs | |||
| @@ -12,7 +12,7 @@ | |||
| 12 | 12 | ||
| 13 | #[path = "../example_common.rs"] | 13 | #[path = "../example_common.rs"] |
| 14 | mod example_common; | 14 | mod example_common; |
| 15 | use embassy::blocking_mutex::kind::Noop; | 15 | use embassy::blocking_mutex::raw::NoopRawMutex; |
| 16 | use embassy::channel::mpsc::{self, Channel, Receiver, Sender}; | 16 | use embassy::channel::mpsc::{self, Channel, Receiver, Sender}; |
| 17 | use embassy::executor::Spawner; | 17 | use embassy::executor::Spawner; |
| 18 | use embassy::time::{with_timeout, Duration, Timer}; | 18 | use embassy::time::{with_timeout, Duration, Timer}; |
| @@ -77,7 +77,7 @@ enum ButtonEvent { | |||
| 77 | Hold, | 77 | Hold, |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | static BUTTON_EVENTS_QUEUE: Forever<Channel<Noop, ButtonEvent, 4>> = Forever::new(); | 80 | static BUTTON_EVENTS_QUEUE: Forever<Channel<NoopRawMutex, ButtonEvent, 4>> = Forever::new(); |
| 81 | 81 | ||
| 82 | #[embassy::main] | 82 | #[embassy::main] |
| 83 | async fn main(spawner: Spawner, p: Peripherals) { | 83 | async fn main(spawner: Spawner, p: Peripherals) { |
| @@ -103,7 +103,10 @@ async fn main(spawner: Spawner, p: Peripherals) { | |||
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | #[embassy::task] | 105 | #[embassy::task] |
| 106 | async fn led_blinker(mut leds: Leds<'static>, queue: Receiver<'static, Noop, ButtonEvent, 4>) { | 106 | async fn led_blinker( |
| 107 | mut leds: Leds<'static>, | ||
| 108 | queue: Receiver<'static, NoopRawMutex, ButtonEvent, 4>, | ||
| 109 | ) { | ||
| 107 | loop { | 110 | loop { |
| 108 | leds.blink().await; | 111 | leds.blink().await; |
| 109 | match queue.try_recv() { | 112 | match queue.try_recv() { |
| @@ -121,7 +124,7 @@ async fn led_blinker(mut leds: Leds<'static>, queue: Receiver<'static, Noop, But | |||
| 121 | #[embassy::task] | 124 | #[embassy::task] |
| 122 | async fn button_waiter( | 125 | async fn button_waiter( |
| 123 | mut button: ExtiInput<'static, PA0>, | 126 | mut button: ExtiInput<'static, PA0>, |
| 124 | queue: Sender<'static, Noop, ButtonEvent, 4>, | 127 | queue: Sender<'static, NoopRawMutex, ButtonEvent, 4>, |
| 125 | ) { | 128 | ) { |
| 126 | const DOUBLE_CLICK_DELAY: u64 = 250; | 129 | const DOUBLE_CLICK_DELAY: u64 = 250; |
| 127 | const HOLD_DELAY: u64 = 1000; | 130 | const HOLD_DELAY: u64 = 1000; |
