diff --git a/components/bt/controller/bt.c b/components/bt/controller/bt.c index 36c278e939..271182f068 100644 --- a/components/bt/controller/bt.c +++ b/components/bt/controller/bt.c @@ -1387,6 +1387,19 @@ 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); + } + return; +} + + esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) { int ret; @@ -1450,6 +1463,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; } @@ -1480,6 +1497,7 @@ esp_err_t esp_bt_controller_disable(void) } esp_phy_rf_deinit(PHY_BT_MODULE); btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED; + esp_unregister_shutdown_handler(bt_shutdown); #ifdef CONFIG_PM_ENABLE if (!s_btdm_allow_light_sleep) { diff --git a/components/esp32/system_api.c b/components/esp32/system_api.c index 633aeb47e9..e7a6916a61 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]; esp_err_t esp_base_mac_addr_set(uint8_t *mac)