diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c index 302908e800..fef5a61e53 100644 --- a/drivers/serial/serial.c +++ b/drivers/serial/serial.c @@ -24,6 +24,7 @@ #include +#include #include #include #include @@ -37,6 +38,7 @@ #include #include +#include #include #include #include @@ -887,6 +889,45 @@ static ssize_t uart_read(FAR struct file *filep, *buffer++ = ch; recvd++; + + if (dev->isconsole +#ifdef CONFIG_SERIAL_TERMIOS + || (dev->tc_iflag & ECHO) +#endif + ) + { + /* Check for the beginning of a VT100 escape sequence, 3 byte */ + + if (ch == ASCII_ESC) + { + /* Mark that we should skip 2 more bytes */ + + dev->escape = 2; + continue; + } + else if (dev->escape == 2 && ch != ASCII_LBRACKET) + { + /* It's not an [x 3 byte sequence, show it */ + + dev->escape = 0; + } + + /* Echo if the character is not a control byte */ + + if ((!iscntrl(ch & 0xff) || (ch == '\n')) && dev->escape == 0) + { + { + uart_putxmitchar(dev, ch, true); + } + } + + /* Skipping character count down */ + + if (dev->escape > 0) + { + dev->escape--; + } + } } #ifdef CONFIG_DEV_SERIAL_FULLBLOCKS @@ -1070,6 +1111,14 @@ static ssize_t uart_read(FAR struct file *filep, } } + if (recvd > 0) + { +#ifdef CONFIG_SERIAL_TXDMA + uart_dmatxavail(dev); +#endif + uart_enabletxint(dev); + } + #ifdef CONFIG_SERIAL_RXDMA /* Notify DMA that there is free space in the RX buffer */ @@ -1770,7 +1819,11 @@ int uart_register(FAR const char *path, FAR uart_dev_t *dev) /* Convert CR to LF by default for console */ - dev->tc_iflag |= ICRNL; + dev->tc_iflag |= ICRNL | ECHO; + + /* Clear escape counter */ + + dev->escape = 0; } #endif diff --git a/include/nuttx/serial/serial.h b/include/nuttx/serial/serial.h index 0a791986af..e1a094d0d3 100644 --- a/include/nuttx/serial/serial.h +++ b/include/nuttx/serial/serial.h @@ -271,6 +271,7 @@ struct uart_dev_s /* State data */ uint8_t open_count; /* Number of times the device has been opened */ + uint8_t escape; /* Number of the character to be escaped */ volatile bool xmitwaiting; /* true: User waiting for space in xmit.buffer */ volatile bool recvwaiting; /* true: User waiting for data in recv.buffer */ #ifdef CONFIG_SERIAL_REMOVABLE