Created
July 26, 2024 09:23
-
-
Save maximevince/f6d3b68ec40c661f2c673ece72b4aec2 to your computer and use it in GitHub Desktop.
Configure stdin on Zephyr Shell subsystem for a working scanf()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <zephyr/shell/shell_uart.h> | |
static unsigned char shell_stdin_hook(void) | |
{ | |
const struct shell * sh = shell_backend_uart_get_ptr(); | |
char ch; | |
size_t count = 0; | |
while (count == 0) { | |
(void)sh->iface->api->read(sh->iface, &ch, sizeof(ch), &count); | |
k_usleep(100); // yield to other threads | |
} | |
if (ch == '\r') { | |
putchar('\r'); | |
putchar('\n'); | |
} else { | |
putchar(ch); | |
} | |
return ch; | |
} | |
// Somewhere in your init code: | |
__stdin_hook_install(shell_stdin_hook); // to get input for scanf() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment