From a7732f106b75e24ddcb921d37180e2151297d8ee Mon Sep 17 00:00:00 2001 From: rbaron Date: Wed, 3 Aug 2022 23:11:42 +0200 Subject: [PATCH] Introduces new config flag PRST_BLE_EXPERIMENTAL_LONG_RANGE This flags makes use of the Coded PHY from Bluetooth 5. It should be treated as an experimental feature and it's disabled by default. Note that clients (such as ESPHomme) would also have to scan on the Coded PHY to be able to find b-parasites operating in this mode. Currently, no client does that. Thus the feature is disabled and marked as experimental. --- code/b-parasite/config/prst_config.h | 6 +++++- code/b-parasite/src/prst/ble.c | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/code/b-parasite/config/prst_config.h b/code/b-parasite/config/prst_config.h index ad8b241..49b405e 100644 --- a/code/b-parasite/config/prst_config.h +++ b/code/b-parasite/config/prst_config.h @@ -2,7 +2,6 @@ #define _PRST_CONFIG_H_ #include "nrf_gpio.h" - // Some configurations are version-specific. Uncomment the line corresponding // the the version you're programming. The version can be found on the // b-parasite board. @@ -51,6 +50,11 @@ #define PRST_BLE_ADV_INTERVAL_IN_MS 30 // Possible values are ..., -8, -4, 0, 4, 8. #define PRST_BLE_ADV_TX_POWER 8 +// Experimental support for "long range" BLE, introduced in Bluetooth 5. It uses +// a different type of physical layer - the Coded PHY. Receivers should also +// scan using Coded PHY in order to find this device when operating in this +// mode. +#define PRST_BLE_EXPERIMENTAL_LONG_RANGE 0 // PWM. #define PRST_PWM_PIN NRF_GPIO_PIN_MAP(0, 5) diff --git a/code/b-parasite/src/prst/ble.c b/code/b-parasite/src/prst/ble.c index d4d8cde..3ac15cf 100644 --- a/code/b-parasite/src/prst/ble.c +++ b/code/b-parasite/src/prst/ble.c @@ -72,7 +72,11 @@ static ble_advdata_service_data_t advdata_service_data_ = { // Warning: do not update this while advertising. static ble_advdata_t adv_data_ = { .name_type = BLE_ADVDATA_FULL_NAME, +#if PRST_BLE_EXPERIMENTAL_LONG_RANGE + .flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE, +#else .flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED, +#endif .p_service_data_array = &advdata_service_data_, .service_data_count = 1, }; @@ -91,10 +95,16 @@ static ble_gap_addr_t gap_addr_ = {.addr_type = static void init_advertisement_data() { // We'll just broadcast our data, so we disallow connections and scan // requests. +#if PRST_BLE_EXPERIMENTAL_LONG_RANGE + adv_params_.properties.type = + BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED; + adv_params_.primary_phy = BLE_GAP_PHY_CODED; + adv_params_.secondary_phy = BLE_GAP_PHY_CODED; +#else adv_params_.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_NONSCANNABLE_UNDIRECTED; +#endif - // No particular peer - undirected advertisement. adv_params_.p_peer_addr = NULL; adv_params_.filter_policy = BLE_GAP_ADV_FP_ANY; adv_params_.interval = NON_CONNECTABLE_ADV_INTERVAL;