然后,再次初始化,开启蓝牙、主任务,可以连接蓝牙,但是不能作为音频设备连接上。
只能用一次的蓝牙音箱,不符合要求啊!
测试代码如下:
- ret = esp_bluedroid_disable();
- ESP_LOGI(BT_AV_TAG, "esp_bluedroid_disable");
- vTaskDelay(2*1000/portTICK_RATE_MS);
- ret = esp_bluedroid_deinit();
- ESP_LOGI(BT_AV_TAG, "esp_bluedroid_deinit");
- vTaskDelay(2*1000/portTICK_RATE_MS);
- bt_app_task_shut_down();
- ESP_LOGI(BT_AV_TAG, "FreeHeapSize=%d", xPortGetFreeHeapSize());
- vTaskDelay(20*1000/portTICK_RATE_MS);
- ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_BLE));
- esp_bt_controller_config_t bt_cfg2 = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
- if ((err = esp_bt_controller_init(&bt_cfg2)) != ESP_OK) {
- ESP_LOGE(BT_AV_TAG, "%s initialize controller failed: %s\n", __func__, esp_err_to_name(ret));
- return;
- }
- if ((err = esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT)) != ESP_OK) {
- ESP_LOGE(BT_AV_TAG, "%s enable controller failed: %s\n", __func__, esp_err_to_name(ret));
- return;
- }
- if ((err = esp_bluedroid_init()) != ESP_OK) {
- ESP_LOGE(BT_AV_TAG, "%s initialize bluedroid failed: %s\n", __func__, esp_err_to_name(ret));
- return;
- }
- if ((err = esp_bluedroid_enable()) != ESP_OK) {
- ESP_LOGE(BT_AV_TAG, "%s enable bluedroid failed: %s\n", __func__, esp_err_to_name(ret));
- return;
- }
- /* create application task */
- bt_app_task_start_up();
- /* Bluetooth device name, connection mode and profile set up */
- bt_app_work_dispatch(bt_av_hdl_stack_evt, BT_APP_EVT_STACK_UP, NULL, 0, NULL);