diff --git a/components/bt/bt.c b/components/bt/bt.c index 0a6be36ff3..73931bafab 100644 --- a/components/bt/bt.c +++ b/components/bt/bt.c @@ -1501,6 +1501,21 @@ esp_err_t esp_bt_controller_deinit(void) return ESP_OK; } + +static void bt_shutdown(void) +{ + esp_err_t ret = ESP_OK; + ESP_LOGD(BTDM_LOG_TAG, "stop Bluetooth"); + + ret = esp_bt_controller_disable(); + if (ESP_OK != ret) { + ESP_LOGW(BTDM_LOG_TAG, "controller disable ret=%d", ret); + } + ret = esp_bt_controller_deinit(); + return; +} + + esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) { int ret; @@ -1560,6 +1575,10 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) } btdm_controller_status = ESP_BT_CONTROLLER_STATUS_ENABLED; + ret = esp_register_shutdown_handler(bt_shutdown); + if (ret != ESP_OK) { + ESP_LOGW(BTDM_LOG_TAG, "Register shutdown handler failed, ret = 0x%x", ret); + } return ESP_OK; } diff --git a/components/esp32/system_api.c b/components/esp32/system_api.c index 7616b4b00c..4de32887e2 100644 --- a/components/esp32/system_api.c +++ b/components/esp32/system_api.c @@ -44,7 +44,7 @@ static const char* TAG = "system_api"; static uint8_t base_mac_addr[6] = { 0 }; -#define SHUTDOWN_HANDLERS_NO 2 +#define SHUTDOWN_HANDLERS_NO 3 static shutdown_handler_t shutdown_handlers[SHUTDOWN_HANDLERS_NO]; void system_init()