Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE: Supports setting PHY for extended range #223

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion libraries/Bluefruit52Lib/src/bluefruit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ err_t AdafruitBluefruit::begin(uint8_t prph_count, uint8_t central_count)
.accuracy = NRF_CLOCK_LF_ACCURACY_20_PPM
};
#elif defined( USE_LFRC )
nrf_clock_lf_cfg_t clock_cfg =
nrf_clock_lf_cfg_t clock_cfg =
{
// LXRC
.source = NRF_CLOCK_LF_SRC_RC,
Expand Down Expand Up @@ -538,6 +538,41 @@ uint16_t AdafruitBluefruit::getApperance(void)
return appear;
}

bool AdafruitBluefruit::setPhy(int8_t phy)
{
#if defined(NRF52832_XXAA)
int8_t const accepted[] = { BLE_GAP_PHY_AUTO, BLE_GAP_PHY_1MBPS, BLE_GAP_PHY_2MBPS };
#elif defined( NRF52840_XXAA)
int8_t const accepted[] = { BLE_GAP_PHY_AUTO, BLE_GAP_PHY_1MBPS, BLE_GAP_PHY_2MBPS,
BLE_GAP_PHY_CODED };
#endif

// Check if phy is valid value
uint32_t i;
for (i=0; i<sizeof(accepted); i++)
{
if (accepted[i] == phy) break;
}
VERIFY(i < sizeof(accepted));

// Apply if connected
ble_gap_phys_t phys;
phys.tx_phys = phy;
phys.rx_phys = phy;
if ( _conn_hdl != BLE_CONN_HANDLE_INVALID )
{
VERIFY_STATUS( sd_ble_gap_phy_update(_conn_hdl, &phys), false );
}
_phy = phy;

return true;
}

int8_t AdafruitBluefruit::getPhy(void)
{
return _phy;
}

/*------------------------------------------------------------------*/
/* GAP, Connections and Bonding
*------------------------------------------------------------------*/
Expand Down
4 changes: 4 additions & 0 deletions libraries/Bluefruit52Lib/src/bluefruit.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ class AdafruitBluefruit
void autoConnLed (bool enabled);
void setConnLedInterval (uint32_t ms);

bool setPhy (int8_t phy);
int8_t getPhy (void);

/*------------------------------------------------------------------*/
/* GAP, Connections and Bonding
*------------------------------------------------------------------*/
Expand Down Expand Up @@ -217,6 +220,7 @@ class AdafruitBluefruit
TimerHandle_t _led_blink_th;
bool _led_conn;

int8_t _phy;
BLEDfu _dfu_svc;

uint16_t _conn_hdl;
Expand Down