diff --git a/components/bt/common/btc/profile/esp/blufi/include/esp_blufi.h b/components/bt/common/btc/profile/esp/blufi/include/esp_blufi.h index 9f17758661ff..ee9069059cdc 100644 --- a/components/bt/common/btc/profile/esp/blufi/include/esp_blufi.h +++ b/components/bt/common/btc/profile/esp/blufi/include/esp_blufi.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -40,6 +40,7 @@ void esp_blufi_gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *a /* Initialise gatt server */ int esp_blufi_gatt_svr_init(void); void esp_blufi_btc_init(void); +void esp_blufi_btc_deinit(void); #endif #ifdef CONFIG_BT_BLUEDROID_ENABLED diff --git a/components/bt/common/btc/profile/esp/blufi/nimble_host/esp_blufi.c b/components/bt/common/btc/profile/esp/blufi/nimble_host/esp_blufi.c index 7e4ea095ff42..d86bb607f089 100644 --- a/components/bt/common/btc/profile/esp/blufi/nimble_host/esp_blufi.c +++ b/components/bt/common/btc/profile/esp/blufi/nimble_host/esp_blufi.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -466,4 +466,8 @@ void esp_blufi_btc_init(void) assert(rc == 0); } +void esp_blufi_btc_deinit(void) +{ + btc_deinit(); +} #endif diff --git a/examples/bluetooth/blufi/main/blufi_example.h b/examples/bluetooth/blufi/main/blufi_example.h index 207543fdc51a..595f293beb95 100644 --- a/examples/bluetooth/blufi/main/blufi_example.h +++ b/examples/bluetooth/blufi/main/blufi_example.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -21,3 +21,4 @@ void blufi_security_deinit(void); int esp_blufi_gap_register_callback(void); esp_err_t esp_blufi_host_init(void); esp_err_t esp_blufi_host_and_cb_init(esp_blufi_callbacks_t *callbacks); +esp_err_t esp_blufi_host_deinit(void); diff --git a/examples/bluetooth/blufi/main/blufi_init.c b/examples/bluetooth/blufi/main/blufi_init.c index 46b3af3d85db..da10642608a8 100644 --- a/examples/bluetooth/blufi/main/blufi_init.c +++ b/examples/bluetooth/blufi/main/blufi_init.c @@ -47,6 +47,37 @@ esp_err_t esp_blufi_host_init(void) } +esp_err_t esp_blufi_host_deinit(void) +{ + int ret; + ret = esp_blufi_profile_deinit(); + if(ret != ESP_OK) { + return ret; + } + + ret = esp_bluedroid_disable(); + if (ret) { + BLUFI_ERROR("%s deinit bluedroid failed: %s\n", __func__, esp_err_to_name(ret)); + return ESP_FAIL; + } + + ret = esp_bluedroid_deinit(); + if (ret) { + BLUFI_ERROR("%s deinit bluedroid failed: %s\n", __func__, esp_err_to_name(ret)); + return ESP_FAIL; + } + + ESP_ERROR_CHECK(esp_bt_controller_disable()); + ret = esp_bt_controller_deinit(); + if (ret) { + BLUFI_ERROR("%s deinit bluedroid failed: %s\n", __func__, esp_err_to_name(ret)); + return ESP_FAIL; + } + + return ESP_OK; + +} + esp_err_t esp_blufi_gap_register_callback(void) { int rc; @@ -161,6 +192,25 @@ esp_err_t esp_blufi_host_init(void) return ESP_OK; } +esp_err_t esp_blufi_host_deinit(void) +{ + esp_err_t ret = ESP_OK; + + ret = esp_blufi_profile_deinit(); + if(ret != ESP_OK) { + return ret; + } + + esp_blufi_btc_deinit(); + + ret = nimble_port_stop(); + if (ret == 0) { + nimble_port_deinit(); + } + + return ret; +} + esp_err_t esp_blufi_gap_register_callback(void) { return ESP_OK;