extmod/modbluetooth: Add timeout to deinit.

If the BLE radio stops responding before deinit is called the function can
get stuck waiting for an event that is never received, particularly if the
radio is external or on a separate core.

This commit adds a timeout, similar to the timeout already used in the init
function.  Updated for nimble, btstack, esp32 and zephyr bindings.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
This commit is contained in:
Andrew Leech
2025-05-07 09:11:25 +10:00
committed by Damien George
parent 17898f8607
commit d5f2fc239a
8 changed files with 34 additions and 16 deletions

View File

@@ -290,12 +290,13 @@ static mp_obj_t bluetooth_ble_make_new(const mp_obj_type_t *type, size_t n_args,
static mp_obj_t bluetooth_ble_active(size_t n_args, const mp_obj_t *args) {
if (n_args == 2) {
// Boolean enable/disable argument supplied, set current state.
int err;
if (mp_obj_is_true(args[1])) {
int err = mp_bluetooth_init();
bluetooth_handle_errno(err);
err = mp_bluetooth_init();
} else {
mp_bluetooth_deinit();
err = mp_bluetooth_deinit();
}
bluetooth_handle_errno(err);
}
// Return current state.
return mp_obj_new_bool(mp_bluetooth_is_active());