X-Git-Url: https://git.ucc.asn.au/?p=uccvend-snackrom.git;a=blobdiff_plain;f=ROM2%2Fkeypad.c;h=5bd5e2ed3ee6352400e6d3a32b7615129b5e491b;hp=0e03095e4b2622eada28d8f0322072981393d8f8;hb=b14807a016c121bc79efd5702ffba33c1dbd9be2;hpb=3e4543697766d4777790a051de20f729c7cf8341 diff --git a/ROM2/keypad.c b/ROM2/keypad.c index 0e03095..5bd5e2e 100644 --- a/ROM2/keypad.c +++ b/ROM2/keypad.c @@ -1,35 +1,49 @@ #include "chime.h" #include "vend.h" #include "keypad.h" +#include "display_basic.h" -u8 last_key; /* the last key registered */ -bool new_key; +volatile u8 last_key; /* the last key registered */ +volatile bool new_key; /* first 8 from the first row, then 3 from the second row */ /* keys are 1-9, 0, reset */ -const u8 keymap0[8] = {KEY_8, KEY_7, KEY_6, KEY_5, KEY_4, KEY_3, KEY_2, KEY_1}; -const u8 keymap1[3] = {KEY_RESET, KEY_0, KEY_9}; +const u8 keymap0[8] = {KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8}; +const u8 keymap1[3] = {KEY_9, KEY_0, KEY_RESET}; #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) { +extern inline u8 keypad_read_row(const u8 row) { u8 i, num; + if (row) bset((void*)&_io_ports[M6811_PORTD], PORTD_KEYPAD_ROW); else bclr((void*)&_io_ports[M6811_PORTD], PORTD_KEYPAD_ROW); + spi_enable(); + + bset_misc_output(A3800_KEYPAD_STROBE); + bclr_misc_output(A3800_KEYPAD_STROBE); + bclr_misc_output(A3800_DISPLAY_WRITE); /* disable the display clock */ - _io_ports[M6811_SPDR] = 0; - while(!(_io_ports[M6811_SPDR]&M6811_SPIE)); /* wait for completion */ + _io_ports[M6811_SPDR] = 0x55; /* doesn't matter what we send. */ + while(!(_io_ports[M6811_SPSR]&M6811_SPIF)); /* wait for completion */ + + /* SPDR read to clear SPIF flag is performed below: */ + i = _io_ports[M6811_SPDR]; + + num = 0; + while (((i & 0x80) == 0) && (num < 8)) { + i = i << 1; + num++; + } - for (i = _io_ports[M6811_SPDR], num = 0; - ((i&0x1) == 0) && (num < 8); - i=i>>1, num++); + spi_disable(); return num; }