LSH-Core
Deterministic firmware core for Controllino-based Labo Smart Home nodes
 
Loading...
Searching...
No Matches
debug.hpp
Go to the documentation of this file.
1
21#ifndef LSH_CORE_UTIL_DEBUG_DEBUG_HPP
22#define LSH_CORE_UTIL_DEBUG_DEBUG_HPP
23
27
28#ifdef LSH_DEBUG
29#include <ArduinoJson.h>
30#include "util/debug/memory.hpp"
32#endif // LSH_DEBUG
33
34namespace Debug
35{
39inline auto FPSTR(const char *const progmemString) -> const __FlashStringHelper *
40{
41 return reinterpret_cast<const __FlashStringHelper *>(progmemString);
42}
43
44#ifdef LSH_DEBUG // If in debug mode
45
50#define DP VaPrint::print
51
56#define DPL VaPrint::println
57
62__attribute__((always_inline)) inline void DSB()
63{
64 CONFIG_DEBUG_SERIAL->begin(constants::debugConfigs::DEBUG_SERIAL_BAUD);
65}
66
71#define NDSB()
72
77template <typename T> __attribute__((always_inline)) constexpr inline void DPJ(const T &json)
78{
79 serializeJson(json, *CONFIG_DEBUG_SERIAL);
80 DPL();
81}
82
87[[maybe_unused]] static void DFM()
88{
89 DPL(FPSTR(dStr::FREE_MEMORY), FPSTR(dStr::COLON_SPACE), freeMemory());
90}
91
97#define DP_CONTEXT() DPL(__PRETTY_FUNCTION__)
98
99#else // Not in debug
100
101namespace details
102{
103extern bool serialIsActive;
104} // namespace details
105
106#define DP(...)
107#define DPL(...)
108#define DSB()
109#define DPJ(x)
110#define DP_CONTEXT()
111#define DFM()
112// Non-Debug Serial Begin, turn on Serial when not in debug mode
113void NDSB();
114#endif // LSH_DEBUG
115
116} // namespace Debug
117
118#endif // LSH_CORE_UTIL_DEBUG_DEBUG_HPP
Defines build-time configurable parameters for the controller-to-bridge serial link.
Defines constants, strings, and configuration parameters used for debugging.
auto FPSTR(const char *const progmemString) -> const __FlashStringHelper *
Helper to cast a PROGMEM string to const __FlashStringHelper *, needed to print PROGMEM strings.
Definition debug.hpp:39
void NDSB()
Lazily initialize the debug serial port in non-debug builds.
Definition debug.cpp:33
bool serialIsActive
Tracks whether the fallback debug serial port was already initialized in non-debug builds.
Definition debug.cpp:25
auto freeMemory() -> size_t
Estimate the amount of free SRAM currently available on the MCU.
Definition memory.cpp:71
Declares functions to check for free memory on AVR devices.
__attribute__((noinline)) inline void deviceReset()
Performs a hardware reset using the watchdog timer.
Definition reset.hpp:36
Internal bridge that imports static profile resources into the library's scope.
Declares a variadic print utility for streamlined debugging output.