From d579040e32b73b5ed7c22b9a4342027fbcea5da0 Mon Sep 17 00:00:00 2001 From: Jeroen Domburg Date: Tue, 23 Aug 2016 15:02:27 +0800 Subject: [PATCH] Add cr after a lf is printed (configurable) Formatting --- components/esp32/Kconfig | 13 ++++++++++++- components/esp32/syscalls.c | 7 ++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/components/esp32/Kconfig b/components/esp32/Kconfig index b25780684..ea1cc9739 100644 --- a/components/esp32/Kconfig +++ b/components/esp32/Kconfig @@ -1,4 +1,4 @@ -menu "WiFi config" +menu "ESP32-specific config" config WIFI_ENABLED bool "Enable low-level WiFi stack" @@ -36,4 +36,15 @@ config WIFI_EVENT_TASK_STACK_SIZE help Config WiFi event task stack size in different application. + +config NEWLIB_STDOUT_ADDCR + bool "Standard-out output adds carriage return before newline" + default y + help + Most people are used to end their printf strings with a newline. If this + is sent as is to the serial port, most terminal programs will only move the + cursor one line down, not also move it to the beginning of the line. This + is usually done by an added CR character. Enabling this will make the + standard output code automatically add a CR character before a LF. + endmenu diff --git a/components/esp32/syscalls.c b/components/esp32/syscalls.c index 5fb7c94d0..f6da4a52a 100644 --- a/components/esp32/syscalls.c +++ b/components/esp32/syscalls.c @@ -134,9 +134,14 @@ int _open_r(struct _reent *r, const char * path, int flags, int mode) { } ssize_t _write_r(struct _reent *r, int fd, const void * data, size_t size) { - const char* p = (const char*) data; + const char* p = (const char*) data; if (fd == STDOUT_FILENO) { while(size--) { +#if CONFIG_NEWLIB_STDOUT_ADDCR + if (*p=='\n') { + uart_tx_one_char('\r'); + } +#endif uart_tx_one_char(*p); ++p; }