mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
[board/chronos/drivers]
* simple buzzer driver
This commit is contained in:
parent
5185fcf7f0
commit
7b5f3900ad
@ -7,6 +7,8 @@ BOARD = chronos ;
|
||||
CPU = cc430 ;
|
||||
MCU = cc430x6137 ;
|
||||
|
||||
HDRS += [ FPath $(TOP) board chronos drivers include ] ;
|
||||
|
||||
FLASHER ?= mspdebug ;
|
||||
FLASHFLAGS ?= rf2500 ;
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
SubDir TOP board chronos drivers ;
|
||||
|
||||
HDRS += $(TOP)/board/$(CPU)/drivers/include ;
|
||||
|
||||
Module board_display : display.c display1.c ;
|
||||
Module board_cc110x : cc430-cc110x.c : cc110x_cc430 ;
|
||||
Module board_buzzer : buzzer.c : hwtimer ;
|
||||
|
27
chronos/drivers/buzzer.c
Normal file
27
chronos/drivers/buzzer.c
Normal file
@ -0,0 +1,27 @@
|
||||
#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;
|
||||
}
|
6
chronos/drivers/include/buzzer.h
Normal file
6
chronos/drivers/include/buzzer.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef BUZZER_H
|
||||
#define BUZZER_H
|
||||
|
||||
void buzzer_beep(uint8_t pitch, uint16_t duration);
|
||||
|
||||
#endif /* BUZZER_H */
|
Loading…
Reference in New Issue
Block a user