bullshit commit, sync for travel (to zn00H!) :)
[my-code/arm.git] / betty / buttons.c
index 094e356..735befd 100644 (file)
@@ -10,6 +10,9 @@
 #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
@@ -25,13 +28,11 @@ void button_init(t_button *button) {
         *  - p2.18-p2.24 : the rows
         */
 
-       BUTTON_RESET;
-
        /* 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) {
@@ -53,12 +54,12 @@ u8 button_get_event(t_button *button) {
        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 */
@@ -98,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;
 }