@@ -5,6 +5,16 @@ package bluetooth
55/*
66#include "ble_gap.h"
77#include "ble_gatts.h"
8+
9+ // Workaround wrapper functions which prevent pointer arguments escaping to heap
10+ static inline uint32_t sd_ble_gatts_hvx_noescape(uint16_t conn_handle, uint16_t handle, uint8_t type, uint16_t offset, uint16_t len, uint8_t *p_data) {
11+ ble_gatts_hvx_params_t p_hvx_params = {handle, type, offset, &len, p_data};
12+ return sd_ble_gatts_hvx(conn_handle, &p_hvx_params);
13+ }
14+
15+ static inline uint32_t sd_ble_gatts_value_set_noescape(uint16_t conn_handle, uint16_t handle, ble_gatts_value_t p_value) {
16+ return sd_ble_gatts_value_set(conn_handle, handle, &p_value);
17+ }
818*/
919import "C"
1020
@@ -110,12 +120,13 @@ func (c *Characteristic) Write(p []byte) (n int, err error) {
110120 if connHandle != C .BLE_CONN_HANDLE_INVALID {
111121 // There is a connected central.
112122 p_len := uint16 (len (p ))
113- errCode := C .sd_ble_gatts_hvx (connHandle , & C.ble_gatts_hvx_params_t {
114- handle : c .handle ,
115- _type : C .BLE_GATT_HVX_NOTIFICATION ,
116- p_len : & p_len ,
117- p_data : & p [0 ],
118- })
123+ errCode := C .sd_ble_gatts_hvx_noescape (connHandle ,
124+ c .handle ,
125+ C .BLE_GATT_HVX_NOTIFICATION ,
126+ 0 ,
127+ p_len ,
128+ & p [0 ],
129+ )
119130
120131 // Check for some expected errors. Don't report them as errors, but
121132 // instead fall through and do a normal characteristic value update.
@@ -133,7 +144,7 @@ func (c *Characteristic) Write(p []byte) (n int, err error) {
133144 }
134145 }
135146
136- errCode := C .sd_ble_gatts_value_set (C .BLE_CONN_HANDLE_INVALID , c .handle , & C.ble_gatts_value_t {
147+ errCode := C .sd_ble_gatts_value_set_noescape (C .BLE_CONN_HANDLE_INVALID , c .handle , C.ble_gatts_value_t {
137148 len : uint16 (len (p )),
138149 p_value : & p [0 ],
139150 })
0 commit comments