Skip to content

Commit 13c2724

Browse files
authored
Merge pull request #3916 from willianchanlovegithub/Willianchan
[drivers/serial]add a line feed to the carriage return character when…
2 parents a5ab12c + ee3d05f commit 13c2724

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

components/drivers/serial/serial.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* 2017-11-15 JasonJia fix poll rx issue when data is full.
2323
* add TCFLSH and FIONREAD support.
2424
* 2018-12-08 Ernest Chen add DMA choice
25+
* 2020-09-14 WillianChan add a line feed to the carriage return character
26+
* when using interrupt tx
2527
*/
2628

2729
#include <rthw.h>
@@ -315,6 +317,19 @@ rt_inline int _serial_int_tx(struct rt_serial_device *serial, const rt_uint8_t *
315317

316318
while (length)
317319
{
320+
/*
321+
* to be polite with serial console add a line feed
322+
* to the carriage return character
323+
*/
324+
if (*data == '\n' && (serial->parent.open_flag & RT_DEVICE_FLAG_STREAM))
325+
{
326+
if (serial->ops->putc(serial, '\r') == -1)
327+
{
328+
rt_completion_wait(&(tx->completion), RT_WAITING_FOREVER);
329+
continue;
330+
}
331+
}
332+
318333
if (serial->ops->putc(serial, *(char*)data) == -1)
319334
{
320335
rt_completion_wait(&(tx->completion), RT_WAITING_FOREVER);

0 commit comments

Comments
 (0)