Fix PROGMEM addressing in debug.h

I hate when the compiler doesn't check something what it normally does:
`pgm_read_byte` is more than happy with a parameter (*str), which reads
an address at a location where *str points to - which is obviously not the intent.
pull/126/head
D.R.racer 2021-09-28 08:57:09 +02:00 committed by DRracer
parent 236a40c6ef
commit f18ff63cf7
3 changed files with 25 additions and 10 deletions

View File

@ -22,12 +22,12 @@ const char hal[] PROGMEM = "hal:";
#endif #endif
void dbg_usart(const char *layer_P, const char *s) { 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); hu::usart1.puts(s);
} }
void dbg_usart_P(const char *layer_P, const char *s_P) { 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); hu::usart1.puts_P(s_P);
} }

View File

@ -65,18 +65,26 @@ void USART::Flush() {
// the hardware finished tranmission (TXC is set). // the hardware finished tranmission (TXC is set).
} }
void USART::puts(const char *str) { void USART::WriteS(const char *str) {
while (*str) { while (*str != 0) {
Write(*str++); 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'); Write('\n');
} }
void USART::puts_P(const char *str) { void USART::puts_P(const char *str_P) {
char c; WriteS_P(str_P);
while ((c = pgm_read_byte(*str++)) != 0) {
Write(c);
}
Write('\n'); Write('\n');
} }

View File

@ -45,12 +45,19 @@ public:
/// @param c character to be pushed into the TX buffer (to be sent) /// @param c character to be pushed into the TX buffer (to be sent)
void Write(uint8_t c); 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 /// @param str c string to be sent. NL is appended
/// Works on RAM strings /// Works on RAM strings
void puts(const char *str); void puts(const char *str);
/// @param str c string to be sent. NL is appended /// @param str c string to be sent. NL is appended
/// Works on PROGMEM strings /// 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) /// @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 { bool CanWrite() const {
return !tx_buf.full(); return !tx_buf.full();