Skip to content

Commit

Permalink
Nimble/blufi: Added an API to stop Bluetooth / Blufi
Browse files Browse the repository at this point in the history
  • Loading branch information
RoshanESP committed Oct 31, 2022
1 parent 20949d4 commit ab2dee9
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -466,4 +466,8 @@ void esp_blufi_btc_init(void)
assert(rc == 0);
}

void esp_blufi_btc_deinit(void)
{
btc_deinit();
}
#endif
3 changes: 2 additions & 1 deletion examples/bluetooth/blufi/main/blufi_example.h
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -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);
50 changes: 50 additions & 0 deletions examples/bluetooth/blufi/main/blufi_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ab2dee9

Please sign in to comment.