// ************************************************************************************************* // @fn start_buzzer // @brief Start buzzer output for a number of cylces // @param u8 cycles Keep buzzer output for number of cycles // u16 on_time Output buzzer for "on_time" ACLK ticks // u16 off_time Do not output buzzer for "off_time" ACLK ticks // @return none // ************************************************************************************************* void start_buzzer(u8 cycles, u16 on_time, u16 off_time) { // Store new buzzer duration while buzzer is off if (sBuzzer.time == 0) { sBuzzer.time = cycles; sBuzzer.on_time = on_time; sBuzzer.off_time = off_time; // Need to init every time, because SimpliciTI claims same timer // Reset TA1R, set up mode, TA1 runs from 32768Hz ACLK TA1CTL = TACLR | MC_1 | TASSEL__ACLK; // Set PWM frequency TA1CCR0 = sBuzzer.steps; // Enable IRQ, set output mode "toggle" TA1CCTL0 = OUTMOD_4; // Allow buzzer PWM output on P2.7 P2SEL |= BIT7; // Activate Timer0_A3 periodic interrupts fptr_Timer0_A3_function = toggle_buzzer; Timer0_A3_Start(sBuzzer.on_time); // Preload timer advance variable sTimer.timer0_A3_ticks = sBuzzer.off_time; // Start with buzzer output on sBuzzer.state = BUZZER_ON_OUTPUT_ENABLED; } }
// ************************************************************************************************* // @fn button_repeat_on // @brief Start button auto repeat timer. // @param none // @return none // ************************************************************************************************* void button_repeat_on(u16 msec) { // Set button repeat flag sys.flag.up_down_repeat_enabled = 1; // Set Timer0_A3 function pointer to button repeat function fptr_Timer0_A3_function = button_repeat_function; // Timer0_A3 IRQ triggers every 200ms Timer0_A3_Start(CONV_MS_TO_TICKS(msec)); }