nrf5/bluetooth: Updating bluetooth driver to support GATT client read of a characteristic value. Data passed to caller in interrupt context, and copy has to be performed. The function call is itself blocking.
This commit is contained in:
parent
bb7130a813
commit
c88358d84b
@ -80,6 +80,7 @@ static ble_drv_gatts_evt_callback_t gatts_event_handler;
|
||||
static ble_drv_gattc_evt_callback_t gattc_event_handler;
|
||||
static ble_drv_disc_add_service_callback_t disc_add_service_handler;
|
||||
static ble_drv_disc_add_char_callback_t disc_add_char_handler;
|
||||
static ble_drv_gattc_char_data_callback_t gattc_char_data_handle;
|
||||
|
||||
static mp_obj_t mp_gap_observer;
|
||||
static mp_obj_t mp_adv_observer;
|
||||
@ -87,6 +88,7 @@ static mp_obj_t mp_gatts_observer;
|
||||
static mp_obj_t mp_gattc_observer;
|
||||
static mp_obj_t mp_gattc_disc_service_observer;
|
||||
static mp_obj_t mp_gattc_disc_char_observer;
|
||||
static mp_obj_t mp_gattc_char_data_observer;
|
||||
|
||||
#if (BLUETOOTH_SD != 100) && (BLUETOOTH_SD != 110)
|
||||
#include "nrf_nvic.h"
|
||||
@ -619,7 +621,11 @@ void ble_drv_attr_s_read(uint16_t conn_handle, uint16_t handle, uint16_t len, ui
|
||||
|
||||
}
|
||||
|
||||
void ble_drv_attr_c_read(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data) {
|
||||
void ble_drv_attr_c_read(uint16_t conn_handle, uint16_t handle, mp_obj_t obj, ble_drv_gattc_char_data_callback_t cb) {
|
||||
|
||||
mp_gattc_char_data_observer = obj;
|
||||
gattc_char_data_handle = cb;
|
||||
|
||||
uint32_t err_code = sd_ble_gattc_read(conn_handle,
|
||||
handle,
|
||||
0);
|
||||
@ -627,6 +633,10 @@ void ble_drv_attr_c_read(uint16_t conn_handle, uint16_t handle, uint16_t len, ui
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
|
||||
"Can not read attribute value. status: 0x" HEX2_FMT, (uint16_t)err_code));
|
||||
}
|
||||
|
||||
while (gattc_char_data_handle != NULL) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void ble_drv_attr_write(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data) {
|
||||
@ -963,7 +973,17 @@ static void ble_evt_handler(ble_evt_t * p_ble_evt) {
|
||||
break;
|
||||
|
||||
case BLE_GATTC_EVT_READ_RSP:
|
||||
BLE_DRIVER_LOG("BLE EVT READ RESPONSE\n");
|
||||
BLE_DRIVER_LOG("BLE EVT READ RESPONSE, offset: 0x"HEX2_FMT", length: 0x"HEX2_FMT"\n",
|
||||
p_ble_evt->evt.gattc_evt.params.read_rsp.offset,
|
||||
p_ble_evt->evt.gattc_evt.params.read_rsp.len);
|
||||
|
||||
gattc_char_data_handle(mp_gattc_char_data_observer,
|
||||
p_ble_evt->evt.gattc_evt.params.read_rsp.len,
|
||||
p_ble_evt->evt.gattc_evt.params.read_rsp.data);
|
||||
|
||||
// mark end of read
|
||||
gattc_char_data_handle = NULL;
|
||||
|
||||
break;
|
||||
|
||||
case BLE_GATTC_EVT_WRITE_RSP:
|
||||
|
@ -63,7 +63,7 @@ typedef void (*ble_drv_gattc_evt_callback_t)(mp_obj_t self, uint16_t event_id, u
|
||||
typedef void (*ble_drv_adv_evt_callback_t)(mp_obj_t self, uint16_t event_id, ble_drv_adv_data_t * data);
|
||||
typedef void (*ble_drv_disc_add_service_callback_t)(mp_obj_t self, ble_drv_service_data_t * p_service_data);
|
||||
typedef void (*ble_drv_disc_add_char_callback_t)(mp_obj_t self, ble_drv_char_data_t * p_desc_data);
|
||||
|
||||
typedef void (*ble_drv_gattc_char_data_callback_t)(mp_obj_t self, uint16_t length, uint8_t * p_data);
|
||||
|
||||
uint32_t ble_drv_stack_enable(void);
|
||||
|
||||
@ -91,7 +91,7 @@ void ble_drv_gattc_event_handler_set(mp_obj_t obj, ble_drv_gattc_evt_callback_t
|
||||
|
||||
void ble_drv_attr_s_read(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data);
|
||||
|
||||
void ble_drv_attr_c_read(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data);
|
||||
void ble_drv_attr_c_read(uint16_t conn_handle, uint16_t handle, mp_obj_t obj, ble_drv_gattc_char_data_callback_t cb);
|
||||
|
||||
void ble_drv_attr_write(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user