diff options
-rw-r--r-- | common/uart_buffering.c | 10 | ||||
-rw-r--r-- | include/config.h | 3 | ||||
-rw-r--r-- | include/uart.h | 11 |
3 files changed, 24 insertions, 0 deletions
diff --git a/common/uart_buffering.c b/common/uart_buffering.c index 6e93804e61..8037320340 100644 --- a/common/uart_buffering.c +++ b/common/uart_buffering.c @@ -157,6 +157,10 @@ void uart_process_input(void) for (i = cur_head; i != rx_buf_head; i = RX_BUF_NEXT(i)) { int c = rx_buf[i]; +#ifdef CONFIG_UART_INPUT_FILTER /* TODO(crosbug.com/p/36745): */ +#error "Filtering the UART input with DMA enabled is NOT SUPPORTED!" +#endif + if (c == CTRL('S')) { /* Software flow control - XOFF */ uart_suspended = 1; @@ -197,6 +201,12 @@ void uart_process_input(void) int c = uart_read_char(); int rx_buf_next = RX_BUF_NEXT(rx_buf_head); +#ifdef CONFIG_UART_INPUT_FILTER + /* Intercept the input before it goes to the console */ + if (uart_input_filter(c)) + continue; +#endif + if (c == CTRL('S')) { /* Software flow control - XOFF */ uart_suspended = 1; diff --git a/include/config.h b/include/config.h index 18f2b45c89..5c6d17f99e 100644 --- a/include/config.h +++ b/include/config.h @@ -1143,6 +1143,9 @@ /* UART index (number) for host UART, if present */ #undef CONFIG_UART_HOST +/* Use uart_input_filter() to filter UART input. See prototype in uart.h */ +#undef CONFIG_UART_INPUT_FILTER + /* * UART receive buffer size in bytes. Must be a power of 2 for macros in * common/uart_buffering.c to work properly. Must be larger than diff --git a/include/uart.h b/include/uart.h index 2f0bc8bd8c..6128962726 100644 --- a/include/uart.h +++ b/include/uart.h @@ -227,6 +227,17 @@ void uart_deepsleep_interrupt(enum gpio_signal signal); #define uart_deepsleep_interrupt NULL #endif +#ifdef CONFIG_UART_INPUT_FILTER +/** + * Application-specific input filter, which takes the next input character as + * a parameter. + * + * Return 0 to allow the character to be handled by the console, non-zero if + * the character was handled by the filter. + */ +int uart_input_filter(int c); +#endif + /* * COMx functions */ |