mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-10 16:55:58 +00:00
204 lines
5.2 KiB
C++
204 lines
5.2 KiB
C++
/**
|
|
* @file
|
|
* @brief Printable UART interface definition.
|
|
*/
|
|
#ifndef STA_CORE_PRINTABLE_HPP
|
|
#define STA_CORE_PRINTABLE_HPP
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
|
|
|
|
namespace sta
|
|
{
|
|
/**
|
|
* @brief Integer representation.
|
|
*
|
|
* @ingroup sta_core
|
|
*/
|
|
enum class IntegerBase
|
|
{
|
|
DEC, /**< Decimal */
|
|
BIN, /**< Binary */
|
|
HEX /**< Hexadecimal */
|
|
};
|
|
|
|
/**
|
|
* @brief Printable UART interface.
|
|
*
|
|
* @ingroup sta_core
|
|
*/
|
|
class Printable
|
|
{
|
|
public:
|
|
/**
|
|
* @brief fmt The string defining the desired format.
|
|
* @brief ... The parameters for the formatted string.
|
|
*/
|
|
void printf(const char * fmt, ...);
|
|
|
|
/**
|
|
* @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 c-string.
|
|
*
|
|
* @param str Null terminated string
|
|
*/
|
|
void print(const char * str);
|
|
|
|
/**
|
|
* @brief Print string.
|
|
*
|
|
* @param str String buffer
|
|
* @param length String length
|
|
*/
|
|
virtual void print(const char * str, size_t length) = 0;
|
|
|
|
/**
|
|
* @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 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
|
|
* @param 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);
|
|
};
|
|
} // namespace sta
|
|
|
|
|
|
#endif // STA_CORE_PRINTABLE_HPP
|