aboutsummaryrefslogtreecommitdiff
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
parent91119636631f24bd1bf97f32c3d39f8828da625f (diff)
downloadqmk_firmware-0faa18eab996c2cfcc5da0b60b702f52335c5854.tar.gz
qmk_firmware-0faa18eab996c2cfcc5da0b60b702f52335c5854.zip
audio enable stored in eeprom
-rw-r--r--keyboard/planck/keymaps/default/keymap.c7
-rw-r--r--keyboard/preonic/Makefile4
-rw-r--r--keyboard/preonic/keymaps/default/keymap.c12
-rw-r--r--quantum/audio.c48
-rw-r--r--quantum/audio.h14
-rw-r--r--tmk_core/common/avr/eeconfig.c8
-rw-r--r--tmk_core/common/eeconfig.h6
7 files changed, 89 insertions, 10 deletions
diff --git a/keyboard/planck/keymaps/default/keymap.c b/keyboard/planck/keymaps/default/keymap.c
index 56092d04f..3f34ba412 100644
--- a/keyboard/planck/keymaps/default/keymap.c
+++ b/keyboard/planck/keymaps/default/keymap.c
@@ -135,7 +135,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
135 */ 135 */
136[_AD] = { 136[_AD] = {
137 {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL}, 137 {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL},
138 {_______, _______, _______, _______, _______, _______, _______, M(M_QW), M(M_CM), M(M_DV), _______, _______}, 138 {_______, _______, _______, _______, M(6), _______, _______, M(M_QW), M(M_CM), M(M_DV), _______, _______},
139 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}, 139 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______},
140 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______} 140 {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
141} 141}
@@ -231,6 +231,11 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
231 unregister_code(KC_RSFT); 231 unregister_code(KC_RSFT);
232 } 232 }
233 break; 233 break;
234 case 6:
235 if (record->event.pressed) {
236 audio_toggle();
237 }
238 break;
234 } 239 }
235 return MACRO_NONE; 240 return MACRO_NONE;
236}; 241};
diff --git a/keyboard/preonic/Makefile b/keyboard/preonic/Makefile
index 664aff732..e48052c82 100644
--- a/keyboard/preonic/Makefile
+++ b/keyboard/preonic/Makefile
@@ -139,8 +139,8 @@ COMMAND_ENABLE = yes # Commands for debug and configuration
139# SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend 139# SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
140# NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work 140# NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
141BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality 141BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
142MIDI_ENABLE = YES # MIDI controls 142MIDI_ENABLE = yes # MIDI controls
143AUDIO_ENABLE = YES # Audio output on port C6 143AUDIO_ENABLE = yes # Audio output on port C6
144# UNICODE_ENABLE = YES # Unicode 144# UNICODE_ENABLE = YES # Unicode
145# BLUETOOTH_ENABLE = yes # Enable Bluetooth with the Adafruit EZ-Key HID 145# BLUETOOTH_ENABLE = yes # Enable Bluetooth with the Adafruit EZ-Key HID
146# RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight. Do not enable this with MIDI at the same time. 146# RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight. Do not enable this with MIDI at the same time.
diff --git a/keyboard/preonic/keymaps/default/keymap.c b/keyboard/preonic/keymaps/default/keymap.c
index 784670784..3da69c215 100644
--- a/keyboard/preonic/keymaps/default/keymap.c
+++ b/keyboard/preonic/keymaps/default/keymap.c
@@ -59,11 +59,11 @@ const uint16_t PROGMEM fn_actions[] = {
59}; 59};
60 60
61float start_up[][2] = { 61float start_up[][2] = {
62 {440.0*pow(2.0,(67)/12.0), 600}, 62 {440.0*pow(2.0,(67)/12.0), 4},
63 {440.0*pow(2.0,(64)/12.0), 400}, 63 {440.0*pow(2.0,(64)/12.0), 8},
64 {440.0*pow(2.0,(55)/12.0), 400}, 64 {440.0*pow(2.0,(55)/12.0), 8},
65 {440.0*pow(2.0,(60)/12.0), 400}, 65 {440.0*pow(2.0,(60)/12.0), 8},
66 {440.0*pow(2.0,(64)/12.0), 1000}, 66 {440.0*pow(2.0,(64)/12.0), 10},
67}; 67};
68 68
69const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) 69const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
@@ -76,8 +76,10 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
76 #ifdef BACKLIGHT_ENABLE 76 #ifdef BACKLIGHT_ENABLE
77 backlight_step(); 77 backlight_step();
78 #endif 78 #endif
79 audio_toggle();
79 } else { 80 } else {
80 unregister_code(KC_RSFT); 81 unregister_code(KC_RSFT);
82 play_notes(&start_up, 5, false);
81 } 83 }
82 break; 84 break;
83 } 85 }
diff --git a/quantum/audio.c b/quantum/audio.c
index 50e5505fe..73985479c 100644
--- a/quantum/audio.c
+++ b/quantum/audio.c
@@ -8,6 +8,8 @@
8#include "audio.h" 8#include "audio.h"
9#include "keymap_common.h" 9#include "keymap_common.h"
10 10
11#include "eeconfig.h"
12
11#define PI 3.14159265 13#define PI 3.14159265
12 14
13// #define PWM_AUDIO 15// #define PWM_AUDIO
@@ -57,6 +59,25 @@ uint8_t notes_length;
57bool notes_repeat; 59bool notes_repeat;
58uint8_t current_note = 0; 60uint8_t current_note = 0;
59 61
62audio_config_t audio_config;
63
64
65void audio_toggle(void) {
66 audio_config.enable ^= 1;
67 eeconfig_write_audio(audio_config.raw);
68}
69
70void audio_on(void) {
71 audio_config.enable = 1;
72 eeconfig_write_audio(audio_config.raw);
73}
74
75void audio_off(void) {
76 audio_config.enable = 0;
77 eeconfig_write_audio(audio_config.raw);
78}
79
80
60void stop_all_notes() { 81void stop_all_notes() {
61 voices = 0; 82 voices = 0;
62 #ifdef PWM_AUDIO 83 #ifdef PWM_AUDIO
@@ -129,6 +150,12 @@ void stop_note(double freq) {
129 150
130void init_notes() { 151void init_notes() {
131 152
153 /* check signature */
154 if (!eeconfig_is_enabled()) {
155 eeconfig_init();
156 }
157 audio_config.raw = eeconfig_read_audio();
158
132 #ifdef PWM_AUDIO 159 #ifdef PWM_AUDIO
133 PLLFRQ = _BV(PDIV2); 160 PLLFRQ = _BV(PDIV2);
134 PLLCSR = _BV(PLLE); 161 PLLCSR = _BV(PLLE);
@@ -160,7 +187,6 @@ void init_notes() {
160 187
161 188
162ISR(TIMER3_COMPA_vect) { 189ISR(TIMER3_COMPA_vect) {
163
164 if (note) { 190 if (note) {
165 #ifdef PWM_AUDIO 191 #ifdef PWM_AUDIO
166 if (voices == 1) { 192 if (voices == 1) {
@@ -288,9 +314,16 @@ ISR(TIMER3_COMPA_vect) {
288 314
289 } 315 }
290 316
317 if (!audio_config.enable) {
318 notes = false;
319 note = false;
320 }
291} 321}
292 322
293void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat) { 323void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat) {
324
325if (audio_config.enable) {
326
294 if (note) 327 if (note)
295 stop_all_notes(); 328 stop_all_notes();
296 notes = true; 329 notes = true;
@@ -319,7 +352,12 @@ void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat) {
319 #endif 352 #endif
320} 353}
321 354
355}
356
322void play_sample(uint8_t * s, uint16_t l, bool r) { 357void play_sample(uint8_t * s, uint16_t l, bool r) {
358
359if (audio_config.enable) {
360
323 stop_all_notes(); 361 stop_all_notes();
324 place_int = 0; 362 place_int = 0;
325 sample = s; 363 sample = s;
@@ -330,9 +368,15 @@ void play_sample(uint8_t * s, uint16_t l, bool r) {
330 TIMSK3 |= _BV(OCIE3A); 368 TIMSK3 |= _BV(OCIE3A);
331 #else 369 #else
332 #endif 370 #endif
371
372}
373
333} 374}
334 375
335void play_note(double freq, int vol) { 376void play_note(double freq, int vol) {
377
378if (audio_config.enable) {
379
336 if (notes) 380 if (notes)
337 stop_all_notes(); 381 stop_all_notes();
338 note = true; 382 note = true;
@@ -367,4 +411,6 @@ void play_note(double freq, int vol) {
367 TCCR3A |= _BV(COM3A1); 411 TCCR3A |= _BV(COM3A1);
368 #endif 412 #endif
369 413
414}
415
370} \ No newline at end of file 416} \ No newline at end of file
diff --git a/quantum/audio.h b/quantum/audio.h
index 99203cea7..58270015d 100644
--- a/quantum/audio.h
+++ b/quantum/audio.h
@@ -3,9 +3,21 @@
3#include <avr/io.h> 3#include <avr/io.h>
4#include <util/delay.h> 4#include <util/delay.h>
5 5
6typedef union {
7 uint8_t raw;
8 struct {
9 bool enable :1;
10 uint8_t level :7;
11 };
12} audio_config_t;
13
14void audio_toggle(void);
15void audio_on(void);
16void audio_off(void);
17
6void play_sample(uint8_t * s, uint16_t l, bool r); 18void play_sample(uint8_t * s, uint16_t l, bool r);
7void play_note(double freq, int vol); 19void play_note(double freq, int vol);
8void stop_note(double freq); 20void stop_note(double freq);
9void stop_all_notes(); 21void stop_all_notes();
10void init_notes(); 22void init_notes();
11void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat); \ No newline at end of file 23void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat);
diff --git a/tmk_core/common/avr/eeconfig.c b/tmk_core/common/avr/eeconfig.c
index 5bd47dc6a..d0c3f4f57 100644
--- a/tmk_core/common/avr/eeconfig.c
+++ b/tmk_core/common/avr/eeconfig.c
@@ -13,6 +13,9 @@ void eeconfig_init(void)
13#ifdef BACKLIGHT_ENABLE 13#ifdef BACKLIGHT_ENABLE
14 eeprom_write_byte(EECONFIG_BACKLIGHT, 0); 14 eeprom_write_byte(EECONFIG_BACKLIGHT, 0);
15#endif 15#endif
16#ifdef AUDIO_ENABLE
17 eeprom_write_byte(EECONFIG_AUDIO, 0);
18#endif
16} 19}
17 20
18void eeconfig_enable(void) 21void eeconfig_enable(void)
@@ -43,3 +46,8 @@ void eeconfig_write_keymap(uint8_t val) { eeprom_write_byte(EECONFIG_KEYMAP, val
43uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); } 46uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); }
44void eeconfig_write_backlight(uint8_t val) { eeprom_write_byte(EECONFIG_BACKLIGHT, val); } 47void eeconfig_write_backlight(uint8_t val) { eeprom_write_byte(EECONFIG_BACKLIGHT, val); }
45#endif 48#endif
49
50#ifdef AUDIO_ENABLE
51uint8_t eeconfig_read_audio(void) { return eeprom_read_byte(EECONFIG_AUDIO); }
52void eeconfig_write_audio(uint8_t val) { eeprom_write_byte(EECONFIG_AUDIO, val); }
53#endif \ No newline at end of file
diff --git a/tmk_core/common/eeconfig.h b/tmk_core/common/eeconfig.h
index 3cd1a174f..ddefca134 100644
--- a/tmk_core/common/eeconfig.h
+++ b/tmk_core/common/eeconfig.h
@@ -31,6 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
31#define EECONFIG_KEYMAP (uint8_t *)4 31#define EECONFIG_KEYMAP (uint8_t *)4
32#define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5 32#define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5
33#define EECONFIG_BACKLIGHT (uint8_t *)6 33#define EECONFIG_BACKLIGHT (uint8_t *)6
34#define EECONFIG_AUDIO (uint8_t *)7
34 35
35 36
36/* debug bit */ 37/* debug bit */
@@ -72,4 +73,9 @@ uint8_t eeconfig_read_backlight(void);
72void eeconfig_write_backlight(uint8_t val); 73void eeconfig_write_backlight(uint8_t val);
73#endif 74#endif
74 75
76#ifdef AUDIO_ENABLE
77uint8_t eeconfig_read_audio(void);
78void eeconfig_write_audio(uint8_t val);
79#endif
80
75#endif 81#endif