sta-core/include/sta/debug_serial.hpp
2022-05-07 16:16:19 +02:00

50 lines
1.5 KiB
C++

/**
* @brief Debug output via UART.
*
* Configuration:
* STA_DEBUG_SERIAL_ENABLE: Enable module
* STA_DEBUG_SERIAL_FORCE: Ignore debug defines and always enable output
* DEBUG: Enables output when defined
* NDEBUG: Disables output when defined (overrides DEBUG)
*
* The `sta::DebugSerial` instance must be provided.
* NOTE: Include this header before the definition because
* the default internal linkage of const namespace variables
* will cause undefined reference errors otherwise.
*/
#ifndef STA_DEBUG_SERIAL_HPP
#define STA_DEBUG_SERIAL_HPP
#include <sta/config.hpp>
// Check only if STA_DEBUG_SERIAL_FORCE is not defined
#ifndef STA_DEBUG_SERIAL_FORCE
// Disable module if NDEBUG is defined or DEBUG is not
# if defined(NDEBUG) || !defined(DEBUG)
# ifdef STA_DEBUG_SERIAL_ENABLE
# undef STA_DEBUG_SERIAL_ENABLE
# endif // STA_DEBUG_SERIAL_ENABLE
# endif // NDEBUG || !DEBUG
#endif // !STA_DEBUG_SERIAL_FORCE
#ifdef STA_DEBUG_SERIAL_ENABLE
#include <sta/printable_uart.hpp>
namespace sta
{
extern PrintableUART DebugSerial;
} // namespace sta
# define STA_DEBUG_PRINT(...) sta::DebugSerial.print(__VA_ARGS__)
# define STA_DEBUG_PRINTLN(...) sta::DebugSerial.println(__VA_ARGS__)
#else // !STA_DEBUG_SERIAL_ENABLE
# define STA_DEBUG_PRINT(...) ((void)0)
# define STA_DEBUG_PRINTLN(...) ((void)0)
#endif // !STA_DEBUG_SERIAL_ENABLE
#endif // STA_DEBUG_SERIAL_HPP