From 98a31ce672c3113a2c238dc4e2ae9d632e59713a Mon Sep 17 00:00:00 2001 From: alexmoon Date: Thu, 14 Jul 2022 15:45:28 -0400 Subject: Add rustfmt.toml to match embassy formatting --- nrf-softdevice/src/ble/central.rs | 17 ++--- nrf-softdevice/src/ble/connection.rs | 40 +++-------- nrf-softdevice/src/ble/gap.rs | 21 ++---- nrf-softdevice/src/ble/gatt_client.rs | 79 ++++++---------------- nrf-softdevice/src/ble/gatt_server.rs | 35 +++------- nrf-softdevice/src/ble/gatt_server/builder.rs | 42 ++++-------- nrf-softdevice/src/ble/gatt_traits.rs | 4 +- nrf-softdevice/src/ble/l2cap.rs | 53 ++++----------- nrf-softdevice/src/ble/peripheral.rs | 95 ++++++++++----------------- nrf-softdevice/src/ble/types.rs | 3 +- nrf-softdevice/src/critical_section_impl.rs | 3 +- nrf-softdevice/src/events.rs | 4 +- nrf-softdevice/src/flash.rs | 12 ++-- nrf-softdevice/src/lib.rs | 8 +-- nrf-softdevice/src/softdevice.rs | 47 +++++-------- nrf-softdevice/src/util/mod.rs | 5 +- nrf-softdevice/src/util/portal.rs | 3 +- 17 files changed, 135 insertions(+), 336 deletions(-) (limited to 'nrf-softdevice') diff --git a/nrf-softdevice/src/ble/central.rs b/nrf-softdevice/src/ble/central.rs index e6297c5..79392b2 100644 --- a/nrf-softdevice/src/ble/central.rs +++ b/nrf-softdevice/src/ble/central.rs @@ -3,14 +3,12 @@ //! Typically the Central device is the higher-powered device, such as a smartphone or laptop, since scanning is more //! power-hungry than advertising. -use core::mem; -use core::ptr; +use core::{mem, ptr}; use crate::ble::types::*; use crate::ble::{Address, Connection}; -use crate::raw; use crate::util::{get_union_field, OnDrop, Portal}; -use crate::{RawError, Softdevice}; +use crate::{raw, RawError, Softdevice}; #[derive(Debug, PartialEq, Eq, Clone, Copy)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -30,10 +28,7 @@ impl From for ConnectError { pub(crate) static CONNECT_PORTAL: Portal<*const raw::ble_evt_t> = Portal::new(); // Begins an ATT MTU exchange procedure, followed by a data length update request as necessary. -pub async fn connect( - _sd: &Softdevice, - config: &ConnectConfig<'_>, -) -> Result { +pub async fn connect(_sd: &Softdevice, config: &ConnectConfig<'_>) -> Result { if let Some(w) = config.scan_config.whitelist { if w.len() == 0 { return Err(ConnectError::NoAddresses); @@ -145,11 +140,7 @@ impl From for ScanError { pub(crate) static SCAN_PORTAL: Portal<*const raw::ble_evt_t> = Portal::new(); -pub async fn scan<'a, F, R>( - _sd: &Softdevice, - config: &ScanConfig<'a>, - mut f: F, -) -> Result +pub async fn scan<'a, F, R>(_sd: &Softdevice, config: &ScanConfig<'a>, mut f: F) -> Result where F: for<'b> FnMut(&'b raw::ble_gap_evt_adv_report_t) -> Option, { diff --git a/nrf-softdevice/src/ble/connection.rs b/nrf-softdevice/src/ble/connection.rs index feb1c3c..c9c0d02 100644 --- a/nrf-softdevice/src/ble/connection.rs +++ b/nrf-softdevice/src/ble/connection.rs @@ -1,12 +1,10 @@ -use core::cell::Cell; -use core::cell::UnsafeCell; +use core::cell::{Cell, UnsafeCell}; use core::iter::FusedIterator; use raw::ble_gap_conn_params_t; use crate::ble::types::{Address, AddressType, Role}; -use crate::raw; -use crate::RawError; +use crate::{raw, RawError}; #[cfg(any(feature = "s113", feature = "s132", feature = "s140"))] const BLE_GAP_DATA_LENGTH_DEFAULT: u8 = 27; // The stack's default data length. <27-251> @@ -136,12 +134,8 @@ impl ConnectionState { return Ok(()); } - let ret = unsafe { - raw::sd_ble_gap_disconnect( - conn_handle, - raw::BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION as u8, - ) - }; + let ret = + unsafe { raw::sd_ble_gap_disconnect(conn_handle, raw::BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION as u8) }; unwrap!(RawError::convert(ret), "sd_ble_gap_disconnect"); self.disconnecting = true; @@ -149,10 +143,7 @@ impl ConnectionState { } pub(crate) fn on_disconnected(&mut self, _ble_evt: *const raw::ble_evt_t) { - let conn_handle = unwrap!( - self.conn_handle, - "bug: on_disconnected when already disconnected" - ); + let conn_handle = unwrap!(self.conn_handle, "bug: on_disconnected when already disconnected"); let ibh = index_by_handle(conn_handle); let _index = unwrap!(ibh.get(), "bug: conn_handle has no index"); @@ -201,10 +192,7 @@ impl Drop for Connection { impl Clone for Connection { fn clone(&self) -> Self { self.with_state(|state| { - state.refcount = unwrap!( - state.refcount.checked_add(1), - "Too many references to same connection" - ); + state.refcount = unwrap!(state.refcount.checked_add(1), "Too many references to same connection"); }); Self { index: self.index } @@ -306,10 +294,7 @@ impl Connection { /// For central connections, this will initiate a Link Layer connection parameter update procedure. /// For peripheral connections, this will send the corresponding L2CAP request to the central. It is then /// up to the central to accept or deny the request. - pub fn set_conn_params( - &self, - conn_params: ble_gap_conn_params_t, - ) -> Result<(), SetConnParamsError> { + pub fn set_conn_params(&self, conn_params: ble_gap_conn_params_t) -> Result<(), SetConnParamsError> { let conn_handle = self.with_state(|state| state.check_connected())?; let ret = unsafe { raw::sd_ble_gap_conn_param_update(conn_handle, &conn_params) }; if let Err(err) = RawError::convert(ret) { @@ -383,10 +368,8 @@ impl Iterator for ConnectionIter { let state = &mut *s.get(); if state.conn_handle.is_some() { let index = (n + i) as u8; - state.refcount = unwrap!( - state.refcount.checked_add(1), - "Too many references to same connection" - ); + state.refcount = + unwrap!(state.refcount.checked_add(1), "Too many references to same connection"); self.0 = index + 1; return Some(Connection { index }); } @@ -408,10 +391,7 @@ impl FusedIterator for ConnectionIter {} const DUMMY_STATE: UnsafeCell = UnsafeCell::new(ConnectionState::dummy()); static mut STATES: [UnsafeCell; CONNS_MAX] = [DUMMY_STATE; CONNS_MAX]; -pub(crate) fn with_state_by_conn_handle( - conn_handle: u16, - f: impl FnOnce(&mut ConnectionState) -> T, -) -> T { +pub(crate) fn with_state_by_conn_handle(conn_handle: u16, f: impl FnOnce(&mut ConnectionState) -> T) -> T { let index = unwrap!( index_by_handle(conn_handle).get(), "bug: with_state_by_conn_handle on conn_handle that has no state" diff --git a/nrf-softdevice/src/ble/gap.rs b/nrf-softdevice/src/ble/gap.rs index c01b6ae..4e758ef 100644 --- a/nrf-softdevice/src/ble/gap.rs +++ b/nrf-softdevice/src/ble/gap.rs @@ -1,7 +1,6 @@ use crate::ble::*; -use crate::raw; use crate::util::get_union_field; -use crate::RawError; +use crate::{raw, RawError}; pub(crate) unsafe fn on_evt(ble_evt: *const raw::ble_evt_t) { let gap_evt = get_union_field(ble_evt, &(*ble_evt).evt.gap_evt); @@ -24,17 +23,12 @@ pub(crate) unsafe fn on_evt(ble_evt: *const raw::ble_evt_t) { Role::Peripheral => peripheral::ADV_PORTAL.call(ble_evt), }; if !handled { - raw::sd_ble_gap_disconnect( - gap_evt.conn_handle, - raw::BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION as _, - ); + raw::sd_ble_gap_disconnect(gap_evt.conn_handle, raw::BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION as _); } } raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => { trace!("on_disconnected conn_handle={:?}", gap_evt.conn_handle); - connection::with_state_by_conn_handle(gap_evt.conn_handle, |state| { - state.on_disconnected(ble_evt) - }); + connection::with_state_by_conn_handle(gap_evt.conn_handle, |state| state.on_disconnected(ble_evt)); } raw::BLE_GAP_EVTS_BLE_GAP_EVT_CONN_PARAM_UPDATE => { let conn_params = gap_evt.params.conn_param_update.conn_params; @@ -174,18 +168,13 @@ pub(crate) unsafe fn on_evt(ble_evt: *const raw::ble_evt_t) { } #[cfg(any(feature = "s113", feature = "s132", feature = "s140"))] -pub(crate) unsafe fn do_data_length_update( - conn_handle: u16, - params: *const raw::ble_gap_data_length_params_t, -) { +pub(crate) unsafe fn do_data_length_update(conn_handle: u16, params: *const raw::ble_gap_data_length_params_t) { let mut dl_limitation = core::mem::zeroed(); let ret = raw::sd_ble_gap_data_length_update(conn_handle, params, &mut dl_limitation); if let Err(_err) = RawError::convert(ret) { warn!("sd_ble_gap_data_length_update err {:?}", _err); - if dl_limitation.tx_payload_limited_octets != 0 - || dl_limitation.rx_payload_limited_octets != 0 - { + if dl_limitation.tx_payload_limited_octets != 0 || dl_limitation.rx_payload_limited_octets != 0 { warn!( "The requested TX/RX packet length is too long by {:?}/{:?} octets.", dl_limitation.tx_payload_limited_octets, dl_limitation.rx_payload_limited_octets diff --git a/nrf-softdevice/src/ble/gatt_client.rs b/nrf-softdevice/src/ble/gatt_client.rs index c5e0c8e..54fd69c 100644 --- a/nrf-softdevice/src/ble/gatt_client.rs +++ b/nrf-softdevice/src/ble/gatt_client.rs @@ -4,9 +4,8 @@ use heapless::Vec; use num_enum::{FromPrimitive, IntoPrimitive}; use crate::ble::*; -use crate::raw; use crate::util::{get_flexarray, get_union_field, Portal}; -use crate::RawError; +use crate::{raw, RawError}; /// Discovered characteristic pub struct Characteristic { @@ -35,11 +34,7 @@ pub trait Client { /// Called by [`discover`] for every discovered characteristic. Implementations must /// check if they're interested in the UUID of the characteristic, and save their /// handles if needed. - fn discovered_characteristic( - &mut self, - characteristic: &Characteristic, - descriptors: &[Descriptor], - ); + fn discovered_characteristic(&mut self, characteristic: &Characteristic, descriptors: &[Descriptor]); /// Called by [`discover`] at the end of the discovery procedure. Implementations must check /// that all required characteristics have been discovered, and return [`DiscoverError::ServiceIncomplete`] @@ -122,13 +117,9 @@ impl From for DiscoverError { const DISC_CHARS_MAX: usize = 6; const DISC_DESCS_MAX: usize = 6; -pub(crate) async fn discover_service( - conn: &Connection, - uuid: Uuid, -) -> Result { +pub(crate) async fn discover_service(conn: &Connection, uuid: Uuid) -> Result { let conn_handle = conn.with_state(|state| state.check_connected())?; - let ret = - unsafe { raw::sd_ble_gattc_primary_services_discover(conn_handle, 1, uuid.as_raw_ptr()) }; + let ret = unsafe { raw::sd_ble_gattc_primary_services_discover(conn_handle, 1, uuid.as_raw_ptr()) }; RawError::convert(ret).map_err(|err| { warn!("sd_ble_gattc_primary_services_discover err {:?}", err); err @@ -137,9 +128,7 @@ pub(crate) async fn discover_service( portal(conn_handle) .wait_once(|ble_evt| unsafe { match (*ble_evt).header.evt_id as u32 { - raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => { - return Err(DiscoverError::Disconnected) - } + raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => return Err(DiscoverError::Disconnected), raw::BLE_GATTC_EVTS_BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP => { let gattc_evt = check_status(ble_evt)?; let params = get_union_field(ble_evt, &gattc_evt.params.prim_srvc_disc_rsp); @@ -189,16 +178,13 @@ async fn discover_characteristics( portal(conn_handle) .wait_once(|ble_evt| unsafe { match (*ble_evt).header.evt_id as u32 { - raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => { - return Err(DiscoverError::Disconnected) - } + raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => return Err(DiscoverError::Disconnected), raw::BLE_GATTC_EVTS_BLE_GATTC_EVT_CHAR_DISC_RSP => { let gattc_evt = check_status(ble_evt)?; let params = get_union_field(ble_evt, &gattc_evt.params.char_disc_rsp); let v = get_flexarray(ble_evt, ¶ms.chars, params.count as usize); - let v = Vec::from_slice(v).unwrap_or_else(|_| { - panic!("too many gatt chars, increase DiscCharsMax: {:?}", v.len()) - }); + let v = Vec::from_slice(v) + .unwrap_or_else(|_| panic!("too many gatt chars, increase DiscCharsMax: {:?}", v.len())); Ok(v) } e => panic!("unexpected event {}", e), @@ -233,16 +219,13 @@ async fn discover_descriptors( portal(conn_handle) .wait_once(|ble_evt| unsafe { match (*ble_evt).header.evt_id as u32 { - raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => { - return Err(DiscoverError::Disconnected) - } + raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => return Err(DiscoverError::Disconnected), raw::BLE_GATTC_EVTS_BLE_GATTC_EVT_DESC_DISC_RSP => { let gattc_evt = check_status(ble_evt)?; let params = get_union_field(ble_evt, &gattc_evt.params.desc_disc_rsp); let v = get_flexarray(ble_evt, ¶ms.descs, params.count as usize); - let v = Vec::from_slice(v).unwrap_or_else(|_| { - panic!("too many gatt descs, increase DiscDescsMax: {:?}", v.len()) - }); + let v = Vec::from_slice(v) + .unwrap_or_else(|_| panic!("too many gatt descs, increase DiscDescsMax: {:?}", v.len())); Ok(v) } e => panic!("unexpected event {}", e), @@ -262,9 +245,7 @@ async fn discover_inner( ) -> Result<(), DiscoverError> { // Calcuate range of possible descriptors let start_handle = curr.handle_value + 1; - let end_handle = next - .map(|c| c.handle_decl - 1) - .unwrap_or(svc.handle_range.end_handle); + let end_handle = next.map(|c| c.handle_decl - 1).unwrap_or(svc.handle_range.end_handle); let characteristic = Characteristic { uuid: Uuid::from_raw(curr.uuid), @@ -306,9 +287,7 @@ pub async fn discover(conn: &Connection) -> Result // TODO handle drop. Probably doable gracefully (no DropBomb) let svc = match discover_service(conn, T::uuid()).await { - Err(DiscoverError::Gatt(GattError::AtterrAttributeNotFound)) => { - Err(DiscoverError::ServiceNotFound) - } + Err(DiscoverError::Gatt(GattError::AtterrAttributeNotFound)) => Err(DiscoverError::ServiceNotFound), x => x, }?; @@ -380,9 +359,7 @@ pub async fn read(conn: &Connection, handle: u16, buf: &mut [u8]) -> Result { - return Some(Err(ReadError::Disconnected)) - } + raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => return Some(Err(ReadError::Disconnected)), raw::BLE_GATTC_EVTS_BLE_GATTC_EVT_READ_RSP => { let gattc_evt = match check_status(ble_evt) { Ok(evt) => evt, @@ -453,9 +430,7 @@ pub async fn write(conn: &Connection, handle: u16, buf: &[u8]) -> Result<(), Wri portal(conn_handle) .wait_many(|ble_evt| unsafe { match (*ble_evt).header.evt_id as u32 { - raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => { - return Some(Err(WriteError::Disconnected)) - } + raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => return Some(Err(WriteError::Disconnected)), raw::BLE_GATTC_EVTS_BLE_GATTC_EVT_WRITE_RSP => { match check_status(ble_evt) { Ok(_) => {} @@ -472,11 +447,7 @@ pub async fn write(conn: &Connection, handle: u16, buf: &[u8]) -> Result<(), Wri .await } -pub async fn write_without_response( - conn: &Connection, - handle: u16, - buf: &[u8], -) -> Result<(), WriteError> { +pub async fn write_without_response(conn: &Connection, handle: u16, buf: &[u8]) -> Result<(), WriteError> { loop { let conn_handle = conn.with_state(|state| state.check_connected())?; @@ -500,9 +471,7 @@ pub async fn write_without_response( portal(conn_handle) .wait_many(|ble_evt| unsafe { match (*ble_evt).header.evt_id as u32 { - raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => { - return Some(Err(WriteError::Disconnected)) - } + raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => return Some(Err(WriteError::Disconnected)), raw::BLE_GATTC_EVTS_BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE => Some(Ok(())), _ => None, } @@ -538,11 +507,7 @@ impl From for TryWriteError { } } -pub fn try_write_without_response( - conn: &Connection, - handle: u16, - buf: &[u8], -) -> Result<(), TryWriteError> { +pub fn try_write_without_response(conn: &Connection, handle: u16, buf: &[u8]) -> Result<(), TryWriteError> { let conn_handle = conn.with_state(|state| state.check_connected())?; assert!(buf.len() <= u16::MAX as usize); @@ -563,9 +528,7 @@ pub fn try_write_without_response( } } -unsafe fn check_status( - ble_evt: *const raw::ble_evt_t, -) -> Result<&'static raw::ble_gattc_evt_t, GattError> { +unsafe fn check_status(ble_evt: *const raw::ble_evt_t) -> Result<&'static raw::ble_gattc_evt_t, GattError> { let gattc_evt = get_union_field(ble_evt, &(*ble_evt).evt.gattc_evt); match gattc_evt.gatt_status as u32 { raw::BLE_GATT_STATUS_SUCCESS => Ok(gattc_evt), @@ -633,9 +596,7 @@ pub(crate) async fn att_mtu_exchange(conn: &Connection, mtu: u16) -> Result<(), portal(conn_handle) .wait_once(|ble_evt| unsafe { match (*ble_evt).header.evt_id as u32 { - raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => { - return Err(MtuExchangeError::Disconnected) - } + raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => return Err(MtuExchangeError::Disconnected), raw::BLE_GATTC_EVTS_BLE_GATTC_EVT_EXCHANGE_MTU_RSP => { let gattc_evt = match check_status(ble_evt) { Ok(evt) => evt, diff --git a/nrf-softdevice/src/ble/gatt_server.rs b/nrf-softdevice/src/ble/gatt_server.rs index 9c655fb..6694250 100644 --- a/nrf-softdevice/src/ble/gatt_server.rs +++ b/nrf-softdevice/src/ble/gatt_server.rs @@ -4,10 +4,8 @@ //! In a connection any device can be server and client, and even both can be both at the same time. use crate::ble::*; -use crate::raw; use crate::util::{get_flexarray, get_union_field, Portal}; -use crate::RawError; -use crate::Softdevice; +use crate::{raw, RawError, Softdevice}; pub mod builder; pub mod characteristic; @@ -111,9 +109,7 @@ where portal(conn_handle) .wait_many(|ble_evt| unsafe { match (*ble_evt).header.evt_id as u32 { - raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => { - return Some(Err(RunError::Disconnected)) - } + raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => return Some(Err(RunError::Disconnected)), raw::BLE_GATTS_EVTS_BLE_GATTS_EVT_WRITE => { let evt = &*ble_evt; let gatts_evt = get_union_field(ble_evt, &evt.evt.gatts_evt); @@ -131,8 +127,7 @@ where } raw::BLE_GATTS_EVTS_BLE_GATTS_EVT_SYS_ATTR_MISSING => { debug!("initializing gatt sys att"); - let ret = - raw::sd_ble_gatts_sys_attr_set(conn_handle, ::core::ptr::null(), 0, 0); + let ret = raw::sd_ble_gatts_sys_attr_set(conn_handle, ::core::ptr::null(), 0, 0); RawError::convert(ret).err(); } _ => {} @@ -161,9 +156,7 @@ pub fn get_value(_sd: &Softdevice, handle: u16, buf: &mut [u8]) -> Result buf.len() { @@ -192,9 +185,7 @@ pub fn set_value(_sd: &Softdevice, handle: u16, val: &[u8]) -> Result<(), SetVal len: val.len() as _, offset: 0, }; - let ret = unsafe { - raw::sd_ble_gatts_value_set(raw::BLE_CONN_HANDLE_INVALID as u16, handle, &mut value) - }; + let ret = unsafe { raw::sd_ble_gatts_value_set(raw::BLE_CONN_HANDLE_INVALID as u16, handle, &mut value) }; RawError::convert(ret)?; Ok(()) @@ -257,11 +248,7 @@ impl From for IndicateValueError { } /// This will fail if an indication is already in progress -pub fn indicate_value( - conn: &Connection, - handle: u16, - val: &[u8], -) -> Result<(), IndicateValueError> { +pub fn indicate_value(conn: &Connection, handle: u16, val: &[u8]) -> Result<(), IndicateValueError> { let conn_handle = conn.with_state(|state| state.check_connected())?; let mut len: u16 = val.len() as _; @@ -286,14 +273,8 @@ pub(crate) unsafe fn on_evt(ble_evt: *const raw::ble_evt_t) { let params = get_union_field(ble_evt, &gatts_evt.params.exchange_mtu_request); let want_mtu = params.client_rx_mtu; let max_mtu = crate::Softdevice::steal().att_mtu; - let mtu = want_mtu - .min(max_mtu) - .max(raw::BLE_GATT_ATT_MTU_DEFAULT as u16); - trace!( - "att mtu exchange: peer wants mtu {:?}, granting {:?}", - want_mtu, - mtu - ); + let mtu = want_mtu.min(max_mtu).max(raw::BLE_GATT_ATT_MTU_DEFAULT as u16); + trace!("att mtu exchange: peer wants mtu {:?}, granting {:?}", want_mtu, mtu); let ret = { raw::sd_ble_gatts_exchange_mtu_reply(conn_handle, mtu) }; if let Err(_err) = RawError::convert(ret) { diff --git a/nrf-softdevice/src/ble/gatt_server/builder.rs b/nrf-softdevice/src/ble/gatt_server/builder.rs index c0bff21..4d40258 100644 --- a/nrf-softdevice/src/ble/gatt_server/builder.rs +++ b/nrf-softdevice/src/ble/gatt_server/builder.rs @@ -1,6 +1,9 @@ #![allow(dead_code)] -use core::{convert::TryInto, marker::PhantomData, mem, ptr::null}; +use core::convert::TryInto; +use core::marker::PhantomData; +use core::mem; +use core::ptr::null; #[cfg(feature = "alloc")] extern crate alloc; @@ -8,12 +11,10 @@ extern crate alloc; #[cfg(feature = "alloc")] use alloc::boxed::Box; -use crate::{ble::Uuid, raw, RawError, Softdevice}; - -use super::{ - characteristic::{self, AttributeMetadata}, - CharacteristicHandles, DescriptorHandle, IncludedServiceHandle, RegisterError, ServiceHandle, -}; +use super::characteristic::{self, AttributeMetadata}; +use super::{CharacteristicHandles, DescriptorHandle, IncludedServiceHandle, RegisterError, ServiceHandle}; +use crate::ble::Uuid; +use crate::{raw, RawError, Softdevice}; pub struct ServiceBuilder<'a> { handle: u16, @@ -89,9 +90,7 @@ impl<'a> ServiceBuilder<'a> { let mut char_md = raw::ble_gatts_char_md_t { char_props, char_ext_props, - p_char_user_desc: char_md - .user_description - .map_or(null(), |x| x.value.as_ptr()), + p_char_user_desc: char_md.user_description.map_or(null(), |x| x.value.as_ptr()), char_user_desc_max_size: char_md.user_description.map_or(0, |x| x.max_len), char_user_desc_size: char_md.user_description.map_or(0, |x| x.value.len() as u16), p_char_pf: null(), @@ -112,12 +111,7 @@ impl<'a> ServiceBuilder<'a> { let mut handles: raw::ble_gatts_char_handles_t = unsafe { mem::zeroed() }; let ret = unsafe { - raw::sd_ble_gatts_characteristic_add( - self.handle, - &mut char_md as _, - &mut attr as _, - &mut handles as _, - ) + raw::sd_ble_gatts_characteristic_add(self.handle, &mut char_md as _, &mut attr as _, &mut handles as _) }; RawError::convert(ret)?; @@ -134,13 +128,9 @@ impl<'a> ServiceBuilder<'a> { }) } - pub fn include_service( - &mut self, - service: &ServiceHandle, - ) -> Result { + pub fn include_service(&mut self, service: &ServiceHandle) -> Result { let mut handle = 0; - let ret = - unsafe { raw::sd_ble_gatts_include_add(self.handle, service.0, &mut handle as _) }; + let ret = unsafe { raw::sd_ble_gatts_include_add(self.handle, service.0, &mut handle as _) }; RawError::convert(ret)?; Ok(IncludedServiceHandle(handle)) @@ -190,13 +180,7 @@ impl<'a> CharacteristicBuilder<'a> { }; let mut handle = 0; - let ret = unsafe { - raw::sd_ble_gatts_descriptor_add( - self.handles.value_handle, - &attr as _, - &mut handle as _, - ) - }; + let ret = unsafe { raw::sd_ble_gatts_descriptor_add(self.handles.value_handle, &attr as _, &mut handle as _) }; RawError::convert(ret)?; Ok(DescriptorHandle(handle)) diff --git a/nrf-softdevice/src/ble/gatt_traits.rs b/nrf-softdevice/src/ble/gatt_traits.rs index 490e59a..2b27f8f 100644 --- a/nrf-softdevice/src/ble/gatt_traits.rs +++ b/nrf-softdevice/src/ble/gatt_traits.rs @@ -1,6 +1,6 @@ use core::convert::TryInto; -use core::mem; -use core::slice; +use core::{mem, slice}; + use heapless::{String, Vec}; #[derive(Debug, PartialEq, Eq, Clone, Copy)] diff --git a/nrf-softdevice/src/ble/l2cap.rs b/nrf-softdevice/src/ble/l2cap.rs index 4488e92..a5b79d3 100644 --- a/nrf-softdevice/src/ble/l2cap.rs +++ b/nrf-softdevice/src/ble/l2cap.rs @@ -1,15 +1,13 @@ //! Link-Layer Control and Adaptation Protocol use core::marker::PhantomData; -use core::ptr; use core::ptr::NonNull; use core::sync::atomic::{AtomicBool, Ordering}; -use core::u16; +use core::{ptr, u16}; use crate::ble::*; -use crate::raw; use crate::util::{get_union_field, Portal}; -use crate::{RawError, Softdevice}; +use crate::{raw, RawError, Softdevice}; #[cfg(feature = "ble-l2cap-credit-wrokaround")] fn credit_hack_refill(conn: u16, cid: u16) { @@ -33,10 +31,7 @@ fn credit_hack_refill(conn: u16, cid: u16) { let ret = unsafe { raw::sd_ble_l2cap_ch_flow_control(conn, cid, CREDITS_MAX, ptr::null_mut()) }; if let Err(err) = RawError::convert(ret) { - warn!( - "sd_ble_l2cap_ch_flow_control credits=CREDITS_MAX err {:?}", - err - ); + warn!("sd_ble_l2cap_ch_flow_control credits=CREDITS_MAX err {:?}", err); return; } @@ -162,17 +157,10 @@ impl L2cap

