From 7d01fa595d6fbaacf91f42fd8c958fdba8e773b9 Mon Sep 17 00:00:00 2001 From: h2zero <32826625+h2zero@users.noreply.github.com> Date: Mon, 19 Jul 2021 21:46:30 -0600 Subject: [PATCH] Fix compilation for ESP32C3. (#53) --- src/NimBLEDevice.cpp | 10 ++++++++++ src/NimBLEScan.cpp | 6 ++++-- src/nimconfig_rename.h | 14 +++++++++++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/NimBLEDevice.cpp b/src/NimBLEDevice.cpp index 6917490..bc25365 100644 --- a/src/NimBLEDevice.cpp +++ b/src/NimBLEDevice.cpp @@ -757,8 +757,12 @@ NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) { esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT); esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); +#ifdef CONFIG_IDF_TARGET_ESP32C3 + bt_cfg.bluetooth_mode = ESP_BT_MODE_BLE; +#else bt_cfg.mode = ESP_BT_MODE_BLE; bt_cfg.ble_max_conn = CONFIG_BT_NIMBLE_MAX_CONNECTIONS; +#endif bt_cfg.normal_adv_size = m_scanDuplicateSize; bt_cfg.scan_duplicate_type = m_scanFilterMode; @@ -977,17 +981,23 @@ void NimBLEDevice::setSecurityCallbacks(NimBLESecurityCallbacks* callbacks) { void NimBLEDevice::setOwnAddrType(uint8_t own_addr_type, bool useNRPA) { m_own_addr_type = own_addr_type; switch (own_addr_type) { +#ifdef CONFIG_IDF_TARGET_ESP32 case BLE_OWN_ADDR_PUBLIC: ble_hs_pvcy_rpa_config(NIMBLE_HOST_DISABLE_PRIVACY); break; +#endif case BLE_OWN_ADDR_RANDOM: setSecurityInitKey(BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID); +#ifdef CONFIG_IDF_TARGET_ESP32 ble_hs_pvcy_rpa_config(useNRPA ? NIMBLE_HOST_ENABLE_NRPA : NIMBLE_HOST_ENABLE_RPA); +#endif break; case BLE_OWN_ADDR_RPA_PUBLIC_DEFAULT: case BLE_OWN_ADDR_RPA_RANDOM_DEFAULT: setSecurityInitKey(BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID); +#ifdef CONFIG_IDF_TARGET_ESP32 ble_hs_pvcy_rpa_config(NIMBLE_HOST_ENABLE_RPA); +#endif break; } } // setOwnAddrType diff --git a/src/NimBLEScan.cpp b/src/NimBLEScan.cpp index bc08896..0370552 100644 --- a/src/NimBLEScan.cpp +++ b/src/NimBLEScan.cpp @@ -110,7 +110,7 @@ NimBLEScan::~NimBLEScan() { advertisedDevice->m_timestamp = time(nullptr); advertisedDevice->setRSSI(event->disc.rssi); - advertisedDevice->setPayload(event->disc.data, event->disc.length_data, + advertisedDevice->setPayload(event->disc.data, event->disc.length_data, event->disc.event_type == BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP); if (pScan->m_pAdvertisedDeviceCallbacks) { @@ -128,7 +128,7 @@ NimBLEScan::~NimBLEScan() { advertisedDevice->m_callbackSent = true; pScan->m_pAdvertisedDeviceCallbacks->onResult(advertisedDevice); } - // If not storing results and we have invoked the callback, delete the device. + // If not storing results and we have invoked the callback, delete the device. if(pScan->m_maxResults == 0 && advertisedDevice->m_callbackSent) { pScan->erase(advertisedAddress); } @@ -404,7 +404,9 @@ bool NimBLEScan::stop() { * @brief Clears the duplicate scan filter cache. */ void NimBLEScan::clearDuplicateCache() { +#ifdef CONFIG_IDF_TARGET_ESP32 // Not available for ESP32C3 esp_ble_scan_dupilcate_list_flush(); +#endif } diff --git a/src/nimconfig_rename.h b/src/nimconfig_rename.h index 3b96c1f..c45aa8b 100644 --- a/src/nimconfig_rename.h +++ b/src/nimconfig_rename.h @@ -41,13 +41,21 @@ #endif #if defined(CONFIG_SCAN_DUPLICATE_TYPE) && !defined(CONFIG_BTDM_SCAN_DUPL_TYPE) -#define CONFIG_BTDM_SCAN_DUPL_TYPE CONFIG_SCAN_DUPLICATE_TYPE +#define CONFIG_BTDM_SCAN_DUPL_TYPE CONFIG_SCAN_DUPLICATE_TYPE +#endif + +#if defined(CONFIG_BT_CTRL_SCAN_DUPL_TYPE) && !defined(CONFIG_BTDM_SCAN_DUPL_TYPE) +#define CONFIG_BTDM_SCAN_DUPL_TYPE CONFIG_BT_CTRL_SCAN_DUPL_TYPE #endif #if defined(CONFIG_DUPLICATE_SCAN_CACHE_SIZE) && !defined(CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE) -#define CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE CONFIG_DUPLICATE_SCAN_CACHE_SIZE +#define CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE CONFIG_DUPLICATE_SCAN_CACHE_SIZE +#endif + +#if defined(CONFIG_BT_CTRL_SCAN_DUPL_CACHE_SIZE) && !defined(CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE) +#define CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE CONFIG_BT_CTRL_SCAN_DUPL_CACHE_SIZE #endif #if defined(CONFIG_NIMBLE_MAX_CONNECTIONS ) && !defined(CONFIG_BT_NIMBLE_MAX_CONNECTIONS) -#define CONFIG_BT_NIMBLE_MAX_CONNECTIONS CONFIG_NIMBLE_MAX_CONNECTIONS +#define CONFIG_BT_NIMBLE_MAX_CONNECTIONS CONFIG_NIMBLE_MAX_CONNECTIONS #endif