Optimized high speed nRF24L01+ driver class documentation  1.4.2
TMRh20 2020 - Optimized fork of the nRF24L01+ driver
RF24_config.h
Go to the documentation of this file.
1 
2 /*
3  Copyright (C)
4  2011 J. Coliz <maniacbug@ymail.com>
5  2015-2019 TMRh20
6  2015 spaniakos <spaniakos@gmail.com>
7  2015 nerdralph
8  2015 zador-blood-stained
9  2016 akatran
10  2017-2019 Avamander <avamander@gmail.com>
11  2019 IkpeohaGodson
12  2021 2bndy5
13 
14  This program is free software; you can redistribute it and/or
15  modify it under the terms of the GNU General Public License
16  version 2 as published by the Free Software Foundation.
17 */
18 
19 #ifndef __RF24_CONFIG_H__
20 #define __RF24_CONFIG_H__
21 
22 /*** USER DEFINES: ***/
23 #define FAILURE_HANDLING
24 //#define SERIAL_DEBUG
25 //#define MINIMAL
26 //#define SPI_UART // Requires library from https://github.com/TMRh20/Sketches/tree/master/SPI_UART
27 //#define SOFTSPI // Requires library from https://github.com/greiman/DigitalIO
28 
34 #if !defined(RF24_POWERUP_DELAY)
35 #define RF24_POWERUP_DELAY 5000
36 #endif
37 
38 /**********************/
39 #define rf24_max(a, b) (a>b?a:b)
40 #define rf24_min(a, b) (a<b?a:b)
41 
43 #ifndef RF24_SPI_SPEED
44 #define RF24_SPI_SPEED 10000000
45 #endif
46 
47 //ATXMega
48 #if defined (__AVR_ATxmega64D3__) || defined (__AVR_ATxmega128D3__) || defined (__AVR_ATxmega192D3__) || defined (__AVR_ATxmega256D3__) || defined (__AVR_ATxmega384D3__)
49 // In order to be available both in Windows and Linux this should take presence here.
50  #define XMEGA
51  #define XMEGA_D3
52  #include "utility/ATXMegaD3/RF24_arch_config.h"
53 
54 // RaspberryPi rp2xxx-based devices (e.g. RPi Pico board)
55 #elif defined (PICO_BUILD) && !defined (ARDUINO)
56  #include "utility/rp2/RF24_arch_config.h"
57 
58 #elif (!defined (ARDUINO)) // Any non-arduino device is handled via configure/Makefile
59  // The configure script detects device and copies the correct includes.h file to /utility/includes.h
60  // This behavior can be overridden by calling configure with respective parameters
61  // The includes.h file defines either RF24_RPi, MRAA, LITTLEWIRE or RF24_SPIDEV and includes the correct RF24_arch_config.h file
62  #include "utility/includes.h"
63 
64 //ATTiny
65 #elif defined (__AVR_ATtiny25__) || defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) || defined (__AVR_ATtiny24__) || defined (__AVR_ATtiny44__) || defined (__AVR_ATtiny84__) || defined (__AVR_ATtiny2313__) || defined (__AVR_ATtiny4313__) || defined (__AVR_ATtiny861__) || defined (__AVR_ATtinyX5__) || defined (__AVR_ATtinyX4__) || defined (__AVR_ATtinyX313__) || defined (__AVR_ATtinyX61__)
66  #define RF24_TINY
67  #include "utility/ATTiny/RF24_arch_config.h"
68 
69 #elif defined (LITTLEWIRE) //LittleWire
70  #include "utility/LittleWire/RF24_arch_config.h"
71 
72 #elif defined (TEENSYDUINO) //Teensy
73  #include "utility/Teensy/RF24_arch_config.h"
74 
75 #else //Everything else
76  #include <Arduino.h>
77 
78 
79  #if defined (ARDUINO) && !defined (__arm__) && !defined (__ARDUINO_X86__)
80  #if defined SPI_UART
81  #include <SPI_UART.h>
82  #define _SPI uspi
83  #elif defined (SOFTSPI)
84  // change these pins to your liking
85  //
86  #ifndef SOFT_SPI_MISO_PIN
87  #define SOFT_SPI_MISO_PIN 9
88  #endif // SOFT_SPI_MISO_PIN
89 
90  #ifndef SOFT_SPI_MOSI_PIN
91  #define SOFT_SPI_MOSI_PIN 8
92  #endif // SOFT_SPI_MOSI_PIN
93 
94  #ifndef SOFT_SPI_SCK_PIN
95  #define SOFT_SPI_SCK_PIN 7
96  #endif // SOFT_SPI_SCK_PIN
97 
98  const uint8_t SPI_MODE = 0;
99  #define _SPI spi
100 
101  #elif defined (ARDUINO_SAM_DUE)
102  #include <SPI.h>
103  #define _SPI SPI
104 
105  #else // !defined (SPI_UART) && !defined (SOFTSPI)
106  #include <SPI.h>
107  #define _SPI SPIClass
108  #define RF24_SPI_PTR
109  #endif // !defined (SPI_UART) && !defined (SOFTSPI)
110 
111  #else // !defined(ARDUINO) || defined (__arm__) || defined (__ARDUINO_X86__)
112  // Define _BV for non-Arduino platforms and for Arduino DUE
113  #include <stdint.h>
114  #include <stdio.h>
115  #include <string.h>
116 
117  #if defined (__arm__) || defined (__ARDUINO_X86__)
118  #if defined (__arm__) && defined (SPI_UART)
119  #include <SPI_UART.h>
120  #define _SPI uspi
121 
122  #else // !defined (__arm__) || !defined (SPI_UART)
123  #include <SPI.h>
124  #define _SPI SPIClass
125  #define RF24_SPI_PTR
126 
127  #endif // !defined (__arm__) || !defined (SPI_UART)
128  #elif !defined(__arm__) && !defined (__ARDUINO_X86__)
129  // fallback to unofficially supported Hardware (courtesy of ManiacBug)
130  extern HardwareSPI SPI;
131  #define _SPI HardwareSPI
132  #define RF24_SPI_PTR
133 
134  #endif // !defined(__arm__) && !defined (__ARDUINO_X86__)
135 
136  #ifndef _BV
137  #define _BV(x) (1<<(x))
138  #endif
139  #endif // defined (ARDUINO) && !defined (__arm__) && !defined (__ARDUINO_X86__)
140 
141  #ifdef SERIAL_DEBUG
142  #define IF_SERIAL_DEBUG(x) ({x;})
143  #else
144  #define IF_SERIAL_DEBUG(x)
145  #if defined(RF24_TINY)
146  #define printf_P(...)
147 
148  #endif // defined(RF24_TINY)
149  #endif // SERIAL_DEBUG
150 
151  #if defined (__ARDUINO_X86__)
152  #define printf_P printf
153  #define _BV(bit) (1<<(bit))
154 
155  #endif // defined (__ARDUINO_X86__)
156 
157  // Progmem is Arduino-specific
158  #if defined (ARDUINO_ARCH_ESP8266) || defined (ESP32)
159  #include <pgmspace.h>
160  #define PRIPSTR "%s"
161  #ifndef pgm_read_ptr
162  #define pgm_read_ptr(p) (*(p))
163  #endif
164  #elif defined (ARDUINO) && !defined (ESP_PLATFORM) && !defined (__arm__) && !defined (__ARDUINO_X86__) || defined (XMEGA)
165  #include <avr/pgmspace.h>
166  #define PRIPSTR "%S"
167 
168  #else // !defined (ARDUINO) || defined (ESP_PLATFORM) || defined (__arm__) || defined (__ARDUINO_X86__) && !defined (XMEGA)
169  #if !defined (ARDUINO) // This doesn't work on Arduino DUE
170  typedef char const char;
171  #else // Fill in pgm_read_byte that is used
172  #if defined (ARDUINO_ARCH_AVR) || defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_SAM_DUE)
173  #include <avr/pgmspace.h> // added to ArduinoCore-sam (Due core) in 2013
174  #endif
175 
176  // Since the official arduino/ArduinoCore-samd repo switched to a unified API in 2016,
177  // Serial.printf() is no longer defined in the unifying Arduino/ArduinoCore-API repo
178  #if defined (ARDUINO_ARCH_SAMD) && defined (ARDUINO_SAMD_ADAFRUIT)
179  // it is defined if using the adafruit/ArduinoCore-samd repo
180  #define printf_P Serial.printf
181  #endif // defined (ARDUINO_ARCH_SAMD)
182 
183  #ifndef pgm_read_byte
184  #define pgm_read_byte(addr) (*(const unsigned char *)(addr))
185  #endif
186  #endif // !defined (ARDUINO)
187 
188  #ifndef prog_uint16_t
189  typedef uint16_t prog_uint16_t;
190  #endif
191  #ifndef PSTR
192  #define PSTR(x) (x)
193  #endif
194  #ifndef printf_P
195  #define printf_P printf
196  #endif
197  #ifndef strlen_P
198  #define strlen_P strlen
199  #endif
200  #ifndef PROGMEM
201  #define PROGMEM
202  #endif
203  #ifndef pgm_read_word
204  #define pgm_read_word(p) (*(p))
205  #endif
206  #if !defined pgm_read_ptr || defined ARDUINO_ARCH_MBED
207  #define pgm_read_ptr(p) (*(p))
208  #endif
209  #ifndef PRIPSTR
210  #define PRIPSTR "%s"
211  #endif
212 
213  #endif // !defined (ARDUINO) || defined (ESP_PLATFORM) || defined (__arm__) || defined (__ARDUINO_X86__) && !defined (XMEGA)
214 #endif //Everything else
215 
216 #if defined (SPI_HAS_TRANSACTION) && !defined (SPI_UART) && !defined (SOFTSPI)
217  #define RF24_SPI_TRANSACTIONS
218 #endif // defined (SPI_HAS_TRANSACTION) && !defined (SPI_UART) && !defined (SOFTSPI)
219 
220 #endif // __RF24_CONFIG_H__
uint16_t prog_uint16_t