From bacfe8b822cd95e90f037d24432608751647fe22 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 2 Apr 2015 13:33:46 +0300 Subject: [PATCH] cmd-keypad: Exit also on key press on serial/USB connection. "keypad" command so far assumes rather adhoc keyboard map, and effectively locks up otherwise. Allow to break out of it from host connection. --- cmd-keypad.c | 4 ++-- include/serial.h | 1 + serial.c | 12 ++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cmd-keypad.c b/cmd-keypad.c index dc58b69..7f7bd51 100644 --- a/cmd-keypad.c +++ b/cmd-keypad.c @@ -59,9 +59,9 @@ int cmd_keypad(int argc, char **argv) int end = 0; uint32_t key_state[18] = {0}; - printf("Press %c on keypad to exit\n", + printf("Press %c on keypad or any key on serial to exit\n", key_vals[ARRAY_SIZE(key_vals) - 2]); - while (!end) { + while (!end && !serial_available()) { int key; for (key = 0; key < (ARRAY_SIZE(key_vals) - 1); key++) { diff --git a/include/serial.h b/include/serial.h index 74054d0..15b0b98 100644 --- a/include/serial.h +++ b/include/serial.h @@ -9,6 +9,7 @@ void serial_puth(uint32_t hex, int digits); /* Put hex */ void serial_write(const void *d, int bytes); uint8_t serial_getc(void); +int serial_available(void); int serial_print_hex(const void *bfr, int count); int serial_read(void *data, int bytes); diff --git a/serial.c b/serial.c index e107ec2..f9ee8b6 100644 --- a/serial.c +++ b/serial.c @@ -100,6 +100,12 @@ uint8_t serial_getc(void) return uart_getreg(UART_RBR); } +/* Return true if there's pending received char */ +int serial_available(void) +{ + return uart_getreg(UART_LSR) & 0x01; +} + int serial_puts(const void *s) { const char *str = s; @@ -279,6 +285,12 @@ uint8_t serial_getc(void) return recv_bfr[recv_offset++]; } +int serial_available(void) +{ + usb_handle_irqs(1); + return recv_size != 0; +} + int serial_puts(const void *s) { const char *str = s;