From 059bb79450b456bb9d59f8c53b49e11476157199 Mon Sep 17 00:00:00 2001 From: Hendrik van Essen Date: Tue, 18 Jul 2023 23:00:33 +0200 Subject: [PATCH] sys/stdio_uart: add pseudomodule stdio_clear_rx --- makefiles/pseudomodules.inc.mk | 1 + makefiles/stdio.inc.mk | 5 +++++ sys/include/stdio_base.h | 10 ++++++++++ sys/stdio/stdio.c | 5 +++++ 4 files changed, 21 insertions(+) diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index c6cb490c27d01..7c9642c7117c7 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -484,6 +484,7 @@ PSEUDOMODULES += socket_zep_hello PSEUDOMODULES += soft_uart_modecfg PSEUDOMODULES += stdin PSEUDOMODULES += stdio_available +PSEUDOMODULES += stdio_clear_rx PSEUDOMODULES += stdio_cdc_acm PSEUDOMODULES += stdio_dispatch PSEUDOMODULES += stdio_ethos diff --git a/makefiles/stdio.inc.mk b/makefiles/stdio.inc.mk index 16ce5902f64d3..b05daf9db5cea 100644 --- a/makefiles/stdio.inc.mk +++ b/makefiles/stdio.inc.mk @@ -75,10 +75,15 @@ ifneq (,$(filter stdin,$(USEMODULE))) endif endif +ifneq (,$(filter stdio_clear_rx,$(USEMODULE))) + USEMODULE += stdin +endif + ifneq (,$(filter stdio_uart_rx,$(USEMODULE))) USEMODULE += isrpipe USEMODULE += stdio_uart USEMODULE += stdio_available + USEMODULE += stdio_clear_rx endif ifneq (,$(filter stdio_uart,$(USEMODULE))) diff --git a/sys/include/stdio_base.h b/sys/include/stdio_base.h index 0d0a5a2427b22..8b0b5b7deaa6d 100644 --- a/sys/include/stdio_base.h +++ b/sys/include/stdio_base.h @@ -102,6 +102,16 @@ void stdio_init(void); int stdio_available(void); #endif +#if IS_USED(MODULE_STDIO_CLEAR_RX) || DOXYGEN +/** + * @brief Clear the input buffer + * + * @warning This function is only available if the implementation supports + * it and the @c stdio_clear_rx module is enabled. + */ +void stdio_clear_rx(void); +#endif + /** * @brief read @p len bytes from stdio uart into @p buffer * diff --git a/sys/stdio/stdio.c b/sys/stdio/stdio.c index 11fb6c5cf739c..47922674d7855 100644 --- a/sys/stdio/stdio.c +++ b/sys/stdio/stdio.c @@ -78,3 +78,8 @@ int stdio_available(void) return tsrb_avail(&stdin_isrpipe.tsrb); } #endif + +void stdio_clear_rx(void) +{ + tsrb_clear(&stdin_isrpipe.tsrb); +}