From b5b46661e0f61278a8d48de59e5b533834b6996a Mon Sep 17 00:00:00 2001 From: h2zero <32826625+h2zero@users.noreply.github.com> Date: Tue, 3 Dec 2024 08:47:41 -0700 Subject: [PATCH] Fix compilation with esp32p4 (#253) --- .github/workflows/build.yml | 11 ++++++----- examples/Advanced/NimBLE_Client/main/main.cpp | 2 +- .../NimBLE_extended_client/main/main.cpp | 6 +++--- examples/NimBLE_Async_Client/main/main.cpp | 2 +- src/NimBLEDevice.cpp | 16 +++++++--------- src/NimBLEDevice.h | 8 ++++++-- 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4072a4f..fabde3b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,16 +17,13 @@ jobs: # See https://hub.docker.com/r/espressif/idf/tags and # https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-docker-image.html # for details. - idf_ver: ["release-v4.4", "release-v5.1"] - idf_target: ["esp32", "esp32s3", "esp32c2", "esp32c3", "esp32c6", "esp32h2"] + idf_ver: ["release-v4.4", "release-v5.1", "release-v5.3"] + idf_target: ["esp32", "esp32s3", "esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32p4"] example: - Advanced/NimBLE_Client - Advanced/NimBLE_Server - - Continuous_scan - Bluetooth_5/NimBLE_extended_client - Bluetooth_5/NimBLE_extended_server - - Bluetooth_5/NimBLE_multi_advertiser - - NimBLE_server_get_client_name exclude: - idf_target: "esp32" example: Bluetooth_5/NimBLE_extended_client @@ -40,6 +37,10 @@ jobs: idf_target: "esp32c6" - idf_ver: release-v4.4 idf_target: "esp32h2" + - idf_ver: release-v4.4 + idf_target: "esp32p4" + - idf_ver: release-v5.1 + idf_target: "esp32p4" container: espressif/idf:${{ matrix.idf_ver }} steps: diff --git a/examples/Advanced/NimBLE_Client/main/main.cpp b/examples/Advanced/NimBLE_Client/main/main.cpp index 697e544..4c33d31 100644 --- a/examples/Advanced/NimBLE_Client/main/main.cpp +++ b/examples/Advanced/NimBLE_Client/main/main.cpp @@ -341,7 +341,7 @@ void app_main (void){ NimBLEDevice::setSecurityAuth(/*BLE_SM_PAIR_AUTHREQ_BOND | BLE_SM_PAIR_AUTHREQ_MITM |*/ BLE_SM_PAIR_AUTHREQ_SC); /** Optional: set the transmit power, default is -3db */ - NimBLEDevice::setPower(ESP_PWR_LVL_P9); /** 12db */ + NimBLEDevice::setPower(9); // 9dbm /** create new scan */ NimBLEScan* pScan = NimBLEDevice::getScan(); diff --git a/examples/Bluetooth_5/NimBLE_extended_client/main/main.cpp b/examples/Bluetooth_5/NimBLE_extended_client/main/main.cpp index 3572e59..9056e74 100644 --- a/examples/Bluetooth_5/NimBLE_extended_client/main/main.cpp +++ b/examples/Bluetooth_5/NimBLE_extended_client/main/main.cpp @@ -14,7 +14,7 @@ extern "C" void app_main(void); #define SERVICE_UUID "ABCD" #define CHARACTERISTIC_UUID "1234" -static NimBLEAdvertisedDevice* advDevice; +static const NimBLEAdvertisedDevice* advDevice; static bool doConnect = false; static uint32_t scanTime = 10 * 1000; // In milliseconds, 0 = scan forever @@ -37,7 +37,7 @@ class ClientCallbacks : public NimBLEClientCallbacks { /* Define a class to handle the callbacks when advertisements are received */ class scanCallbacks: public NimBLEScanCallbacks { - void onResult(NimBLEAdvertisedDevice* advertisedDevice) { + void onResult(const NimBLEAdvertisedDevice* advertisedDevice) { printf("Advertised Device found: %s\n", advertisedDevice->toString().c_str()); if(advertisedDevice->isAdvertisingService(NimBLEUUID("ABCD"))) { @@ -52,7 +52,7 @@ class scanCallbacks: public NimBLEScanCallbacks { } /** Callback to process the results of the completed scan or restart it */ - void onScanEnd(NimBLEScanResults results) { + void onScanEnd(const NimBLEScanResults& results, int rc) { printf("Scan Ended\n"); } }; diff --git a/examples/NimBLE_Async_Client/main/main.cpp b/examples/NimBLE_Async_Client/main/main.cpp index b55c632..dd03235 100644 --- a/examples/NimBLE_Async_Client/main/main.cpp +++ b/examples/NimBLE_Async_Client/main/main.cpp @@ -48,7 +48,7 @@ class scanCallbacks : public NimBLEScanCallbacks { } } - void onScanEnd(NimBLEScanResults results) { + void onScanEnd(const NimBLEScanResults&, int reason) { printf("Scan Ended\n"); NimBLEDevice::getScan()->start(scanTimeMs); } diff --git a/src/NimBLEDevice.cpp b/src/NimBLEDevice.cpp index fc62b30..2a5eb0d 100644 --- a/src/NimBLEDevice.cpp +++ b/src/NimBLEDevice.cpp @@ -422,16 +422,13 @@ std::vector NimBLEDevice::getConnectedClients() { /* -------------------------------------------------------------------------- */ # ifdef ESP_PLATFORM +# ifndef CONFIG_IDF_TARGET_ESP32P4 /** * @brief Get the transmission power. * @return The power level currently used in esp_power_level_t. */ esp_power_level_t NimBLEDevice::getPowerLevel(esp_ble_power_type_t powerType) { -# ifdef CONFIG_IDF_TARGET_ESP32P4 - return 0xFF; // CONFIG_IDF_TARGET_ESP32P4 does not support esp_ble_tx_power_get -# else return esp_ble_tx_power_get(powerType); -# endif } // getPowerLevel /** @@ -440,19 +437,16 @@ esp_power_level_t NimBLEDevice::getPowerLevel(esp_ble_power_type_t powerType) { * @return True if the power level was set successfully. */ bool NimBLEDevice::setPowerLevel(esp_power_level_t powerLevel, esp_ble_power_type_t powerType) { -# ifdef CONFIG_IDF_TARGET_ESP32P4 - return false; // CONFIG_IDF_TARGET_ESP32P4 does not support esp_ble_tx_power_set -# else esp_err_t errRc = esp_ble_tx_power_set(powerType, powerLevel); if (errRc != ESP_OK) { NIMBLE_LOGE(LOG_TAG, "esp_ble_tx_power_set: rc=%d", errRc); } return errRc == ESP_OK; -# endif } // setPowerLevel +# endif // !CONFIG_IDF_TARGET_ESP32P4 +# endif // ESP_PLATFORM -# endif /** * @brief Set the transmission power. * @param [in] dbm The power level to set in dBm. @@ -460,10 +454,14 @@ bool NimBLEDevice::setPowerLevel(esp_power_level_t powerLevel, esp_ble_power_typ */ bool NimBLEDevice::setPower(int8_t dbm) { # ifdef ESP_PLATFORM +# ifdef CONFIG_IDF_TARGET_ESP32P4 + return false; // CONFIG_IDF_TARGET_ESP32P4 does not support esp_ble_tx_power_set +# else if (dbm % 3 == 2) { dbm++; // round up to the next multiple of 3 to be able to target 20dbm } return setPowerLevel(static_cast(dbm / 3 + ESP_PWR_LVL_N0)); +# endif # else NIMBLE_LOGD(LOG_TAG, ">> setPower: %d", dbm); ble_hci_vs_set_tx_pwr_cp cmd{dbm}; diff --git a/src/NimBLEDevice.h b/src/NimBLEDevice.h index add0fec..fd1b937 100644 --- a/src/NimBLEDevice.h +++ b/src/NimBLEDevice.h @@ -18,7 +18,9 @@ #include "nimconfig.h" #if defined(CONFIG_BT_ENABLED) # ifdef ESP_PLATFORM -# include +# ifndef CONFIG_IDF_TARGET_ESP32P4 +# include +# endif # endif # if defined(CONFIG_NIMBLE_CPP_IDF) @@ -136,9 +138,11 @@ class NimBLEDevice { static int getPower(); static bool setPower(int8_t dbm); -# if defined(ESP_PLATFORM) +# ifdef ESP_PLATFORM +# ifndef CONFIG_IDF_TARGET_ESP32P4 static esp_power_level_t getPowerLevel(esp_ble_power_type_t powerType = ESP_BLE_PWR_TYPE_DEFAULT); static bool setPowerLevel(esp_power_level_t powerLevel, esp_ble_power_type_t powerType = ESP_BLE_PWR_TYPE_DEFAULT); +# endif # endif # if CONFIG_BT_NIMBLE_EXT_ADV