Skip to content

Commit a7f7bdc

Browse files
committed
bluetooth: add ble tx power configuration
Allow bluetooth controller to be initialized with default custom tx power level. Signed-off-by: Sylvio Alves <[email protected]>
1 parent 2da6ac8 commit a7f7bdc

File tree

4 files changed

+97
-2
lines changed

4 files changed

+97
-2
lines changed

zephyr/esp32/include/bt/esp_bt.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,26 @@ extern "C" {
5656
*/
5757
#define ESP_BT_CONTROLLER_CONFIG_MAGIC_VAL 0x20240722
5858

59+
#if defined(CONFIG_BT_CTLR_TX_PWR_PLUS_9)
60+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_P9
61+
#elif defined(CONFIG_BT_CTLR_TX_PWR_PLUS_6)
62+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_P6
63+
#elif defined(CONFIG_BT_CTLR_TX_PWR_PLUS_3)
64+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_P3
65+
#elif defined(CONFIG_BT_CTLR_TX_PWR_0)
66+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N0
67+
#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_3)
68+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N3
69+
#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_6)
70+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N6
71+
#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_9)
72+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N9
73+
#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_12)
74+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N12
75+
#else
76+
#error "Invalid ESP32 BLE TX Power"
77+
#endif
78+
5979
/**
6080
* @brief Bluetooth Controller mode
6181
*/

zephyr/esp32/src/bt/esp_bt_adapter.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,9 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
12601260

12611261
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_ENABLED;
12621262

1263+
/* set default TX power level */
1264+
esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_DEFAULT, ESP32_RADIO_TXP_DEFAULT);
1265+
12631266
return ESP_OK;
12641267
}
12651268

zephyr/esp32c3/include/bt/esp_bt.h

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,42 @@ extern "C" {
2323
#define ESP_BT_HCI_TL_MAGIC_VALUE 0xfadebead
2424
#define ESP_BT_HCI_TL_VERSION 0x00010000
2525

26+
#if defined(CONFIG_BT_CTLR_TX_PWR_PLUS_21)
27+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_P21
28+
#elif defined(CONFIG_BT_CTLR_TX_PWR_PLUS_18)
29+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_P18
30+
#elif defined(CONFIG_BT_CTLR_TX_PWR_PLUS_15)
31+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_P15
32+
#elif defined(CONFIG_BT_CTLR_TX_PWR_PLUS_12)
33+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_P12
34+
#elif defined(CONFIG_BT_CTLR_TX_PWR_PLUS_9)
35+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_P9
36+
#elif defined(CONFIG_BT_CTLR_TX_PWR_PLUS_6)
37+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_P6
38+
#elif defined(CONFIG_BT_CTLR_TX_PWR_PLUS_3)
39+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_P3
40+
#elif defined(CONFIG_BT_CTLR_TX_PWR_0)
41+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N0
42+
#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_3)
43+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N3
44+
#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_6)
45+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N6
46+
#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_9)
47+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N9
48+
#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_12)
49+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N12
50+
#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_15)
51+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N15
52+
#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_18)
53+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N18
54+
#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_21)
55+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N21
56+
#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_24)
57+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N24
58+
#else
59+
#error "Invalid ESP32 BLE TX Power"
60+
#endif
61+
2662
/**
2763
* @brief Bluetooth mode for controller enable/disable
2864
*/
@@ -249,7 +285,7 @@ typedef void (* btdm_vnd_ol_task_func_t)(void *param);
249285
.hci_tl_funcs = NULL, \
250286
.txant_dft = 0, \
251287
.rxant_dft = 0, \
252-
.txpwr_dft = 8, \
288+
.txpwr_dft = ESP32_RADIO_TXP_DEFAULT, \
253289
.cfg_mask = CFG_MASK, \
254290
.scan_duplicate_mode = SCAN_DUPLICATE_MODE, \
255291
.scan_duplicate_type = SCAN_DUPLICATE_TYPE_VALUE, \

zephyr/esp32s3/include/bt/esp_bt.h

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,42 @@ extern "C" {
2323
#define ESP_BT_HCI_TL_MAGIC_VALUE 0xfadebead
2424
#define ESP_BT_HCI_TL_VERSION 0x00010000
2525

26+
#if defined(CONFIG_BT_CTLR_TX_PWR_PLUS_21)
27+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_P21
28+
#elif defined(CONFIG_BT_CTLR_TX_PWR_PLUS_18)
29+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_P18
30+
#elif defined(CONFIG_BT_CTLR_TX_PWR_PLUS_15)
31+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_P15
32+
#elif defined(CONFIG_BT_CTLR_TX_PWR_PLUS_12)
33+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_P12
34+
#elif defined(CONFIG_BT_CTLR_TX_PWR_PLUS_9)
35+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_P9
36+
#elif defined(CONFIG_BT_CTLR_TX_PWR_PLUS_6)
37+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_P6
38+
#elif defined(CONFIG_BT_CTLR_TX_PWR_PLUS_3)
39+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_P3
40+
#elif defined(CONFIG_BT_CTLR_TX_PWR_0)
41+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N0
42+
#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_3)
43+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N3
44+
#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_6)
45+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N6
46+
#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_9)
47+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N9
48+
#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_12)
49+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N12
50+
#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_15)
51+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N15
52+
#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_18)
53+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N18
54+
#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_21)
55+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N21
56+
#elif defined(CONFIG_BT_CTLR_TX_PWR_MINUS_24)
57+
#define ESP32_RADIO_TXP_DEFAULT ESP_PWR_LVL_N24
58+
#else
59+
#error "Invalid ESP32 BLE TX Power"
60+
#endif
61+
2662
/**
2763
* @brief Bluetooth mode for controller enable/disable
2864
*/
@@ -249,7 +285,7 @@ typedef void (* btdm_vnd_ol_task_func_t)(void *param);
249285
.hci_tl_funcs = NULL, \
250286
.txant_dft = 0, \
251287
.rxant_dft = 0, \
252-
.txpwr_dft = 8, \
288+
.txpwr_dft = ESP32_RADIO_TXP_DEFAULT, \
253289
.cfg_mask = CFG_MASK, \
254290
.scan_duplicate_mode = SCAN_DUPLICATE_MODE, \
255291
.scan_duplicate_type = SCAN_DUPLICATE_TYPE_VALUE, \

0 commit comments

Comments
 (0)