summaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2016-04-15 23:38:21 -0400
committerJack Humbert <jack.humb@gmail.com>2016-04-15 23:38:21 -0400
commit0faa18eab996c2cfcc5da0b60b702f52335c5854 (patch)
tree33ed4babd10d6e8051edafa48f142e0e78aeeed5 /quantum
parent91119636631f24bd1bf97f32c3d39f8828da625f (diff)
downloadqmk_firmware-0faa18eab996c2cfcc5da0b60b702f52335c5854.tar.gz
qmk_firmware-0faa18eab996c2cfcc5da0b60b702f52335c5854.zip
audio enable stored in eeprom
Diffstat (limited to 'quantum')
-rw-r--r--quantum/audio.c48
-rw-r--r--quantum/audio.h14
2 files changed, 60 insertions, 2 deletions
diff --git a/quantum/audio.c b/quantum/audio.c
index 50e5505fe0..73985479cc 100644
--- a/quantum/audio.c
+++ b/quantum/audio.c
@@ -8,6 +8,8 @@
#include "audio.h"
#include "keymap_common.h"
+#include "eeconfig.h"
+
#define PI 3.14159265
// #define PWM_AUDIO
@@ -57,6 +59,25 @@ uint8_t notes_length;
bool notes_repeat;
uint8_t current_note = 0;
+audio_config_t audio_config;
+
+
+void audio_toggle(void) {
+ audio_config.enable ^= 1;
+ eeconfig_write_audio(audio_config.raw);
+}
+
+void audio_on(void) {
+ audio_config.enable = 1;
+ eeconfig_write_audio(audio_config.raw);
+}
+
+void audio_off(void) {
+ audio_config.enable = 0;
+ eeconfig_write_audio(audio_config.raw);
+}
+
+
void stop_all_notes() {
voices = 0;
#ifdef PWM_AUDIO
@@ -129,6 +150,12 @@ void stop_note(double freq) {
void init_notes() {
+ /* check signature */
+ if (!eeconfig_is_enabled()) {
+ eeconfig_init();
+ }
+ audio_config.raw = eeconfig_read_audio();
+
#ifdef PWM_AUDIO
PLLFRQ = _BV(PDIV2);
PLLCSR = _BV(PLLE);
@@ -160,7 +187,6 @@ void init_notes() {
ISR(TIMER3_COMPA_vect) {
-
if (note) {
#ifdef PWM_AUDIO
if (voices == 1) {
@@ -288,9 +314,16 @@ ISR(TIMER3_COMPA_vect) {
}
+ if (!audio_config.enable) {
+ notes = false;
+ note = false;
+ }
}
void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat) {
+
+if (audio_config.enable) {
+
if (note)
stop_all_notes();
notes = true;
@@ -319,7 +352,12 @@ void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat) {
#endif
}
+}
+
void play_sample(uint8_t * s, uint16_t l, bool r) {
+
+if (audio_config.enable) {
+
stop_all_notes();
place_int = 0;
sample = s;
@@ -330,9 +368,15 @@ void play_sample(uint8_t * s, uint16_t l, bool r) {
TIMSK3 |= _BV(OCIE3A);
#else
#endif
+
+}
+
}
void play_note(double freq, int vol) {
+
+if (audio_config.enable) {
+
if (notes)
stop_all_notes();
note = true;
@@ -367,4 +411,6 @@ void play_note(double freq, int vol) {
TCCR3A |= _BV(COM3A1);
#endif
+}
+
} \ No newline at end of file
diff --git a/quantum/audio.h b/quantum/audio.h
index 99203cea7a..58270015df 100644
--- a/quantum/audio.h
+++ b/quantum/audio.h
@@ -3,9 +3,21 @@
#include <avr/io.h>
#include <util/delay.h>
+typedef union {
+ uint8_t raw;
+ struct {
+ bool enable :1;
+ uint8_t level :7;
+ };
+} audio_config_t;
+
+void audio_toggle(void);
+void audio_on(void);
+void audio_off(void);
+
void play_sample(uint8_t * s, uint16_t l, bool r);
void play_note(double freq, int vol);
void stop_note(double freq);
void stop_all_notes();
void init_notes();
-void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat); \ No newline at end of file
+void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat);