Skip to content

Commit

Permalink
Merge branch 'feature/add_ble_multi_conn_example_with_vs_hci' into 'm…
Browse files Browse the repository at this point in the history
…aster'

Feature/add ble multi conn example with vs hci

See merge request espressif/esp-idf!24602
  • Loading branch information
ShenWeilong committed Jul 18, 2023
2 parents a2d76ad + e9e6372 commit 13ea139
Show file tree
Hide file tree
Showing 35 changed files with 2,018 additions and 7 deletions.
2 changes: 1 addition & 1 deletion components/bt/controller/esp32c6/Kconfig.in
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ config BT_LE_LL_SCA
config BT_LE_MAX_CONNECTIONS
int "Maximum number of concurrent connections"
depends on !BT_NIMBLE_ENABLED
range 1 9
range 1 70
default 3
help
Defines maximum number of concurrent BLE connections. For ESP32, user
Expand Down
2 changes: 1 addition & 1 deletion components/bt/controller/esp32h2/Kconfig.in
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ config BT_LE_LL_SCA
config BT_LE_MAX_CONNECTIONS
int "Maximum number of concurrent connections"
depends on !BT_NIMBLE_ENABLED
range 1 9
range 1 35
default 3
help
Defines maximum number of concurrent BLE connections. For ESP32, user
Expand Down
12 changes: 12 additions & 0 deletions components/bt/host/nimble/Kconfig.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ config BT_NIMBLE_LOG_LEVEL
config BT_NIMBLE_MAX_CONNECTIONS
int "Maximum number of concurrent connections"
range 1 2 if IDF_TARGET_ESP32C2
range 1 70 if IDF_TARGET_ESP32C6
range 1 35 if IDF_TARGET_ESP32H2
range 1 9
default 2 if IDF_TARGET_ESP32C2
default 3
Expand Down Expand Up @@ -825,3 +827,13 @@ config BT_NIMBLE_VS_SUPPORT
help
This option is used to enable support for sending Vendor Specific HCI commands and handling
Vendor Specific HCI Events.

config BT_NIMBLE_OPTIMIZE_MULTI_CONN
bool "Enable the optimization of multi-connection"
depends on SOC_BLE_MULTI_CONN_OPTIMIZATION
select BT_NIMBLE_VS_SUPPORT
default n
help
This option enables the use of vendor-specific APIs for multi-connections, which can
greatly enhance the stability of coexistence between numerous central and peripheral
devices. It will prohibit the usage of standard APIs.
2 changes: 1 addition & 1 deletion components/bt/host/nimble/nimble
10 changes: 9 additions & 1 deletion components/bt/host/nimble/port/include/esp_nimble_cfg.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -1707,4 +1707,12 @@
#define MYNEWT_VAL_BLE_HCI_VS (0)
#endif

#ifndef MYNEWT_VAL_OPTIMIZE_MULTI_CONN
#ifdef CONFIG_BT_NIMBLE_OPTIMIZE_MULTI_CONN
#define MYNEWT_VAL_OPTIMIZE_MULTI_CONN CONFIG_BT_NIMBLE_OPTIMIZE_MULTI_CONN
#else
#define MYNEWT_VAL_OPTIMIZE_MULTI_CONN (0)
#endif
#endif

#endif
4 changes: 4 additions & 0 deletions components/soc/esp32c6/include/soc/Kconfig.soc_caps.in
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,10 @@ config SOC_BLUFI_SUPPORTED
bool
default y

config SOC_BLE_MULTI_CONN_OPTIMIZATION
bool
default y

config SOC_BLE_USE_WIFI_PWR_CLK_WORKAROUND
bool
default y
1 change: 1 addition & 0 deletions components/soc/esp32c6/include/soc/soc_caps.h
Original file line number Diff line number Diff line change
Expand Up @@ -532,5 +532,6 @@
#define SOC_BLE_DEVICE_PRIVACY_SUPPORTED (1) /*!< Support BLE device privacy mode */
#define SOC_BLE_POWER_CONTROL_SUPPORTED (1) /*!< Support Bluetooth Power Control */
#define SOC_BLUFI_SUPPORTED (1) /*!< Support BLUFI */
#define SOC_BLE_MULTI_CONN_OPTIMIZATION (1) /*!< Support multiple connections optimization */

#define SOC_BLE_USE_WIFI_PWR_CLK_WORKAROUND (1)
4 changes: 4 additions & 0 deletions components/soc/esp32h2/include/soc/Kconfig.soc_caps.in
Original file line number Diff line number Diff line change
Expand Up @@ -1214,3 +1214,7 @@ config SOC_BLE_DEVICE_PRIVACY_SUPPORTED
config SOC_BLE_POWER_CONTROL_SUPPORTED
bool
default y

config SOC_BLE_MULTI_CONN_OPTIMIZATION
bool
default y
1 change: 1 addition & 0 deletions components/soc/esp32h2/include/soc/soc_caps.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,4 @@
#define SOC_BLE_50_SUPPORTED (1) /*!< Support Bluetooth 5.0 */
#define SOC_BLE_DEVICE_PRIVACY_SUPPORTED (1) /*!< Support BLE device privacy mode */
#define SOC_BLE_POWER_CONTROL_SUPPORTED (1) /*!< Support Bluetooth Power Control */
#define SOC_BLE_MULTI_CONN_OPTIMIZATION (1) /*!< Support multiple connections optimization */
10 changes: 10 additions & 0 deletions examples/bluetooth/.build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ examples/bluetooth/nimble/ble_multi_adv:
temporary: true
reason: The runner doesn't support yet

