/* 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
*/
}
}
-/*
- * 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
/* variables */
t_button button;
- u8 contrast;
/* system init */
pll_init();
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;
}
-
#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
* - 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) {
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 */
break;
}
- BUTTON_RESET;
- button->cnt=cnt;
+ if(button->mode&BUTTON_INT)
+ BUTTON_UNSET;
+ else if(button->mode&BUTTON_POLL)
+ BUTTON_RESET;
return cnt;
}
#include "interrupts.h"
-/*
- * module static interrupt variable
- */
-
+// 'module global' interrupt variable
static t_interrupt interrupt;
/*
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)
*/
#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
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);