Explorar o código

Merge branch 'bugfix/remove_inappropriate_bluetooth_init_api' into 'master'

Remove unused bluetooth init api

See merge request espressif/esp-idf!18923
Jiang Jiang Jian %!s(int64=3) %!d(string=hai) anos
pai
achega
92b4e134bb

+ 1 - 1
components/bt/CMakeLists.txt

@@ -614,7 +614,7 @@ if(CONFIG_BT_ENABLED)
             )
         endif()
 
-        if(CONFIG_IDF_TARGET_ESP32 OR CONFIG_IDF_TARGET_ESP32C3 OR CONFIG_IDF_TARGET_ESP32S3 OR TRUE)
+        if(CONFIG_BT_NIMBLE_LEGACY_VHCI_ENABLE)
             list(APPEND srcs
                 "host/nimble/esp-hci/src/esp_nimble_hci.c"
             )

+ 0 - 1
components/bt/common/btc/profile/esp/blufi/nimble_host/esp_blufi.c

@@ -20,7 +20,6 @@
 #include "console/console.h"
 
 /*nimBLE Host*/
-#include "esp_nimble_hci.h"
 #include "nimble/nimble_port.h"
 #include "nimble/nimble_port_freertos.h"
 #include "host/ble_hs.h"

+ 7 - 0
components/bt/host/nimble/Kconfig.in

@@ -628,3 +628,10 @@ config BT_NIMBLE_USE_ESP_TIMER
     default y
     help
         Set this option to use Esp Timer which has higher priority timer instead of FreeRTOS timer
+
+config BT_NIMBLE_LEGACY_VHCI_ENABLE
+    bool
+    default y if (IDF_TARGET_ESP32 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3)
+    default n
+    help
+        This option is used to distinguish whether a previous version of VHCI is being used

+ 0 - 71
components/bt/host/nimble/esp-hci/include/esp_nimble_hci.h

@@ -33,46 +33,6 @@ extern "C" {
  */
 esp_err_t esp_nimble_hci_init(void);
 
-/**
- * @brief Initialize ESP Bluetooth controller(link layer) and VHCI transport
- * layer between NimBLE Host and ESP Bluetooth controller
- *
- * This function initializes ESP controller in BLE only mode and the
- * transport buffers to be exchanged between NimBLE host and ESP controller.
- * It also registers required host callbacks with the controller.
- *
- * Below is the sequence of APIs to be called to init/enable NimBLE host and ESP controller:
- *
- * @code{c}
- * void ble_host_task(void *param)
- * {
- *      nimble_port_run(); //This function will return only when nimble_port_stop() is executed.
- *      nimble_port_freertos_deinit();
- * }
- *
- * int ret = esp_nimble_hci_and_controller_init();
- * if (ret != ESP_OK) {
-        ESP_LOGE(TAG, "esp_nimble_hci_and_controller_init() failed with error: %d", ret);
- *      return;
- * }
- *
- * nimble_port_init();
- *
- * //Initialize the NimBLE Host configuration
- *
- * nimble_port_freertos_init(ble_host_task);
- * @endcode
- *
- * nimble_port_freertos_init() is an optional call that creates a new task in which the NimBLE
- * host will run. The task function should have a call to nimble_port_run(). If a separate task
- * is not required, calling nimble_port_run() will run the NimBLE host in the current task.
- *
- * @return
- *    - ESP_OK if the initialization is successful
- *    - Appropriate error code from esp_err_t in case of an error
- */
-esp_err_t esp_nimble_hci_and_controller_init(void);
-
 /**
  * @brief Deinitialize VHCI transport layer between NimBLE Host and
  * ESP Bluetooth controller
@@ -85,37 +45,6 @@ esp_err_t esp_nimble_hci_and_controller_init(void);
  */
 esp_err_t esp_nimble_hci_deinit(void);
 
-/**
- * @brief Deinitialize VHCI transport layer between NimBLE Host and
- * ESP Bluetooth controller and disable and deinitialize the controller
- *
- * @note This function should not be executed in the context of Bluetooth host task.
- *
- * @note This function should be called after the NimBLE host is deinitialized.
- *
- * Below is the sequence of APIs to be called to disable/deinit NimBLE host and ESP controller:
- *
- * @code{c}
- * int ret = nimble_port_stop();
- * if (ret == 0) {
- *      nimble_port_deinit();
- *
- *      ret = esp_nimble_hci_and_controller_deinit();
- *      if (ret != ESP_OK) {
-            ESP_LOGE(TAG, "esp_nimble_hci_and_controller_deinit() failed with error: %d", ret);
- *      }
- * }
- * @endcode
- *
- * If nimble_port_freertos_init() is used during initialization, then
- * nimble_port_freertos_deinit() should be called in the host task after nimble_port_run().
- *
- * @return
- *    - ESP_OK if the deinitialization is successful
- *    - Appropriate error codes from esp_err_t in case of an error
- */
-esp_err_t esp_nimble_hci_and_controller_deinit(void);
-
 #ifdef __cplusplus
 }
 #endif

