Skip to content

Commit

Permalink
Merge pull request #16 from tobigun/add-support-for-nrf52805
Browse files Browse the repository at this point in the history
Add support for nRF52805
  • Loading branch information
TMRh20 authored Mar 12, 2024
2 parents 6dbb3b1 + 659356e commit bd77971
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
52 changes: 34 additions & 18 deletions src/nrf_to_nrf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

#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

// 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
Expand Down Expand Up @@ -131,7 +145,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 @@ -141,6 +155,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 @@ -155,6 +170,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 @@ -1062,17 +1078,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 @@ -1084,20 +1100,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 @@ -396,7 +400,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 bd77971

Please sign in to comment.