From ebb7650e63c595ce016234b32c7a0b5cfea1fbf7 Mon Sep 17 00:00:00 2001 From: wangmengyang Date: Fri, 20 Jan 2023 10:47:58 +0800 Subject: [PATCH] bluetooth: fix that functions "coex_enable" and "coex_disable" are not used in pairs on ESP32-C3, ESP32-S3 and ESP32-C2 --- components/bt/controller/esp32c2/bt.c | 15 ++++++++++++++- components/bt/controller/esp32c3/bt.c | 5 ++++- components/bt/controller/esp32s3/bt.c | 5 ++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/components/bt/controller/esp32c2/bt.c b/components/bt/controller/esp32c2/bt.c index 25d1e699ba..ca5ae2256b 100644 --- a/components/bt/controller/esp32c2/bt.c +++ b/components/bt/controller/esp32c2/bt.c @@ -750,6 +750,8 @@ esp_err_t esp_bt_controller_deinit(void) esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) { + esp_err_t ret = ESP_OK; + if (mode != ESP_BT_MODE_BLE) { ESP_LOGW(NIMBLE_PORT_LOG_TAG, "invalid controller mode"); return ESP_FAIL; @@ -762,10 +764,18 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) coex_enable(); #endif if (ble_controller_enable(mode) != 0) { - return ESP_FAIL; + ret = ESP_FAIL; + goto error; } + ble_controller_status = ESP_BT_CONTROLLER_STATUS_ENABLED; return ESP_OK; + +error: +#if CONFIG_SW_COEXIST_ENABLE + coex_disable(); +#endif + return ret; } esp_err_t esp_bt_controller_disable(void) @@ -777,6 +787,9 @@ esp_err_t esp_bt_controller_disable(void) if (ble_controller_disable() != 0) { return ESP_FAIL; } +#if CONFIG_SW_COEXIST_ENABLE + coex_disable(); +#endif ble_controller_status = ESP_BT_CONTROLLER_STATUS_INITED; return ESP_OK; } diff --git a/components/bt/controller/esp32c3/bt.c b/components/bt/controller/esp32c3/bt.c index 5d98444792..f16d1dde56 100644 --- a/components/bt/controller/esp32c3/bt.c +++ b/components/bt/controller/esp32c3/bt.c @@ -1383,7 +1383,7 @@ static void bt_controller_deinit_internal(void) esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) { - int ret = ESP_OK; + esp_err_t ret = ESP_OK; if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_INITED) { return ESP_ERR_INVALID_STATE; @@ -1438,6 +1438,9 @@ error: #endif } while (0); +#if CONFIG_SW_COEXIST_ENABLE + coex_disable(); +#endif return ret; } diff --git a/components/bt/controller/esp32s3/bt.c b/components/bt/controller/esp32s3/bt.c index 9e625dc05b..ab4c187bb6 100644 --- a/components/bt/controller/esp32s3/bt.c +++ b/components/bt/controller/esp32s3/bt.c @@ -1429,7 +1429,7 @@ static void bt_controller_deinit_internal(void) esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) { - int ret = ESP_OK; + esp_err_t ret = ESP_OK; if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_INITED) { return ESP_ERR_INVALID_STATE; @@ -1484,6 +1484,9 @@ error: #endif } while (0); +#if CONFIG_SW_COEXIST_ENABLE + coex_disable(); +#endif return ret; }