Big assert / debug clean up

This commit is contained in:
Dario
2023-07-12 14:05:51 +01:00
parent 27350f71b8
commit 6da6666559
26 changed files with 108 additions and 218 deletions

11
include/sta/config.hpp Normal file
View File

@@ -0,0 +1,11 @@
#ifndef STA_CONFIG_HPP
#define STA_CONFIG_HPP
#include <sta/devices/raspi/mcu/common.hpp>
#define STA_DEBUGGING_ENABLED
#define STA_PRINTF_USE_STDLIB
#define STA_ASSERT_FORCE
#endif // STA_CONFIG_HPP

View File

@@ -4,7 +4,7 @@
#include <sta/config.hpp>
#ifdef STA_DEBUGGING_ENABLED
#include <sta/printable.hpp>
#include <sta/debug/printing/printable.hpp>
namespace sta
{

View File

@@ -0,0 +1,28 @@
#ifndef STA_CORE_PRINTABLE_PRINTF_HPP
#define STA_CORE_PRINTABLE_PRINTF_HPP
#include <sta/debug/printing/printable.hpp>
namespace sta
{
class PrintablePrintf : public Printable
{
public:
/**
* @brief Construct a new Printable Printf object
*/
PrintablePrintf();
/**
* @brief Print string.
*
* @param str String buffer
* @param length String length
*/
void print(const char * str, size_t length) override;
};
} // namespace sta
#endif // STA_CORE_PRINTABLE_PRINTF_HPP

View File

@@ -6,7 +6,7 @@
#define STA_CORE_PRINTABLE_UART_HPP
#include <sta/bus/uart/uart.hpp>
#include <sta/printable.hpp>
#include <sta/debug/printing/printable.hpp>
#include <cstddef>
#include <cstdint>

View File

@@ -1,49 +0,0 @@
#ifndef STA_CORE_DEBUG_PRINTF_HPP
#define STA_CORE_DEBUG_PRINTF_HPP
#include <sta/config.hpp>
// Determine if module should be enabled
// Condition 1: STA_DEBUG_PRINTF is defined
// Condition 2:
// STA_DEBUG_PRINTF_FORCE is defined
// or
// DEBUG is defined but not NDEBUG
#ifdef STA_DEBUG_PRINTF
# ifdef STA_DEBUG_PRINTF_FORCE
# define STA_DEBUG_SERIAL_ENABLED
# else // !STA_DEBUG_PRINTF_FORCE
# if defined(DEBUG) && !defined(NDEBUG)
# define STA_DEBUG_PRINTF_ENABLED
# endif // DEBUG && !NDEBUG
# endif // !STA_DEBUG_PRINTF_FORCE
#endif // STA_DEBUG_PRINTF
#if defined(STA_DEBUG_PRINTF_ENABLED) || defined(DOXYGEN)
#include <sta/printable.hpp>
/**
* @brief Print debug output.
*
* @param ... See @ref sta::PrintableUART::print
*
* @ingroup sta_core_debug
*/
# define STA_DEBUG_PRINT(...) sta::print(__VA_ARGS__)
/**
* @brief Print debug output followed by new-line to UART.
*
* @param ... See @ref sta::PrintableUART::println
*
* @ingroup sta_core_debug
*/
# define STA_DEBUG_PRINTLN(...) sta::println(__VA_ARGS__)
#else // !STA_DEBUG_PRINTF_ENABLED
# define STA_DEBUG_PRINT(...) ((void)0)
# define STA_DEBUG_PRINTLN(...) ((void)0)
#endif // !STA_DEBUG_PRINTF_ENABLED
#endif // STA_CORE_DEBUG_PRINTF_HPP

View File

@@ -1,79 +0,0 @@
/**
* @file
* @brief Debug output via UART.
*
* Configuration:
* * STA_DEBUG_SERIAL_UART: UART interface for output
* * STA_DEBUG_SERIAL_FORCE: Ignore debug defines and always enable output
* * DEBUG: Enables output when defined
* * NDEBUG: Disables output when defined (overrides DEBUG)
*/
#ifndef STA_CORE_DEBUG_SERIAL_HPP
#define STA_CORE_DEBUG_SERIAL_HPP
#include <sta/config.hpp>
// Determine if module should be enabled
// Condition 1: STA_DEBUG_SERIAL_UART is defined
// Condition 2:
// STA_DEBUG_SERIAL_FORCE is defined
// or
// DEBUG is defined but not NDEBUG
#ifdef STA_DEBUG_SERIAL_UART
# ifdef STA_DEBUG_SERIAL_FORCE
# define STA_DEBUG_SERIAL_ENABLED
# else // !STA_DEBUG_SERIAL_FORCE
# if defined(DEBUG) && !defined(NDEBUG)
# define STA_DEBUG_SERIAL_ENABLED
# endif // DEBUG && !NDEBUG
# endif // !STA_DEBUG_SERIAL_FORCE
#endif // STA_DEBUG_SERIAL_UART
#if defined(STA_DEBUG_SERIAL_ENABLED) || defined(DOXYGEN)
#include <sta/printable_uart.hpp>
/**
* @defgroup sta_core_debug Debug Serial
* @ingroup sta_core
* @brief Debug serial output.
*/
namespace sta
{
/**
* @brief %UART print object for debug serial output.
*
* @ingroup sta_core_debug
*/
extern PrintableUART DebugSerial;
} // namespace sta
/**
* @brief Print debug output to UART.
*
* @param ... See @ref sta::PrintableUART::print
*
* @ingroup sta_core_debug
*/
# define STA_DEBUG_PRINT(...) sta::DebugSerial.print(__VA_ARGS__)
/**
* @brief Print debug output followed by new-line to UART.
*
* @param ... See @ref sta::PrintableUART::println
*
* @ingroup sta_core_debug
*/
# define STA_DEBUG_PRINTLN(...) sta::DebugSerial.println(__VA_ARGS__)
#else // !STA_DEBUG_SERIAL_ENABLED
# define STA_DEBUG_PRINT(...) ((void)0)
# define STA_DEBUG_PRINTLN(...) ((void)0)
#endif // !STA_DEBUG_SERIAL_ENABLED
#endif // STA_CORE_DEBUG_SERIAL_HPP

View File

@@ -12,16 +12,16 @@
namespace sta
{
enum class I2cNode {
enum class I2CNode {
DEV_1,
DEV_2
};
class RaspiI2c : public I2c
class RaspiI2C : public I2C
{
public:
RaspiI2c(I2cNode node, Mutex * mutex=nullptr, bool persistent_open=false);
~RaspiI2c();
RaspiI2C(I2CNode node, Mutex * mutex=nullptr, bool persistent_open=false);
~RaspiI2C();
void transfer(uint8_t value) override;
void transfer16(uint16_t value) override;
@@ -29,11 +29,10 @@ namespace sta
void transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size) override;
void receive(uint8_t * buffer, size_t size) override;
void fill(uint8_t value, size_t count) override;
void selectAddress(uint16_t address) override;
void acquire() override;
void release() override;
void fill(uint8_t value, size_t count) override;
private:
char * i2cdev_;
int i2cfd_;
@@ -41,9 +40,9 @@ namespace sta
const bool persistent_open_;
};
class RaspiI2cDevice : public I2cDevice
class RaspiI2CDevice : public I2CDevice
{
RaspiI2cDevice(I2c * intf, uint16_t address_10bit, Mutex* mutex=nullptr, bool master=false, bool blocking=true);
RaspiI2CDevice(RaspiI2C * intf, uint16_t address_10bit, Mutex* mutex=nullptr, bool master=false, bool blocking=true);
};
} // namespace sta