Silence unused-variable warning (#2872)
[ExpressLRS.git] / src / lib / logging / logging.h
blob9b188e66492205c448cd0215a1607f975469fa96
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) && TARGET_RX) || defined(DEBUG_INIT)
20 #define DEBUG_LOG
21 #endif
22 #endif
24 #if defined(TARGET_RX) && (defined(DEBUG_RCVR_LINKSTATS) || defined(DEBUG_RX_SCOREBOARD) || defined(DEBUG_RCVR_SIGNAL_STATS)) || defined(DEBUG_LOG)
25 #define DEBUG_ENABLED
26 #endif
28 #if defined(TARGET_TX)
29 extern Stream *TxBackpack;
30 #if defined(PLATFORM_ESP32_S3)
31 #define LOGGING_UART (Serial)
32 #else
33 #define LOGGING_UART (*TxBackpack)
34 #endif
35 #else
36 extern Stream *SerialLogger;
37 #define LOGGING_UART (*SerialLogger)
38 #endif
40 // #define LOG_USE_PROGMEM
42 void debugPrintf(const char* fmt, ...);
43 #if defined(LOG_INIT)
44 void debugCreateInitLogger();
45 void debugFreeInitLogger();
46 #else
47 #define debugCreateInitLogger()
48 #define debugFreeInitLogger()
49 #endif
51 #if defined(CRITICAL_FLASH) || ((defined(DEBUG_RCVR_LINKSTATS)) && !defined(DEBUG_LOG))
52 #define ERRLN(msg, ...)
53 #else
54 #define ERRLN(msg, ...) IFNE(__VA_ARGS__)({ \
55 LOGGING_UART.print("ERROR: "); \
56 debugPrintf(msg, ##__VA_ARGS__); \
57 LOGGING_UART.println(); \
58 },LOGGING_UART.println("ERROR: " msg))
59 #endif
61 #if defined(DEBUG_LOG) && !defined(CRITICAL_FLASH)
62 #define DBGCR LOGGING_UART.println()
63 #define DBGW(c) LOGGING_UART.write(c)
64 #ifndef LOG_USE_PROGMEM
65 #define DBG(msg, ...) debugPrintf(msg, ##__VA_ARGS__)
66 #define DBGLN(msg, ...) do { \
67 debugPrintf(msg, ##__VA_ARGS__); \
68 LOGGING_UART.println(); \
69 } while(0)
70 #else
71 #define DBG(msg, ...) debugPrintf(PSTR(msg), ##__VA_ARGS__)
72 #define DBGLN(msg, ...) { \
73 debugPrintf(PSTR(msg), ##__VA_ARGS__); \
74 LOGGING_UART.println(); \
76 #endif
78 // Verbose logging is for spammy stuff
79 #if defined(DEBUG_LOG_VERBOSE)
80 #define DBGVCR DBGCR
81 #define DBGVW(c) DBGW(c)
82 #define DBGV(...) DBG(__VA_ARGS__)
83 #define DBGVLN(...) DBGLN(__VA_ARGS__)
84 #else
85 #define DBGVCR
86 #define DBGVW(c)
87 #define DBGV(...)
88 #define DBGVLN(...)
89 #endif
90 #else
91 #define DBGCR
92 #define DBGW(c)
93 #define DBG(...)
94 #define DBGLN(...)
95 #define DBGVCR
96 #define DBGV(...)
97 #define DBGVLN(...)
98 #endif
100 #endif