RadioLib
Universal wireless communication library for Arduino
BuildOpt.h
1 #if !defined(_RADIOLIB_BUILD_OPTIONS_H)
2 #define _RADIOLIB_BUILD_OPTIONS_H
3 
4 #if ARDUINO >= 100
5  // Arduino build
6  #include "Arduino.h"
7  #define RADIOLIB_BUILD_ARDUINO
8 #else
9  // generic build
10  #include <stdio.h>
11  #define RADIOLIB_BUILD_GENERIC
12 #endif
13 
14 #if defined(RADIOLIB_BUILD_ARDUINO)
15 /*
16  * Platform-specific configuration.
17  *
18  * RADIOLIB_PLATFORM - platform name, used in debugging to quickly check the correct platform is detected.
19  * RADIOLIB_NC - alias for unused pin, usually the largest possible value of uint8_t.
20  * RADIOLIB_DEFAULT_SPI - default SPIClass instance to use.
21  * RADIOLIB_NONVOLATILE - macro to place variable into program storage (usually Flash).
22  * RADIOLIB_NONVOLATILE_READ_BYTE - function/macro to read variables saved in program storage (usually Flash).
23  * RADIOLIB_TYPE_ALIAS - construct to create an alias for a type, usually vai the `using` keyword.
24  * RADIOLIB_TONE_UNSUPPORTED - some platforms do not have tone()/noTone(), which is required for AFSK.
25  * RADIOLIB_BUILTIN_MODULE - some platforms have a builtin radio module on fixed pins, this macro is used to specify that pinout.
26  *
27  * In addition, some platforms may require RadioLib to disable specific drivers (such as ESP8266).
28  *
29  * Users may also specify their own configuration by uncommenting the RADIOLIB_CUSTOM_ARDUINO,
30  * and then specifying all platform parameters in the section below. This will override automatic
31  * platform detection.
32  */
33 
34  // uncomment to enable custom platform definition
35  //#define RADIOLIB_CUSTOM_ARDUINO
36 
37 #if defined(RADIOLIB_CUSTOM_ARDUINO)
38  // name for your platform
39  #define RADIOLIB_PLATFORM "Custom"
40 
41  // the following must be defined if the Arduino core does not support tone or yield function
42  //#define RADIOLIB_TONE_UNSUPPORTED
43  //#define RADIOLIB_YIELD_UNSUPPORTED
44 
45  // some of RadioLib drivers may be excluded, to prevent collisions with platforms (or to speed up build process)
46  // the following is a complete list of all possible exclusion macros, uncomment any of them to disable that driver
47  // NOTE: Some of the exclusion macros are dependent on each other. For example, it is not possible to exclude RF69
48  // while keeping SX1231 (because RF69 is the base class for SX1231). The dependency is always uni-directional,
49  // so excluding SX1231 and keeping RF69 is valid.
50  //#define RADIOLIB_EXCLUDE_CC1101
51  //#define RADIOLIB_EXCLUDE_NRF24
52  //#define RADIOLIB_EXCLUDE_RF69
53  //#define RADIOLIB_EXCLUDE_SX1231 // dependent on RADIOLIB_EXCLUDE_RF69
54  //#define RADIOLIB_EXCLUDE_SI443X
55  //#define RADIOLIB_EXCLUDE_RFM2X // dependent on RADIOLIB_EXCLUDE_SI443X
56  //#define RADIOLIB_EXCLUDE_SX127X
57  //#define RADIOLIB_EXCLUDE_RFM9X // dependent on RADIOLIB_EXCLUDE_SX127X
58  //#define RADIOLIB_EXCLUDE_SX126X
59  //#define RADIOLIB_EXCLUDE_STM32WLX // dependent on RADIOLIB_EXCLUDE_SX126X
60  //#define RADIOLIB_EXCLUDE_SX128X
61  //#define RADIOLIB_EXCLUDE_AFSK
62  //#define RADIOLIB_EXCLUDE_AX25
63  //#define RADIOLIB_EXCLUDE_HELLSCHREIBER
64  //#define RADIOLIB_EXCLUDE_MORSE
65  //#define RADIOLIB_EXCLUDE_RTTY
66  //#define RADIOLIB_EXCLUDE_SSTV
67  //#define RADIOLIB_EXCLUDE_DIRECT_RECEIVE
68 #elif defined(__AVR__) && !(defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) || defined(ARDUINO_ARCH_MEGAAVR))
69  // Arduino AVR boards (except for megaAVR) - Uno, Mega etc.
70  #define RADIOLIB_PLATFORM "Arduino AVR"
71 #elif defined(ESP8266)
72  // ESP8266 boards
73  #define RADIOLIB_PLATFORM "ESP8266"
74 #elif defined(ESP32)
75  // ESP32 boards
76  #define RADIOLIB_PLATFORM "ESP32"
77  // ESP32 doesn't support tone(), but it can be emulated via LED control peripheral
78  #define RADIOLIB_TONE_UNSUPPORTED
79  #define RADIOLIB_TONE_ESP32_CHANNEL (1)
80 #elif defined(ARDUINO_ARCH_STM32)
81  // official STM32 Arduino core (https://github.com/stm32duino/Arduino_Core_STM32)
82  #define RADIOLIB_PLATFORM "Arduino STM32 (official)"
83 #elif defined(SAMD_SERIES)
84  // Adafruit SAMD boards (M0 and M4)
85  #define RADIOLIB_PLATFORM "Adafruit SAMD"
86 #elif defined(ARDUINO_ARCH_SAMD)
87  // Arduino SAMD (Zero, MKR, etc.)
88  #define RADIOLIB_PLATFORM "Arduino SAMD"
89 
90  #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST (PinMode)
91  #define RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST (PinStatus)
92  #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST (PinStatus)
93 #elif defined(__SAM3X8E__)
94  // Arduino Due
95  #define RADIOLIB_PLATFORM "Arduino Due"
96  #define RADIOLIB_TONE_UNSUPPORTED
97 #elif (defined(NRF52832_XXAA) || defined(NRF52840_XXAA)) && !defined(ARDUINO_ARDUINO_NANO33BLE)
98  // Adafruit nRF52 boards
99  #define RADIOLIB_PLATFORM "Adafruit nRF52"
100 #elif defined(ARDUINO_ARC32_TOOLS)
101  // Intel Curie
102  #define RADIOLIB_PLATFORM "Intel Curie"
103 #elif defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) || defined(PORTDUINO)
104  // Arduino megaAVR boards - Uno Wifi Rev.2, Nano Every
105  #define RADIOLIB_PLATFORM "Arduino megaAVR"
106 #elif defined(ARDUINO_ARCH_APOLLO3)
107  // Sparkfun Apollo3 boards
108  #define RADIOLIB_PLATFORM "Sparkfun Apollo3"
109 
110  #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST (Arduino_PinMode)
111  #define RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST (PinStatus)
112  #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST (PinStatus)
113 #elif defined(ARDUINO_ARDUINO_NANO33BLE)
114  // Arduino Nano 33 BLE
115  #define RADIOLIB_PLATFORM "Arduino Nano 33 BLE"
116 
117  #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST (PinMode)
118  #define RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST (PinStatus)
119  #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST (PinStatus)
120 
121  // Arduino mbed OS boards have a really bad tone implementation which will crash after a couple seconds
122  #define RADIOLIB_TONE_UNSUPPORTED
123  #define RADIOLIB_MBED_TONE_OVERRIDE
124 #elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4)
125  // Arduino Portenta H7
126  #define RADIOLIB_PLATFORM "Portenta H7"
127 
128  #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST (PinMode)
129  #define RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST (PinStatus)
130  #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST (PinStatus)
131 
132  // Arduino mbed OS boards have a really bad tone implementation which will crash after a couple seconds
133  #define RADIOLIB_TONE_UNSUPPORTED
134  #define RADIOLIB_MBED_TONE_OVERRIDE
135 #elif defined(__STM32F4__) || defined(__STM32F1__)
136  // Arduino STM32 core by Roger Clark (https://github.com/rogerclarkmelbourne/Arduino_STM32)
137  #define RADIOLIB_PLATFORM "STM32duino (unofficial)"
138 
139  #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST (WiringPinMode)
140  #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST (ExtIntTriggerMode)
141 #elif defined(ARDUINO_ARCH_MEGAAVR)
142  // MegaCoreX by MCUdude (https://github.com/MCUdude/MegaCoreX)
143  #define RADIOLIB_PLATFORM "MegaCoreX"
144 #elif defined(ARDUINO_ARCH_MBED_RP2040)
145  // Raspberry Pi Pico (official mbed core)
146  #define RADIOLIB_PLATFORM "Raspberry Pi Pico"
147 
148  #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST (PinMode)
149  #define RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST (PinStatus)
150  #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST (PinStatus)
151 
152  // Arduino mbed OS boards have a really bad tone implementation which will crash after a couple seconds
153  #define RADIOLIB_TONE_UNSUPPORTED
154  #define RADIOLIB_MBED_TONE_OVERRIDE
155 #elif defined(ARDUINO_ARCH_RP2040)
156  // Raspberry Pi Pico (unofficial core)
157  #define RADIOLIB_PLATFORM "Raspberry Pi Pico (unofficial)"
158 
159  #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST (PinMode)
160  #define RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST (PinStatus)
161  #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST (PinStatus)
162 #elif defined(__ASR6501__) || defined(ARDUINO_ARCH_ASR650X) || defined(DARDUINO_ARCH_ASR6601)
163  // CubeCell
164  #define RADIOLIB_PLATFORM "CubeCell"
165  #define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(1000000, MSBFIRST, SPI_MODE0) // see issue #709
166 
167  #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST (PINMODE)
168  #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST (IrqModes)
169 
170  // provide an easy access to the on-board module
171  #include "board-config.h"
172  #define RADIOLIB_BUILTIN_MODULE RADIO_NSS, RADIO_DIO_1, RADIO_RESET, RADIO_BUSY
173 
174  // CubeCell doesn't seem to define nullptr, let's do something like that now
175  #define nullptr NULL
176 
177  // ... and also defines pinMode() as a macro, which is by far the stupidest thing I have seen on Arduino
178  #undef pinMode
179 
180  // ... and uses an outdated GCC which does not support type aliases
181  #define RADIOLIB_TYPE_ALIAS(type, alias) typedef class type alias;
182 
183  // ... and it also has no tone(). This platform was designed by an idiot.
184  #define RADIOLIB_TONE_UNSUPPORTED
185 
186  // ... AND as the (hopefully) final nail in the coffin, IT F*CKING DEFINES YIELD() AS A MACRO THAT DOES NOTHING!!!
187  #define RADIOLIB_YIELD_UNSUPPORTED
188  #if defined(yield)
189  #undef yield
190  #endif
191 #elif defined(RASPI)
192  // RaspiDuino framework (https://github.com/me-no-dev/RasPiArduino)
193  #define RADIOLIB_PLATFORM "RasPiArduino"
194 
195  // let's start off easy - no tone on this platform, that can happen
196  #define RADIOLIB_TONE_UNSUPPORTED
197 
198  // hmm, no yield either - weird on something like Raspberry PI, but sure, we can handle it
199  #define RADIOLIB_YIELD_UNSUPPORTED
200 
201  // aight, getting to the juicy stuff - PGM_P seems missing, that's the first time
202  #define PGM_P const char *
203 
204  // ... and for the grand finale, we have millis() and micros() DEFINED AS MACROS!
205  #if defined(millis)
206  #undef millis
207  inline unsigned long millis() { return((unsigned long)(STCV / 1000)); };
208  #endif
209 
210  #if defined(micros)
211  #undef micros
212  inline unsigned long micros() { return((unsigned long)(STCV)); };
213  #endif
214 #elif defined(TEENSYDUINO)
215  // Teensy
216  #define RADIOLIB_PLATFORM "Teensy"
217 #else
218  // other Arduino platforms not covered by the above list - this may or may not work
219  #define RADIOLIB_PLATFORM "Unknown Arduino"
220  #define RADIOLIB_UNKNOWN_PLATFORM
221 #endif
222 
223  #if !defined(RADIOLIB_NC)
224  #define RADIOLIB_NC (0xFFFFFFFF)
225  #endif
226  #if !defined(RADIOLIB_DEFAULT_SPI)
227  #define RADIOLIB_DEFAULT_SPI SPI
228  #endif
229  #if !defined(RADIOLIB_DEFAULT_SPI_SETTINGS)
230  #define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
231  #endif
232  #if !defined(RADIOLIB_NONVOLATILE)
233  #define RADIOLIB_NONVOLATILE PROGMEM
234  #endif
235  #if !defined(RADIOLIB_NONVOLATILE_READ_BYTE)
236  #define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
237  #endif
238  #if !defined(RADIOLIB_NONVOLATILE_READ_DWORD)
239  #define RADIOLIB_NONVOLATILE_READ_DWORD(addr) pgm_read_dword(addr)
240  #endif
241  #if !defined(RADIOLIB_TYPE_ALIAS)
242  #define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
243  #endif
244 
245  #if !defined(RADIOLIB_ARDUINOHAL_PIN_MODE_CAST)
246  #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST
247  #endif
248  #if !defined(RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST)
249  #define RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST
250  #endif
251  #if !defined(RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST)
252  #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST
253  #endif
254 #else
255  // generic non-Arduino platform
256  #define RADIOLIB_PLATFORM "Generic"
257 
258  #define RADIOLIB_NC (0xFF)
259  #define RADIOLIB_NONVOLATILE
260  #define RADIOLIB_NONVOLATILE_READ_BYTE(addr) (*((uint8_t *)(void *)(addr)))
261  #define RADIOLIB_NONVOLATILE_READ_DWORD(addr) (*((uint32_t *)(void *)(addr)))
262  #define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
263 
264  #if !defined(RADIOLIB_DEBUG_PORT)
265  #define RADIOLIB_DEBUG_PORT stdout
266  #endif
267 
268  #define DEC 10
269  #define HEX 16
270  #define OCT 8
271  #define BIN 2
272 
273  #include <algorithm>
274  #include <stdint.h>
275 
276  using std::max;
277  using std::min;
278 #endif
279 
280 /*
281  * Uncomment to enable debug output.
282  * Warning: Debug output will slow down the whole system significantly.
283  * Also, it will result in larger compiled binary.
284  * Levels: debug - only main info
285  * verbose - full transcript of all SPI communication
286  */
287 #if !defined(RADIOLIB_DEBUG)
288  //#define RADIOLIB_DEBUG
289 #endif
290 #if !defined(RADIOLIB_VERBOSE)
291  //#define RADIOLIB_VERBOSE
292 #endif
293 
294 // set which output port should be used for debug output
295 // may be Serial port (on Arduino) or file like stdout or stderr (on generic platforms)
296 #if defined(RADIOLIB_BUILD_ARDUINO) && !defined(RADIOLIB_DEBUG_PORT)
297  #define RADIOLIB_DEBUG_PORT Serial
298 #endif
299 
300 /*
301  * Uncomment to enable "paranoid" SPI mode
302  * Every write to an SPI register using SPI set function will be verified by a subsequent read operation.
303  * This improves reliablility, but slightly slows down communication.
304  * Note: Enabled by default.
305  */
306 #if !defined(RADIOLIB_SPI_PARANOID)
307  #define RADIOLIB_SPI_PARANOID
308 #endif
309 
310 /*
311  * Uncomment to enable parameter range checking
312  * RadioLib will check provided parameters (such as frequency) against limits determined by the device manufacturer.
313  * It is highly advised to keep this macro defined, removing it will allow invalid values to be set,
314  * possibly leading to bricked module and/or program crashing.
315  * Note: Enabled by default.
316  */
317 #if !defined(RADIOLIB_CHECK_PARAMS)
318  #define RADIOLIB_CHECK_PARAMS
319 #endif
320 
321 /*
322  * Uncomment to enable SX127x errata fix
323  * Warning: SX127x errata fix has been reported to cause issues with LoRa bandwidths lower than 62.5 kHz.
324  * It should only be enabled if you really are observing some errata-related issue.
325  * Note: Disabled by default.
326  */
327 #if !defined(RADIOLIB_FIX_ERRATA_SX127X)
328  //#define RADIOLIB_FIX_ERRATA_SX127X
329 #endif
330 
331 /*
332  * Uncomment to enable god mode - all methods and member variables in all classes will be made public, thus making them accessible from Arduino code.
333  * Warning: Come on, it's called GOD mode - obviously only use this if you know what you're doing.
334  * Failure to heed the above warning may result in bricked module.
335  */
336 #if !defined(RADIOLIB_GODMODE)
337  //#define RADIOLIB_GODMODE
338 #endif
339 
340 /*
341  * Uncomment to enable low-level hardware access
342  * This will make some hardware methods like SPI get/set accessible from the user sketch - think of it as "god mode lite"
343  * Warning: RadioLib won't stop you from writing invalid stuff into your device, so it's quite easy to brick your module with this.
344  */
345 #if !defined(RADIOLIB_LOW_LEVEL)
346  //#define RADIOLIB_LOW_LEVEL
347 #endif
348 
349 /*
350  * Uncomment to enable pre-defined modules when using RadioShield.
351  */
352 #if !defined(RADIOLIB_RADIOSHIELD)
353  //#define RADIOLIB_RADIOSHIELD
354 #endif
355 
356 /*
357  * Uncomment to enable interrupt-based timing control
358  * For details, see https://github.com/jgromes/RadioLib/wiki/Interrupt-Based-Timing
359  */
360 #if !defined(RADIOLIB_INTERRUPT_TIMING)
361  //#define RADIOLIB_INTERRUPT_TIMING
362 #endif
363 
364 /*
365  * Uncomment to enable static-only memory management: no dynamic allocation will be performed.
366  * Warning: Large static arrays will be created in some methods. It is not advised to send large packets in this mode.
367  */
368 #if !defined(RADIOLIB_STATIC_ONLY)
369  //#define RADIOLIB_STATIC_ONLY
370 #endif
371 
372 // set the size of static arrays to use
373 #if !defined(RADIOLIB_STATIC_ARRAY_SIZE)
374  #define RADIOLIB_STATIC_ARRAY_SIZE (256)
375 #endif
376 
377 
378 // This only compiles on STM32 boards with SUBGHZ module, but also
379 // include when generating docs
380 #if (!defined(ARDUINO_ARCH_STM32) || !defined(SUBGHZSPI_BASE)) && !defined(DOXYGEN)
381  #define RADIOLIB_EXCLUDE_STM32WLX
382 #endif
383 
384 #if defined(RADIOLIB_DEBUG)
385  #if defined(RADIOLIB_BUILD_ARDUINO)
386  #define RADIOLIB_DEBUG_PRINT(...) Module::serialPrintf(__VA_ARGS__)
387  #define RADIOLIB_DEBUG_PRINTLN(M, ...) Module::serialPrintf(M "\n", ##__VA_ARGS__)
388  #else
389  #if !defined(RADIOLIB_DEBUG_PRINT)
390  #define RADIOLIB_DEBUG_PRINT(...) fprintf(RADIOLIB_DEBUG_PORT, __VA_ARGS__)
391  #endif
392  #if !defined(RADIOLIB_DEBUG_PRINTLN)
393  #define RADIOLIB_DEBUG_PRINTLN(M, ...) fprintf(RADIOLIB_DEBUG_PORT, M "\n", ##__VA_ARGS__)
394  #endif
395  #endif
396 #else
397  #define RADIOLIB_DEBUG_PRINT(...) {}
398  #define RADIOLIB_DEBUG_PRINTLN(...) {}
399 #endif
400 
401 #if defined(RADIOLIB_VERBOSE)
402  #define RADIOLIB_VERBOSE_PRINT(...) RADIOLIB_DEBUG_PRINT(__VA_ARGS__)
403  #define RADIOLIB_VERBOSE_PRINTLN(...) RADIOLIB_DEBUG_PRINTLN(__VA_ARGS__)
404 #else
405  #define RADIOLIB_VERBOSE_PRINT(...) {}
406  #define RADIOLIB_VERBOSE_PRINTLN(...) {}
407 #endif
408 
412 #define RADIOLIB_ASSERT(STATEVAR) { if((STATEVAR) != RADIOLIB_ERR_NONE) { return(STATEVAR); } }
413 
414 
418 #if defined(RADIOLIB_CHECK_PARAMS)
419  #define RADIOLIB_CHECK_RANGE(VAR, MIN, MAX, ERR) { if(!(((VAR) >= (MIN)) && ((VAR) <= (MAX)))) { return(ERR); } }
420 #else
421  #define RADIOLIB_CHECK_RANGE(VAR, MIN, MAX, ERR) {}
422 #endif
423 
424 #if defined(RADIOLIB_FIX_ERRATA_SX127X)
425  #define RADIOLIB_ERRATA_SX127X(...) { errataFix(__VA_ARGS__); }
426 #else
427  #define RADIOLIB_ERRATA_SX127X(...) {}
428 #endif
429 
430 // version definitions
431 #define RADIOLIB_VERSION_MAJOR (0x05)
432 #define RADIOLIB_VERSION_MINOR (0x07)
433 #define RADIOLIB_VERSION_PATCH (0x00)
434 #define RADIOLIB_VERSION_EXTRA (0x00)
435 
436 #define RADIOLIB_VERSION ((RADIOLIB_VERSION_MAJOR << 24) | (RADIOLIB_VERSION_MINOR << 16) | (RADIOLIB_VERSION_PATCH << 8) | (RADIOLIB_VERSION_EXTRA))
437 
438 #endif