diff options
author | Andrew Leech <andrew.leech@planetinnovation.com.au> | 2025-05-07 09:11:25 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2025-06-04 02:21:32 +1000 |
commit | d5f2fc239af2d69407170fa290ba6752c8f1790c (patch) | |
tree | f765b059b0887de6e8f7f0f10bb5541c47bd5b95 /extmod/btstack/modbluetooth_btstack.c | |
parent | 17898f8607dc4fb881e860719cc1906d304e60f4 (diff) | |
download | micropython-d5f2fc239af2d69407170fa290ba6752c8f1790c.tar.gz micropython-d5f2fc239af2d69407170fa290ba6752c8f1790c.zip |
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>
Diffstat (limited to 'extmod/btstack/modbluetooth_btstack.c')
-rw-r--r-- | extmod/btstack/modbluetooth_btstack.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/extmod/btstack/modbluetooth_btstack.c b/extmod/btstack/modbluetooth_btstack.c index b29970842c..7694a1874f 100644 --- a/extmod/btstack/modbluetooth_btstack.c +++ b/extmod/btstack/modbluetooth_btstack.c @@ -705,12 +705,12 @@ int mp_bluetooth_init(void) { return 0; } -void mp_bluetooth_deinit(void) { +int mp_bluetooth_deinit(void) { DEBUG_printf("mp_bluetooth_deinit\n"); // Nothing to do if not initialised. if (!MP_STATE_PORT(bluetooth_btstack_root_pointers)) { - return; + return 0; } mp_bluetooth_gap_advertise_stop(); @@ -737,6 +737,9 @@ void mp_bluetooth_deinit(void) { deinit_stack(); DEBUG_printf("mp_bluetooth_deinit: complete\n"); + + bool timeout = mp_bluetooth_btstack_state == MP_BLUETOOTH_BTSTACK_STATE_TIMEOUT; + return timeout ? MP_ETIMEDOUT : 0; } bool mp_bluetooth_is_active(void) { |