summaryrefslogtreecommitdiff
path: root/examples/src/bin/ble_bas_peripheral.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <dirbaio@dirbaio.net>2022-08-22 19:53:17 +0200
committerDario Nieuwenhuis <dirbaio@dirbaio.net>2022-08-22 19:55:16 +0200
commit36d14808e2019556d502105081bd36f80aba06c0 (patch)
tree67c1824e23c96b7ddb4440ce895b37646618e6d4 /examples/src/bin/ble_bas_peripheral.rs
parente1e4e2a2c2e9a8243368214fac02532e79c127a8 (diff)
downloadnrf-softdevice-36d14808e2019556d502105081bd36f80aba06c0.zip
Update Embassy.
Diffstat (limited to 'examples/src/bin/ble_bas_peripheral.rs')
-rw-r--r--examples/src/bin/ble_bas_peripheral.rs94
1 files changed, 41 insertions, 53 deletions
diff --git a/examples/src/bin/ble_bas_peripheral.rs b/examples/src/bin/ble_bas_peripheral.rs
index 03fc603..685bfc5 100644
--- a/examples/src/bin/ble_bas_peripheral.rs
+++ b/examples/src/bin/ble_bas_peripheral.rs
@@ -7,18 +7,14 @@ mod example_common;
use core::mem;
-use cortex_m_rt::entry;
use defmt::{info, *};
-use embassy_executor::executor::Executor;
-use embassy_util::Forever;
+use embassy_executor::Spawner;
use nrf_softdevice::ble::{gatt_server, peripheral};
use nrf_softdevice::{raw, Softdevice};
-static EXECUTOR: Forever<Executor> = Forever::new();
-
#[embassy_executor::task]
-async fn softdevice_task(sd: &'static Softdevice) {
- sd.run().await;
+async fn softdevice_task(sd: &'static Softdevice) -> ! {
+ sd.run().await
}
#[nrf_softdevice::gatt_service(uuid = "180f")]
@@ -39,8 +35,44 @@ struct Server {
foo: FooService,
}
-#[embassy_executor::task]
-async fn bluetooth_task(sd: &'static Softdevice, server: Server) {
+#[embassy_executor::main]
+async fn main(spawner: Spawner) {
+ info!("Hello World!");
+
+ let config = nrf_softdevice::Config {
+ clock: Some(raw::nrf_clock_lf_cfg_t {
+ source: raw::NRF_CLOCK_LF_SRC_RC as u8,
+ rc_ctiv: 4,
+ rc_temp_ctiv: 2,
+ accuracy: 7,
+ }),
+ conn_gap: Some(raw::ble_gap_conn_cfg_t {
+ conn_count: 6,
+ event_length: 24,
+ }),
+ conn_gatt: Some(raw::ble_gatt_conn_cfg_t { att_mtu: 256 }),
+ gatts_attr_tab_size: Some(raw::ble_gatts_cfg_attr_tab_size_t { attr_tab_size: 32768 }),
+ gap_role_count: Some(raw::ble_gap_cfg_role_count_t {
+ adv_set_count: 1,
+ periph_role_count: 3,
+ central_role_count: 3,
+ central_sec_count: 0,
+ _bitfield_1: raw::ble_gap_cfg_role_count_t::new_bitfield_1(0),
+ }),
+ gap_device_name: Some(raw::ble_gap_cfg_device_name_t {
+ p_value: b"HelloRust" as *const u8 as _,
+ current_len: 9,
+ max_len: 9,
+ write_perm: unsafe { mem::zeroed() },
+ _bitfield_1: raw::ble_gap_cfg_device_name_t::new_bitfield_1(raw::BLE_GATTS_VLOC_STACK as u8),
+ }),
+ ..Default::default()
+ };
+
+ let sd = Softdevice::enable(&config);
+ let server = unwrap!(Server::new(sd));
+ unwrap!(spawner.spawn(softdevice_task(sd)));
+
#[rustfmt::skip]
let adv_data = &[
0x02, 0x01, raw::BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE as u8,
@@ -88,47 +120,3 @@ async fn bluetooth_task(sd: &'static Softdevice, server: Server) {
}
}
}
-
-#[entry]
-fn main() -> ! {
- info!("Hello World!");
-
- let config = nrf_softdevice::Config {
- clock: Some(raw::nrf_clock_lf_cfg_t {
- source: raw::NRF_CLOCK_LF_SRC_RC as u8,
- rc_ctiv: 4,
- rc_temp_ctiv: 2,
- accuracy: 7,
- }),
- conn_gap: Some(raw::ble_gap_conn_cfg_t {
- conn_count: 6,
- event_length: 24,
- }),
- conn_gatt: Some(raw::ble_gatt_conn_cfg_t { att_mtu: 256 }),
- gatts_attr_tab_size: Some(raw::ble_gatts_cfg_attr_tab_size_t { attr_tab_size: 32768 }),
- gap_role_count: Some(raw::ble_gap_cfg_role_count_t {
- adv_set_count: 1,
- periph_role_count: 3,
- central_role_count: 3,
- central_sec_count: 0,
- _bitfield_1: raw::ble_gap_cfg_role_count_t::new_bitfield_1(0),
- }),
- gap_device_name: Some(raw::ble_gap_cfg_device_name_t {
- p_value: b"HelloRust" as *const u8 as _,
- current_len: 9,
- max_len: 9,
- write_perm: unsafe { mem::zeroed() },
- _bitfield_1: raw::ble_gap_cfg_device_name_t::new_bitfield_1(raw::BLE_GATTS_VLOC_STACK as u8),
- }),
- ..Default::default()
- };
-
- let sd = Softdevice::enable(&config);
-
- let executor = EXECUTOR.put(Executor::new());
- executor.run(move |spawner| {
- let server = unwrap!(Server::new(sd));
- unwrap!(spawner.spawn(softdevice_task(sd)));
- unwrap!(spawner.spawn(bluetooth_task(sd, server)));
- });
-}