aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--keyboards/planck/keymaps/rai-suta/Makefile2
-rw-r--r--quantum/quantum.c236
-rw-r--r--quantum/quantum.h1
3 files changed, 96 insertions, 143 deletions
diff --git a/keyboards/planck/keymaps/rai-suta/Makefile b/keyboards/planck/keymaps/rai-suta/Makefile
index 4263440ec..5238d3201 100644
--- a/keyboards/planck/keymaps/rai-suta/Makefile
+++ b/keyboards/planck/keymaps/rai-suta/Makefile
@@ -21,7 +21,7 @@ RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. Do not enable this
21SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend 21SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
22 22
23# Option defines 23# Option defines
24OPT_DEFS += -DJIS_KEYCODE 24OPT_DEFS += -DSENDSTRING_JIS_KEYCODE
25 25
26ifndef QUANTUM_DIR 26ifndef QUANTUM_DIR
27 include ../../../../Makefile 27 include ../../../../Makefile
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 5bb7b04d5..b5acc75c3 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -455,103 +455,29 @@ bool process_record_quantum(keyrecord_t *record) {
455 return process_action_kb(record); 455 return process_action_kb(record);
456} 456}
457 457
458#ifdef JIS_KEYCODE 458#if defined SENDSTRING_JIS_KEYCODE
459static const uint16_t ascii_to_shift_lut[8] PROGMEM = { 459/* for users with JIS keyboards */
460 0x0000, /*0, 0, 0, 0, 0, 0, 0, 0, 460const bool ascii_to_shift_lut[0x80] PROGMEM = {
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, 461 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, 462 0, 0, 0, 0, 0, 0, 0, 0,
491 0, 0, 0, KC_ESC, 0, 0, 0, 0, 463 0, 0, 0, 0, 0, 0, 0, 0,
492 }, 464 0, 0, 0, 0, 0, 0, 0, 0,
493 .numerics = { 465 0, 1, 1, 1, 1, 1, 1, 1,
494 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, 466 1, 1, 1, 1, 0, 0, 0, 0,
495 KC_8, KC_9, KC_QUOT, KC_SCLN, KC_COMM, KC_MINS, KC_DOT, KC_SLSH, 467 0, 0, 0, 0, 0, 0, 0, 0,
496 }, 468 0, 0, 0, 0, 1, 1, 1, 1,
497 .alphabets_0 = { 469 0, 1, 1, 1, 1, 1, 1, 1,
498 KC_LBRC, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G, 470 1, 1, 1, 1, 1, 1, 1, 1,
499 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O, 471 1, 1, 1, 1, 1, 1, 1, 1,
500 }, 472 1, 1, 1, 0, 0, 0, 0, 1,
501 .alphabets_1 = { 473 1, 0, 0, 0, 0, 0, 0, 0,
502 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W, 474 0, 0, 0, 0, 0, 0, 0, 0,
503 KC_X, KC_Y, KC_Z, KC_RBRC, KC_JYEN, KC_BSLS, KC_EQL, KC_RO, 475 0, 0, 0, 0, 0, 0, 0, 0,
504 }, 476 0, 0, 0, 1, 1, 1, 1, 0
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}; 477};
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 478#else
554static const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = { 479/* for standard keycodes */
480const bool ascii_to_shift_lut[0x80] PROGMEM = {
555 0, 0, 0, 0, 0, 0, 0, 0, 481 0, 0, 0, 0, 0, 0, 0, 0,
556 0, 0, 0, 0, 0, 0, 0, 0, 482 0, 0, 0, 0, 0, 0, 0, 0,
557 0, 0, 0, 0, 0, 0, 0, 0, 483 0, 0, 0, 0, 0, 0, 0, 0,
@@ -569,8 +495,73 @@ static const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = {
569 0, 0, 0, 0, 0, 0, 0, 0, 495 0, 0, 0, 0, 0, 0, 0, 0,
570 0, 0, 0, 1, 1, 1, 1, 0 496 0, 0, 0, 1, 1, 1, 1, 0
571}; 497};
498#endif
572 499
573static const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = { 500#if defined SENDSTRING_JIS_KEYCODE
501/* for users with JIS keyboards */
502const uint8_t ascii_to_keycode_lut[0x80] PROGMEM = {
503 0, 0, 0, 0, 0, 0, 0, 0,
504 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
505 0, 0, 0, 0, 0, 0, 0, 0,
506 0, 0, 0, KC_ESC, 0, 0, 0, 0,
507 KC_SPC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
508 KC_8, KC_9, KC_QUOT, KC_SCLN, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
509 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
510 KC_8, KC_9, KC_QUOT, KC_SCLN, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
511 KC_LBRC, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
512 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
513 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
514 KC_X, KC_Y, KC_Z, KC_RBRC, KC_JYEN, KC_BSLS, KC_EQL, KC_RO,
515 KC_LBRC, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
516 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
517 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
518 KC_X, KC_Y, KC_Z, KC_RBRC, KC_JYEN, KC_BSLS, KC_EQL, KC_DEL,
519};
520#elif defined SENDSTRING_COLEMAK_KEYCODE
521/* for users whose OSes are set to Colemak */
522#include "keymap_colemak.h"
523const uint8_t ascii_to_keycode_lut[0x80] PROGMEM = {
524 0, 0, 0, 0, 0, 0, 0, 0,
525 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
526 0, 0, 0, 0, 0, 0, 0, 0,
527 0, 0, 0, KC_ESC, 0, 0, 0, 0,
528 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
529 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
530 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
531 KC_8, KC_9, CM_SCLN, CM_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
532 KC_2, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
533 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
534 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
535 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
536 KC_GRV, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
537 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
538 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
539 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
540};
541#elif defined SENDSTRING_DVORAK_KEYCODE
542/* for users whose OSes are set to Dvorak */
543#include "keymap_dvorak.h"
544const uint8_t ascii_to_keycode_lut[0x80] PROGMEM = {
545 0, 0, 0, 0, 0, 0, 0, 0,
546 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
547 0, 0, 0, 0, 0, 0, 0, 0,
548 0, 0, 0, KC_ESC, 0, 0, 0, 0,
549 KC_SPC, DV_1, DV_QUOT, DV_3, DV_4, DV_5, DV_7, DV_QUOT,
550 DV_9, DV_0, DV_8, DV_EQL, DV_COMM, DV_MINS, DV_DOT, DV_SLSH,
551 DV_0, DV_1, DV_2, DV_3, DV_4, DV_5, DV_6, DV_7,
552 DV_8, DV_9, DV_SCLN, DV_SCLN, DV_COMM, DV_EQL, DV_DOT, DV_SLSH,
553 DV_2, DV_A, DV_B, DV_C, DV_D, DV_E, DV_F, DV_G,
554 DV_H, DV_I, DV_J, DV_K, DV_L, DV_M, DV_N, DV_O,
555 DV_P, DV_Q, DV_R, DV_S, DV_T, DV_U, DV_V, DV_W,
556 DV_X, DV_Y, DV_Z, DV_LBRC, DV_BSLS, DV_RBRC, DV_6, DV_MINS,
557 DV_GRV, DV_A, DV_B, DV_C, DV_D, DV_E, DV_F, DV_G,
558 DV_H, DV_I, DV_J, DV_K, DV_L, DV_M, DV_N, DV_O,
559 DV_P, DV_Q, DV_R, DV_S, DV_T, DV_U, DV_V, DV_W,
560 DV_X, DV_Y, DV_Z, DV_LBRC, DV_BSLS, DV_RBRC, DV_GRV, KC_DEL
561};
562#else
563/* For users with default keyboard layout in OS */
564const uint8_t ascii_to_keycode_lut[0x80] PROGMEM = {
574 0, 0, 0, 0, 0, 0, 0, 0, 565 0, 0, 0, 0, 0, 0, 0, 0,
575 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0, 566 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
576 0, 0, 0, 0, 0, 0, 0, 0, 567 0, 0, 0, 0, 0, 0, 0, 0,
@@ -588,14 +579,19 @@ static const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = {
588 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W, 579 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
589 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL 580 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
590}; 581};
582#endif
591 583
592void send_string(const char *str) { 584void send_string(const char *str) {
585 send_string_with_delay(str, 0);
586}
587
588void send_string_with_delay(const char *str, uint8_t interval) {
593 while (1) { 589 while (1) {
594 uint8_t keycode; 590 uint8_t keycode;
595 uint8_t ascii_code = pgm_read_byte(str); 591 uint8_t ascii_code = pgm_read_byte(str);
596 if (!ascii_code) break; 592 if (!ascii_code) break;
597 keycode = pgm_read_byte(&ascii_to_qwerty_keycode_lut[ascii_code]); 593 keycode = pgm_read_byte(&ascii_to_keycode_lut[ascii_code]);
598 if (pgm_read_byte(&ascii_to_qwerty_shift_lut[ascii_code])) { 594 if (pgm_read_byte(&ascii_to_shift_lut[ascii_code])) {
599 register_code(KC_LSFT); 595 register_code(KC_LSFT);
600 register_code(keycode); 596 register_code(keycode);
601 unregister_code(keycode); 597 unregister_code(keycode);
@@ -606,55 +602,11 @@ void send_string(const char *str) {
606 unregister_code(keycode); 602 unregister_code(keycode);
607 } 603 }
608 ++str; 604 ++str;
605 // interval
606 { uint8_t ms = interval; while (ms--) wait_ms(1); }
609 } 607 }
610} 608}
611 609
612#endif
613
614/* for users whose OSes are set to Colemak */
615#if 0
616#include "keymap_colemak.h"
617
618const bool ascii_to_colemak_shift_lut[0x80] PROGMEM = {
619 0, 0, 0, 0, 0, 0, 0, 0,
620 0, 0, 0, 0, 0, 0, 0, 0,
621 0, 0, 0, 0, 0, 0, 0, 0,
622 0, 0, 0, 0, 0, 0, 0, 0,
623 0, 1, 1, 1, 1, 1, 1, 0,
624 1, 1, 1, 1, 0, 0, 0, 0,
625 0, 0, 0, 0, 0, 0, 0, 0,
626 0, 0, 1, 0, 1, 0, 1, 1,
627 1, 1, 1, 1, 1, 1, 1, 1,
628 1, 1, 1, 1, 1, 1, 1, 1,
629 1, 1, 1, 1, 1, 1, 1, 1,
630 1, 1, 1, 0, 0, 0, 1, 1,
631 0, 0, 0, 0, 0, 0, 0, 0,
632 0, 0, 0, 0, 0, 0, 0, 0,
633 0, 0, 0, 0, 0, 0, 0, 0,
634 0, 0, 0, 1, 1, 1, 1, 0
635};
636
637const uint8_t ascii_to_colemak_keycode_lut[0x80] PROGMEM = {
638 0, 0, 0, 0, 0, 0, 0, 0,
639 KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
640 0, 0, 0, 0, 0, 0, 0, 0,
641 0, 0, 0, KC_ESC, 0, 0, 0, 0,
642 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
643 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
644 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
645 KC_8, KC_9, CM_SCLN, CM_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
646 KC_2, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
647 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
648 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
649 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
650 KC_GRV, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
651 CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
652 CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
653 CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
654};
655
656#endif
657
658void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) { 610void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
659 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) { 611 if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
660 layer_on(layer3); 612 layer_on(layer3);
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 2bf18d095..1dafbf3b0 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -96,6 +96,7 @@ extern uint32_t default_layer_state;
96 96
97#define SEND_STRING(str) send_string(PSTR(str)) 97#define SEND_STRING(str) send_string(PSTR(str))
98void send_string(const char *str); 98void send_string(const char *str);
99void send_string_with_delay(const char *str, uint8_t interval);
99 100
100// For tri-layer 101// For tri-layer
101void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3); 102void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);