]> hackdaworld.org Git - my-code/arm.git/blob - betty/buttons.c
the interrupt routines
[my-code/arm.git] / betty / buttons.c
1 /*
2  * buttons.c - button api
3  *
4  * author: hackbard@hackdaworld.org
5  *
6  */
7
8 #include "buttons.h"
9
10 #define BUTTON_RESET \
11         IOSET2=((1<<18)|(1<<19)|(1<<20)|(1<<21)|(1<<22)|(1<<23)|(1<<24))
12
13 #define COUNT_AND_CHECK         cnt++; \
14                                 if(cnt==BUTTON_MAX) \
15                                         break
16
17 void button_init(t_button *button) {
18
19         /*
20          * input:
21          *  - p0.30 : interrupt! wtf is the 'vw 3 p9'? a transistor?
22          *  - p0.28, p0.27, p3.21, p3.20, p0.22, p0.13 : the columns
23          *
24          * output:
25          *  - p2.18-p2.24 : the rows
26          */
27
28         BUTTON_RESET;
29
30         /* poll / interrupt mode */
31         if(button->mode&BUTTON_INT) {
32         }
33         else if(button->mode&BUTTON_POLL) {
34         }
35 }
36
37 void button_set_retries(t_button *button,int retries) {
38
39         button->retries=retries;
40 }
41
42 void button_select_row(u8 row) {
43
44         BUTTON_RESET;
45         if(row>6)
46                 return;
47         IOCLR2=(1<<(18+row));
48 }
49
50 u8 button_get_event(t_button *button) {
51
52         u8 row;
53         u8 offset;
54         u8 cnt;
55         u32 port0,port3;
56         u8 retries;
57
58         cnt=0;
59         retries=button->retries;
60
61         while(retries--) {
62                 /* rest offset counter */
63                 offset=0;
64                 /* rows */
65                 for(row=0;row<7;row++) {
66                         /* select the row */
67                         button_select_row(row);
68                         /* scan the columns 6 */
69                         port0=IOPIN0;
70                         port3=IOPIN3;
71                         if(!(port0&(1<<28))) {
72                                 button->key[cnt]=offset+0;
73                                 COUNT_AND_CHECK;
74                         }
75                         if(!(port0&(1<<27))) {
76                                 button->key[cnt]=offset+1;
77                                 COUNT_AND_CHECK;
78                         }
79                         if(!(port0&(1<<22))) {
80                                 button->key[cnt]=offset+2;
81                                 COUNT_AND_CHECK;
82                         }
83                         if(!(port0&(1<<13))) {
84                                 button->key[cnt]=offset+3;
85                                 COUNT_AND_CHECK;
86                         }
87                         if(!(port3&(1<<21))) {
88                                 button->key[cnt]=offset+4;
89                                 COUNT_AND_CHECK;
90                         }
91                         if(!(port3&(1<<20))) {
92                                 button->key[cnt]=offset+5;
93                                 COUNT_AND_CHECK;
94                         }
95                         offset+=6;
96                 }
97                 if(cnt)
98                         break;
99         }
100
101         BUTTON_RESET;
102         button->cnt=cnt;
103
104         return cnt;
105 }
106