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 97 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::available | ( | ) |
Same as NRF24 radio.available();
Definition at line 172 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::available | ( | uint8_t * | pipe_num | ) |
Same as NRF24 radio.available();
Definition at line 180 of file nrf_to_nrf.cpp.
void nrf_to_nrf::read | ( | void * | buf, |
uint8_t | len ) |
Same as NRF24 radio.read();
Definition at line 363 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 372 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 714 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 737 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 944 of file nrf_to_nrf.cpp.
void nrf_to_nrf::openWritingPipe | ( | const uint8_t * | address | ) |
Same as NRF24
Definition at line 986 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::isChipConnected | ( | ) |
Same as NRF24
Definition at line 1065 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 1046 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 565 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 663 of file nrf_to_nrf.cpp.
void nrf_to_nrf::enableAckPayload | ( | ) |
Same as NRF24
Definition at line 706 of file nrf_to_nrf.cpp.
void nrf_to_nrf::disableAckPayload | ( | ) |
Same as NRF24
Definition at line 710 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 761 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::isValid | ( | ) |
Same as NRF24
Definition at line 769 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setChannel | ( | uint8_t | channel | ) |
Same as NRF24
Definition at line 783 of file nrf_to_nrf.cpp.
uint8_t nrf_to_nrf::getChannel | ( | ) |
Same as NRF24
Definition at line 787 of file nrf_to_nrf.cpp.
bool nrf_to_nrf::setDataRate | ( | uint8_t | speed | ) |
Supported speeds: NRF_1MBPS NRF_2MBPS
Definition at line 1069 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 1090 of file nrf_to_nrf.cpp.
uint8_t nrf_to_nrf::getPALevel | ( | ) |
Same as NRF24
Definition at line 1112 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setAutoAck | ( | bool | enable | ) |
Same as NRF24
Definition at line 791 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setAutoAck | ( | uint8_t | pipe, |
bool | enable ) |
Definition at line 804 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.
payloadSize | Set the maximum payload size. Up to 125 with CRC disabled or 123 with 16-bit CRC |
Definition at line 815 of file nrf_to_nrf.cpp.
void nrf_to_nrf::disableDynamicPayloads | ( | ) |
Same as NRF24
Definition at line 835 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setPayloadSize | ( | uint8_t | size | ) |
NRF52840 will handle up to 127 byte payloads with CRC disabled, 125 with 16-bit CRC
Definition at line 850 of file nrf_to_nrf.cpp.
uint8_t nrf_to_nrf::getPayloadSize | ( | ) |
Same as NRF24
Definition at line 866 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setCRCLength | ( | nrf_crclength_e | length | ) |
Same as NRF24
Definition at line 1143 of file nrf_to_nrf.cpp.
nrf_crclength_e nrf_to_nrf::getCRCLength | ( | ) |
Same as NRF24
Definition at line 1165 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 873 of file nrf_to_nrf.cpp.
void nrf_to_nrf::openReadingPipe | ( | uint8_t | child, |
uint64_t | address ) |
Same as NRF24
Definition at line 882 of file nrf_to_nrf.cpp.
void nrf_to_nrf::openWritingPipe | ( | uint64_t | address | ) |
Same as NRF24
Definition at line 923 of file nrf_to_nrf.cpp.
void nrf_to_nrf::setAddressWidth | ( | uint8_t | a_width | ) |
Same as NRF24
Definition at line 1226 of file nrf_to_nrf.cpp.
void nrf_to_nrf::printDetails | ( | ) |
Same as NRF24
Definition at line 1241 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
Definition at line 1213 of file nrf_to_nrf.cpp.
void nrf_to_nrf::powerDown | ( | ) |
When called ALL radio settings will be reverted to default
Definition at line 1220 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 1006 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 1026 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 1180 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 1195 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 1202 of file nrf_to_nrf.cpp.
uint8_t nrf_to_nrf::getARC | ( | ) |
Same as NRF24
Definition at line 1136 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
Definition at line 1335 of file nrf_to_nrf.cpp.
uint8_t nrf_to_nrf::decrypt | ( | void * | bufferIn, |
uint8_t | size ) |
Function to decrypt data
Definition at line 1367 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 1400 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 1408 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 1416 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 is disabled 125 bytes if using 16-bit CRC
Definition at line 204 of file nrf_to_nrf.h.
bool nrf_to_nrf::failureDetected |
Not implemented due to SOC
Definition at line 366 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 437 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 470 of file nrf_to_nrf.h.