makes GPIO_PIN_RST optional for the sx1276
[ExpressLRS.git] / src / lib / logging / logging.h
blobcb05cadeaef2a8a45825988fb6ed198d19285efd
1 #ifndef DEBUG_H
2 #define DEBUG_H
4 #include "VA_OPT.h"
6 /**
7 * Debug logging macros. Define DEBUG_LOG or DEBUG_LOG_VERBOSE to enable logging,
8 * verbose adds overwhelming detail. All macros start with DBG or DBGV (for verbose)
9 * DBGCR / DBGVCR - Print newline (Serial.println())
10 * DBG / DBGV - Print messag with optional format specifier (Serial.printf(x, ...))
11 * DBGLN / DBGVLN - Same as DBG except also includes newline
12 * DBGW / DBGVW - Write a single byte to logging (Serial.write(x))
14 * Set LOGGING_UART define to Serial instance to use if not Serial
15 **/
17 // DEBUG_LOG_VERBOSE and DEBUG_RX_SCOREBOARD implies DEBUG_LOG
18 #if !defined(DEBUG_LOG)
19 #if defined(DEBUG_LOG_VERBOSE) || defined(DEBUG_RX_SCOREBOARD)
20 #define DEBUG_LOG
21 #endif
22 #endif
24 #ifndef LOGGING_UART
25 #define LOGGING_UART Serial
26 #endif
28 // #define LOG_USE_PROGMEM
30 extern void debugPrintf(const char* fmt, ...);
32 #if defined(CRSF_RCVR_NO_SERIAL) && !defined(DEBUG_LOG)
33 #define INFOLN(msg, ...)
34 #define ERRLN(msg)
35 #else
36 #define INFOLN(msg, ...) { \
37 debugPrintf(msg, ##__VA_ARGS__); \
38 LOGGING_UART.println(); \
41 #define ERRLN(msg, ...) IFNE(__VA_ARGS__)({ \
42 LOGGING_UART.print("ERROR: "); \
43 debugPrintf(msg, ##__VA_ARGS__); \
44 LOGGING_UART.println(); \
45 })(LOGGING_UART.println("ERROR: " msg))
46 #endif
48 #if defined(DEBUG_LOG)
49 #define DBGCR LOGGING_UART.println()
50 #define DBGW(c) LOGGING_UART.write(c)
51 #ifndef LOG_USE_PROGMEM
52 #define DBG(msg, ...) debugPrintf(msg, ##__VA_ARGS__)
53 #define DBGLN(msg, ...) { \
54 debugPrintf(msg, ##__VA_ARGS__); \
55 LOGGING_UART.println(); \
57 #else
58 #define DBG(msg, ...) debugPrintf(PSTR(msg), ##__VA_ARGS__)
59 #define DBGLN(msg, ...) { \
60 debugPrintf(PSTR(msg), ##__VA_ARGS__); \
61 LOGGING_UART.println(); \
63 #endif
65 // Verbose logging is for spammy stuff
66 #if defined(DEBUG_LOG_VERBOSE)
67 #define DBGVCR DBGCR
68 #define DBGVW(c) DBGW(c)
69 #define DBGV(...) DBG(__VA_ARGS__)
70 #define DBGVLN(...) DBGLN(__VA_ARGS__)
71 #else
72 #define DBGVCR
73 #define DBGVW(c)
74 #define DBGV(...)
75 #define DBGVLN(...)
76 #endif
77 #else
78 #define DBGCR
79 #define DBGW(c)
80 #define DBG(...)
81 #define DBGLN(...)
82 #define DBGVCR
83 #define DBGV(...)
84 #define DBGVLN(...)
85 #endif
87 #endif