+ 0 - 54
components/bt/host/nimble/esp-hci/src/esp_nimble_hci.c

@@ -20,20 +20,6 @@
 #include "esp_compiler.h"
 #include "soc/soc_caps.h"
 
-#if SOC_ESP_NIMBLE_CONTROLLER
-
-/* For Chips not using VHCI, these functions return success */
-esp_err_t esp_nimble_hci_and_controller_init(void)
-{
-    return ESP_OK;
-}
-
-esp_err_t esp_nimble_hci_and_controller_deinit(void)
-{
-    return ESP_OK;
-}
-#else
-
 #define NIMBLE_VHCI_TIMEOUT_MS  2000
 #define BLE_HCI_EVENT_HDR_LEN               (2)
 #define BLE_HCI_CMD_HDR_LEN                 (3)
@@ -461,24 +447,6 @@ err:
 
 }
 
-esp_err_t esp_nimble_hci_and_controller_init(void)
-{
-    esp_err_t ret;
-
-    esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT);
-
-    esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
-
-    if ((ret = esp_bt_controller_init(&bt_cfg)) != ESP_OK) {
-        return ret;
-    }
-
-    if ((ret = esp_bt_controller_enable(ESP_BT_MODE_BLE)) != ESP_OK) {
-        return ret;
-    }
-    return esp_nimble_hci_init();
-}
-
 static esp_err_t ble_hci_transport_deinit(void)
 {
     int ret = 0;
@@ -516,25 +484,3 @@ esp_err_t esp_nimble_hci_deinit(void)
 
     return ESP_OK;
 }
-
-esp_err_t esp_nimble_hci_and_controller_deinit(void)
-{
-    int ret;
-    ret = esp_nimble_hci_deinit();
-    if (ret != ESP_OK) {
-        return ret;
-    }
-
-    ret = esp_bt_controller_disable();
-    if (ret != ESP_OK) {
-        return ret;
-    }
-
-    ret = esp_bt_controller_deinit();
-    if (ret != ESP_OK) {
-        return ret;
-    }
-
-    return ESP_OK;
-}
-#endif // #if SOC_ESP_NIMBLE_CONTROLLER

+ 1 - 1
components/bt/host/nimble/nimble

@@ -1 +1 @@
-Subproject commit 643226881d1ed4378ed7819a1e966176a3746936
+Subproject commit c1cb851c8562d0f1a4d105614c336341e2a535b2

+ 0 - 6
components/protocomm/src/transports/protocomm_nimble.c

@@ -13,7 +13,6 @@
 #include "protocomm_priv.h"
 
 /* NimBLE */
-#include "esp_nimble_hci.h"
 #include "nimble/nimble_port.h"
 #include "nimble/nimble_port_freertos.h"
 #include "host/ble_hs.h"
@@ -480,7 +479,6 @@ static int simple_ble_start(const simple_ble_cfg_t *cfg)
     int rc;
     ESP_LOGD(TAG, "Free memory at start of simple_ble_init %d", esp_get_free_heap_size());
 
-    ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init());
     nimble_port_init();
 
     /* Initialize the NimBLE host configuration. */
@@ -953,10 +951,6 @@ esp_err_t protocomm_ble_stop(protocomm_t *pc)
         ret = nimble_port_stop();
         if (ret == 0) {
             nimble_port_deinit();
-            ret = esp_nimble_hci_and_controller_deinit();
-            if (ret != ESP_OK) {
-                ESP_LOGE(TAG, "esp_nimble_hci_and_controller_deinit() failed with error: %d", ret);
-            }
         }
 
         free_gatt_ble_misc_memory(ble_cfg_p);

+ 13 - 5
examples/bluetooth/blufi/main/blufi_init.c

@@ -1,5 +1,5 @@
 /*
- * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
+ * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
  *
  * SPDX-License-Identifier: Unlicense OR CC0-1.0
  */
@@ -17,7 +17,6 @@
 #endif
 
 #ifdef CONFIG_BT_NIMBLE_ENABLED
-#include "esp_nimble_hci.h"
 #include "nimble/nimble_port.h"
 #include "nimble/nimble_port_freertos.h"
 #include "host/ble_hs.h"
