From 9cfc74c35b940884618b0fe1e6fd25c570e1c974 Mon Sep 17 00:00:00 2001 From: Erez Zukerman Date: Thu, 7 Apr 2016 15:21:06 +0300 Subject: [Erez & Jack] Makes tri-layer available across Quantum --- quantum/keymap_common.c | 8 ++++++++ quantum/keymap_common.h | 4 ++++ 2 files changed, 12 insertions(+) (limited to 'quantum') diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index e3030a8869..3a00d36f08 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -291,3 +291,11 @@ action_t keymap_func_to_action(uint16_t keycode) // For FUNC without 8bit limit return (action_t){ .code = pgm_read_word(&fn_actions[(int)keycode]) }; } + +void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) { + if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) { + layer_on(layer3); + } else { + layer_off(layer3); + } +} diff --git a/quantum/keymap_common.h b/quantum/keymap_common.h index 4a877d2a70..7452a1ff3f 100644 --- a/quantum/keymap_common.h +++ b/quantum/keymap_common.h @@ -208,5 +208,9 @@ extern const uint16_t fn_actions[]; #define UNICODE(n) (n | 0x8000) #define UC(n) UNICODE(n) +// For tri-layer +void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3); +#define IS_LAYER_ON(layer) ((layer_state) & (1UL<<(layer))) +#define IS_LAYER_OFF(layer) ((!layer_state) & (1UL<<(layer))) #endif -- cgit v1.2.3 From 63462bf8c12cea1c13ca1bd1f105fe53f556806e Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Thu, 14 Apr 2016 20:42:14 -0400 Subject: changing up the makefile a bit --- quantum/quantum.mk | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'quantum') diff --git a/quantum/quantum.mk b/quantum/quantum.mk index de93af7e8c..3069f582c3 100644 --- a/quantum/quantum.mk +++ b/quantum/quantum.mk @@ -23,19 +23,19 @@ ifndef CUSTOM_MATRIX SRC += $(QUANTUM_DIR)/matrix.c endif -ifdef MIDI_ENABLE +ifeq ($(MIDI_ENABLE), yes) SRC += $(QUANTUM_DIR)/keymap_midi.c endif -ifdef AUDIO_ENABLE +ifeq ($(AUDIO_ENABLE), yes) SRC += $(QUANTUM_DIR)/audio.c endif -ifdef UNICODE_ENABLE +ifeq ($(UNICODE_ENABLE), yes) SRC += $(QUANTUM_DIR)/keymap_unicode.c endif -ifdef RGBLIGHT_ENABLE +ifeq ($(RGBLIGHT_ENABLE), yes) SRC += $(QUANTUM_DIR)/light_ws2812.c SRC += $(QUANTUM_DIR)/rgblight.c OPT_DEFS += -DRGBLIGHT_ENABLE -- cgit v1.2.3 From bb0836c62016f482f517771a9f5a8dbc68bd0a1c Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Fri, 15 Apr 2016 00:26:22 -0400 Subject: the spacessss --- quantum/quantum.mk | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'quantum') diff --git a/quantum/quantum.mk b/quantum/quantum.mk index 3069f582c3..17bb501718 100644 --- a/quantum/quantum.mk +++ b/quantum/quantum.mk @@ -23,19 +23,19 @@ ifndef CUSTOM_MATRIX SRC += $(QUANTUM_DIR)/matrix.c endif -ifeq ($(MIDI_ENABLE), yes) +ifeq ($(strip $(MIDI_ENABLE)), yes) SRC += $(QUANTUM_DIR)/keymap_midi.c endif -ifeq ($(AUDIO_ENABLE), yes) +ifeq ($(strip $(AUDIO_ENABLE)), yes) SRC += $(QUANTUM_DIR)/audio.c endif -ifeq ($(UNICODE_ENABLE), yes) +ifeq ($(strip $(UNICODE_ENABLE)), yes) SRC += $(QUANTUM_DIR)/keymap_unicode.c endif -ifeq ($(RGBLIGHT_ENABLE), yes) +ifeq ($(strip $(RGBLIGHT_ENABLE)), yes) SRC += $(QUANTUM_DIR)/light_ws2812.c SRC += $(QUANTUM_DIR)/rgblight.c OPT_DEFS += -DRGBLIGHT_ENABLE -- cgit v1.2.3 From ee2ee7f4f049dda385a9db7dddd8e7e91681315b Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Fri, 15 Apr 2016 13:44:07 -0400 Subject: audio note length fixes --- quantum/audio.c | 7 ++++++- quantum/keymap_common.c | 10 ++++------ 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'quantum') diff --git a/quantum/audio.c b/quantum/audio.c index f29d941d7c..50e5505fe0 100644 --- a/quantum/audio.c +++ b/quantum/audio.c @@ -255,7 +255,12 @@ ISR(TIMER3_COMPA_vect) { note_position++; - if (note_position >= note_length) { + bool end_of_note = false; + if (ICR3 > 0) + end_of_note = (note_position >= (note_length / ICR3 * 0xFFFF)); + else + end_of_note = (note_position >= (note_length * 0x7FF)); + if (end_of_note) { current_note++; if (current_note >= notes_length) { if (notes_repeat) { diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index ae6cddb343..e3030a8869 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -33,11 +33,9 @@ along with this program. If not, see . #include "audio.h" float goodbye[][2] = { - {440.0*pow(2.0,(67)/12.0), 400}, - {0, 50}, - {440.0*pow(2.0,(60)/12.0), 400}, - {0, 50}, - {440.0*pow(2.0,(55)/12.0), 600}, + {440.0*pow(2.0,(67)/12.0), 8}, + {440.0*pow(2.0,(60)/12.0), 8}, + {440.0*pow(2.0,(55)/12.0), 12}, }; #endif @@ -90,7 +88,7 @@ action_t action_for_key(uint8_t layer, keypos_t key) action_t action; clear_keyboard(); #ifdef AUDIO_ENABLE - play_notes(&goodbye, 5, false); + play_notes(&goodbye, 3, false); #endif _delay_ms(250); #ifdef ATREUS_ASTAR -- cgit v1.2.3 From 8f85117aa9e060371177e3b523bc89dc7aad19e8 Mon Sep 17 00:00:00 2001 From: IBNobody Date: Fri, 15 Apr 2016 14:42:50 -0500 Subject: Added Audio to my Atomic --- quantum/audio.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'quantum') diff --git a/quantum/audio.h b/quantum/audio.h index 99203cea7a..31f9a35793 100644 --- a/quantum/audio.h +++ b/quantum/audio.h @@ -6,6 +6,6 @@ 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 stop_all_notes(void); +void init_notes(void); void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat); \ No newline at end of file -- cgit v1.2.3 From 0faa18eab996c2cfcc5da0b60b702f52335c5854 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Fri, 15 Apr 2016 23:38:21 -0400 Subject: audio enable stored in eeprom --- quantum/audio.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- quantum/audio.h | 14 +++++++++++++- 2 files changed, 60 insertions(+), 2 deletions(-) (limited to 'quantum') 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 #include +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); -- cgit v1.2.3 From 0b0ec82427aff54481103559066213056b6d7598 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sat, 16 Apr 2016 00:01:22 -0400 Subject: eeprom reset tool --- quantum/tools/README.md | 6 ++++++ quantum/tools/eeprom_reset.hex | 9 +++++++++ 2 files changed, 15 insertions(+) create mode 100644 quantum/tools/README.md create mode 100644 quantum/tools/eeprom_reset.hex (limited to 'quantum') diff --git a/quantum/tools/README.md b/quantum/tools/README.md new file mode 100644 index 0000000000..0702144238 --- /dev/null +++ b/quantum/tools/README.md @@ -0,0 +1,6 @@ +`eeprom_reset.hex` is to reset the eeprom on the Atmega32u4, like this: + + dfu-programmer atmega32u4 erase + dfu-programmer atmega32u4 flash --eeprom eeprom-reset.bin + + You'll need to reflash afterwards, because DFU requires the flash to be erased before messing with the eeprom. \ No newline at end of file diff --git a/quantum/tools/eeprom_reset.hex b/quantum/tools/eeprom_reset.hex new file mode 100644 index 0000000000..a8a75389fe --- /dev/null +++ b/quantum/tools/eeprom_reset.hex @@ -0,0 +1,9 @@ +:10000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00 +:10001000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0 +:10002000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 +:10003000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD0 +:10004000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC0 +:10005000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB0 +:10006000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA0 +:10007000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF90 +:00000001FF -- cgit v1.2.3 From 142ce47698613bb8fb757f13c29928a572a4d9d9 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sat, 16 Apr 2016 01:23:08 -0400 Subject: added keymap_extras to path --- quantum/quantum.mk | 1 + 1 file changed, 1 insertion(+) (limited to 'quantum') diff --git a/quantum/quantum.mk b/quantum/quantum.mk index 17bb501718..1fe7390eba 100644 --- a/quantum/quantum.mk +++ b/quantum/quantum.mk @@ -46,6 +46,7 @@ endif # Search Path VPATH += $(TOP_DIR)/$(QUANTUM_DIR) +VPATH += $(TOP_DIR)/$(QUANTUM_DIR)/keymap_extras include $(TMK_DIR)/protocol/lufa.mk -- cgit v1.2.3 From 86169833c597fa5f2b5226e1587c48a6692ec017 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sat, 16 Apr 2016 15:47:17 -0400 Subject: updates to preonic default, music mode integrated --- quantum/audio.c | 100 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 45 deletions(-) (limited to 'quantum') diff --git a/quantum/audio.c b/quantum/audio.c index 73985479cc..5edcccdbe1 100644 --- a/quantum/audio.c +++ b/quantum/audio.c @@ -32,6 +32,8 @@ int voice_place = 0; double frequency = 0; int volume = 0; long position = 0; +int duty_place = 1; +int duty_counter = 0; double frequencies[8] = {0, 0, 0, 0, 0, 0, 0, 0}; int volumes[8] = {0, 0, 0, 0, 0, 0, 0, 0}; @@ -98,53 +100,55 @@ void stop_all_notes() { } void stop_note(double freq) { - #ifdef PWM_AUDIO - freq = freq / SAMPLE_RATE; - #endif - for (int i = 7; i >= 0; i--) { - if (frequencies[i] == freq) { - frequencies[i] = 0; - volumes[i] = 0; - for (int j = i; (j < 7); j++) { - frequencies[j] = frequencies[j+1]; - frequencies[j+1] = 0; - volumes[j] = volumes[j+1]; - volumes[j+1] = 0; - } - } - } - voices--; - if (voices < 0) - voices = 0; - if (voices == 0) { + if (note) { #ifdef PWM_AUDIO - TIMSK3 &= ~_BV(OCIE3A); - #else - TIMSK3 &= ~_BV(OCIE3A); - TCCR3A &= ~_BV(COM3A1); + freq = freq / SAMPLE_RATE; #endif - frequency = 0; - volume = 0; - note = false; - } else { - double freq = frequencies[voices - 1]; - int vol = volumes[voices - 1]; - double starting_f = frequency; - if (frequency < freq) { - sliding = true; - for (double f = starting_f; f <= freq; f += ((freq - starting_f) / 2000.0)) { - frequency = f; + for (int i = 7; i >= 0; i--) { + if (frequencies[i] == freq) { + frequencies[i] = 0; + volumes[i] = 0; + for (int j = i; (j < 7); j++) { + frequencies[j] = frequencies[j+1]; + frequencies[j+1] = 0; + volumes[j] = volumes[j+1]; + volumes[j+1] = 0; + } } - sliding = false; - } else if (frequency > freq) { - sliding = true; - for (double f = starting_f; f >= freq; f -= ((starting_f - freq) / 2000.0)) { - frequency = f; + } + voices--; + if (voices < 0) + voices = 0; + if (voices == 0) { + #ifdef PWM_AUDIO + TIMSK3 &= ~_BV(OCIE3A); + #else + TIMSK3 &= ~_BV(OCIE3A); + TCCR3A &= ~_BV(COM3A1); + #endif + frequency = 0; + volume = 0; + note = false; + } else { + double freq = frequencies[voices - 1]; + int vol = volumes[voices - 1]; + double starting_f = frequency; + if (frequency < freq) { + sliding = true; + for (double f = starting_f; f <= freq; f += ((freq - starting_f) / 2000.0)) { + frequency = f; + } + sliding = false; + } else if (frequency > freq) { + sliding = true; + for (double f = starting_f; f >= freq; f -= ((starting_f - freq) / 2000.0)) { + frequency = f; + } + sliding = false; } - sliding = false; + frequency = freq; + volume = vol; } - frequency = freq; - volume = vol; } } @@ -239,13 +243,19 @@ ISR(TIMER3_COMPA_vect) { if (frequency > 0) { // ICR3 = (int)(((double)F_CPU) / frequency); // Set max to the period // OCR3A = (int)(((double)F_CPU) / frequency) >> 1; // Set compare to half the period - if (place > 10) { + voice_place %= voices; + if (place > (frequencies[voice_place] / 500)) { voice_place = (voice_place + 1) % voices; place = 0.0; } ICR3 = (int)(((double)F_CPU) / frequencies[voice_place]); // Set max to the period - OCR3A = (int)(((double)F_CPU) / frequencies[voice_place]) >> 1; // Set compare to half the period + OCR3A = (int)(((double)F_CPU) / frequencies[voice_place]) >> 1 * duty_place; // Set compare to half the period place++; + // if (duty_counter > (frequencies[voice_place] / 500)) { + // duty_place = (duty_place % 3) + 1; + // duty_counter = 0; + // } + // duty_counter++; } #endif } @@ -375,7 +385,7 @@ if (audio_config.enable) { void play_note(double freq, int vol) { -if (audio_config.enable) { +if (audio_config.enable && voices < 8) { if (notes) stop_all_notes(); -- cgit v1.2.3 From ab19ebd08a8b955775e6fa94cdf6b8d128d8b43c Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sat, 16 Apr 2016 18:51:58 -0400 Subject: MAGIC functionality, AG swap in default layout --- quantum/keymap_common.c | 250 ++++++++++++++++++++++++++---------------------- quantum/keymap_common.h | 28 +++++- 2 files changed, 163 insertions(+), 115 deletions(-) (limited to 'quantum') diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index 3a00d36f08..b919166853 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -27,6 +27,8 @@ along with this program. If not, see . #include "keymap_midi.h" #include "bootloader.h" +extern keymap_config_t keymap_config; + #include #include #ifdef AUDIO_ENABLE @@ -47,120 +49,9 @@ action_t action_for_key(uint8_t layer, keypos_t key) // 16bit keycodes - important uint16_t keycode = keymap_key_to_keycode(layer, key); - if (keycode >= 0x0100 && keycode < 0x2000) { - // Has a modifier - action_t action; - // Split it up - action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key - return action; - } else if (keycode >= 0x2000 && keycode < 0x3000) { - // Is a shortcut for function layer, pull last 12bits - // This means we have 4,096 FN macros at our disposal - return keymap_func_to_action(keycode & 0xFFF); - } else if (keycode >= 0x3000 && keycode < 0x4000) { - // When the code starts with 3, it's an action macro. - action_t action; - action.code = ACTION_MACRO(keycode & 0xFF); - return action; -#ifdef BACKLIGHT_ENABLE - } else if (keycode >= BL_0 && keycode <= BL_15) { - action_t action; - action.code = ACTION_BACKLIGHT_LEVEL(keycode & 0x000F); - return action; - } else if (keycode == BL_DEC) { - action_t action; - action.code = ACTION_BACKLIGHT_DECREASE(); - return action; - } else if (keycode == BL_INC) { - action_t action; - action.code = ACTION_BACKLIGHT_INCREASE(); - return action; - } else if (keycode == BL_TOGG) { - action_t action; - action.code = ACTION_BACKLIGHT_TOGGLE(); - return action; - } else if (keycode == BL_STEP) { - action_t action; - action.code = ACTION_BACKLIGHT_STEP(); - return action; -#endif - } else if (keycode == RESET) { // RESET is 0x5000, which is why this is here - action_t action; - clear_keyboard(); - #ifdef AUDIO_ENABLE - play_notes(&goodbye, 3, false); - #endif - _delay_ms(250); - #ifdef ATREUS_ASTAR - *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific - #endif - bootloader_jump(); - return action; - } else if (keycode == DEBUG) { // DEBUG is 0x5001 - // TODO: Does this actually work? - action_t action; - print("\nDEBUG: enabled.\n"); - debug_enable = true; - return action; - } else if (keycode >= 0x5000 && keycode < 0x6000) { - // Layer movement shortcuts - // See .h to see constraints/usage - int type = (keycode >> 0x8) & 0xF; - if (type == 0x1) { - // Layer set "GOTO" - int when = (keycode >> 0x4) & 0x3; - int layer = keycode & 0xF; - action_t action; - action.code = ACTION_LAYER_SET(layer, when); - return action; - } else if (type == 0x2) { - // Momentary layer - int layer = keycode & 0xFF; - action_t action; - action.code = ACTION_LAYER_MOMENTARY(layer); - return action; - } else if (type == 0x3) { - // Set default layer - int layer = keycode & 0xFF; - action_t action; - action.code = ACTION_DEFAULT_LAYER_SET(layer); - return action; - } else if (type == 0x4) { - // Set default layer - int layer = keycode & 0xFF; - action_t action; - action.code = ACTION_LAYER_TOGGLE(layer); - return action; - } -#ifdef MIDI_ENABLE - } else if (keycode >= 0x6000 && keycode < 0x7000) { - action_t action; - action.code = ACTION_FUNCTION_OPT(keycode & 0xFF, (keycode & 0x0F00) >> 8); - return action; -#endif - } else if (keycode >= 0x7000 && keycode < 0x8000) { - action_t action; - action.code = ACTION_MODS_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF); - return action; - } else if (keycode >= 0x8000 && keycode < 0x9000) { - action_t action; - action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF); - return action; -#ifdef UNICODE_ENABLE - } else if (keycode >= 0x8000000) { - action_t action; - uint16_t unicode = keycode & ~(0x8000); - action.code = ACTION_FUNCTION_OPT(unicode & 0xFF, (unicode & 0xFF00) >> 8); - return action; -#endif - } else { - - } - switch (keycode) { case KC_FN0 ... KC_FN31: return keymap_fn_to_action(keycode); -#ifdef BOOTMAGIC_ENABLE case KC_CAPSLOCK: case KC_LOCKING_CAPS: if (keymap_config.swap_control_capslock || keymap_config.capslock_to_control) { @@ -224,7 +115,6 @@ action_t action_for_key(uint8_t layer, keypos_t key) return keycode_to_action(KC_BSLASH); } return keycode_to_action(KC_BSPACE); -#endif default: return keycode_to_action(keycode); } @@ -265,6 +155,142 @@ static action_t keycode_to_action(uint16_t keycode) case KC_TRNS: action.code = ACTION_TRANSPARENT; break; + case 0x0100 ... 0x1FFF: ; + // Has a modifier + // Split it up + action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key + break; + case 0x2000 ... 0x2FFF: + // Is a shortcut for function layer, pull last 12bits + // This means we have 4,096 FN macros at our disposal + return keymap_func_to_action(keycode & 0xFFF); + break; + case 0x3000 ... 0x3FFF: ; + // When the code starts with 3, it's an action macro. + action.code = ACTION_MACRO(keycode & 0xFF); + break; + #ifdef BACKLIGHT_ENABLE + case BL_0 ... BL_15: + action.code = ACTION_BACKLIGHT_LEVEL(keycode & 0x000F); + break; + case BL_DEC: + action.code = ACTION_BACKLIGHT_DECREASE(); + break; + case BL_INC: + action.code = ACTION_BACKLIGHT_INCREASE(); + break; + case BL_TOGG: + action.code = ACTION_BACKLIGHT_TOGGLE(); + break; + case BL_STEP: + action.code = ACTION_BACKLIGHT_STEP(); + break; + #endif + case RESET: ; // RESET is 0x5000, which is why this is here + clear_keyboard(); + #ifdef AUDIO_ENABLE + play_notes(&goodbye, 3, false); + #endif + _delay_ms(250); + #ifdef ATREUS_ASTAR + *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific + #endif + bootloader_jump(); + break; + case DEBUG: ; // DEBUG is 0x5001 + print("\nDEBUG: enabled.\n"); + debug_enable = true; + break; + case 0x5002 ... 0x50FF: + // MAGIC actions (BOOTMAGIC without the boot) + if (!eeconfig_is_enabled()) { + eeconfig_init(); + } + /* keymap config */ + keymap_config.raw = eeconfig_read_keymap(); + if (keycode == MAGIC_SWAP_CONTROL_CAPSLOCK) { + keymap_config.swap_control_capslock = 1; + } else if (keycode == MAGIC_CAPSLOCK_TO_CONTROL) { + keymap_config.capslock_to_control = 1; + } else if (keycode == MAGIC_SWAP_LALT_LGUI) { + keymap_config.swap_lalt_lgui = 1; + } else if (keycode == MAGIC_SWAP_RALT_RGUI) { + keymap_config.swap_ralt_rgui = 1; + } else if (keycode == MAGIC_NO_GUI) { + keymap_config.no_gui = 1; + } else if (keycode == MAGIC_SWAP_GRAVE_ESC) { + keymap_config.swap_grave_esc = 1; + } else if (keycode == MAGIC_SWAP_BACKSLASH_BACKSPACE) { + keymap_config.swap_backslash_backspace = 1; + } else if (keycode == MAGIC_HOST_NKRO) { + keymap_config.nkro = 1; + } else if (keycode == MAGIC_SWAP_ALT_GUI) { + keymap_config.swap_lalt_lgui = 1; + keymap_config.swap_ralt_rgui = 1; + } + /* UNs */ + else if (keycode == MAGIC_UNSWAP_CONTROL_CAPSLOCK) { + keymap_config.swap_control_capslock = 0; + } else if (keycode == MAGIC_UNCAPSLOCK_TO_CONTROL) { + keymap_config.capslock_to_control = 0; + } else if (keycode == MAGIC_UNSWAP_LALT_LGUI) { + keymap_config.swap_lalt_lgui = 0; + } else if (keycode == MAGIC_UNSWAP_RALT_RGUI) { + keymap_config.swap_ralt_rgui = 0; + } else if (keycode == MAGIC_UNNO_GUI) { + keymap_config.no_gui = 0; + } else if (keycode == MAGIC_UNSWAP_GRAVE_ESC) { + keymap_config.swap_grave_esc = 0; + } else if (keycode == MAGIC_UNSWAP_BACKSLASH_BACKSPACE) { + keymap_config.swap_backslash_backspace = 0; + } else if (keycode == MAGIC_UNHOST_NKRO) { + keymap_config.nkro = 0; + } else if (keycode == MAGIC_UNSWAP_ALT_GUI) { + keymap_config.swap_lalt_lgui = 0; + keymap_config.swap_ralt_rgui = 0; + } + eeconfig_write_keymap(keymap_config.raw); + break; + case 0x5100 ... 0x5FFF: ; + // Layer movement shortcuts + // See .h to see constraints/usage + int type = (keycode >> 0x8) & 0xF; + if (type == 0x1) { + // Layer set "GOTO" + int when = (keycode >> 0x4) & 0x3; + int layer = keycode & 0xF; + action.code = ACTION_LAYER_SET(layer, when); + } else if (type == 0x2) { + // Momentary layer + int layer = keycode & 0xFF; + action.code = ACTION_LAYER_MOMENTARY(layer); + } else if (type == 0x3) { + // Set default layer + int layer = keycode & 0xFF; + action.code = ACTION_DEFAULT_LAYER_SET(layer); + } else if (type == 0x4) { + // Set default layer + int layer = keycode & 0xFF; + action.code = ACTION_LAYER_TOGGLE(layer); + } + break; + #ifdef MIDI_ENABLE + case 0x6000 ... 0x6FFF: + action.code = ACTION_FUNCTION_OPT(keycode & 0xFF, (keycode & 0x0F00) >> 8); + break; + #endif + case 0x7000 ... 0x7FFF: + action.code = ACTION_MODS_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF); + break; + case 0x8000 ... 0x8FFF: + action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF); + break; + #ifdef UNICODE_ENABLE + case 0x8000000 ... 0x8FFFFFF: + uint16_t unicode = keycode & ~(0x8000); + action.code = ACTION_FUNCTION_OPT(unicode & 0xFF, (unicode & 0xFF00) >> 8); + break; + #endif default: action.code = ACTION_NO; break; diff --git a/quantum/keymap_common.h b/quantum/keymap_common.h index 7452a1ff3f..ce87e4770e 100644 --- a/quantum/keymap_common.h +++ b/quantum/keymap_common.h @@ -30,7 +30,6 @@ along with this program. If not, see . // #include "print.h" #include "debug.h" -#ifdef BOOTMAGIC_ENABLE /* NOTE: Not portable. Bit field order depends on implementation */ typedef union { uint16_t raw; @@ -45,8 +44,6 @@ typedef union { bool nkro:1; }; } keymap_config_t; -keymap_config_t keymap_config; -#endif /* translates key to keycode */ @@ -168,6 +165,30 @@ extern const uint16_t fn_actions[]; #define RESET 0x5000 #define DEBUG 0x5001 +// MAGIC keycodes +#define MAGIC_SWAP_CONTROL_CAPSLOCK 0x5002 +#define MAGIC_UNSWAP_CONTROL_CAPSLOCK 0x5003 +#define MAGIC_CAPSLOCK_TO_CONTROL 0x5004 +#define MAGIC_UNCAPSLOCK_TO_CONTROL 0x5005 +#define MAGIC_SWAP_LALT_LGUI 0x5006 +#define MAGIC_UNSWAP_LALT_LGUI 0x5007 +#define MAGIC_SWAP_RALT_RGUI 0x5008 +#define MAGIC_UNSWAP_RALT_RGUI 0x5009 +#define MAGIC_NO_GUI 0x500a +#define MAGIC_UNNO_GUI 0x500b +#define MAGIC_SWAP_GRAVE_ESC 0x500c +#define MAGIC_UNSWAP_GRAVE_ESC 0x500d +#define MAGIC_SWAP_BACKSLASH_BACKSPACE 0x500e +#define MAGIC_UNSWAP_BACKSLASH_BACKSPACE 0x500f +#define MAGIC_HOST_NKRO 0x5010 +#define MAGIC_UNHOST_NKRO 0x5011 +#define MAGIC_SWAP_ALT_GUI 0x5012 +#define MAGIC_UNSWAP_ALT_GUI 0x5013 + +#define AG_SWAP MAGIC_SWAP_ALT_GUI +#define AG_NORM MAGIC_UNSWAP_ALT_GUI + + // GOTO layer - 16 layers max // when: // ON_PRESS = 1 @@ -213,4 +234,5 @@ void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3); #define IS_LAYER_ON(layer) ((layer_state) & (1UL<<(layer))) #define IS_LAYER_OFF(layer) ((!layer_state) & (1UL<<(layer))) + #endif -- cgit v1.2.3 From c83aa16f1d614c1c10f7597a67ffb9f2ae871951 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sat, 16 Apr 2016 20:26:02 -0400 Subject: fixes audio prescaler to emit correct freq --- quantum/audio.c | 12 +++++++----- quantum/keymap_common.c | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'quantum') diff --git a/quantum/audio.c b/quantum/audio.c index 5edcccdbe1..470dc8e0c7 100644 --- a/quantum/audio.c +++ b/quantum/audio.c @@ -12,6 +12,8 @@ #define PI 3.14159265 +#define CPU_PRESCALER 8 + // #define PWM_AUDIO #ifdef PWM_AUDIO @@ -244,12 +246,12 @@ ISR(TIMER3_COMPA_vect) { // ICR3 = (int)(((double)F_CPU) / frequency); // Set max to the period // OCR3A = (int)(((double)F_CPU) / frequency) >> 1; // Set compare to half the period voice_place %= voices; - if (place > (frequencies[voice_place] / 500)) { + if (place > (frequencies[voice_place] / 50)) { voice_place = (voice_place + 1) % voices; place = 0.0; } - ICR3 = (int)(((double)F_CPU) / frequencies[voice_place]); // Set max to the period - OCR3A = (int)(((double)F_CPU) / frequencies[voice_place]) >> 1 * duty_place; // Set compare to half the period + ICR3 = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)); // Set max to the period + OCR3A = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)) >> 1 * duty_place; // Set compare to half the period place++; // if (duty_counter > (frequencies[voice_place] / 500)) { // duty_place = (duty_place % 3) + 1; @@ -281,8 +283,8 @@ ISR(TIMER3_COMPA_vect) { place -= SINE_LENGTH; #else if (note_frequency > 0) { - ICR3 = (int)(((double)F_CPU) / note_frequency); // Set max to the period - OCR3A = (int)(((double)F_CPU) / note_frequency) >> 1; // Set compare to half the period + ICR3 = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)); // Set max to the period + OCR3A = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)) >> 1; // Set compare to half the period } else { ICR3 = 0; OCR3A = 0; diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index b919166853..899437f447 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -35,9 +35,9 @@ extern keymap_config_t keymap_config; #include "audio.h" float goodbye[][2] = { - {440.0*pow(2.0,(67)/12.0), 8}, - {440.0*pow(2.0,(60)/12.0), 8}, - {440.0*pow(2.0,(55)/12.0), 12}, + {440.0*pow(2.0,(31)/12.0), 8}, + {440.0*pow(2.0,(24)/12.0), 8}, + {440.0*pow(2.0,(19)/12.0), 12}, }; #endif -- cgit v1.2.3 From 41cc35425ab32c9a9492006da8b667d01d32dfa6 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sat, 16 Apr 2016 21:31:40 -0400 Subject: rests between notes as an argument --- quantum/audio.c | 29 +++++++++++++++++++++-------- quantum/audio.h | 3 ++- quantum/keymap_common.c | 2 +- 3 files changed, 24 insertions(+), 10 deletions(-) (limited to 'quantum') diff --git a/quantum/audio.c b/quantum/audio.c index 470dc8e0c7..40d09d62fd 100644 --- a/quantum/audio.c +++ b/quantum/audio.c @@ -61,7 +61,11 @@ uint16_t note_position = 0; float (* notes_pointer)[][2]; uint8_t notes_length; bool notes_repeat; +float notes_rest; +bool note_resting = false; + uint8_t current_note = 0; +uint8_t rest_counter = 0; audio_config_t audio_config; @@ -314,13 +318,21 @@ ISR(TIMER3_COMPA_vect) { return; } } - #ifdef PWM_AUDIO - note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE; - note_length = (*notes_pointer)[current_note][1]; - #else - note_frequency = (*notes_pointer)[current_note][0]; - note_length = (*notes_pointer)[current_note][1] / 4; - #endif + if (!note_resting && ((int)notes_rest != 0)) { + note_resting = true; + note_frequency = 0; + note_length = notes_rest; + current_note--; + } else { + note_resting = false; + #ifdef PWM_AUDIO + note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE; + note_length = (*notes_pointer)[current_note][1]; + #else + note_frequency = (*notes_pointer)[current_note][0]; + note_length = (*notes_pointer)[current_note][1] / 4; + #endif + } note_position = 0; } @@ -332,7 +344,7 @@ ISR(TIMER3_COMPA_vect) { } } -void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat) { +void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat, float n_rest) { if (audio_config.enable) { @@ -343,6 +355,7 @@ if (audio_config.enable) { notes_pointer = np; notes_length = n_length; notes_repeat = n_repeat; + notes_rest = n_rest; place = 0; current_note = 0; diff --git a/quantum/audio.h b/quantum/audio.h index 58270015df..65a6f9434d 100644 --- a/quantum/audio.h +++ b/quantum/audio.h @@ -2,6 +2,7 @@ #include #include #include +#include "musical_notes.h" typedef union { uint8_t raw; @@ -20,4 +21,4 @@ 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); +void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat, float n_rest); diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index 899437f447..457f70a448 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -189,7 +189,7 @@ static action_t keycode_to_action(uint16_t keycode) case RESET: ; // RESET is 0x5000, which is why this is here clear_keyboard(); #ifdef AUDIO_ENABLE - play_notes(&goodbye, 3, false); + play_notes(&goodbye, 3, false, 0); #endif _delay_ms(250); #ifdef ATREUS_ASTAR -- cgit v1.2.3 From 8bbd064cf52a76508589579f19595607a1f3af21 Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sat, 16 Apr 2016 23:07:50 -0400 Subject: changes to play_notes, goodbye --- quantum/audio.c | 2 +- quantum/keymap_common.c | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'quantum') diff --git a/quantum/audio.c b/quantum/audio.c index 40d09d62fd..773edfd8ee 100644 --- a/quantum/audio.c +++ b/quantum/audio.c @@ -318,7 +318,7 @@ ISR(TIMER3_COMPA_vect) { return; } } - if (!note_resting && ((int)notes_rest != 0)) { + if (!note_resting && (notes_rest > 0)) { note_resting = true; note_frequency = 0; note_length = notes_rest; diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index 457f70a448..8f35521a2d 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -33,12 +33,14 @@ extern keymap_config_t keymap_config; #include #ifdef AUDIO_ENABLE #include "audio.h" - - float goodbye[][2] = { - {440.0*pow(2.0,(31)/12.0), 8}, - {440.0*pow(2.0,(24)/12.0), 8}, - {440.0*pow(2.0,(19)/12.0), 12}, - }; + #ifndef GOODBYE_TUNE + #define GOODBYE_TUNE { \ + {440.0*pow(2.0,(31)/12.0), 8}, \ + {440.0*pow(2.0,(24)/12.0), 8}, \ + {440.0*pow(2.0,(19)/12.0), 12}, \ + } + #endif + float goodbye_tune[][2] = GOODBYE_TUNE; #endif static action_t keycode_to_action(uint16_t keycode); @@ -189,7 +191,7 @@ static action_t keycode_to_action(uint16_t keycode) case RESET: ; // RESET is 0x5000, which is why this is here clear_keyboard(); #ifdef AUDIO_ENABLE - play_notes(&goodbye, 3, false, 0); + play_notes(&goodbye_tune, false, 0); #endif _delay_ms(250); #ifdef ATREUS_ASTAR -- cgit v1.2.3 From 45f10b4c4b308226fa1568277654a13853a03ab4 Mon Sep 17 00:00:00 2001 From: IBNobody Date: Sat, 16 Apr 2016 22:10:18 -0500 Subject: Fixed how note arrays are used. --- quantum/audio.c | 14 +++++++------- quantum/audio.h | 17 +++++++++++++++-- quantum/keymap_common.c | 4 ++-- quantum/musical_notes.h | 7 ++++++- 4 files changed, 30 insertions(+), 12 deletions(-) (limited to 'quantum') diff --git a/quantum/audio.c b/quantum/audio.c index 40d09d62fd..90f3c5a13f 100644 --- a/quantum/audio.c +++ b/quantum/audio.c @@ -181,7 +181,7 @@ void init_notes() { DDRC |= _BV(PORTC6); TIMSK3 &= ~_BV(OCIE3A); // Turn off 3A interputs - + TCCR3A = 0x0; // Options not needed TCCR3B = _BV(CS31) | _BV(CS30) | _BV(WGM32); // 64th prescaling and CTC OCR3A = SAMPLE_DIVIDER - 1; // Correct count/compare, related to sample playback @@ -202,14 +202,14 @@ ISR(TIMER3_COMPA_vect) { if (voices == 1) { // SINE OCR4A = pgm_read_byte(&sinewave[(uint16_t)place]) >> 2; - + // SQUARE // if (((int)place) >= 1024){ // OCR4A = 0xFF >> 2; // } else { // OCR4A = 0x00; // } - + // SAWTOOTH // OCR4A = (int)place / 4; @@ -298,9 +298,9 @@ ISR(TIMER3_COMPA_vect) { note_position++; bool end_of_note = false; - if (ICR3 > 0) + if (ICR3 > 0) end_of_note = (note_position >= (note_length / ICR3 * 0xFFFF)); - else + else end_of_note = (note_position >= (note_length * 0x7FF)); if (end_of_note) { current_note++; @@ -318,7 +318,7 @@ ISR(TIMER3_COMPA_vect) { return; } } - if (!note_resting && ((int)notes_rest != 0)) { + if (!note_resting && (notes_rest > 0)) { note_resting = true; note_frequency = 0; note_length = notes_rest; @@ -412,7 +412,7 @@ if (audio_config.enable && voices < 8) { if (frequency != 0) { double starting_f = frequency; if (frequency < freq) { - for (double f = starting_f; f <= freq; f += ((freq - starting_f) / 2000.0)) { + for (double f = starting_f; f <= freq; f += ((freq - starting_f) / 2000.0)) { frequency = f; } } else if (frequency > freq) { diff --git a/quantum/audio.h b/quantum/audio.h index 65a6f9434d..762c980643 100644 --- a/quantum/audio.h +++ b/quantum/audio.h @@ -4,6 +4,9 @@ #include #include "musical_notes.h" +#ifndef AUDIO_H +#define AUDIO_H + typedef union { uint8_t raw; struct { @@ -19,6 +22,16 @@ 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 stop_all_notes(void); +void init_notes(void); void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat, float n_rest); + + +// These macros are used to allow play_notes to play an array of indeterminate +// length. This works around the limitation of C's sizeof operation on pointers. +// The global float array for the song must be used here. +#define NOTE_ARRAY_SIZE(x) ((int)(sizeof(x) / (sizeof(x[0])))) +#define PLAY_NOTE_ARRAY(note_array, note_repeat, note_rest_style) play_notes(¬e_array, NOTE_ARRAY_SIZE((note_array)), (note_repeat), (note_rest_style)); + + +#endif \ No newline at end of file diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index 457f70a448..61a51aedb4 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -189,7 +189,7 @@ static action_t keycode_to_action(uint16_t keycode) case RESET: ; // RESET is 0x5000, which is why this is here clear_keyboard(); #ifdef AUDIO_ENABLE - play_notes(&goodbye, 3, false, 0); + PLAY_NOTE_ARRAY(goodbye, false, 0); #endif _delay_ms(250); #ifdef ATREUS_ASTAR @@ -202,7 +202,7 @@ static action_t keycode_to_action(uint16_t keycode) debug_enable = true; break; case 0x5002 ... 0x50FF: - // MAGIC actions (BOOTMAGIC without the boot) + // MAGIC actions (BOOTMAGIC without the boot) if (!eeconfig_is_enabled()) { eeconfig_init(); } diff --git a/quantum/musical_notes.h b/quantum/musical_notes.h index 79f04fd988..837f6a069d 100644 --- a/quantum/musical_notes.h +++ b/quantum/musical_notes.h @@ -9,7 +9,7 @@ #define WHOLE_NOTE(note) {(NOTE##note), 64} #define HALF_NOTE(note) {(NOTE##note), 32} #define QUARTER_NOTE(note) {(NOTE##note), 16} -#define EIGTH_NOTE(note) {(NOTE##note), 8} +#define EIGHTH_NOTE(note) {(NOTE##note), 8} #define SIXTEENTH_NOTE(note) {(NOTE##note), 4} // Note Types Short @@ -19,6 +19,11 @@ #define E_NOTE(n) EIGTH_NOTE(n) #define S_NOTE(n) SIXTEENTH_NOTE(n) +// Note Styles +// Staccato makes sure there is a rest between each note. Think: TA TA TA +// Legato makes notes flow together. Think: TAAA +#define STACCATO 0.01 +#define LEGATO 0 // Notes - # = Octave #define NOTE_REST 0.00 -- cgit v1.2.3 From a67d425f4d5278595e7ab785a0f246b83fb1a09f Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sun, 17 Apr 2016 01:00:39 -0400 Subject: planck default layout updates --- quantum/audio.c | 5 +++-- quantum/keymap_common.c | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'quantum') diff --git a/quantum/audio.c b/quantum/audio.c index 90f3c5a13f..6bd6532a3a 100644 --- a/quantum/audio.c +++ b/quantum/audio.c @@ -350,7 +350,6 @@ if (audio_config.enable) { if (note) stop_all_notes(); - notes = true; notes_pointer = np; notes_length = n_length; @@ -375,6 +374,8 @@ if (audio_config.enable) { TIMSK3 |= _BV(OCIE3A); TCCR3A |= _BV(COM3A1); #endif + + notes = true; } } @@ -404,7 +405,6 @@ if (audio_config.enable && voices < 8) { if (notes) stop_all_notes(); - note = true; #ifdef PWM_AUDIO freq = freq / SAMPLE_RATE; #endif @@ -436,6 +436,7 @@ if (audio_config.enable && voices < 8) { TCCR3A |= _BV(COM3A1); #endif + note = true; } } \ No newline at end of file diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index 02d3c74be6..d38e6fdb20 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -33,14 +33,14 @@ extern keymap_config_t keymap_config; #include #ifdef AUDIO_ENABLE #include "audio.h" - #ifndef GOODBYE_TUNE - #define GOODBYE_TUNE { \ + #ifndef TONE_GOODBYE + #define TONE_GOODBYE { \ {440.0*pow(2.0,(31)/12.0), 8}, \ {440.0*pow(2.0,(24)/12.0), 8}, \ {440.0*pow(2.0,(19)/12.0), 12}, \ } #endif - float goodbye_tune[][2] = GOODBYE_TUNE; + float tone_goodbye[][2] = TONE_GOODBYE; #endif static action_t keycode_to_action(uint16_t keycode); @@ -191,7 +191,7 @@ static action_t keycode_to_action(uint16_t keycode) case RESET: ; // RESET is 0x5000, which is why this is here clear_keyboard(); #ifdef AUDIO_ENABLE - PLAY_NOTE_ARRAY(goodbye_tune, false, 0); + PLAY_NOTE_ARRAY(tone_goodbye, false, 0); #endif _delay_ms(250); #ifdef ATREUS_ASTAR -- cgit v1.2.3 From 943b5b770955be937a89016680052be56d874c4a Mon Sep 17 00:00:00 2001 From: IBNobody Date: Sun, 17 Apr 2016 00:24:58 -0500 Subject: Adding folding to #if, etc --- quantum/audio.c | 3 ++- quantum/musical_notes.h | 38 +++++++++++++++++++++++++++----------- quantum/song_list.h | 12 ++++++++++++ 3 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 quantum/song_list.h (limited to 'quantum') diff --git a/quantum/audio.c b/quantum/audio.c index 90f3c5a13f..119bd92298 100644 --- a/quantum/audio.c +++ b/quantum/audio.c @@ -288,7 +288,8 @@ ISR(TIMER3_COMPA_vect) { #else if (note_frequency > 0) { ICR3 = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)); // Set max to the period - OCR3A = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)) >> 1; // Set compare to half the period + //OCR3A = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)) >> 1; // Set compare to half the period + OCR3A = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)) >> 2; // Set compare to half the period } else { ICR3 = 0; OCR3A = 0; diff --git a/quantum/musical_notes.h b/quantum/musical_notes.h index 837f6a069d..d2256a7736 100644 --- a/quantum/musical_notes.h +++ b/quantum/musical_notes.h @@ -4,20 +4,36 @@ // Tempo Placeholder #define TEMPO 120 +#define SONG(notes...) { notes } + // Note Types -#define WHOLE_NOTE(note) {(NOTE##note), 64} -#define HALF_NOTE(note) {(NOTE##note), 32} -#define QUARTER_NOTE(note) {(NOTE##note), 16} -#define EIGHTH_NOTE(note) {(NOTE##note), 8} -#define SIXTEENTH_NOTE(note) {(NOTE##note), 4} +#define MUSICAL_NOTE(note, duration) {(NOTE##note), duration} +#define WHOLE_NOTE(note) MUSICAL_NOTE(note, 64) +#define HALF_NOTE(note) MUSICAL_NOTE(note, 32) +#define QUARTER_NOTE(note) MUSICAL_NOTE(note, 16) +#define EIGHTH_NOTE(note) MUSICAL_NOTE(note, 8) +#define SIXTEENTH_NOTE(note) MUSICAL_NOTE(note, 4) + +#define WHOLE_DOT_NOTE(note) MUSICAL_NOTE(note, 64+32) +#define HALF_DOT_NOTE(note) MUSICAL_NOTE(note, 32+16) +#define QUARTER_DOT_NOTE(note) MUSICAL_NOTE(note, 16+8) +#define EIGHTH_DOT_NOTE(note) MUSICAL_NOTE(note, 8+4) +#define SIXTEENTH_DOT_NOTE(note) MUSICAL_NOTE(note, 4+2) + -// Note Types Short -#define W_NOTE(n) WHOLE_NOTE(n) -#define H_NOTE(n) HALF_NOTE(n) -#define Q_NOTE(n) QUARTER_NOTE(n) -#define E_NOTE(n) EIGTH_NOTE(n) -#define S_NOTE(n) SIXTEENTH_NOTE(n) +// Note Type Shortcuts +#define M__NOTE(note, duration) MUSICAL_NOTE(note, duration) +#define W__NOTE(n) WHOLE_NOTE(n) +#define H__NOTE(n) HALF_NOTE(n) +#define Q__NOTE(n) QUARTER_NOTE(n) +#define E__NOTE(n) EIGHTH_NOTE(n) +#define S__NOTE(n) SIXTEENTH_NOTE(n) +#define WD_NOTE(n) WHOLE_DOT_NOTE(n) +#define HD_NOTE(n) HALF_DOT_NOTE(n) +#define QD_NOTE(n) QUARTER_DOT_NOTE(n) +#define ED_NOTE(n) EIGTH_DOT_NOTE(n) +#define SD_NOTE(n) SIXTEENTH_DOT_NOTE(n) // Note Styles // Staccato makes sure there is a rest between each note. Think: TA TA TA diff --git a/quantum/song_list.h b/quantum/song_list.h new file mode 100644 index 0000000000..ef25eac35a --- /dev/null +++ b/quantum/song_list.h @@ -0,0 +1,12 @@ +#include "musical_notes.h" + +#ifndef SONG_LIST_H +#define SONG_LIST_H + +#define ODE_TO_JOY \ + Q__NOTE(_E4), Q__NOTE(_E4), Q__NOTE(_F4), Q__NOTE(_G4), \ + Q__NOTE(_G4), Q__NOTE(_F4), Q__NOTE(_E4), Q__NOTE(_D4), \ + Q__NOTE(_C4), Q__NOTE(_C4), Q__NOTE(_D4), Q__NOTE(_E4), \ + QD_NOTE(_E4), E__NOTE(_D4), H__NOTE(_D4), + +#endif \ No newline at end of file -- cgit v1.2.3 From 29e495be2a57d1eb41699909b204c12ac6bc4c0e Mon Sep 17 00:00:00 2001 From: IBNobody Date: Sun, 17 Apr 2016 02:52:38 -0500 Subject: Added trimble and tempo adjustments! --- quantum/audio.c | 56 +++++++++++++++++++++++++++++++++++++------------ quantum/audio.h | 6 +++++- quantum/musical_notes.h | 13 ++++++++++-- quantum/song_list.h | 6 ++++++ 4 files changed, 65 insertions(+), 16 deletions(-) (limited to 'quantum') diff --git a/quantum/audio.c b/quantum/audio.c index 119bd92298..9b9589f133 100644 --- a/quantum/audio.c +++ b/quantum/audio.c @@ -4,7 +4,7 @@ #include #include #include - +#include "print.h" #include "audio.h" #include "keymap_common.h" @@ -57,9 +57,11 @@ bool notes = false; bool note = false; float note_frequency = 0; float note_length = 0; +float note_tempo = TEMPO_DEFAULT; +float note_timbre = TIMBRE_DEFAULT; uint16_t note_position = 0; float (* notes_pointer)[][2]; -uint8_t notes_length; +uint8_t notes_count; bool notes_repeat; float notes_rest; bool note_resting = false; @@ -255,7 +257,8 @@ ISR(TIMER3_COMPA_vect) { place = 0.0; } ICR3 = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)); // Set max to the period - OCR3A = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)) >> 1 * duty_place; // Set compare to half the period + OCR3A = (int)((((double)F_CPU) / (note_frequency * CPU_PRESCALER)) * note_timbre); // Set compare to half the period + //OCR3A = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)) >> 1 * duty_place; // Set compare to half the period place++; // if (duty_counter > (frequencies[voice_place] / 500)) { // duty_place = (duty_place % 3) + 1; @@ -288,8 +291,7 @@ ISR(TIMER3_COMPA_vect) { #else if (note_frequency > 0) { ICR3 = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)); // Set max to the period - //OCR3A = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)) >> 1; // Set compare to half the period - OCR3A = (int)(((double)F_CPU) / (note_frequency * CPU_PRESCALER)) >> 2; // Set compare to half the period + OCR3A = (int)((((double)F_CPU) / (note_frequency * CPU_PRESCALER)) * note_timbre); // Set compare to half the period } else { ICR3 = 0; OCR3A = 0; @@ -305,7 +307,7 @@ ISR(TIMER3_COMPA_vect) { end_of_note = (note_position >= (note_length * 0x7FF)); if (end_of_note) { current_note++; - if (current_note >= notes_length) { + if (current_note >= notes_count) { if (notes_repeat) { current_note = 0; } else { @@ -328,10 +330,10 @@ ISR(TIMER3_COMPA_vect) { note_resting = false; #ifdef PWM_AUDIO note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE; - note_length = (*notes_pointer)[current_note][1]; + note_length = (*notes_pointer)[current_note][1] * (note_tempo / 100); #else note_frequency = (*notes_pointer)[current_note][0]; - note_length = (*notes_pointer)[current_note][1] / 4; + note_length = ((*notes_pointer)[current_note][1] / 4) * (note_tempo / 100); #endif } note_position = 0; @@ -345,7 +347,7 @@ ISR(TIMER3_COMPA_vect) { } } -void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat, float n_rest) { +void play_notes(float (*np)[][2], uint8_t n_count, bool n_repeat, float n_rest) { if (audio_config.enable) { @@ -354,7 +356,7 @@ if (audio_config.enable) { notes = true; notes_pointer = np; - notes_length = n_length; + notes_count = n_count; notes_repeat = n_repeat; notes_rest = n_rest; @@ -362,10 +364,10 @@ if (audio_config.enable) { current_note = 0; #ifdef PWM_AUDIO note_frequency = (*notes_pointer)[current_note][0] / SAMPLE_RATE; - note_length = (*notes_pointer)[current_note][1]; + note_length = (*notes_pointer)[current_note][1] * (note_tempo / 100); #else note_frequency = (*notes_pointer)[current_note][0]; - note_length = (*notes_pointer)[current_note][1] / 4; + note_length = ((*notes_pointer)[current_note][1] / 4) * (note_tempo / 100); #endif note_position = 0; @@ -439,4 +441,32 @@ if (audio_config.enable && voices < 8) { } -} \ No newline at end of file +} + +void set_timbre(float timbre) +{ + note_timbre = timbre; +} + +void set_tempo(float tempo) +{ + note_tempo = tempo; +} + +void decrease_tempo(uint8_t tempo_change) +{ + note_tempo += (float) tempo_change; +} + +void increase_tempo(uint8_t tempo_change) +{ + if (note_tempo - (float) tempo_change < 10) + { + note_tempo = 10; + } + else + { + note_tempo -= (float) tempo_change; + } +} + diff --git a/quantum/audio.h b/quantum/audio.h index 762c980643..8012aa6bf1 100644 --- a/quantum/audio.h +++ b/quantum/audio.h @@ -24,8 +24,12 @@ void play_note(double freq, int vol); void stop_note(double freq); void stop_all_notes(void); void init_notes(void); -void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat, float n_rest); +void play_notes(float (*np)[][2], uint8_t n_count, bool n_repeat, float n_rest); +void set_timbre(float timbre); +void set_tempo(float tempo); +void increase_tempo(uint8_t tempo_change); +void decrease_tempo(uint8_t tempo_change); // These macros are used to allow play_notes to play an array of indeterminate // length. This works around the limitation of C's sizeof operation on pointers. diff --git a/quantum/musical_notes.h b/quantum/musical_notes.h index d2256a7736..2170f3f18b 100644 --- a/quantum/musical_notes.h +++ b/quantum/musical_notes.h @@ -2,7 +2,8 @@ #define MUSICAL_NOTES_H // Tempo Placeholder -#define TEMPO 120 +#define TEMPO_DEFAULT 100 + #define SONG(notes...) { notes } @@ -21,7 +22,6 @@ #define EIGHTH_DOT_NOTE(note) MUSICAL_NOTE(note, 8+4) #define SIXTEENTH_DOT_NOTE(note) MUSICAL_NOTE(note, 4+2) - // Note Type Shortcuts #define M__NOTE(note, duration) MUSICAL_NOTE(note, duration) #define W__NOTE(n) WHOLE_NOTE(n) @@ -41,6 +41,15 @@ #define STACCATO 0.01 #define LEGATO 0 +// Note Timbre +// Changes how the notes sound +#define TIMBRE_12 0.125 +#define TIMBRE_25 0.250 +#define TIMBRE_50 0.500 +#define TIMBRE_75 0.750 +#define TIMBRE_DEFAULT TIMBRE_50 + + // Notes - # = Octave #define NOTE_REST 0.00 #define NOTE_C0 16.35 diff --git a/quantum/song_list.h b/quantum/song_list.h index ef25eac35a..ef36a1cddf 100644 --- a/quantum/song_list.h +++ b/quantum/song_list.h @@ -9,4 +9,10 @@ Q__NOTE(_C4), Q__NOTE(_C4), Q__NOTE(_D4), Q__NOTE(_E4), \ QD_NOTE(_E4), E__NOTE(_D4), H__NOTE(_D4), +#define ROCK_A_BYE_BABY \ + QD_NOTE(_B4), E__NOTE(_D4), Q__NOTE(_B5), \ + H__NOTE(_A5), Q__NOTE(_G5), \ + QD_NOTE(_B4), E__NOTE(_D5), Q__NOTE(_G5), \ + H__NOTE(_FS5), + #endif \ No newline at end of file -- cgit v1.2.3 From c940e87235c9fe26f5c7451464af54a493270a68 Mon Sep 17 00:00:00 2001 From: IBNobody Date: Sun, 17 Apr 2016 10:41:07 -0500 Subject: fixed single note play copy/paste bug --- quantum/audio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'quantum') diff --git a/quantum/audio.c b/quantum/audio.c index 9b9589f133..58b9ab76bf 100644 --- a/quantum/audio.c +++ b/quantum/audio.c @@ -257,7 +257,7 @@ ISR(TIMER3_COMPA_vect) { place = 0.0; } ICR3 = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)); // Set max to the period - OCR3A = (int)((((double)F_CPU) / (note_frequency * CPU_PRESCALER)) * note_timbre); // Set compare to half the period + OCR3A = (int)((((double)F_CPU) /(frequencies[voice_place] * CPU_PRESCALER)) * note_timbre); // Set compare to half the period //OCR3A = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)) >> 1 * duty_place; // Set compare to half the period place++; // if (duty_counter > (frequencies[voice_place] / 500)) { -- cgit v1.2.3 From 90289aa53fe06a867c773d447c6d3a950575d69a Mon Sep 17 00:00:00 2001 From: a0-c Date: Sun, 17 Apr 2016 06:51:39 -1000 Subject: __attribute__ ((weak)) added to led_set __attribute__ ((weak)) added to led_set --- quantum/led.c | 1 + 1 file changed, 1 insertion(+) (limited to 'quantum') diff --git a/quantum/led.c b/quantum/led.c index 9cdb8a5c20..208e348f34 100644 --- a/quantum/led.c +++ b/quantum/led.c @@ -24,6 +24,7 @@ void led_set_kb(uint8_t usb_led) { } +__attribute__ ((weak)) void led_set(uint8_t usb_led) { -- cgit v1.2.3 From d5b72e7bde5ede25f7d5699b50b7d9eb6f31ba92 Mon Sep 17 00:00:00 2001 From: IBNobody Date: Sun, 17 Apr 2016 12:54:32 -0500 Subject: Fixed many compiler warnings related to print being disabled --- quantum/keymap_common.c | 1 + 1 file changed, 1 insertion(+) (limited to 'quantum') diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index 61a51aedb4..ce1d007f3a 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -26,6 +26,7 @@ along with this program. If not, see . #include "backlight.h" #include "keymap_midi.h" #include "bootloader.h" +#include "eeconfig.h" extern keymap_config_t keymap_config; -- cgit v1.2.3 From 23231fa577f7c6c585124226a83f21a7668e62dd Mon Sep 17 00:00:00 2001 From: IBNobody Date: Sun, 17 Apr 2016 14:16:03 -0500 Subject: Converted goodbye to notes, fixed eighth dotted note macro --- quantum/audio.h | 1 + quantum/keymap_common.c | 14 ++++++-------- quantum/musical_notes.h | 2 +- quantum/song_list.h | 7 ++++++- 4 files changed, 14 insertions(+), 10 deletions(-) (limited to 'quantum') diff --git a/quantum/audio.h b/quantum/audio.h index 3aba8370ac..05d314c940 100644 --- a/quantum/audio.h +++ b/quantum/audio.h @@ -3,6 +3,7 @@ #include #include #include "musical_notes.h" +#include "song_list.h" #ifndef AUDIO_H #define AUDIO_H diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index c705b7a730..2001438b90 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -34,15 +34,13 @@ extern keymap_config_t keymap_config; #include #ifdef AUDIO_ENABLE #include "audio.h" + #ifndef TONE_GOODBYE - #define TONE_GOODBYE { \ - {440.0*pow(2.0,(31)/12.0), 8}, \ - {440.0*pow(2.0,(24)/12.0), 8}, \ - {440.0*pow(2.0,(19)/12.0), 12}, \ - } - #endif - float tone_goodbye[][2] = TONE_GOODBYE; -#endif + #define TONE_GOODBYE OLKB_GOODBYE + #endif /*! TONE_GOODBYE */ + + float tone_goodbye[][2] = SONG(TONE_GOODBYE); +#endif /* AUDIO_ENABLE */ static action_t keycode_to_action(uint16_t keycode); diff --git a/quantum/musical_notes.h b/quantum/musical_notes.h index 2170f3f18b..ccdc34f270 100644 --- a/quantum/musical_notes.h +++ b/quantum/musical_notes.h @@ -32,7 +32,7 @@ #define WD_NOTE(n) WHOLE_DOT_NOTE(n) #define HD_NOTE(n) HALF_DOT_NOTE(n) #define QD_NOTE(n) QUARTER_DOT_NOTE(n) -#define ED_NOTE(n) EIGTH_DOT_NOTE(n) +#define ED_NOTE(n) EIGHTH_DOT_NOTE(n) #define SD_NOTE(n) SIXTEENTH_DOT_NOTE(n) // Note Styles diff --git a/quantum/song_list.h b/quantum/song_list.h index ef36a1cddf..b626c3fa6b 100644 --- a/quantum/song_list.h +++ b/quantum/song_list.h @@ -15,4 +15,9 @@ QD_NOTE(_B4), E__NOTE(_D5), Q__NOTE(_G5), \ H__NOTE(_FS5), -#endif \ No newline at end of file +#define OLKB_GOODBYE \ + E__NOTE(_E7), \ + E__NOTE(_A6), \ + ED_NOTE(_E6), + +#endif -- cgit v1.2.3 From ce463ef424c5bd26b84ead7de5f31eab366f98eb Mon Sep 17 00:00:00 2001 From: Jack Humbert Date: Sun, 17 Apr 2016 18:14:42 -0400 Subject: audio fixes --- quantum/audio.c | 6 +++--- quantum/audio.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'quantum') diff --git a/quantum/audio.c b/quantum/audio.c index 855e97361b..e0413051a0 100644 --- a/quantum/audio.c +++ b/quantum/audio.c @@ -257,7 +257,7 @@ ISR(TIMER3_COMPA_vect) { place = 0.0; } ICR3 = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)); // Set max to the period - OCR3A = (int)((((double)F_CPU) / (note_frequency * CPU_PRESCALER)) * note_timbre); // Set compare to half the period + OCR3A = (int)((((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)) * note_timbre); // Set compare to half the period //OCR3A = (int)(((double)F_CPU) / (frequencies[voice_place] * CPU_PRESCALER)) >> 1 * duty_place; // Set compare to half the period place++; // if (duty_counter > (frequencies[voice_place] / 500)) { @@ -353,6 +353,7 @@ if (audio_config.enable) { if (note) stop_all_notes(); + notes = true; notes_pointer = np; notes_count = n_count; @@ -378,7 +379,6 @@ if (audio_config.enable) { TCCR3A |= _BV(COM3A1); #endif - notes = true; } } @@ -408,6 +408,7 @@ if (audio_config.enable && voices < 8) { if (notes) stop_all_notes(); + note = true; #ifdef PWM_AUDIO freq = freq / SAMPLE_RATE; #endif @@ -439,7 +440,6 @@ if (audio_config.enable && voices < 8) { TCCR3A |= _BV(COM3A1); #endif - note = true; } } diff --git a/quantum/audio.h b/quantum/audio.h index 3aba8370ac..05d314c940 100644 --- a/quantum/audio.h +++ b/quantum/audio.h @@ -3,6 +3,7 @@ #include #include #include "musical_notes.h" +#include "song_list.h" #ifndef AUDIO_H #define AUDIO_H -- cgit v1.2.3 From 5c98ad59606ee95b82c27bf2525383a9ec88542b Mon Sep 17 00:00:00 2001 From: IBNobody Date: Sun, 17 Apr 2016 20:14:37 -0500 Subject: Added extra songs, LED indicator notes --- quantum/audio.c | 17 +++++++- quantum/audio.h | 2 + quantum/keymap_common.c | 14 ++----- quantum/musical_notes.h | 5 +++ quantum/song_list.h | 104 ++++++++++++++++++++++++++++++++++++++++++------ 5 files changed, 117 insertions(+), 25 deletions(-) (limited to 'quantum') diff --git a/quantum/audio.c b/quantum/audio.c index 3ccd5ab9bc..6023669739 100644 --- a/quantum/audio.c +++ b/quantum/audio.c @@ -351,7 +351,7 @@ void play_notes(float (*np)[][2], uint8_t n_count, bool n_repeat, float n_rest) if (audio_config.enable) { - if (note) + if (note || notes) stop_all_notes(); notes_pointer = np; @@ -406,7 +406,7 @@ void play_note(double freq, int vol) { if (audio_config.enable && voices < 8) { - if (notes) + if (note || notes) stop_all_notes(); #ifdef PWM_AUDIO freq = freq / SAMPLE_RATE; @@ -471,3 +471,16 @@ void increase_tempo(uint8_t tempo_change) } } +//------------------------------------------------------------------------------ +// Override these functions in your keymap file to play different tunes on +// startup and bootloader jump +__attribute__ ((weak)) +void play_startup_tone() +{ +} + +__attribute__ ((weak)) +void play_goodbye_tone() +{ +} +//------------------------------------------------------------------------------ diff --git a/quantum/audio.h b/quantum/audio.h index 05d314c940..44cafccd68 100644 --- a/quantum/audio.h +++ b/quantum/audio.h @@ -44,5 +44,7 @@ void decrease_tempo(uint8_t tempo_change); #define NOTE_ARRAY_SIZE(x) ((int)(sizeof(x) / (sizeof(x[0])))) #define PLAY_NOTE_ARRAY(note_array, note_repeat, note_rest_style) play_notes(¬e_array, NOTE_ARRAY_SIZE((note_array)), (note_repeat), (note_rest_style)); +void play_goodbye_tone(void); +void play_startup_tone(void); #endif \ No newline at end of file diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index 2001438b90..4ee290ad03 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -34,12 +34,6 @@ extern keymap_config_t keymap_config; #include #ifdef AUDIO_ENABLE #include "audio.h" - - #ifndef TONE_GOODBYE - #define TONE_GOODBYE OLKB_GOODBYE - #endif /*! TONE_GOODBYE */ - - float tone_goodbye[][2] = SONG(TONE_GOODBYE); #endif /* AUDIO_ENABLE */ static action_t keycode_to_action(uint16_t keycode); @@ -47,7 +41,7 @@ static action_t keycode_to_action(uint16_t keycode); /* converts key to action */ action_t action_for_key(uint8_t layer, keypos_t key) { - // 16bit keycodes - important + // 16bit keycodes - important uint16_t keycode = keymap_key_to_keycode(layer, key); switch (keycode) { @@ -190,7 +184,7 @@ static action_t keycode_to_action(uint16_t keycode) case RESET: ; // RESET is 0x5000, which is why this is here clear_keyboard(); #ifdef AUDIO_ENABLE - PLAY_NOTE_ARRAY(tone_goodbye, false, 0); + play_goodbye_tone(); #endif _delay_ms(250); #ifdef ATREUS_ASTAR @@ -303,7 +297,7 @@ static action_t keycode_to_action(uint16_t keycode) /* translates key to keycode */ uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) { - // Read entire word (16bits) + // Read entire word (16bits) return pgm_read_word(&keymaps[(layer)][(key.row)][(key.col)]); } @@ -315,7 +309,7 @@ action_t keymap_fn_to_action(uint16_t keycode) action_t keymap_func_to_action(uint16_t keycode) { - // For FUNC without 8bit limit + // For FUNC without 8bit limit return (action_t){ .code = pgm_read_word(&fn_actions[(int)keycode]) }; } diff --git a/quantum/musical_notes.h b/quantum/musical_notes.h index ccdc34f270..b08d16a6fa 100644 --- a/quantum/musical_notes.h +++ b/quantum/musical_notes.h @@ -51,7 +51,10 @@ // Notes - # = Octave + #define NOTE_REST 0.00 + +/* These notes are currently bugged #define NOTE_C0 16.35 #define NOTE_CS0 17.32 #define NOTE_D0 18.35 @@ -75,6 +78,8 @@ #define NOTE_GS1 51.91 #define NOTE_A1 55.00 #define NOTE_AS1 58.27 +*/ + #define NOTE_B1 61.74 #define NOTE_C2 65.41 #define NOTE_CS2 69.30 diff --git a/quantum/song_list.h b/quantum/song_list.h index b626c3fa6b..e992bd18a2 100644 --- a/quantum/song_list.h +++ b/quantum/song_list.h @@ -4,20 +4,98 @@ #define SONG_LIST_H #define ODE_TO_JOY \ - Q__NOTE(_E4), Q__NOTE(_E4), Q__NOTE(_F4), Q__NOTE(_G4), \ - Q__NOTE(_G4), Q__NOTE(_F4), Q__NOTE(_E4), Q__NOTE(_D4), \ - Q__NOTE(_C4), Q__NOTE(_C4), Q__NOTE(_D4), Q__NOTE(_E4), \ - QD_NOTE(_E4), E__NOTE(_D4), H__NOTE(_D4), + Q__NOTE(_E4), Q__NOTE(_E4), Q__NOTE(_F4), Q__NOTE(_G4), \ + Q__NOTE(_G4), Q__NOTE(_F4), Q__NOTE(_E4), Q__NOTE(_D4), \ + Q__NOTE(_C4), Q__NOTE(_C4), Q__NOTE(_D4), Q__NOTE(_E4), \ + QD_NOTE(_E4), E__NOTE(_D4), H__NOTE(_D4), #define ROCK_A_BYE_BABY \ - QD_NOTE(_B4), E__NOTE(_D4), Q__NOTE(_B5), \ - H__NOTE(_A5), Q__NOTE(_G5), \ - QD_NOTE(_B4), E__NOTE(_D5), Q__NOTE(_G5), \ - H__NOTE(_FS5), - -#define OLKB_GOODBYE \ - E__NOTE(_E7), \ - E__NOTE(_A6), \ - ED_NOTE(_E6), + QD_NOTE(_B4), E__NOTE(_D4), Q__NOTE(_B5), \ + H__NOTE(_A5), Q__NOTE(_G5), \ + QD_NOTE(_B4), E__NOTE(_D5), Q__NOTE(_G5), \ + H__NOTE(_FS5), + +#define CLOSE_ENCOUNTERS_5_NOTE \ + Q__NOTE(_D5), \ + Q__NOTE(_E5), \ + Q__NOTE(_C5), \ + Q__NOTE(_C4), \ + Q__NOTE(_G4), + +#define DOE_A_DEER \ + QD_NOTE(_C4), E__NOTE(_D4), \ + QD_NOTE(_E4), E__NOTE(_C4), \ + Q__NOTE(_E4), Q__NOTE(_C4), \ + Q__NOTE(_E4), + +#define GOODBYE_SOUND \ + E__NOTE(_E7), \ + E__NOTE(_A6), \ + ED_NOTE(_E6), + +#define STARTUP_SOUND \ + ED_NOTE(_E7 ), \ + E__NOTE(_CS7), \ + E__NOTE(_E6 ), \ + E__NOTE(_A6 ), \ + M__NOTE(_CS7, 20), + +#define QWERTY_SOUND \ + E__NOTE(_GS6 ), \ + E__NOTE(_A6 ), \ + S__NOTE(_REST), \ + Q__NOTE(_E7 ), + +#define COLEMAK_SOUND \ + E__NOTE(_GS6 ), \ + E__NOTE(_A6 ), \ + S__NOTE(_REST), \ + ED_NOTE(_E7 ), \ + S__NOTE(_REST), \ + ED_NOTE(_GS7 ), + +#define DVORAK_SOUND \ + E__NOTE(_GS6 ), \ + E__NOTE(_A6 ), \ + S__NOTE(_REST), \ + E__NOTE(_E7 ), \ + S__NOTE(_REST), \ + E__NOTE(_FS7 ), \ + S__NOTE(_REST), \ + E__NOTE(_E7 ), + +#define MUSIC_SCALE_SOUND \ + E__NOTE(_A5 ), \ + E__NOTE(_B5 ), \ + E__NOTE(_CS6), \ + E__NOTE(_D6 ), \ + E__NOTE(_E6 ), \ + E__NOTE(_FS6), \ + E__NOTE(_GS6), \ + E__NOTE(_A6 ), + +#define CAPS_LOCK_ON_SOUND \ + E__NOTE(_A3), \ + E__NOTE(_B3), + +#define CAPS_LOCK_OFF_SOUND \ + E__NOTE(_B3), \ + E__NOTE(_A3), + +#define SCROLL_LOCK_ON_SOUND \ + E__NOTE(_D4), \ + E__NOTE(_E4), + +#define SCROLL_LOCK_OFF_SOUND \ + E__NOTE(_E4), \ + E__NOTE(_D4), + +#define NUM_LOCK_ON_SOUND \ + E__NOTE(_D5), \ + E__NOTE(_E5), + +#define NUM_LOCK_OFF_SOUND \ + E__NOTE(_E5), \ + E__NOTE(_D5), #endif -- cgit v1.2.3 From ef73ab662812232f5e73c8098a059439dcb201fa Mon Sep 17 00:00:00 2001 From: IBNobody Date: Sun, 17 Apr 2016 22:08:05 -0500 Subject: Notes Bugfix --- quantum/audio.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'quantum') diff --git a/quantum/audio.c b/quantum/audio.c index 6023669739..ba85e418ed 100644 --- a/quantum/audio.c +++ b/quantum/audio.c @@ -351,7 +351,8 @@ void play_notes(float (*np)[][2], uint8_t n_count, bool n_repeat, float n_rest) if (audio_config.enable) { - if (note || notes) + // Cancel note if a note is playing + if (note) stop_all_notes(); notes_pointer = np; @@ -406,7 +407,8 @@ void play_note(double freq, int vol) { if (audio_config.enable && voices < 8) { - if (note || notes) + // Cancel notes if notes are playing + if (notes) stop_all_notes(); #ifdef PWM_AUDIO freq = freq / SAMPLE_RATE; -- cgit v1.2.3