Skip to content

Commit 1480c23

Browse files
committed
Added config option for newline conversion
1 parent 2330dcc commit 1480c23

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

hal/common/retarget.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ FileHandle::~FileHandle() {
8888
#if DEVICE_SERIAL
8989
extern int stdio_uart_inited;
9090
extern serial_t stdio_uart;
91+
#ifdef MBED_CONF_CORE_STDIO_CONVERT_NEWLINES
9192
static char stdio_in_prev;
9293
static char stdio_out_prev;
9394
#endif
95+
#endif
9496

9597
static void init_serial() {
9698
#if DEVICE_SERIAL
@@ -228,13 +230,19 @@ extern "C" int PREFIX(_write)(FILEHANDLE fh, const unsigned char *buffer, unsign
228230
if (fh < 3) {
229231
#if DEVICE_SERIAL
230232
if (!stdio_uart_inited) init_serial();
233+
#ifdef MBED_CONF_CORE_STDIO_CONVERT_NEWLINES
231234
for (unsigned int i = 0; i < length; i++) {
232235
if (buffer[i] == '\n' && stdio_out_prev != '\r') {
233236
serial_putc(&stdio_uart, '\r');
234237
}
235238
serial_putc(&stdio_uart, buffer[i]);
236239
stdio_out_prev = buffer[i];
237240
}
241+
#else
242+
for (unsigned int i = 0; i < length; i++) {
243+
serial_putc(&stdio_uart, buffer[i]);
244+
}
245+
#endif
238246
#endif
239247
n = length;
240248
} else {
@@ -260,6 +268,7 @@ extern "C" int PREFIX(_read)(FILEHANDLE fh, unsigned char *buffer, unsigned int
260268
// only read a character at a time from stdin
261269
#if DEVICE_SERIAL
262270
if (!stdio_uart_inited) init_serial();
271+
#ifdef MBED_CONF_CORE_STDIO_CONVERT_NEWLINES
263272
while (true) {
264273
char c = serial_getc(&stdio_uart);
265274
if ((c == '\r' && stdio_in_prev != '\n') ||
@@ -278,6 +287,9 @@ extern "C" int PREFIX(_read)(FILEHANDLE fh, unsigned char *buffer, unsigned int
278287
break;
279288
}
280289
}
290+
#else
291+
*buffer = serial_getc(&stdio_uart);
292+
#endif
281293
#endif
282294
n = 1;
283295
} else {

mbed_lib.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "core",
3+
"config": {
4+
"stdio-convert-newlines": {
5+
"help": "Enable conversion to standard newlines on stdin/stdout"
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)