From da1372d6913f782612f6ae9fc43b8b08c2a513d8 Mon Sep 17 00:00:00 2001 From: Shen Wei Long Date: Tue, 11 Mar 2025 20:54:07 +0800 Subject: [PATCH] feat(ble/controller): Deleted useless functions for ESP32-C2 --- components/bt/CMakeLists.txt | 1 + components/bt/controller/esp32c2/ble.c | 58 +++++++++++++++++++ components/bt/controller/esp32c2/ble_priv.h | 13 +++++ components/bt/controller/esp32c2/bt.c | 10 +++- components/bt/controller/esp32c2/esp_bt_cfg.h | 8 ++- .../bt/controller/lib_esp32c2/esp32c2-bt-lib | 2 +- .../bt/include/esp32c2/include/esp_bt.h | 8 ++- .../esp32c2/ld/esp32c2.rom.ble-eco4.ld | 8 +-- .../esp_rom/esp32c2/ld/esp32c2.rom.ble.ld | 4 +- 9 files changed, 100 insertions(+), 12 deletions(-) create mode 100644 components/bt/controller/esp32c2/ble.c create mode 100644 components/bt/controller/esp32c2/ble_priv.h diff --git a/components/bt/CMakeLists.txt b/components/bt/CMakeLists.txt index 568635f51f..01edccfefc 100644 --- a/components/bt/CMakeLists.txt +++ b/components/bt/CMakeLists.txt @@ -86,6 +86,7 @@ if(CONFIG_BT_ENABLED) elseif(CONFIG_IDF_TARGET_ESP32S3) list(APPEND ldscripts "linker_rw_bt_controller.lf") elseif(CONFIG_IDF_TARGET_ESP32C2) + list(APPEND srcs "controller/esp32c2/ble.c") if(CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY) list(APPEND srcs "controller/esp32c2/dummy.c") endif() diff --git a/components/bt/controller/esp32c2/ble.c b/components/bt/controller/esp32c2/ble.c new file mode 100644 index 0000000000..9ea49196e5 --- /dev/null +++ b/components/bt/controller/esp32c2/ble.c @@ -0,0 +1,58 @@ +/* + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include + +#include "sdkconfig.h" +#include "esp_bt_cfg.h" + +/* External functions or variables + ************************************************************************ + */ +#if (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) +void adv_stack_enableClearLegacyAdvVsCmd(bool en); +void scan_stack_enableAdvFlowCtrlVsCmd(bool en); +void chanSel_stack_enableSetCsaVsCmd(bool en); +#endif // (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) + +/* Local functions definition + *************************************************************************** + */ +#if (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) +void ble_stack_enableVsCmds(bool en) +{ +#if DEFAULT_BT_LE_ROLE_BROADCASTER + adv_stack_enableClearLegacyAdvVsCmd(en); +#endif // DEFAULT_BT_LE_ROLE_BROADCASTER + +#if DEFAULT_BT_LE_ROLE_OBSERVER + scan_stack_enableAdvFlowCtrlVsCmd(en); +#endif // DEFAULT_BT_LE_ROLE_OBSERVER + + chanSel_stack_enableSetCsaVsCmd(en); +} + +void ble_stack_enableVsEvents(bool en) +{ +} +#endif // (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) + +int ble_stack_enable(void) +{ +#if (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) + ble_stack_enableVsCmds(true); + ble_stack_enableVsEvents(true); +#endif // (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) + + return 0; +} + +void ble_stack_disable(void) +{ +#if (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) + ble_stack_enableVsEvents(false); + ble_stack_enableVsCmds(false); +#endif // (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) +} diff --git a/components/bt/controller/esp32c2/ble_priv.h b/components/bt/controller/esp32c2/ble_priv.h new file mode 100644 index 0000000000..024bb0426f --- /dev/null +++ b/components/bt/controller/esp32c2/ble_priv.h @@ -0,0 +1,13 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef _BLE_PRIV_H_ +#define _BLE_PRIV_H_ + +int ble_stack_enable(void); + +void ble_stack_disable(void); + +#endif // _BLE_PRIV_H_ diff --git a/components/bt/controller/esp32c2/bt.c b/components/bt/controller/esp32c2/bt.c index 991b5889f2..f3a2b546d9 100644 --- a/components/bt/controller/esp32c2/bt.c +++ b/components/bt/controller/esp32c2/bt.c @@ -35,6 +35,7 @@ #include "os/endian.h" #include "esp_bt.h" +#include "ble_priv.h" #include "esp_intr_alloc.h" #include "esp_sleep.h" #include "esp_pm.h" @@ -999,6 +1000,12 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) #if CONFIG_SW_COEXIST_ENABLE coex_enable(); #endif + + if (ble_stack_enable() != 0) { + ret = ESP_FAIL; + goto error; + } + if (ble_controller_enable(mode) != 0) { ret = ESP_FAIL; goto error; @@ -1008,6 +1015,7 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) return ESP_OK; error: + ble_stack_disable(); #if CONFIG_SW_COEXIST_ENABLE coex_disable(); #endif @@ -1030,7 +1038,7 @@ esp_err_t esp_bt_controller_disable(void) if (ble_controller_disable() != 0) { return ESP_FAIL; } - + ble_stack_disable(); if (s_ble_active) { esp_phy_disable(PHY_MODEM_BT); #if CONFIG_PM_ENABLE diff --git a/components/bt/controller/esp32c2/esp_bt_cfg.h b/components/bt/controller/esp32c2/esp_bt_cfg.h index a78eca6ace..74d226a609 100644 --- a/components/bt/controller/esp32c2/esp_bt_cfg.h +++ b/components/bt/controller/esp32c2/esp_bt_cfg.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -232,6 +232,12 @@ extern "C" { #define HCI_UART_EN 0 // hci ram mode #endif +#ifdef CONFIG_BT_LE_HCI_INTERFACE_USE_RAM +#define DEFAULT_BT_LE_VHCI_ENABLED (CONFIG_BT_LE_HCI_INTERFACE_USE_RAM) +#else +#define DEFAULT_BT_LE_VHCI_ENABLED (0) +#endif + #ifdef CONFIG_BT_LE_SLEEP_ENABLE #define NIMBLE_SLEEP_ENABLE CONFIG_BT_LE_SLEEP_ENABLE #else diff --git a/components/bt/controller/lib_esp32c2/esp32c2-bt-lib b/components/bt/controller/lib_esp32c2/esp32c2-bt-lib index 1e510cbc50..1e88fa4606 160000 --- a/components/bt/controller/lib_esp32c2/esp32c2-bt-lib +++ b/components/bt/controller/lib_esp32c2/esp32c2-bt-lib @@ -1 +1 @@ -Subproject commit 1e510cbc50746259d53389309363058b89396a49 +Subproject commit 1e88fa4606b62faf7350ac12d4317ab4d1cd286d diff --git a/components/bt/include/esp32c2/include/esp_bt.h b/components/bt/include/esp32c2/include/esp_bt.h index 6a5ce5a1d6..3b4d5973a7 100644 --- a/components/bt/include/esp32c2/include/esp_bt.h +++ b/components/bt/include/esp32c2/include/esp_bt.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -167,7 +167,7 @@ esp_power_level_t esp_ble_tx_power_get_enhanced(esp_ble_enhanced_power_type_t po */ uint8_t esp_ble_get_chip_rev_version(void); -#define CONFIG_VERSION 0x20241121 +#define CONFIG_VERSION 0x20250310 #define CONFIG_MAGIC 0x5A5AA5A5 /** @@ -227,7 +227,8 @@ typedef struct { uint8_t version_num; /*!< Version number */ uint8_t ignore_wl_for_direct_adv; /*!< Ignore the white list for directed advertising */ uint8_t csa2_select; /*!< Select CSA#2 */ - uint8_t ble_aa_check; /*!< True if adds a verification step for the Access Address within the CONNECT_IND PDU; false otherwise. Configurable in menuconfig */ + uint8_t ble_aa_check; /*!< True if adds a verification step for the Access Address within the CONNECT_IND PDU; false otherwise. Configurable in menuconfig */ + uint8_t vhci_enabled; /*!< VHCI mode is enabled */ uint32_t config_magic; /*!< Configuration magic value */ } esp_bt_controller_config_t; @@ -275,6 +276,7 @@ typedef struct { .ignore_wl_for_direct_adv = 0, \ .csa2_select = DEFAULT_BT_LE_50_FEATURE_SUPPORT, \ .ble_aa_check = DEFAULT_BT_LE_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS, \ + .vhci_enabled = DEFAULT_BT_LE_VHCI_ENABLED, \ .config_magic = CONFIG_MAGIC, \ } diff --git a/components/esp_rom/esp32c2/ld/esp32c2.rom.ble-eco4.ld b/components/esp_rom/esp32c2/ld/esp32c2.rom.ble-eco4.ld index 5d0a91ae80..ed08b1a83c 100644 --- a/components/esp_rom/esp32c2/ld/esp32c2.rom.ble-eco4.ld +++ b/components/esp_rom/esp32c2/ld/esp32c2.rom.ble-eco4.ld @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -400,7 +400,7 @@ r_ble_ll_hci_set_adv_data = 0x40001088; r_ble_ll_hci_set_le_event_mask = 0x4000108c; r_ble_ll_hci_set_scan_rsp_data = 0x40001090; r_ble_ll_hci_status_params_cmd_proc = 0x40001094; -r_ble_ll_hci_vs_cmd_proc = 0x40001098; +//r_ble_ll_hci_vs_cmd_proc = 0x40001098; r_ble_ll_hci_vs_rd_static_addr = 0x4000109c; r_ble_ll_hw_err_timer_cb = 0x400010a0; r_ble_ll_hw_error = 0x400010a4; @@ -937,7 +937,7 @@ r_ble_phy_xcvr_state_get = 0x400018ec; r_ble_plf_set_log_level = 0x400018f0; r_ble_rtc_wake_up_cpu_init = 0x400018f4; r_ble_rtc_wake_up_state_clr = 0x400018f8; -r_ble_vendor_hci_register = 0x400018fc; +//r_ble_vendor_hci_register = 0x400018fc; r_bt_rf_coex_cfg_set = 0x40001900; r_bt_rf_coex_coded_txrx_time_upper_lim = 0x40001904; r_bt_rf_coex_dft_pti_set = 0x40001908; @@ -1173,7 +1173,7 @@ r_ble_ll_get_npl_element_info = 0x40002f48; r_ble_rtc_wake_up_cpu_clr = 0x40002f4c; r_ble_ll_scan_hci_set_adv_report_flow_ctrl = 0x40002f50; r_ble_ll_scan_hci_update_adv_report_flow_ctrl = 0x40002f54; -r_ble_ll_scan_send_adv_lost_report = 0x40002f58; +//r_ble_ll_scan_send_adv_lost_report = 0x40002f58; r_ble_ll_scan_adv_report_cth_flow_is_enabled = 0x40002f5c; r_ble_ll_scan_adv_report_cth_flow_alloc_credit = 0x40002f60; r_ble_ll_scan_adv_report_cth_flow_free_credit = 0x40002f64; diff --git a/components/esp_rom/esp32c2/ld/esp32c2.rom.ble.ld b/components/esp_rom/esp32c2/ld/esp32c2.rom.ble.ld index c4e201cc07..71cc8a7744 100644 --- a/components/esp_rom/esp32c2/ld/esp32c2.rom.ble.ld +++ b/components/esp_rom/esp32c2/ld/esp32c2.rom.ble.ld @@ -320,7 +320,7 @@ r_ble_ll_hci_set_adv_data = 0x40001088; r_ble_ll_hci_set_le_event_mask = 0x4000108c; r_ble_ll_hci_set_scan_rsp_data = 0x40001090; r_ble_ll_hci_status_params_cmd_proc = 0x40001094; -r_ble_ll_hci_vs_cmd_proc = 0x40001098; +//r_ble_ll_hci_vs_cmd_proc = 0x40001098; r_ble_ll_hci_vs_rd_static_addr = 0x4000109c; r_ble_ll_hw_err_timer_cb = 0x400010a0; r_ble_ll_hw_error = 0x400010a4; @@ -739,7 +739,7 @@ r_ble_phy_xcvr_state_get = 0x400018ec; r_ble_plf_set_log_level = 0x400018f0; r_ble_rtc_wake_up_cpu_init = 0x400018f4; r_ble_rtc_wake_up_state_clr = 0x400018f8; -r_ble_vendor_hci_register = 0x400018fc; +//r_ble_vendor_hci_register = 0x400018fc; r_bt_rf_coex_cfg_set = 0x40001900; r_bt_rf_coex_coded_txrx_time_upper_lim = 0x40001904; r_bt_rf_coex_dft_pti_set = 0x40001908;