]> hackdaworld.org Git - my-code/arm.git/commitdiff
first button test using interrupts (untested!)
authorhackbard <hackbard@sage.physik.uni-augsburg.de>
Thu, 20 Sep 2007 15:42:20 +0000 (17:42 +0200)
committerhackbard <hackbard@sage.physik.uni-augsburg.de>
Thu, 20 Sep 2007 15:42:20 +0000 (17:42 +0200)
betty/betty.c
betty/betty.h
betty/buttons.c
betty/interrupts.c
betty/interrupts.h

index d10456e30b8a8290c310b4312b305d4d3dc13bdd..2cd287f885825a1a179d5a523993399dee477db6 100644 (file)
@@ -8,6 +8,15 @@
 /* includes */
 #include "betty.h"
 
+/*
+ * global variables
+ */
+
+const char announce[]="betty - live from flash at 0x80000000! ;)\r\n";
+const char d1_txt[]="betty";
+const char d2_txt[]="- alphablend -";
+u8 contrast;
+
 /*
  * functions
  */
@@ -27,13 +36,79 @@ void display_string_page(u8 x,u8 p,u8 *s,u8 f,u8 o,u8 sp) {
        }
 }
 
-/*
- * global variables
- */
-
-const char announce[]="betty - live from flash at 0x80000000! ;)\r\n";
-const char d1_txt[]="betty";
-const char d2_txt[]="- alphablend -";
+void input_event(void) {
+
+       /* button test! */
+       if(button_get_event(&button)) {
+               switch(button.key[0]) {
+                       case BUTTON_POWER:
+                               display_logo((u8 *)default_logo);
+                               break;
+                       case BUTTON_DOWN:
+                               if(contrast>0x00)
+                                       contrast-=1;
+                               DISPLAY_SET_CONTRAST(contrast);
+                               break;
+                       case BUTTON_UP:
+                               if(contrast<0x3f)
+                                       contrast+=1;
+                               DISPLAY_SET_CONTRAST(contrast);
+                               break;
+                       case BUTTON_A:
+                               display_fill_screen(DISPLAY_FILL_W);
+                               break;
+                       case BUTTON_B:
+                               display_fill_screen(DISPLAY_FILL_LG);
+                               break;
+                       case BUTTON_C:
+                               display_fill_screen(DISPLAY_FILL_DG);
+                               break;
+                       case BUTTON_D:
+                               display_fill_screen(DISPLAY_FILL_B);
+                               break;
+                       case BUTTON_1:
+                               display_rectangle_page(4,2,60,5,
+                                                      DISPLAY_FILL_B,0xff);
+                               break;
+                       case BUTTON_2:
+                               display_rectangle_page(40,5,50,5,
+                                                      DISPLAY_FILL_LG,0x7f);
+                               break;
+                       case BUTTON_3:
+                               break;
+                       case BUTTON_4:
+                               display_font_page(42,18,
+                                                 (u8 *)default_font+(0x34<<3),
+                                                 DISPLAY_FILL_B);
+                               break;
+                       case BUTTON_5:
+                               display_font_page(50,18,
+                                                 (u8 *)default_font+(0x35<<3),
+                                                 DISPLAY_FILL_DG);
+                               break;
+                       case BUTTON_6:
+                               display_font_page(58,18,
+                                                 (u8 *)default_font+(0x36<<3),
+                                                 DISPLAY_FILL_W);
+                               break;
+                       case BUTTON_7:
+                               break;
+                       case BUTTON_8:
+                               break;
+                       case BUTTON_BETTY:
+                               display_string_page(50,13,(u8 *)d1_txt,
+                                                   DISPLAY_FILL_B,0,8);
+                               break;
+                       case BUTTON_EXIT:
+                               display_string_page(10,8,(u8 *)d2_txt,
+                                                   DISPLAY_FILL_B,0,8);
+                               break;
+                       default:
+                               display_clear_screen();
+                               break;
+               }
+       }
+}
 
 /*
  * main function
@@ -43,7 +118,6 @@ int main() {
 
        /* variables */
        t_button button;
