diff options
Diffstat (limited to 'quantum/quantum.c')
| -rw-r--r-- | quantum/quantum.c | 158 |
1 files changed, 12 insertions, 146 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c index 5bb7b04d5..36e586d31 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c | |||
| @@ -455,103 +455,8 @@ 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 | __attribute__ ((weak)) |
| 459 | static const uint16_t ascii_to_shift_lut[8] PROGMEM = { | 459 | const bool ascii_to_shift_lut[0x80] 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 | |||
| 478 | static 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 | }; | ||
| 506 | static 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 | |||
| 517 | void 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 | ||
| 554 | static const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = { | ||
| 555 | 0, 0, 0, 0, 0, 0, 0, 0, | 460 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 556 | 0, 0, 0, 0, 0, 0, 0, 0, | 461 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 557 | 0, 0, 0, 0, 0, 0, 0, 0, | 462 | 0, 0, 0, 0, 0, 0, 0, 0, |
| @@ -570,7 +475,8 @@ static const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = { | |||
| 570 | 0, 0, 0, 1, 1, 1, 1, 0 | 475 | 0, 0, 0, 1, 1, 1, 1, 0 |
| 571 | }; | 476 | }; |
| 572 | 477 | ||
| 573 | static const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = { | 478 | __attribute__ ((weak)) |
| 479 | const uint8_t ascii_to_keycode_lut[0x80] PROGMEM = { | ||
| 574 | 0, 0, 0, 0, 0, 0, 0, 0, | 480 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 575 | KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0, | 481 | KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0, |
| 576 | 0, 0, 0, 0, 0, 0, 0, 0, | 482 | 0, 0, 0, 0, 0, 0, 0, 0, |
| @@ -590,12 +496,16 @@ static const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = { | |||
| 590 | }; | 496 | }; |
| 591 | 497 | ||
| 592 | void send_string(const char *str) { | 498 | void send_string(const char *str) { |
| 499 | send_string_with_delay(str, 0); | ||
| 500 | } | ||
| 501 | |||
| 502 | void send_string_with_delay(const char *str, uint8_t interval) { | ||
| 593 | while (1) { | 503 | while (1) { |
| 594 | uint8_t keycode; | 504 | uint8_t keycode; |
| 595 | uint8_t ascii_code = pgm_read_byte(str); | 505 | uint8_t ascii_code = pgm_read_byte(str); |
| 596 | if (!ascii_code) break; | 506 | if (!ascii_code) break; |
| 597 | keycode = pgm_read_byte(&ascii_to_qwerty_keycode_lut[ascii_code]); | 507 | keycode = pgm_read_byte(&ascii_to_keycode_lut[ascii_code]); |
| 598 | if (pgm_read_byte(&ascii_to_qwerty_shift_lut[ascii_code])) { | 508 | if (pgm_read_byte(&ascii_to_shift_lut[ascii_code])) { |
| 599 | register_code(KC_LSFT); | 509 | register_code(KC_LSFT); |
| 600 | register_code(keycode); | 510 | register_code(keycode); |
| 601 | unregister_code(keycode); | 511 | unregister_code(keycode); |
| @@ -606,55 +516,11 @@ void send_string(const char *str) { | |||
| 606 | unregister_code(keycode); | 516 | unregister_code(keycode); |
| 607 | } | 517 | } |
| 608 | ++str; | 518 | ++str; |
| 519 | // interval | ||
| 520 | { uint8_t ms = interval; while (ms--) wait_ms(1); } | ||
| 609 | } | 521 | } |
| 610 | } | 522 | } |
| 611 | 523 | ||
| 612 | #endif | ||
| 613 | |||
| 614 | /* for users whose OSes are set to Colemak */ | ||
| 615 | #if 0 | ||
| 616 | #include "keymap_colemak.h" | ||
| 617 | |||
| 618 | const 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 | |||
| 637 | const 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 | |||
| 658 | void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) { | 524 | void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) { |
| 659 | if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) { | 525 | if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) { |
| 660 | layer_on(layer3); | 526 | layer_on(layer3); |
