Reworking of the assembly
[uccvend-snackrom.git] / ROM2 / keypad.c
1 #include "vend.h"
2
3 u8 last_key; /* the last key registered */
4 u8 curr_key; /* the key currently being held down */
5
6 /* first 8 from the first row, then 3 from the second row */
7 /* keys are 1-9, 0, reset */
8 const u8 keymap0[8] = {8, 7, 6, 5, 4, 3, 2, 1};
9 const u8 keymap1[3] = {11, 10, 9};
10
11 extern inline int keypad_read_row(int row) {
12         int i, num;
13         if (row)
14                 _io_ports[M6811_PORTD] |= PORTD_KEYPAD_ROW;
15         else
16                 _io_ports[M6811_PORTD] &= ~PORTD_KEYPAD_ROW;
17
18         bclr_misc_output(A3800_DISPLAY_WRITE);  /* disable the display clock */
19
20         _io_ports[M6811_SPDR] = 0;
21         while(!(_io_ports[M6811_SPDR]&M6811_SPIE)); /* wait for completion */
22
23         for (i = _io_ports[M6811_SPDR], num = 0;
24                 (i&0x1) == 0;
25                 i=i>>1, num++);
26
27         return num;
28 }
29
30 /* returns a key 0..9 or 11 for reset */
31 void keypad_read() {
32         /* FIXME: need to do debouncing of some sort? */
33         int key;
34         key = keypad_read_row(0);
35         if (!key) {
36                 key = keypad_read_row(1);
37                 curr_key = keymap0[key];
38         }
39         curr_key = keymap1[key];
40
41         if (curr_key != last_key) {
42                 last_key = curr_key;
43         }
44 }

UCC git Repository :: git.ucc.asn.au