diff --git a/components/esp8266/source/ets_printf.c b/components/esp8266/source/ets_printf.c index bc0e316e..e72519f7 100644 --- a/components/esp8266/source/ets_printf.c +++ b/components/esp8266/source/ets_printf.c @@ -23,7 +23,7 @@ #include "esp8266/uart_register.h" #include "esp8266/rom_functions.h" -int ets_putc(int c) +static void uart_putc(int c) { while (1) { uint32_t fifo_cnt = READ_PERI_REG(UART_STATUS(CONFIG_CONSOLE_UART_NUM)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S); @@ -33,6 +33,19 @@ int ets_putc(int c) } WRITE_PERI_REG(UART_FIFO(CONFIG_CONSOLE_UART_NUM) , c); +} + +int ets_putc(int c) +{ +#ifdef CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF + if (c == '\n') + uart_putc('\r'); +#elif defined(CONFIG_NEWLIB_STDOUT_LINE_ENDING_CR) + if (c == '\n') + c = '\r'; +#endif + + uart_putc(c); return c; } diff --git a/components/newlib/newlib/port/syscall.c b/components/newlib/newlib/port/syscall.c index e2ef5b6b..b71e5273 100644 --- a/components/newlib/newlib/port/syscall.c +++ b/components/newlib/newlib/port/syscall.c @@ -37,22 +37,8 @@ _ssize_t _write_r(struct _reent *r, int fd, const void *buf, size_t len) int i; const char *cbuf = buf; - for (i = 0; i < len; i++) { -#ifdef CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF - if (cbuf[i] == '\n') { - ets_putc('\r'); - ets_putc('\n'); - } else - ets_putc(cbuf[i]); -#elif defined(CONFIG_NEWLIB_STDOUT_LINE_ENDING_CR) - if (cbuf[i] == '\n') - ets_putc('\r'); - else - ets_putc(cbuf[i]); -#elif defined(CONFIG_NEWLIB_STDOUT_LINE_ENDING_LF) + for (i = 0; i < len; i++) ets_putc(cbuf[i]); -#endif - } return len; }