Optimized high speed nRF24L01+ driver class documentation v1.6.0
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_NRF54L15)
97 #define sprintf_P sprintf
98 #endif
99
100 #if defined(ARDUINO) && !defined(__arm__) && !defined(__ARDUINO_X86__)
101 #if defined SPI_UART
102 #include <SPI_UART.h>
103 #define _SPI uspi
104 #elif defined(SOFTSPI)
105 // change these pins to your liking
106 //
107 #ifndef SOFT_SPI_MISO_PIN
108 #define SOFT_SPI_MISO_PIN 9
109 #endif // SOFT_SPI_MISO_PIN
110
111 #ifndef SOFT_SPI_MOSI_PIN
112 #define SOFT_SPI_MOSI_PIN 8
113 #endif // SOFT_SPI_MOSI_PIN
114
115 #ifndef SOFT_SPI_SCK_PIN
116 #define SOFT_SPI_SCK_PIN 7
117 #endif // SOFT_SPI_SCK_PIN
118
119const uint8_t SPI_MODE = 0;
120 #define _SPI spi
121
122 #elif defined(ARDUINO_SAM_DUE)
123 #include <SPI.h>
124 #define _SPI SPI
125
126 #else // !defined (SPI_UART) && !defined (SOFTSPI)
127 #include <SPI.h>
128 #define _SPI SPIClass
129 #define RF24_SPI_PTR
130 #endif // !defined (SPI_UART) && !defined (SOFTSPI)
131
132 #else // !defined(ARDUINO) || defined (__arm__) || defined (__ARDUINO_X86__)
133 // Define _BV for non-Arduino platforms and for Arduino DUE
134 #include <stdint.h>
135 #include <stdio.h>
136 #include <string.h>
137
138 #if defined(__arm__) || defined(__ARDUINO_X86__)
139 #if defined(__arm__) && defined(SPI_UART)
140 #include <SPI_UART.h>
141 #define _SPI uspi
142
143 #else // !defined (__arm__) || !defined (SPI_UART)
144 #include <SPI.h>
145 #define _SPI SPIClass
146 #define RF24_SPI_PTR
147
148 #endif // !defined (__arm__) || !defined (SPI_UART)
149 #elif !defined(__arm__) && !defined(__ARDUINO_X86__)
150// fallback to unofficially supported Hardware (courtesy of ManiacBug)
151extern HardwareSPI SPI;
152 #define _SPI HardwareSPI
153 #define RF24_SPI_PTR
154
155 #endif // !defined(__arm__) && !defined (__ARDUINO_X86__)
156
157 #ifndef _BV
158 #define _BV(x) (1 << (x))
159 #endif
160 #endif // defined (ARDUINO) && !defined (__arm__) && !defined (__ARDUINO_X86__)
161
162 #ifdef RF24_DEBUG
163 #define IF_RF24_DEBUG(x) ({ x; })
164 #else
165 #define IF_RF24_DEBUG(x)
166 #if defined(RF24_TINY)
167 #define printf_P(...)
168 #endif // defined(RF24_TINY)
169
170 #endif // RF24_DEBUG
171
172 #if defined(__ARDUINO_X86__)
173 #define printf_P printf
174 #define _BV(bit) (1 << (bit))
175
176 #endif // defined (__ARDUINO_X86__)
177
178 // Progmem is Arduino-specific
179 #if defined(ARDUINO_ARCH_ESP8266) || defined(ESP32) || (defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED))
180 #include <pgmspace.h>
181 #define PRIPSTR "%s"
182 #ifndef pgm_read_ptr
183 #define pgm_read_ptr(p) (*(void* const*)(p))
184 #endif
185 // Serial.printf() is no longer defined in the unifying Arduino/ArduinoCore-API repo
186 // Serial.printf() is defined if using the arduino-pico/esp32/8266 repo
187 #if defined(ARDUINO_ARCH_ESP32) // do not `undef` when using the espressif SDK only
188 #undef printf_P // needed for ESP32 core
189 #endif
190 #define printf_P Serial.printf
191 #elif defined(ARDUINO) && !defined(ESP_PLATFORM) && !defined(__arm__) && !defined(__ARDUINO_X86__) || defined(XMEGA)
192 #include <avr/pgmspace.h>
193 #define PRIPSTR "%S"
194
195 #else // !defined (ARDUINO) || defined (ESP_PLATFORM) || defined (__arm__) || defined (__ARDUINO_X86__) && !defined (XMEGA)
196 #if !defined(ARDUINO) // This doesn't work on Arduino DUE
197typedef char const char;
198 #else // Fill in pgm_read_byte that is used
199 #if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_SAM_DUE)
200 #include <avr/pgmspace.h> // added to ArduinoCore-sam (Due core) in 2013
201 #endif
202
203 // Since the official arduino/ArduinoCore-samd repo switched to a unified API in 2016,
204 // Serial.printf() is no longer defined in the unifying Arduino/ArduinoCore-API repo
205 #if defined(ARDUINO_ARCH_SAMD) && defined(ARDUINO_SAMD_ADAFRUIT)
206 // it is defined if using the adafruit/ArduinoCore-samd repo
207 #define printf_P Serial.printf
208 #endif // defined (ARDUINO_ARCH_SAMD)
209
210 #ifndef pgm_read_byte
211 #define pgm_read_byte(addr) (*(const unsigned char*)(addr))
212 #endif
213 #endif // !defined (ARDUINO)
214
215 #ifndef prog_uint16_t
216typedef uint16_t prog_uint16_t;
217 #endif
218 #ifndef PSTR
219 #define PSTR(x) (x)
220 #endif
221 #ifndef printf_P
222 #define printf_P printf
223 #endif
224 #ifndef strlen_P
225 #define strlen_P strlen
226 #endif
227 #ifndef PROGMEM
228 #define PROGMEM
229 #endif
230 #ifndef pgm_read_word
231 #define pgm_read_word(p) (*(const unsigned short*)(p))
232 #endif
233 #if !defined pgm_read_ptr || defined ARDUINO_ARCH_MBED
234 #define pgm_read_ptr(p) (*(void* const*)(p))
235 #endif
236 #ifndef PRIPSTR
237 #define PRIPSTR "%s"
238 #endif
239
240 #endif // !defined (ARDUINO) || defined (ESP_PLATFORM) || defined (__arm__) || defined (__ARDUINO_X86__) && !defined (XMEGA)
241
242#endif //Everything else
243
244#if defined(SPI_HAS_TRANSACTION) && !defined(SPI_UART) && !defined(SOFTSPI)
245 #define RF24_SPI_TRANSACTIONS
246#endif // defined (SPI_HAS_TRANSACTION) && !defined (SPI_UART) && !defined (SOFTSPI)
247
248#endif // RF24_CONFIG_H_
uint16_t prog_uint16_t
uint16_t rf24_gpio_pin_t