@@ -110,8 +109,13 @@ void bleprph_host_task(void *param)
 
 esp_err_t esp_blufi_host_init(void)
 {
-   ESP_ERROR_CHECK(esp_nimble_hci_init());
-   nimble_port_init();
+    esp_err_t err;
+    err = esp_nimble_init();
+    if (err) {
+        BLUFI_ERROR("%s failed: %s\n", __func__, esp_err_to_name(err));
+        return ESP_FAIL;
+    }
+
 /* Initialize the NimBLE host configuration. */
     ble_hs_cfg.reset_cb = blufi_on_reset;
     ble_hs_cfg.sync_cb = blufi_on_sync;
@@ -148,7 +152,11 @@ esp_err_t esp_blufi_host_init(void)
 
     esp_blufi_btc_init();
 
-    nimble_port_freertos_init(bleprph_host_task);
+    err = esp_nimble_enable(bleprph_host_task);
+    if (err) {
+        BLUFI_ERROR("%s failed: %s\n", __func__, esp_err_to_name(err));
+        return ESP_FAIL;
+    }
 
     return ESP_OK;
 }

+ 11 - 0
examples/bluetooth/blufi/sdkconfig.defaults.esp32c2

@@ -0,0 +1,11 @@
+# This file was generated using idf.py save-defconfig. It can be edited manually.
+# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration
+#
+CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE=y
+CONFIG_BT_ENABLED=y
+CONFIG_BT_BLE_BLUFI_ENABLE=y
+# CONFIG_BT_GATTC_ENABLE is not set
+# CONFIG_BT_BLE_SMP_ENABLE is not set
+# CONFIG_BT_BLE_50_FEATURES_SUPPORTED is not set
+CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
+CONFIG_MBEDTLS_DHM_C=y

+ 1 - 4
examples/bluetooth/esp_ble_mesh/common_components/example_init/ble_mesh_example_init.c

@@ -1,6 +1,6 @@
 /*
  * SPDX-FileCopyrightText: 2017 Intel Corporation
- * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
+ * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
  *
  * SPDX-License-Identifier: Apache-2.0
  */
@@ -16,7 +16,6 @@
 #endif
 
 #ifdef CONFIG_BT_NIMBLE_ENABLED
-#include "esp_nimble_hci.h"
 #include "nimble/nimble_port.h"
 #include "nimble/nimble_port_freertos.h"
 #include "host/ble_hs.h"
@@ -139,8 +138,6 @@ esp_err_t bluetooth_init(void)
         return ESP_FAIL;
     }
 
-    ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init());
-
     nimble_port_init();
     /* Initialize the NimBLE host configuration. */
     ble_hs_cfg.reset_cb = mesh_on_reset;

+ 0 - 3
examples/bluetooth/nimble/ble_spp/spp_client/main/main.c

@@ -7,7 +7,6 @@
 #include "esp_log.h"
 #include "nvs_flash.h"
 /* BLE */
-#include "esp_nimble_hci.h"
 #include "nimble/nimble_port.h"
 #include "nimble/nimble_port_freertos.h"
 #include "host/ble_hs.h"
@@ -423,8 +422,6 @@ app_main(void)
     }
     ESP_ERROR_CHECK(ret);
 
-    ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init());
-
     nimble_port_init();
 
     /* Initialize UART driver and start uart task */

+ 0 - 3
examples/bluetooth/nimble/ble_spp/spp_server/main/main.c

@@ -7,7 +7,6 @@
 #include "esp_log.h"
 #include "nvs_flash.h"
 /* BLE */
-#include "esp_nimble_hci.h"
 #include "nimble/nimble_port.h"
 #include "nimble/nimble_port_freertos.h"
 #include "host/ble_hs.h"
@@ -398,8 +397,6 @@ app_main(void)
     }
     ESP_ERROR_CHECK(ret);
 
-    ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init());
-
     nimble_port_init();
 
     /* Initialize uart driver and start uart task */

+ 0 - 3
examples/bluetooth/nimble/blecent/main/main.c

@@ -20,7 +20,6 @@
 #include "esp_log.h"
 #include "nvs_flash.h"
 /* BLE */
-#include "esp_nimble_hci.h"
 #include "nimble/nimble_port.h"
 #include "nimble/nimble_port_freertos.h"
 #include "host/ble_hs.h"
@@ -603,8 +602,6 @@ app_main(void)
     }
     ESP_ERROR_CHECK(ret);
 
-    ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init());
-
     nimble_port_init();
     /* Configure the host. */
     ble_hs_cfg.reset_cb = blecent_on_reset;

+ 0 - 3
examples/bluetooth/nimble/blehr/main/main.c

@@ -21,7 +21,6 @@
 #include "nvs_flash.h"
 #include "freertos/FreeRTOSConfig.h"
 /* BLE */
-#include "esp_nimble_hci.h"
 #include "nimble/nimble_port.h"
 #include "nimble/nimble_port_freertos.h"
 #include "host/ble_hs.h"
@@ -281,8 +280,6 @@ void app_main(void)
     }
     ESP_ERROR_CHECK(ret);
 
