aboutsummaryrefslogtreecommitdiff
path: root/speaker.c
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2014-09-16 15:31:53 +0200
committerLars-Dominik Braun <lars@6xq.net>2014-09-16 15:33:30 +0200
commitb742ab3a288a1164b4ceb6e58ae42115d320d580 (patch)
tree7df7348f08f79e6e4cb3f492ba77f5d08260fa88 /speaker.c
parent0a9d079451c1ae4ba85f6735943734767140248d (diff)
downloadhourglass-b742ab3a288a1164b4ceb6e58ae42115d320d580.tar.gz
hourglass-b742ab3a288a1164b4ceb6e58ae42115d320d580.tar.bz2
hourglass-b742ab3a288a1164b4ceb6e58ae42115d320d580.zip
Finally fix speaker
Use one timer for LED/speaker. Not sure why two did not work.
Diffstat (limited to 'speaker.c')
-rw-r--r--speaker.c55
1 files changed, 0 insertions, 55 deletions
diff --git a/speaker.c b/speaker.c
deleted file mode 100644
index e96afcf..0000000
--- a/speaker.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/* speaker control, uses timer2
- */
-
-#include "common.h"
-
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <stdbool.h>
-#include <stdlib.h>
-
-#include "speaker.h"
-
-static volatile uint16_t count;
-
-/* Compare interrupt
- */
-ISR(TIMER2_COMPA_vect) {
- PORTD ^= (1 << PD6);
- --count;
- if (count == 0) {
- speakerStop ();
- }
-}
-
-void speakerInit () {
- /* set PD6 to output */
- DDRD |= (1 << PD6);
- /* turn off */
- PORTD = PORTD & ~(1 << PD6);
-}
-
-void speakerStart (const speakerMode mode) {
- /* 12.8ms */
- count = 100;
-
- /* compare value (hit on every tick) */
- OCR2A = 1;
- /* reset timer value */
- TCNT2 = 0;
- /* set ctc mode */
- TCCR2A = (1 << WGM21);
- /* enable overflow interrupt */
- TIMSK2 = (1 << OCIE2A);
- /* io clock with 1024 prescaler -> ~4kHz tone, ctc part2 */
- TCCR2B = (1 << CS22) | (1 << CS21) | (1 << CS20);
-}
-
-void speakerStop () {
- /* zero clock source */
- TCCR2B &= ~(0x7);
- /* turn off */
- PORTD = PORTD & ~(1 << PD6);
-}
-