-       u8 contrast;
 
        /* system init */
        pll_init();
@@ -63,93 +137,37 @@ int main() {
        display_bl_init();
 
        /* button init */
+       button.mode=BUTTON_INT;
        button_init(&button);
-       button_set_retries(&button,100);
+       button_set_retries(&button,0);
 
        /* flash init */
        flash_init();
 
+       /* display init */
+       display_init();
+       contrast=0x38;
+
+       /* interrupt init */
+       interrupt_init();
+       interrupt_ext_ir_config(INTERRUPT_EXT3,INTERRUPT_EXT_NOWAKE,
+                               INTERRUPT_EXT_MODE_EDGE,
+                               INTERRUPT_EXT_POLAR_LOW);
+       interrupt_enable(INTERRUPT_EINT3,INTERRUPT_MODE_VIRQ,0,input_event);
+
        /*
         * start it ...
         */
 
-       /* display init */
+       /* toggle the display back light */
        display_bl_toggle();
-       display_init();
-       contrast=0x38;
-
-       /* pasue again */
 
        /* announce */
        uart0_send_string((char *)announce);
 
        
        while(1) {
-               pause(0x0fffff);
-
-               /* button test! */
-               if(button_get_event(&button)) {
-                       //uart0_send_string(announce);
-                       switch(button.key[0]) {
-                               case BUTTON_POWER:
-                                       display_logo((u8 *)default_logo);
-                                       break;
-                               case BUTTON_DOWN:
-                                       if(contrast>0x00)
-                                               contrast-=1;
-                                       DISPLAY_SET_CONTRAST(contrast);
-                                       break;
-                               case BUTTON_UP:
-                                       if(contrast<0x3f)
-                                               contrast+=1;
-                                       DISPLAY_SET_CONTRAST(contrast);
-                                       break;
-                               case BUTTON_A:
-                                       display_fill_screen(DISPLAY_FILL_W);
-                                       break;
-                               case BUTTON_B:
-                                       display_fill_screen(DISPLAY_FILL_LG);
-                                       break;
-                               case BUTTON_C:
-                                       display_fill_screen(DISPLAY_FILL_DG);
-                                       break;
-                               case BUTTON_D:
-                                       display_fill_screen(DISPLAY_FILL_B);
-                                       break;
-                               case BUTTON_1:
-                                       display_rectangle_page(4,2,60,5,DISPLAY_FILL_B,0xff);
-                                       break;
-                               case BUTTON_2:
-                                       display_rectangle_page(40,5,50,5,DISPLAY_FILL_LG,0x7f);
-                                       break;
-                               case BUTTON_3:
-                                       break;
-                               case BUTTON_4:
-                                       display_font_page(42,18,(u8 *)default_font+(0x34<<3),DISPLAY_FILL_B);
-                                       break;
-                               case BUTTON_5:
-                                       display_font_page(50,18,(u8 *)default_font+(0x35<<3),DISPLAY_FILL_DG);
-                                       break;
-                               case BUTTON_6:
-                                       display_font_page(58,18,(u8 *)default_font+(0x36<<3),DISPLAY_FILL_W);
-                                       break;
-                               case BUTTON_7:
-                                       break;
-                               case BUTTON_8:
-                                       break;
-                               case BUTTON_BETTY:
-                                       display_string_page(50,13,(u8 *)d1_txt,DISPLAY_FILL_B,0,8);
-                                       break;
-                               case BUTTON_EXIT:
-                                       display_string_page(10,8,(u8 *)d2_txt,DISPLAY_FILL_B,0,8);
-                                       break;
-                               default:
-                                       display_clear_screen();
-                                       break;
-                       }
-               }
        }
 
        return 0;
 }
-
index f21d0922674b788c85086fa7e2249f8eea4dd151..07d063a01d512962796842f2696f0d18755db5db 100644 (file)
 
 // api
 #include "system.h"
