4 void matrix_init_kb(void) {}
7 void matrix_scan_kb(void) {}
10 bool process_action_kb(keyrecord_t *record) {
14 __attribute__ ((weak))
15 bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
16 return process_record_user(keycode, record);
19 __attribute__ ((weak))
20 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
24 __attribute__ ((weak))
25 void leader_start(void) {}
27 __attribute__ ((weak))
28 void leader_end(void) {}
30 uint8_t starting_note = 0x0C;
35 bool music_activated = false;
38 static bool music_sequence_recording = false;
39 static bool music_sequence_playing = false;
40 static float music_sequence[16] = {0};
41 static uint8_t music_sequence_count = 0;
42 static uint8_t music_sequence_position = 0;
44 static uint16_t music_sequence_timer = 0;
45 static uint16_t music_sequence_interval = 100;
50 bool midi_activated = false;
55 uint16_t leader_time = 0;
57 uint16_t leader_sequence[5] = {0, 0, 0, 0, 0};
58 uint8_t leader_sequence_size = 0;
61 #define CHORDING_MAX 4
62 bool chording = false;
64 uint8_t chord_keys[CHORDING_MAX] = {0};
65 uint8_t chord_key_count = 0;
66 uint8_t chord_key_down = 0;
69 static uint8_t input_mode;
72 // Shift / paren setup
81 static bool shift_interrupted[2] = {0, 0};
83 bool keys_chord(uint8_t keys[]) {
84 uint8_t keys_size = sizeof(keys)/sizeof(keys[0]);
87 for (uint8_t i = 0; i < chord_key_count; i++) {
89 for (uint8_t j = 0; j < keys_size; j++) {
90 if (chord_keys[i] == (keys[j] & 0xFF)) {
91 in++; // detects key in chord
98 if (chord_keys[i] != 0) {
99 pass = false; // makes sure rest are blank
102 return (pass && (in == keys_size));
105 #ifdef UNICODE_ENABLE
107 uint16_t hex_to_keycode(uint8_t hex)
111 } else if (hex < 0xA) {
112 return KC_1 + (hex - 0x1);
114 return KC_A + (hex - 0xA);
118 void set_unicode_mode(uint8_t os_target)
120 input_mode = os_target;
125 bool process_record_quantum(keyrecord_t *record) {
127 /* This gets the keycode from the key pressed */
128 keypos_t key = record->event.key;
131 #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
134 if (record->event.pressed) {
135 layer = layer_switch_get_layer(key);
136 update_source_layers_cache(key, layer);
138 layer = read_source_layers_cache(key);
140 keycode = keymap_key_to_keycode(layer, key);
142 keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key);
145 if (!process_record_kb(keycode, record))
148 // This is how you use actions here
149 // if (keycode == KC_LEAD) {
151 // action.code = ACTION_DEFAULT_LAYER_SET(0);
152 // process_action(record, action);
157 if (keycode == MI_ON && record->event.pressed) {
158 midi_activated = true;
163 if (keycode == MI_OFF && record->event.pressed) {
164 midi_activated = false;
165 midi_send_cc(&midi_device, 0, 0x7B, 0);
169 if (midi_activated) {
170 if (record->event.key.col == (MATRIX_COLS - 1) && record->event.key.row == (MATRIX_ROWS - 1)) {
171 if (record->event.pressed) {
172 starting_note++; // Change key
173 midi_send_cc(&midi_device, 0, 0x7B, 0);
177 if (record->event.key.col == (MATRIX_COLS - 2) && record->event.key.row == (MATRIX_ROWS - 1)) {
178 if (record->event.pressed) {
179 starting_note--; // Change key
180 midi_send_cc(&midi_device, 0, 0x7B, 0);
184 if (record->event.key.col == (MATRIX_COLS - 3) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
185 offset++; // Change scale
186 midi_send_cc(&midi_device, 0, 0x7B, 0);
189 if (record->event.key.col == (MATRIX_COLS - 4) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
190 offset--; // Change scale
191 midi_send_cc(&midi_device, 0, 0x7B, 0);
195 // uint8_t note = (starting_note + SCALE[record->event.key.col + offset])+12*(MATRIX_ROWS - record->event.key.row);
197 // uint8_t note = (starting_note + record->event.key.col + offset)+12*(MATRIX_ROWS - record->event.key.row);
199 uint8_t note = (starting_note + record->event.key.col + offset)+5*(MATRIX_ROWS - record->event.key.row);
201 // uint8_t note = (starting_note + record->event.key.col + offset)+7*(MATRIX_ROWS - record->event.key.row);
203 if (record->event.pressed) {
204 // midi_send_noteon(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
205 midi_send_noteon(&midi_device, 0, note, 127);
207 // midi_send_noteoff(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
208 midi_send_noteoff(&midi_device, 0, note, 127);
211 if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
217 if (keycode == AU_ON && record->event.pressed) {
222 if (keycode == AU_OFF && record->event.pressed) {
227 if (keycode == AU_TOG && record->event.pressed) {
239 if (keycode == MU_ON && record->event.pressed) {
244 if (keycode == MU_OFF && record->event.pressed) {
249 if (keycode == MU_TOG && record->event.pressed) {
261 if (keycode == MUV_IN && record->event.pressed) {
267 if (keycode == MUV_DE && record->event.pressed) {
273 if (music_activated) {
275 if (keycode == KC_LCTL && record->event.pressed) { // Start recording
277 music_sequence_recording = true;
278 music_sequence_playing = false;
279 music_sequence_count = 0;
283 if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing
285 music_sequence_recording = false;
286 music_sequence_playing = false;
290 if (keycode == KC_LGUI && record->event.pressed) { // Start playing
292 music_sequence_recording = false;
293 music_sequence_playing = true;
294 music_sequence_position = 0;
295 music_sequence_timer = 0;
299 if (keycode == KC_UP) {
300 if (record->event.pressed)
301 music_sequence_interval-=10;
305 if (keycode == KC_DOWN) {
306 if (record->event.pressed)
307 music_sequence_interval+=10;
311 float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row));
312 if (record->event.pressed) {
313 play_note(freq, 0xF);
314 if (music_sequence_recording) {
315 music_sequence[music_sequence_count] = freq;
316 music_sequence_count++;
322 if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
327 #ifndef DISABLE_LEADER
329 if (record->event.pressed) {
330 if (!leading && keycode == KC_LEAD) {
333 leader_time = timer_read();
334 leader_sequence_size = 0;
335 leader_sequence[0] = 0;
336 leader_sequence[1] = 0;
337 leader_sequence[2] = 0;
338 leader_sequence[3] = 0;
339 leader_sequence[4] = 0;
342 if (leading && timer_elapsed(leader_time) < LEADER_TIMEOUT) {
343 leader_sequence[leader_sequence_size] = keycode;
344 leader_sequence_size++;
350 #define DISABLE_CHORDING
351 #ifndef DISABLE_CHORDING
353 if (keycode >= QK_CHORDING && keycode <= QK_CHORDING_MAX) {
354 if (record->event.pressed) {
357 for (uint8_t i = 0; i < CHORDING_MAX; i++)
362 chord_keys[chord_key_count] = (keycode & 0xFF);
369 if (chord_key_down == 0) {
372 if (keys_chord((uint8_t[]){KC_ENTER, KC_SPACE})) {
374 unregister_code(KC_A);
377 for (uint8_t i = 0; i < chord_key_count; i++) {
378 register_code(chord_keys[i]);
379 unregister_code(chord_keys[i]);
389 #ifdef UNICODE_ENABLE
391 if (keycode > QK_UNICODE && record->event.pressed) {
392 uint16_t unicode = keycode & 0x7FFF;
395 register_code(KC_LALT);
398 register_code(KC_LCTL);
399 register_code(KC_LSFT);
401 unregister_code(KC_U);
404 register_code(KC_LALT);
405 register_code(KC_PPLS);
406 unregister_code(KC_PPLS);
409 for(int i = 3; i >= 0; i--) {
410 uint8_t digit = ((unicode >> (i*4)) & 0xF);
411 register_code(hex_to_keycode(digit));
412 unregister_code(hex_to_keycode(digit));
417 unregister_code(KC_LALT);
420 unregister_code(KC_LCTL);
421 unregister_code(KC_LSFT);
428 // Shift / paren setup
432 if (record->event.pressed) {
440 *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific
447 if (record->event.pressed) {
448 print("\nDEBUG: enabled.\n");
453 case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_UNSWAP_ALT_GUI:
454 if (record->event.pressed) {
455 // MAGIC actions (BOOTMAGIC without the boot)
456 if (!eeconfig_is_enabled()) {
460 keymap_config.raw = eeconfig_read_keymap();
461 if (keycode == MAGIC_SWAP_CONTROL_CAPSLOCK) {
462 keymap_config.swap_control_capslock = 1;
463 } else if (keycode == MAGIC_CAPSLOCK_TO_CONTROL) {
464 keymap_config.capslock_to_control = 1;
465 } else if (keycode == MAGIC_SWAP_LALT_LGUI) {
466 keymap_config.swap_lalt_lgui = 1;
467 } else if (keycode == MAGIC_SWAP_RALT_RGUI) {
468 keymap_config.swap_ralt_rgui = 1;
469 } else if (keycode == MAGIC_NO_GUI) {
470 keymap_config.no_gui = 1;
471 } else if (keycode == MAGIC_SWAP_GRAVE_ESC) {
472 keymap_config.swap_grave_esc = 1;
473 } else if (keycode == MAGIC_SWAP_BACKSLASH_BACKSPACE) {
474 keymap_config.swap_backslash_backspace = 1;
475 } else if (keycode == MAGIC_HOST_NKRO) {
476 keymap_config.nkro = 1;
477 } else if (keycode == MAGIC_SWAP_ALT_GUI) {
478 keymap_config.swap_lalt_lgui = 1;
479 keymap_config.swap_ralt_rgui = 1;
482 else if (keycode == MAGIC_UNSWAP_CONTROL_CAPSLOCK) {
483 keymap_config.swap_control_capslock = 0;
484 } else if (keycode == MAGIC_UNCAPSLOCK_TO_CONTROL) {
485 keymap_config.capslock_to_control = 0;
486 } else if (keycode == MAGIC_UNSWAP_LALT_LGUI) {
487 keymap_config.swap_lalt_lgui = 0;
488 } else if (keycode == MAGIC_UNSWAP_RALT_RGUI) {
489 keymap_config.swap_ralt_rgui = 0;
490 } else if (keycode == MAGIC_UNNO_GUI) {
491 keymap_config.no_gui = 0;
492 } else if (keycode == MAGIC_UNSWAP_GRAVE_ESC) {
493 keymap_config.swap_grave_esc = 0;
494 } else if (keycode == MAGIC_UNSWAP_BACKSLASH_BACKSPACE) {
495 keymap_config.swap_backslash_backspace = 0;
496 } else if (keycode == MAGIC_UNHOST_NKRO) {
497 keymap_config.nkro = 0;
498 } else if (keycode == MAGIC_UNSWAP_ALT_GUI) {
499 keymap_config.swap_lalt_lgui = 0;
500 keymap_config.swap_ralt_rgui = 0;
502 eeconfig_update_keymap(keymap_config.raw);
507 if (record->event.pressed) {
508 shift_interrupted[0] = false;
509 register_mods(MOD_BIT(KC_LSFT));
512 if (!shift_interrupted[0]) {
513 register_code(LSPO_KEY);
514 unregister_code(LSPO_KEY);
516 unregister_mods(MOD_BIT(KC_LSFT));
523 if (record->event.pressed) {
524 shift_interrupted[1] = false;
525 register_mods(MOD_BIT(KC_RSFT));
528 if (!shift_interrupted[1]) {
529 register_code(RSPC_KEY);
530 unregister_code(RSPC_KEY);
532 unregister_mods(MOD_BIT(KC_RSFT));
538 shift_interrupted[0] = true;
539 shift_interrupted[1] = true;
544 return process_action_kb(record);
547 const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = {
548 0, 0, 0, 0, 0, 0, 0, 0,
549 0, 0, 0, 0, 0, 0, 0, 0,
550 0, 0, 0, 0, 0, 0, 0, 0,
551 0, 0, 0, 0, 0, 0, 0, 0,
552 0, 1, 1, 1, 1, 1, 1, 0,
553 1, 1, 1, 1, 0, 0, 0, 0,
554 0, 0, 0, 0, 0, 0, 0, 0,
555 0, 0, 1, 0, 1, 0, 1, 1,
556 1, 1, 1, 1, 1, 1, 1, 1,
557 1, 1, 1, 1, 1, 1, 1, 1,
558 1, 1, 1, 1, 1, 1, 1, 1,
559 1, 1, 1, 0, 0, 0, 1, 1,
560 0, 0, 0, 0, 0, 0, 0, 0,
561 0, 0, 0, 0, 0, 0, 0, 0,
562 0, 0, 0, 0, 0, 0, 0, 0,
563 0, 0, 0, 1, 1, 1, 1, 0
566 const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = {
567 0, 0, 0, 0, 0, 0, 0, 0,
568 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
569 0, 0, 0, 0, 0, 0, 0, 0,
570 0, 0, 0, KC_ESC, 0, 0, 0, 0,
571 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
572 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
573 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
574 KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
575 KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
576 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
577 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
578 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
579 KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
580 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
581 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
582 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
585 /* for users whose OSes are set to Colemak */
587 #include "keymap_colemak.h"
589 const bool ascii_to_colemak_shift_lut[0x80] PROGMEM = {
590 0, 0, 0, 0, 0, 0, 0, 0,
591 0, 0, 0, 0, 0, 0, 0, 0,
592 0, 0, 0, 0, 0, 0, 0, 0,
593 0, 0, 0, 0, 0, 0, 0, 0,
594 0, 1, 1, 1, 1, 1, 1, 0,
595 1, 1, 1, 1, 0, 0, 0, 0,
596 0, 0, 0, 0, 0, 0, 0, 0,
597 0, 0, 1, 0, 1, 0, 1, 1,
598 1, 1, 1, 1, 1, 1, 1, 1,
599 1, 1, 1, 1, 1, 1, 1, 1,
600 1, 1, 1, 1, 1, 1, 1, 1,
601 1, 1, 1, 0, 0, 0, 1, 1,
602 0, 0, 0, 0, 0, 0, 0, 0,
603 0, 0, 0, 0, 0, 0, 0, 0,
604 0, 0, 0, 0, 0, 0, 0, 0,
605 0, 0, 0, 1, 1, 1, 1, 0
608 const uint8_t ascii_to_colemak_keycode_lut[0x80] PROGMEM = {
609 0, 0, 0, 0, 0, 0, 0, 0,
610 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
611 0, 0, 0, 0, 0, 0, 0, 0,
612 0, 0, 0, KC_ESC, 0, 0, 0, 0,
613 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
614 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
615 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
616 KC_8, KC_9, CM_SCLN, CM_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
617 KC_2, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
618 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
619 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
620 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
621 KC_GRV, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
622 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
623 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
624 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
629 void send_string(const char *str) {
632 uint8_t ascii_code = pgm_read_byte(str);
633 if (!ascii_code) break;
634 keycode = pgm_read_byte(&ascii_to_qwerty_keycode_lut[ascii_code]);
635 if (pgm_read_byte(&ascii_to_qwerty_shift_lut[ascii_code])) {
636 register_code(KC_LSFT);
637 register_code(keycode);
638 unregister_code(keycode);
639 unregister_code(KC_LSFT);
642 register_code(keycode);
643 unregister_code(keycode);
649 void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
650 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
657 void matrix_init_quantum() {
661 void matrix_scan_quantum() {
663 if (music_sequence_playing) {
664 if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
665 music_sequence_timer = timer_read();
666 stop_note(music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]);
667 play_note(music_sequence[music_sequence_position], 0xF);
668 music_sequence_position = (music_sequence_position + 1) % music_sequence_count;
677 bool is_music_on(void) {
678 return (music_activated != 0);
681 void music_toggle(void) {
682 if (!music_activated) {
689 void music_on(void) {
694 void music_off(void) {
701 //------------------------------------------------------------------------------
702 // Override these functions in your keymap file to play different tunes on
703 // different events such as startup and bootloader jump
705 __attribute__ ((weak))
706 void startup_user() {}
708 __attribute__ ((weak))
709 void shutdown_user() {}
711 __attribute__ ((weak))
712 void music_on_user() {}
714 __attribute__ ((weak))
715 void audio_on_user() {}
717 __attribute__ ((weak))
718 void music_scale_user() {}
720 //------------------------------------------------------------------------------