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>
This commit is contained in:
Damien George
2022-09-08 12:51:19 +10:00
parent 4f946ba963
commit 67f98ba10c
8 changed files with 44 additions and 28 deletions

View File

@@ -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");
}