Skip to content

Commit

Permalink
Merge branch 'bugfix/fix_blufi_deinit_v5.1' into 'release/v5.1'
Browse files Browse the repository at this point in the history
Blufi : Corrected blufi host deinit API (v5.1)

See merge request espressif/esp-idf!29000
  • Loading branch information
rahult-github committed Feb 28, 2024
2 parents 48777e7 + 52d36be commit 2b07dbf
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 19 deletions.
2 changes: 2 additions & 0 deletions examples/bluetooth/blufi/main/blufi_example.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ 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);
esp_err_t esp_blufi_controller_init(void);
esp_err_t esp_blufi_controller_deinit(void);
12 changes: 2 additions & 10 deletions examples/bluetooth/blufi/main/blufi_example_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,17 +463,9 @@ void app_main(void)

initialise_wifi();

ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));

esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
ret = esp_bt_controller_init(&bt_cfg);
if (ret) {
BLUFI_ERROR("%s initialize bt controller failed: %s\n", __func__, esp_err_to_name(ret));
}

ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
ret = esp_blufi_controller_init();
if (ret) {
BLUFI_ERROR("%s enable bt controller failed: %s\n", __func__, esp_err_to_name(ret));
BLUFI_ERROR("%s BLUFI controller init failed: %s\n", __func__, esp_err_to_name(ret));
return;
}

Expand Down
49 changes: 40 additions & 9 deletions examples/bluetooth/blufi/main/blufi_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include "esp_log.h"
#include "esp_blufi.h"
#include "blufi_example.h"
#ifdef CONFIG_BT_BLUEDROID_ENABLED
#include "esp_bt.h"
#ifdef CONFIG_BT_BLUEDROID_ENABLED
#include "esp_bt_main.h"
#include "esp_bt_device.h"
#endif
Expand Down Expand Up @@ -67,13 +67,6 @@ esp_err_t esp_blufi_host_deinit(void)
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;

}
Expand Down Expand Up @@ -116,6 +109,44 @@ esp_err_t esp_blufi_host_and_cb_init(esp_blufi_callbacks_t *example_callbacks)

#endif /* CONFIG_BT_BLUEDROID_ENABLED */

esp_err_t esp_blufi_controller_init() {
esp_err_t ret = ESP_OK;
#if CONFIG_IDF_TARGET_ESP32
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
#endif

esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
ret = esp_bt_controller_init(&bt_cfg);
if (ret) {
BLUFI_ERROR("%s initialize bt controller failed: %s\n", __func__, esp_err_to_name(ret));
return ret;
}

ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
if (ret) {
BLUFI_ERROR("%s enable bt controller failed: %s\n", __func__, esp_err_to_name(ret));
return ret;
}
return ret;
}

esp_err_t esp_blufi_controller_deinit() {
esp_err_t ret = ESP_OK;
ret = esp_bt_controller_disable();
if (ret) {
BLUFI_ERROR("%s disable bt controller failed: %s\n", __func__, esp_err_to_name(ret));
return ret;
}

ret = esp_bt_controller_deinit();
if (ret) {
BLUFI_ERROR("%s deinit bt controller failed: %s\n", __func__, esp_err_to_name(ret));
return ret;
}

return ret;
}

#ifdef CONFIG_BT_NIMBLE_ENABLED
void ble_store_config_init(void);
static void blufi_on_reset(int reason)
Expand Down Expand Up @@ -205,7 +236,7 @@ esp_err_t esp_blufi_host_deinit(void)

ret = nimble_port_stop();
if (ret == 0) {
nimble_port_deinit();
esp_nimble_deinit();
}

return ret;
Expand Down

0 comments on commit 2b07dbf

Please sign in to comment.