feat(examples/bluedroid): Add BLE time interval conversion macros for better readability

Add macros to convert time values from milliseconds to BLE interval units:
- ESP_BLE_GAP_ADV_ITVL_MS: Convert advertising interval (0.625ms unit)
- ESP_BLE_GAP_SCAN_ITVL_MS: Convert scan interval (0.625ms unit)
- ESP_BLE_GAP_SCAN_WIN_MS: Convert scan window (0.625ms unit)
- ESP_BLE_GAP_CONN_ITVL_MS: Convert connection interval (1.25ms unit)
- ESP_BLE_GAP_PERIODIC_ADV_ITVL_MS: Convert periodic adv interval (1.25ms unit)
- ESP_BLE_GAP_SUPERVISION_TIMEOUT_MS: Convert supervision timeout (10ms unit)

(cherry picked from commit 7cd2f7b34d)

Co-authored-by: zhanghaipeng <zhanghaipeng@espressif.com>
This commit is contained in:
Zhang Hai Peng
2026-01-09 14:09:16 +08:00
committed by zhanghaipeng
parent 28e016917c
commit d1bf2668c1
27 changed files with 150 additions and 129 deletions
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -66,32 +66,32 @@ static esp_ble_ext_scan_params_t ext_scan_params = {
};
const esp_ble_conn_params_t phy_1m_conn_params = {
.scan_interval = 0x40,
.scan_window = 0x40,
.scan_interval = ESP_BLE_GAP_SCAN_ITVL_MS(40),
.scan_window = ESP_BLE_GAP_SCAN_WIN_MS(40),
.interval_min = 320,
.interval_max = 320,
.latency = 0,
.supervision_timeout = 600,
.supervision_timeout = ESP_BLE_GAP_SUPERVISION_TIMEOUT_MS(6000),
.min_ce_len = 0,
.max_ce_len = 0,
};
const esp_ble_conn_params_t phy_2m_conn_params = {
.scan_interval = 0x40,
.scan_window = 0x40,
.scan_interval = ESP_BLE_GAP_SCAN_ITVL_MS(40),
.scan_window = ESP_BLE_GAP_SCAN_WIN_MS(40),
.interval_min = 320,
.interval_max = 320,
.latency = 0,
.supervision_timeout = 600,
.supervision_timeout = ESP_BLE_GAP_SUPERVISION_TIMEOUT_MS(6000),
.min_ce_len = 0,
.max_ce_len = 0,
};
const esp_ble_conn_params_t phy_coded_conn_params = {
.scan_interval = 0x40,
.scan_window = 0x40,
.scan_interval = ESP_BLE_GAP_SCAN_ITVL_MS(40),
.scan_window = ESP_BLE_GAP_SCAN_WIN_MS(40),
.interval_min = 320, // 306-> 362Kbps
.interval_max = 320,
.latency = 0,
.supervision_timeout = 600,
.supervision_timeout = ESP_BLE_GAP_SUPERVISION_TIMEOUT_MS(6000),
.min_ce_len = 0,
.max_ce_len = 0,
};
@@ -52,8 +52,8 @@ static esp_ble_gap_ext_adv_t ext_adv[1] = {
esp_ble_gap_ext_adv_params_t ext_adv_params_2M = {
.type = ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE,
.interval_min = 0x20,
.interval_max = 0x20,
.interval_min = ESP_BLE_GAP_ADV_ITVL_MS(20),
.interval_max = ESP_BLE_GAP_ADV_ITVL_MS(20),
.channel_map = ADV_CHNL_ALL,
.filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
.primary_phy = ESP_BLE_GAP_PHY_1M,
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -110,9 +110,9 @@ const esp_ble_conn_params_t phy_1m_conn_params = {
.latency = 0,
.max_ce_len = 0,
.min_ce_len = 0,
.scan_interval = 0x40,
.scan_window = 0x40,
.supervision_timeout = 600,
.scan_interval = ESP_BLE_GAP_SCAN_ITVL_MS(40),
.scan_window = ESP_BLE_GAP_SCAN_WIN_MS(40),
.supervision_timeout = ESP_BLE_GAP_SUPERVISION_TIMEOUT_MS(6000),
};
const esp_ble_conn_params_t phy_2m_conn_params = {
@@ -121,9 +121,9 @@ const esp_ble_conn_params_t phy_2m_conn_params = {
.latency = 0,
.max_ce_len = 0,
.min_ce_len = 0,
.scan_interval = 0x40,
.scan_window = 0x40,
.supervision_timeout = 600,
.scan_interval = ESP_BLE_GAP_SCAN_ITVL_MS(40),
.scan_window = ESP_BLE_GAP_SCAN_WIN_MS(40),
.supervision_timeout = ESP_BLE_GAP_SUPERVISION_TIMEOUT_MS(6000),
};
const esp_ble_conn_params_t phy_coded_conn_params = {
@@ -132,9 +132,9 @@ const esp_ble_conn_params_t phy_coded_conn_params = {
.latency = 0,
.max_ce_len = 0,
.min_ce_len = 0,
.scan_interval = 0x40,
.scan_window = 0x40,
.supervision_timeout = 600,
.scan_interval = ESP_BLE_GAP_SCAN_ITVL_MS(40),
.scan_window = ESP_BLE_GAP_SCAN_WIN_MS(40),
.supervision_timeout = ESP_BLE_GAP_SUPERVISION_TIMEOUT_MS(6000),
};
struct gattc_profile_inst {
@@ -112,8 +112,8 @@ static esp_ble_gap_ext_adv_t ext_adv[1] = {
esp_ble_gap_ext_adv_params_t ext_adv_params = {
.type = ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE,
.interval_min = 0x20,
.interval_max = 0x20,
.interval_min = ESP_BLE_GAP_ADV_ITVL_MS(20),
.interval_max = ESP_BLE_GAP_ADV_ITVL_MS(20),
.channel_map = ADV_CHNL_ALL,
.filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
.primary_phy = ESP_BLE_GAP_PHY_1M,
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -49,8 +49,8 @@ static SemaphoreHandle_t test_sem = NULL;
esp_ble_gap_ext_adv_params_t ext_adv_params_1M = {
.type = ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE,
.interval_min = 0x30,
.interval_max = 0x30,
.interval_min = ESP_BLE_GAP_ADV_ITVL_MS(30),
.interval_max = ESP_BLE_GAP_ADV_ITVL_MS(30),
.channel_map = ADV_CHNL_ALL,
.filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
.primary_phy = ESP_BLE_GAP_PHY_1M,
@@ -64,8 +64,8 @@ esp_ble_gap_ext_adv_params_t ext_adv_params_1M = {
esp_ble_gap_ext_adv_params_t ext_adv_params_2M = {
.type = ESP_BLE_GAP_SET_EXT_ADV_PROP_SCANNABLE,
.interval_min = 0x40,
.interval_max = 0x40,
.interval_min = ESP_BLE_GAP_ADV_ITVL_MS(40),
.interval_max = ESP_BLE_GAP_ADV_ITVL_MS(40),
.channel_map = ADV_CHNL_ALL,
.filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
.primary_phy = ESP_BLE_GAP_PHY_1M,
@@ -79,8 +79,8 @@ esp_ble_gap_ext_adv_params_t ext_adv_params_2M = {
esp_ble_gap_ext_adv_params_t legacy_adv_params = {
.type = ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_IND,
.interval_min = 0x45,
.interval_max = 0x45,
.interval_min = ESP_BLE_GAP_ADV_ITVL_MS(43),
.interval_max = ESP_BLE_GAP_ADV_ITVL_MS(43),
.channel_map = ADV_CHNL_ALL,
.filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
.primary_phy = ESP_BLE_GAP_PHY_1M,
@@ -94,8 +94,8 @@ esp_ble_gap_ext_adv_params_t legacy_adv_params = {
esp_ble_gap_ext_adv_params_t ext_adv_params_coded = {
.type = ESP_BLE_GAP_SET_EXT_ADV_PROP_SCANNABLE,
.interval_min = 0x50,
.interval_max = 0x50,
.interval_min = ESP_BLE_GAP_ADV_ITVL_MS(50),
.interval_max = ESP_BLE_GAP_ADV_ITVL_MS(50),
.channel_map = ADV_CHNL_ALL,
.filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
.primary_phy = ESP_BLE_GAP_PHY_1M,
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -58,8 +58,8 @@ static SemaphoreHandle_t test_sem = NULL;
esp_ble_gap_ext_adv_params_t ext_adv_params_2M = {
.type = ESP_BLE_GAP_SET_EXT_ADV_PROP_NONCONN_NONSCANNABLE_UNDIRECTED,
.interval_min = 0x30,
.interval_max = 0x30,
.interval_min = ESP_BLE_GAP_ADV_ITVL_MS(30),
.interval_max = ESP_BLE_GAP_ADV_ITVL_MS(30),
.channel_map = ADV_CHNL_ALL,
.filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY,
.primary_phy = ESP_BLE_GAP_PHY_1M,
@@ -72,8 +72,8 @@ esp_ble_gap_ext_adv_params_t ext_adv_params_2M = {
};
static esp_ble_gap_periodic_adv_params_t periodic_adv_params = {
.interval_min = 0x40, // 80 ms interval
.interval_max = 0x40,
.interval_min = ESP_BLE_GAP_PERIODIC_ADV_ITVL_MS(80),
.interval_max = ESP_BLE_GAP_PERIODIC_ADV_ITVL_MS(80),
.properties = 0, // Do not include TX power
};