examples/bluetooth/nimble/ble_multi_conn:
enable:
- if: IDF_TARGET in ["esp32c6", "esp32h2"]
temporary: true
reason: the other targets are not tested yet
disable_test:
- if: IDF_TARGET in ["esp32c6", "esp32h2"]
temporary: true
reason: The runner doesn't support yet

examples/bluetooth/nimble/ble_periodic_adv:
enable:
- if: IDF_TARGET in ["esp32c2", "esp32c3", "esp32c6" , "esp32s3", "esp32h2" ]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)

set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/bluetooth/nimble/common/nimble_central_utils)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(blecent)
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
| Supported Targets | ESP32-C6 | ESP32-H2 |
| ----------------- | -------- | -------- |

# BLE Multiple Connection Central Example

(See the README.md file in the upper level 'examples' directory for more information about examples.)

Please check the [tutorial](tutorial/Ble_Multiple_Connections_Central_Example_Walkthrough.md) for more information about this example.

## How to Use Example

Before project configuration and build, be sure to set the correct chip target using:

```bash
idf.py set-target <chip_name>
```

### Hardware Required

* At least two development board with ESP32-C6/ESP32-H2 SoC (e.g., ESP32-C6-DevKitC, ESP32-H2-DevKitC, etc.)
* USB cable for Power supply and programming

See [Development Boards](https://www.espressif.com/en/products/devkits) for more information about it.

### Build and Flash

Run `idf.py -p PORT flash monitor` to build, flash and monitor the project.

(To exit the serial monitor, type ``Ctrl-]``.)

See the [Getting Started Guide](https://idf.espressif.com/) for full steps to configure and use ESP-IDF to build projects.

## Example Output

This is the console output on successful connection:

```
controller lib commit: [5cacafa]
I (564) ESP_MULTI_CONN_EXT: BLE Host Task Started
I (564) main_task: Returned from app_main()
I (604) ESP_MULTI_CONN_EXT: Create connection. -> peer addr e0:e1:f5:6f:ec:9d
I (1234) ESP_MULTI_CONN_EXT: Connection established. Handle:1, Total:1
I (2754) ESP_MULTI_CONN_EXT: Create connection. -> peer addr ee:16:69:80:72:d5
I (3394) ESP_MULTI_CONN_EXT: Connection established. Handle:2, Total:2
I (4454) ESP_MULTI_CONN_EXT: Create connection. -> peer addr ef:1a:6e:d6:64:44
I (5094) ESP_MULTI_CONN_EXT: Connection established. Handle:3, Total:3
I (6144) ESP_MULTI_CONN_EXT: Create connection. -> peer addr cb:f4:5d:b2:c8:1d
I (6244) ESP_MULTI_CONN_EXT: Connection established. Handle:4, Total:4
I (6444) ESP_MULTI_CONN_EXT: Create connection. -> peer addr e8:08:e5:ad:61:f6
I (7394) ESP_MULTI_CONN_EXT: Connection established. Handle:5, Total:5
I (8504) ESP_MULTI_CONN_EXT: Create connection. -> peer addr c1:53:a8:6f:2a:b4
I (9124) ESP_MULTI_CONN_EXT: Connection established. Handle:6, Total:6
I (9274) ESP_MULTI_CONN_EXT: Create connection. -> peer addr dd:fb:5b:13:6a:20
I (9904) ESP_MULTI_CONN_EXT: Connection established. Handle:7, Total:7
I (10934) ESP_MULTI_CONN_EXT: Create connection. -> peer addr d5:71:9c:fe:4f:6e
I (11574) ESP_MULTI_CONN_EXT: Connection established. Handle:8, Total:8
I (12264) ESP_MULTI_CONN_EXT: Create connection. -> peer addr d9:56:91:21:d4:25
I (12884) ESP_MULTI_CONN_EXT: Connection established. Handle:9, Total:9
I (13084) ESP_MULTI_CONN_EXT: Create connection. -> peer addr f7:f9:b1:73:38:13
I (13704) ESP_MULTI_CONN_EXT: Connection established. Handle:10, Total:10
I (14724) ESP_MULTI_CONN_EXT: Create connection. -> peer addr e7:e5:94:d0:32:78
I (15354) ESP_MULTI_CONN_EXT: Connection established. Handle:11, Total:11
I (16404) ESP_MULTI_CONN_EXT: Create connection. -> peer addr fb:c6:f9:46:11:dc
I (17344) ESP_MULTI_CONN_EXT: Connection established. Handle:12, Total:12
I (18434) ESP_MULTI_CONN_EXT: Create connection. -> peer addr c0:e3:ef:80:e6:fd
I (19374) ESP_MULTI_CONN_EXT: Connection established. Handle:13, Total:13
I (20484) ESP_MULTI_CONN_EXT: Create connection. -> peer addr d8:9d:6d:b8:c9:40
I (21104) ESP_MULTI_CONN_EXT: Connection established. Handle:14, Total:14
I (30814) ESP_MULTI_CONN_EXT: Connected to central. Handle:15
I (39624) BLE_CENT_SVC: Characteristic write; conn_handle=15
I (39624) BLE_CENT_SVC: 12
```

## Troubleshooting

For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(srcs "main.c"
"gatt_svr.c")

idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS ".")
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
menu "Example Configuration"


endmenu
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef H_BLECENT_
#define H_BLECENT_

#include "esp_central.h"
#ifdef __cplusplus
extern "C" {
#endif

int gatt_svr_init(void);

#ifdef __cplusplus
}
#endif

#endif
Loading

0 comments on commit 13ea139

Please sign in to comment.