From ccd4b4ad10ce7a0000b85412e53ea3741437a948 Mon Sep 17 00:00:00 2001 From: Shun Jing Goh Date: Sun, 29 Jan 2023 08:57:49 +0100 Subject: [PATCH] drivers: console: uart_console.c: add LF detection Add case \n, so that new line from unix or linux host can be detected. Signed-off-by: Shun Jing Goh --- drivers/console/uart_console.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/console/uart_console.c b/drivers/console/uart_console.c index 3a3141b640b1235..beb24155dad3d13 100644 --- a/drivers/console/uart_console.c +++ b/drivers/console/uart_console.c @@ -429,6 +429,7 @@ static void uart_console_isr(const struct device *unused, void *user_data) { ARG_UNUSED(unused); ARG_UNUSED(user_data); + static uint8_t last_char = '\0'; while (uart_irq_update(uart_console_dev) && uart_irq_is_pending(uart_console_dev)) { @@ -501,6 +502,11 @@ static void uart_console_isr(const struct device *unused, void *user_data) case ESC: atomic_set_bit(&esc_state, ESC_ESC); break; + case '\n': + if (last_char == '\r') { + /* break to avoid double line*/ + break; + } case '\r': cmd->line[cur + end] = '\0'; uart_poll_out(uart_console_dev, '\r'); @@ -519,6 +525,7 @@ static void uart_console_isr(const struct device *unused, void *user_data) break; } + last_char = byte; continue; }