Skip to content

Commit

Permalink
Merge branch 'feature/periodic_adv_enhancement' into 'master'
Browse files Browse the repository at this point in the history
NimBLE : Added periodic Adv Feature Updates in BLE 5.3

See merge request espressif/esp-idf!20474
  • Loading branch information
rahult-github committed Aug 22, 2023
2 parents 514d9a8 + 67b956f commit 94234f0
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 4 deletions.
6 changes: 6 additions & 0 deletions components/bt/host/nimble/Kconfig.in
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,12 @@ config BT_NIMBLE_BLE_POWER_CONTROL
help
Set this option to enable the Power Control feature

config BT_NIMBLE_PERIODIC_ADV_ENH
bool "Periodic adv enhancements(adi support)"
depends on BT_NIMBLE_ENABLE_PERIODIC_ADV && BT_NIMBLE_50_FEATURE_SUPPORT && SOC_BLE_PERIODIC_ADV_ENH_SUPPORTED
help
Enable the periodic advertising enhancements

choice BT_NIMBLE_COEX_PHY_CODED_TX_RX_TLIM
prompt "Coexistence: limit on MAX Tx/Rx time for coded-PHY connection"
default BT_NIMBLE_COEX_PHY_CODED_TX_RX_TLIM_DIS
Expand Down
2 changes: 1 addition & 1 deletion components/bt/host/nimble/nimble
5 changes: 5 additions & 0 deletions components/bt/host/nimble/port/include/esp_nimble_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@
#else
#define MYNEWT_VAL_BLE_CONN_SUBRATING (CONFIG_BT_NIMBLE_SUBRATE)
#endif
#ifndef CONFIG_BT_NIMBLE_PERIODIC_ADV_ENH
#define MYNEWT_VAL_BLE_PERIODIC_ADV_ENH (0)
#else
#define MYNEWT_VAL_BLE_PERIODIC_ADV_ENH (CONFIG_BT_NIMBLE_PERIODIC_ADV_ENH)
#endif

/*** @apache-mynewt-nimble/nimble/controller */
/*** @apache-mynewt-nimble/nimble/controller */
Expand Down
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 @@ -1319,6 +1319,10 @@ config SOC_BLE_POWER_CONTROL_SUPPORTED
bool
default y

config SOC_BLE_PERIODIC_ADV_ENH_SUPPORTED
bool
default y

config SOC_BLUFI_SUPPORTED
bool
default y
Expand Down
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 @@ -539,6 +539,7 @@
#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_PERIODIC_ADV_ENH_SUPPORTED (1) /*!< Support For BLE Periodic Adv Enhancements */
#define SOC_BLUFI_SUPPORTED (1) /*!< Support BLUFI */
#define SOC_BLE_MULTI_CONN_OPTIMIZATION (1) /*!< Support multiple connections optimization */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ menu "Example Configuration"
prompt "Advertise RANDOM Address"
help
Use this option to advertise a random address instead of public address

config EXAMPLE_PERIODIC_ADV_ENH
bool
prompt "Enable Periodic Adv Enhancements"
depends on SOC_BLE_50_SUPPORTED && SOC_BLE_PERIODIC_ADV_ENH_SUPPORTED
select BT_NIMBLE_PERIODIC_ADV_ENH
help
Use this option to enable periodic advertising enhancements
endmenu
17 changes: 16 additions & 1 deletion examples/bluetooth/nimble/ble_periodic_adv/main/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
Expand Down Expand Up @@ -47,6 +47,10 @@ start_periodic_adv(void)
struct os_mbuf *data;
uint8_t instance = 1;
ble_addr_t addr;
#if MYNEWT_VAL(BLE_PERIODIC_ADV_ENH)
struct ble_gap_periodic_adv_enable_params eparams;
memset(&eparams, 0, sizeof(eparams));
#endif

/* set random (NRPA) address for instance */
rc = ble_hs_id_gen_rnd(1, &addr);
Expand Down Expand Up @@ -101,11 +105,22 @@ start_periodic_adv(void)

rc = os_mbuf_append(data, periodic_adv_raw_data, sizeof(periodic_adv_raw_data));
assert(rc == 0);
#if MYNEWT_VAL(BLE_PERIODIC_ADV_ENH)
rc = ble_gap_periodic_adv_set_data(instance, data, NULL);
#else
rc = ble_gap_periodic_adv_set_data(instance, data);
#endif
assert (rc == 0);

/* start periodic advertising */
#if MYNEWT_VAL(BLE_PERIODIC_ADV_ENH)
#if CONFIG_EXAMPLE_PERIODIC_ADV_ENH
eparams.include_adi = 1;
#endif
rc = ble_gap_periodic_adv_start(instance, &eparams);
#else
rc = ble_gap_periodic_adv_start(instance);
#endif
assert (rc == 0);

/* start advertising */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@ menu "Example Configuration"
help
Use this option to enable extended advertising in the example.
If this option is disabled, ensure config BT_NIMBLE_EXT_ADV is
also disabled from Nimble stack menuconfig
also disabled from NimBLE stack menuconfig

config EXAMPLE_PERIODIC_ADV_ENH
bool
prompt "Enable Periodic Adv Enhancements"
depends on SOC_BLE_50_SUPPORTED && SOC_BLE_PERIODIC_ADV_ENH_SUPPORTED
select BT_NIMBLE_PERIODIC_ADV_ENH
help
Use this option to enable periodic adv enhancements
endmenu
9 changes: 8 additions & 1 deletion examples/bluetooth/nimble/ble_periodic_sync/main/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
Expand Down Expand Up @@ -122,6 +122,13 @@ periodic_sync_gap_event(struct ble_gap_event *event, void *arg)
memcpy(&adv_sid, &disc->sid, sizeof(disc->sid));
params.skip = 10;
params.sync_timeout = 1000;

#if CONFIG_EXAMPLE_PERIODIC_ADV_ENH
/* This way the periodic advertising reports will not be
delivered to host unless the advertising data is changed
or the Data-Id is updated by the advertiser */
params.filter_duplicates = 1;
#endif
rc = ble_gap_periodic_adv_sync_create(&addr, adv_sid, &params, periodic_sync_gap_event, NULL);
assert(rc == 0);
}
Expand Down

0 comments on commit 94234f0

Please sign in to comment.