Merge branch 'bugfix/fix_blufi_deinit' into 'master'

Blufi : Corrected blufi host deinit API

See merge request espressif/esp-idf!23826
This commit is contained in:
Roshan Bangar 2023-06-01 14:30:01 +08:00
commit c797e05f25
3 changed files with 44 additions and 19 deletions

View File

@ -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_init(void);
esp_err_t esp_blufi_host_and_cb_init(esp_blufi_callbacks_t *callbacks); 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_host_deinit(void);
esp_err_t esp_blufi_controller_init(void);
esp_err_t esp_blufi_controller_deinit(void);

View File

@ -463,17 +463,9 @@ void app_main(void)
initialise_wifi(); initialise_wifi();
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT)); ret = esp_blufi_controller_init();
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
ret = esp_bt_controller_init(&bt_cfg);
if (ret) { if (ret) {
BLUFI_ERROR("%s initialize 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));
}
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; return;
} }

View File

@ -10,8 +10,8 @@
#include "esp_log.h" #include "esp_log.h"
#include "esp_blufi.h" #include "esp_blufi.h"
#include "blufi_example.h" #include "blufi_example.h"
#ifdef CONFIG_BT_BLUEDROID_ENABLED
#include "esp_bt.h" #include "esp_bt.h"
#ifdef CONFIG_BT_BLUEDROID_ENABLED
#include "esp_bt_main.h" #include "esp_bt_main.h"
#include "esp_bt_device.h" #include "esp_bt_device.h"
#endif #endif
@ -67,13 +67,6 @@ esp_err_t esp_blufi_host_deinit(void)
return ESP_FAIL; 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; return ESP_OK;
} }
@ -116,6 +109,44 @@ esp_err_t esp_blufi_host_and_cb_init(esp_blufi_callbacks_t *example_callbacks)
#endif /* CONFIG_BT_BLUEDROID_ENABLED */ #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 #ifdef CONFIG_BT_NIMBLE_ENABLED
void ble_store_config_init(void); void ble_store_config_init(void);
static void blufi_on_reset(int reason) static void blufi_on_reset(int reason)
@ -205,7 +236,7 @@ esp_err_t esp_blufi_host_deinit(void)
ret = nimble_port_stop(); ret = nimble_port_stop();
if (ret == 0) { if (ret == 0) {
nimble_port_deinit(); esp_nimble_deinit();
} }
return ret; return ret;