Skip to content

Commit

Permalink
Merge branch 'main' into add-support-for-nrf52805
Browse files Browse the repository at this point in the history
  • Loading branch information
TMRh20 authored Mar 12, 2024
2 parents 02968a3 + 6dbb3b1 commit 659356e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/nrf_to_nrf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "nrf_to_nrf.h"


#if defined (NRF52832_XXAA) || defined (NRF52832_XXAB) || defined (NRF52811_XXAA) || defined (NRF52810_XXAA) || defined (NRF52805_XXAA)
// TX power range (Product Specification): -20 .. +4dbm, configurable in 4 dB steps
#define TXPOWER_PA_MIN 0xF4 // -12dBm
Expand All @@ -17,6 +16,12 @@
#define TXPOWER_PA_MAX 0x08 // 8dBm
#endif

// Note that 250Kbit mode is deprecated and might not work reliably on all devices.
// See: https://devzone.nordicsemi.com/f/nordic-q-a/78469/250-kbit-s-nordic-proprietary-radio-mode-on-nrf52840
#ifndef RADIO_MODE_MODE_Nrf_250Kbit
#define RADIO_MODE_MODE_Nrf_250Kbit (2UL)
#endif

/**********************************************************************************************************/

// Function to do bytewise bit-swap on an unsigned 32-bit value
Expand Down Expand Up @@ -105,10 +110,10 @@ bool nrf_to_nrf::begin()
// Do nothing.
}

NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
NRF_CLOCK->TASKS_LFCLKSTART = 1;

/* Wait for the low frequency clock to start up */
while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) {
// Do nothing.
}
Expand Down Expand Up @@ -465,8 +470,9 @@ bool nrf_to_nrf::write(void* buf, uint8_t len, bool multicast, bool doEncryption
if (!DPL) {
if (NRF_RADIO->MODE == (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos)) {
realAckTimeout -= ACK_TIMEOUT_1MBPS_OFFSET;
}
else {
} else if (NRF_RADIO->MODE == (RADIO_MODE_MODE_Nrf_250Kbit << RADIO_MODE_MODE_Pos)) {
realAckTimeout -= ACK_TIMEOUT_250KBPS_OFFSET;
} else {
realAckTimeout -= ACK_TIMEOUT_2MBPS_OFFSET;
}
}else{
Expand Down Expand Up @@ -1049,14 +1055,19 @@ bool nrf_to_nrf::isChipConnected() { return isValid(); }
bool nrf_to_nrf::setDataRate(uint8_t speed)
{

if (!speed) {
if (speed == NRF_1MBPS) {
NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos);
ackTimeout = ACK_TIMEOUT_1MBPS;
}
else {
else if (speed == NRF_250KBPS) {
NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_250Kbit << RADIO_MODE_MODE_Pos);
ackTimeout = ACK_TIMEOUT_250KBPS;
}
else { // NRF_2MBPS
NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_2Mbit << RADIO_MODE_MODE_Pos);
ackTimeout = ACK_TIMEOUT_2MBPS;
}

return 1;
}

Expand Down
2 changes: 2 additions & 0 deletions src/nrf_to_nrf.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
#define ACTUAL_MAX_PAYLOAD_SIZE 127
#define ACK_TIMEOUT_1MBPS 500 // 200 with static payloads
#define ACK_TIMEOUT_2MBPS 300 // 165 with static payloads
#define ACK_TIMEOUT_250KBPS 500
#define ACK_TIMEOUT_1MBPS_OFFSET 300
#define ACK_TIMEOUT_2MBPS_OFFSET 135
#define ACK_TIMEOUT_250KBPS_OFFSET 300
#define ACK_PAYLOAD_TIMEOUT_OFFSET 750

// AES CCM ENCRYPTION
Expand Down

0 comments on commit 659356e

Please sign in to comment.