nrf5/bluetooth: Moving callback definitions to bluetooth driver header. Refactoring bluetooth driver, setting new names on callback functions and updating api to use new callback function name prefix.

This commit is contained in:
Glenn Ruben Bakke 2017-03-14 08:13:32 +01:00
parent e028eda0bc
commit c066344a14
3 changed files with 21 additions and 21 deletions

View File

@ -74,9 +74,9 @@ if (ble_drv_stack_enabled() == 0) { \
static volatile bool m_adv_in_progress; static volatile bool m_adv_in_progress;
static volatile bool m_tx_in_progress; static volatile bool m_tx_in_progress;
static ubluepy_gap_evt_callback_t ubluepy_gap_event_handler; static ble_drv_gap_evt_callback_t gap_event_handler;
static ubluepy_adv_evt_callback_t ubluepy_adv_event_handler; static ble_drv_adv_evt_callback_t adv_event_handler;
static ubluepy_gatts_evt_callback_t ubluepy_gatts_event_handler; static ble_drv_gatts_evt_callback_t gatts_event_handler;
static mp_obj_t mp_gap_observer; static mp_obj_t mp_gap_observer;
static mp_obj_t mp_adv_observer; static mp_obj_t mp_adv_observer;
@ -653,19 +653,19 @@ void ble_drv_attr_notify(uint16_t conn_handle, uint16_t handle, uint16_t len, ui
} }
} }
void ble_drv_gap_event_handler_set(mp_obj_t obj, ubluepy_gap_evt_callback_t evt_handler) { void ble_drv_gap_event_handler_set(mp_obj_t obj, ble_drv_gap_evt_callback_t evt_handler) {
mp_gap_observer = obj; mp_gap_observer = obj;
ubluepy_gap_event_handler = evt_handler; gap_event_handler = evt_handler;
} }
void ble_drv_gatts_event_handler_set(mp_obj_t obj, ubluepy_gatts_evt_callback_t evt_handler) { void ble_drv_gatts_event_handler_set(mp_obj_t obj, ble_drv_gatts_evt_callback_t evt_handler) {
mp_gatts_observer = obj; mp_gatts_observer = obj;
ubluepy_gatts_event_handler = evt_handler; gatts_event_handler = evt_handler;
} }
void ble_drv_adv_report_handler_set(mp_obj_t obj, ubluepy_adv_evt_callback_t evt_handler) { void ble_drv_adv_report_handler_set(mp_obj_t obj, ble_drv_adv_evt_callback_t evt_handler) {
mp_adv_observer = obj; mp_adv_observer = obj;
ubluepy_adv_event_handler = evt_handler; adv_event_handler = evt_handler;
} }
#if (BLUETOOTH_SD == 130) || (BLUETOOTH_SD == 132) #if (BLUETOOTH_SD == 130) || (BLUETOOTH_SD == 132)
@ -710,7 +710,7 @@ static void ble_evt_handler(ble_evt_t * p_ble_evt) {
case BLE_GAP_EVT_CONNECTED: case BLE_GAP_EVT_CONNECTED:
BLE_DRIVER_LOG("GAP CONNECT\n"); BLE_DRIVER_LOG("GAP CONNECT\n");
m_adv_in_progress = false; m_adv_in_progress = false;
ubluepy_gap_event_handler(mp_gap_observer, p_ble_evt->header.evt_id, p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->header.evt_len - (2 * sizeof(uint16_t)), NULL); gap_event_handler(mp_gap_observer, p_ble_evt->header.evt_id, p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->header.evt_len - (2 * sizeof(uint16_t)), NULL);
ble_gap_conn_params_t conn_params; ble_gap_conn_params_t conn_params;
(void)sd_ble_gap_ppcp_get(&conn_params); (void)sd_ble_gap_ppcp_get(&conn_params);
@ -719,11 +719,11 @@ static void ble_evt_handler(ble_evt_t * p_ble_evt) {
case BLE_GAP_EVT_DISCONNECTED: case BLE_GAP_EVT_DISCONNECTED:
BLE_DRIVER_LOG("GAP DISCONNECT\n"); BLE_DRIVER_LOG("GAP DISCONNECT\n");
ubluepy_gap_event_handler(mp_gap_observer, p_ble_evt->header.evt_id, p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->header.evt_len - (2 * sizeof(uint16_t)), NULL); gap_event_handler(mp_gap_observer, p_ble_evt->header.evt_id, p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->header.evt_len - (2 * sizeof(uint16_t)), NULL);
break; break;
case BLE_GATTS_EVT_HVC: case BLE_GATTS_EVT_HVC:
ubluepy_gatts_event_handler(mp_gatts_observer, p_ble_evt->header.evt_id, p_ble_evt->evt.gatts_evt.params.hvc.handle, p_ble_evt->header.evt_len - (2 * sizeof(uint16_t)), NULL); gatts_event_handler(mp_gatts_observer, p_ble_evt->header.evt_id, p_ble_evt->evt.gatts_evt.params.hvc.handle, p_ble_evt->header.evt_len - (2 * sizeof(uint16_t)), NULL);
break; break;
case BLE_GATTS_EVT_WRITE: case BLE_GATTS_EVT_WRITE:
@ -733,7 +733,7 @@ static void ble_evt_handler(ble_evt_t * p_ble_evt) {
uint16_t data_len = p_ble_evt->evt.gatts_evt.params.write.len; uint16_t data_len = p_ble_evt->evt.gatts_evt.params.write.len;
uint8_t * p_data = &p_ble_evt->evt.gatts_evt.params.write.data[0]; uint8_t * p_data = &p_ble_evt->evt.gatts_evt.params.write.data[0];
ubluepy_gatts_event_handler(mp_gatts_observer, p_ble_evt->header.evt_id, handle, data_len, p_data); gatts_event_handler(mp_gatts_observer, p_ble_evt->header.evt_id, handle, data_len, p_data);
break; break;
case BLE_GAP_EVT_CONN_PARAM_UPDATE: case BLE_GAP_EVT_CONN_PARAM_UPDATE:
@ -777,7 +777,7 @@ static void ble_evt_handler(ble_evt_t * p_ble_evt) {
}; };
// TODO: Fix unsafe callback to possible undefined callback... // TODO: Fix unsafe callback to possible undefined callback...
ubluepy_adv_event_handler(mp_adv_observer, adv_event_handler(mp_adv_observer,
p_ble_evt->header.evt_id, p_ble_evt->header.evt_id,
&adv_data); &adv_data);
break; break;

View File

@ -40,6 +40,10 @@ typedef struct {
uint8_t * p_data; uint8_t * p_data;
} ble_drv_adv_data_t; } ble_drv_adv_data_t;
typedef void (*ble_drv_gap_evt_callback_t)(mp_obj_t self, uint16_t event_id, uint16_t conn_handle, uint16_t length, uint8_t * data);
typedef void (*ble_drv_gatts_evt_callback_t)(mp_obj_t self, uint16_t event_id, uint16_t attr_handle, uint16_t length, uint8_t * data);
typedef void (*ble_drv_adv_evt_callback_t)(mp_obj_t self, uint16_t event_id, ble_drv_adv_data_t * data);
uint32_t ble_drv_stack_enable(void); uint32_t ble_drv_stack_enable(void);
void ble_drv_stack_disable(void); void ble_drv_stack_disable(void);
@ -58,9 +62,9 @@ bool ble_drv_characteristic_add(ubluepy_characteristic_obj_t * p_char_obj);
bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params); bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params);
void ble_drv_gap_event_handler_set(mp_obj_t obs, ubluepy_gap_evt_callback_t evt_handler); void ble_drv_gap_event_handler_set(mp_obj_t obs, ble_drv_gap_evt_callback_t evt_handler);
void ble_drv_gatts_event_handler_set(mp_obj_t obj, ubluepy_gatts_evt_callback_t evt_handler); void ble_drv_gatts_event_handler_set(mp_obj_t obj, ble_drv_gatts_evt_callback_t evt_handler);
void ble_drv_attr_read(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data); void ble_drv_attr_read(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data);
@ -72,6 +76,6 @@ void ble_drv_scan_start(void);
void ble_drv_scan_stop(void); void ble_drv_scan_stop(void);
void ble_drv_adv_report_handler_set(mp_obj_t obj, ubluepy_adv_evt_callback_t evt_handler); void ble_drv_adv_report_handler_set(mp_obj_t obj, ble_drv_adv_evt_callback_t evt_handler);
#endif // BLUETOOTH_LE_DRIVER_H__ #endif // BLUETOOTH_LE_DRIVER_H__

View File

@ -169,8 +169,4 @@ typedef enum _ubluepy_attr_t {
UBLUEPY_ATTR_SCCD = 0x02, UBLUEPY_ATTR_SCCD = 0x02,
} ubluepy_attr_t; } ubluepy_attr_t;
typedef void (*ubluepy_gap_evt_callback_t)(mp_obj_t self, uint16_t event_id, uint16_t conn_handle, uint16_t length, uint8_t * data);
typedef void (*ubluepy_gatts_evt_callback_t)(mp_obj_t self, uint16_t event_id, uint16_t attr_handle, uint16_t length, uint8_t * data);
typedef void (*ubluepy_adv_evt_callback_t)(mp_obj_t self, uint16_t event_id, ble_drv_adv_data_t * data);
#endif // UBLUEPY_H__ #endif // UBLUEPY_H__