diff options
Diffstat (limited to 'quantum/quantum.c')
| -rw-r--r-- | quantum/quantum.c | 149 |
1 files changed, 118 insertions, 31 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c index ab47fa48f..85db100ab 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c | |||
| @@ -42,6 +42,11 @@ extern backlight_config_t backlight_config; | |||
| 42 | #include "process_midi.h" | 42 | #include "process_midi.h" |
| 43 | #endif | 43 | #endif |
| 44 | 44 | ||
| 45 | |||
| 46 | #ifdef ENCODER_ENABLE | ||
| 47 | #include "encoder.h" | ||
| 48 | #endif | ||
| 49 | |||
| 45 | #ifdef AUDIO_ENABLE | 50 | #ifdef AUDIO_ENABLE |
| 46 | #ifndef GOODBYE_SONG | 51 | #ifndef GOODBYE_SONG |
| 47 | #define GOODBYE_SONG SONG(GOODBYE_SOUND) | 52 | #define GOODBYE_SONG SONG(GOODBYE_SOUND) |
| @@ -127,6 +132,14 @@ void unregister_code16 (uint16_t code) { | |||
| 127 | } | 132 | } |
| 128 | } | 133 | } |
| 129 | 134 | ||
| 135 | void tap_code16(uint16_t code) { | ||
| 136 | register_code16(code); | ||
| 137 | #if TAP_CODE_DELAY > 0 | ||
| 138 | wait_ms(TAP_CODE_DELAY); | ||
| 139 | #endif | ||
| 140 | unregister_code16(code); | ||
| 141 | } | ||
| 142 | |||
| 130 | __attribute__ ((weak)) | 143 | __attribute__ ((weak)) |
| 131 | bool process_action_kb(keyrecord_t *record) { | 144 | bool process_action_kb(keyrecord_t *record) { |
| 132 | return true; | 145 | return true; |
| @@ -196,7 +209,7 @@ bool process_record_quantum(keyrecord_t *record) { | |||
| 196 | keypos_t key = record->event.key; | 209 | keypos_t key = record->event.key; |
| 197 | uint16_t keycode; | 210 | uint16_t keycode; |
| 198 | 211 | ||
| 199 | #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) | 212 | #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) |
| 200 | /* TODO: Use store_or_get_action() or a similar function. */ | 213 | /* TODO: Use store_or_get_action() or a similar function. */ |
| 201 | if (!disable_action_cache) { | 214 | if (!disable_action_cache) { |
| 202 | uint8_t layer; | 215 | uint8_t layer; |
| @@ -230,7 +243,7 @@ bool process_record_quantum(keyrecord_t *record) { | |||
| 230 | process_key_lock(&keycode, record) && | 243 | process_key_lock(&keycode, record) && |
| 231 | #endif | 244 | #endif |
| 232 | #if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY) | 245 | #if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY) |
| 233 | process_clicky(keycode, record) && | 246 | process_clicky(keycode, record) && |
| 234 | #endif //AUDIO_CLICKY | 247 | #endif //AUDIO_CLICKY |
| 235 | process_record_kb(keycode, record) && | 248 | process_record_kb(keycode, record) && |
| 236 | #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_KEYPRESSES) | 249 | #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_KEYPRESSES) |
| @@ -245,36 +258,27 @@ bool process_record_quantum(keyrecord_t *record) { | |||
| 245 | #ifdef STENO_ENABLE | 258 | #ifdef STENO_ENABLE |
| 246 | process_steno(keycode, record) && | 259 | process_steno(keycode, record) && |
| 247 | #endif | 260 | #endif |
| 248 | #if ( defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))) && !defined(NO_MUSIC_MODE) | 261 | #if (defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))) && !defined(NO_MUSIC_MODE) |
| 249 | process_music(keycode, record) && | 262 | process_music(keycode, record) && |
| 250 | #endif | 263 | #endif |
| 251 | #ifdef TAP_DANCE_ENABLE | 264 | #ifdef TAP_DANCE_ENABLE |
| 252 | process_tap_dance(keycode, record) && | 265 | process_tap_dance(keycode, record) && |
| 253 | #endif | 266 | #endif |
| 254 | #ifndef DISABLE_LEADER | 267 | #if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE) |
| 255 | process_leader(keycode, record) && | 268 | process_unicode_common(keycode, record) && |
| 256 | #endif | 269 | #endif |
| 257 | #ifndef DISABLE_CHORDING | 270 | #ifdef LEADER_ENABLE |
| 258 | process_chording(keycode, record) && | 271 | process_leader(keycode, record) && |
| 259 | #endif | 272 | #endif |
| 260 | #ifdef COMBO_ENABLE | 273 | #ifdef COMBO_ENABLE |
| 261 | process_combo(keycode, record) && | 274 | process_combo(keycode, record) && |
| 262 | #endif | 275 | #endif |
| 263 | #ifdef UNICODE_ENABLE | ||
| 264 | process_unicode(keycode, record) && | ||
| 265 | #endif | ||
| 266 | #ifdef UCIS_ENABLE | ||
| 267 | process_ucis(keycode, record) && | ||
| 268 | #endif | ||
| 269 | #ifdef PRINTING_ENABLE | 276 | #ifdef PRINTING_ENABLE |
| 270 | process_printer(keycode, record) && | 277 | process_printer(keycode, record) && |
| 271 | #endif | 278 | #endif |
| 272 | #ifdef AUTO_SHIFT_ENABLE | 279 | #ifdef AUTO_SHIFT_ENABLE |
| 273 | process_auto_shift(keycode, record) && | 280 | process_auto_shift(keycode, record) && |
| 274 | #endif | 281 | #endif |
| 275 | #ifdef UNICODEMAP_ENABLE | ||
| 276 | process_unicode_map(keycode, record) && | ||
| 277 | #endif | ||
| 278 | #ifdef TERMINAL_ENABLE | 282 | #ifdef TERMINAL_ENABLE |
| 279 | process_terminal(keycode, record) && | 283 | process_terminal(keycode, record) && |
| 280 | #endif | 284 | #endif |
| @@ -296,6 +300,11 @@ bool process_record_quantum(keyrecord_t *record) { | |||
| 296 | print("DEBUG: enabled.\n"); | 300 | print("DEBUG: enabled.\n"); |
| 297 | } | 301 | } |
| 298 | return false; | 302 | return false; |
| 303 | case EEPROM_RESET: | ||
| 304 | if (record->event.pressed) { | ||
| 305 | eeconfig_init(); | ||
| 306 | } | ||
| 307 | return false; | ||
| 299 | #ifdef FAUXCLICKY_ENABLE | 308 | #ifdef FAUXCLICKY_ENABLE |
| 300 | case FC_TOG: | 309 | case FC_TOG: |
| 301 | if (record->event.pressed) { | 310 | if (record->event.pressed) { |
| @@ -445,75 +454,97 @@ bool process_record_quantum(keyrecord_t *record) { | |||
| 445 | return false; | 454 | return false; |
| 446 | case RGB_MODE_PLAIN: | 455 | case RGB_MODE_PLAIN: |
| 447 | if (record->event.pressed) { | 456 | if (record->event.pressed) { |
| 448 | rgblight_mode(1); | 457 | rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT); |
| 449 | #ifdef SPLIT_KEYBOARD | 458 | #ifdef SPLIT_KEYBOARD |
| 450 | RGB_DIRTY = true; | 459 | RGB_DIRTY = true; |
| 451 | #endif | 460 | #endif |
| 452 | } | 461 | } |
| 453 | return false; | 462 | return false; |
| 454 | case RGB_MODE_BREATHE: | 463 | case RGB_MODE_BREATHE: |
| 464 | #ifdef RGBLIGHT_EFFECT_BREATHING | ||
| 455 | if (record->event.pressed) { | 465 | if (record->event.pressed) { |
| 456 | if ((2 <= rgblight_get_mode()) && (rgblight_get_mode() < 5)) { | 466 | if ((RGBLIGHT_MODE_BREATHING <= rgblight_get_mode()) && |
| 467 | (rgblight_get_mode() < RGBLIGHT_MODE_BREATHING_end)) { | ||
| 457 | rgblight_step(); | 468 | rgblight_step(); |
| 458 | } else { | 469 | } else { |
| 459 | rgblight_mode(2); | 470 | rgblight_mode(RGBLIGHT_MODE_BREATHING); |
| 460 | } | 471 | } |
| 461 | } | 472 | } |
| 473 | #endif | ||
| 462 | return false; | 474 | return false; |
| 463 | case RGB_MODE_RAINBOW: | 475 | case RGB_MODE_RAINBOW: |
| 476 | #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD | ||
| 464 | if (record->event.pressed) { | 477 | if (record->event.pressed) { |
| 465 | if ((6 <= rgblight_get_mode()) && (rgblight_get_mode() < 8)) { | 478 | if ((RGBLIGHT_MODE_RAINBOW_MOOD <= rgblight_get_mode()) && |
| 479 | (rgblight_get_mode() < RGBLIGHT_MODE_RAINBOW_MOOD_end)) { | ||
| 466 | rgblight_step(); | 480 | rgblight_step(); |
| 467 | } else { | 481 | } else { |
| 468 | rgblight_mode(6); | 482 | rgblight_mode(RGBLIGHT_MODE_RAINBOW_MOOD); |
| 469 | } | 483 | } |
| 470 | } | 484 | } |
| 485 | #endif | ||
| 471 | return false; | 486 | return false; |
| 472 | case RGB_MODE_SWIRL: | 487 | case RGB_MODE_SWIRL: |
| 488 | #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL | ||
| 473 | if (record->event.pressed) { | 489 | if (record->event.pressed) { |
| 474 | if ((9 <= rgblight_get_mode()) && (rgblight_get_mode() < 14)) { | 490 | if ((RGBLIGHT_MODE_RAINBOW_SWIRL <= rgblight_get_mode()) && |
| 491 | (rgblight_get_mode() < RGBLIGHT_MODE_RAINBOW_SWIRL_end)) { | ||
| 475 | rgblight_step(); | 492 | rgblight_step(); |
| 476 | } else { | 493 | } else { |
| 477 | rgblight_mode(9); | 494 | rgblight_mode(RGBLIGHT_MODE_RAINBOW_SWIRL); |
| 478 | } | 495 | } |
| 479 | } | 496 | } |
| 497 | #endif | ||
| 480 | return false; | 498 | return false; |
| 481 | case RGB_MODE_SNAKE: | 499 | case RGB_MODE_SNAKE: |
| 500 | #ifdef RGBLIGHT_EFFECT_SNAKE | ||
| 482 | if (record->event.pressed) { | 501 | if (record->event.pressed) { |
| 483 | if ((15 <= rgblight_get_mode()) && (rgblight_get_mode() < 20)) { | 502 | if ((RGBLIGHT_MODE_SNAKE <= rgblight_get_mode()) && |
| 503 | (rgblight_get_mode() < RGBLIGHT_MODE_SNAKE_end)) { | ||
| 484 | rgblight_step(); | 504 | rgblight_step(); |
| 485 | } else { | 505 | } else { |
| 486 | rgblight_mode(15); | 506 | rgblight_mode(RGBLIGHT_MODE_SNAKE); |
| 487 | } | 507 | } |
| 488 | } | 508 | } |
| 509 | #endif | ||
| 489 | return false; | 510 | return false; |
| 490 | case RGB_MODE_KNIGHT: | 511 | case RGB_MODE_KNIGHT: |
| 512 | #ifdef RGBLIGHT_EFFECT_KNIGHT | ||
| 491 | if (record->event.pressed) { | 513 | if (record->event.pressed) { |
| 492 | if ((21 <= rgblight_get_mode()) && (rgblight_get_mode() < 23)) { | 514 | if ((RGBLIGHT_MODE_KNIGHT <= rgblight_get_mode()) && |
| 515 | (rgblight_get_mode() < RGBLIGHT_MODE_KNIGHT_end)) { | ||
| 493 | rgblight_step(); | 516 | rgblight_step(); |
| 494 | } else { | 517 | } else { |
| 495 | rgblight_mode(21); | 518 | rgblight_mode(RGBLIGHT_MODE_KNIGHT); |
| 496 | } | 519 | } |
| 497 | } | 520 | } |
| 521 | #endif | ||
| 498 | return false; | 522 | return false; |
| 499 | case RGB_MODE_XMAS: | 523 | case RGB_MODE_XMAS: |
| 524 | #ifdef RGBLIGHT_EFFECT_CHRISTMAS | ||
| 500 | if (record->event.pressed) { | 525 | if (record->event.pressed) { |
| 501 | rgblight_mode(24); | 526 | rgblight_mode(RGBLIGHT_MODE_CHRISTMAS); |
| 502 | } | 527 | } |
| 528 | #endif | ||
| 503 | return false; | 529 | return false; |
| 504 | case RGB_MODE_GRADIENT: | 530 | case RGB_MODE_GRADIENT: |
| 531 | #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT | ||
| 505 | if (record->event.pressed) { | 532 | if (record->event.pressed) { |
| 506 | if ((25 <= rgblight_get_mode()) && (rgblight_get_mode() < 34)) { | 533 | if ((RGBLIGHT_MODE_STATIC_GRADIENT <= rgblight_get_mode()) && |
| 534 | (rgblight_get_mode() < RGBLIGHT_MODE_STATIC_GRADIENT_end)) { | ||
| 507 | rgblight_step(); | 535 | rgblight_step(); |
| 508 | } else { | 536 | } else { |
| 509 | rgblight_mode(25); | 537 | rgblight_mode(RGBLIGHT_MODE_STATIC_GRADIENT); |
| 510 | } | 538 | } |
| 511 | } | 539 | } |
| 540 | #endif | ||
| 512 | return false; | 541 | return false; |
| 513 | case RGB_MODE_RGBTEST: | 542 | case RGB_MODE_RGBTEST: |
| 543 | #ifdef RGBLIGHT_EFFECT_RGB_TEST | ||
| 514 | if (record->event.pressed) { | 544 | if (record->event.pressed) { |
| 515 | rgblight_mode(35); | 545 | rgblight_mode(RGBLIGHT_MODE_RGB_TEST); |
| 516 | } | 546 | } |
| 547 | #endif | ||
| 517 | return false; | 548 | return false; |
| 518 | #endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) | 549 | #endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) |
| 519 | #ifdef PROTOCOL_LUFA | 550 | #ifdef PROTOCOL_LUFA |
| @@ -607,6 +638,17 @@ bool process_record_quantum(keyrecord_t *record) { | |||
| 607 | PLAY_SONG(ag_norm_song); | 638 | PLAY_SONG(ag_norm_song); |
| 608 | #endif | 639 | #endif |
| 609 | break; | 640 | break; |
| 641 | case MAGIC_TOGGLE_ALT_GUI: | ||
| 642 | keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui; | ||
| 643 | keymap_config.swap_ralt_rgui = !keymap_config.swap_ralt_rgui; | ||
| 644 | #ifdef AUDIO_ENABLE | ||
| 645 | if (keymap_config.swap_ralt_rgui) { | ||
| 646 | PLAY_SONG(ag_swap_song); | ||
| 647 | } else { | ||
| 648 | PLAY_SONG(ag_norm_song); | ||
| 649 | } | ||
| 650 | #endif | ||
| 651 | break; | ||
| 610 | case MAGIC_TOGGLE_NKRO: | 652 | case MAGIC_TOGGLE_NKRO: |
| 611 | keymap_config.nkro = !keymap_config.nkro; | 653 | keymap_config.nkro = !keymap_config.nkro; |
| 612 | break; | 654 | break; |
| @@ -914,7 +956,42 @@ void tap_random_base64(void) { | |||
| 914 | } | 956 | } |
| 915 | } | 957 | } |
| 916 | 958 | ||
| 959 | __attribute__((weak)) | ||
| 960 | void bootmagic_lite(void) { | ||
| 961 | // The lite version of TMK's bootmagic based on Wilba. | ||
| 962 | // 100% less potential for accidentally making the | ||
| 963 | // keyboard do stupid things. | ||
| 964 | |||
| 965 | // We need multiple scans because debouncing can't be turned off. | ||
| 966 | matrix_scan(); | ||
| 967 | #if defined(DEBOUNCING_DELAY) && DEBOUNCING_DELAY > 0 | ||
| 968 | wait_ms(DEBOUNCING_DELAY * 2); | ||
| 969 | #elif defined(DEBOUNCE) && DEBOUNCE > 0 | ||
| 970 | wait_ms(DEBOUNCE * 2); | ||
| 971 | #else | ||
| 972 | wait_ms(30); | ||
| 973 | #endif | ||
| 974 | matrix_scan(); | ||
| 975 | |||
| 976 | // If the Esc and space bar are held down on power up, | ||
| 977 | // reset the EEPROM valid state and jump to bootloader. | ||
| 978 | // Assumes Esc is at [0,0]. | ||
| 979 | // This isn't very generalized, but we need something that doesn't | ||
| 980 | // rely on user's keymaps in firmware or EEPROM. | ||
| 981 | if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) { | ||
| 982 | eeconfig_disable(); | ||
| 983 | // Jump to bootloader. | ||
| 984 | bootloader_jump(); | ||
| 985 | } | ||
| 986 | } | ||
| 987 | |||
| 917 | void matrix_init_quantum() { | 988 | void matrix_init_quantum() { |
| 989 | #ifdef BOOTMAGIC_LITE | ||
| 990 | bootmagic_lite(); | ||
| 991 | #endif | ||
| 992 | if (!eeconfig_is_enabled()) { | ||
| 993 | eeconfig_init(); | ||
| 994 | } | ||
| 918 | #ifdef BACKLIGHT_ENABLE | 995 | #ifdef BACKLIGHT_ENABLE |
| 919 | backlight_init_ports(); | 996 | backlight_init_ports(); |
| 920 | #endif | 997 | #endif |
| @@ -924,6 +1001,12 @@ void matrix_init_quantum() { | |||
| 924 | #ifdef RGB_MATRIX_ENABLE | 1001 | #ifdef RGB_MATRIX_ENABLE |
| 925 | rgb_matrix_init(); | 1002 | rgb_matrix_init(); |
| 926 | #endif | 1003 | #endif |
| 1004 | #ifdef ENCODER_ENABLE | ||
| 1005 | encoder_init(); | ||
| 1006 | #endif | ||
| 1007 | #if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE) | ||
| 1008 | unicode_input_mode_init(); | ||
| 1009 | #endif | ||
| 927 | matrix_init_kb(); | 1010 | matrix_init_kb(); |
| 928 | } | 1011 | } |
| 929 | 1012 | ||
| @@ -958,6 +1041,10 @@ void matrix_scan_quantum() { | |||
| 958 | rgb_matrix_task_counter = ((rgb_matrix_task_counter + 1) % (RGB_MATRIX_SKIP_FRAMES + 1)); | 1041 | rgb_matrix_task_counter = ((rgb_matrix_task_counter + 1) % (RGB_MATRIX_SKIP_FRAMES + 1)); |
| 959 | #endif | 1042 | #endif |
| 960 | 1043 | ||
| 1044 | #ifdef ENCODER_ENABLE | ||
| 1045 | encoder_read(); | ||
| 1046 | #endif | ||
| 1047 | |||
| 961 | matrix_scan_kb(); | 1048 | matrix_scan_kb(); |
| 962 | } | 1049 | } |
| 963 | #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN) | 1050 | #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN) |
