void ToneAlarm::start_note(unsigned note) { // check if circuit breaker is enabled if (_cbrk == CBRK_UNINIT) { _cbrk = circuit_breaker_enabled("CBRK_BUZZER", CBRK_BUZZER_KEY); } if (_cbrk != CBRK_OFF) { return; } // compute the divisor unsigned divisor = note_to_divisor(note); // pick the lowest prescaler value that we can use // (note that the effective prescale value is 1 greater) unsigned prescale = divisor / 65536; // calculate the timer period for the selected prescaler value unsigned period = (divisor / (prescale + 1)) - 1; #if TONE_ALARM_NOT_DONE rPSC = prescale; // load new prescaler rARR = period; // load new toggle period rEGR = GTIM_EGR_UG; // force a reload of the period rCCER |= TONE_CCER; // enable the output #else prescale++; period++; #endif // configure the GPIO to enable timer output sam_configgpio(GPIO_TONE_ALARM); }
void ToneAlarm::start_note(unsigned note) { // compute the divisor unsigned divisor = note_to_divisor(note); // pick the lowest prescaler value that we can use // (note that the effective prescale value is 1 greater) unsigned prescale = divisor / 65536; // calculate the timer period for the selected prescaler value unsigned period = (divisor / (prescale + 1)) - 1; rPSC = prescale; // load new prescaler rARR = period; // load new toggle period rEGR = GTIM_EGR_UG; // force a reload of the period rCCER |= TONE_CCER; // enable the output // configure the GPIO to enable timer output stm32_configgpio(GPIO_TONE_ALARM); }