mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-08-05 18:21:54 +00:00
Separate print methods from UART interface
This commit is contained in:
@@ -30,22 +30,20 @@
|
||||
|
||||
#ifdef STA_DEBUG_SERIAL_ENABLE
|
||||
|
||||
#include <sta/intf/uart.hpp>
|
||||
#include <sta/printable_uart.hpp>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
extern UART * const DebugSerial;
|
||||
extern PrintableUART DebugSerial;
|
||||
} // namespace sta
|
||||
|
||||
|
||||
# define STA_DEBUG_PRINT(...) sta::DebugSerial->print(__VA_ARGS__)
|
||||
# define STA_DEBUG_PRINTLN(...) sta::DebugSerial->println(__VA_ARGS__)
|
||||
# define STA_DEBUG_WRITE(b, s) sta::DebugSerial->write(b, s)
|
||||
# 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)
|
||||
# define STA_DEBUG_WRITE(b, s) ((void)0)
|
||||
#endif // !STA_DEBUG_SERIAL_ENABLE
|
||||
|
||||
#endif // STA_DEBUG_SERIAL_HPP
|
||||
|
@@ -28,8 +28,6 @@ namespace sta
|
||||
*/
|
||||
HalUART(UART_HandleTypeDef * handle);
|
||||
|
||||
using UART::print;
|
||||
|
||||
void write(const uint8_t * buffer, size_t size) override;
|
||||
|
||||
private:
|
||||
|
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* @brief UART interface definition.
|
||||
*/
|
||||
#ifndef STA_UART_HPP
|
||||
#define STA_UART_HPP
|
||||
#ifndef STA_INTF_UART_HPP
|
||||
#define STA_INTF_UART_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
@@ -10,148 +10,12 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Integer representation.
|
||||
*/
|
||||
enum class IntegerBase
|
||||
{
|
||||
DEC, /**< Decimal */
|
||||
BIN, /**< Binary */
|
||||
HEX /**< Hexadecimal */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for UART.
|
||||
*/
|
||||
class UART
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Print single character.
|
||||
*
|
||||
* @param c Character to print
|
||||
*/
|
||||
void print(char c);
|
||||
/**
|
||||
* @brief Print boolean value.
|
||||
*
|
||||
* @param b Boolean value
|
||||
*/
|
||||
void print(bool b);
|
||||
/**
|
||||
* @brief Print floating point value.
|
||||
*
|
||||
* @param d Floating point value
|
||||
*/
|
||||
void print(double d);
|
||||
/**
|
||||
* @brief Print integer in selected base.
|
||||
*
|
||||
* @param num 8-bit unsigned integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void print(uint8_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print integer in selected base.
|
||||
*
|
||||
* @param num 16-bit unsigned integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void print(uint16_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print integer in selected base.
|
||||
*
|
||||
* @param num 32-bit unsigned integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void print(uint32_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print integer in selected base.
|
||||
*
|
||||
* @param num Integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void print(size_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print c-string.
|
||||
*
|
||||
* @param str Null terminated string
|
||||
*/
|
||||
void print(const char * str);
|
||||
/**
|
||||
* @brief Print string.
|
||||
*
|
||||
* @param str String buffer
|
||||
* @parma length String length
|
||||
*/
|
||||
void print(const char * str, size_t length);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Print new-line.
|
||||
*/
|
||||
void println();
|
||||
/**
|
||||
* @brief Print single character followed by a new-line.
|
||||
*
|
||||
* @param c Character to print
|
||||
*/
|
||||
void println(char c);
|
||||
/**
|
||||
* @brief Print boolean value followed by a new-line.
|
||||
*
|
||||
* @param b Boolean value
|
||||
*/
|
||||
void println(bool b);
|
||||
/**
|
||||
* @brief Print floating point value followed by a new-line.
|
||||
*
|
||||
* @param d Floating point value
|
||||
*/
|
||||
void println(double d);
|
||||
/**
|
||||
* @brief Print integer in selected base followed by a new-line.
|
||||
*
|
||||
* @param num 8-bit unsigned integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void println(uint8_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print integer in selected base followed by a new-line.
|
||||
*
|
||||
* @param num 16-bit unsigned integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void println(uint16_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print integer in selected base followed by a new-line.
|
||||
*
|
||||
* @param num 32-bit unsigned integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void println(uint32_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print integer in selected base followed by a new-line.
|
||||
*
|
||||
* @param num Integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void println(size_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print c-string followed by a new-line.
|
||||
*
|
||||
* @param str Null terminated string
|
||||
*/
|
||||
void println(const char * str);
|
||||
/**
|
||||
* @brief Print string followed by a new-line.
|
||||
*
|
||||
* @param str String buffer
|
||||
* @parma length String length
|
||||
*/
|
||||
void println(const char * str, size_t length);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Write buffer to UART.
|
||||
*
|
||||
@@ -160,39 +24,26 @@ namespace sta
|
||||
*/
|
||||
virtual void write(const uint8_t * buffer, size_t size) = 0;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Print unsigned integer in selected base.
|
||||
* @brief Write unsigned integer to UART.
|
||||
*
|
||||
* @param value Unsigned integer value
|
||||
* @param base Integer base
|
||||
* @param fmt printf format string for base 10
|
||||
* @param size Size of value in bytes
|
||||
*/
|
||||
void printBase(uintmax_t value, IntegerBase base, const char * fmt, size_t size);
|
||||
void write(uint8_t value);
|
||||
/**
|
||||
* @brief Print unsigned integer in base 10.
|
||||
* @brief Write unsigned integer to UART.
|
||||
*
|
||||
* @param value Unsigned integer value
|
||||
* @param fmt printf format string
|
||||
*/
|
||||
void printDec(uintmax_t value, const char * fmt);
|
||||
void write(uint16_t value);
|
||||
/**
|
||||
* @brief Print unsigned integer in base 2.
|
||||
* @brief Write unsigned integer to UART.
|
||||
*
|
||||
* @param value Unsigned integer value
|
||||
* @param digits Number of digits to print
|
||||
*/
|
||||
void printBin(uintmax_t value, size_t digits);
|
||||
/**
|
||||
* @brief Print unsigned integer in base 16.
|
||||
*
|
||||
* @param value Unsigned integer value
|
||||
* @param digits Number of digits to print
|
||||
*/
|
||||
void printHex(uintmax_t value, size_t digits);
|
||||
void write(uint32_t value);
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_UART_HPP
|
||||
#endif // STA_INTF_UART_HPP
|
||||
|
196
include/sta/printable_uart.hpp
Normal file
196
include/sta/printable_uart.hpp
Normal file
@@ -0,0 +1,196 @@
|
||||
/**
|
||||
* @brief UART interface definition.
|
||||
*/
|
||||
#ifndef STA_PRINTABLE_UART_HPP
|
||||
#define STA_PRINTABLE_UART_HPP
|
||||
|
||||
#include <sta/intf/uart.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Integer representation.
|
||||
*/
|
||||
enum class IntegerBase
|
||||
{
|
||||
DEC, /**< Decimal */
|
||||
BIN, /**< Binary */
|
||||
HEX /**< Hexadecimal */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for UART.
|
||||
*/
|
||||
class PrintableUART
|
||||
{
|
||||
public:
|
||||
PrintableUART(UART * intf);
|
||||
|
||||
/**
|
||||
* @brief Print single character.
|
||||
*
|
||||
* @param c Character to print
|
||||
*/
|
||||
void print(char c);
|
||||
/**
|
||||
* @brief Print boolean value.
|
||||
*
|
||||
* @param b Boolean value
|
||||
*/
|
||||
void print(bool b);
|
||||
/**
|
||||
* @brief Print floating point value.
|
||||
*
|
||||
* @param d Floating point value
|
||||
*/
|
||||
void print(double d);
|
||||
/**
|
||||
* @brief Print integer in selected base.
|
||||
*
|
||||
* @param num 8-bit unsigned integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void print(uint8_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print integer in selected base.
|
||||
*
|
||||
* @param num 16-bit unsigned integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void print(uint16_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print integer in selected base.
|
||||
*
|
||||
* @param num 32-bit unsigned integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void print(uint32_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print integer in selected base.
|
||||
*
|
||||
* @param num Integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void print(size_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print c-string.
|
||||
*
|
||||
* @param str Null terminated string
|
||||
*/
|
||||
void print(const char * str);
|
||||
/**
|
||||
* @brief Print string.
|
||||
*
|
||||
* @param str String buffer
|
||||
* @parma length String length
|
||||
*/
|
||||
void print(const char * str, size_t length);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Print new-line.
|
||||
*/
|
||||
void println();
|
||||
/**
|
||||
* @brief Print single character followed by a new-line.
|
||||
*
|
||||
* @param c Character to print
|
||||
*/
|
||||
void println(char c);
|
||||
/**
|
||||
* @brief Print boolean value followed by a new-line.
|
||||
*
|
||||
* @param b Boolean value
|
||||
*/
|
||||
void println(bool b);
|
||||
/**
|
||||
* @brief Print floating point value followed by a new-line.
|
||||
*
|
||||
* @param d Floating point value
|
||||
*/
|
||||
void println(double d);
|
||||
/**
|
||||
* @brief Print integer in selected base followed by a new-line.
|
||||
*
|
||||
* @param num 8-bit unsigned integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void println(uint8_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print integer in selected base followed by a new-line.
|
||||
*
|
||||
* @param num 16-bit unsigned integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void println(uint16_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print integer in selected base followed by a new-line.
|
||||
*
|
||||
* @param num 32-bit unsigned integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void println(uint32_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print integer in selected base followed by a new-line.
|
||||
*
|
||||
* @param num Integer
|
||||
* @param base Integer base
|
||||
*/
|
||||
void println(size_t num, IntegerBase base = IntegerBase::DEC);
|
||||
/**
|
||||
* @brief Print c-string followed by a new-line.
|
||||
*
|
||||
* @param str Null terminated string
|
||||
*/
|
||||
void println(const char * str);
|
||||
/**
|
||||
* @brief Print string followed by a new-line.
|
||||
*
|
||||
* @param str String buffer
|
||||
* @parma length String length
|
||||
*/
|
||||
void println(const char * str, size_t length);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Print unsigned integer in selected base.
|
||||
*
|
||||
* @param value Unsigned integer value
|
||||
* @param base Integer base
|
||||
* @param fmt printf format string for base 10
|
||||
* @param size Size of value in bytes
|
||||
*/
|
||||
void printBase(uintmax_t value, IntegerBase base, const char * fmt, size_t size);
|
||||
/**
|
||||
* @brief Print unsigned integer in base 10.
|
||||
*
|
||||
* @param value Unsigned integer value
|
||||
* @param fmt printf format string
|
||||
*/
|
||||
void printDec(uintmax_t value, const char * fmt);
|
||||
/**
|
||||
* @brief Print unsigned integer in base 2.
|
||||
*
|
||||
* @param value Unsigned integer value
|
||||
* @param digits Number of digits to print
|
||||
*/
|
||||
void printBin(uintmax_t value, size_t digits);
|
||||
/**
|
||||
* @brief Print unsigned integer in base 16.
|
||||
*
|
||||
* @param value Unsigned integer value
|
||||
* @param digits Number of digits to print
|
||||
*/
|
||||
void printHex(uintmax_t value, size_t digits);
|
||||
|
||||
private:
|
||||
UART * intf_;
|
||||
};
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_PRINTABLE_UART_HPP
|
Reference in New Issue
Block a user