From: Bernard Blackham Date: Sat, 16 Aug 2003 17:00:43 +0000 (+0000) Subject: Fixed non-terminating logic of keypad decoder. X-Git-Tag: ROMW~52 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=4ce97d7a672372f9d13383e40397fa6b51d840ca;p=uccvend-snackrom.git Fixed non-terminating logic of keypad decoder. Removed unused function keypad_getkey() --- diff --git a/ROM2/keypad.c b/ROM2/keypad.c index 23eddb8..8f50c19 100644 --- a/ROM2/keypad.c +++ b/ROM2/keypad.c @@ -12,6 +12,9 @@ const u8 keymap1[3] = {KEY_RESET, KEY_0, KEY_9}; #define NO_KEY 8 +/* reads the keypad and returns the bit number that was turned on in the shift + * register (from 0..7). If no bits were turned on, it returns 8 (aka NO_KEY) + */ extern inline u8 keypad_read_row(u8 row) { u8 i, num; if (row) @@ -25,7 +28,7 @@ extern inline u8 keypad_read_row(u8 row) { while(!(_io_ports[M6811_SPDR]&M6811_SPIE)); /* wait for completion */ for (i = _io_ports[M6811_SPDR], num = 0; - (i&0x1) == 0; + (i&0x1 == 0) && (num < 7); i=i>>1, num++); return num; @@ -38,7 +41,10 @@ void keypad_read() { key = keypad_read_row(0); if (NO_KEY == key) { key = keypad_read_row(1); - key = keymap1[key]; + if (key >= 0 && key <= 2) + key = keymap1[key]; + else + key = 0; } else key = keymap0[key]; @@ -56,9 +62,3 @@ bool keypad_pressed() { new_key = 0; return 1; } - -u8 keypad_getkey() { - while (!keypad_pressed()) - keypad_read(); - return last_key; -}