Skip to content

Commit

Permalink
Add support for 250kbps mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tobigun committed Mar 11, 2024
1 parent 924dff5 commit 95126e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/nrf_to_nrf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

#include "nrf_to_nrf.h"

// 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 @@ -448,8 +454,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 @@ -1032,14 +1039,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 @@ -17,8 +17,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 95126e2

Please sign in to comment.