From 29610b8a1bc2ceda5d70d98b64c453f2eaf65ff6 Mon Sep 17 00:00:00 2001 From: wangmengyang Date: Wed, 4 Jan 2023 15:34:05 +0800 Subject: [PATCH] bluetooth: fix that functions "coex_enable" and "coex_disable" are not used in pairs on ESP32-C3, ESP32-S3, ESP32-C2 and ESP32-C6 --- components/bt/controller/esp32c2/bt.c | 15 ++++++++++++++- components/bt/controller/esp32c3/bt.c | 5 ++++- components/bt/controller/esp32c6/bt.c | 14 +++++++++++++- components/bt/controller/esp32s3/bt.c | 5 ++++- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/components/bt/controller/esp32c2/bt.c b/components/bt/controller/esp32c2/bt.c index 25d1e699ba5..ca5ae2256b9 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 1bab7da38c7..06acad6b17a 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 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) #endif } while (0); +#if CONFIG_SW_COEXIST_ENABLE + coex_disable(); +#endif return ret; } diff --git a/components/bt/controller/esp32c6/bt.c b/components/bt/controller/esp32c6/bt.c index c659d747d80..23cf720bd6c 100644 --- a/components/bt/controller/esp32c6/bt.c +++ b/components/bt/controller/esp32c6/bt.c @@ -729,6 +729,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; @@ -743,10 +745,17 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) #endif // CONFIG_SW_COEXIST_ENABLE 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) @@ -758,6 +767,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/esp32s3/bt.c b/components/bt/controller/esp32s3/bt.c index 9e625dc05bc..ab4c187bb6b 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 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) #endif } while (0); +#if CONFIG_SW_COEXIST_ENABLE + coex_disable(); +#endif return ret; }