summaryrefslogtreecommitdiff
path: root/extmod/btstack/modbluetooth_btstack.c
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2022-09-08 12:51:19 +1000
committerDamien George <damien@micropython.org>2022-10-22 14:28:25 +1100
commit67f98ba10c3d894e737f275f0a508b7ccf4f1807 (patch)
treedbd68c43fc3f5ad4564bd3e6a3c19bc983a5d8d2 /extmod/btstack/modbluetooth_btstack.c
parent4f946ba963b452cb79524225e0a88134921f2ebb (diff)
extmod/btstack: Update BTstack bindings to work with latest BTstack.
The following multi-tests pass (eg with PYBD_SF6+LEGO_HUB_NO6): ble_gap_advertise.py ble_gap_connect.py ble_gap_device_name.py ble_gattc_discover_services.py ble_gatt_data_transfer.py perf_gatt_char_write.py perf_gatt_notify.py stress_log_filesystem.py These are the same tests that passed prior to this BTstack update. Also tested on the unix port using H4 transport. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'extmod/btstack/modbluetooth_btstack.c')
-rw-r--r--extmod/btstack/modbluetooth_btstack.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/extmod/btstack/modbluetooth_btstack.c b/extmod/btstack/modbluetooth_btstack.c
index b58be78a9..e9c003739 100644
--- a/extmod/btstack/modbluetooth_btstack.c
+++ b/extmod/btstack/modbluetooth_btstack.c
@@ -368,7 +368,7 @@ STATIC void btstack_packet_handler(uint8_t packet_type, uint8_t *packet, uint8_t
event_type == SM_EVENT_PAIRING_COMPLETE ||
// event_type == GAP_EVENT_DEDICATED_BONDING_COMPLETED || // No conn_handle
event_type == HCI_EVENT_ENCRYPTION_CHANGE) {
- DEBUG_printf(" --> enc/auth/pair/bond change\n", );
+ DEBUG_printf(" --> enc/auth/pair/bond change\n");
#if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
uint16_t conn_handle;
switch (event_type) {
@@ -420,6 +420,11 @@ STATIC void btstack_packet_handler(uint8_t packet_type, uint8_t *packet, uint8_t
mp_bluetooth_gap_on_scan_result(address_type, address, adv_event_type, rssi, data, length);
#endif // MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE
#if MICROPY_PY_BLUETOOTH_ENABLE_GATT_CLIENT
+ } else if (event_type == GATT_EVENT_MTU) {
+ // This is triggered in client mode.
+ uint16_t conn_handle = gatt_event_mtu_get_handle(packet);
+ uint16_t mtu = gatt_event_mtu_get_MTU(packet);
+ mp_bluetooth_gatts_on_mtu_exchanged(conn_handle, mtu);
} else if (event_type == GATT_EVENT_QUERY_COMPLETE) {
uint16_t conn_handle = gatt_event_query_complete_get_handle(packet);
uint16_t status = gatt_event_query_complete_get_att_status(packet);
@@ -625,6 +630,19 @@ STATIC void set_random_address(void) {
DEBUG_printf("set_random_address: Address loaded by controller\n");
}
+STATIC void deinit_stack(void) {
+ mp_bluetooth_btstack_state = MP_BLUETOOTH_BTSTACK_STATE_OFF;
+
+ // Deinitialise BTstack components.
+ sm_deinit();
+ l2cap_deinit();
+ hci_deinit();
+ btstack_memory_deinit();
+ btstack_run_loop_deinit();
+
+ MP_STATE_PORT(bluetooth_btstack_root_pointers) = NULL;
+}
+
int mp_bluetooth_init(void) {
DEBUG_printf("mp_bluetooth_init\n");
@@ -702,8 +720,8 @@ int mp_bluetooth_init(void) {
// Attempt a shutdown (may not do anything).
mp_bluetooth_btstack_port_deinit();
- // Clean up.
- MP_STATE_PORT(bluetooth_btstack_root_pointers) = NULL;
+ // Clean up BTstack.
+ deinit_stack();
return timeout ? MP_ETIMEDOUT : MP_EINVAL;
}
@@ -757,8 +775,8 @@ void mp_bluetooth_deinit(void) {
}
btstack_run_loop_remove_timer(&btstack_init_deinit_timeout);
- mp_bluetooth_btstack_state = MP_BLUETOOTH_BTSTACK_STATE_OFF;
- MP_STATE_PORT(bluetooth_btstack_root_pointers) = NULL;
+ // Clean up BTstack.
+ deinit_stack();
DEBUG_printf("mp_bluetooth_deinit: complete\n");
}