aboutsummaryrefslogtreecommitdiff
path: root/quantum/quantum.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/quantum.c')
-rw-r--r--quantum/quantum.c150
1 files changed, 128 insertions, 22 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 4f4cee4e9..5bb7b04d5 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -437,6 +437,14 @@ bool process_record_quantum(keyrecord_t *record) {
437 return false; 437 return false;
438 // break; 438 // break;
439 } 439 }
440 case GRAVE_ESC: {
441 void (*method)(uint8_t) = (record->event.pressed) ? &add_key : &del_key;
442 uint8_t shifted = get_mods() & ((MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT)
443 |MOD_BIT(KC_LGUI)|MOD_BIT(KC_RGUI)));
444
445 method(shifted ? KC_GRAVE : KC_ESCAPE);
446 send_keyboard_report();
447 }
440 default: { 448 default: {
441 shift_interrupted[0] = true; 449 shift_interrupted[0] = true;
442 shift_interrupted[1] = true; 450 shift_interrupted[1] = true;
@@ -447,7 +455,103 @@ bool process_record_quantum(keyrecord_t *record) {
447 return process_action_kb(record); 455 return process_action_kb(record);
448} 456}
449 457
450const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = { 458#ifdef JIS_KEYCODE
459static const uint16_t ascii_to_shift_lut[8] PROGMEM = {
460 0x0000, /*0, 0, 0, 0, 0, 0, 0, 0,
461 0, 0, 0, 0, 0, 0, 0, 0,*/
462 0x0000, /*0, 0, 0, 0, 0, 0, 0, 0,
463 0, 0, 0, 0, 0, 0, 0, 0,*/
464 0x7ff0, /*0, 1, 1, 1, 1, 1, 1, 1,
465 1, 1, 1, 1, 0, 0, 0, 0,*/
466 0x000f, /*0, 0, 0, 0, 0, 0, 0, 0,
467 0, 0, 0, 0, 1, 1, 1, 1,*/
468 0x7fff, /*0, 1, 1, 1, 1, 1, 1, 1,
469 1, 1, 1, 1, 1, 1, 1, 1,*/
470 0xffe1, /*1, 1, 1, 1, 1, 1, 1, 1,
471 1, 1, 1, 0, 0, 0, 0, 1,*/
472 0x8000, /*1, 0, 0, 0, 0, 0, 0, 0,
473 0, 0, 0, 0, 0, 0, 0, 0,*/
474 0x001e, /*0, 0, 0, 0, 0, 0, 0, 0,
475 0, 0, 0, 1, 1, 1, 1, 0*/
476};
477
478static const struct {
479 uint8_t controls_0[16],
480 controls_1[16],
481 numerics[16],
482 alphabets_0[16],
483 alphabets_1[16];
484} lower_to_keycode PROGMEM = {
485 .controls_0 = {
486 0, 0, 0, 0, 0, 0, 0, 0,
487 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
488 },
489 .controls_1 = {
490 0, 0, 0, 0, 0, 0, 0, 0,
491 0, 0, 0, KC_ESC, 0, 0, 0, 0,
492 },
493 .numerics = {
494 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
495 KC_8, KC_9, KC_QUOT, KC_SCLN, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
496 },
497 .alphabets_0 = {
498 KC_LBRC, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
499 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
500 },
501 .alphabets_1 = {
502 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
503 KC_X, KC_Y, KC_Z, KC_RBRC, KC_JYEN, KC_BSLS, KC_EQL, KC_RO,
504 },
505};
506static const uint8_t* ascii_to_keycode_lut[8] = {
507 lower_to_keycode.controls_0,
508 lower_to_keycode.controls_1,
509 lower_to_keycode.numerics,
510 lower_to_keycode.numerics,
511 lower_to_keycode.alphabets_0,
512 lower_to_keycode.alphabets_1,
513 lower_to_keycode.alphabets_0,
514 lower_to_keycode.alphabets_1
515};
516
517void send_string(const char *str) {
518 while (1) {
519 uint8_t keycode;
520 bool shift;
521 uint8_t ascii_code = pgm_read_byte(str);
522
523 if ( ascii_code == 0x00u ){ break; }
524 else if (ascii_code == 0x20u) {
525 keycode = KC_SPC;
526 shift = false;
527 }
528 else if (ascii_code == 0x7Fu) {
529 keycode = KC_DEL;
530 shift = false;
531 }
532 else {
533 int hi = ascii_code>>4 & 0x0f,
534 lo = ascii_code & 0x0f;
535 keycode = pgm_read_byte(&ascii_to_keycode_lut[hi][lo]);
536 shift = !!( pgm_read_word(&ascii_to_shift_lut[hi]) & (0x8000u>>lo) );
537 }
538
539 if (shift) {
540 register_code(KC_LSFT);
541 register_code(keycode);
542 unregister_code(keycode);
543 unregister_code(KC_LSFT);
544 }
545 else {
546 register_code(keycode);
547 unregister_code(keycode);
548 }
549 ++str;
550 }
551}
552
553#else
554static const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = {
451 0, 0, 0, 0, 0, 0, 0, 0, 555 0, 0, 0, 0, 0, 0, 0, 0,
452 0, 0, 0, 0, 0, 0, 0, 0, 556 0, 0, 0, 0, 0, 0, 0, 0,
453 0, 0, 0, 0, 0, 0, 0, 0, 557 0, 0, 0, 0, 0, 0, 0, 0,
@@ -466,7 +570,7 @@ const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = {
466 0, 0, 0, 1, 1, 1, 1, 0 570 0, 0, 0, 1, 1, 1, 1, 0
467}; 571};
468 572
469const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = { 573static const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = {
470 0, 0, 0, 0, 0, 0, 0, 0, 574 0, 0, 0, 0, 0, 0, 0, 0,
471 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0, 575 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
472 0, 0, 0, 0, 0, 0, 0, 0, 576 0, 0, 0, 0, 0, 0, 0, 0,
@@ -485,6 +589,28 @@ const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = {
485 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL 589 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
486}; 590};
487 591
592void send_string(const char *str) {
593 while (1) {
594 uint8_t keycode;
595 uint8_t ascii_code = pgm_read_byte(str);
596 if (!ascii_code) break;
597 keycode = pgm_read_byte(&ascii_to_qwerty_keycode_lut[ascii_code]);
598 if (pgm_read_byte(&ascii_to_qwerty_shift_lut[ascii_code])) {
599 register_code(KC_LSFT);
600 register_code(keycode);
601 unregister_code(keycode);
602 unregister_code(KC_LSFT);
603 }
604 else {
605 register_code(keycode);
606 unregister_code(keycode);
607 }
608 ++str;
609 }
610}
611
612#endif
613
488/* for users whose OSes are set to Colemak */ 614/* for users whose OSes are set to Colemak */
489#if 0 615#if 0
490#include "keymap_colemak.h" 616#include "keymap_colemak.h"
@@ -529,26 +655,6 @@ const uint8_t ascii_to_colemak_keycode_lut[0x80] PROGMEM = {
529 655
530#endif 656#endif
531 657
532void send_string(const char *str) {
533 while (1) {
534 uint8_t keycode;
535 uint8_t ascii_code = pgm_read_byte(str);
536 if (!ascii_code) break;
537 keycode = pgm_read_byte(&ascii_to_qwerty_keycode_lut[ascii_code]);
538 if (pgm_read_byte(&ascii_to_qwerty_shift_lut[ascii_code])) {
539 register_code(KC_LSFT);
540 register_code(keycode);
541 unregister_code(keycode);
542 unregister_code(KC_LSFT);
543 }
544 else {
545 register_code(keycode);
546 unregister_code(keycode);
547 }
548 ++str;
549 }
550}
551
552void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) { 658void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
553 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) { 659 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
554 layer_on(layer3); 660 layer_on(layer3);