nrf_to_nrf - NRF52 Radio Driver v1.2.2
TMRh20 2023 - OSI Layer 2 radio driver using RF24 API
Loading...
Searching...
No Matches
nrf_to_nrf.h
Go to the documentation of this file.
1
7#ifndef __nrf52840_nrf24l01_H__
8#define __nrf52840_nrf24l01_H__
9#include <Arduino.h>
10#if defined(USE_TINYUSB)
11 // Needed for Serial.print on non-MBED enabled or adafruit-based nRF52 cores
12 #include "Adafruit_TinyUSB.h"
13#endif
14
15#if defined(NRF52811_XXAA) || defined(NRF52820_XXAA) || defined(NRF52833_XXAA) || defined(NRF52840_XXAA)
16 #define NRF_HAS_ENERGY_DETECT
17#endif
18
19#define NRF52_RADIO_LIBRARY
20#define DEFAULT_MAX_PAYLOAD_SIZE 32
21#define ACTUAL_MAX_PAYLOAD_SIZE 127
22#define ACK_TIMEOUT_1MBPS 600 // 300 with static payloads
23#define ACK_TIMEOUT_2MBPS 400 // 265 with static payloads
24#define ACK_TIMEOUT_250KBPS 800 // 500 with staticPayloads
25#define ACK_TIMEOUT_1MBPS_OFFSET 300
26#define ACK_TIMEOUT_2MBPS_OFFSET 135
27#define ACK_TIMEOUT_250KBPS_OFFSET 300
28#define ACK_PAYLOAD_TIMEOUT_OFFSET 750
29
30// AES CCM ENCRYPTION
31#if defined NRF_CCM || defined(DOXYGEN)
32 #define CCM_ENCRYPTION_ENABLED
33#endif
34#if defined CCM_ENCRYPTION_ENABLED || defined(DOXYGEN)
35 #define MAX_PACKET_SIZE ACTUAL_MAX_PAYLOAD_SIZE // Max Payload Size
36 #define CCM_KEY_SIZE 16
37 #define CCM_IV_SIZE 5
38 #define CCM_IV_SIZE_ACTUAL 8
39 #define CCM_COUNTER_SIZE 3
40 #define CCM_MIC_SIZE 4
41 #define CCM_START_SIZE 3
42 #define CCM_MODE_LENGTH_EXTENDED 16
43#endif
44
68
87
108
115{
116
117public:
132 nrf_to_nrf();
133
140 bool begin();
141
145 bool available();
146
150 bool available(uint8_t* pipe_num);
151
155 void read(void* buf, uint8_t len);
156
160 bool write(void* buf, uint8_t len, bool multicast = false, bool doEncryption = true);
161
166 void startListening(bool resetAddresses = true);
167
173 void stopListening(bool setWritingPipe = true, bool resetAddresses = true);
174
178 void openReadingPipe(uint8_t child, const uint8_t* address);
179
183 void openWritingPipe(const uint8_t* address);
184
188 bool isChipConnected();
189
205
209 bool writeFast(void* buf, uint8_t len, bool multicast = 0);
210
219 bool startWrite(void* buf, uint8_t len, bool multicast, bool doEncryption = true);
220
224 bool writeAckPayload(uint8_t pipe, void* buf, uint8_t len);
225
229 void enableAckPayload();
230
234 void disableAckPayload();
235
240
244 uint8_t getDynamicPayloadSize();
245
249 bool isValid();
250
254 void setChannel(uint8_t channel);
255
259 uint8_t getChannel();
260
264 bool setDataRate(uint8_t speed);
265
274 void setPALevel(uint8_t level, bool lnaEnable = true);
275
279 uint8_t getPALevel();
280
284 void setAutoAck(bool enable);
285
289 void setAutoAck(uint8_t pipe, bool enable);
290
296 void enableDynamicPayloads(uint8_t payloadSize = DEFAULT_MAX_PAYLOAD_SIZE);
297
302
306 void setPayloadSize(uint8_t size);
307
311 uint8_t getPayloadSize();
312
316 void setCRCLength(nrf_crclength_e length);
317
322
327
331 void setRetries(uint8_t retryVar, uint8_t attempts);
332
336 void openReadingPipe(uint8_t child, uint64_t address);
337
341 void openWritingPipe(uint64_t address);
342
346 void setAddressWidth(uint8_t a_width);
347
351 void printDetails();
352
356 void powerUp();
357
361 void powerDown();
362
367
373 bool txStandBy();
374
380 bool txStandBy(uint32_t timeout, bool startTx = 0);
381
386 bool testCarrier(uint8_t RSSI = 65);
387
392 bool testRPD(uint8_t RSSI = 65);
393
399 uint8_t getRSSI();
400
404 uint8_t getARC();
405
406#ifdef NRF_HAS_ENERGY_DETECT
407 uint8_t sample_ed(void);
408#endif
409
421 uint32_t addrConv32(uint32_t addr);
422#if defined CCM_ENCRYPTION_ENABLED || defined(DOXYGEN)
423
427 uint8_t encrypt(void* bufferIn, uint8_t size);
428
432 uint8_t decrypt(void* bufferIn, uint8_t size);
433
438
442 void setKey(uint8_t key[CCM_KEY_SIZE]);
443
447 void setCounter(uint64_t counter);
448
454 void setIV(uint8_t IV[CCM_IV_SIZE]);
455
472#endif
473
474private:
475 bool acksEnabled(uint8_t pipe);
476 bool acksPerPipe[8];
477 uint8_t retries;
478 uint8_t retryDuration;
479 uint8_t rxBuffer[ACTUAL_MAX_PAYLOAD_SIZE + 1];
480 uint8_t ackBuffer[ACTUAL_MAX_PAYLOAD_SIZE + 1];
481 uint8_t rxFifoAvailable;
482 bool DPL;
483 bool ackPayloadsEnabled;
484 bool inRxMode;
485 uint8_t staticPayloadSize;
486 uint8_t ackPID;
487 uint8_t ackPipe;
488 bool lastTxResult;
489 bool overWrite;
490 uint32_t rxBase;
491 uint32_t rxPrefix;
492 uint32_t txBase;
493 uint32_t txPrefix;
494 bool ackPayloadAvailable;
495 uint8_t ackAvailablePipeNo;
496 uint8_t lastPacketCounter;
497 uint16_t lastData;
498 bool dynamicAckEnabled;
499 uint8_t ARC;
500 uint8_t addressWidth;
501 uint16_t ackTimeout;
502 bool payloadAvailable;
503#if defined CCM_ENCRYPTION_ENABLED
504 uint8_t inBuffer[MAX_PACKET_SIZE + CCM_MIC_SIZE + CCM_START_SIZE];
505 uint8_t scratchPTR[MAX_PACKET_SIZE + CCM_MODE_LENGTH_EXTENDED];
506 typedef struct
507 {
508 uint8_t key[CCM_KEY_SIZE];
509 uint64_t counter;
510 uint8_t direction;
511 uint8_t iv[CCM_IV_SIZE_ACTUAL];
512 } ccmData_t;
513 ccmData_t ccmData;
514 uint32_t packetCounter;
515#endif
516};
517
577#endif //__nrf52840_nrf24l01_H__
Driver class for nRF52840 2.4GHz Wireless Transceiver.
Definition nrf_to_nrf.h:115
void startListening(bool resetAddresses=true)
void openReadingPipe(uint8_t child, const uint8_t *address)
bool available()
void setPALevel(uint8_t level, bool lnaEnable=true)
bool testCarrier(uint8_t RSSI=65)
bool txStandBy()
uint8_t decrypt(void *bufferIn, uint8_t size)
uint8_t radioData[ACTUAL_MAX_PAYLOAD_SIZE+2]
Definition nrf_to_nrf.h:204
void setChannel(uint8_t channel)
uint32_t addrConv32(uint32_t addr)
void disableDynamicPayloads()
bool write(void *buf, uint8_t len, bool multicast=false, bool doEncryption=true)
bool testRPD(uint8_t RSSI=65)
void setCounter(uint64_t counter)
bool isChipConnected()
void setAddressWidth(uint8_t a_width)
uint8_t getDynamicPayloadSize()
bool setDataRate(uint8_t speed)
bool isValid()
void enableDynamicAck()
void setKey(uint8_t key[CCM_KEY_SIZE])
bool begin()
bool writeAckPayload(uint8_t pipe, void *buf, uint8_t len)
bool enableEncryption
Definition nrf_to_nrf.h:470
void enableDynamicPayloads(uint8_t payloadSize=DEFAULT_MAX_PAYLOAD_SIZE)
void disableAckPayload()
void disableCRC()
void powerDown()
uint8_t getARC()
uint8_t encrypt(void *bufferIn, uint8_t size)
void printDetails()
uint8_t getChannel()
bool startWrite(void *buf, uint8_t len, bool multicast, bool doEncryption=true)
uint8_t getRSSI()
uint8_t outBuffer[MAX_PACKET_SIZE+CCM_MIC_SIZE+CCM_START_SIZE]
Definition nrf_to_nrf.h:437
void setRetries(uint8_t retryVar, uint8_t attempts)
void enableAckPayload()
void openWritingPipe(const uint8_t *address)
void setCRCLength(nrf_crclength_e length)
bool failureDetected
Definition nrf_to_nrf.h:366
bool writeFast(void *buf, uint8_t len, bool multicast=0)
uint8_t getPALevel()
void setAutoAck(bool enable)
void read(void *buf, uint8_t len)
void stopListening(bool setWritingPipe=true, bool resetAddresses=true)
void setIV(uint8_t IV[CCM_IV_SIZE])
void setPayloadSize(uint8_t size)
nrf_crclength_e getCRCLength()
uint8_t getPayloadSize()
#define CCM_MODE_LENGTH_EXTENDED
Definition nrf_to_nrf.h:42
#define DEFAULT_MAX_PAYLOAD_SIZE
Definition nrf_to_nrf.h:20
nrf_pa_dbm_e
Definition nrf_to_nrf.h:46
@ NRF_PA_MAX
Definition nrf_to_nrf.h:62
@ NRF_PA_HIGH
Definition nrf_to_nrf.h:58
@ NRF_PA_LOW
Definition nrf_to_nrf.h:54
@ NRF_PA_MIN
Definition nrf_to_nrf.h:50
@ NRF_PA_ERROR
Definition nrf_to_nrf.h:66
nrf_crclength_e
Definition nrf_to_nrf.h:100
@ NRF_CRC_8
Definition nrf_to_nrf.h:104
@ NRF_CRC_DISABLED
Definition nrf_to_nrf.h:102
@ NRF_CRC_16
Definition nrf_to_nrf.h:106
#define CCM_IV_SIZE_ACTUAL
Definition nrf_to_nrf.h:38
nrf_datarate_e
Definition nrf_to_nrf.h:79
@ NRF_1MBPS
Definition nrf_to_nrf.h:81
@ NRF_2MBPS
Definition nrf_to_nrf.h:83
@ NRF_250KBPS
Definition nrf_to_nrf.h:85
#define CCM_START_SIZE
Definition nrf_to_nrf.h:41
#define ACTUAL_MAX_PAYLOAD_SIZE
Definition nrf_to_nrf.h:21
#define MAX_PACKET_SIZE
Definition nrf_to_nrf.h:35
#define CCM_MIC_SIZE
Definition nrf_to_nrf.h:40
#define CCM_KEY_SIZE
Definition nrf_to_nrf.h:36
#define CCM_IV_SIZE
Definition nrf_to_nrf.h:37