diff options
author | Dario Nieuwenhuis <dirbaio@dirbaio.net> | 2020-10-31 23:24:31 +0100 |
---|---|---|
committer | Dario Nieuwenhuis <dirbaio@dirbaio.net> | 2020-10-31 23:24:31 +0100 |
commit | c621ed316cf6f49805a4db7b1f8e220bfc8fe86e (patch) | |
tree | 7950b43e8ea8d4de7cee8b9954807d2e2b9b0848 /examples | |
parent | 908eb3faedfd029704b068ed92bfd2c8680798a7 (diff) | |
download | nrf-softdevice-c621ed316cf6f49805a4db7b1f8e220bfc8fe86e.zip |
Migrate to embassy (removes static-executor and async-flash)
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Cargo.toml | 5 | ||||
-rw-r--r-- | examples/src/bin/ble_bas_central.rs | 18 | ||||
-rw-r--r-- | examples/src/bin/ble_bas_peripheral.rs | 18 | ||||
-rw-r--r-- | examples/src/bin/ble_peripheral_gattspam.rs | 18 | ||||
-rw-r--r-- | examples/src/bin/flash.rs | 21 | ||||
-rw-r--r-- | examples/src/bin/interrupts.rs | 19 | ||||
-rw-r--r-- | examples/src/bin/rtic.rs | 21 | ||||
-rw-r--r-- | examples/src/example_common.rs | 1 |
8 files changed, 79 insertions, 42 deletions
diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 8a46c73..a9eedc5 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -23,7 +23,8 @@ ble-gatt-server = ["nrf-softdevice/ble-gatt-server"] ble-gatt-client = ["nrf-softdevice/ble-gatt-client"] [dependencies] -async-flash = { version = "0.1.0", path = "../async-flash" } +embassy = { version = "0.1.0" } +embassy-nrf = { version = "0.1.0", features = [ "52840" ]} cortex-m = { version = "0.6.3" } cortex-m-rt = "0.6.12" cortex-m-rtic = { version = "0.5.5", optional = true } @@ -33,8 +34,6 @@ panic-probe = "0.1.0" nrf52840-hal = { version = "0.11.0" } nrf-softdevice = { version = "0.1.0", path = "../nrf-softdevice", features = ["defmt-trace", "nrf52840", "s140", "ble-peripheral", "ble-central"] } nrf-softdevice-s140 = { version = "0.1.1", path = "../nrf-softdevice-s140" } -static-executor = { version = "0.1.0", features=["defmt"]} -static-executor-cortex-m = { version = "0.1.0" } futures = { version = "0.3.5", default-features = false } fixed = "1.2.0" diff --git a/examples/src/bin/ble_bas_central.rs b/examples/src/bin/ble_bas_central.rs index 184dda3..a1cb0d9 100644 --- a/examples/src/bin/ble_bas_central.rs +++ b/examples/src/bin/ble_bas_central.rs @@ -9,12 +9,16 @@ use example_common::*; use core::mem; use cortex_m_rt::entry; use defmt::info; +use embassy::executor::{task, Executor}; +use embassy::util::Forever; use nrf_softdevice::ble::{central, gatt_client, Address, Connection, Uuid}; use nrf_softdevice::raw; use nrf_softdevice::Softdevice; -#[static_executor::task] +static EXECUTOR: Forever<Executor> = Forever::new(); + +#[task] async fn softdevice_task(sd: &'static Softdevice) { sd.run().await; } @@ -72,7 +76,7 @@ impl gatt_client::Client for BatteryServiceClient { } } -#[static_executor::task] +#[task] async fn ble_central_task(sd: &'static Softdevice) { let addrs = &[Address::new_random_static([ 0x59, 0xf9, 0xb1, 0x9c, 0x01, 0xf5, @@ -154,10 +158,12 @@ fn main() -> ! { let sd = Softdevice::enable(&config); - unsafe { - softdevice_task.spawn(sd).dewrap(); - ble_central_task.spawn(sd).dewrap(); + let executor = EXECUTOR.put(Executor::new(cortex_m::asm::wfi)); + executor.spawn(softdevice_task(sd)).dewrap(); + executor.spawn(ble_central_task(sd)).dewrap(); - static_executor::run(); + loop { + executor.run(); + cortex_m::asm::wfe(); } } diff --git a/examples/src/bin/ble_bas_peripheral.rs b/examples/src/bin/ble_bas_peripheral.rs index 131f9c1..ac87c46 100644 --- a/examples/src/bin/ble_bas_peripheral.rs +++ b/examples/src/bin/ble_bas_peripheral.rs @@ -14,7 +14,11 @@ use nrf_softdevice::ble::gatt_server::{Characteristic, CharacteristicHandles, Re use nrf_softdevice::ble::{gatt_server, peripheral, Connection, Uuid}; use nrf_softdevice::{raw, RawError, Softdevice}; -#[static_executor::task] +use embassy::executor::{task, Executor}; +use embassy::util::Forever; +static EXECUTOR: Forever<Executor> = Forever::new(); + +#[task] async fn softdevice_task(sd: &'static Softdevice) { sd.run().await; } @@ -28,7 +32,7 @@ struct BatteryService { battery_level: u8, } -#[static_executor::task] +#[task] async fn bluetooth_task(sd: &'static Softdevice) { let server: BatteryService = gatt_server::register(sd).dewrap(); @@ -119,10 +123,12 @@ fn main() -> ! { let sd = Softdevice::enable(&config); - unsafe { - softdevice_task.spawn(sd).dewrap(); - bluetooth_task.spawn(sd).dewrap(); + let executor = EXECUTOR.put(Executor::new(cortex_m::asm::wfi)); + executor.spawn(softdevice_task(sd)).dewrap(); + executor.spawn(bluetooth_task(sd)).dewrap(); - static_executor::run(); + loop { + executor.run(); + cortex_m::asm::wfe(); } } diff --git a/examples/src/bin/ble_peripheral_gattspam.rs b/examples/src/bin/ble_peripheral_gattspam.rs index 0f6b75b..c67dc84 100644 --- a/examples/src/bin/ble_peripheral_gattspam.rs +++ b/examples/src/bin/ble_peripheral_gattspam.rs @@ -9,16 +9,20 @@ use example_common::*; use core::mem; use cortex_m_rt::entry; use defmt::info; +use embassy::executor::{task, Executor}; +use embassy::util::Forever; use nrf_softdevice::ble::{peripheral, Uuid}; use nrf_softdevice::{raw, RawError, Softdevice}; -#[static_executor::task] +static EXECUTOR: Forever<Executor> = Forever::new(); + +#[task] async fn softdevice_task(sd: &'static Softdevice) { sd.run().await; } -#[static_executor::task] +#[task] async fn bluetooth_task(sd: &'static Softdevice) { for i in 0..24 { let service_uuid = Uuid::new_16(0x4200 + i); @@ -153,10 +157,12 @@ fn main() -> ! { let sd = Softdevice::enable(&config); - unsafe { - softdevice_task.spawn(sd).dewrap(); - bluetooth_task.spawn(sd).dewrap(); + let executor = EXECUTOR.put(Executor::new(cortex_m::asm::wfi)); + executor.spawn(softdevice_task(sd)).dewrap(); + executor.spawn(bluetooth_task(sd)).dewrap(); - static_executor::run(); + loop { + executor.run(); + cortex_m::asm::wfe(); } } diff --git a/examples/src/bin/flash.rs b/examples/src/bin/flash.rs index e4570c2..54bde9a 100644 --- a/examples/src/bin/flash.rs +++ b/examples/src/bin/flash.rs @@ -6,16 +6,21 @@ mod example_common; use example_common::*; -use async_flash::Flash as _; use cortex_m_rt::entry; +use embassy::executor::{task, Executor}; +use embassy::flash::Flash as _; +use embassy::util::Forever; + use nrf_softdevice::{Flash, Softdevice}; -#[static_executor::task] +static EXECUTOR: Forever<Executor> = Forever::new(); + +#[task] async fn softdevice_task(sd: &'static Softdevice) { sd.run().await; } -#[static_executor::task] +#[task] async fn flash_task(sd: &'static Softdevice) { let mut f = Flash::take(sd); @@ -38,10 +43,12 @@ fn main() -> ! { let sd = Softdevice::enable(&Default::default()); - unsafe { - softdevice_task.spawn(sd).dewrap(); - flash_task.spawn(sd).dewrap(); + let executor = EXECUTOR.put(Executor::new(cortex_m::asm::wfi)); + executor.spawn(softdevice_task(sd)).dewrap(); + executor.spawn(flash_task(sd)).dewrap(); - static_executor::run(); + loop { + executor.run(); + cortex_m::asm::wfe(); } } diff --git a/examples/src/bin/interrupts.rs b/examples/src/bin/interrupts.rs index de9feae..574ecf2 100644 --- a/examples/src/bin/interrupts.rs +++ b/examples/src/bin/interrupts.rs @@ -7,15 +7,20 @@ mod example_common; use example_common::*; use cortex_m_rt::entry; +use embassy::executor::{task, Executor}; +use embassy::util::Forever; + use nrf_softdevice::interrupt; use nrf_softdevice::Softdevice; -#[static_executor::task] +static EXECUTOR: Forever<Executor> = Forever::new(); + +#[task] async fn softdevice_task(sd: &'static Softdevice) { sd.run().await; } -#[static_executor::task] +#[task] async fn interrupt_task(sd: &'static Softdevice) { let enabled = interrupt::is_enabled(interrupt::SWI0_EGU0); info!("enabled: {:?}", enabled); @@ -84,10 +89,12 @@ fn main() -> ! { let sd = Softdevice::enable(&Default::default()); - unsafe { - softdevice_task.spawn(sd).dewrap(); - interrupt_task.spawn(sd).dewrap(); + let executor = EXECUTOR.put(Executor::new(cortex_m::asm::wfi)); + executor.spawn(softdevice_task(sd)).dewrap(); + executor.spawn(interrupt_task(sd)).dewrap(); - static_executor::run(); + loop { + executor.run(); + cortex_m::asm::wfe(); } } diff --git a/examples/src/bin/rtic.rs b/examples/src/bin/rtic.rs index eb3bd4b..8e3de03 100644 --- a/examples/src/bin/rtic.rs +++ b/examples/src/bin/rtic.rs @@ -18,19 +18,24 @@ mod example_common; use example_common::*; use core::mem; +use embassy::executor::{task, Executor}; +use embassy::util::Forever; use nrf52840_hal::pac::TIMER1; use nrf52840_hal::prelude::*; use nrf52840_hal::timer::{Periodic, Timer}; +use rtic::app; + use nrf_softdevice::ble::peripheral; use nrf_softdevice::{raw, temperature_celsius, Softdevice}; -use rtic::app; -#[static_executor::task] +static EXECUTOR: Forever<Executor> = Forever::new(); + +#[task] async fn softdevice_task(sd: &'static Softdevice) { sd.run().await; } -#[static_executor::task] +#[task] async fn bluetooth_task(sd: &'static Softdevice) { #[rustfmt::skip] let adv_data = &[ @@ -123,11 +128,13 @@ const APP: () = { let temp = temperature_celsius(&sd).dewrap(); info!("{:i32}°C", temp.to_num::<i32>()); - unsafe { - softdevice_task.spawn(sd).dewrap(); - bluetooth_task.spawn(sd).dewrap(); + let executor = EXECUTOR.put(Executor::new(cortex_m::asm::wfi)); + executor.spawn(softdevice_task(sd)).dewrap(); + executor.spawn(bluetooth_task(sd)).dewrap(); - static_executor::run(); + loop { + executor.run(); + cortex_m::asm::wfe(); } } diff --git a/examples/src/example_common.rs b/examples/src/example_common.rs index e991915..65bfe6b 100644 --- a/examples/src/example_common.rs +++ b/examples/src/example_common.rs @@ -3,7 +3,6 @@ use defmt_rtt as _; // global logger use nrf52840_hal as _; use panic_probe as _; -use static_executor_cortex_m as _; pub use defmt::{info, intern}; |