aboutsummaryrefslogtreecommitdiff
path: root/quantum/quantum.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/quantum.c')
-rw-r--r--quantum/quantum.c183
1 files changed, 124 insertions, 59 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 0a900aac2..a310608e0 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -1,5 +1,4 @@
1#include "quantum.h" 1#include "quantum.h"
2#include "timer.h"
3 2
4__attribute__ ((weak)) 3__attribute__ ((weak))
5void matrix_init_kb(void) {} 4void matrix_init_kb(void) {}
@@ -35,15 +34,15 @@ int offset = 7;
35#ifdef AUDIO_ENABLE 34#ifdef AUDIO_ENABLE
36 bool music_activated = false; 35 bool music_activated = false;
37 36
38// music sequencer 37 // music sequencer
39static bool music_sequence_recording = false; 38 static bool music_sequence_recording = false;
40static bool music_sequence_playing = false; 39 static bool music_sequence_playing = false;
41static float music_sequence[16] = {0}; 40 static float music_sequence[16] = {0};
42static uint8_t music_sequence_count = 0; 41 static uint8_t music_sequence_count = 0;
43static uint8_t music_sequence_position = 0; 42 static uint8_t music_sequence_position = 0;
44 43
45static uint16_t music_sequence_timer = 0; 44 static uint16_t music_sequence_timer = 0;
46static uint16_t music_sequence_interval = 100; 45 static uint16_t music_sequence_interval = 100;
47 46
48#endif 47#endif
49 48
@@ -172,10 +171,6 @@ bool process_record_quantum(keyrecord_t *record) {
172 if (record->event.pressed) { 171 if (record->event.pressed) {
173 starting_note++; // Change key 172 starting_note++; // Change key
174 midi_send_cc(&midi_device, 0, 0x7B, 0); 173 midi_send_cc(&midi_device, 0, 0x7B, 0);
175 // midi_send_cc(&midi_device, 1, 0x7B, 0);
176 // midi_send_cc(&midi_device, 2, 0x7B, 0);
177 // midi_send_cc(&midi_device, 3, 0x7B, 0);
178 // midi_send_cc(&midi_device, 4, 0x7B, 0);
179 } 174 }
180 return false; 175 return false;
181 } 176 }
@@ -183,29 +178,17 @@ bool process_record_quantum(keyrecord_t *record) {
183 if (record->event.pressed) { 178 if (record->event.pressed) {
184 starting_note--; // Change key 179 starting_note--; // Change key
185 midi_send_cc(&midi_device, 0, 0x7B, 0); 180 midi_send_cc(&midi_device, 0, 0x7B, 0);
186 // midi_send_cc(&midi_device, 1, 0x7B, 0);
187 // midi_send_cc(&midi_device, 2, 0x7B, 0);
188 // midi_send_cc(&midi_device, 3, 0x7B, 0);
189 // midi_send_cc(&midi_device, 4, 0x7B, 0);
190 } 181 }
191 return false; 182 return false;
192 } 183 }
193 if (record->event.key.col == (MATRIX_COLS - 3) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) { 184 if (record->event.key.col == (MATRIX_COLS - 3) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
194 offset++; // Change scale 185 offset++; // Change scale
195 midi_send_cc(&midi_device, 0, 0x7B, 0); 186 midi_send_cc(&midi_device, 0, 0x7B, 0);
196 // midi_send_cc(&midi_device, 1, 0x7B, 0);
197 // midi_send_cc(&midi_device, 2, 0x7B, 0);
198 // midi_send_cc(&midi_device, 3, 0x7B, 0);
199 // midi_send_cc(&midi_device, 4, 0x7B, 0);
200 return false; 187 return false;
201 } 188 }
202 if (record->event.key.col == (MATRIX_COLS - 4) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) { 189 if (record->event.key.col == (MATRIX_COLS - 4) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
203 offset--; // Change scale 190 offset--; // Change scale
204 midi_send_cc(&midi_device, 0, 0x7B, 0); 191 midi_send_cc(&midi_device, 0, 0x7B, 0);
205 // midi_send_cc(&midi_device, 1, 0x7B, 0);
206 // midi_send_cc(&midi_device, 2, 0x7B, 0);
207 // midi_send_cc(&midi_device, 3, 0x7B, 0);
208 // midi_send_cc(&midi_device, 4, 0x7B, 0);
209 return false; 192 return false;
210 } 193 }
211 // basic 194 // basic
@@ -365,7 +348,7 @@ bool process_record_quantum(keyrecord_t *record) {
365#define DISABLE_CHORDING 348#define DISABLE_CHORDING
366#ifndef DISABLE_CHORDING 349#ifndef DISABLE_CHORDING
367 350
368 if (keycode >= 0x5700 && keycode <= 0x57FF) { 351 if (keycode >= QK_CHORDING && keycode <= QK_CHORDING_MAX) {
369 if (record->event.pressed) { 352 if (record->event.pressed) {
370 if (!chording) { 353 if (!chording) {
371 chording = true; 354 chording = true;
@@ -403,7 +386,7 @@ bool process_record_quantum(keyrecord_t *record) {
403 386
404#ifdef UNICODE_ENABLE 387#ifdef UNICODE_ENABLE
405 388
406 if (keycode > UNICODE(0) && record->event.pressed) { 389 if (keycode > QK_UNICODE && record->event.pressed) {
407 uint16_t unicode = keycode & 0x7FFF; 390 uint16_t unicode = keycode & 0x7FFF;
408 switch(input_mode) { 391 switch(input_mode) {
409 case UC_OSX: 392 case UC_OSX:
@@ -443,42 +426,117 @@ bool process_record_quantum(keyrecord_t *record) {
443 // Shift / paren setup 426 // Shift / paren setup
444 427
445 switch(keycode) { 428 switch(keycode) {
429 case RESET:
430 if (record->event.pressed) {
431 clear_keyboard();
432 #ifdef AUDIO_ENABLE
433 stop_all_notes();
434 shutdown_user();
435 #endif
436 _delay_ms(250);
437 #ifdef ATREUS_ASTAR
438 *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific
439 #endif
440 bootloader_jump();
441 return false;
442 }
443 break;
444 case DEBUG:
445 if (record->event.pressed) {
446 print("\nDEBUG: enabled.\n");
447 debug_enable = true;
448 return false;
449 }
450 break;
451 case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_UNSWAP_ALT_GUI:
452 if (record->event.pressed) {
453 // MAGIC actions (BOOTMAGIC without the boot)
454 if (!eeconfig_is_enabled()) {
455 eeconfig_init();
456 }
457 /* keymap config */
458 keymap_config.raw = eeconfig_read_keymap();
459 if (keycode == MAGIC_SWAP_CONTROL_CAPSLOCK) {
460 keymap_config.swap_control_capslock = 1;
461 } else if (keycode == MAGIC_CAPSLOCK_TO_CONTROL) {
462 keymap_config.capslock_to_control = 1;
463 } else if (keycode == MAGIC_SWAP_LALT_LGUI) {
464 keymap_config.swap_lalt_lgui = 1;
465 } else if (keycode == MAGIC_SWAP_RALT_RGUI) {
466 keymap_config.swap_ralt_rgui = 1;
467 } else if (keycode == MAGIC_NO_GUI) {
468 keymap_config.no_gui = 1;
469 } else if (keycode == MAGIC_SWAP_GRAVE_ESC) {
470 keymap_config.swap_grave_esc = 1;
471 } else if (keycode == MAGIC_SWAP_BACKSLASH_BACKSPACE) {
472 keymap_config.swap_backslash_backspace = 1;
473 } else if (keycode == MAGIC_HOST_NKRO) {
474 keymap_config.nkro = 1;
475 } else if (keycode == MAGIC_SWAP_ALT_GUI) {
476 keymap_config.swap_lalt_lgui = 1;
477 keymap_config.swap_ralt_rgui = 1;
478 }
479 /* UNs */
480 else if (keycode == MAGIC_UNSWAP_CONTROL_CAPSLOCK) {
481 keymap_config.swap_control_capslock = 0;
482 } else if (keycode == MAGIC_UNCAPSLOCK_TO_CONTROL) {
483 keymap_config.capslock_to_control = 0;
484 } else if (keycode == MAGIC_UNSWAP_LALT_LGUI) {
485 keymap_config.swap_lalt_lgui = 0;
486 } else if (keycode == MAGIC_UNSWAP_RALT_RGUI) {
487 keymap_config.swap_ralt_rgui = 0;
488 } else if (keycode == MAGIC_UNNO_GUI) {
489 keymap_config.no_gui = 0;
490 } else if (keycode == MAGIC_UNSWAP_GRAVE_ESC) {
491 keymap_config.swap_grave_esc = 0;
492 } else if (keycode == MAGIC_UNSWAP_BACKSLASH_BACKSPACE) {
493 keymap_config.swap_backslash_backspace = 0;
494 } else if (keycode == MAGIC_UNHOST_NKRO) {
495 keymap_config.nkro = 0;
496 } else if (keycode == MAGIC_UNSWAP_ALT_GUI) {
497 keymap_config.swap_lalt_lgui = 0;
498 keymap_config.swap_ralt_rgui = 0;
499 }
500 eeconfig_update_keymap(keymap_config.raw);
501 return false;
502 }
503 break;
446 case KC_LSPO: { 504 case KC_LSPO: {
447 if (record->event.pressed) { 505 if (record->event.pressed) {
448 shift_interrupted[0] = false; 506 shift_interrupted[0] = false;
449 register_mods(MOD_LSFT); 507 register_mods(MOD_LSFT);
450 } 508 }
451 else { 509 else {
452 if (!shift_interrupted[0]) { 510 if (!shift_interrupted[0]) {
453 register_code(LSPO_KEY); 511 register_code(LSPO_KEY);
454 unregister_code(LSPO_KEY); 512 unregister_code(LSPO_KEY);
455 } 513 }
456 unregister_mods(MOD_LSFT); 514 unregister_mods(MOD_LSFT);
457 } 515 }
458 return false; 516 return false;
459 break; 517 break;
460 } 518 }
461 519
462 case KC_RSPC: { 520 case KC_RSPC: {
463 if (record->event.pressed) { 521 if (record->event.pressed) {
464 shift_interrupted[1] = false; 522 shift_interrupted[1] = false;
465 register_mods(MOD_RSFT); 523 register_mods(MOD_RSFT);
466 } 524 }
467 else { 525 else {
468 if (!shift_interrupted[1]) { 526 if (!shift_interrupted[1]) {
469 register_code(RSPC_KEY); 527 register_code(RSPC_KEY);
470 unregister_code(RSPC_KEY); 528 unregister_code(RSPC_KEY);
471 } 529 }
472 unregister_mods(MOD_RSFT); 530 unregister_mods(MOD_RSFT);
473 } 531 }
474 return false; 532 return false;
475 break; 533 break;
476 } 534 }
477 default: { 535 default: {
478 shift_interrupted[0] = true; 536 shift_interrupted[0] = true;
479 shift_interrupted[1] = true; 537 shift_interrupted[1] = true;
480 break; 538 break;
481 } 539 }
482 } 540 }
483 541
484 return process_action_kb(record); 542 return process_action_kb(record);
@@ -586,6 +644,13 @@ void send_string(const char *str) {
586 } 644 }
587} 645}
588 646
647void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
648 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
649 layer_on(layer3);
650 } else {
651 layer_off(layer3);
652 }
653}
589 654
590void matrix_init_quantum() { 655void matrix_init_quantum() {
591 matrix_init_kb(); 656 matrix_init_kb();