This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 68384e9db4 drivers/serial: Echo input in driver layer
68384e9db4 is described below
commit 68384e9db42e254b2cf6720bc3380aebdd2b298c
Author: Huang Qi <[email protected]>
AuthorDate: Wed Mar 1 23:25:35 2023 +0800
drivers/serial: Echo input in driver layer
Signed-off-by: Huang Qi <[email protected]>
---
drivers/serial/serial.c | 55 ++++++++++++++++++++++++++++++++++++++++++-
include/nuttx/serial/serial.h | 1 +
2 files changed, 55 insertions(+), 1 deletion(-)
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 <nuttx/config.h>
+#include <ctype.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
@@ -37,6 +38,7 @@
#include <spawn.h>
#include <nuttx/irq.h>
+#include <nuttx/ascii.h>
#include <nuttx/arch.h>
#include <nuttx/clock.h>
#include <nuttx/sched.h>
@@ -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 <esc>[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