From ed2c59d5de3e26f35dd42ae68d3cc01c1ae1c90c Mon Sep 17 00:00:00 2001 From: chegewara Date: Fri, 1 Nov 2024 02:06:57 +0100 Subject: [PATCH] Add initial esp32-P4 support (#208) --- CMakeLists.txt | 1 + Kconfig | 47 +++++++++++++++++++++++++++++++++++++++ idf_component.yml | 16 +++++++++++++ src/NimBLEAdvertising.cpp | 4 ++++ src/NimBLEDevice.cpp | 5 ++++- src/NimBLEDevice.h | 4 ++++ 6 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 idf_component.yml diff --git a/CMakeLists.txt b/CMakeLists.txt index 055e5d9..a537e2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,7 @@ idf_component_register( "esp32c3" "esp32c6" "esp32h2" + "esp32p4" INCLUDE_DIRS "src" SRCS diff --git a/Kconfig b/Kconfig index 0878176..db71798 100644 --- a/Kconfig +++ b/Kconfig @@ -76,4 +76,51 @@ config NIMBLE_CPP_DEBUG_ASSERT_ENABLED Enabling this option will add debug asserts to the NimBLE CPP library. This will use approximately 1kB of flash memory. +# +# BT config +# +config BT_ENABLED + bool "Bluetooth" + default "y" + help + Select this option to enable Bluetooth and show the submenu with Bluetooth configuration choices. + + +config BT_NIMBLE_ENABLED + bool "NimBLE - BLE only" + default "y" + help + This option is recommended for BLE only usecases to save on memory + +if IDF_TARGET_ESP32P4 + + config BT_NIMBLE_TRANSPORT_UART + bool "Enable Uart Transport" + default "n" + + # + # Enable ESP Hosted BT + # Used as VHCI transport between BT Host and Controller + # + config ESP_ENABLE_BT + bool "Enable Hosted Bluetooth support" + default "y" + help + Enable Bluetooth Support via Hosted + + choice ESP_WIFI_REMOTE_LIBRARY + prompt "Choose WiFi-remote implementation" + default ESP_WIFI_REMOTE_LIBRARY_HOSTED + help + Select type of WiFi Remote implementation + + ESP-HOSTED is the default and most versatile option. + It's also possible to use EPPP, which uses PPPoS link between micros and NAPT, so it's slower + and less universal. + + config ESP_WIFI_REMOTE_LIBRARY_HOSTED + bool "ESP-HOSTED" + endchoice +endif + endmenu diff --git a/idf_component.yml b/idf_component.yml new file mode 100644 index 0000000..52a0df2 --- /dev/null +++ b/idf_component.yml @@ -0,0 +1,16 @@ +## IDF Component Manager Manifest File +dependencies: + espressif/esp_hosted: + version: "*" + rules: + - if: "target in [esp32p4]" + espressif/esp_wifi_remote: + version: "*" + rules: + - if: "target in [esp32p4]" + + ## Required IDF version + idf: + version: ">=5.3.0" + rules: + - if: "target in [esp32p4]" diff --git a/src/NimBLEAdvertising.cpp b/src/NimBLEAdvertising.cpp index 9c21634..0ac09d7 100644 --- a/src/NimBLEAdvertising.cpp +++ b/src/NimBLEAdvertising.cpp @@ -56,7 +56,9 @@ void NimBLEAdvertising::reset() { m_advData.name = (uint8_t *)name; m_advData.name_len = strlen(name); m_advData.name_is_complete = 1; +#ifndef CONFIG_IDF_TARGET_ESP32P4 m_advData.tx_pwr_lvl = NimBLEDevice::getPower(); +#endif m_advData.flags = (BLE_HS_ADV_F_DISC_GEN | BLE_HS_ADV_F_BREDR_UNSUP); #if !defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL) @@ -1018,7 +1020,9 @@ void NimBLEAdvertisementData::addTxPower() { char cdata[3]; cdata[0] = BLE_HS_ADV_TX_PWR_LVL_LEN + 1; cdata[1] = BLE_HS_ADV_TYPE_TX_PWR_LVL; +#ifndef CONFIG_IDF_TARGET_ESP32P4 cdata[2] = NimBLEDevice::getPower(); +#endif addData(cdata, 3); } // addTxPower diff --git a/src/NimBLEDevice.cpp b/src/NimBLEDevice.cpp index 00ff8f4..f6d7019 100644 --- a/src/NimBLEDevice.cpp +++ b/src/NimBLEDevice.cpp @@ -20,7 +20,9 @@ #ifdef ESP_PLATFORM # include "esp_err.h" +#ifndef CONFIG_IDF_TARGET_ESP32P4 # include "esp_bt.h" +#endif # include "nvs_flash.h" # if defined(CONFIG_NIMBLE_CPP_IDF) # if (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) || CONFIG_BT_NIMBLE_LEGACY_VHCI_ENABLE) @@ -360,6 +362,7 @@ NimBLEClient* NimBLEDevice::getDisconnectedClient() { #endif // #if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL) #ifdef ESP_PLATFORM +#ifndef CONFIG_IDF_TARGET_ESP32P4 /** * @brief Set the transmission power. * @param [in] powerLevel The power level to set, can be one of: @@ -438,7 +441,7 @@ int NimBLEDevice::getPower(esp_ble_power_type_t powerType) { return BLE_HS_ADV_TX_PWR_LVL_AUTO; } } // getPower - +#endif #else void NimBLEDevice::setPower(int dbm) { diff --git a/src/NimBLEDevice.h b/src/NimBLEDevice.h index 121df58..b9dce8d 100644 --- a/src/NimBLEDevice.h +++ b/src/NimBLEDevice.h @@ -42,8 +42,10 @@ class NimBLEClient; #include "NimBLEAddress.h" #ifdef ESP_PLATFORM +#ifndef CONFIG_IDF_TARGET_ESP32P4 # include "esp_bt.h" #endif +#endif #include #include @@ -116,8 +118,10 @@ public: #endif #ifdef ESP_PLATFORM +#ifndef CONFIG_IDF_TARGET_ESP32P4 static void setPower(esp_power_level_t powerLevel, esp_ble_power_type_t powerType=ESP_BLE_PWR_TYPE_DEFAULT); static int getPower(esp_ble_power_type_t powerType=ESP_BLE_PWR_TYPE_DEFAULT); +#endif static void setOwnAddrType(uint8_t own_addr_type, bool useNRPA=false); static void setScanDuplicateCacheSize(uint16_t cacheSize); static void setScanFilterMode(uint8_t type);