-    ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init());
-
     nimble_port_init();
     /* Initialize the NimBLE host configuration */
     ble_hs_cfg.sync_cb = blehr_on_sync;

+ 0 - 2
examples/bluetooth/nimble/blemesh/main/app_mesh.c

@@ -21,7 +21,6 @@
 #include "nvs_flash.h"
 #include "freertos/FreeRTOSConfig.h"
 /* BLE */
-#include "esp_nimble_hci.h"
 #include "nimble/nimble_port.h"
 #include "nimble/nimble_port_freertos.h"
 #include "host/ble_hs.h"
@@ -444,7 +443,6 @@ void app_main(void)
     }
     ESP_ERROR_CHECK(ret);
 
-    ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init());
     nimble_port_init();
 
     ble_svc_gap_init();

+ 0 - 3
examples/bluetooth/nimble/bleprph/main/main.c

@@ -20,7 +20,6 @@
 #include "esp_log.h"
 #include "nvs_flash.h"
 /* BLE */
-#include "esp_nimble_hci.h"
 #include "nimble/nimble_port.h"
 #include "nimble/nimble_port_freertos.h"
 #include "host/ble_hs.h"
@@ -422,8 +421,6 @@ app_main(void)
     }
     ESP_ERROR_CHECK(ret);
 
-    ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init());
-
     nimble_port_init();
     /* Initialize the NimBLE host configuration. */
     ble_hs_cfg.reset_cb = bleprph_on_reset;

+ 0 - 2
examples/bluetooth/nimble/bleprph_wifi_coex/main/main.c

@@ -18,7 +18,6 @@
 #include "esp_log.h"
 #include "nvs_flash.h"
 /* BLE */
-#include "esp_nimble_hci.h"
 #include "nimble/nimble_port.h"
 #include "nimble/nimble_port_freertos.h"
 #include "host/ble_hs.h"
@@ -539,7 +538,6 @@ app_main(void)
     ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
     wifi_init_sta();
     do_ping_cmd();
-    ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init());
 
     nimble_port_init();
     /* Initialize the NimBLE host configuration. */

+ 0 - 2
examples/bluetooth/nimble/throughput_app/blecent_throughput/main/main.c

@@ -7,7 +7,6 @@
 #include "esp_log.h"
 #include "nvs_flash.h"
 /* BLE */
-#include "esp_nimble_hci.h"
 #include "nimble/nimble_port.h"
 #include "nimble/nimble_port_freertos.h"
 #include "host/ble_hs.h"
@@ -723,7 +722,6 @@ app_main(void)
         ret = nvs_flash_init();
     }
     ESP_ERROR_CHECK(ret);
-    ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init());
 
     nimble_port_init();
 

+ 0 - 2
examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/main.c

@@ -8,7 +8,6 @@
 #include "nvs_flash.h"
 #include "freertos/FreeRTOSConfig.h"
 /* BLE */
-#include "esp_nimble_hci.h"
 #include "nimble/nimble_port.h"
 #include "nimble/nimble_port_freertos.h"
 #include "host/ble_hs.h"
@@ -371,7 +370,6 @@ void app_main(void)
         ret = nvs_flash_init();
     }
     ESP_ERROR_CHECK(ret);
-    ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init());
 
     nimble_port_init();
     /* Initialize the NimBLE host configuration */

+ 5 - 15
examples/system/ota/advanced_https_ota/main/ble_helper/ble_api.c

@@ -1,16 +1,8 @@
-// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+/*
+ * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
 
 #include "sdkconfig.h"
 
@@ -79,8 +71,6 @@ void esp_ble_helper_init(void)
 
 #elif CONFIG_BT_NIMBLE_ENABLED
 
-    ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init());
-
     nimble_port_init();
     /* Initialize the NimBLE host configuration. */
     ble_hs_cfg.reset_cb = bleprph_on_reset;

+ 0 - 1
examples/system/ota/advanced_https_ota/main/ble_helper/include/nimble_gatts.h

@@ -17,7 +17,6 @@ extern "C" {
 #include <stdbool.h>
 #include "nimble/ble.h"
 #include "modlog/modlog.h"
-#include "esp_nimble_hci.h"
 #include "nimble/nimble_port.h"
 #include "nimble/nimble_port_freertos.h"
 #include "host/ble_hs.h"

+ 0 - 1
tools/ci/check_copyright_ignore.txt

@@ -1986,7 +1986,6 @@ examples/system/ipc/ipc_isr/main/main.c
 examples/system/light_sleep/example_test.py
 examples/system/ota/advanced_https_ota/example_test.py
 examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c
-examples/system/ota/advanced_https_ota/main/ble_helper/ble_api.c
 examples/system/ota/advanced_https_ota/main/ble_helper/include/ble_api.h
 examples/system/ota/native_ota_example/example_test.py
 examples/system/ota/native_ota_example/main/native_ota_example.c