Skip to content

Commit

Permalink
driver: gpio: fix shell blink command
Browse files Browse the repository at this point in the history
The blink command should blink until the user presses a key, however on
some systems a pending keypress is present when entering the loop
causing it to immediate exit before getting a chance to blink.

Add a dummy read to clear the buffer before starting the blink loop.

Signed-off-by: Eric Holmberg <eric.holmberg@northriversystems.co.nz>
  • Loading branch information
EricNRS authored and fabiobaltieri committed Jul 4, 2023
1 parent 03c04fd commit acde5fe
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/gpio/gpio_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ static int cmd_gpio_blink(const struct shell *sh,
shell_fprintf(sh, SHELL_NORMAL, "Blinking port %s index %d.", argv[1], index);
shell_fprintf(sh, SHELL_NORMAL, " Hit any key to exit");

/* dummy read to clear any pending input */
(void)sh->iface->api->read(sh->iface, &data, sizeof(data), &count);

while (true) {
(void)sh->iface->api->read(sh->iface, &data, sizeof(data), &count);
if (count != 0) {
Expand Down

0 comments on commit acde5fe

Please sign in to comment.