2 * buttons.c - button api
4 * author: hackbard@hackdaworld.org
10 #define BUTTON_RESET \
11 IOSET2=((1<<18)|(1<<19)|(1<<20)|(1<<21)|(1<<22)|(1<<23)|(1<<24))
13 #define COUNT_AND_CHECK cnt++; \
17 void button_init(t_button *button) {
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
25 * - p2.18-p2.24 : the rows
30 /* poll / interrupt mode */
31 if(button->mode&BUTTON_INT) {
33 else if(button->mode&BUTTON_POLL) {
37 void button_set_retries(t_button *button,int retries) {
39 button->retries=retries;
42 void button_select_row(u8 row) {
50 u8 button_get_event(t_button *button) {
59 retries=button->retries;
62 /* rest offset counter */
65 for(row=0;row<7;row++) {
67 button_select_row(row);
68 /* scan the columns 6 */
71 if(!(port0&(1<<28))) {
72 button->key[cnt]=offset+0;
75 if(!(port0&(1<<27))) {
76 button->key[cnt]=offset+1;
79 if(!(port0&(1<<22))) {
80 button->key[cnt]=offset+2;
83 if(!(port0&(1<<13))) {
84 button->key[cnt]=offset+3;
87 if(!(port3&(1<<21))) {
88 button->key[cnt]=offset+4;
91 if(!(port3&(1<<20))) {
92 button->key[cnt]=offset+5;