From 6f9edfe7a295ed49ebcdd6bb5674bc70c070e1a3 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 stdio_clear_stdin --- sys/include/stdio_base.h | 9 +++++++++ sys/stdio/stdio.c | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/sys/include/stdio_base.h b/sys/include/stdio_base.h index 0d0a5a2427..2a9bf6d702 100644 --- a/sys/include/stdio_base.h +++ b/sys/include/stdio_base.h @@ -102,6 +102,15 @@ void stdio_init(void); int stdio_available(void); #endif +/** + * @brief Clear the input buffer + * + * @note Requires 'USEMODULE += stdin' + * + * @warning This function does only work if the stdio implementation supports it. + */ +void stdio_clear_stdin(void); + /** * @brief read @p len bytes from stdio uart into @p buffer * diff --git a/sys/stdio/stdio.c b/sys/stdio/stdio.c index 11fb6c5cf7..e98e70c8ed 100644 --- a/sys/stdio/stdio.c +++ b/sys/stdio/stdio.c @@ -78,3 +78,10 @@ int stdio_available(void) return tsrb_avail(&stdin_isrpipe.tsrb); } #endif + +void stdio_clear_stdin(void) +{ + if (IS_USED(MODULE_STDIN)) { + tsrb_clear(&stdin_isrpipe.tsrb); + } +}