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 4fe196113d..c7cd91b968 100644 --- a/sys/stdio/stdio.c +++ b/sys/stdio/stdio.c @@ -81,3 +81,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); + } +}