From aeff7fc0974d5e240d0cb725dbd943344822e037 Mon Sep 17 00:00:00 2001 From: xutao Date: Fri, 2 Sep 2022 11:26:56 +0800 Subject: [PATCH] example: fix example issues 1. fix `wifi_bt_ble_coex` example ble cover bt name 2. fix BluFi's network issue when enable blufi at the same time enable the class BT --- .../wifi_service/blufi_config/blufi_config.c | 6 --- .../main/esp_dispatcher_dueros_app.c | 39 ++++++++++++++++++- .../main/wifi_bt_ble_coex_example.c | 6 ++- examples/korvo_du1906/main/app_player_init.c | 1 + 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/components/wifi_service/blufi_config/blufi_config.c b/components/wifi_service/blufi_config/blufi_config.c index 52bfffd85..d1071c1b2 100644 --- a/components/wifi_service/blufi_config/blufi_config.c +++ b/components/wifi_service/blufi_config/blufi_config.c @@ -244,8 +244,6 @@ static void wifi_ble_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_par #if (defined CONFIG_BT_BLE_BLUFI_ENABLE) || (defined CONFIG_BLUEDROID_ENABLED) esp_err_t esp_blufi_host_init(void) { - ESP_ERROR_CHECK(esp_bluedroid_init()); - ESP_ERROR_CHECK(esp_bluedroid_enable()); ESP_LOGI(TAG, "BD ADDR: "ESP_BD_ADDR_STR"\n", ESP_BD_ADDR_HEX(esp_bt_dev_get_address())); return ESP_OK; } @@ -365,10 +363,6 @@ esp_wifi_setting_handle_t blufi_config_create(void *info) return NULL; }); esp_wifi_setting_set_data(bc_setting_handle, cfg); - 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(); - ESP_ERROR_CHECK(esp_bt_controller_init(&bt_cfg)); - ESP_ERROR_CHECK(esp_bt_controller_enable(ESP_BT_MODE_BLE)); ESP_ERROR_CHECK(esp_blufi_host_and_cb_init(&wifi_ble_callbacks)); esp_wifi_setting_register_function(bc_setting_handle, _ble_config_start, _ble_config_stop, NULL); return bc_setting_handle; diff --git a/examples/advanced_examples/esp_dispatcher_dueros/main/esp_dispatcher_dueros_app.c b/examples/advanced_examples/esp_dispatcher_dueros/main/esp_dispatcher_dueros_app.c index 5fd75ca60..f29b6afc6 100644 --- a/examples/advanced_examples/esp_dispatcher_dueros/main/esp_dispatcher_dueros_app.c +++ b/examples/advanced_examples/esp_dispatcher_dueros/main/esp_dispatcher_dueros_app.c @@ -27,13 +27,16 @@ #include #include "sdkconfig.h" +#include "esp_log.h" +#include "esp_bt.h" +#include "esp_bt_main.h" + #include "esp_peripherals.h" #include "audio_mem.h" #include "audio_setup.h" #include "esp_dispatcher_dueros_app.h" #include "esp_player_wrapper.h" #include "duer_audio_action.h" -#include "esp_log.h" #include "display_service.h" #include "dueros_service.h" @@ -247,6 +250,39 @@ static esp_err_t input_key_service_cb(periph_service_handle_t handle, periph_ser return ESP_OK; } +static esp_err_t initialize_ble_stack(void) +{ + esp_err_t ret = ESP_OK; + 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) { + ESP_LOGE(TAG, "%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) { + ESP_LOGE(TAG, "%s enable bt controller failed: %s\n", __func__, esp_err_to_name(ret)); + return ret; + } + + ret = esp_bluedroid_init(); + if (ret) { + ESP_LOGE(TAG, "%s init bluedroid failed: %s\n", __func__, esp_err_to_name(ret)); + return ret; + } + + ret = esp_bluedroid_enable(); + if (ret) { + ESP_LOGE(TAG, "%s init bluedroid failed: %s\n", __func__, esp_err_to_name(ret)); + return ret; + } + return ESP_OK; +} + + void duer_app_init(void) { esp_log_level_set("*", ESP_LOG_INFO); @@ -369,6 +405,7 @@ void duer_app_init(void) smart_config_info_t info = SMART_CONFIG_INFO_DEFAULT(); h = smart_config_create(&info); #elif (defined CONFIG_ESP_BLUFI_PROVISIONING) + initialize_ble_stack(); h = blufi_config_create(NULL); #endif esp_wifi_setting_regitster_notify_handle(h, (void *)dueros_speaker->wifi_serv); diff --git a/examples/advanced_examples/wifi_bt_ble_coex/main/wifi_bt_ble_coex_example.c b/examples/advanced_examples/wifi_bt_ble_coex/main/wifi_bt_ble_coex_example.c index 12c97a368..0a90b917c 100644 --- a/examples/advanced_examples/wifi_bt_ble_coex/main/wifi_bt_ble_coex_example.c +++ b/examples/advanced_examples/wifi_bt_ble_coex/main/wifi_bt_ble_coex_example.c @@ -195,6 +195,10 @@ static esp_err_t wifi_service_cb(periph_service_handle_t handle, periph_service_ if (evt->type == WIFI_SERV_EVENT_CONNECTED) { ESP_LOGI(TAG, "WIFI_CONNECTED"); g_wifi_connect_state = true; + esp_err_t set_dev_name_ret = esp_bt_dev_set_device_name(SAMPLE_DEVICE_NAME); + if (set_dev_name_ret) { + ESP_LOGE(TAG, "Set BT device name failed, error code = %x, line(%d)", set_dev_name_ret, __LINE__); + } } else if (evt->type == WIFI_SERV_EVENT_DISCONNECTED) { ESP_LOGI(TAG, "WIFI_DISCONNECTED"); g_wifi_connect_state = false; @@ -314,7 +318,7 @@ static void a2dp_sink_blufi_start(coex_handle_t *handle) esp_err_t set_dev_name_ret = esp_bt_dev_set_device_name(SAMPLE_DEVICE_NAME); if (set_dev_name_ret) { - ESP_LOGE(TAG, "set device name failed, error code = %x", set_dev_name_ret); + ESP_LOGE(TAG, "Set BT device name failed, error code = %x, line(%d)", set_dev_name_ret, __LINE__); } ESP_LOGI(TAG, "[4.3] Create Bluetooth peripheral"); handle->bt_periph = bt_create_periph(); diff --git a/examples/korvo_du1906/main/app_player_init.c b/examples/korvo_du1906/main/app_player_init.c index 9324c5e6f..5c3398245 100644 --- a/examples/korvo_du1906/main/app_player_init.c +++ b/examples/korvo_du1906/main/app_player_init.c @@ -159,6 +159,7 @@ esp_err_t app_player_init(QueueHandle_t que, audio_player_evt_callback cb, esp_p audio_board_handle_t board_handle = audio_board_init(); audio_hal_ctrl_codec(board_handle->audio_hal, AUDIO_HAL_CODEC_MODE_BOTH, AUDIO_HAL_CTRL_START); + // This API must call before BluFI's network esp_periph_handle_t bt_periph = app_bluetooth_init(set); esp_audio_cfg_t default_cfg = DEFAULT_ESP_AUDIO_CONFIG();