]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
audio enable stored in eeprom
authorJack Humbert <jack.humb@gmail.com>
Sat, 16 Apr 2016 03:38:21 +0000 (23:38 -0400)
committerJack Humbert <jack.humb@gmail.com>
Sat, 16 Apr 2016 03:38:21 +0000 (23:38 -0400)
keyboard/planck/keymaps/default/keymap.c
keyboard/preonic/Makefile
keyboard/preonic/keymaps/default/keymap.c
quantum/audio.c
quantum/audio.h
tmk_core/common/avr/eeconfig.c
tmk_core/common/eeconfig.h

index 56092d04fb8715a22792b6f18ee7ae089c498b30..3f34ba4120028f3955aa30ee2a4edf5abcd3efb5 100644 (file)
@@ -135,7 +135,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  */
 [_AD] = {
   {_______, RESET,   _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL},
-  {_______, _______, _______, _______, _______, _______, _______, M(M_QW), M(M_CM), M(M_DV), _______, _______},
+  {_______, _______, _______, _______, M(6),    _______, _______, M(M_QW), M(M_CM), M(M_DV), _______, _______},
   {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______},
   {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
 }
@@ -231,6 +231,11 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
             unregister_code(KC_RSFT);
           }
         break;
+        case 6:
+          if (record->event.pressed) {
+            audio_toggle();
+          }
+        break;
       }
     return MACRO_NONE;
 };
index 664aff7321513479678306a283a16ee691b6d60f..e48052c82570c6e70fa06a8cc1d502ba165227e4 100644 (file)
@@ -139,8 +139,8 @@ COMMAND_ENABLE = yes    # Commands for debug and configuration
 # SLEEP_LED_ENABLE = yes  # Breathing sleep LED during USB suspend
 # NKRO_ENABLE = yes            # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
 BACKLIGHT_ENABLE = yes  # Enable keyboard backlight functionality
-MIDI_ENABLE = YES              # MIDI controls
-AUDIO_ENABLE = YES             # Audio output on port C6
+MIDI_ENABLE = yes              # MIDI controls
+AUDIO_ENABLE = yes             # Audio output on port C6
 # UNICODE_ENABLE = YES                 # Unicode
 # BLUETOOTH_ENABLE = yes # Enable Bluetooth with the Adafruit EZ-Key HID
 # RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight.  Do not enable this with MIDI at the same time.
index 784670784809bd20fb80235ae4918f852cea7fab..3da69c2155c0579635222976060f5dd109b54346 100644 (file)
@@ -59,11 +59,11 @@ const uint16_t PROGMEM fn_actions[] = {
 };
 
 float start_up[][2] = {
-  {440.0*pow(2.0,(67)/12.0), 600},
-  {440.0*pow(2.0,(64)/12.0), 400},
-  {440.0*pow(2.0,(55)/12.0), 400},
-  {440.0*pow(2.0,(60)/12.0), 400},
-  {440.0*pow(2.0,(64)/12.0), 1000},
+  {440.0*pow(2.0,(67)/12.0), 4},
+  {440.0*pow(2.0,(64)/12.0), 8},
+  {440.0*pow(2.0,(55)/12.0), 8},
+  {440.0*pow(2.0,(60)/12.0), 8},
+  {440.0*pow(2.0,(64)/12.0), 10},
 };
 
 const 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)
             #ifdef BACKLIGHT_ENABLE
               backlight_step();
             #endif
+            audio_toggle();
           } else {
             unregister_code(KC_RSFT);
+            play_notes(&start_up, 5, false);
           }
         break;
       }
index 50e5505fe0826dd6f74b833df26eb58558ab4ed8..73985479cceb763bcdf5d720e941d611d6554358 100644 (file)
@@ -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
index 99203cea7ab2ff1a613ba4ba661284a3b643ca7a..58270015df3890497f9718b842d2781ac19dbdd5 100644 (file)
@@ -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);
index 5bd47dc6ad242c9fec46e09e8f568dca6ae8134d..d0c3f4f570fc33c5d2e137b164eaf7d5146f460d 100644 (file)
@@ -13,6 +13,9 @@ void eeconfig_init(void)
 #ifdef BACKLIGHT_ENABLE
     eeprom_write_byte(EECONFIG_BACKLIGHT,      0);
 #endif
+#ifdef AUDIO_ENABLE
+    eeprom_write_byte(EECONFIG_AUDIO,             0);
+#endif
 }
 
 void eeconfig_enable(void)
@@ -43,3 +46,8 @@ void eeconfig_write_keymap(uint8_t val) { eeprom_write_byte(EECONFIG_KEYMAP, val
 uint8_t eeconfig_read_backlight(void)      { return eeprom_read_byte(EECONFIG_BACKLIGHT); }
 void eeconfig_write_backlight(uint8_t val) { eeprom_write_byte(EECONFIG_BACKLIGHT, val); }
 #endif
+
+#ifdef AUDIO_ENABLE
+uint8_t eeconfig_read_audio(void)      { return eeprom_read_byte(EECONFIG_AUDIO); }
+void eeconfig_write_audio(uint8_t val) { eeprom_write_byte(EECONFIG_AUDIO, val); }
+#endif
\ No newline at end of file
index 3cd1a174f6658b2e795e8b0980d9cddf8f93f6d6..ddefca13472aa3bb794a02ff94dfdccba6afd21d 100644 (file)
@@ -31,6 +31,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define EECONFIG_KEYMAP                             (uint8_t *)4
 #define EECONFIG_MOUSEKEY_ACCEL                     (uint8_t *)5
 #define EECONFIG_BACKLIGHT                          (uint8_t *)6
+#define EECONFIG_AUDIO                              (uint8_t *)7
 
 
 /* debug bit */
@@ -72,4 +73,9 @@ uint8_t eeconfig_read_backlight(void);
 void eeconfig_write_backlight(uint8_t val);
 #endif
 
+#ifdef AUDIO_ENABLE
+uint8_t eeconfig_read_audio(void);
+void eeconfig_write_audio(uint8_t val);
+#endif
+
 #endif