X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Farm.git;a=blobdiff_plain;f=betty%2Fbuttons.c;h=735befdf46cf3f17b1e7707b19f0bce9adc2d838;hp=21efe018d58d38d8f45ad0b55ce3ecb21e38d81f;hb=HEAD;hpb=5da509dc909c60d63c5fba98e7ced43040eb6827 diff --git a/betty/buttons.c b/betty/buttons.c index 21efe01..735befd 100644 --- a/betty/buttons.c +++ b/betty/buttons.c @@ -7,43 +7,32 @@ #include "buttons.h" +#define BUTTON_RESET \ + IOSET2=((1<<18)|(1<<19)|(1<<20)|(1<<21)|(1<<22)|(1<<23)|(1<<24)) + +#define BUTTON_UNSET \ + IOCLR2=((1<<18)|(1<<19)|(1<<20)|(1<<21)|(1<<22)|(1<<23)|(1<<24)) + +#define COUNT_AND_CHECK cnt++; \ + if(cnt==BUTTON_MAX) \ + break + void button_init(t_button *button) { - /* - * select as input the following pins - * - p0.30 : interrupt! wtf is the 'vw 3 p9'? - * - p0.28, p0.27, p3.21, p3.20, p0.22, p0.13 : column select + /* + * input: + * - p0.30 : interrupt! wtf is the 'vw 3 p9'? a transistor? + * - p0.28, p0.27, p3.21, p3.20, p0.22, p0.13 : the columns * - * select as output + * output: * - p2.18-p2.24 : the rows */ - // gpio, as is: p3.20, p3.21 - PINSEL1&=~((1<<29)|(1<<28)); // p0.30 - PINSEL1&=~((1<<25)|(1<<24)); // p0.28 - PINSEL1&=~((1<<23)|(1<<22)); // p0.27 - PINSEL1&=~((1<<13)|(1<<12)); // p0.22 - PINSEL0&=~((1<<27)|(1<<26)); // p0.13 - - // ctrl databus for p2.18 - p2.24 - PINSEL2=(PINSEL2&P2MASK&~((1<<5)|(1<<4)))|(1<<4); - - // ctrl addr bus for p3.20, p3.21 - PINSEL2=(PINSEL2&P2MASK&~((1<<27)|(1<<26)|(1<<25)))|(1<<27)|(1<<26); - - // input - IODIR0&=~((1<<30)|(1<<28)|(1<<27)|(1<<22)|(1<<13)); - IODIR3&=~((1<<21)|(1<<20)); - - // output + pull them high - IODIR2|=((1<<18)|(1<<19)|(1<<20)|(1<<21)|(1<<22)|(1<<23)|(1<<24)); - IOSET2=((1<<18)|(1<<19)|(1<<20)|(1<<21)|(1<<22)|(1<<23)|(1<<24)); - /* poll / interrupt mode */ - if(button->mode&BUTTON_INT) { - } - else if(button->mode&BUTTON_POLL) { - } + if(button->mode&BUTTON_INT) + BUTTON_UNSET; + else if(button->mode&BUTTON_POLL) + BUTTON_RESET; } void button_set_retries(t_button *button,int retries) { @@ -51,9 +40,6 @@ void button_set_retries(t_button *button,int retries) { button->retries=retries; } -#define BUTTON_RESET \ - IOSET2=((1<<18)|(1<<19)|(1<<20)|(1<<21)|(1<<22)|(1<<23)|(1<<24)) - void button_select_row(u8 row) { BUTTON_RESET; @@ -62,22 +48,18 @@ void button_select_row(u8 row) { IOCLR2=(1<<(18+row)); } -#define COUNT_AND_CHECK cnt++; \ - if(cnt==BUTTON_MAX) \ - break - u8 button_get_event(t_button *button) { u8 row; u8 offset; u8 cnt; u32 port0,port3; - u8 retries; + u8 tries; cnt=0; - retries=button->retries; + tries=button->retries+1; - while(retries--) { + while(tries--) { /* rest offset counter */ offset=0; /* rows */ @@ -117,8 +99,10 @@ u8 button_get_event(t_button *button) { break; } - BUTTON_RESET; - button->cnt=cnt; + if(button->mode&BUTTON_INT) + BUTTON_UNSET; + else if(button->mode&BUTTON_POLL) + BUTTON_RESET; return cnt; }