diff --git a/src/lib.rs b/src/lib.rs index 83fc07e..1807bbe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ #![allow(clippy::single_match)] #![allow(static_mut_refs)] #![feature(decl_macro)] +#![feature(get_mut_unchecked)] #![doc = include_str!("../README.md")] extern crate alloc; diff --git a/src/server/ble_characteristic.rs b/src/server/ble_characteristic.rs index e3e3d28..823671a 100644 --- a/src/server/ble_characteristic.rs +++ b/src/server/ble_characteristic.rs @@ -12,7 +12,7 @@ use crate::cpfd::Cpfd; use crate::{ utilities::{ - as_mut_ptr, ble_npl_hw_enter_critical, ble_npl_hw_exit_critical, mutex::Mutex, os_mbuf_append, + ble_npl_hw_enter_critical, ble_npl_hw_exit_critical, mutex::Mutex, os_mbuf_append, voidp_to_ref, BleUuid, }, AttValue, BLEConnDesc, BLEDescriptor, BLEDevice, DescriptorProperties, OnWriteArgs, BLE2904, @@ -206,8 +206,8 @@ impl BLECharacteristic { } self.svc_def_descriptors.clear(); - for dsc in &self.descriptors { - let arg = unsafe { as_mut_ptr(Arc::into_raw(dsc.clone())) }; + for dsc in &mut self.descriptors { + let arg = unsafe { Arc::get_mut_unchecked(dsc) } as *mut Mutex; let dsc = dsc.lock(); self .svc_def_descriptors diff --git a/src/server/ble_service.rs b/src/server/ble_service.rs index a2fdc88..e8dc479 100644 --- a/src/server/ble_service.rs +++ b/src/server/ble_service.rs @@ -3,7 +3,7 @@ use esp_idf_sys::ble_uuid_any_t; use crate::{ ble, - utilities::{as_mut_ptr, mutex::Mutex, BleUuid}, + utilities::{mutex::Mutex, BleUuid}, BLECharacteristic, BLEError, }; @@ -43,10 +43,9 @@ impl BLEService { if self.characteristics.is_empty() { } else { - for chr in &self.characteristics { - let arg = unsafe { as_mut_ptr(Arc::into_raw(chr.clone())) }; + for chr in &mut self.characteristics { + let arg = unsafe { Arc::get_mut_unchecked(chr) } as *mut Mutex; let mut chr = chr.lock(); - self .svc_def_characteristics .push(esp_idf_sys::ble_gatt_chr_def {