X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Farm.git;a=blobdiff_plain;f=betty%2Fbetty.c;h=3a3e7a51313d9f398055ad43ce54508b5abffd0a;hp=3b29d2e2207c5a2e2659ea68771c6384a5f0889f;hb=HEAD;hpb=9f1a71389dff6cddd11c4b9975a0d1b91806ee2d diff --git a/betty/betty.c b/betty/betty.c index 3b29d2e..3a3e7a5 100644 --- a/betty/betty.c +++ b/betty/betty.c @@ -38,14 +38,31 @@ void display_string_page(u8 x,u8 p,u8 *s,u8 f,u8 o,u8 sp) { } } +void audio_mute_toggle(void) { + + 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'); + //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_M0); + interrupt_tc_ir_set(INTERRUPT_TC0,INTERRUPT_MATCH0); } void __attribute__ ((interrupt("IRQ"))) input_event(void) { @@ -117,6 +134,9 @@ void __attribute__ ((interrupt("IRQ"))) input_event(void) { 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; @@ -191,16 +211,19 @@ int main() { // timer interrupt interrupt_tc_config(INTERRUPT_TC0,INTERRUPT_TC_MODE_T,0,0); - interrupt_tc_match_config(INTERRUPT_TC0,INTERRUPT_M0,120, - INTERRUPT_TC_MATCH_IR|INTERRUPT_TC_MATCH_RESET); - interrupt_tc_ir_set(INTERRUPT_TC0,INTERRUPT_M0); - interrupt_enable(INTERRUPT_PWM,INTERRUPT_MODE_VIRQ,1,(u32)&set_sample); + 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,0); - interrupt_pwm_ir_set(PWM_CHAN2); + pwm_match_ctrl_config(PWM_CHAN2,PWM_MATCH_RESET); pwm_enable;