diff options
| author | huntc <[email protected]> | 2021-07-07 18:08:36 +1000 |
|---|---|---|
| committer | huntc <[email protected]> | 2021-07-15 12:31:52 +1000 |
| commit | ae62948d6c21bc1ac4af50c3e39888c52d696b24 (patch) | |
| tree | a2667126df078bfc1487543483dff71c2d999a29 /examples | |
| parent | 1b49acc2f734201d8bc8d7b59e692817f4f64dea (diff) | |
Replace UnsafeCell
Using a new ChannelCell so that there's no leaking of the abstraction
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/nrf/src/bin/mpsc.rs | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/examples/nrf/src/bin/mpsc.rs b/examples/nrf/src/bin/mpsc.rs index d692abee2..eafa29e60 100644 --- a/examples/nrf/src/bin/mpsc.rs +++ b/examples/nrf/src/bin/mpsc.rs | |||
| @@ -8,12 +8,10 @@ | |||
| 8 | #[path = "../example_common.rs"] | 8 | #[path = "../example_common.rs"] |
| 9 | mod example_common; | 9 | mod example_common; |
| 10 | 10 | ||
| 11 | use core::cell::UnsafeCell; | ||
| 12 | |||
| 13 | use defmt::panic; | 11 | use defmt::panic; |
| 14 | use embassy::executor::Spawner; | 12 | use embassy::executor::Spawner; |
| 15 | use embassy::time::{Duration, Timer}; | 13 | use embassy::time::{Duration, Timer}; |
| 16 | use embassy::util::mpsc::TryRecvError; | 14 | use embassy::util::mpsc::{ChannelCell, TryRecvError}; |
| 17 | use embassy::util::{mpsc, Forever}; | 15 | use embassy::util::{mpsc, Forever}; |
| 18 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; | 16 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; |
| 19 | use embassy_nrf::Peripherals; | 17 | use embassy_nrf::Peripherals; |
| @@ -25,7 +23,7 @@ enum LedState { | |||
| 25 | Off, | 23 | Off, |
| 26 | } | 24 | } |
| 27 | 25 | ||
| 28 | static CHANNEL: Forever<UnsafeCell<Channel<WithThreadModeOnly, LedState, 1>>> = Forever::new(); | 26 | static CHANNEL: Forever<ChannelCell<Channel<WithThreadModeOnly, LedState, 1>>> = Forever::new(); |
| 29 | 27 | ||
| 30 | #[embassy::task(pool_size = 1)] | 28 | #[embassy::task(pool_size = 1)] |
| 31 | async fn my_task(sender: Sender<'static, LedState>) { | 29 | async fn my_task(sender: Sender<'static, LedState>) { |
| @@ -41,7 +39,7 @@ async fn my_task(sender: Sender<'static, LedState>) { | |||
| 41 | async fn main(spawner: Spawner, p: Peripherals) { | 39 | async fn main(spawner: Spawner, p: Peripherals) { |
| 42 | let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); | 40 | let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); |
| 43 | 41 | ||
| 44 | let channel = CHANNEL.put(UnsafeCell::new(Channel::with_thread_mode_only())); | 42 | let channel = CHANNEL.put(ChannelCell::new(Channel::with_thread_mode_only())); |
| 45 | let (sender, mut receiver) = mpsc::split(channel); | 43 | let (sender, mut receiver) = mpsc::split(channel); |
| 46 | 44 | ||
| 47 | spawner.spawn(my_task(sender)).unwrap(); | 45 | spawner.spawn(my_task(sender)).unwrap(); |
