aboutsummaryrefslogtreecommitdiff
path: root/speaker.c
diff options
context:
space:
mode:
Diffstat (limited to 'speaker.c')
-rw-r--r--speaker.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/speaker.c b/speaker.c
index 2eace8d..92c1e78 100644
--- a/speaker.c
+++ b/speaker.c
@@ -1,49 +1,45 @@
/* speaker control, uses timer2
*/
+#include "common.h"
+
#include <avr/io.h>
#include <avr/interrupt.h>
+#include <util/delay.h>
#include <stdbool.h>
+#include <assert.h>
+#include <stdlib.h>
#include "speaker.h"
-static bool value = false;
-
-static void speakerSet () {
- if (value) {
- PORTD = PORTD | (1 << PD6);
- } else {
- PORTD = PORTD & ~(1 << PD6);
- }
-}
-
ISR(TIMER2_OVF_vect) {
- value = !value;
- speakerSet ();
+ PORTD ^= (1 << PD6);
}
void speakerInit () {
/* set PD6 to output */
DDRD |= (1 << PD6);
- /* value is false */
- speakerSet ();
+ /* turn off */
+ PORTD = PORTD & ~(1 << PD6);
}
-void speakerStart () {
+void speakerStart (const speakerMode mode) {
/* reset timer value */
TCNT2 = 0;
- /* set normal mode timer0 */
+ /* set normal mode */
TCCR2A = 0;
/* enable overflow interrupt */
TIMSK2 = (1 << TOIE2);
/* io clock with 1024 prescaler */
TCCR2B = ((TCCR2B & ~(1 << CS21)) | (1 << CS22) | (1 << CS20));
+ _delay_ms (50);
+ speakerStop ();
}
void speakerStop () {
/* zero clock source */
TCCR2B = 0;
- value = false;
- speakerSet ();
+ /* turn off */
+ PORTD = PORTD & ~(1 << PD6);
}