From 02968a3402d6a7f2469261c5480cc3436459ec9d Mon Sep 17 00:00:00 2001 From: Tobias Gunkel Date: Mon, 11 Mar 2024 02:14:40 +0100 Subject: [PATCH] Add support for NRF52805 --- src/nrf_to_nrf.cpp | 53 ++++++++++++++++++++++++++++++---------------- src/nrf_to_nrf.h | 6 ++++++ 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/nrf_to_nrf.cpp b/src/nrf_to_nrf.cpp index d9ce0b3..d42a8fc 100644 --- a/src/nrf_to_nrf.cpp +++ b/src/nrf_to_nrf.cpp @@ -2,6 +2,21 @@ #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 +#define TXPOWER_PA_LOW 0xFC // -4dBm +#define TXPOWER_PA_HIGH 0x00 // 0dBm +#define TXPOWER_PA_MAX 0x04 // 4dBm +#else // nRF52840, nRF52833, nRF52820 +// TX power range (Product Specification): -20 .. +8dbm, configurable in 4 dB steps +#define TXPOWER_PA_MIN 0xF4 // -12dBm +#define TXPOWER_PA_LOW 0x02 // 2dBm +#define TXPOWER_PA_HIGH 0x06 // 6dBm +#define TXPOWER_PA_MAX 0x08 // 8dBm +#endif + /**********************************************************************************************************/ // Function to do bytewise bit-swap on an unsigned 32-bit value @@ -125,7 +140,7 @@ bool nrf_to_nrf::begin() NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos); NRF_RADIO->MODECNF0 = 0x200; NRF_RADIO->MODECNF0 |= 1; - NRF_RADIO->TXPOWER = (0x8 << RADIO_TXPOWER_TXPOWER_Pos); + NRF_RADIO->TXPOWER = (TXPOWER_PA_MAX << RADIO_TXPOWER_TXPOWER_Pos); NRF_RADIO->SHORTS = 1 << 19; NRF_RADIO->FREQUENCY = 0x4C; @@ -135,6 +150,7 @@ bool nrf_to_nrf::begin() /**********************************************************************************************************/ +#ifdef NRF_HAS_ENERGY_DETECT #define ED_RSSISCALE 4 // From electrical specifications uint8_t nrf_to_nrf::sample_ed(void) { @@ -149,6 +165,7 @@ uint8_t nrf_to_nrf::sample_ed(void) ? 255 : val * ED_RSSISCALE); // Convert to IEEE 802.15.4 scale } +#endif /**********************************************************************************************************/ @@ -1050,17 +1067,17 @@ void nrf_to_nrf::setPALevel(uint8_t level, bool lnaEnable) uint8_t paLevel = 0x00; - if (level == 0) { - paLevel = 0xF4; + if (level == NRF_PA_MIN) { + paLevel = TXPOWER_PA_MIN; } - else if (level == 1) { - paLevel = 0x2; + else if (level == NRF_PA_LOW) { + paLevel = TXPOWER_PA_LOW; } - else if (level == 2) { - paLevel = 0x6; + else if (level == NRF_PA_HIGH) { + paLevel = TXPOWER_PA_HIGH; } - else if (level == 3) { - paLevel = 0x8; + else if (level == NRF_PA_MAX) { + paLevel = TXPOWER_PA_MAX; } NRF_RADIO->TXPOWER = paLevel; } @@ -1072,20 +1089,20 @@ uint8_t nrf_to_nrf::getPALevel() uint8_t paLevel = NRF_RADIO->TXPOWER; - if (paLevel == 0xF4) { - return 0; + if (paLevel == TXPOWER_PA_MIN) { + return NRF_PA_MIN; } - else if (paLevel == 0x2) { - return 1; + else if (paLevel == TXPOWER_PA_LOW) { + return NRF_PA_LOW; } - else if (paLevel == 0x6) { - return 2; + else if (paLevel == TXPOWER_PA_HIGH) { + return NRF_PA_HIGH; } - else if (paLevel == 0x8) { - return 3; + else if (paLevel == TXPOWER_PA_MAX) { + return NRF_PA_MAX; } else { - return 4; + return NRF_PA_ERROR; } } diff --git a/src/nrf_to_nrf.h b/src/nrf_to_nrf.h index ab00abe..115a1a6 100644 --- a/src/nrf_to_nrf.h +++ b/src/nrf_to_nrf.h @@ -12,6 +12,10 @@ #include "Adafruit_TinyUSB.h" #endif +#if defined (NRF52811_XXAA) || defined (NRF52820_XXAA) || defined (NRF52833_XXAA) || defined (NRF52840_XXAA) +#define NRF_HAS_ENERGY_DETECT +#endif + #define NRF52_RADIO_LIBRARY #define DEFAULT_MAX_PAYLOAD_SIZE 32 #define ACTUAL_MAX_PAYLOAD_SIZE 127 @@ -394,7 +398,9 @@ class nrf_to_nrf */ uint8_t getARC(); +#ifdef NRF_HAS_ENERGY_DETECT uint8_t sample_ed(void); +#endif /**@}*/ /**