{ }) } - Self { - _private: PhantomData, - } + Self { _private: PhantomData } } - pub async fn setup( - &self, - conn: &Connection, - config: &Config, - psm: u16, - ) -> Result, SetupError> { + pub async fn setup(&self, conn: &Connection, config: &Config, psm: u16) -> Result, SetupError> { let sd = unsafe { Softdevice::steal() }; let conn_handle = conn.with_state(|state| state.check_connected())?; @@ -199,9 +187,7 @@ impl L2cap

{ portal(conn_handle) .wait_once(|ble_evt| unsafe { match (*ble_evt).header.evt_id as u32 { - raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => { - return Err(SetupError::Disconnected) - } + raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => return Err(SetupError::Disconnected), raw::BLE_L2CAP_EVTS_BLE_L2CAP_EVT_CH_RELEASED => { // It is possible to get L2CAP_EVT_CH_RELEASED for the // "half-setup" channel if the conn gets disconnected while @@ -216,12 +202,8 @@ impl L2cap

{ let _ = config.credits; #[cfg(not(feature = "ble-l2cap-credit-wrokaround"))] if config.credits != 1 { - let ret = raw::sd_ble_l2cap_ch_flow_control( - conn_handle, - cid, - config.credits, - ptr::null_mut(), - ); + let ret = + raw::sd_ble_l2cap_ch_flow_control(conn_handle, cid, config.credits, ptr::null_mut()); if let Err(err) = RawError::convert(ret) { warn!("sd_ble_l2cap_ch_flow_control err {:?}", err); return Err(err.into()); @@ -245,12 +227,7 @@ impl L2cap

{ .await } - pub async fn listen( - &self, - conn: &Connection, - config: &Config, - psm: u16, - ) -> Result, SetupError> { + pub async fn listen(&self, conn: &Connection, config: &Config, psm: u16) -> Result, SetupError> { self.listen_with(conn, config, move |got_psm| got_psm == psm) .await .map(|(_, ch)| ch) @@ -268,9 +245,7 @@ impl L2cap

{ portal(conn_handle) .wait_many(|ble_evt| unsafe { match (*ble_evt).header.evt_id as u32 { - raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => { - return Some(Err(SetupError::Disconnected)) - } + raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => return Some(Err(SetupError::Disconnected)), raw::BLE_L2CAP_EVTS_BLE_L2CAP_EVT_CH_SETUP_REQUEST => { let l2cap_evt = get_union_field(ble_evt, &(*ble_evt).evt.l2cap_evt); let evt = &l2cap_evt.params.ch_setup_request; @@ -379,9 +354,7 @@ impl Channel

{ let ret = unsafe { raw::sd_ble_l2cap_ch_tx(conn_handle, self.cid, &data) }; match RawError::convert(ret) { - Err(RawError::Resources) => { - Err(TxError::TxQueueFull(unsafe { P::from_raw_parts(ptr, len) })) - } + Err(RawError::Resources) => Err(TxError::TxQueueFull(unsafe { P::from_raw_parts(ptr, len) })), Err(err) => { warn!("sd_ble_l2cap_ch_tx err {:?}", err); // The SD didn't take ownership of the buffer, so it's on us to free it. @@ -446,9 +419,7 @@ impl Channel

{ .wait_many(|ble_evt| unsafe { match (*ble_evt).header.evt_id as u32 { raw::BLE_GAP_EVTS_BLE_GAP_EVT_DISCONNECTED => Some(Err(RxError::Disconnected)), - raw::BLE_L2CAP_EVTS_BLE_L2CAP_EVT_CH_RELEASED => { - Some(Err(RxError::Disconnected)) - } + raw::BLE_L2CAP_EVTS_BLE_L2CAP_EVT_CH_RELEASED => Some(Err(RxError::Disconnected)), raw::BLE_L2CAP_EVTS_BLE_L2CAP_EVT_CH_RX => { let l2cap_evt = get_union_field(ble_evt, &(*ble_evt).evt.l2cap_evt); let evt = &l2cap_evt.params.rx; diff --git a/nrf-softdevice/src/ble/peripheral.rs b/nrf-softdevice/src/ble/peripheral.rs index 5c8ee41..f5edc2a 100644 --- a/nrf-softdevice/src/ble/peripheral.rs +++ b/nrf-softdevice/src/ble/peripheral.rs @@ -1,13 +1,10 @@ //! Bluetooth Peripheral operations. Peripheral devices emit advertisements, and optionally accept connections from Central devices. -use core::mem; -use core::ptr; +use core::{mem, ptr}; use crate::ble::*; -use crate::raw; -use crate::util::get_union_field; -use crate::util::{OnDrop, Portal}; -use crate::{RawError, Softdevice}; +use crate::util::{get_union_field, OnDrop, Portal}; +use crate::{raw, RawError, Softdevice}; struct RawAdvertisement<'a> { kind: u8, @@ -40,10 +37,7 @@ pub enum ConnectableAdvertisement<'a> { impl<'a> From> for RawAdvertisement<'a> { fn from(val: ConnectableAdvertisement<'a>) -> RawAdvertisement<'a> { match val { - ConnectableAdvertisement::ScannableUndirected { - adv_data, - scan_data, - } => RawAdvertisement { + ConnectableAdvertisement::ScannableUndirected { adv_data, scan_data } => RawAdvertisement { kind: raw::BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED as u8, adv_data: Some(adv_data), scan_data: Some(scan_data), @@ -53,30 +47,23 @@ impl<'a> From> for RawAdvertisement<'a> { adv_data: None, scan_data: Some(scan_data), }, - ConnectableAdvertisement::NonscannableDirectedHighDuty { scan_data } => { - RawAdvertisement { - kind: raw::BLE_GAP_ADV_TYPE_CONNECTABLE_NONSCANNABLE_DIRECTED_HIGH_DUTY_CYCLE - as u8, - adv_data: None, - scan_data: Some(scan_data), - } - } + ConnectableAdvertisement::NonscannableDirectedHighDuty { scan_data } => RawAdvertisement { + kind: raw::BLE_GAP_ADV_TYPE_CONNECTABLE_NONSCANNABLE_DIRECTED_HIGH_DUTY_CYCLE as u8, + adv_data: None, + scan_data: Some(scan_data), + }, #[cfg(any(feature = "s132", feature = "s140"))] - ConnectableAdvertisement::ExtendedNonscannableUndirected { adv_data } => { - RawAdvertisement { - kind: raw::BLE_GAP_ADV_TYPE_EXTENDED_CONNECTABLE_NONSCANNABLE_UNDIRECTED as u8, - adv_data: Some(adv_data), - scan_data: None, - } - } + ConnectableAdvertisement::ExtendedNonscannableUndirected { adv_data } => RawAdvertisement { + kind: raw::BLE_GAP_ADV_TYPE_EXTENDED_CONNECTABLE_NONSCANNABLE_UNDIRECTED as u8, + adv_data: Some(adv_data), + scan_data: None, + }, #[cfg(any(feature = "s132", feature = "s140"))] - ConnectableAdvertisement::ExtendedNonscannableDirected { adv_data } => { - RawAdvertisement { - kind: raw::BLE_GAP_ADV_TYPE_EXTENDED_CONNECTABLE_NONSCANNABLE_DIRECTED as u8, - adv_data: Some(adv_data), - scan_data: None, - } - } + ConnectableAdvertisement::ExtendedNonscannableDirected { adv_data } => RawAdvertisement { + kind: raw::BLE_GAP_ADV_TYPE_EXTENDED_CONNECTABLE_NONSCANNABLE_DIRECTED as u8, + adv_data: Some(adv_data), + scan_data: None, + }, } } } @@ -114,10 +101,7 @@ pub enum NonconnectableAdvertisement<'a> { impl<'a> From> for RawAdvertisement<'a> { fn from(val: NonconnectableAdvertisement<'a>) -> RawAdvertisement<'a> { match val { - NonconnectableAdvertisement::ScannableUndirected { - adv_data, - scan_data, - } => RawAdvertisement { + NonconnectableAdvertisement::ScannableUndirected { adv_data, scan_data } => RawAdvertisement { kind: raw::BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED as _, adv_data: Some(adv_data), scan_data: Some(scan_data), @@ -128,40 +112,29 @@ impl<'a> From> for RawAdvertisement<'a> { scan_data: None, }, #[cfg(any(feature = "s132", feature = "s140"))] - NonconnectableAdvertisement::ExtendedScannableUndirected { - adv_data, - scan_data, - } => RawAdvertisement { + NonconnectableAdvertisement::ExtendedScannableUndirected { adv_data, scan_data } => RawAdvertisement { kind: raw::BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_SCANNABLE_UNDIRECTED as _, adv_data: Some(adv_data), scan_data: Some(scan_data), }, #[cfg(any(feature = "s132", feature = "s140"))] - NonconnectableAdvertisement::ExtendedScannableDirected { - adv_data, - scan_data, - } => RawAdvertisement { + NonconnectableAdvertisement::ExtendedScannableDirected { adv_data, scan_data } => RawAdvertisement { kind: raw::BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_SCANNABLE_DIRECTED as _, adv_data: Some(adv_data), scan_data: Some(scan_data), }, #[cfg(any(feature = "s132", feature = "s140"))] - NonconnectableAdvertisement::ExtendedNonscannableUndirected { adv_data } => { - RawAdvertisement { - kind: raw::BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED - as _, - adv_data: Some(adv_data), - scan_data: None, - } - } + NonconnectableAdvertisement::ExtendedNonscannableUndirected { adv_data } => RawAdvertisement { + kind: raw::BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED as _, + adv_data: Some(adv_data), + scan_data: None, + }, #[cfg(any(feature = "s132", feature = "s140"))] - NonconnectableAdvertisement::ExtendedNonscannableDirected { adv_data } => { - RawAdvertisement { - kind: raw::BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_NONSCANNABLE_DIRECTED as _, - adv_data: Some(adv_data), - scan_data: None, - } - } + NonconnectableAdvertisement::ExtendedNonscannableDirected { adv_data } => RawAdvertisement { + kind: raw::BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_NONSCANNABLE_DIRECTED as _, + adv_data: Some(adv_data), + scan_data: None, + }, } } } @@ -213,9 +186,7 @@ fn start_adv(adv: RawAdvertisement<'_>, config: &Config) -> Result<(), Advertise scan_rsp_data: map_data(adv.scan_data), }; - let ret = unsafe { - raw::sd_ble_gap_adv_set_configure(&mut ADV_HANDLE as _, &datas as _, &adv_params as _) - }; + let ret = unsafe { raw::sd_ble_gap_adv_set_configure(&mut ADV_HANDLE as _, &datas as _, &adv_params as _) }; RawError::convert(ret).map_err(|err| { warn!("sd_ble_gap_adv_set_configure err {:?}", err); err diff --git a/nrf-softdevice/src/ble/types.rs b/nrf-softdevice/src/ble/types.rs index 6011808..b426090 100644 --- a/nrf-softdevice/src/ble/types.rs +++ b/nrf-softdevice/src/ble/types.rs @@ -1,7 +1,6 @@ use core::mem; -use crate::raw; -use crate::RawError; +use crate::{raw, RawError}; #[repr(transparent)] #[derive(Copy, Clone)] diff --git a/nrf-softdevice/src/critical_section_impl.rs b/nrf-softdevice/src/critical_section_impl.rs index 828e102..59f9445 100644 --- a/nrf-softdevice/src/critical_section_impl.rs +++ b/nrf-softdevice/src/critical_section_impl.rs @@ -1,7 +1,8 @@ -use crate::pac::{Interrupt, NVIC}; use core::arch::asm; use core::sync::atomic::{compiler_fence, AtomicBool, Ordering}; +use crate::pac::{Interrupt, NVIC}; + #[cfg(any(feature = "nrf52810", feature = "nrf52811"))] const RESERVED_IRQS: u32 = (1 << (Interrupt::POWER_CLOCK as u8)) | (1 << (Interrupt::RADIO as u8)) diff --git a/nrf-softdevice/src/events.rs b/nrf-softdevice/src/events.rs index f4a397e..c9d4362 100644 --- a/nrf-softdevice/src/events.rs +++ b/nrf-softdevice/src/events.rs @@ -1,13 +1,13 @@ use core::convert::TryFrom; use core::mem::MaybeUninit; use core::task::Poll; + use embassy::waitqueue::AtomicWaker; use futures::future::poll_fn; use num_enum::{IntoPrimitive, TryFromPrimitive}; use crate::pac::interrupt; -use crate::raw; -use crate::RawError; +use crate::{raw, RawError}; static SWI2_WAKER: AtomicWaker = AtomicWaker::new(); diff --git a/nrf-softdevice/src/flash.rs b/nrf-softdevice/src/flash.rs index afee483..2ba2337 100644 --- a/nrf-softdevice/src/flash.rs +++ b/nrf-softdevice/src/flash.rs @@ -1,12 +1,12 @@ use core::future::Future; use core::marker::PhantomData; use core::sync::atomic::{AtomicBool, Ordering}; + use embedded_storage::nor_flash::{ErrorType, NorFlashError, NorFlashErrorKind, ReadNorFlash}; use embedded_storage_async::nor_flash::{AsyncNorFlash, AsyncReadNorFlash}; -use crate::raw; use crate::util::{DropBomb, Signal}; -use crate::{RawError, Softdevice}; +use crate::{raw, RawError, Softdevice}; #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -51,9 +51,7 @@ impl Flash { panic!("nrf_softdevice::Softdevice::take_flash() called multiple times.") } - Flash { - _private: PhantomData, - } + Flash { _private: PhantomData } } } @@ -78,9 +76,7 @@ impl ReadNorFlash for Flash { // Reading is simple since SoC flash is memory-mapped :) // TODO check addr/len is in bounds. - data.copy_from_slice(unsafe { - core::slice::from_raw_parts(address as *const u8, data.len()) - }); + data.copy_from_slice(unsafe { core::slice::from_raw_parts(address as *const u8, data.len()) }); Ok(()) } diff --git a/nrf-softdevice/src/lib.rs b/nrf-softdevice/src/lib.rs index d018a36..e51112b 100644 --- a/nrf-softdevice/src/lib.rs +++ b/nrf-softdevice/src/lib.rs @@ -5,9 +5,7 @@ pub(crate) mod util; #[cfg(not(any(feature = "ble-central", feature = "ble-peripheral",)))] -compile_error!( - "You must activate at least one of the following features: ble-central, ble-peripheral" -); +compile_error!("You must activate at least one of the following features: ble-central, ble-peripheral"); #[cfg(not(any( feature = "s112", @@ -135,7 +133,6 @@ use nrf52832_pac as pac; use nrf52833_pac as pac; #[cfg(feature = "nrf52840")] use nrf52840_pac as pac; - #[cfg(feature = "s112")] pub use nrf_softdevice_s112 as raw; #[cfg(feature = "s113")] @@ -167,6 +164,5 @@ mod temperature; pub use temperature::temperature_celsius; mod random; -pub use random::random_bytes; - pub use nrf_softdevice_macro::*; +pub use random::random_bytes; diff --git a/nrf-softdevice/src/softdevice.rs b/nrf-softdevice/src/softdevice.rs index 282ba04..84248e8 100644 --- a/nrf-softdevice/src/softdevice.rs +++ b/nrf-softdevice/src/softdevice.rs @@ -1,11 +1,10 @@ use core::marker::PhantomData; use core::ptr; use core::sync::atomic::{AtomicBool, Ordering}; + use embassy::util::Forever; -use crate::raw; -use crate::RawError; -use crate::{pac, SocEvent}; +use crate::{pac, raw, RawError, SocEvent}; unsafe extern "C" fn fault_handler(id: u32, pc: u32, info: u32) { match (id, info) { @@ -148,9 +147,7 @@ impl Softdevice { &raw::ble_cfg_t { conn_cfg: raw::ble_conn_cfg_t { conn_cfg_tag: APP_CONN_CFG_TAG, - params: raw::ble_conn_cfg_t__bindgen_ty_1 { - gattc_conn_cfg: val, - }, + params: raw::ble_conn_cfg_t__bindgen_ty_1 { gattc_conn_cfg: val }, }, }, ); @@ -162,9 +159,7 @@ impl Softdevice { &raw::ble_cfg_t { conn_cfg: raw::ble_conn_cfg_t { conn_cfg_tag: APP_CONN_CFG_TAG, - params: raw::ble_conn_cfg_t__bindgen_ty_1 { - gatts_conn_cfg: val, - }, + params: raw::ble_conn_cfg_t__bindgen_ty_1 { gatts_conn_cfg: val }, }, }, ); @@ -177,9 +172,7 @@ impl Softdevice { &raw::ble_cfg_t { conn_cfg: raw::ble_conn_cfg_t { conn_cfg_tag: APP_CONN_CFG_TAG, - params: raw::ble_conn_cfg_t__bindgen_ty_1 { - l2cap_conn_cfg: val, - }, + params: raw::ble_conn_cfg_t__bindgen_ty_1 { l2cap_conn_cfg: val }, }, }, ); @@ -198,9 +191,7 @@ impl Softdevice { cfg_set( raw::BLE_GAP_CFGS_BLE_GAP_CFG_ROLE_COUNT, &raw::ble_cfg_t { - gap_cfg: raw::ble_gap_cfg_t { - role_count_cfg: val, - }, + gap_cfg: raw::ble_gap_cfg_t { role_count_cfg: val }, }, ); } @@ -209,9 +200,7 @@ impl Softdevice { cfg_set( raw::BLE_GAP_CFGS_BLE_GAP_CFG_DEVICE_NAME, &raw::ble_cfg_t { - gap_cfg: raw::ble_gap_cfg_t { - device_name_cfg: val, - }, + gap_cfg: raw::ble_gap_cfg_t { device_name_cfg: val }, }, ); } @@ -220,9 +209,7 @@ impl Softdevice { cfg_set( raw::BLE_GAP_CFGS_BLE_GAP_CFG_PPCP_INCL_CONFIG, &raw::ble_cfg_t { - gap_cfg: raw::ble_gap_cfg_t { - ppcp_include_cfg: val, - }, + gap_cfg: raw::ble_gap_cfg_t { ppcp_include_cfg: val }, }, ); } @@ -231,9 +218,7 @@ impl Softdevice { cfg_set( raw::BLE_GAP_CFGS_BLE_GAP_CFG_CAR_INCL_CONFIG, &raw::ble_cfg_t { - gap_cfg: raw::ble_gap_cfg_t { - car_include_cfg: val, - }, + gap_cfg: raw::ble_gap_cfg_t { car_include_cfg: val }, }, ); } @@ -241,9 +226,7 @@ impl Softdevice { cfg_set( raw::BLE_GATTS_CFGS_BLE_GATTS_CFG_SERVICE_CHANGED, &raw::ble_cfg_t { - gatts_cfg: raw::ble_gatts_cfg_t { - service_changed: val, - }, + gatts_cfg: raw::ble_gatts_cfg_t { service_changed: val }, }, ); } @@ -258,17 +241,17 @@ impl Softdevice { let mut wanted_app_ram_base = app_ram_base; let ret = unsafe { raw::sd_ble_enable(&mut wanted_app_ram_base as _) }; - info!( - "softdevice RAM: {:?} bytes", - wanted_app_ram_base - 0x20000000 - ); + info!("softdevice RAM: {:?} bytes", wanted_app_ram_base - 0x20000000); match RawError::convert(ret) { Ok(()) => {} Err(RawError::NoMem) => { if wanted_app_ram_base <= app_ram_base { panic!("selected configuration has too high RAM requirements.") } else { - panic!("too little RAM for softdevice. Change your app's RAM start address to {:x}", wanted_app_ram_base); + panic!( + "too little RAM for softdevice. Change your app's RAM start address to {:x}", + wanted_app_ram_base + ); } } Err(err) => panic!("sd_ble_enable err {:?}", err), diff --git a/nrf-softdevice/src/util/mod.rs b/nrf-softdevice/src/util/mod.rs index c341a1d..03492d3 100644 --- a/nrf-softdevice/src/util/mod.rs +++ b/nrf-softdevice/src/util/mod.rs @@ -32,10 +32,7 @@ pub(crate) unsafe fn get_flexarray( /// This function is a workaround for UB in __BindgenUnionField /// see https://github.com/rust-lang/rust-bindgen/issues/1892 /// see https://github.com/rust-lang/unsafe-code-guidelines/issues/134 -pub(crate) unsafe fn get_union_field( - orig_ptr: *const raw::ble_evt_t, - member: &raw::__BindgenUnionField, -) -> &T { +pub(crate) unsafe fn get_union_field(orig_ptr: *const raw::ble_evt_t, member: &raw::__BindgenUnionField) -> &T { let offs = member as *const _ as usize - orig_ptr as usize; let sanitized_ptr = (orig_ptr as *const u8).add(offs) as *const T; &*sanitized_ptr diff --git a/nrf-softdevice/src/util/portal.rs b/nrf-softdevice/src/util/portal.rs index bc6becd..92505a6 100644 --- a/nrf-softdevice/src/util/portal.rs +++ b/nrf-softdevice/src/util/portal.rs @@ -22,8 +22,7 @@ unsafe impl Sync for Portal {} fn assert_thread_mode() { assert!( - cortex_m::peripheral::SCB::vect_active() - == cortex_m::peripheral::scb::VectActive::ThreadMode, + cortex_m::peripheral::SCB::vect_active() == cortex_m::peripheral::scb::VectActive::ThreadMode, "portals are not usable from interrupts" ); } -- cgit v1.2.3