nrf: Remove the ble drv specific characteristic struct
This commit is contained in:
parent
98aa8c5923
commit
6545aa99a9
@ -54,34 +54,6 @@ STATIC void gattc_event_handler(bleio_device_obj_t *device, uint16_t event_id, u
|
|||||||
m_disc_evt_received = true;
|
m_disc_evt_received = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void disc_add_char(bleio_service_obj_t *service, ble_drv_char_data_t *chara_data) {
|
|
||||||
bleio_characteristic_obj_t *chara = m_new_obj(bleio_characteristic_obj_t);
|
|
||||||
chara->base.type = &bleio_characteristic_type;
|
|
||||||
|
|
||||||
bleio_uuid_obj_t * p_uuid = m_new_obj(bleio_uuid_obj_t);
|
|
||||||
p_uuid->base.type = &bleio_uuid_type;
|
|
||||||
|
|
||||||
chara->uuid = p_uuid;
|
|
||||||
|
|
||||||
p_uuid->type = chara_data->uuid_type;
|
|
||||||
p_uuid->value[0] = chara_data->uuid & 0xFF;
|
|
||||||
p_uuid->value[1] = chara_data->uuid >> 8;
|
|
||||||
|
|
||||||
// add characteristic specific data from discovery
|
|
||||||
chara->props.broadcast = chara_data->props.broadcast;
|
|
||||||
chara->props.indicate = chara_data->props.indicate;
|
|
||||||
chara->props.notify = chara_data->props.notify;
|
|
||||||
chara->props.read = chara_data->props.read;
|
|
||||||
chara->props.write = chara_data->props.write;
|
|
||||||
chara->props.write_wo_resp = chara_data->props.write_wo_resp;
|
|
||||||
chara->handle = chara_data->value_handle;
|
|
||||||
|
|
||||||
chara->service_handle = service->handle;
|
|
||||||
chara->service = service;
|
|
||||||
|
|
||||||
mp_obj_list_append(service->char_list, MP_OBJ_FROM_PTR(chara));
|
|
||||||
}
|
|
||||||
|
|
||||||
void common_hal_bleio_device_start_advertising(bleio_device_obj_t *device, bleio_advertisement_data_t *adv_data) {
|
void common_hal_bleio_device_start_advertising(bleio_device_obj_t *device, bleio_advertisement_data_t *adv_data) {
|
||||||
if (adv_data->connectable) {
|
if (adv_data->connectable) {
|
||||||
ble_drv_gap_event_handler_set(device, gap_event_handler);
|
ble_drv_gap_event_handler_set(device, gap_event_handler);
|
||||||
@ -126,7 +98,7 @@ void common_hal_bleio_device_connect(bleio_device_obj_t *device) {
|
|||||||
for (size_t i = 0; i < service_list->len; ++i) {
|
for (size_t i = 0; i < service_list->len; ++i) {
|
||||||
bleio_service_obj_t *service = service_list->items[i];
|
bleio_service_obj_t *service = service_list->items[i];
|
||||||
|
|
||||||
bool found_char = ble_drv_discover_characteristic(device, service, service->start_handle, disc_add_char);
|
bool found_char = ble_drv_discover_characteristic(device, service, service->start_handle);
|
||||||
while (found_char) {
|
while (found_char) {
|
||||||
const mp_obj_list_t *char_list = MP_OBJ_TO_PTR(service->char_list);
|
const mp_obj_list_t *char_list = MP_OBJ_TO_PTR(service->char_list);
|
||||||
const bleio_characteristic_obj_t *characteristic = char_list->items[char_list->len - 1];
|
const bleio_characteristic_obj_t *characteristic = char_list->items[char_list->len - 1];
|
||||||
@ -136,7 +108,7 @@ void common_hal_bleio_device_connect(bleio_device_obj_t *device) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
found_char = ble_drv_discover_characteristic(device, service, next_handle, disc_add_char);
|
found_char = ble_drv_discover_characteristic(device, service, next_handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#define NRF52 // Needed for SD132 v2
|
#define NRF52 // Needed for SD132 v2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "shared-bindings/bleio/Characteristic.h"
|
||||||
#include "shared-bindings/bleio/ScanEntry.h"
|
#include "shared-bindings/bleio/ScanEntry.h"
|
||||||
#include "shared-bindings/bleio/Service.h"
|
#include "shared-bindings/bleio/Service.h"
|
||||||
#include "shared-bindings/bleio/UUID.h"
|
#include "shared-bindings/bleio/UUID.h"
|
||||||
@ -91,7 +92,6 @@ static volatile bool m_write_done;
|
|||||||
|
|
||||||
static volatile ble_drv_adv_evt_callback_t adv_event_handler;
|
static volatile ble_drv_adv_evt_callback_t adv_event_handler;
|
||||||
static volatile ble_drv_gattc_evt_callback_t gattc_event_handler;
|
static volatile ble_drv_gattc_evt_callback_t gattc_event_handler;
|
||||||
static volatile ble_drv_disc_add_char_callback_t disc_add_char_handler;
|
|
||||||
static volatile ble_drv_gattc_char_data_callback_t gattc_char_data_handle;
|
static volatile ble_drv_gattc_char_data_callback_t gattc_char_data_handle;
|
||||||
|
|
||||||
static bleio_scanner_obj_t *mp_adv_observer;
|
static bleio_scanner_obj_t *mp_adv_observer;
|
||||||
@ -820,11 +820,10 @@ bool ble_drv_discover_services(bleio_device_obj_t *device, uint16_t start_handle
|
|||||||
return m_primary_service_found;
|
return m_primary_service_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ble_drv_discover_characteristic(bleio_device_obj_t *device, bleio_service_obj_t *service, uint16_t start_handle, ble_drv_disc_add_char_callback_t cb) {
|
bool ble_drv_discover_characteristic(bleio_device_obj_t *device, bleio_service_obj_t *service, uint16_t start_handle) {
|
||||||
BLE_DRIVER_LOG("Discover characteristicts. Conn handle: 0x" HEX2_FMT "\n", device->conn_handle);
|
BLE_DRIVER_LOG("Discover characteristicts. Conn handle: 0x" HEX2_FMT "\n", device->conn_handle);
|
||||||
|
|
||||||
mp_gattc_disc_char_observer = service;
|
mp_gattc_disc_char_observer = service;
|
||||||
disc_add_char_handler = cb;
|
|
||||||
|
|
||||||
ble_gattc_handle_range_t handle_range;
|
ble_gattc_handle_range_t handle_range;
|
||||||
handle_range.start_handle = start_handle;
|
handle_range.start_handle = start_handle;
|
||||||
@ -837,7 +836,7 @@ bool ble_drv_discover_characteristic(bleio_device_obj_t *device, bleio_service_o
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (disc_add_char_handler != NULL) {
|
while (mp_gattc_disc_char_observer != NULL) {
|
||||||
#ifdef MICROPY_VM_HOOK_LOOP
|
#ifdef MICROPY_VM_HOOK_LOOP
|
||||||
MICROPY_VM_HOOK_LOOP
|
MICROPY_VM_HOOK_LOOP
|
||||||
#endif
|
#endif
|
||||||
@ -902,6 +901,44 @@ STATIC void on_primary_srv_discovery_rsp(ble_gattc_evt_prim_srvc_disc_rsp_t *res
|
|||||||
mp_gattc_disc_service_observer = NULL;
|
mp_gattc_disc_service_observer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STATIC void on_characteristic_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response) {
|
||||||
|
BLE_DRIVER_LOG(">>> characteristic count: %d\n", response->count);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < response->count; ++i) {
|
||||||
|
const ble_gattc_char_t *gattc_char = &response->chars[i];
|
||||||
|
|
||||||
|
bleio_characteristic_obj_t *characteristic = m_new_obj(bleio_characteristic_obj_t);
|
||||||
|
characteristic->base.type = &bleio_characteristic_type;
|
||||||
|
|
||||||
|
bleio_uuid_obj_t *uuid = m_new_obj(bleio_uuid_obj_t);
|
||||||
|
uuid->base.type = &bleio_uuid_type;
|
||||||
|
uuid->type = (gattc_char->uuid.type == BLE_UUID_TYPE_BLE) ? UUID_TYPE_16BIT : UUID_TYPE_128BIT;
|
||||||
|
uuid->value[0] = gattc_char->uuid.uuid & 0xFF;
|
||||||
|
uuid->value[1] = gattc_char->uuid.uuid >> 8;
|
||||||
|
characteristic->uuid = uuid;
|
||||||
|
|
||||||
|
characteristic->props.broadcast = gattc_char->char_props.broadcast;
|
||||||
|
characteristic->props.indicate = gattc_char->char_props.indicate;
|
||||||
|
characteristic->props.notify = gattc_char->char_props.notify;
|
||||||
|
characteristic->props.read = gattc_char->char_props.read;
|
||||||
|
characteristic->props.write = gattc_char->char_props.write;
|
||||||
|
characteristic->props.write_wo_resp = gattc_char->char_props.write_wo_resp;
|
||||||
|
characteristic->handle = gattc_char->handle_value;
|
||||||
|
|
||||||
|
characteristic->service_handle = mp_gattc_disc_char_observer->handle;
|
||||||
|
characteristic->service = mp_gattc_disc_char_observer;
|
||||||
|
|
||||||
|
mp_obj_list_append(mp_gattc_disc_char_observer->char_list, MP_OBJ_FROM_PTR(characteristic));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response->count > 0) {
|
||||||
|
m_characteristic_found = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// mark end of characteristic discovery
|
||||||
|
mp_gattc_disc_char_observer = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
STATIC void ble_evt_handler(ble_evt_t *p_ble_evt) {
|
STATIC void ble_evt_handler(ble_evt_t *p_ble_evt) {
|
||||||
printf("%s - 0x%02X\r\n", __func__, p_ble_evt->header.evt_id);
|
printf("%s - 0x%02X\r\n", __func__, p_ble_evt->header.evt_id);
|
||||||
|
|
||||||
@ -984,35 +1021,7 @@ STATIC void ble_evt_handler(ble_evt_t *p_ble_evt) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case BLE_GATTC_EVT_CHAR_DISC_RSP:
|
case BLE_GATTC_EVT_CHAR_DISC_RSP:
|
||||||
BLE_DRIVER_LOG("BLE EVT CHAR DISCOVERY RESPONSE\n");
|
on_characteristic_discovery_rsp(&p_ble_evt->evt.gattc_evt.params.char_disc_rsp);
|
||||||
BLE_DRIVER_LOG(">>> characteristic count: %d\n", p_ble_evt->evt.gattc_evt.params.char_disc_rsp.count);
|
|
||||||
|
|
||||||
for (uint16_t i = 0; i < p_ble_evt->evt.gattc_evt.params.char_disc_rsp.count; i++) {
|
|
||||||
ble_gattc_char_t * p_char = &p_ble_evt->evt.gattc_evt.params.char_disc_rsp.chars[i];
|
|
||||||
|
|
||||||
ble_drv_char_data_t char_data;
|
|
||||||
char_data.uuid_type = p_char->uuid.type;
|
|
||||||
char_data.uuid = p_char->uuid.uuid;
|
|
||||||
char_data.decl_handle = p_char->handle_decl;
|
|
||||||
char_data.value_handle = p_char->handle_value;
|
|
||||||
|
|
||||||
char_data.props.broadcast = p_char->char_props.broadcast;
|
|
||||||
char_data.props.read = p_char->char_props.read;
|
|
||||||
char_data.props.write_wo_resp = p_char->char_props.write_wo_resp;
|
|
||||||
char_data.props.write = p_char->char_props.write;
|
|
||||||
char_data.props.notify = p_char->char_props.notify;
|
|
||||||
char_data.props.indicate = p_char->char_props.indicate;
|
|
||||||
|
|
||||||
disc_add_char_handler(mp_gattc_disc_char_observer, &char_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p_ble_evt->evt.gattc_evt.params.char_disc_rsp.count > 0) {
|
|
||||||
m_characteristic_found = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// mark end of characteristic discovery
|
|
||||||
disc_add_char_handler = NULL;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BLE_GATTC_EVT_READ_RSP:
|
case BLE_GATTC_EVT_READ_RSP:
|
||||||
|
@ -39,26 +39,10 @@
|
|||||||
#include "shared-module/bleio/Scanner.h"
|
#include "shared-module/bleio/Scanner.h"
|
||||||
#include "shared-module/bleio/Service.h"
|
#include "shared-module/bleio/Service.h"
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint16_t uuid;
|
|
||||||
uint8_t uuid_type;
|
|
||||||
struct {
|
|
||||||
bool broadcast : 1;
|
|
||||||
bool read : 1;
|
|
||||||
bool write_wo_resp : 1;
|
|
||||||
bool write : 1;
|
|
||||||
bool notify : 1;
|
|
||||||
bool indicate : 1;
|
|
||||||
} props;
|
|
||||||
uint16_t decl_handle;
|
|
||||||
uint16_t value_handle;
|
|
||||||
} ble_drv_char_data_t;
|
|
||||||
|
|
||||||
typedef void (*ble_drv_gap_evt_callback_t)(bleio_device_obj_t *device, uint16_t event_id, uint16_t conn_handle, uint16_t length, uint8_t * data);
|
typedef void (*ble_drv_gap_evt_callback_t)(bleio_device_obj_t *device, uint16_t event_id, uint16_t conn_handle, uint16_t length, uint8_t * data);
|
||||||
typedef void (*ble_drv_gatts_evt_callback_t)(bleio_device_obj_t *device, uint16_t event_id, uint16_t attr_handle, uint16_t length, uint8_t * data);
|
typedef void (*ble_drv_gatts_evt_callback_t)(bleio_device_obj_t *device, uint16_t event_id, uint16_t attr_handle, uint16_t length, uint8_t * data);
|
||||||
typedef void (*ble_drv_gattc_evt_callback_t)(bleio_device_obj_t *device, uint16_t event_id, uint16_t attr_handle, uint16_t length, uint8_t * data);
|
typedef void (*ble_drv_gattc_evt_callback_t)(bleio_device_obj_t *device, uint16_t event_id, uint16_t attr_handle, uint16_t length, uint8_t * data);
|
||||||
typedef void (*ble_drv_adv_evt_callback_t)(bleio_scanner_obj_t *scanner, bleio_scanentry_obj_t *entry);
|
typedef void (*ble_drv_adv_evt_callback_t)(bleio_scanner_obj_t *scanner, bleio_scanentry_obj_t *entry);
|
||||||
typedef void (*ble_drv_disc_add_char_callback_t)(bleio_service_obj_t *service, ble_drv_char_data_t * p_desc_data);
|
|
||||||
typedef void (*ble_drv_gattc_char_data_callback_t)(bleio_characteristic_obj_t *self, uint16_t length, uint8_t * p_data);
|
typedef void (*ble_drv_gattc_char_data_callback_t)(bleio_characteristic_obj_t *self, uint16_t length, uint8_t * p_data);
|
||||||
|
|
||||||
uint32_t ble_drv_stack_enable(void);
|
uint32_t ble_drv_stack_enable(void);
|
||||||
@ -109,7 +93,7 @@ void ble_drv_disconnect(bleio_device_obj_t *device);
|
|||||||
|
|
||||||
bool ble_drv_discover_services(bleio_device_obj_t *device, uint16_t start_handle);
|
bool ble_drv_discover_services(bleio_device_obj_t *device, uint16_t start_handle);
|
||||||
|
|
||||||
bool ble_drv_discover_characteristic(bleio_device_obj_t *device, bleio_service_obj_t *service, uint16_t start_handle, ble_drv_disc_add_char_callback_t cb);
|
bool ble_drv_discover_characteristic(bleio_device_obj_t *device, bleio_service_obj_t *service, uint16_t start_handle);
|
||||||
|
|
||||||
void ble_drv_discover_descriptors(void);
|
void ble_drv_discover_descriptors(void);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user