From: hackbard Date: Thu, 20 Sep 2007 15:42:20 +0000 (+0200) Subject: first button test using interrupts (untested!) X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=a409cb5b36482767f766ec9efc5dbecaa2274660;p=my-code%2Farm.git first button test using interrupts (untested!) --- diff --git a/betty/betty.c b/betty/betty.c index d10456e..2cd287f 100644 --- a/betty/betty.c +++ b/betty/betty.c @@ -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; } - diff --git a/betty/betty.h b/betty/betty.h index f21d092..07d063a 100644 --- a/betty/betty.h +++ b/betty/betty.h @@ -20,12 +20,14 @@ // 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" diff --git a/betty/buttons.c b/betty/buttons.c index 094e356..735befd 100644 --- a/betty/buttons.c +++ b/betty/buttons.c @@ -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; } diff --git a/betty/interrupts.c b/betty/interrupts.c index bb2344c..49ea0cd 100644 --- a/betty/interrupts.c +++ b/betty/interrupts.c @@ -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<3) + return; + + if(wakeup) + EXTWAKE=(EXTWAKE&0xf)|(1<