Inherit from Serial and use software buffers for TX and RX. This allows the UART peripherals to operate in a IRQ driven mode. Overrides most (but not all) stdio functions as Serial did
Fork of BufferedSerial by
Diff: BufferedSerial.cpp
- Revision:
- 11:9c34df035d99
- Parent:
- 10:9ee15ae3d1a3
--- a/BufferedSerial.cpp Wed Jan 07 18:37:11 2015 +0000 +++ b/BufferedSerial.cpp Sun May 03 02:48:55 2015 +0000 @@ -52,9 +52,36 @@ int BufferedSerial::getc(void) { + while (!readable() && !SERIAL_BASE::readable()) + ; return _rxbuf; } + +char* BufferedSerial::readl(char *s, int size) +{ + if (s == NULL || size <= 0) + return NULL; + + char* ptr = s; + + while (1) { + if (readable()) { + if ((size--) > 0) { + *ptr = _rxbuf; + if (*ptr == '\n' || *ptr == 0) { + break; + } + ptr++; + } else + goto end; + } + } + if (size > 0) + *ptr = 0; + end: return s; +} + int BufferedSerial::putc(int c) { _txbuf = (char)c;