2 * buttons.c - button api
4 * author: hackbard@hackdaworld.org
10 void button_init(void) {
13 * select as input the following pins
14 * - p0.30 : interrupt, wtf is the 'vw 3 p9'?
15 * - p0.28, p0.27, p3.21, p3.20, p0.22, p0.13 : column select
18 * - p2.18-p2.24 : the rows
21 // gpio, as is: p3.20, p3.21
22 PINSEL1&=~((1<<29)|(1<<28)); // p0.30
23 PINSEL1&=~((1<<25)|(1<<24)); // p0.28
24 PINSEL1&=~((1<<23)|(1<<22)); // p0.27
25 PINSEL1&=~((1<<13)|(1<<12)); // p0.22
26 PINSEL0&=~((1<<27)|(1<<26)); // p0.13
27 // ctrl databus for p2.18 - p2.24
28 PINSEL2&=(PINSEL2&(~((1<<5)|(1<<4))))|(1<<4);
29 // ctrl addr bus for p3.20, p3.21
30 PINSEL2=(PINSEL2&(~((1<<27)|(1<<26)|(1<<25))))|(1<<27)|(1<<26);
32 IODIR0&=~((1<<30)|(1<<28)|(1<<27)|(1<<22)|(1<<13));
33 IODIR3&=~((1<<21)|(1<<20));
34 // output + pull them high
35 IODIR2|=((1<<18)|(1<<19)|(1<<20)|(1<<21)|(1<<22)|(1<<23)|(1<<24));
36 IOSET2=((1<<18)|(1<<19)|(1<<20)|(1<<21)|(1<<22)|(1<<23)|(1<<24));
39 void button_select_row(u8 row) {
41 IOSET2=((1<<18)|(1<<19)|(1<<20)|(1<<21)|(1<<22)|(1<<23)|(1<<24));
47 u8 button_get_event(u64 *keys,int retries) {
61 for(row=0;row<7;row++) {
63 button_select_row(row);
64 /* scan the columns 6 */
67 if(!(port0&(1<<28))) {
68 *keys|=(1<<(offset+0));
71 if(!(port0&(1<<27))) {
72 *keys|=(1<<(offset+1));
75 if(!(port0&(1<<22))) {
76 *keys|=(1<<(offset+2));
79 if(!(port0&(1<<13))) {
80 *keys|=(1<<(offset+3));
83 if(!(port3&(1<<21))) {
84 *keys|=(1<<(offset+4));
87 if(!(port3&(1<<20))) {
88 *keys|=(1<<(offset+5));