mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
28 lines
590 B
C
28 lines
590 B
C
|
#include <stdint.h>
|
||
|
#include <buzzer.h>
|
||
|
#include <cc430x613x.h>
|
||
|
|
||
|
void buzzer_beep(uint8_t pitch, uint16_t duration) {
|
||
|
// Reset TA1R, set up mode, TA1 runs from 32768Hz ACLK
|
||
|
TA1CTL = TACLR | MC_1 | TASSEL__ACLK;
|
||
|
|
||
|
// Set PWM frequency
|
||
|
TA1CCR0 = pitch;
|
||
|
|
||
|
// Enable IRQ, set output mode "toggle"
|
||
|
TA1CCTL0 = OUTMOD_4;
|
||
|
|
||
|
// Allow buzzer PWM output on P2.7
|
||
|
P2SEL |= BIT7;
|
||
|
|
||
|
hwtimer_wait(duration);
|
||
|
|
||
|
// Stop PWM timer
|
||
|
TA1CTL &= ~(BIT4 | BIT5);
|
||
|
|
||
|
// Reset and disable buzzer PWM output
|
||
|
P2OUT &= ~BIT7;
|
||
|
P2SEL &= ~BIT7;
|
||
|
TA1CCTL0 &= ~CCIE;
|
||
|
}
|