summaryrefslogtreecommitdiff
path: root/nrf-softdevice
diff options
context:
space:
mode:
authorDario Nieuwenhuis <dirbaio@dirbaio.net>2021-08-18 23:35:38 +0200
committerGitHub <noreply@github.com>2021-08-18 23:35:38 +0200
commit1094ac4d82c9c8eab75d3199a7da4e8db6d096b9 (patch)
tree4ed8cc1b52ca5f5ec1191f028f696b31f304a4d5 /nrf-softdevice
parent29211a57b49b7c7b80a54ccd35336adff001f6b2 (diff)
downloadnrf-softdevice-1094ac4d82c9c8eab75d3199a7da4e8db6d096b9.zip
Update rust, embassy, PACs. Add support for nrf52805, 820. (#77)
Diffstat (limited to 'nrf-softdevice')
-rw-r--r--nrf-softdevice/Cargo.toml19
-rw-r--r--nrf-softdevice/src/ble/central.rs7
-rw-r--r--nrf-softdevice/src/ble/connection.rs22
-rw-r--r--nrf-softdevice/src/ble/gap.rs7
-rw-r--r--nrf-softdevice/src/ble/gatt_client.rs1
-rw-r--r--nrf-softdevice/src/ble/gatt_server.rs5
-rw-r--r--nrf-softdevice/src/events.rs4
-rw-r--r--nrf-softdevice/src/lib.rs23
-rw-r--r--nrf-softdevice/src/softdevice.rs10
-rw-r--r--nrf-softdevice/src/util/mod.rs9
-rw-r--r--nrf-softdevice/src/util/portal.rs1
11 files changed, 71 insertions, 37 deletions
diff --git a/nrf-softdevice/Cargo.toml b/nrf-softdevice/Cargo.toml
index 1fb39dc..1034aad 100644
--- a/nrf-softdevice/Cargo.toml
+++ b/nrf-softdevice/Cargo.toml
@@ -12,8 +12,10 @@ defmt-info = []
defmt-warn = []
defmt-error = []
+nrf52805 = ["nrf52805-pac"]
nrf52810 = ["nrf52810-pac"]
nrf52811 = ["nrf52811-pac"]
+nrf52820 = ["nrf52820-pac"]
nrf52832 = ["nrf52832-pac"]
nrf52833 = ["nrf52833-pac"]
nrf52840 = ["nrf52840-pac"]
@@ -27,8 +29,9 @@ s140 = ["nrf-softdevice-s140"]
ble-peripheral = []
ble-central = []
ble-l2cap = []
-ble-gatt-server = []
-ble-gatt-client = []
+ble-gatt = []
+ble-gatt-server = ["ble-gatt"]
+ble-gatt-client = ["ble-gatt"]
critical-section-impl = ["critical-section/custom-impl"]
@@ -44,11 +47,13 @@ cortex-m-rt = "0.6.13"
heapless = "0.7.1"
fixed = "1.5.0"
-nrf52810-pac = { version = "0.9.0", features = ["rt"], optional = true }
-nrf52811-pac = { version = "0.9.0", features = ["rt"], optional = true }
-nrf52832-pac = { version = "0.9.0", features = ["rt"], optional = true }
-nrf52833-pac = { version = "0.9.0", features = ["rt"], optional = true }
-nrf52840-pac = { version = "0.9.0", features = ["rt"], optional = true }
+nrf52805-pac = { version = "0.10.0", features = ["rt"], optional = true }
+nrf52810-pac = { version = "0.10.0", features = ["rt"], optional = true }
+nrf52811-pac = { version = "0.10.0", features = ["rt"], optional = true }
+nrf52820-pac = { version = "0.10.0", features = ["rt"], optional = true }
+nrf52832-pac = { version = "0.10.0", features = ["rt"], optional = true }
+nrf52833-pac = { version = "0.10.0", features = ["rt"], optional = true }
+nrf52840-pac = { version = "0.10.0", features = ["rt"], optional = true }
nrf-softdevice-s112 = { version = "0.1.1", path = "../nrf-softdevice-s112", optional = true }
nrf-softdevice-s113 = { version = "0.1.1", path = "../nrf-softdevice-s113", optional = true }
diff --git a/nrf-softdevice/src/ble/central.rs b/nrf-softdevice/src/ble/central.rs
index c2356d4..c30da39 100644
--- a/nrf-softdevice/src/ble/central.rs
+++ b/nrf-softdevice/src/ble/central.rs
@@ -6,7 +6,6 @@
use core::mem;
use core::ptr;
-use crate::ble::gap;
use crate::ble::types::*;
use crate::ble::{Address, Connection};
use crate::raw;
@@ -32,7 +31,7 @@ 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,
+ _sd: &Softdevice,
config: &ConnectConfig<'_>,
) -> Result<Connection, ConnectError> {
if let Some(w) = config.scan_config.whitelist {
@@ -75,7 +74,7 @@ pub async fn connect(
match Connection::new(conn_handle, role, peer_address, conn_params) {
Ok(conn) => {
#[cfg(any(feature = "s113", feature = "s132", feature = "s140"))]
- gap::do_data_length_update(conn_handle, ptr::null());
+ crate::ble::gap::do_data_length_update(conn_handle, ptr::null());
Ok(conn)
}
@@ -98,7 +97,7 @@ pub async fn connect(
#[cfg(feature = "ble-gatt-client")]
{
- let mtu = config.att_mtu.unwrap_or(sd.att_mtu);
+ let mtu = config.att_mtu.unwrap_or(_sd.att_mtu);
unwrap!(crate::ble::gatt_client::att_mtu_exchange(&conn, mtu).await);
}
diff --git a/nrf-softdevice/src/ble/connection.rs b/nrf-softdevice/src/ble/connection.rs
index 342524f..eac0c00 100644
--- a/nrf-softdevice/src/ble/connection.rs
+++ b/nrf-softdevice/src/ble/connection.rs
@@ -3,11 +3,11 @@ use core::cell::UnsafeCell;
use raw::ble_gap_conn_params_t;
-use crate::ble::types::*;
-use crate::ble::*;
+use crate::ble::types::{Address, AddressType, Role};
use crate::raw;
use crate::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>
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
@@ -66,6 +66,7 @@ pub(crate) struct ConnectionState {
pub conn_params: ble_gap_conn_params_t,
+ #[cfg(feature = "ble-gatt")]
pub att_mtu: u16, // Effective ATT_MTU size (in bytes).
#[cfg(any(feature = "s113", feature = "s132", feature = "s140"))]
pub data_length_effective: u8, // Effective data length (in bytes).
@@ -90,6 +91,7 @@ impl ConnectionState {
min_conn_interval: 0,
slave_latency: 0,
},
+ #[cfg(feature = "ble-gatt")]
att_mtu: 0,
#[cfg(any(feature = "s113", feature = "s132", feature = "s140"))]
data_length_effective: 0,
@@ -118,7 +120,7 @@ impl ConnectionState {
Ok(())
}
- pub(crate) fn on_disconnected(&mut self, ble_evt: *const raw::ble_evt_t) {
+ 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"
@@ -132,11 +134,11 @@ impl ConnectionState {
// Signal possible in-progess operations that the connection has disconnected.
#[cfg(feature = "ble-gatt-client")]
- gatt_client::portal(conn_handle).call(ble_evt);
+ crate::ble::gatt_client::portal(conn_handle).call(_ble_evt);
#[cfg(feature = "ble-gatt-server")]
- gatt_server::portal(conn_handle).call(ble_evt);
+ crate::ble::gatt_server::portal(conn_handle).call(_ble_evt);
#[cfg(feature = "ble-l2cap")]
- l2cap::portal(conn_handle).call(ble_evt);
+ crate::ble::l2cap::portal(conn_handle).call(_ble_evt);
trace!("conn {:?}: disconnected", _index);
}
@@ -215,6 +217,8 @@ impl Connection {
disconnecting: false,
conn_params,
+
+ #[cfg(feature = "ble-gatt")]
att_mtu: raw::BLE_GATT_ATT_MTU_DEFAULT as _,
#[cfg(any(feature = "s113", feature = "s132", feature = "s140"))]
@@ -236,6 +240,12 @@ impl Connection {
with_state(self.index, |s| s.conn_params)
}
+ /// Get the currently active ATT MTU.
+ #[cfg(feature = "ble-gatt")]
+ pub fn att_mtu(&self) -> u16 {
+ with_state(self.index, |s| s.att_mtu)
+ }
+
/// Set the connection params.
///
/// Note that this just initiates the connection param change, it does not wait for completion.
diff --git a/nrf-softdevice/src/ble/gap.rs b/nrf-softdevice/src/ble/gap.rs
index b28a49f..7b6fca5 100644
--- a/nrf-softdevice/src/ble/gap.rs
+++ b/nrf-softdevice/src/ble/gap.rs
@@ -1,6 +1,3 @@
-use core::mem;
-use core::ptr;
-
use crate::ble::*;
use crate::raw;
use crate::util::get_union_field;
@@ -143,7 +140,7 @@ pub(crate) unsafe fn on_evt(ble_evt: *const raw::ble_evt_t) {
);
let conn_handle = gap_evt.conn_handle;
- do_data_length_update(conn_handle, ptr::null());
+ do_data_length_update(conn_handle, core::ptr::null());
}
#[cfg(any(feature = "s113", feature = "s132", feature = "s140"))]
raw::BLE_GAP_EVTS_BLE_GAP_EVT_DATA_LENGTH_UPDATE => {
@@ -171,7 +168,7 @@ pub(crate) unsafe fn do_data_length_update(
conn_handle: u16,
params: *const raw::ble_gap_data_length_params_t,
) {
- let mut dl_limitation = mem::zeroed();
+ 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);
diff --git a/nrf-softdevice/src/ble/gatt_client.rs b/nrf-softdevice/src/ble/gatt_client.rs
index 48c5f72..5affd5f 100644
--- a/nrf-softdevice/src/ble/gatt_client.rs
+++ b/nrf-softdevice/src/ble/gatt_client.rs
@@ -605,6 +605,7 @@ impl From<RawError> for MtuExchangeError {
}
}
+#[cfg(feature = "ble-central")]
pub(crate) async fn att_mtu_exchange(conn: &Connection, mtu: u16) -> Result<(), MtuExchangeError> {
let conn_handle = conn.with_state(|state| state.check_connected())?;
diff --git a/nrf-softdevice/src/ble/gatt_server.rs b/nrf-softdevice/src/ble/gatt_server.rs
index 3634127..58663cc 100644
--- a/nrf-softdevice/src/ble/gatt_server.rs
+++ b/nrf-softdevice/src/ble/gatt_server.rs
@@ -7,7 +7,7 @@ use core::mem;
use crate::ble::*;
use crate::raw;
-use crate::util::{get_flexarray, get_union_field, BoundedLifetime, Portal};
+use crate::util::{get_flexarray, get_union_field, Portal};
use crate::RawError;
use crate::Softdevice;
@@ -151,8 +151,7 @@ where
return Some(Err(RunError::Disconnected))
}
raw::BLE_GATTS_EVTS_BLE_GATTS_EVT_WRITE => {
- let bounded = BoundedLifetime;
- let evt = bounded.deref(ble_evt);
+ let evt = &*ble_evt;
let gatts_evt = get_union_field(ble_evt, &evt.evt.gatts_evt);
let params = get_union_field(ble_evt, &gatts_evt.params.write);
let v = get_flexarray(ble_evt, &params.data, params.len as usize);
diff --git a/nrf-softdevice/src/events.rs b/nrf-softdevice/src/events.rs
index f00de57..f74f256 100644
--- a/nrf-softdevice/src/events.rs
+++ b/nrf-softdevice/src/events.rs
@@ -80,13 +80,13 @@ pub(crate) async fn run() {
}
}
-#[cfg(any(feature = "nrf52810", feature = "nrf52811"))]
+#[cfg(any(feature = "nrf52805", feature = "nrf52810", feature = "nrf52811"))]
#[interrupt]
unsafe fn SWI2() {
SWI2_SIGNAL.signal(());
}
-#[cfg(not(any(feature = "nrf52810", feature = "nrf52811")))]
+#[cfg(not(any(feature = "nrf52805", feature = "nrf52810", feature = "nrf52811")))]
#[interrupt]
unsafe fn SWI2_EGU2() {
SWI2_SIGNAL.signal(());
diff --git a/nrf-softdevice/src/lib.rs b/nrf-softdevice/src/lib.rs
index 44648fb..614cb1f 100644
--- a/nrf-softdevice/src/lib.rs
+++ b/nrf-softdevice/src/lib.rs
@@ -38,8 +38,10 @@ compile_error!("No softdevice feature activated. You must activate exactly one o
compile_error!("Multiple softdevice features activated. You must activate exactly one of the following features: s112, s113, s122, s132, s140");
#[cfg(not(any(
+ feature = "nrf52805",
feature = "nrf52810",
feature = "nrf52811",
+ feature = "nrf52820",
feature = "nrf52832",
feature = "nrf52833",
feature = "nrf52840",
@@ -47,13 +49,24 @@ compile_error!("Multiple softdevice features activated. You must activate exactl
compile_error!("No chip feature activated. You must activate exactly one of the following features: nrf52810, nrf52811, nrf52832, nrf52833, nrf52840");
#[cfg(any(
+ all(feature = "nrf52805", feature = "nrf52810"),
+ all(feature = "nrf52805", feature = "nrf52811"),
+ all(feature = "nrf52805", feature = "nrf52820"),
+ all(feature = "nrf52805", feature = "nrf52832"),
+ all(feature = "nrf52805", feature = "nrf52833"),
+ all(feature = "nrf52805", feature = "nrf52840"),
all(feature = "nrf52810", feature = "nrf52811"),
+ all(feature = "nrf52810", feature = "nrf52820"),
all(feature = "nrf52810", feature = "nrf52832"),
all(feature = "nrf52810", feature = "nrf52833"),
all(feature = "nrf52810", feature = "nrf52840"),
+ all(feature = "nrf52811", feature = "nrf52820"),
all(feature = "nrf52811", feature = "nrf52832"),
all(feature = "nrf52811", feature = "nrf52833"),
all(feature = "nrf52811", feature = "nrf52840"),
+ all(feature = "nrf52820", feature = "nrf52832"),
+ all(feature = "nrf52820", feature = "nrf52833"),
+ all(feature = "nrf52820", feature = "nrf52840"),
all(feature = "nrf52832", feature = "nrf52833"),
all(feature = "nrf52832", feature = "nrf52840"),
all(feature = "nrf52833", feature = "nrf52840"),
@@ -71,12 +84,18 @@ compile_error!("Multile chip features activated. You must activate exactly one o
// s140 | X X X | X X X X
#[cfg(not(any(
+ all(feature = "nrf52805", feature = "s112"),
+ all(feature = "nrf52805", feature = "s113"),
all(feature = "nrf52810", feature = "s112"),
all(feature = "nrf52810", feature = "s113"),
all(feature = "nrf52810", feature = "s132"),
all(feature = "nrf52811", feature = "s112"),
all(feature = "nrf52811", feature = "s113"),
all(feature = "nrf52811", feature = "s140"),
+ all(feature = "nrf52820", feature = "s112"),
+ all(feature = "nrf52820", feature = "s113"),
+ all(feature = "nrf52820", feature = "s122"),
+ all(feature = "nrf52820", feature = "s140"),
all(feature = "nrf52832", feature = "s112"),
all(feature = "nrf52832", feature = "s113"),
all(feature = "nrf52832", feature = "s132"),
@@ -106,10 +125,14 @@ compile_error!("The selected softdevice does not support ble-peripheral.");
))]
compile_error!("The selected softdevice does not support ble-l2cap.");
+#[cfg(feature = "nrf52805")]
+use nrf52805_pac as pac;
#[cfg(feature = "nrf52810")]
use nrf52810_pac as pac;
#[cfg(feature = "nrf52811")]
use nrf52811_pac as pac;
+#[cfg(feature = "nrf52820")]
+use nrf52820_pac as pac;
#[cfg(feature = "nrf52832")]
use nrf52832_pac as pac;
#[cfg(feature = "nrf52833")]
diff --git a/nrf-softdevice/src/softdevice.rs b/nrf-softdevice/src/softdevice.rs
index 981ec5f..a306554 100644
--- a/nrf-softdevice/src/softdevice.rs
+++ b/nrf-softdevice/src/softdevice.rs
@@ -37,6 +37,8 @@ unsafe extern "C" fn fault_handler(id: u32, pc: u32, info: u32) {
pub struct Softdevice {
// Prevent Send, Sync
_private: PhantomData<*mut ()>,
+ #[cfg(feature = "ble-gatt")]
+ #[allow(unused)]
pub(crate) att_mtu: u16,
#[cfg(feature = "ble-l2cap")]
pub(crate) l2cap_rx_mps: u16,
@@ -277,12 +279,13 @@ impl Softdevice {
}
unsafe {
- #[cfg(any(feature = "nrf52810", feature = "nrf52811"))]
+ #[cfg(any(feature = "nrf52805", feature = "nrf52810", feature = "nrf52811"))]
pac::NVIC::unmask(pac::interrupt::SWI2);
- #[cfg(not(any(feature = "nrf52810", feature = "nrf52811")))]
+ #[cfg(not(any(feature = "nrf52805", feature = "nrf52810", feature = "nrf52811")))]
pac::NVIC::unmask(pac::interrupt::SWI2_EGU2);
}
+ #[cfg(feature = "ble-gatt")]
let att_mtu = config
.conn_gatt
.map(|x| x.att_mtu)
@@ -296,7 +299,10 @@ impl Softdevice {
SOFTDEVICE.put(Softdevice {
_private: PhantomData,
+
+ #[cfg(feature = "ble-gatt")]
att_mtu,
+
#[cfg(feature = "ble-l2cap")]
l2cap_rx_mps,
})
diff --git a/nrf-softdevice/src/util/mod.rs b/nrf-softdevice/src/util/mod.rs
index b82c893..c341a1d 100644
--- a/nrf-softdevice/src/util/mod.rs
+++ b/nrf-softdevice/src/util/mod.rs
@@ -11,19 +11,12 @@ pub use on_drop::*;
use crate::raw;
-pub(crate) struct BoundedLifetime;
-
-impl BoundedLifetime {
- pub(crate) unsafe fn deref<T>(&self, ptr: *const T) -> &T {
- &*ptr
- }
-}
-
/// Create a slice from a variable-length array in a BLE event.
///
/// This function is a workaround for UB in __IncompleteArrayField
/// see https://github.com/rust-lang/rust-bindgen/issues/1892
/// see https://github.com/rust-lang/unsafe-code-guidelines/issues/134
+#[allow(unused)]
pub(crate) unsafe fn get_flexarray<T>(
orig_ptr: *const raw::ble_evt_t,
array: &raw::__IncompleteArrayField<T>,
diff --git a/nrf-softdevice/src/util/portal.rs b/nrf-softdevice/src/util/portal.rs
index 28c1d88..bc6becd 100644
--- a/nrf-softdevice/src/util/portal.rs
+++ b/nrf-softdevice/src/util/portal.rs
@@ -97,6 +97,7 @@ impl<T> Portal<T> {
}
}
+ #[allow(unused)]
pub fn wait_many<'a, R, F>(&'a self, mut func: F) -> impl Future<Output = R> + 'a
where
F: FnMut(T) -> Option<R> + 'a,