X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Farm.git;a=blobdiff_plain;f=betty%2Fbetty.c;h=3a3e7a51313d9f398055ad43ce54508b5abffd0a;hp=d10456e30b8a8290c310b4312b305d4d3dc13bdd;hb=HEAD;hpb=916c8dd1dfa2414ae8b58ab1e3d477b24c553815 diff --git a/betty/betty.c b/betty/betty.c index d10456e..3a3e7a5 100644 --- a/betty/betty.c +++ b/betty/betty.c @@ -8,6 +8,17 @@ /* 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; +t_button button; +int sample_count; + /* * functions */ @@ -27,13 +38,125 @@ void display_string_page(u8 x,u8 p,u8 *s,u8 f,u8 o,u8 sp) { } } -/* - * global variables - */ +void audio_mute_toggle(void) { -const char announce[]="betty - live from flash at 0x80000000! ;)\r\n"; -const char d1_txt[]="betty"; -const char d2_txt[]="- alphablend -"; + if(IOPIN0&(1<<11)) + IOCLR0=(1<<11); + else + IOSET0=(1<<11); +} + +#define AUDIO_TONE_C (7500000/(262*256)) +#define AUDIO_TONE_D (7500000/(294*256)) +#define AUDIO_TONE_E (7500000/(330*256)) +#define AUDIO_TONE_F (7500000/(349*256)) +#define AUDIO_TONE_G (7500000/(392*256)) +//#define AUDIO_TONE_A (7500000/(440*256)) +#define AUDIO_TONE_A 120 +#define AUDIO_TONE_H (7500000/(494*256)) + +void __attribute__ ((interrupt("IRQ"))) set_sample(void) { + + //uart0_send_byte('S'); + pwm_update_match(PWM_CHAN2,PWM_SINGLE_EDGE,sinus[sample_count++],0); + if(sample_count==0xff) + sample_count=0; + interrupt_ack(); + interrupt_tc_ir_set(INTERRUPT_TC0,INTERRUPT_MATCH0); +} + +void __attribute__ ((interrupt("IRQ"))) input_event(void) { + + u8 noret,tries; + + /* button scan */ + 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; + case BUTTON_MUTE: + audio_mute_toggle(); + break; + default: + display_clear_screen(); + break; + } + } + + /* resume the interrupt at button release */ + noret=1; + while(noret) { + tries=0xff; + noret=1; + while(tries--) { + noret=IOPIN0&(1<<30)?0:1; + if(noret) + break; + } + } + interrupt_ack(); + interrupt_ext_ir_set(INTERRUPT_EXT3); +} /* * main function @@ -42,8 +165,9 @@ const char d2_txt[]="- alphablend -"; int main() { /* variables */ - t_button button; - u8 contrast; + + /* init */ + sample_count=0; /* system init */ pll_init(); @@ -63,93 +187,61 @@ int main() { display_bl_init(); /* button init */ + button.mode=BUTTON_INT; button_init(&button); - button_set_retries(&button,100); + button_set_retries(&button,30); /* flash init */ flash_init(); + /* display init */ + display_init(); + contrast=0x38; + + /* interrupt init */ + interrupt_init(); + + // ext interrupt + interrupt_ext_ir_config(INTERRUPT_EXT3,INTERRUPT_EXT_NOWAKE, + INTERRUPT_EXT_MODE_EDGE, + INTERRUPT_EXT_POLAR_LOW); + interrupt_ext_ir_set(INTERRUPT_EXT3); + interrupt_enable(INTERRUPT_EINT3,INTERRUPT_MODE_VIRQ, + 0,(u32)&input_event); + + // timer interrupt + interrupt_tc_config(INTERRUPT_TC0,INTERRUPT_TC_MODE_T,0,0); + interrupt_tc_match_config(INTERRUPT_TC0,INTERRUPT_M0,AUDIO_TONE_A, + INTERRUPT_TC_MATCH_IR| + INTERRUPT_TC_MATCH_RESET); + interrupt_tc_ir_set(INTERRUPT_TC0,INTERRUPT_MATCH0); + interrupt_enable(INTERRUPT_TIMER0,INTERRUPT_MODE_VIRQ, + 1,(u32)&set_sample); + interrupt_tc_enable(INTERRUPT_TC0); + + /* pwm init */ + pwm_reset; + pwm_set_rate_and_prescaler(0xff,0); + pwm_config(PWM_CHAN2,PWM_SINGLE_EDGE,0,0); + pwm_match_ctrl_config(PWM_CHAN2,PWM_MATCH_RESET); + pwm_enable; + + /* * 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; - } - } + pause(0xffffff); + uart0_send_string((char *)announce); } return 0; } -