Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: HelloWorld_CCA01M1 HelloWorld_CCA02M1 CI-data-logger-server HelloWorld_CCA02M1 ... more
This is a fork of the events subdirectory of https://github.com/ARMmbed/mbed-os.
Note, you must import this library with import name: events!!!
Diff: hal/common/retarget.cpp
- Revision:
- 6547:5f2779e36035
- Parent:
- 6546:b7f6a8e13048
- Child:
- 6548:c08cb6087b0a
diff -r b7f6a8e13048 -r 5f2779e36035 hal/common/retarget.cpp
--- a/hal/common/retarget.cpp Tue Jun 07 09:43:40 2016 -0500
+++ b/hal/common/retarget.cpp Tue Jun 07 10:08:07 2016 -0500
@@ -88,7 +88,8 @@
#if DEVICE_SERIAL
extern int stdio_uart_inited;
extern serial_t stdio_uart;
-static char stdio_prev;
+static char stdio_in_prev;
+static char stdio_out_prev;
#endif
static void init_serial() {
@@ -228,11 +229,11 @@
#if DEVICE_SERIAL
if (!stdio_uart_inited) init_serial();
for (unsigned int i = 0; i < length; i++) {
- if (buffer[i] == '\n' && stdio_prev != '\r') {
+ if (buffer[i] == '\n' && stdio_out_prev != '\r') {
serial_putc(&stdio_uart, '\r');
}
serial_putc(&stdio_uart, buffer[i]);
- stdio_prev = buffer[i];
+ stdio_out_prev = buffer[i];
}
#endif
n = length;
@@ -259,7 +260,24 @@
// only read a character at a time from stdin
#if DEVICE_SERIAL
if (!stdio_uart_inited) init_serial();
- *buffer = serial_getc(&stdio_uart);
+ while (true) {
+ char c = serial_getc(&stdio_uart);
+ if ((c == '\r' && stdio_in_prev != '\n') ||
+ (c == '\n' && stdio_in_prev != '\r')) {
+ stdio_in_prev = c;
+ *buffer = '\n';
+ break;
+ } else if ((c == '\r' && stdio_in_prev == '\n') ||
+ (c == '\n' && stdio_in_prev == '\r')) {
+ stdio_in_prev = c;
+ // onto next character
+ continue;
+ } else {
+ stdio_in_prev = c;
+ *buffer = c;
+ break;
+ }
+ }
#endif
n = 1;
} else {