+#include "functions.h"
 #include "uart.h"
 #include "buttons.h"
 #include "spi.h"
 #include "display.h"
 #include "flash.h"
 #include "pffs.h"
+#include "interrupts.h"
 
 // font/logo
 #include "default_font.h"
index 094e356d0f093f4668f6037b6bd36086d5261554..735befdf46cf3f17b1e7707b19f0bce9adc2d838 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;
 }
index bb2344cca56897fe873747d8de306d0bbca3711f..49ea0cdc488a81017170096921be0bea8aee2481 100644 (file)
@@ -7,10 +7,7 @@
 
 #include "interrupts.h"
 
-/*
- * module static interrupt variable
- */
-
+// 'module global' interrupt variable
 static t_interrupt interrupt;
 
 /*
@@ -80,21 +77,34 @@ int interrupt_enable(u8 src_number,u8 mode,u8 priority,u32 callback_addr) {
        VICIntEnable=(1<<src_number);
 
        switch(mode) {
-               case INTERRUPT_FIQ:
+               case INTERRUPT_MODE_FIQ:
                        VICIntSelect|=(1<<src_number);
                        break;
-               case INTERRUPT_VIRQ:
+               case INTERRUPT_MODE_VIRQ:
                        if(addr[p]&0x3f)
                                return INTERRUP_PRIORITY_USED;
                        *((volatile u32 *)(addr+p))=callback_addr;
                        *((volatile u32 *)(cntl+p))=src_number&0x1f+(1<<5);
-               case INTERRUPT_IRQ:
+               case INTERRUPT_MODE_IRQ:
                case default:
        }
 
        return INTERRUPT_SET;
 }
 
+void interrupt_ext_ir_config(u8 eint,u8 wakeup,u8 mode,u8 polarity) {
+
+       if(eint>3)
+               return;
+
+       if(wakeup)
+               EXTWAKE=(EXTWAKE&0xf)|(1<<eint);
+
+       EXTMODE=(EXTMODE&0xf)|(mode<<eint);
+       EXTPOLAR=(EXTPOLAR&0xf)|(polarity<<eint);
+       EXTINT=(EXTINT&0xf)|(1<<eint);
+}
+
 /*
  * the actual exception handlers (as defined in startup.s)
  */
index c1a4f0461cbdf259935cee6c6efb53ef2f1d2af4..194dd9adc2ad02d2bbd81faccfbe5f057a916434 100644 (file)
 #define INTERRUPT_EINT3                        17
 #define INTERRUPT_ADC                  18
 
-#define INTERRUPT_IRQ                  0
-#define INTERRUPT_VIRQ                 1
-#define INTERRUPT_FIQ                  2
+#define INTERRUPT_MODE_IRQ             0
+#define INTERRUPT_MODE_VIRQ            1
+#define INTERRUPT_MODE_FIQ             2
 
 #define INTERRUPT_EXT_MODE_EDGE                0
 #define INTERRUPT_EXT_MODE_LEVEL       1
 #define INTERRUPT_EXT_POLAR_LOW                0
 #define INTERRUPT_EXT_POLAR_HIGH       1
+#define INTERRUPT_EXT_NOWAKE           0
+#define INTERRUPT_EXT_WAKEUP           1
+
+#define INTERRUPT_EXT0                 0
+#define INTERRUPT_EXT1                 1
+#define INTERRUPT_EXT2                 2
+#define INTERRUPT_EXT3                 3
 
 #define INTERRUPT_SET                  0x00
 #define INTERRUPT_USED                 0x01
@@ -62,6 +69,7 @@ void interrupt_soft_clear(u8 src_number);
 void interrupt_clear(u8 src_number);
 void interrupt_soft_enable(u8 src_number);
 int interrupt_enable(u8 src_number,u8 mode,u8 priority,u32 callback_addr);
+void interrupt_ext_ir_config(u8 eint,u8 wakeup,u8 mode,u8 polarity);
 
 void interrupt_handler_reset(void);
 void interrupt_handler_undef_instruction(void);