Skip to content

Commit c0db953

Browse files
committed
Add a workaround for esp32s3 and esp32c3 tx power bug
This adds a workaround to get the tx power when the function returns error due to a bug introduced in some versions of esp-idf.
1 parent 6c85cfa commit c0db953

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/NimBLEDevice.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,14 +482,21 @@ bool NimBLEDevice::setPower(int8_t dbm) {
482482
/**
483483
* @brief Get the transmission power.
484484
* @return The power level currently used in dbm.
485-
* @note ESP32S3 only returns 0xFF as of IDF 5, so this function will return 20dbm.
486485
*/
487486
int NimBLEDevice::getPower() {
488487
# ifdef ESP_PLATFORM
489488
# ifdef CONFIG_IDF_TARGET_ESP32P4
490489
return 0xFF; // CONFIG_IDF_TARGET_ESP32P4 does not support esp_ble_tx_power_get
491490
# else
492491
int pwr = esp_ble_tx_power_get(ESP_BLE_PWR_TYPE_DEFAULT);
492+
493+
# if defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S3)
494+
// workaround for bug when "enhanced tx power" was added
495+
if (pwr == 0xFF) {
496+
pwr = esp_ble_tx_power_get(ESP_BLE_PWR_TYPE_CONN_HDL3);
497+
}
498+
# endif
499+
493500
if (pwr < ESP_PWR_LVL_N0) {
494501
return -3 * (ESP_PWR_LVL_N0 - pwr);
495502
}

0 commit comments

Comments
 (0)