RadioLib
Universal wireless communication library for Arduino
Loading...
Searching...
No Matches
BuildOpt.h
1#if !defined(_RADIOLIB_BUILD_OPTIONS_H)
2#define _RADIOLIB_BUILD_OPTIONS_H
3
4#include "TypeDef.h"
5
6/* RadioLib build configuration options */
7
8/*
9 * Debug output enable.
10 * Warning: Debug output will slow down the whole system significantly.
11 * Also, it will result in larger compiled binary.
12 * Levels: basic - only main info
13 * protocol - mainly LoRaWAN stuff, but other protocols as well
14 * SPI - full transcript of all SPI communication
15 */
16#if !defined(RADIOLIB_DEBUG_BASIC)
17 #define RADIOLIB_DEBUG_BASIC (0)
18#endif
19#if !defined(RADIOLIB_DEBUG_PROTOCOL)
20 #define RADIOLIB_DEBUG_PROTOCOL (0)
21#endif
22#if !defined(RADIOLIB_DEBUG_SPI)
23 #define RADIOLIB_DEBUG_SPI (0)
24#endif
25#if !defined(RADIOLIB_VERBOSE_ASSERT)
26 #define RADIOLIB_VERBOSE_ASSERT (0)
27#endif
28
29// set which output port should be used for debug output
30// may be Serial port (on Arduino) or file like stdout or stderr (on generic platforms)
31#if !defined(RADIOLIB_DEBUG_PORT)
32 #if ARDUINO >= 100
33 #define RADIOLIB_DEBUG_PORT Serial
34 #else
35 #define RADIOLIB_DEBUG_PORT stdout
36 #endif
37#endif
38
39/*
40 * Comment to disable "paranoid" SPI mode, or set RADIOLIB_SPI_PARANOID to 0
41 * Every write to an SPI register using SPI set function will be verified by a subsequent read operation.
42 * This improves reliability, but slightly slows down communication.
43 * Note: Enabled by default.
44 */
45#if !defined(RADIOLIB_SPI_PARANOID)
46 #define RADIOLIB_SPI_PARANOID (1)
47#endif
48
49/*
50 * Comment to disable parameter range checking
51 * RadioLib will check provided parameters (such as frequency) against limits determined by the device manufacturer.
52 * It is highly advised to keep this macro defined, removing it will allow invalid values to be set,
53 * possibly leading to bricked module and/or program crashing.
54 * Note: Enabled by default.
55 */
56#if !defined(RADIOLIB_CHECK_PARAMS)
57 #define RADIOLIB_CHECK_PARAMS (1)
58#endif
59
60/*
61 * SX127x errata fix enable
62 * Warning: SX127x errata fix has been reported to cause issues with LoRa bandwidths lower than 62.5 kHz.
63 * It should only be enabled if you really are observing some errata-related issue.
64 * Note: Disabled by default.
65 */
66#if !defined(RADIOLIB_FIX_ERRATA_SX127X)
67 #define RADIOLIB_FIX_ERRATA_SX127X (0)
68#endif
69
70/*
71 * God mode enable - all methods and member variables in all classes will be made public, thus making them accessible from Arduino code.
72 * Warning: Come on, it's called GOD mode - obviously only use this if you know what you're doing.
73 * Failure to heed the above warning may result in bricked module.
74 */
75#if !defined(RADIOLIB_GODMODE)
76 #define RADIOLIB_GODMODE (0)
77#endif
78
79/*
80 * Low-level hardware access enable
81 * This will make some hardware methods like SPI get/set accessible from the user sketch - think of it as "god mode lite"
82 * Warning: RadioLib won't stop you from writing invalid stuff into your device, so it's quite easy to brick your module with this.
83 */
84#if !defined(RADIOLIB_LOW_LEVEL)
85 #define RADIOLIB_LOW_LEVEL (0)
86#endif
87
88/*
89 * Enable interrupt-based timing control
90 * For details, see https://github.com/jgromes/RadioLib/wiki/Interrupt-Based-Timing
91 */
92#if !defined(RADIOLIB_INTERRUPT_TIMING)
93 #define RADIOLIB_INTERRUPT_TIMING (0)
94#endif
95
96/*
97 * Enable static-only memory management: no dynamic allocation will be performed.
98 * Warning: Large static arrays will be created in some methods. It is not advised to send large packets in this mode.
99 */
100#if !defined(RADIOLIB_STATIC_ONLY)
101 #define RADIOLIB_STATIC_ONLY (0)
102#endif
103
104// set the size of static arrays to use
105#if !defined(RADIOLIB_STATIC_ARRAY_SIZE)
106 #define RADIOLIB_STATIC_ARRAY_SIZE (256)
107#endif
108
109/*
110 * Uncomment on boards whose clock runs too slow or too fast
111 * Set the value according to the following scheme:
112 * Enable timestamps on your terminal
113 * Print something to terminal, wait 1000 milliseconds, print something again
114 * If the difference is e.g. 1014 milliseconds between the prints, set this value to 14
115 * Or, for more accuracy, wait for 100,000 milliseconds and divide the total drift by 100
116 */
117#if !defined(RADIOLIB_CLOCK_DRIFT_MS)
118 //#define RADIOLIB_CLOCK_DRIFT_MS (0)
119#endif
120
121#if !defined(RADIOLIB_LINE_FEED)
122 #define RADIOLIB_LINE_FEED "\r\n"
123#endif
124
125#if ARDUINO >= 100
126 // Arduino build
127 #include "Arduino.h"
128 #define RADIOLIB_BUILD_ARDUINO
129#else
130 // generic build
131 #include <stdio.h>
132 #define RADIOLIB_BUILD_GENERIC
133#endif
134
135#if defined(RADIOLIB_BUILD_ARDUINO)
136/*
137 * Platform-specific configuration.
138 *
139 * RADIOLIB_PLATFORM - platform name, used in debugging to quickly check the correct platform is detected.
140 * RADIOLIB_NC - alias for unused pin, usually the largest possible value of uint32_t.
141 * RADIOLIB_DEFAULT_SPI - default SPIClass instance to use.
142 * RADIOLIB_NONVOLATILE - macro to place variable into program storage (usually Flash).
143 * RADIOLIB_NONVOLATILE_READ_BYTE - function/macro to read variables saved in program storage (usually Flash).
144 * RADIOLIB_TYPE_ALIAS - construct to create an alias for a type, usually via the `using` keyword.
145 * RADIOLIB_TONE_UNSUPPORTED - some platforms do not have tone()/noTone(), which is required for AFSK.
146 *
147 * Users may also specify their own configuration by uncommenting the RADIOLIB_CUSTOM_ARDUINO,
148 * and then specifying all platform parameters in the section below. This will override automatic
149 * platform detection.
150 */
151
152 // uncomment to enable custom platform definition
153 //#define RADIOLIB_CUSTOM_ARDUINO
154
155#if defined(RADIOLIB_CUSTOM_ARDUINO)
156 // name for your platform
157 #define RADIOLIB_PLATFORM "Custom"
158
159 // the following must be defined if the Arduino core does not support tone or yield function
160 //#define RADIOLIB_TONE_UNSUPPORTED
161 //#define RADIOLIB_YIELD_UNSUPPORTED
162
163 // in addition, the following macros may be defined if the Arduino core differs from the defaults
164 #define RADIOLIB_NC (0xFFFFFFFF)
165 #define RADIOLIB_DEFAULT_SPI SPI
166 #define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
167 #define RADIOLIB_NONVOLATILE PROGMEM
168 #define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
169 #define RADIOLIB_NONVOLATILE_READ_DWORD(addr) pgm_read_dword(addr)
170 #define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
171
172 // you might also have to define these if the Arduino core has some uncommon pin mode/status types
173 #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST
174 #define RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST
175 #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST
176
177 // some of RadioLib drivers may be excluded, to prevent collisions with platforms (or to speed up build process)
178 // the following is a complete list of all possible exclusion macros, uncomment any of them to disable that driver
179 // NOTE: Some of the exclusion macros are dependent on each other. For example, it is not possible to exclude RF69
180 // while keeping SX1231 (because RF69 is the base class for SX1231). The dependency is always uni-directional,
181 // so excluding SX1231 and keeping RF69 is valid.
182 //#define RADIOLIB_EXCLUDE_CC1101 (1)
183 //#define RADIOLIB_EXCLUDE_NRF24 (1)
184 //#define RADIOLIB_EXCLUDE_RF69 (1)
185 //#define RADIOLIB_EXCLUDE_SX1231 (1) // dependent on RADIOLIB_EXCLUDE_RF69
186 //#define RADIOLIB_EXCLUDE_SI443X (1)
187 //#define RADIOLIB_EXCLUDE_RFM2X (1) // dependent on RADIOLIB_EXCLUDE_SI443X
188 //#define RADIOLIB_EXCLUDE_SX127X (1)
189 //#define RADIOLIB_EXCLUDE_SX126X (1)
190 //#define RADIOLIB_EXCLUDE_STM32WLX (1) // dependent on RADIOLIB_EXCLUDE_SX126X
191 //#define RADIOLIB_EXCLUDE_SX128X (1)
192 //#define RADIOLIB_EXCLUDE_AFSK (1)
193 //#define RADIOLIB_EXCLUDE_AX25 (1)
194 //#define RADIOLIB_EXCLUDE_HELLSCHREIBER (1)
195 //#define RADIOLIB_EXCLUDE_MORSE (1)
196 //#define RADIOLIB_EXCLUDE_RTTY (1)
197 //#define RADIOLIB_EXCLUDE_SSTV (1)
198 //#define RADIOLIB_EXCLUDE_DIRECT_RECEIVE (1)
199 //#define RADIOLIB_EXCLUDE_BELL (1)
200 //#define RADIOLIB_EXCLUDE_APRS (1)
201 //#define RADIOLIB_EXCLUDE_LORAWAN (1)
202 //#define RADIOLIB_EXCLUDE_LR11X0 (1)
203 //#define RADIOLIB_EXCLUDE_FSK4 (1)
204 //#define RADIOLIB_EXCLUDE_PAGER (1)
205
206#elif defined(__AVR__) && !(defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) || defined(ARDUINO_ARCH_MEGAAVR))
207 // Arduino AVR boards (except for megaAVR) - Uno, Mega etc.
208 #define RADIOLIB_PLATFORM "Arduino AVR"
209
210 #if !(defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
211 #define RADIOLIB_LOWEND_PLATFORM
212 #endif
213
214#elif defined(ESP8266)
215 // ESP8266 boards
216 #define RADIOLIB_PLATFORM "ESP8266"
217
218#elif defined(ESP32) || defined(ARDUINO_ARCH_ESP32)
219 #define RADIOLIB_ESP32
220
221 // ESP32 boards
222 #define RADIOLIB_PLATFORM "ESP32"
223
224 // ESP32 doesn't support tone(), but it can be emulated via LED control peripheral
225 #define RADIOLIB_TONE_UNSUPPORTED
226 #define RADIOLIB_TONE_ESP32_CHANNEL (1)
227
228#elif defined(ARDUINO_ARCH_STM32)
229 // official STM32 Arduino core (https://github.com/stm32duino/Arduino_Core_STM32)
230 #define RADIOLIB_PLATFORM "Arduino STM32 (official)"
231
232#elif defined(SAMD_SERIES)
233 // Adafruit SAMD boards (M0 and M4)
234 #define RADIOLIB_PLATFORM "Adafruit SAMD"
235
236#elif defined(ARDUINO_ARCH_SAMD)
237 // Arduino SAMD (Zero, MKR, etc.)
238 #define RADIOLIB_PLATFORM "Arduino SAMD"
239 #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST (PinMode)
240 #define RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST (PinStatus)
241 #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST (PinStatus)
242
243#elif defined(__SAM3X8E__)
244 // Arduino Due
245 #define RADIOLIB_PLATFORM "Arduino Due"
246 #define RADIOLIB_TONE_UNSUPPORTED
247
248#elif (defined(NRF52832_XXAA) || defined(NRF52840_XXAA)) && !defined(ARDUINO_ARDUINO_NANO33BLE)
249 // Adafruit nRF52 boards
250 #define RADIOLIB_PLATFORM "Adafruit nRF52"
251
252#elif defined(ARDUINO_ARC32_TOOLS)
253 // Intel Curie
254 #define RADIOLIB_PLATFORM "Intel Curie"
255
256#elif defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) || defined(PORTDUINO)
257 // Arduino megaAVR boards - Uno Wifi Rev.2, Nano Every
258 #define RADIOLIB_PLATFORM "Arduino megaAVR"
259 #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST (PinMode)
260 #define RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST (PinStatus)
261 #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST (PinStatus)
262
263#elif defined(ARDUINO_ARCH_APOLLO3)
264 // Sparkfun Apollo3 boards
265 #define RADIOLIB_PLATFORM "Sparkfun Apollo3"
266 #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST (Arduino_PinMode)
267 #define RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST (PinStatus)
268 #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST (PinStatus)
269
270#elif defined(ARDUINO_ARDUINO_NANO33BLE)
271 // Arduino Nano 33 BLE
272 #define RADIOLIB_PLATFORM "Arduino Nano 33 BLE"
273 #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST (PinMode)
274 #define RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST (PinStatus)
275 #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST (PinStatus)
276
277 #if defined(ARDUINO_ARCH_MBED)
278 // Arduino mbed OS boards have a really bad tone implementation which will crash after a couple seconds
279 #define RADIOLIB_TONE_UNSUPPORTED
280 #define RADIOLIB_MBED_TONE_OVERRIDE
281 #endif
282
283#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7)
284 // Arduino Portenta H7
285 #define RADIOLIB_PLATFORM "Portenta H7"
286 #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST (PinMode)
287 #define RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST (PinStatus)
288 #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST (PinStatus)
289
290 #if defined(ARDUINO_ARCH_MBED)
291 // Arduino mbed OS boards have a really bad tone implementation which will crash after a couple seconds
292 #define RADIOLIB_TONE_UNSUPPORTED
293 #define RADIOLIB_MBED_TONE_OVERRIDE
294 #endif
295
296#elif defined(__STM32F4__) || defined(__STM32F1__)
297 // Arduino STM32 core by Roger Clark (https://github.com/rogerclarkmelbourne/Arduino_STM32)
298 #define RADIOLIB_PLATFORM "STM32duino (unofficial)"
299 #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST (WiringPinMode)
300 #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST (ExtIntTriggerMode)
301
302#elif defined(ARDUINO_ARCH_MEGAAVR)
303 // MegaCoreX by MCUdude (https://github.com/MCUdude/MegaCoreX)
304 #define RADIOLIB_PLATFORM "MegaCoreX"
305
306#elif defined(ARDUINO_ARCH_MBED_RP2040)
307 // Raspberry Pi Pico (official mbed core)
308 #define RADIOLIB_PLATFORM "Raspberry Pi Pico"
309 #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST (PinMode)
310 #define RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST (PinStatus)
311 #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST (PinStatus)
312
313 // Arduino mbed OS boards have a really bad tone implementation which will crash after a couple seconds
314 #define RADIOLIB_TONE_UNSUPPORTED
315 #define RADIOLIB_MBED_TONE_OVERRIDE
316
317#elif defined(ARDUINO_ARCH_RP2040)
318 // Raspberry Pi Pico (unofficial core)
319 #define RADIOLIB_PLATFORM "Raspberry Pi Pico (unofficial)"
320 #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST (PinMode)
321 #define RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST (PinStatus)
322 #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST (PinStatus)
323
324#elif defined(__ASR6501__) || defined(ARDUINO_ARCH_ASR650X) || defined(DARDUINO_ARCH_ASR6601)
325 // CubeCell
326 #define RADIOLIB_PLATFORM "CubeCell"
327 #define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(1000000, MSBFIRST, SPI_MODE0) // see issue #709
328 #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST (PINMODE)
329 #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST (IrqModes)
330
331 // CubeCell doesn't seem to define nullptr, let's do something like that now
332 #define nullptr NULL
333
334 // ... and also defines pinMode() as a macro, which is by far the stupidest thing I have seen on Arduino
335 #undef pinMode
336
337 // ... and uses an outdated GCC which does not support type aliases
338 #define RADIOLIB_TYPE_ALIAS(type, alias) typedef class type alias;
339
340 // ... and it also has no tone(). This platform was designed by an idiot.
341 #define RADIOLIB_TONE_UNSUPPORTED
342
343 // ... AND as the (hopefully) final nail in the coffin, IT F*CKING DEFINES YIELD() AS A MACRO THAT DOES NOTHING!!!
344 #define RADIOLIB_YIELD_UNSUPPORTED
345 #if defined(yield)
346 #undef yield
347 #endif
348
349#elif defined(RASPI)
350 // RaspiDuino framework (https://github.com/me-no-dev/RasPiArduino)
351 #define RADIOLIB_PLATFORM "RasPiArduino"
352
353 // let's start off easy - no tone on this platform, that can happen
354 #define RADIOLIB_TONE_UNSUPPORTED
355
356 // hmm, no yield either - weird on something like Raspberry PI, but sure, we can handle it
357 #define RADIOLIB_YIELD_UNSUPPORTED
358
359 // aight, getting to the juicy stuff - PGM_P seems missing, that's the first time
360 #define PGM_P const char *
361
362 // ... and for the grand finale, we have millis() and micros() DEFINED AS MACROS!
363 #if defined(millis)
364 #undef millis
365 inline RadioLibTime_t millis() { return((RadioLibTime_t)(STCV / 1000)); };
366 #endif
367
368 #if defined(micros)
369 #undef micros
370 inline RadioLibTime_t micros() { return((RadioLibTime_t)(STCV)); };
371 #endif
372
373#elif defined(TEENSYDUINO)
374 // Teensy
375 #define RADIOLIB_PLATFORM "Teensy"
376
377#elif defined(ARDUINO_ARCH_RENESAS)
378 // Arduino Renesas (UNO R4)
379 #define RADIOLIB_PLATFORM "Arduino Renesas (UNO R4)"
380 #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST (PinMode)
381 #define RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST (PinStatus)
382 #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST (PinStatus)
383
384#elif defined(ARDUINO_ARCH_SILABS)
385 // Silicon Labs Arduino
386 #define RADIOLIB_PLATFORM "Arduino Silicon Labs"
387 #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST (PinMode)
388 #define RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST (PinStatus)
389 #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST (PinStatus)
390
391#elif defined(ARDUINO_ARCH_ZEPHYR) && defined(ARDUINO_UNO_Q)
392 // Arduino Uno Q (Zephyr OS)
393 #define RADIOLIB_PLATFORM "Arduino Uno Q (Zephyr OS)"
394 #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST (PinMode)
395 #define RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST (PinStatus)
396 #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST (PinStatus)
397
398#else
399 // other Arduino platforms not covered by the above list - this may or may not work
400 #define RADIOLIB_PLATFORM "Unknown Arduino"
401 #define RADIOLIB_UNKNOWN_PLATFORM
402
403#endif
404
405 // set the default values for all macros
406 // these will be applied if they were not defined above
407 #if !defined(RADIOLIB_NC)
408 #define RADIOLIB_NC (0xFFFFFFFF)
409 #endif
410
411 #if !defined(RADIOLIB_DEFAULT_SPI)
412 #define RADIOLIB_DEFAULT_SPI SPI
413 #endif
414
415 #if !defined(RADIOLIB_DEFAULT_SPI_SETTINGS)
416 #define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
417 #endif
418
419 #if !defined(RADIOLIB_NONVOLATILE)
420 #define RADIOLIB_NONVOLATILE PROGMEM
421 #endif
422
423 #if !defined(RADIOLIB_NONVOLATILE_PTR)
424 #define RADIOLIB_NONVOLATILE_PTR PGM_P
425 #endif
426
427 #if !defined(RADIOLIB_NONVOLATILE_READ_BYTE)
428 #define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
429 #endif
430
431 #if !defined(RADIOLIB_NONVOLATILE_READ_DWORD)
432 #define RADIOLIB_NONVOLATILE_READ_DWORD(addr) pgm_read_dword(addr)
433 #endif
434
435 #if !defined(RADIOLIB_TYPE_ALIAS)
436 #define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
437 #endif
438
439 #if !defined(RADIOLIB_ARDUINOHAL_PIN_MODE_CAST)
440 #define RADIOLIB_ARDUINOHAL_PIN_MODE_CAST
441 #endif
442
443 #if !defined(RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST)
444 #define RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST
445 #endif
446
447 #if !defined(RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST)
448 #define RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST
449 #endif
450
451#else
452 // generic non-Arduino platform
453 #define RADIOLIB_PLATFORM "Generic"
454
455 #define RADIOLIB_NC (0xFFFFFFFF)
456 #define RADIOLIB_NONVOLATILE
457 #define RADIOLIB_NONVOLATILE_READ_BYTE(addr) (*(reinterpret_cast<uint8_t *>(reinterpret_cast<void *>(addr))))
458 #define RADIOLIB_NONVOLATILE_READ_DWORD(addr) (*(reinterpret_cast<uint32_t *>(reinterpret_cast<void *>(addr))))
459 #define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
460
461 #define DEC 10
462 #define HEX 16
463 #define OCT 8
464 #define BIN 2
465
466 #include <stdint.h>
467
468#endif
469
470// This only compiles on STM32 boards with SUBGHZ module, but also
471// include when generating docs
472#if (!defined(ARDUINO_ARCH_STM32) || !defined(SUBGHZSPI_BASE)) && !defined(DOXYGEN)
473 #define RADIOLIB_EXCLUDE_STM32WLX (1)
474#endif
475
476// if verbose assert is enabled, enable basic debug too
477#if RADIOLIB_VERBOSE_ASSERT
478 #define RADIOLIB_DEBUG (1)
479#endif
480
481// set the global debug mode flag
482#if RADIOLIB_DEBUG_BASIC || RADIOLIB_DEBUG_PROTOCOL || RADIOLIB_DEBUG_SPI
483 #define RADIOLIB_DEBUG (1)
484#else
485 #define RADIOLIB_DEBUG (0)
486#endif
487
488#if RADIOLIB_DEBUG
489 #if !defined(RADIOLIB_DEBUG_PRINT)
490 #define RADIOLIB_DEBUG_PRINT(M, ...) rlb_printf(false, M, ##__VA_ARGS__)
491 #define RADIOLIB_DEBUG_PRINT_LVL(LEVEL, M, ...) rlb_printf(true, LEVEL "" M, ##__VA_ARGS__)
492 #endif
493
494 #if !defined(RADIOLIB_DEBUG_PRINTLN)
495 #define RADIOLIB_DEBUG_PRINTLN(M, ...) rlb_printf(false, M RADIOLIB_LINE_FEED, ##__VA_ARGS__)
496 #define RADIOLIB_DEBUG_PRINTLN_LVL(LEVEL, M, ...) rlb_printf(true, LEVEL "" M RADIOLIB_LINE_FEED, ##__VA_ARGS__)
497 #endif
498
499 // some Arduino platforms do not support printf("%f"), so it has to be done this way
500 #if defined(RADIOLIB_BUILD_ARDUINO)
501 #define RADIOLIB_DEBUG_PRINT_FLOAT(LEVEL, VAL, DECIMALS) RADIOLIB_DEBUG_PRINT(LEVEL); RADIOLIB_DEBUG_PORT.print(VAL, DECIMALS)
502 #else
503 #define RADIOLIB_DEBUG_PRINT_FLOAT(LEVEL, VAL, DECIMALS) RADIOLIB_DEBUG_PRINT(LEVEL "%.3f", VAL)
504 #endif
505
506 #define RADIOLIB_DEBUG_HEXDUMP(LEVEL, ...) rlb_hexdump(LEVEL, __VA_ARGS__)
507#else
508 #define RADIOLIB_DEBUG_PRINT(...) {}
509 #define RADIOLIB_DEBUG_PRINTLN(...) {}
510 #define RADIOLIB_DEBUG_PRINT_FLOAT(LEVEL, VAL, DECIMALS) {}
511 #define RADIOLIB_DEBUG_HEXDUMP(...) {}
512#endif
513
514#define RADIOLIB_DEBUG_TAG ": "
515#define RADIOLIB_DEBUG_TAG_BASIC "RLB_DBG" RADIOLIB_DEBUG_TAG
516#define RADIOLIB_DEBUG_TAG_PROTOCOL "RLB_PRO" RADIOLIB_DEBUG_TAG
517#define RADIOLIB_DEBUG_TAG_SPI "RLB_SPI" RADIOLIB_DEBUG_TAG
518
519#if RADIOLIB_DEBUG_BASIC
520 #define RADIOLIB_DEBUG_BASIC_PRINT(...) RADIOLIB_DEBUG_PRINT_LVL(RADIOLIB_DEBUG_TAG_BASIC, __VA_ARGS__)
521 #define RADIOLIB_DEBUG_BASIC_PRINTLN(...) RADIOLIB_DEBUG_PRINTLN_LVL(RADIOLIB_DEBUG_TAG_BASIC, __VA_ARGS__)
522 #define RADIOLIB_DEBUG_BASIC_HEXDUMP(...) RADIOLIB_DEBUG_HEXDUMP(RADIOLIB_DEBUG_TAG_BASIC, __VA_ARGS__)
523 #define RADIOLIB_DEBUG_BASIC_PRINT_FLOAT(...) RADIOLIB_DEBUG_PRINT_FLOAT(RADIOLIB_DEBUG_TAG_BASIC, __VA_ARGS__)
524 #define RADIOLIB_DEBUG_BASIC_PRINT_NOTAG(...) RADIOLIB_DEBUG_PRINT(__VA_ARGS__)
525 #define RADIOLIB_DEBUG_BASIC_PRINTLN_NOTAG(...) RADIOLIB_DEBUG_PRINTLN(__VA_ARGS__)
526#else
527 #define RADIOLIB_DEBUG_BASIC_PRINT(...) {}
528 #define RADIOLIB_DEBUG_BASIC_PRINTLN(...) {}
529 #define RADIOLIB_DEBUG_BASIC_HEXDUMP(...) {}
530 #define RADIOLIB_DEBUG_BASIC_PRINT_FLOAT(...) {}
531 #define RADIOLIB_DEBUG_BASIC_PRINT_NOTAG(...) {}
532 #define RADIOLIB_DEBUG_BASIC_PRINTLN_NOTAG(...) {}
533#endif
534
535#if RADIOLIB_DEBUG_PROTOCOL
536 #define RADIOLIB_DEBUG_PROTOCOL_PRINT(...) RADIOLIB_DEBUG_PRINT_LVL(RADIOLIB_DEBUG_TAG_PROTOCOL, __VA_ARGS__)
537 #define RADIOLIB_DEBUG_PROTOCOL_PRINTLN(...) RADIOLIB_DEBUG_PRINTLN_LVL(RADIOLIB_DEBUG_TAG_PROTOCOL, __VA_ARGS__)
538 #define RADIOLIB_DEBUG_PROTOCOL_HEXDUMP(...) RADIOLIB_DEBUG_HEXDUMP(RADIOLIB_DEBUG_TAG_PROTOCOL, __VA_ARGS__)
539 #define RADIOLIB_DEBUG_PROTOCOL_PRINT_FLOAT(...) RADIOLIB_DEBUG_PRINT_FLOAT(RADIOLIB_DEBUG_TAG_PROTOCOL, __VA_ARGS__)
540 #define RADIOLIB_DEBUG_PROTOCOL_PRINT_NOTAG(...) RADIOLIB_DEBUG_PRINT(__VA_ARGS__)
541 #define RADIOLIB_DEBUG_PROTOCOL_PRINTLN_NOTAG(...) RADIOLIB_DEBUG_PRINTLN(__VA_ARGS__)
542#else
543 #define RADIOLIB_DEBUG_PROTOCOL_PRINT(...) {}
544 #define RADIOLIB_DEBUG_PROTOCOL_PRINTLN(...) {}
545 #define RADIOLIB_DEBUG_PROTOCOL_HEXDUMP(...) {}
546 #define RADIOLIB_DEBUG_PROTOCOL_PRINT_FLOAT(...) {}
547 #define RADIOLIB_DEBUG_PROTOCOL_PRINT_NOTAG(...) {}
548 #define RADIOLIB_DEBUG_PROTOCOL_PRINTLN_NOTAG(...) {}
549#endif
550
551#if RADIOLIB_DEBUG_SPI
552 #define RADIOLIB_DEBUG_SPI_PRINT(...) RADIOLIB_DEBUG_PRINT_LVL(RADIOLIB_DEBUG_TAG_SPI, __VA_ARGS__)
553 #define RADIOLIB_DEBUG_SPI_PRINTLN(...) RADIOLIB_DEBUG_PRINTLN_LVL(RADIOLIB_DEBUG_TAG_SPI, __VA_ARGS__)
554 #define RADIOLIB_DEBUG_SPI_HEXDUMP(...) RADIOLIB_DEBUG_HEXDUMP(RADIOLIB_DEBUG_TAG_SPI, __VA_ARGS__)
555 #define RADIOLIB_DEBUG_SPI_PRINT_FLOAT(...) RADIOLIB_DEBUG_PRINT_FLOAT(RADIOLIB_DEBUG_TAG_SPI, __VA_ARGS__)
556 #define RADIOLIB_DEBUG_SPI_PRINT_NOTAG(...) RADIOLIB_DEBUG_PRINT(__VA_ARGS__)
557 #define RADIOLIB_DEBUG_SPI_PRINTLN_NOTAG(...) RADIOLIB_DEBUG_PRINTLN(__VA_ARGS__)
558#else
559 #define RADIOLIB_DEBUG_SPI_PRINT(...) {}
560 #define RADIOLIB_DEBUG_SPI_PRINTLN(...) {}
561 #define RADIOLIB_DEBUG_SPI_HEXDUMP(...) {}
562 #define RADIOLIB_DEBUG_SPI_PRINT_FLOAT(...) {}
563 #define RADIOLIB_DEBUG_SPI_PRINT_NOTAG(...) {}
564 #define RADIOLIB_DEBUG_SPI_PRINTLN_NOTAG(...) {}
565#endif
566
567// debug info strings
568#define RADIOLIB_VALUE_TO_STRING(x) #x
569#define RADIOLIB_VALUE(x) RADIOLIB_VALUE_TO_STRING(x)
570
571#define RADIOLIB_INFO "\r\nRadioLib Info\nVersion: \"" \
572 RADIOLIB_VALUE(RADIOLIB_VERSION_MAJOR) "." \
573 RADIOLIB_VALUE(RADIOLIB_VERSION_MINOR) "." \
574 RADIOLIB_VALUE(RADIOLIB_VERSION_PATCH) "." \
575 RADIOLIB_VALUE(RADIOLIB_VERSION_EXTRA) "\"\r\n" \
576 "Platform: " RADIOLIB_VALUE(RADIOLIB_PLATFORM) "\r\n" \
577 RADIOLIB_VALUE(__DATE__) " " RADIOLIB_VALUE(__TIME__)
578
584#if RADIOLIB_VERBOSE_ASSERT
585#define RADIOLIB_ASSERT(STATEVAR) { if((STATEVAR) != RADIOLIB_ERR_NONE) { RADIOLIB_DEBUG_BASIC_PRINTLN("%d at %s:%d", STATEVAR, __FILE__, __LINE__); return(STATEVAR); } }
586#define RADIOLIB_ASSERT_PTR(PTR) { if((PTR) == NULL) { RADIOLIB_DEBUG_BASIC_PRINTLN("NULL at %s:%d", __FILE__, __LINE__); return(RADIOLIB_ERR_MEMORY_ALLOCATION_FAILED); } }
587#else
588#define RADIOLIB_ASSERT(STATEVAR) { if((STATEVAR) != RADIOLIB_ERR_NONE) { return(STATEVAR); } }
589#define RADIOLIB_ASSERT_PTR(PTR) { if((PTR) == NULL) { return(RADIOLIB_ERR_MEMORY_ALLOCATION_FAILED); } }
590#endif
591
595#if RADIOLIB_CHECK_PARAMS
596 #define RADIOLIB_CHECK_RANGE(VAR, MIN, MAX, ERR) { if(!(((VAR) >= (MIN)) && ((VAR) <= (MAX)))) { return(ERR); } }
597#else
598 #define RADIOLIB_CHECK_RANGE(VAR, MIN, MAX, ERR) {}
599#endif
600
601#if RADIOLIB_FIX_ERRATA_SX127X
602 #define RADIOLIB_ERRATA_SX127X(...) { errataFix(__VA_ARGS__); }
603#else
604 #define RADIOLIB_ERRATA_SX127X(...) {}
605#endif
606
607// these macros are usually defined by Arduino, but some platforms undef them, so its safer to use our own
608#define RADIOLIB_MIN(a,b) ((a)<(b)?(a):(b))
609#define RADIOLIB_MAX(a,b) ((a)>(b)?(a):(b))
610#define RADIOLIB_ABS(x) ((x)>0?(x):-(x))
611
612// version definitions
613#define RADIOLIB_VERSION_MAJOR 7
614#define RADIOLIB_VERSION_MINOR 4
615#define RADIOLIB_VERSION_PATCH 0
616#define RADIOLIB_VERSION_EXTRA 0
617
618#define RADIOLIB_VERSION (((RADIOLIB_VERSION_MAJOR) << 24) | ((RADIOLIB_VERSION_MINOR) << 16) | ((RADIOLIB_VERSION_PATCH) << 8) | (RADIOLIB_VERSION_EXTRA))
619
620#endif
unsigned long RadioLibTime_t
Type used for durations in RadioLib.
Definition TypeDef.h:647