diff --git a/src/debug.cpp b/src/debug.cpp index 40eef19..ef97ac6 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -22,12 +22,12 @@ const char hal[] PROGMEM = "hal:"; #endif void dbg_usart(const char *layer_P, const char *s) { - hu::usart1.puts_P(layer_P); + hu::usart1.WriteS_P(layer_P); hu::usart1.puts(s); } void dbg_usart_P(const char *layer_P, const char *s_P) { - hu::usart1.puts_P(layer_P); + hu::usart1.WriteS_P(layer_P); hu::usart1.puts_P(s_P); } diff --git a/src/hal/avr/usart.cpp b/src/hal/avr/usart.cpp index 6380fad..db85f0c 100644 --- a/src/hal/avr/usart.cpp +++ b/src/hal/avr/usart.cpp @@ -65,18 +65,26 @@ void USART::Flush() { // the hardware finished tranmission (TXC is set). } -void USART::puts(const char *str) { - while (*str) { +void USART::WriteS(const char *str) { + while (*str != 0) { Write(*str++); } +} + +void USART::WriteS_P(const char *str_P) { + char c = 0; + while ((c = pgm_read_byte(str_P++)) != 0) { + Write(c); + } +} + +void USART::puts(const char *str) { + WriteS(str); Write('\n'); } -void USART::puts_P(const char *str) { - char c; - while ((c = pgm_read_byte(*str++)) != 0) { - Write(c); - } +void USART::puts_P(const char *str_P) { + WriteS_P(str_P); Write('\n'); } diff --git a/src/hal/usart.h b/src/hal/usart.h index fdbfc51..43f16ba 100644 --- a/src/hal/usart.h +++ b/src/hal/usart.h @@ -45,12 +45,19 @@ public: /// @param c character to be pushed into the TX buffer (to be sent) void Write(uint8_t c); + /// @param str pointer to a string in RAM to be pushed byte-by-byte into the TX buffer (to be sent) + /// No NL character is appended + void WriteS(const char *str); + /// @param str pointer to a string in PROGMEM to be pushed byte-by-byte into the TX buffer (to be sent) + /// No NL character is appended + void WriteS_P(const char *str_P); + /// @param str c string to be sent. NL is appended /// Works on RAM strings void puts(const char *str); /// @param str c string to be sent. NL is appended /// Works on PROGMEM strings - void puts_P(const char *str); + void puts_P(const char *str_P); /// @returns true if there is at least one byte free in the TX buffer (i.e. some space to add a character to be sent) bool CanWrite() const { return !tx_buf.full();