From 95126e2b9e7ecc2bdc5341ad15bb1f59f68c8bfa Mon Sep 17 00:00:00 2001 From: Tobias Gunkel Date: Mon, 11 Mar 2024 02:36:24 +0100 Subject: [PATCH] Add support for 250kbps mode --- src/nrf_to_nrf.cpp | 20 ++++++++++++++++---- src/nrf_to_nrf.h | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/nrf_to_nrf.cpp b/src/nrf_to_nrf.cpp index d9ce0b3..a2767d6 100644 --- a/src/nrf_to_nrf.cpp +++ b/src/nrf_to_nrf.cpp @@ -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 @@ -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{ @@ -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; } diff --git a/src/nrf_to_nrf.h b/src/nrf_to_nrf.h index ab00abe..1edcffa 100644 --- a/src/nrf_to_nrf.h +++ b/src/nrf_to_nrf.h @@ -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