Updated printable to reduce mutex operations when printing newlines

This commit is contained in:
dario
2024-06-26 11:29:23 +02:00
parent ad4e77a7be
commit d4f03a9249
7 changed files with 126 additions and 72 deletions

View File

@@ -19,7 +19,7 @@ namespace sta
*
* @ingroup sta_core_debug
*/
# define STA_DEBUG_PRINT(...) sta::Debug->print(__VA_ARGS__)
# define STA_DEBUG_PRINT(...) sta::Debug->print(__VA_ARGS__)
/**
* @brief Debug print message followed by new-line to UART.
@@ -28,7 +28,7 @@ namespace sta
*
* @ingroup sta_core_debug
*/
# define STA_DEBUG_PRINTLN(...) sta::Debug->println(__VA_ARGS__)
# define STA_DEBUG_PRINTLN(...) sta::Debug->println(__VA_ARGS__)
/**
* @brief Formatted debug printing with new-line.
@@ -36,13 +36,16 @@ namespace sta
* @param fmt See @ref sta::PrintableUART::printf
* @param ... See @ref sta::PrintableUART::printf
*/
# define STA_DEBUG_PRINTF(fmt, ...) sta::Debug->printf(fmt, __VA_ARGS__)
# define STA_DEBUG_PRINTF(fmt, ...) sta::Debug->printf(fmt, __VA_ARGS__)
# define STA_DEBUG_READ(buffer, length) sta::Debug->read(buffer, length)
#else // !STA_DEBUGGING_ENABLED
# define STA_DEBUG_PRINT(...) ((void)0)
# define STA_DEBUG_PRINTLN(...) ((void)0)
# define STA_DEBUG_PRINTF(fmt, ...) ((void)0)
# define STA_DEBUG_PRINT(...) ((void)0)
# define STA_DEBUG_PRINTLN(...) ((void)0)
# define STA_DEBUG_PRINTF(fmt, ...) ((void)0)
# define STA_DEBUG_READ(buffer, length) ((void)0)
#endif // STA_DEBUGGING_ENABLED

View File

@@ -40,62 +40,70 @@ namespace sta
/**
* @brief Print single character.
*
* @param c Character to print
* @param c Character to print
* @param newline If true, send a \r\n to start a new line.
*/
void print(char c);
void print(char c, bool newline = false);
/**
* @brief Print boolean value.
*
* @param b Boolean value
* @param b Boolean value
* @param newline If true, send a \r\n to start a new line.
*/
void print(bool b);
void print(bool b, bool newline = false);
/**
* @brief Print floating point value.
*
* @param d Floating point value
* @param d Floating point value
* @param newline If true, send a \r\n to start a new line.
*/
void print(double d);
void print(double d, bool newline = false);
/**
* @brief Print integer in selected base.
*
* @param num 8-bit unsigned integer
* @param base Integer base
* @param num 8-bit unsigned integer
* @param base Integer base
* @param newline If true, send a \r\n to start a new line.
*/
void print(uint8_t num, IntegerBase base = IntegerBase::DEC);
void print(uint8_t num, IntegerBase base = IntegerBase::DEC, bool newline = false);
/**
* @brief Print integer in selected base.
*
* @param num 16-bit unsigned integer
* @param base Integer base
* @param num 16-bit unsigned integer
* @param base Integer base
* @param newline If true, send a \r\n to start a new line.
*/
void print(uint16_t num, IntegerBase base = IntegerBase::DEC);
void print(uint16_t num, IntegerBase base = IntegerBase::DEC, bool newline = false);
/**
* @brief Print integer in selected base.
*
* @param num 32-bit unsigned integer
* @param base Integer base
* @param num 32-bit unsigned integer
* @param base Integer base
* @param newline If true, send a \r\n to start a new line.
*/
void print(uint32_t num, IntegerBase base = IntegerBase::DEC);
void print(uint32_t num, IntegerBase base = IntegerBase::DEC, bool newline = false);
/**
* @brief Print c-string.
*
* @param str Null terminated string
* @param str Null terminated string
* @param newline If true, send a \r\n to start a new line.
*/
void print(const char * str);
void print(const char * str, bool newline = false);
/**
* @brief Print string.
*
* @param str String buffer
* @param length String length
* @param newline If true, send a \r\n to start a new line.
*/
virtual void print(const char * str, size_t length) = 0;
virtual void print(const char * str, size_t length, bool newline = false) = 0;
/**
* @brief Print new-line.
@@ -161,6 +169,14 @@ namespace sta
* @param length String length
*/
void println(const char * str, size_t length);
public:
/**
* @brief Read string.
*
* @param str String buffer
* @param length String length
*/
virtual void read(char* str, size_t length) = 0;
private:
/**
@@ -170,32 +186,36 @@ namespace sta
* @param base Integer base
* @param fmt printf format string for base 10
* @param size Size of value in bytes
* @param newline If true, send a \r\n to start a new line.
*/
void printBase(uintmax_t value, IntegerBase base, const char * fmt, size_t size);
void printBase(uintmax_t value, IntegerBase base, const char * fmt, size_t size, bool newline = false);
/**
* @brief Print unsigned integer in base 10.
*
* @param value Unsigned integer value
* @param fmt printf format string
* @param newline If true, send a \r\n to start a new line.
*/
void printDec(uintmax_t value, const char * fmt);
void printDec(uintmax_t value, const char * fmt, bool newline = false);
/**
* @brief Print unsigned integer in base 2.
*
* @param value Unsigned integer value
* @param digits Number of digits to print
* @param newline If true, send a \r\n to start a new line.
*/
void printBin(uintmax_t value, size_t digits);
void printBin(uintmax_t value, size_t digits, bool newline = false);
/**
* @brief Print unsigned integer in base 16.
*
* @param value Unsigned integer value
* @param digits Number of digits to print
* @param newline If true, send a \r\n to start a new line.
*/
void printHex(uintmax_t value, size_t digits);
void printHex(uintmax_t value, size_t digits, bool newline = false);
};
} // namespace sta

View File

@@ -23,8 +23,17 @@ namespace sta
*
* @param str String buffer
* @param length String length
* @param newline If true, send a \r\n to start a new line.
*/
void print(const char * str, size_t length) override;
void print(const char * str, size_t length, bool newline = false) override;
/**
* @brief Print string.
*
* @param str String buffer
* @param length String length
*/
void read(char * str, size_t length) override;
};
} // namespace sta

View File

@@ -32,8 +32,17 @@ namespace sta
*
* @param str String buffer
* @param length String length
* @param newline If true, send a \r\n to start a new line.
*/
void print(const char * str, size_t length) override;
void print(const char * str, size_t length, bool newline = false) override;
/**
* @brief Read string.
*
* @param str String buffer
* @param length String length
*/
void read(char * str, size_t length) override;
private:
UART * intf_;