nrf_to_nrf - NRF52 Radio Driver v1.2.2
TMRh20 2023 - OSI Layer 2 radio driver using RF24 API
|
Driver class for nRF52840 2.4GHz Wireless Transceiver. More...
#include <nrf_to_nrf.h>
Public Member Functions | |
Primary public interface | |
These are the main methods you need to operate the chip | |
nrf_to_nrf () | |
bool | begin () |
bool | available () |
bool | available (uint8_t *pipe_num) |
void | read (void *buf, uint8_t len) |
bool | write (void *buf, uint8_t len, bool multicast=false, bool doEncryption=true) |
void | startListening (bool resetAddresses=true) |
void | stopListening (bool setWritingPipe=true, bool resetAddresses=true) |
void | openReadingPipe (uint8_t child, const uint8_t *address) |
void | openWritingPipe (const uint8_t *address) |
bool | isChipConnected () |
Advanced Operation | |
Methods you can use to drive the chip in more advanced ways | |
uint8_t | radioData [ACTUAL_MAX_PAYLOAD_SIZE+2] |
bool | failureDetected |
bool | writeFast (void *buf, uint8_t len, bool multicast=0) |
bool | startWrite (void *buf, uint8_t len, bool multicast, bool doEncryption=true) |
bool | writeAckPayload (uint8_t pipe, void *buf, uint8_t len) |
void | enableAckPayload () |
void | disableAckPayload () |
void | enableDynamicAck () |
uint8_t | getDynamicPayloadSize () |
bool | isValid () |
void | setChannel (uint8_t channel) |
uint8_t | getChannel () |
bool | setDataRate (uint8_t speed) |
void | setPALevel (uint8_t level, bool lnaEnable=true) |
uint8_t | getPALevel () |
void | setAutoAck (bool enable) |
void | setAutoAck (uint8_t pipe, bool enable) |
void | enableDynamicPayloads (uint8_t payloadSize=DEFAULT_MAX_PAYLOAD_SIZE) |
void | disableDynamicPayloads () |
void | setPayloadSize (uint8_t size) |
uint8_t | getPayloadSize () |
void | setCRCLength (nrf_crclength_e length) |
nrf_crclength_e | getCRCLength () |
void | disableCRC () |
void | setRetries (uint8_t retryVar, uint8_t attempts) |
void | openReadingPipe (uint8_t child, uint64_t address) |
void | openWritingPipe (uint64_t address) |
void | setAddressWidth (uint8_t a_width) |
void | printDetails () |
void | powerUp () |
void | powerDown () |
bool | txStandBy () |
bool | txStandBy (uint32_t timeout, bool startTx=0) |
bool | testCarrier (uint8_t RSSI=65) |
bool | testRPD (uint8_t RSSI=65) |
uint8_t | getRSSI () |
uint8_t | getARC () |
Encryption | |
Methods you can use to enable encryption & authentication | |
uint8_t | outBuffer [MAX_PACKET_SIZE+CCM_MIC_SIZE+CCM_START_SIZE] |
bool | enableEncryption |
uint32_t | addrConv32 (uint32_t addr) |
uint8_t | encrypt (void *bufferIn, uint8_t size) |
uint8_t | decrypt (void *bufferIn, uint8_t size) |
void | setKey (uint8_t key[CCM_KEY_SIZE]) |
void | setCounter (uint64_t counter) |
void | setIV (uint8_t IV[CCM_IV_SIZE]) |
Driver class for nRF52840 2.4GHz Wireless Transceiver.
Definition at line 114 of file nrf_to_nrf.h.
nrf_to_nrf::nrf_to_nrf | ( | ) |
bool nrf_to_nrf::begin | ( | ) |
Call this before operating the radio
Definition at line 89 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::available | ( | ) |
Same as NRF24 radio.available();
Definition at line 166 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::available | ( | uint8_t * | pipe_num | ) |
Same as NRF24 radio.available();
Definition at line 174 of file nrf_to_nrf.cpp.
void nrf_to_nrf::read | ( | void * | buf, |
uint8_t | len ) |
Same as NRF24 radio.read();
Definition at line 356 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::write | ( | void * | buf, |
uint8_t | len, | ||
bool | multicast = false, | ||
bool | doEncryption = true ) |
Same as NRF24 radio.write();
Definition at line 365 of file nrf_to_nrf.cpp.
void nrf_to_nrf::startListening | ( | bool | resetAddresses = true | ) |
Same as NRF24
resetAddresses | Used internally to reset addresses |
Definition at line 691 of file nrf_to_nrf.cpp.
void nrf_to_nrf::stopListening | ( | bool | setWritingPipe = true, |
bool | resetAddresses = true ) |
Same as NRF24
setWritingPipe | Used internally |
resetAddresses | Used internally to reset addresses |
Definition at line 714 of file nrf_to_nrf.cpp.
void nrf_to_nrf::openReadingPipe | ( | uint8_t | child, |
const uint8_t * | address ) |
Same as NRF24 except the 52840 has 8 pipes
Definition at line 926 of file nrf_to_nrf.cpp.
void nrf_to_nrf::openWritingPipe | ( | const uint8_t * | address | ) |
Same as NRF24
Definition at line 968 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::isChipConnected | ( | ) |
Same as NRF24
Definition at line 1039 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::writeFast | ( | void * | buf, |
uint8_t | len, | ||
bool | multicast = 0 ) |
Not currently fully functional, calls the regular write();
Definition at line 1020 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::startWrite | ( | void * | buf, |
uint8_t | len, | ||
bool | multicast, | ||
bool | doEncryption = true ) |
Writes a payload to the radio without waiting for completion.
This function will not wait for the radio to finish transmitting or for an ACK
Call txStandBy() to take the radio out of TX state or call startListening() to go into RX mode
Definition at line 550 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::writeAckPayload | ( | uint8_t | pipe, |
void * | buf, | ||
uint8_t | len ) |
Same as NRF24
Definition at line 640 of file nrf_to_nrf.cpp.
void nrf_to_nrf::enableAckPayload | ( | ) |
Same as NRF24
Definition at line 683 of file nrf_to_nrf.cpp.
void nrf_to_nrf::disableAckPayload | ( | ) |
Same as NRF24
Definition at line 687 of file nrf_to_nrf.cpp.
void nrf_to_nrf::enableDynamicAck | ( | ) |
Same as NRF24
uint8_t nrf_to_nrf::getDynamicPayloadSize | ( | ) |
Same as NRF24
Definition at line 743 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::isValid | ( | ) |
Same as NRF24
Definition at line 751 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setChannel | ( | uint8_t | channel | ) |
Same as NRF24
Definition at line 765 of file nrf_to_nrf.cpp.
uint8_t nrf_to_nrf::getChannel | ( | ) |
Same as NRF24
Definition at line 769 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::setDataRate | ( | uint8_t | speed | ) |
Supported speeds: NRF_250KBPS NRF_1MBPS NRF_2MBPS
Definition at line 1043 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setPALevel | ( | uint8_t | level, |
bool | lnaEnable = true ) |
Same as NRF24 except there is no LNA and the PA levels are as follows:
(0) represents -12dBm (1) represents 2dBm (2) represents 6dBm (3) represents 8dBm
Definition at line 1064 of file nrf_to_nrf.cpp.
uint8_t nrf_to_nrf::getPALevel | ( | ) |
Same as NRF24
Definition at line 1086 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setAutoAck | ( | bool | enable | ) |
Same as NRF24
Definition at line 773 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setAutoAck | ( | uint8_t | pipe, |
bool | enable ) |
Definition at line 786 of file nrf_to_nrf.cpp.
void nrf_to_nrf::enableDynamicPayloads | ( | uint8_t | payloadSize = DEFAULT_MAX_PAYLOAD_SIZE | ) |
Once this function has been called, users need to call disableDynamicPayloads if they want to call it again, else it has no effect.
radio.begin()
then radio.enableDynamicPayloads(123);
before initializing the network. This will enable maximum payload sizes and fragmentation/reassembly won't engage until this length is exceeded. payloadSize | Set the maximum payload size. Up to 125 with DPL enabled & CRC disabled or 123 with 16-bit CRC & DPL enabled |
Definition at line 797 of file nrf_to_nrf.cpp.
void nrf_to_nrf::disableDynamicPayloads | ( | ) |
Same as NRF24
Definition at line 817 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setPayloadSize | ( | uint8_t | size | ) |
NRF52840 will handle up to 127 byte payloads with CRC & DPL disabled, 125 with 16-bit CRC and DPL disabled
Definition at line 832 of file nrf_to_nrf.cpp.
uint8_t nrf_to_nrf::getPayloadSize | ( | ) |
Same as NRF24
Definition at line 848 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setCRCLength | ( | nrf_crclength_e | length | ) |
Same as NRF24
Definition at line 1117 of file nrf_to_nrf.cpp.
nrf_crclength_e nrf_to_nrf::getCRCLength | ( | ) |
Same as NRF24
Definition at line 1139 of file nrf_to_nrf.cpp.
void nrf_to_nrf::disableCRC | ( | ) |
Same as NRF24
void nrf_to_nrf::setRetries | ( | uint8_t | retryVar, |
uint8_t | attempts ) |
Same as NRF24
Definition at line 855 of file nrf_to_nrf.cpp.
void nrf_to_nrf::openReadingPipe | ( | uint8_t | child, |
uint64_t | address ) |
Same as NRF24
Definition at line 864 of file nrf_to_nrf.cpp.
void nrf_to_nrf::openWritingPipe | ( | uint64_t | address | ) |
Same as NRF24
Definition at line 905 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setAddressWidth | ( | uint8_t | a_width | ) |
Same as NRF24
Definition at line 1220 of file nrf_to_nrf.cpp.
void nrf_to_nrf::printDetails | ( | ) |
Same as NRF24
Definition at line 1235 of file nrf_to_nrf.cpp.
void nrf_to_nrf::powerUp | ( | ) |
When powering up from powerdown ALL radio settings will need to be re-applied
Enables the Radio & HF Clock
If encryption is enabled, also enables RNG & CCM peripherals
Definition at line 1187 of file nrf_to_nrf.cpp.
void nrf_to_nrf::powerDown | ( | ) |
When called ALL radio settings will be reverted to default
Disables the Radio & HF Clock
If encryption is enabled, also disables RNG & CCM peripherals
Definition at line 1208 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::txStandBy | ( | ) |
Takes the radio out of TX state.
Can be called after any type of write to put the radio into a disabled state
Definition at line 988 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::txStandBy | ( | uint32_t | timeout, |
bool | startTx = 0 ) |
Takes the radio out of TX state
Can be called after any type of write to put the radio into a disabled state
Definition at line 1004 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::testCarrier | ( | uint8_t | RSSI = 65 | ) |
Similar to NRF24, but can be modified to look for signals better than specified RSSI value
RSSI | The function will return 1 if a value better than -65dBm by default |
Definition at line 1154 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::testRPD | ( | uint8_t | RSSI = 65 | ) |
Similar to NRF24, but can be modified to look for signals better than specified RSSI value
RSSI | The function will return 1 if a value better than -65dBm by default |
Definition at line 1169 of file nrf_to_nrf.cpp.
uint8_t nrf_to_nrf::getRSSI | ( | ) |
A new function specific to the NRF52x devices, not available on NRF24
Definition at line 1176 of file nrf_to_nrf.cpp.
uint8_t nrf_to_nrf::getARC | ( | ) |
Same as NRF24
Definition at line 1110 of file nrf_to_nrf.cpp.
uint32_t nrf_to_nrf::addrConv32 | ( | uint32_t | addr | ) |
Used internally to convert addresses
Definition at line 48 of file nrf_to_nrf.cpp.
uint8_t nrf_to_nrf::encrypt | ( | void * | bufferIn, |
uint8_t | size ) |
Function to encrypt data
Called automatically when a write is performed
Definition at line 1329 of file nrf_to_nrf.cpp.
uint8_t nrf_to_nrf::decrypt | ( | void * | bufferIn, |
uint8_t | size ) |
Function to decrypt data
Called automatically when incoming data is received
Definition at line 1362 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setKey | ( | uint8_t | key[CCM_KEY_SIZE] | ) |
Set our 16-byte (128-bit) encryption key
Definition at line 1401 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setCounter | ( | uint64_t | counter | ) |
Set the (default 3-byte) packet counter used for encryption
Definition at line 1417 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setIV | ( | uint8_t | IV[CCM_IV_SIZE] | ) |
Set IV for encryption. This is only used for manual encryption, a random IV is generated using the on-board RNG for encryption during normal operation.
Definition at line 1425 of file nrf_to_nrf.cpp.
uint8_t nrf_to_nrf::radioData[ACTUAL_MAX_PAYLOAD_SIZE+2] |
Data buffer for radio data The radio can handle packets up to 127 bytes if CRC & DPL is disabled 125 bytes if using 16-bit CRC & DPL is disabled
Definition at line 204 of file nrf_to_nrf.h.
bool nrf_to_nrf::failureDetected |
Not implemented due to SOC
Definition at line 375 of file nrf_to_nrf.h.
uint8_t nrf_to_nrf::outBuffer[MAX_PACKET_SIZE+CCM_MIC_SIZE+CCM_START_SIZE] |
The data buffer where encrypted data is placed. See the datasheet p115 for the CCM data structure
Definition at line 450 of file nrf_to_nrf.h.
bool nrf_to_nrf::enableEncryption |
Enable use of the on-board AES CCM mode encryption
Cipher block chaining - message authentication code (CCM) mode is an authenticated encryption algorithm designed to provide both authentication and confidentiality during data transfer. CCM combines counter mode encryption and CBC-MAC authentication
Users need to take extra steps to prevent specific attacks, such as replay attacks, which can be prevented by transmitting a timestamp or counter value, and only accepting packets with a current timestamp/counter value, rejecting old data.
Encryption uses a 5-byte IV and 3-byte counter, the sizes of which can be configured in nrf_to_nrf.h Maximum: 8-byte IV, 4-byte counter, plus the MAC/MIC is 4-bytes
Definition at line 483 of file nrf_to_nrf.h.