Optimized high speed nRF24L01+ driver class documentation v1.4.11
TMRh20 2020 - Optimized fork of the nRF24L01+ driver
Loading...
Searching...
No Matches
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 RF24_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 #define sprintf_P sprintf
58
59#elif (!defined(ARDUINO)) // Any non-arduino device is handled via configure/Makefile
60 // The configure script detects device and copies the correct includes.h file to /utility/includes.h
61 // This behavior can be overridden by calling configure with respective parameters
62 // The includes.h file defines either RF24_RPi, MRAA, LITTLEWIRE or RF24_SPIDEV and includes the correct RF24_arch_config.h file
63 #include "utility/includes.h"
64
65 #ifndef sprintf_P
66 #define sprintf_P sprintf
67 #endif // sprintf_P
68
69//ATTiny
70#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__)
71 #define RF24_TINY
72 #include "utility/ATTiny/RF24_arch_config.h"
73
74#elif defined(LITTLEWIRE) //LittleWire
75 #include "utility/LittleWire/RF24_arch_config.h"
76
77#elif defined(TEENSYDUINO) //Teensy
78 #include "utility/Teensy/RF24_arch_config.h"
79
80#else //Everything else
81 #include <Arduino.h>
82
83 #ifdef NUM_DIGITAL_PINS
84 #if NUM_DIGITAL_PINS < 255
85typedef uint8_t rf24_gpio_pin_t;
86 #define RF24_PIN_INVALID 0xFF
87 #else
88typedef uint16_t rf24_gpio_pin_t;
89 #define RF24_PIN_INVALID 0xFFFF
90 #endif
91 #else
92typedef uint16_t rf24_gpio_pin_t;
93 #define RF24_PIN_INVALID 0xFFFF
94 #endif
95
96 #if defined(ARDUINO) && !defined(__arm__) && !defined(__ARDUINO_X86__)
97 #if defined SPI_UART
98 #include <SPI_UART.h>
99 #define _SPI uspi
100 #elif defined(SOFTSPI)
101 // change these pins to your liking
102 //
103 #ifndef SOFT_SPI_MISO_PIN
104 #define SOFT_SPI_MISO_PIN 9
105 #endif // SOFT_SPI_MISO_PIN
106
107 #ifndef SOFT_SPI_MOSI_PIN
108 #define SOFT_SPI_MOSI_PIN 8
109 #endif // SOFT_SPI_MOSI_PIN
110
111 #ifndef SOFT_SPI_SCK_PIN
112 #define SOFT_SPI_SCK_PIN 7
113 #endif // SOFT_SPI_SCK_PIN
114
115const uint8_t SPI_MODE = 0;
116 #define _SPI spi
117
118 #elif defined(ARDUINO_SAM_DUE)
119 #include <SPI.h>
120 #define _SPI SPI
121
122 #else // !defined (SPI_UART) && !defined (SOFTSPI)
123 #include <SPI.h>
124 #define _SPI SPIClass
125 #define RF24_SPI_PTR
126 #endif // !defined (SPI_UART) && !defined (SOFTSPI)
127
128 #else // !defined(ARDUINO) || defined (__arm__) || defined (__ARDUINO_X86__)
129 // Define _BV for non-Arduino platforms and for Arduino DUE
130 #include <stdint.h>
131 #include <stdio.h>
132 #include <string.h>
133
134 #if defined(__arm__) || defined(__ARDUINO_X86__)
135 #if defined(__arm__) && defined(SPI_UART)
136 #include <SPI_UART.h>
137 #define _SPI uspi
138
139 #else // !defined (__arm__) || !defined (SPI_UART)
140 #include <SPI.h>
141 #define _SPI SPIClass
142 #define RF24_SPI_PTR
143
144 #endif // !defined (__arm__) || !defined (SPI_UART)
145 #elif !defined(__arm__) && !defined(__ARDUINO_X86__)
146// fallback to unofficially supported Hardware (courtesy of ManiacBug)
147extern HardwareSPI SPI;
148 #define _SPI HardwareSPI
149 #define RF24_SPI_PTR
150
151 #endif // !defined(__arm__) && !defined (__ARDUINO_X86__)
152
153 #ifndef _BV
154 #define _BV(x) (1 << (x))
155 #endif
156 #endif // defined (ARDUINO) && !defined (__arm__) && !defined (__ARDUINO_X86__)
157
158 #ifdef RF24_DEBUG
159 #define IF_RF24_DEBUG(x) ({ x; })
160 #else
161 #define IF_RF24_DEBUG(x)
162 #if defined(RF24_TINY)
163 #define printf_P(...)
164 #endif // defined(RF24_TINY)
165
166 #endif // RF24_DEBUG
167
168 #if defined(__ARDUINO_X86__)
169 #define printf_P printf
170 #define _BV(bit) (1 << (bit))
171
172 #endif // defined (__ARDUINO_X86__)
173
174 // Progmem is Arduino-specific
175 #if defined(ARDUINO_ARCH_ESP8266) || defined(ESP32) || (defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED))
176 #include <pgmspace.h>
177 #define PRIPSTR "%s"
178 #ifndef pgm_read_ptr
179 #define pgm_read_ptr(p) (*(void* const*)(p))
180 #endif
181 // Serial.printf() is no longer defined in the unifying Arduino/ArduinoCore-API repo
182 // Serial.printf() is defined if using the arduino-pico/esp32/8266 repo
183 #if defined(ARDUINO_ARCH_ESP32) // do not `undef` when using the espressif SDK only
184 #undef printf_P // needed for ESP32 core
185 #endif
186 #define printf_P Serial.printf
187 #elif defined(ARDUINO) && !defined(ESP_PLATFORM) && !defined(__arm__) && !defined(__ARDUINO_X86__) || defined(XMEGA)
188 #include <avr/pgmspace.h>
189 #define PRIPSTR "%S"
190
191 #else // !defined (ARDUINO) || defined (ESP_PLATFORM) || defined (__arm__) || defined (__ARDUINO_X86__) && !defined (XMEGA)
192 #if !defined(ARDUINO) // This doesn't work on Arduino DUE
193typedef char const char;
194 #else // Fill in pgm_read_byte that is used
195 #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_SAM_DUE)
196 #include <avr/pgmspace.h> // added to ArduinoCore-sam (Due core) in 2013
197 #endif
198
199 // Since the official arduino/ArduinoCore-samd repo switched to a unified API in 2016,
200 // Serial.printf() is no longer defined in the unifying Arduino/ArduinoCore-API repo
201 #if defined(ARDUINO_ARCH_SAMD) && defined(ARDUINO_SAMD_ADAFRUIT)
202 // it is defined if using the adafruit/ArduinoCore-samd repo
203 #define printf_P Serial.printf
204 #endif // defined (ARDUINO_ARCH_SAMD)
205
206 #ifndef pgm_read_byte
207 #define pgm_read_byte(addr) (*(const unsigned char*)(addr))
208 #endif
209 #endif // !defined (ARDUINO)
210
211 #ifndef prog_uint16_t
212typedef uint16_t prog_uint16_t;
213 #endif
214 #ifndef PSTR
215 #define PSTR(x) (x)
216 #endif
217 #ifndef printf_P
218 #define printf_P printf
219 #endif
220 #ifndef strlen_P
221 #define strlen_P strlen
222 #endif
223 #ifndef PROGMEM
224 #define PROGMEM
225 #endif
226 #ifndef pgm_read_word
227 #define pgm_read_word(p) (*(const unsigned short*)(p))
228 #endif
229 #if !defined pgm_read_ptr || defined ARDUINO_ARCH_MBED
230 #define pgm_read_ptr(p) (*(void* const*)(p))
231 #endif
232 #ifndef PRIPSTR
233 #define PRIPSTR "%s"
234 #endif
235
236 #endif // !defined (ARDUINO) || defined (ESP_PLATFORM) || defined (__arm__) || defined (__ARDUINO_X86__) && !defined (XMEGA)
237
238#endif //Everything else
239
240#if defined(SPI_HAS_TRANSACTION) && !defined(SPI_UART) && !defined(SOFTSPI)
241 #define RF24_SPI_TRANSACTIONS
242#endif // defined (SPI_HAS_TRANSACTION) && !defined (SPI_UART) && !defined (SOFTSPI)
243
244#endif // RF24_CONFIG_H_
uint16_t prog_uint16_t
uint16_t rf24_gpio_pin_t