aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common_features.mk1
-rw-r--r--quantum/quantum.c232
-rw-r--r--quantum/quantum.h27
-rw-r--r--quantum/send_string.c252
-rw-r--r--quantum/send_string.h47
5 files changed, 301 insertions, 258 deletions
diff --git a/common_features.mk b/common_features.mk
index 109c50c5f..bdde278b9 100644
--- a/common_features.mk
+++ b/common_features.mk
@@ -17,6 +17,7 @@ SERIAL_PATH := $(QUANTUM_PATH)/serial_link
17 17
18QUANTUM_SRC += \ 18QUANTUM_SRC += \
19 $(QUANTUM_DIR)/quantum.c \ 19 $(QUANTUM_DIR)/quantum.c \
20 $(QUANTUM_DIR)/send_string.c \
20 $(QUANTUM_DIR)/bitwise.c \ 21 $(QUANTUM_DIR)/bitwise.c \
21 $(QUANTUM_DIR)/led.c \ 22 $(QUANTUM_DIR)/led.c \
22 $(QUANTUM_DIR)/keymap_common.c \ 23 $(QUANTUM_DIR)/keymap_common.c \
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 7345ab0d5..ef751a233 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -14,7 +14,6 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */ 15 */
16 16
17#include <ctype.h>
18#include "quantum.h" 17#include "quantum.h"
19#include "magic.h" 18#include "magic.h"
20 19
@@ -326,237 +325,6 @@ bool process_record_quantum(keyrecord_t *record) {
326 return process_action_kb(record); 325 return process_action_kb(record);
327} 326}
328 327
329// clang-format off
330
331/* Bit-Packed look-up table to convert an ASCII character to whether
332 * [Shift] needs to be sent with the keycode.
333 */
334__attribute__((weak)) const uint8_t ascii_to_shift_lut[16] PROGMEM = {
335 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
336 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
337 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
338 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
339
340 KCLUT_ENTRY(0, 1, 1, 1, 1, 1, 1, 0),
341 KCLUT_ENTRY(1, 1, 1, 1, 0, 0, 0, 0),
342 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
343 KCLUT_ENTRY(0, 0, 1, 0, 1, 0, 1, 1),
344 KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1),
345 KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1),
346 KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1),
347 KCLUT_ENTRY(1, 1, 1, 0, 0, 0, 1, 1),
348 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
349 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
350 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
351 KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 1, 0),
352};
353
354/* Bit-Packed look-up table to convert an ASCII character to whether
355 * [AltGr] needs to be sent with the keycode.
356 */
357__attribute__((weak)) const uint8_t ascii_to_altgr_lut[16] PROGMEM = {
358 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
359 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
360 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
361 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
362
363 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
364 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
365 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
366 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
367 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
368 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
369 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
370 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
371 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
372 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
373 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
374 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
375};
376
377/* Bit-Packed look-up table to convert an ASCII character to whether
378 * [Space] needs to be sent after the keycode
379 */
380__attribute__((weak)) const uint8_t ascii_to_dead_lut[16] PROGMEM = {
381 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
382 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
383 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
384 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
385
386 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
387 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
388 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
389 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
390 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
391 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
392 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
393 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
394 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
395 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
396 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
397 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
398};
399
400/* Look-up table to convert an ASCII character to a keycode.
401 */
402__attribute__((weak)) const uint8_t ascii_to_keycode_lut[128] PROGMEM = {
403 // NUL SOH STX ETX EOT ENQ ACK BEL
404 XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
405 // BS TAB LF VT FF CR SO SI
406 KC_BSPC, KC_TAB, KC_ENT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
407 // DLE DC1 DC2 DC3 DC4 NAK SYN ETB
408 XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
409 // CAN EM SUB ESC FS GS RS US
410 XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
411
412 // ! " # $ % & '
413 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
414 // ( ) * + , - . /
415 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
416 // 0 1 2 3 4 5 6 7
417 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
418 // 8 9 : ; < = > ?
419 KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
420 // @ A B C D E F G
421 KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
422 // H I J K L M N O
423 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
424 // P Q R S T U V W
425 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
426 // X Y Z [ \ ] ^ _
427 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
428 // ` a b c d e f g
429 KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
430 // h i j k l m n o
431 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
432 // p q r s t u v w
433 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
434 // x y z { | } ~ DEL
435 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
436};
437
438// clang-format on
439
440// Note: we bit-pack in "reverse" order to optimize loading
441#define PGM_LOADBIT(mem, pos) ((pgm_read_byte(&((mem)[(pos) / 8])) >> ((pos) % 8)) & 0x01)
442
443void send_string(const char *str) { send_string_with_delay(str, 0); }
444
445void send_string_P(const char *str) { send_string_with_delay_P(str, 0); }
446
447void send_string_with_delay(const char *str, uint8_t interval) {
448 while (1) {
449 char ascii_code = *str;
450 if (!ascii_code) break;
451 if (ascii_code == SS_QMK_PREFIX) {
452 ascii_code = *(++str);
453 if (ascii_code == SS_TAP_CODE) {
454 // tap
455 uint8_t keycode = *(++str);
456 tap_code(keycode);
457 } else if (ascii_code == SS_DOWN_CODE) {
458 // down
459 uint8_t keycode = *(++str);
460 register_code(keycode);
461 } else if (ascii_code == SS_UP_CODE) {
462 // up
463 uint8_t keycode = *(++str);
464 unregister_code(keycode);
465 } else if (ascii_code == SS_DELAY_CODE) {
466 // delay
467 int ms = 0;
468 uint8_t keycode = *(++str);
469 while (isdigit(keycode)) {
470 ms *= 10;
471 ms += keycode - '0';
472 keycode = *(++str);
473 }
474 while (ms--) wait_ms(1);
475 }
476 } else {
477 send_char(ascii_code);
478 }
479 ++str;
480 // interval
481 {
482 uint8_t ms = interval;
483 while (ms--) wait_ms(1);
484 }
485 }
486}
487
488void send_string_with_delay_P(const char *str, uint8_t interval) {
489 while (1) {
490 char ascii_code = pgm_read_byte(str);
491 if (!ascii_code) break;
492 if (ascii_code == SS_QMK_PREFIX) {
493 ascii_code = pgm_read_byte(++str);
494 if (ascii_code == SS_TAP_CODE) {
495 // tap
496 uint8_t keycode = pgm_read_byte(++str);
497 tap_code(keycode);
498 } else if (ascii_code == SS_DOWN_CODE) {
499 // down
500 uint8_t keycode = pgm_read_byte(++str);
501 register_code(keycode);
502 } else if (ascii_code == SS_UP_CODE) {
503 // up
504 uint8_t keycode = pgm_read_byte(++str);
505 unregister_code(keycode);
506 } else if (ascii_code == SS_DELAY_CODE) {
507 // delay
508 int ms = 0;
509 uint8_t keycode = pgm_read_byte(++str);
510 while (isdigit(keycode)) {
511 ms *= 10;
512 ms += keycode - '0';
513 keycode = pgm_read_byte(++str);
514 }
515 while (ms--) wait_ms(1);
516 }
517 } else {
518 send_char(ascii_code);
519 }
520 ++str;
521 // interval
522 {
523 uint8_t ms = interval;
524 while (ms--) wait_ms(1);
525 }
526 }
527}
528
529void send_char(char ascii_code) {
530#if defined(AUDIO_ENABLE) && defined(SENDSTRING_BELL)
531 if (ascii_code == '\a') { // BEL
532 PLAY_SONG(bell_song);
533 return;
534 }
535#endif
536
537 uint8_t keycode = pgm_read_byte(&ascii_to_keycode_lut[(uint8_t)ascii_code]);
538 bool is_shifted = PGM_LOADBIT(ascii_to_shift_lut, (uint8_t)ascii_code);
539 bool is_altgred = PGM_LOADBIT(ascii_to_altgr_lut, (uint8_t)ascii_code);
540 bool is_dead = PGM_LOADBIT(ascii_to_dead_lut, (uint8_t)ascii_code);
541
542 if (is_shifted) {
543 register_code(KC_LSFT);
544 }
545 if (is_altgred) {
546 register_code(KC_RALT);
547 }
548 tap_code(keycode);
549 if (is_altgred) {
550 unregister_code(KC_RALT);
551 }
552 if (is_shifted) {
553 unregister_code(KC_LSFT);
554 }
555 if (is_dead) {
556 tap_code(KC_SPACE);
557 }
558}
559
560void set_single_persistent_default_layer(uint8_t default_layer) { 328void set_single_persistent_default_layer(uint8_t default_layer) {
561#if defined(AUDIO_ENABLE) && defined(DEFAULT_LAYER_SONGS) 329#if defined(AUDIO_ENABLE) && defined(DEFAULT_LAYER_SONGS)
562 PLAY_SONG(default_layer_songs[default_layer]); 330 PLAY_SONG(default_layer_songs[default_layer]);
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 7bb6e796e..070bd0131 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -62,7 +62,7 @@
62#include "action_util.h" 62#include "action_util.h"
63#include "action_tapping.h" 63#include "action_tapping.h"
64#include "print.h" 64#include "print.h"
65#include "send_string_keycodes.h" 65#include "send_string.h"
66#include "suspend.h" 66#include "suspend.h"
67#include <stddef.h> 67#include <stddef.h>
68#include <stdlib.h> 68#include <stdlib.h>
@@ -232,31 +232,6 @@ extern layer_state_t layer_state;
232# define waitInputPinDelay() wait_cpuclock(GPIO_INPUT_PIN_DELAY) 232# define waitInputPinDelay() wait_cpuclock(GPIO_INPUT_PIN_DELAY)
233 233
234#endif 234#endif
235#define SEND_STRING(string) send_string_P(PSTR(string))
236#define SEND_STRING_DELAY(string, interval) send_string_with_delay_P(PSTR(string), interval)
237
238// Look-Up Tables (LUTs) to convert ASCII character to keycode sequence.
239extern const uint8_t ascii_to_keycode_lut[128];
240extern const uint8_t ascii_to_shift_lut[16];
241extern const uint8_t ascii_to_altgr_lut[16];
242extern const uint8_t ascii_to_dead_lut[16];
243// clang-format off
244#define KCLUT_ENTRY(a, b, c, d, e, f, g, h) \
245 ( ((a) ? 1 : 0) << 0 \
246 | ((b) ? 1 : 0) << 1 \
247 | ((c) ? 1 : 0) << 2 \
248 | ((d) ? 1 : 0) << 3 \
249 | ((e) ? 1 : 0) << 4 \
250 | ((f) ? 1 : 0) << 5 \
251 | ((g) ? 1 : 0) << 6 \
252 | ((h) ? 1 : 0) << 7 )
253// clang-format on
254
255void send_string(const char *str);
256void send_string_with_delay(const char *str, uint8_t interval);
257void send_string_P(const char *str);
258void send_string_with_delay_P(const char *str, uint8_t interval);
259void send_char(char ascii_code);
260 235
261// For tri-layer 236// For tri-layer
262void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3); 237void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
diff --git a/quantum/send_string.c b/quantum/send_string.c
new file mode 100644
index 000000000..0e8902ca3
--- /dev/null
+++ b/quantum/send_string.c
@@ -0,0 +1,252 @@
1/* Copyright 2021
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <ctype.h>
18
19#include "quantum.h"
20
21#include "send_string.h"
22
23// clang-format off
24
25/* Bit-Packed look-up table to convert an ASCII character to whether
26 * [Shift] needs to be sent with the keycode.
27 */
28__attribute__((weak)) const uint8_t ascii_to_shift_lut[16] PROGMEM = {
29 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
30 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
31 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
32 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
33
34 KCLUT_ENTRY(0, 1, 1, 1, 1, 1, 1, 0),
35 KCLUT_ENTRY(1, 1, 1, 1, 0, 0, 0, 0),
36 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
37 KCLUT_ENTRY(0, 0, 1, 0, 1, 0, 1, 1),
38 KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1),
39 KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1),
40 KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1),
41 KCLUT_ENTRY(1, 1, 1, 0, 0, 0, 1, 1),
42 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
43 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
44 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
45 KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 1, 0)
46};
47
48/* Bit-Packed look-up table to convert an ASCII character to whether
49 * [AltGr] needs to be sent with the keycode.
50 */
51__attribute__((weak)) const uint8_t ascii_to_altgr_lut[16] PROGMEM = {
52 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
53 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
54 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
55 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
56
57 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
58 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
59 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
60 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
61 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
62 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
63 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
64 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
65 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
66 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
67 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
68 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0)
69};
70
71/* Bit-Packed look-up table to convert an ASCII character to whether
72 * [Space] needs to be sent after the keycode
73 */
74__attribute__((weak)) const uint8_t ascii_to_dead_lut[16] PROGMEM = {
75 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
76 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
77 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
78 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
79
80 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
81 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
82 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
83 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
84 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
85 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
86 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
87 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
88 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
89 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
90 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0),
91 KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0)
92};
93
94/* Look-up table to convert an ASCII character to a keycode.
95 */
96__attribute__((weak)) const uint8_t ascii_to_keycode_lut[128] PROGMEM = {
97 // NUL SOH STX ETX EOT ENQ ACK BEL
98 XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
99 // BS TAB LF VT FF CR SO SI
100 KC_BSPC, KC_TAB, KC_ENT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
101 // DLE DC1 DC2 DC3 DC4 NAK SYN ETB
102 XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
103 // CAN EM SUB ESC FS GS RS US
104 XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
105
106 // ! " # $ % & '
107 KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
108 // ( ) * + , - . /
109 KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
110 // 0 1 2 3 4 5 6 7
111 KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
112 // 8 9 : ; < = > ?
113 KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
114 // @ A B C D E F G
115 KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
116 // H I J K L M N O
117 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
118 // P Q R S T U V W
119 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
120 // X Y Z [ \ ] ^ _
121 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
122 // ` a b c d e f g
123 KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
124 // h i j k l m n o
125 KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
126 // p q r s t u v w
127 KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
128 // x y z { | } ~ DEL
129 KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
130};
131
132// clang-format on
133
134// Note: we bit-pack in "reverse" order to optimize loading
135#define PGM_LOADBIT(mem, pos) ((pgm_read_byte(&((mem)[(pos) / 8])) >> ((pos) % 8)) & 0x01)
136
137void send_string(const char *str) { send_string_with_delay(str, 0); }
138
139void send_string_P(const char *str) { send_string_with_delay_P(str, 0); }
140
141void send_string_with_delay(const char *str, uint8_t interval) {
142 while (1) {
143 char ascii_code = *str;
144 if (!ascii_code) break;
145 if (ascii_code == SS_QMK_PREFIX) {
146 ascii_code = *(++str);
147 if (ascii_code == SS_TAP_CODE) {
148 // tap
149 uint8_t keycode = *(++str);
150 tap_code(keycode);
151 } else if (ascii_code == SS_DOWN_CODE) {
152 // down
153 uint8_t keycode = *(++str);
154 register_code(keycode);
155 } else if (ascii_code == SS_UP_CODE) {
156 // up
157 uint8_t keycode = *(++str);
158 unregister_code(keycode);
159 } else if (ascii_code == SS_DELAY_CODE) {
160 // delay
161 int ms = 0;
162 uint8_t keycode = *(++str);
163 while (isdigit(keycode)) {
164 ms *= 10;
165 ms += keycode - '0';
166 keycode = *(++str);
167 }
168 while (ms--) wait_ms(1);
169 }
170 } else {
171 send_char(ascii_code);
172 }
173 ++str;
174 // interval
175 {
176 uint8_t ms = interval;
177 while (ms--) wait_ms(1);
178 }
179 }
180}
181
182void send_string_with_delay_P(const char *str, uint8_t interval) {
183 while (1) {
184 char ascii_code = pgm_read_byte(str);
185 if (!ascii_code) break;
186 if (ascii_code == SS_QMK_PREFIX) {
187 ascii_code = pgm_read_byte(++str);
188 if (ascii_code == SS_TAP_CODE) {
189 // tap
190 uint8_t keycode = pgm_read_byte(++str);
191 tap_code(keycode);
192 } else if (ascii_code == SS_DOWN_CODE) {
193 // down
194 uint8_t keycode = pgm_read_byte(++str);
195 register_code(keycode);
196 } else if (ascii_code == SS_UP_CODE) {
197 // up
198 uint8_t keycode = pgm_read_byte(++str);
199 unregister_code(keycode);
200 } else if (ascii_code == SS_DELAY_CODE) {
201 // delay
202 int ms = 0;
203 uint8_t keycode = pgm_read_byte(++str);
204 while (isdigit(keycode)) {
205 ms *= 10;
206 ms += keycode - '0';
207 keycode = pgm_read_byte(++str);
208 }
209 while (ms--) wait_ms(1);
210 }
211 } else {
212 send_char(ascii_code);
213 }
214 ++str;
215 // interval
216 {
217 uint8_t ms = interval;
218 while (ms--) wait_ms(1);
219 }
220 }
221}
222
223void send_char(char ascii_code) {
224#if defined(AUDIO_ENABLE) && defined(SENDSTRING_BELL)
225 if (ascii_code == '\a') { // BEL
226 PLAY_SONG(bell_song);
227 return;
228 }
229#endif
230
231 uint8_t keycode = pgm_read_byte(&ascii_to_keycode_lut[(uint8_t)ascii_code]);
232 bool is_shifted = PGM_LOADBIT(ascii_to_shift_lut, (uint8_t)ascii_code);
233 bool is_altgred = PGM_LOADBIT(ascii_to_altgr_lut, (uint8_t)ascii_code);
234 bool is_dead = PGM_LOADBIT(ascii_to_dead_lut, (uint8_t)ascii_code);
235
236 if (is_shifted) {
237 register_code(KC_LSFT);
238 }
239 if (is_altgred) {
240 register_code(KC_RALT);
241 }
242 tap_code(keycode);
243 if (is_altgred) {
244 unregister_code(KC_RALT);
245 }
246 if (is_shifted) {
247 unregister_code(KC_LSFT);
248 }
249 if (is_dead) {
250 tap_code(KC_SPACE);
251 }
252} \ No newline at end of file
diff --git a/quantum/send_string.h b/quantum/send_string.h
new file mode 100644
index 000000000..570522eb0
--- /dev/null
+++ b/quantum/send_string.h
@@ -0,0 +1,47 @@
1/* Copyright 2021
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <stdint.h>
18
19#include "progmem.h"
20#include "send_string_keycodes.h"
21
22#define SEND_STRING(string) send_string_P(PSTR(string))
23#define SEND_STRING_DELAY(string, interval) send_string_with_delay_P(PSTR(string), interval)
24
25// Look-Up Tables (LUTs) to convert ASCII character to keycode sequence.
26extern const uint8_t ascii_to_keycode_lut[128];
27extern const uint8_t ascii_to_shift_lut[16];
28extern const uint8_t ascii_to_altgr_lut[16];
29extern const uint8_t ascii_to_dead_lut[16];
30
31// clang-format off
32#define KCLUT_ENTRY(a, b, c, d, e, f, g, h) \
33 ( ((a) ? 1 : 0) << 0 \
34 | ((b) ? 1 : 0) << 1 \
35 | ((c) ? 1 : 0) << 2 \
36 | ((d) ? 1 : 0) << 3 \
37 | ((e) ? 1 : 0) << 4 \
38 | ((f) ? 1 : 0) << 5 \
39 | ((g) ? 1 : 0) << 6 \
40 | ((h) ? 1 : 0) << 7 )
41// clang-format on
42
43void send_string(const char *str);
44void send_string_with_delay(const char *str, uint8_t interval);
45void send_string_P(const char *str);
46void send_string_with_delay_P(const char *str, uint8_t interval);
47void send_char(char ascii_code);