Skip to content

Commit

Permalink
Add support for NRF52805
Browse files Browse the repository at this point in the history
  • Loading branch information
tobigun committed Mar 11, 2024
1 parent 924dff5 commit 02968a3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
53 changes: 35 additions & 18 deletions src/nrf_to_nrf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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)
{
Expand All @@ -149,6 +165,7 @@ uint8_t nrf_to_nrf::sample_ed(void)
? 255
: val * ED_RSSISCALE); // Convert to IEEE 802.15.4 scale
}
#endif

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

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/nrf_to_nrf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -394,7 +398,9 @@ class nrf_to_nrf
*/
uint8_t getARC();

#ifdef NRF_HAS_ENERGY_DETECT
uint8_t sample_ed(void);
#endif

/**@}*/
/**
Expand Down

0 comments on commit 02968a3

Please sign in to comment.