diff options
author | alexmoon <alex.r.moon@gmail.com> | 2022-07-14 15:45:28 -0400 |
---|---|---|
committer | alexmoon <alex.r.moon@gmail.com> | 2022-07-14 15:45:28 -0400 |
commit | 98a31ce672c3113a2c238dc4e2ae9d632e59713a (patch) | |
tree | 36af82b9b26b04e2a7738515d50fc6b189d540b0 /examples | |
parent | 84006cd336adf2642cb5716433abb5540c4fb8b9 (diff) | |
download | nrf-softdevice-98a31ce672c3113a2c238dc4e2ae9d632e59713a.zip |
Add rustfmt.toml to match embassy formatting
Diffstat (limited to 'examples')
-rw-r--r-- | examples/src/bin/ble_advertise.rs | 15 | ||||
-rw-r--r-- | examples/src/bin/ble_bas_central.rs | 16 | ||||
-rw-r--r-- | examples/src/bin/ble_bas_peripheral.rs | 31 | ||||
-rw-r--r-- | examples/src/bin/ble_dis_bas_peripheral_builder.rs | 51 | ||||
-rw-r--r-- | examples/src/bin/ble_l2cap_central.rs | 24 | ||||
-rw-r--r-- | examples/src/bin/ble_l2cap_peripheral.rs | 22 | ||||
-rw-r--r-- | examples/src/bin/ble_peripheral_onoff.rs | 22 | ||||
-rw-r--r-- | examples/src/bin/ble_scan.rs | 22 | ||||
-rw-r--r-- | examples/src/bin/flash.rs | 1 |
9 files changed, 54 insertions, 150 deletions
diff --git a/examples/src/bin/ble_advertise.rs b/examples/src/bin/ble_advertise.rs index 144568e..b6f7bd4 100644 --- a/examples/src/bin/ble_advertise.rs +++ b/examples/src/bin/ble_advertise.rs @@ -6,11 +6,11 @@ mod example_common; use core::mem; + use cortex_m_rt::entry; use defmt::{info, unreachable, *}; use embassy::executor::Executor; use embassy::util::Forever; - use nrf_softdevice::ble::peripheral; use nrf_softdevice::{raw, Softdevice}; @@ -36,10 +36,7 @@ async fn bluetooth_task(sd: &'static Softdevice) { let mut config = peripheral::Config::default(); config.interval = 50; - let adv = peripheral::NonconnectableAdvertisement::ScannableUndirected { - adv_data, - scan_data, - }; + let adv = peripheral::NonconnectableAdvertisement::ScannableUndirected { adv_data, scan_data }; unwrap!(peripheral::advertise(sd, adv, &config).await); // advertise never returns @@ -62,9 +59,7 @@ fn main() -> ! { 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, - }), + 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, @@ -77,9 +72,7 @@ fn main() -> ! { 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, - ), + _bitfield_1: raw::ble_gap_cfg_device_name_t::new_bitfield_1(raw::BLE_GATTS_VLOC_STACK as u8), }), ..Default::default() }; diff --git a/examples/src/bin/ble_bas_central.rs b/examples/src/bin/ble_bas_central.rs index f09cb91..f0bda6e 100644 --- a/examples/src/bin/ble_bas_central.rs +++ b/examples/src/bin/ble_bas_central.rs @@ -6,15 +6,13 @@ mod example_common; use core::mem; + use cortex_m_rt::entry; -use defmt::info; -use defmt::*; +use defmt::{info, *}; use embassy::executor::Executor; use embassy::util::Forever; - use nrf_softdevice::ble::{central, gatt_client, Address, AddressType}; -use nrf_softdevice::raw; -use nrf_softdevice::Softdevice; +use nrf_softdevice::{raw, Softdevice}; static EXECUTOR: Forever<Executor> = Forever::new(); @@ -71,9 +69,7 @@ fn main() -> ! { event_length: 6, }), conn_gatt: Some(raw::ble_gatt_conn_cfg_t { att_mtu: 128 }), - gatts_attr_tab_size: Some(raw::ble_gatts_cfg_attr_tab_size_t { - attr_tab_size: 32768, - }), + 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, @@ -86,9 +82,7 @@ fn main() -> ! { 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, - ), + _bitfield_1: raw::ble_gap_cfg_device_name_t::new_bitfield_1(raw::BLE_GATTS_VLOC_STACK as u8), }), ..Default::default() }; diff --git a/examples/src/bin/ble_bas_peripheral.rs b/examples/src/bin/ble_bas_peripheral.rs index 2c7e769..d62a111 100644 --- a/examples/src/bin/ble_bas_peripheral.rs +++ b/examples/src/bin/ble_bas_peripheral.rs @@ -6,12 +6,11 @@ mod example_common; use core::mem; + use cortex_m_rt::entry; -use defmt::info; -use defmt::*; +use defmt::{info, *}; use embassy::executor::Executor; use embassy::util::Forever; - use nrf_softdevice::ble::{gatt_server, peripheral}; use nrf_softdevice::{raw, Softdevice}; @@ -30,13 +29,7 @@ struct BatteryService { #[nrf_softdevice::gatt_service(uuid = "9e7312e0-2354-11eb-9f10-fbc30a62cf38")] struct FooService { - #[characteristic( - uuid = "9e7312e0-2354-11eb-9f10-fbc30a63cf38", - read, - write, - notify, - indicate - )] + #[characteristic(uuid = "9e7312e0-2354-11eb-9f10-fbc30a63cf38", read, write, notify, indicate)] foo: u16, } @@ -61,10 +54,7 @@ async fn bluetooth_task(sd: &'static Softdevice, server: Server) { loop { let config = peripheral::Config::default(); - let adv = peripheral::ConnectableAdvertisement::ScannableUndirected { - adv_data, - scan_data, - }; + let adv = peripheral::ConnectableAdvertisement::ScannableUndirected { adv_data, scan_data }; let conn = unwrap!(peripheral::advertise_connectable(sd, adv, &config).await); info!("advertising done!"); @@ -87,10 +77,7 @@ async fn bluetooth_task(sd: &'static Softdevice, server: Server) { indications, notifications, } => { - info!( - "foo indications: {}, notifications: {}", - indications, notifications - ) + info!("foo indications: {}, notifications: {}", indications, notifications) } }, }) @@ -118,9 +105,7 @@ fn main() -> ! { 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, - }), + 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, @@ -133,9 +118,7 @@ fn main() -> ! { 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, - ), + _bitfield_1: raw::ble_gap_cfg_device_name_t::new_bitfield_1(raw::BLE_GATTS_VLOC_STACK as u8), }), ..Default::default() }; diff --git a/examples/src/bin/ble_dis_bas_peripheral_builder.rs b/examples/src/bin/ble_dis_bas_peripheral_builder.rs index 012ba7d..4d65e67 100644 --- a/examples/src/bin/ble_dis_bas_peripheral_builder.rs +++ b/examples/src/bin/ble_dis_bas_peripheral_builder.rs @@ -6,9 +6,9 @@ mod example_common; use core::mem; + use cortex_m_rt::entry; -use defmt::info; -use defmt::*; +use defmt::{info, *}; use embassy::executor::Executor; use embassy::util::Forever; use nrf_softdevice::ble::gatt_server::builder::ServiceBuilder; @@ -65,11 +65,7 @@ pub struct DeviceInformation { pub struct DeviceInformationService {} impl DeviceInformationService { - pub fn new( - sd: &mut Softdevice, - pnp_id: &PnPID, - info: DeviceInformation, - ) -> Result<Self, RegisterError> { + pub fn new(sd: &mut Softdevice, pnp_id: &PnPID, info: DeviceInformation) -> Result<Self, RegisterError> { let mut sb = ServiceBuilder::new(sd, DEVICE_INFORMATION)?; Self::add_pnp_characteristic(&mut sb, pnp_id)?; @@ -99,17 +95,10 @@ impl DeviceInformationService { } } - fn add_pnp_characteristic( - sb: &mut ServiceBuilder, - pnp_id: &PnPID, - ) -> Result<CharacteristicHandles, RegisterError> { + fn add_pnp_characteristic(sb: &mut ServiceBuilder, pnp_id: &PnPID) -> Result<CharacteristicHandles, RegisterError> { // SAFETY: `PnPID` is `repr(C, packed)` so viewing it as an immutable slice of bytes is safe. - let val = unsafe { - core::slice::from_raw_parts( - pnp_id as *const _ as *const u8, - core::mem::size_of::<PnPID>(), - ) - }; + let val = + unsafe { core::slice::from_raw_parts(pnp_id as *const _ as *const u8, core::mem::size_of::<PnPID>()) }; let attr = Attribute::new(val); let md = Metadata::new(Properties::new().read()); @@ -128,8 +117,7 @@ impl BatteryService { let attr = Attribute::new(&[0u8]); let metadata = Metadata::new(Properties::new().read().notify()); - let characteristic_builder = - service_builder.add_characteristic(BATTERY_LEVEL, attr, metadata)?; + let characteristic_builder = service_builder.add_characteristic(BATTERY_LEVEL, attr, metadata)?; let characteristic_handles = characteristic_builder.build(); let _service_handle = service_builder.build(); @@ -146,18 +134,10 @@ impl BatteryService { Ok(buf[0]) } - pub fn battery_level_set( - &self, - sd: &Softdevice, - val: u8, - ) -> Result<(), gatt_server::SetValueError> { + pub fn battery_level_set(&self, sd: &Softdevice, val: u8) -> Result<(), gatt_server::SetValueError> { gatt_server::set_value(sd, self.value_handle, &[val]) } - pub fn battery_level_notify( - &self, - conn: &Connection, - val: u8, - ) -> Result<(), gatt_server::NotifyValueError> { + pub fn battery_level_notify(&self, conn: &Connection, val: u8) -> Result<(), gatt_server::NotifyValueError> { gatt_server::notify_value(conn, self.value_handle, &[val]) } @@ -221,10 +201,7 @@ async fn bluetooth_task(sd: &'static Softdevice, server: Server) { loop { let config = peripheral::Config::default(); - let adv = peripheral::ConnectableAdvertisement::ScannableUndirected { - adv_data, - scan_data, - }; + let adv = peripheral::ConnectableAdvertisement::ScannableUndirected { adv_data, scan_data }; let conn = unwrap!(peripheral::advertise_connectable(sd, adv, &config).await); info!("advertising done!"); @@ -254,9 +231,7 @@ fn main() -> ! { 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, - }), + 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, @@ -269,9 +244,7 @@ fn main() -> ! { 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, - ), + _bitfield_1: raw::ble_gap_cfg_device_name_t::new_bitfield_1(raw::BLE_GATTS_VLOC_STACK as u8), }), ..Default::default() }; diff --git a/examples/src/bin/ble_l2cap_central.rs b/examples/src/bin/ble_l2cap_central.rs index 2169c35..f344fa8 100644 --- a/examples/src/bin/ble_l2cap_central.rs +++ b/examples/src/bin/ble_l2cap_central.rs @@ -5,18 +5,16 @@ #[path = "../example_common.rs"] mod example_common; -use core::mem; use core::ptr::NonNull; -use core::slice; +use core::{mem, slice}; + use cortex_m_rt::entry; use defmt::{info, *}; use embassy::executor::Executor; use embassy::util::Forever; - use nrf_softdevice::ble::l2cap::Packet as _; use nrf_softdevice::ble::{central, l2cap, Address, TxPower}; -use nrf_softdevice::raw; -use nrf_softdevice::Softdevice; +use nrf_softdevice::{raw, Softdevice}; static EXECUTOR: Forever<Executor> = Forever::new(); @@ -52,8 +50,7 @@ async fn ble_central_task(sd: &'static Softdevice) { if key == 0x06 && value == &[ - 0xeb, 0x04, 0x8b, 0xfd, 0x5b, 0x03, 0x21, 0xb5, 0xeb, 0x11, 0x65, 0x2f, - 0x18, 0xce, 0x9c, 0x82, + 0xeb, 0x04, 0x8b, 0xfd, 0x5b, 0x03, 0x21, 0xb5, 0xeb, 0x11, 0x65, 0x2f, 0x18, 0xce, 0x9c, 0x82, ] { return Some(Address::from_raw(params.peer_addr)); @@ -104,10 +101,7 @@ impl Packet { fn new(data: &[u8]) -> Self { let mut buf = unwrap!(Box::<PacketPool>::new([0; 512])); buf[..data.len()].copy_from_slice(data); - Packet { - len: data.len(), - buf, - } + Packet { len: data.len(), buf } } } @@ -158,9 +152,7 @@ fn main() -> ! { conn_gattc: Some(raw::ble_gattc_conn_cfg_t { write_cmd_tx_queue_size: 0, }), - conn_gatts: Some(raw::ble_gatts_conn_cfg_t { - hvn_tx_queue_size: 0, - }), + conn_gatts: Some(raw::ble_gatts_conn_cfg_t { hvn_tx_queue_size: 0 }), gatts_attr_tab_size: Some(raw::ble_gatts_cfg_attr_tab_size_t { attr_tab_size: 512 }), gap_role_count: Some(raw::ble_gap_cfg_role_count_t { adv_set_count: 1, @@ -174,9 +166,7 @@ fn main() -> ! { 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, - ), + _bitfield_1: raw::ble_gap_cfg_device_name_t::new_bitfield_1(raw::BLE_GATTS_VLOC_STACK as u8), }), conn_l2cap: Some(raw::ble_l2cap_conn_cfg_t { ch_count: 1, diff --git a/examples/src/bin/ble_l2cap_peripheral.rs b/examples/src/bin/ble_l2cap_peripheral.rs index 77aae30..d542a45 100644 --- a/examples/src/bin/ble_l2cap_peripheral.rs +++ b/examples/src/bin/ble_l2cap_peripheral.rs @@ -7,14 +7,13 @@ mod example_common; use core::mem; use core::ptr::NonNull; + use cortex_m_rt::entry; use defmt::*; use embassy::executor::Executor; use embassy::util::Forever; - use nrf_softdevice::ble::{l2cap, peripheral}; -use nrf_softdevice::{ble, RawError}; -use nrf_softdevice::{raw, Softdevice}; +use nrf_softdevice::{ble, raw, RawError, Softdevice}; static EXECUTOR: Forever<Executor> = Forever::new(); @@ -42,10 +41,7 @@ async fn bluetooth_task(sd: &'static Softdevice) { loop { let config = peripheral::Config::default(); - let adv = peripheral::ConnectableAdvertisement::ScannableUndirected { - adv_data, - scan_data, - }; + let adv = peripheral::ConnectableAdvertisement::ScannableUndirected { adv_data, scan_data }; let conn = unwrap!(peripheral::advertise_connectable(sd, adv, &config).await); info!("advertising done!"); @@ -123,12 +119,8 @@ fn main() -> ! { conn_gattc: Some(raw::ble_gattc_conn_cfg_t { write_cmd_tx_queue_size: 0, }), - conn_gatts: Some(raw::ble_gatts_conn_cfg_t { - hvn_tx_queue_size: 0, - }), - gatts_attr_tab_size: Some(raw::ble_gatts_cfg_attr_tab_size_t { - attr_tab_size: 1024, - }), + conn_gatts: Some(raw::ble_gatts_conn_cfg_t { hvn_tx_queue_size: 0 }), + gatts_attr_tab_size: Some(raw::ble_gatts_cfg_attr_tab_size_t { attr_tab_size: 1024 }), gap_role_count: Some(raw::ble_gap_cfg_role_count_t { adv_set_count: 1, periph_role_count: 5, @@ -141,9 +133,7 @@ fn main() -> ! { 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, - ), + _bitfield_1: raw::ble_gap_cfg_device_name_t::new_bitfield_1(raw::BLE_GATTS_VLOC_STACK as u8), }), conn_l2cap: Some(raw::ble_l2cap_conn_cfg_t { ch_count: 1, diff --git a/examples/src/bin/ble_peripheral_onoff.rs b/examples/src/bin/ble_peripheral_onoff.rs index 101f208..a75ec49 100644 --- a/examples/src/bin/ble_peripheral_onoff.rs +++ b/examples/src/bin/ble_peripheral_onoff.rs @@ -6,6 +6,7 @@ mod example_common; use core::mem; + use cortex_m_rt::entry; use defmt::*; use embassy::executor::Executor; @@ -13,7 +14,6 @@ use embassy::util::Forever; use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull}; use embassy_nrf::interrupt::Priority; use futures::pin_mut; - use nrf_softdevice::ble::{gatt_server, peripheral}; use nrf_softdevice::{raw, Softdevice}; @@ -49,10 +49,7 @@ async fn run_bluetooth(sd: &'static Softdevice, server: &Server) { loop { let config = peripheral::Config::default(); - let adv = peripheral::ConnectableAdvertisement::ScannableUndirected { - adv_data, - scan_data, - }; + let adv = peripheral::ConnectableAdvertisement::ScannableUndirected { adv_data, scan_data }; let conn = unwrap!(peripheral::advertise_connectable(sd, adv, &config).await); info!("advertising done!"); @@ -141,9 +138,7 @@ fn main() -> ! { 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, - }), + 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, @@ -156,9 +151,7 @@ fn main() -> ! { 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, - ), + _bitfield_1: raw::ble_gap_cfg_device_name_t::new_bitfield_1(raw::BLE_GATTS_VLOC_STACK as u8), }), ..Default::default() }; @@ -169,11 +162,6 @@ fn main() -> ! { executor.run(move |spawner| { let server = unwrap!(Server::new(sd)); unwrap!(spawner.spawn(softdevice_task(sd))); - unwrap!(spawner.spawn(bluetooth_task( - sd, - server, - p.P0_11.degrade(), - p.P0_12.degrade() - ))); + unwrap!(spawner.spawn(bluetooth_task(sd, server, p.P0_11.degrade(), p.P0_12.degrade()))); }); } diff --git a/examples/src/bin/ble_scan.rs b/examples/src/bin/ble_scan.rs index f0b4cf8..c8ed543 100644 --- a/examples/src/bin/ble_scan.rs +++ b/examples/src/bin/ble_scan.rs @@ -5,16 +5,14 @@ #[path = "../example_common.rs"] mod example_common; -use core::mem; -use core::slice; +use core::{mem, slice}; + use cortex_m_rt::entry; use defmt::*; use embassy::executor::Executor; use embassy::util::Forever; - use nrf_softdevice::ble::central; -use nrf_softdevice::raw; -use nrf_softdevice::Softdevice; +use nrf_softdevice::{raw, Softdevice}; static EXECUTOR: Forever<Executor> = Forever::new(); @@ -46,7 +44,7 @@ async fn ble_task(sd: &'static Softdevice) { let mut data = slice::from_raw_parts(params.data.p_data, params.data.len as usize); while data.len() != 0 { let len = data[0] as usize; - if data.len() < len+1 { + if data.len() < len + 1 { warn!("Advertisement data truncated?"); break; } @@ -55,9 +53,9 @@ async fn ble_task(sd: &'static Softdevice) { break; } let key = data[1]; - let value = &data[2..len+1]; + let value = &data[2..len + 1]; info!("value {}: {:x}", key, value); - data = &data[len+1..]; + data = &data[len + 1..]; } None }) @@ -82,9 +80,7 @@ fn main() -> ! { event_length: 6, }), conn_gatt: Some(raw::ble_gatt_conn_cfg_t { att_mtu: 128 }), - gatts_attr_tab_size: Some(raw::ble_gatts_cfg_attr_tab_size_t { - attr_tab_size: 32768, - }), + 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, @@ -97,9 +93,7 @@ fn main() -> ! { 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, - ), + _bitfield_1: raw::ble_gap_cfg_device_name_t::new_bitfield_1(raw::BLE_GATTS_VLOC_STACK as u8), }), ..Default::default() }; diff --git a/examples/src/bin/flash.rs b/examples/src/bin/flash.rs index 3c293bd..dfaa7fb 100644 --- a/examples/src/bin/flash.rs +++ b/examples/src/bin/flash.rs @@ -11,7 +11,6 @@ use embassy::executor::Executor; use embassy::util::Forever; use embedded_storage_async::nor_flash::*; use futures::pin_mut; - use nrf_softdevice::{Flash, Softdevice}; static EXECUTOR: Forever<Executor> = Forever::new(); |