From b191eaaf28fd456e95a5d8a04f4c2067f5d487d7 Mon Sep 17 00:00:00 2001 From: Ted M Lin Date: Mon, 3 Feb 2020 15:07:08 -0500 Subject: [PATCH 1/5] Reduce PROGMEM usage for keycode map Bit-pack the keycode bool array to gain back a small amount of flash space. The trade-off is an increase in runtime instructions when running macros. It does make the code a bit harder to read, as well as maintain. For configs that use send_string() et al, it saves ~100 bytes. --- quantum/keymap_extras/sendstring_belgian.h | 20 +++ quantum/keymap_extras/sendstring_bepo.h | 20 +++ quantum/keymap_extras/sendstring_french.h | 20 +++ quantum/keymap_extras/sendstring_german.h | 20 +++ quantum/keymap_extras/sendstring_jis.h | 10 ++ quantum/keymap_extras/sendstring_spanish.h | 21 +++ quantum/keymap_extras/sendstring_uk.h | 10 ++ quantum/quantum.c | 146 +++++++++++++++------ quantum/quantum.h | 5 + 9 files changed, 232 insertions(+), 40 deletions(-) diff --git a/quantum/keymap_extras/sendstring_belgian.h b/quantum/keymap_extras/sendstring_belgian.h index ca0edfb683cc..4fc952e09f2d 100644 --- a/quantum/keymap_extras/sendstring_belgian.h +++ b/quantum/keymap_extras/sendstring_belgian.h @@ -22,6 +22,7 @@ // clang-format off +#ifndef USE_PACKED_KEYCODE_LUT const bool ascii_to_shift_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -41,7 +42,17 @@ const bool ascii_to_shift_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +#else +const uint8_t ascii_to_shift_lutp[16] PROGMEM = { + 0x00, 0x00, 0x00, 0x00, + 0x04, 0x33, 0xff, 0xc3, + 0x7f, 0xff, 0xff, 0xe1, + 0x00, 0x00, 0x00, 0x00 +}; +#endif + +#ifndef USE_PACKED_KEYCODE_LUT const bool ascii_to_altgr_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -61,6 +72,15 @@ const bool ascii_to_altgr_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0 }; +#else +const uint8_t ascii_to_altgr_lutp[16] PROGMEM = { + 0x00, 0x00, 0x00, 0x00, + + 0x10, 0x00, 0x00, 0x00, + 0x80, 0x00, 0x00, 0x1e, + 0x80, 0x00, 0x00, 0x1e +}; +#endif const uint8_t ascii_to_keycode_lut[128] PROGMEM = { // NUL SOH STX ETX EOT ENQ ACK BEL diff --git a/quantum/keymap_extras/sendstring_bepo.h b/quantum/keymap_extras/sendstring_bepo.h index ca5f73d7ec31..e3f4b2055317 100644 --- a/quantum/keymap_extras/sendstring_bepo.h +++ b/quantum/keymap_extras/sendstring_bepo.h @@ -22,6 +22,7 @@ // clang-format off +#ifndef USE_PACKED_KEYCODE_LUT const bool ascii_to_shift_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -41,7 +42,17 @@ const bool ascii_to_shift_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +#else +const uint8_t ascii_to_shift_lutp[16] PROGMEM = { + 0x00, 0x00, 0x00, 0x00, + 0x50, 0x00, 0xff, 0xf1, + 0x7f, 0xff, 0xff, 0xe0, + 0x80, 0x00, 0x00, 0x00 +}; +#endif + +#ifndef USE_PACKED_KEYCODE_LUT const bool ascii_to_altgr_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -61,6 +72,15 @@ const bool ascii_to_altgr_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0 }; +#else +const uint8_t ascii_to_altgr_lutp[16] PROGMEM = { + 0x00, 0x00, 0x00, 0x00, + + 0x02, 0x00, 0x00, 0x0a, + 0x00, 0x00, 0x00, 0x1f, + 0x00, 0x00, 0x00, 0x1e +}; +#endif const uint8_t ascii_to_keycode_lut[128] PROGMEM = { // NUL SOH STX ETX EOT ENQ ACK BEL diff --git a/quantum/keymap_extras/sendstring_french.h b/quantum/keymap_extras/sendstring_french.h index 966685ccca50..d550f1e72d14 100644 --- a/quantum/keymap_extras/sendstring_french.h +++ b/quantum/keymap_extras/sendstring_french.h @@ -22,6 +22,7 @@ // clang-format off +#ifndef USE_PACKED_KEYCODE_LUT const bool ascii_to_shift_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -41,7 +42,17 @@ const bool ascii_to_shift_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +#else +const uint8_t ascii_to_shift_lutp[16] PROGMEM = { + 0x00, 0x00, 0x00, 0x00, + 0x04, 0x13, 0xff, 0xc3, + 0x7f, 0xff, 0xff, 0xe0, + 0x00, 0x00, 0x00, 0x00 +}; +#endif + +#ifndef USE_PACKED_KEYCODE_LUT const bool ascii_to_altgr_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -61,6 +72,15 @@ const bool ascii_to_altgr_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0 }; +#else +const uint8_t ascii_to_altgr_lutp[16] PROGMEM = { + 0x00, 0x00, 0x00, 0x00, + + 0x10, 0x00, 0x00, 0x00, + 0x80, 0x00, 0x00, 0x1e, + 0x80, 0x00, 0x00, 0x1e +}; +#endif const uint8_t ascii_to_keycode_lut[128] PROGMEM = { // NUL SOH STX ETX EOT ENQ ACK BEL diff --git a/quantum/keymap_extras/sendstring_german.h b/quantum/keymap_extras/sendstring_german.h index 3f27a9b2cabe..3c8a93440656 100644 --- a/quantum/keymap_extras/sendstring_german.h +++ b/quantum/keymap_extras/sendstring_german.h @@ -22,6 +22,7 @@ // clang-format off +#ifndef USE_PACKED_KEYCODE_LUT const bool ascii_to_shift_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -41,7 +42,17 @@ const bool ascii_to_shift_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +#else +const uint8_t ascii_to_shift_lutp[16] PROGMEM = { + 0x00, 0x00, 0x00, 0x00, + 0x6f, 0xe1, 0x00, 0x37, + 0x7f, 0xff, 0xff, 0xe1, + 0x80, 0x00, 0x00, 0x00 +}; +#endif + +#ifndef USE_PACKED_KEYCODE_LUT const bool ascii_to_altgr_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -61,6 +72,15 @@ const bool ascii_to_altgr_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0 }; +#else +const uint8_t ascii_to_altgr_lutp[16] PROGMEM = { + 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, + 0x80, 0x00, 0x00, 0x1c, + 0x00, 0x00, 0x00, 0x1e +}; +#endif const uint8_t ascii_to_keycode_lut[128] PROGMEM = { // NUL SOH STX ETX EOT ENQ ACK BEL diff --git a/quantum/keymap_extras/sendstring_jis.h b/quantum/keymap_extras/sendstring_jis.h index 421ceb0438ed..51b7ac30daaa 100644 --- a/quantum/keymap_extras/sendstring_jis.h +++ b/quantum/keymap_extras/sendstring_jis.h @@ -22,6 +22,7 @@ // clang-format off +#ifndef USE_PACKED_KEYCODE_LUT const bool ascii_to_shift_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -41,6 +42,15 @@ const bool ascii_to_shift_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0 }; +#else +const uint8_t ascii_to_shift_lutp[16] PROGMEM = { + 0x00, 0x00, 0x00, 0x00, + + 0x7f, 0xf0, 0x00, 0x0f, + 0x7f, 0xff, 0xff, 0xe1, + 0x80, 0x00, 0x00, 0x1e +}; +#endif const uint8_t ascii_to_keycode_lut[128] PROGMEM = { // NUL SOH STX ETX EOT ENQ ACK BEL diff --git a/quantum/keymap_extras/sendstring_spanish.h b/quantum/keymap_extras/sendstring_spanish.h index 92bada269a04..dcd237aa2014 100644 --- a/quantum/keymap_extras/sendstring_spanish.h +++ b/quantum/keymap_extras/sendstring_spanish.h @@ -22,6 +22,7 @@ // clang-format off +#ifndef USE_PACKED_KEYCODE_LUT const bool ascii_to_shift_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -41,7 +42,17 @@ const bool ascii_to_shift_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +#else +const uint8_t ascii_to_shift_lutp[16] PROGMEM = { + 0x00, 0x00, 0x00, 0x00, + 0x6e, 0xe1, 0x00, 0x37, + 0x7f, 0xff, 0xff, 0xe3, + 0x00, 0x00, 0x00, 0x00 +}; +#endif + +#ifndef USE_PACKED_KEYCODE_LUT const bool ascii_to_altgr_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -61,6 +72,16 @@ const bool ascii_to_altgr_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0 }; +#else +const uint8_t ascii_to_altgr_lutp[16] PROGMEM = { + 0x00, 0x00, 0x00, 0x00, + + 0x10, 0x00, 0x00, 0x00, + 0x80, 0x00, 0x00, 0x1c, + 0x00, 0x00, 0x00, 0x1e +}; + +#endif const uint8_t ascii_to_keycode_lut[128] PROGMEM = { // NUL SOH STX ETX EOT ENQ ACK BEL diff --git a/quantum/keymap_extras/sendstring_uk.h b/quantum/keymap_extras/sendstring_uk.h index 982456e40ae7..c66386ba0ed1 100644 --- a/quantum/keymap_extras/sendstring_uk.h +++ b/quantum/keymap_extras/sendstring_uk.h @@ -22,6 +22,7 @@ // clang-format off +#ifndef USE_PACKED_KEYCODE_LUT const bool ascii_to_shift_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -41,6 +42,15 @@ const bool ascii_to_shift_lut[128] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0 }; +#else +const uint8_t ascii_to_shift_lutp[16] PROGMEM = { + 0x00, 0x00, 0x00, 0x00, + + 0x6e, 0xf0, 0x00, 0x2b, + 0xff, 0xff, 0xff, 0xe3, + 0x00, 0x00, 0x00, 0x1e +}; +#endif const uint8_t ascii_to_keycode_lut[128] PROGMEM = { // NUL SOH STX ETX EOT ENQ ACK BEL diff --git a/quantum/quantum.c b/quantum/quantum.c index 52062bb17482..82f510e77b6b 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -322,50 +322,111 @@ bool process_record_quantum(keyrecord_t *record) { return process_action_kb(record); } -__attribute__((weak)) const bool ascii_to_shift_lut[128] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}; - -__attribute__((weak)) const bool ascii_to_altgr_lut[128] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +/* Two versions of the keycode conversion: + * fast, but uses more flash + * not-as-fast, as requires a few instructions to do a lookup + */ // clang-format off -__attribute__((weak)) const uint8_t ascii_to_keycode_lut[128] PROGMEM = {// NUL SOH STX ETX EOT ENQ ACK BEL - XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, - // BS TAB LF VT FF CR SO SI - KC_BSPC, KC_TAB, KC_ENT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, - // DLE DC1 DC2 DC3 DC4 NAK SYN ETB - XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, - // CAN EM SUB ESC FS GS RS US - XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, - - // ! " # $ % & ' - KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT, - // ( ) * + , - . / - KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH, - // 0 1 2 3 4 5 6 7 - KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, - // 8 9 : ; < = > ? - KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH, - // @ A B C D E F G - KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G, - // H I J K L M N O - KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O, - // P Q R S T U V W - KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W, - // X Y Z [ \ ] ^ _ - KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS, - // ` a b c d e f g - KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G, - // h i j k l m n o - KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O, - // p q r s t u v w - KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W, - // x y z { | } ~ DEL - KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL}; +#ifndef USE_PACKED_KEYCODE_LUT +__attribute__((weak)) const bool ascii_to_shift_lut[128] PROGMEM = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 1, 1, 1, 1, 1, 1, 0, + 1, 1, 1, 1, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 1, 0, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 0, 0, 0, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 1, 1, 1, 0 +}; +#else +__attribute__((weak)) const uint8_t ascii_to_shift_lutp[16] PROGMEM = { + 0x00, 0x00, 0x00, 0x00, + + 0x7e, 0xf0, 0x00, 0x2b, + 0xff, 0xff, 0xff, 0xe3, + 0x00, 0x00, 0x00, 0x1e +}; +#endif + +#ifndef USE_PACKED_KEYCODE_LUT +__attribute__((weak)) const bool ascii_to_altgr_lut[128] PROGMEM = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 +}; +#else +__attribute__((weak)) const uint8_t ascii_to_altgr_lutp[16] PROGMEM = { + 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 +}; +#endif + +__attribute__((weak)) const uint8_t ascii_to_keycode_lut[128] PROGMEM = { + // NUL SOH STX ETX EOT ENQ ACK BEL + XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, + // BS TAB LF VT FF CR SO SI + KC_BSPC, KC_TAB, KC_ENT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, + // DLE DC1 DC2 DC3 DC4 NAK SYN ETB + XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, + // CAN EM SUB ESC FS GS RS US + XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, + + // ! " # $ % & ' + KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT, + // ( ) * + , - . / + KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH, + // 0 1 2 3 4 5 6 7 + KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, + // 8 9 : ; < = > ? + KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH, + // @ A B C D E F G + KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G, + // H I J K L M N O + KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O, + // P Q R S T U V W + KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W, + // X Y Z [ \ ] ^ _ + KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS, + // ` a b c d e f g + KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G, + // h i j k l m n o + KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O, + // p q r s t u v w + KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W, + // x y z { | } ~ DEL + KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL +}; // clang-format on +#define PGM_LOADBIT(mem, pos) ((pgm_read_byte(&((mem)[(pos) / 8])) >> (7 - ((pos) % 8))) & 0x01) + void send_string(const char *str) { send_string_with_delay(str, 0); } void send_string_P(const char *str) { send_string_with_delay_P(str, 0); } @@ -437,8 +498,13 @@ void send_char(char ascii_code) { #endif uint8_t keycode = pgm_read_byte(&ascii_to_keycode_lut[(uint8_t)ascii_code]); +#ifndef USE_PACKED_KEYCODE_LUT bool is_shifted = pgm_read_byte(&ascii_to_shift_lut[(uint8_t)ascii_code]); bool is_altgred = pgm_read_byte(&ascii_to_altgr_lut[(uint8_t)ascii_code]); +#else + bool is_shifted = PGM_LOADBIT(ascii_to_shift_lutp, (uint8_t)ascii_code); + bool is_altgred = PGM_LOADBIT(ascii_to_altgr_lutp, (uint8_t)ascii_code); +#endif if (is_shifted) { register_code(KC_LSFT); diff --git a/quantum/quantum.h b/quantum/quantum.h index fbd5e9079271..03ab0ad59fd3 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -207,8 +207,13 @@ typedef ioline_t pin_t; #define SEND_STRING(string) send_string_P(PSTR(string)) #define SEND_STRING_DELAY(string, interval) send_string_with_delay_P(PSTR(string), interval) +#ifndef USE_PACKED_KEYCODE_LUT extern const bool ascii_to_shift_lut[128]; extern const bool ascii_to_altgr_lut[128]; +#else +extern const uint8_t ascii_to_shift_lutp[16]; +extern const uint8_t ascii_to_altgr_lutp[16]; +#endif extern const uint8_t ascii_to_keycode_lut[128]; void send_string(const char *str); From 32537b78e7f56a3821bede352baee0a5a3adf75a Mon Sep 17 00:00:00 2001 From: Ted M Lin Date: Fri, 21 Feb 2020 17:08:02 -0500 Subject: [PATCH 2/5] Switch to macro and common definition Rewrite the array declarations so both the unpacked (original) and packed LUT arrays can use the same value definitions. This is done by defining a macro that "knows what to do". This makes the code much easier to read and maintain. --- quantum/keymap_extras/sendstring_belgian.h | 91 ++++++++++----------- quantum/keymap_extras/sendstring_bepo.h | 91 ++++++++++----------- quantum/keymap_extras/sendstring_french.h | 91 ++++++++++----------- quantum/keymap_extras/sendstring_german.h | 91 ++++++++++----------- quantum/keymap_extras/sendstring_jis.h | 46 +++++------ quantum/keymap_extras/sendstring_spanish.h | 92 ++++++++++----------- quantum/keymap_extras/sendstring_uk.h | 46 +++++------ quantum/quantum.c | 94 ++++++++++------------ quantum/quantum.h | 10 +++ 9 files changed, 299 insertions(+), 353 deletions(-) diff --git a/quantum/keymap_extras/sendstring_belgian.h b/quantum/keymap_extras/sendstring_belgian.h index 4fc952e09f2d..c0a48933faa1 100644 --- a/quantum/keymap_extras/sendstring_belgian.h +++ b/quantum/keymap_extras/sendstring_belgian.h @@ -19,68 +19,59 @@ #pragma once #include "keymap_belgian.h" +#include "quantum.h" // clang-format off #ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_shift_lut[128] PROGMEM = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 0, 0, 0, 0, 1, 0, 0, - 0, 0, 1, 1, 0, 0, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 0, 0, 0, 0, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 -}; +const bool ascii_to_shift_lut[128] PROGMEM = #else -const uint8_t ascii_to_shift_lutp[16] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, +const uint8_t ascii_to_shift_lutp[16] PROGMEM = +#endif +{ + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), - 0x04, 0x33, 0xff, 0xc3, - 0x7f, 0xff, 0xff, 0xe1, - 0x00, 0x00, 0x00, 0x00 + KCLUT_ENTRY(0, 0, 0, 0, 0, 1, 0, 0), + KCLUT_ENTRY(0, 0, 1, 1, 0, 0, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 0, 0, 0, 0, 1, 1), + KCLUT_ENTRY(0, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 0, 0, 0, 0, 1), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), }; -#endif #ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_altgr_lut[128] PROGMEM = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 0, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 0, - 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 0 -}; +const bool ascii_to_altgr_lut[128] PROGMEM = #else -const uint8_t ascii_to_altgr_lutp[16] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, +const uint8_t ascii_to_altgr_lutp[16] PROGMEM = +#endif +{ + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), - 0x10, 0x00, 0x00, 0x00, - 0x80, 0x00, 0x00, 0x1e, - 0x80, 0x00, 0x00, 0x1e + KCLUT_ENTRY(0, 0, 0, 1, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(1, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 1, 0), + KCLUT_ENTRY(1, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 1, 0), }; -#endif const uint8_t ascii_to_keycode_lut[128] PROGMEM = { // NUL SOH STX ETX EOT ENQ ACK BEL diff --git a/quantum/keymap_extras/sendstring_bepo.h b/quantum/keymap_extras/sendstring_bepo.h index e3f4b2055317..68c37b8f1441 100644 --- a/quantum/keymap_extras/sendstring_bepo.h +++ b/quantum/keymap_extras/sendstring_bepo.h @@ -19,68 +19,59 @@ #pragma once #include "keymap_bepo.h" +#include "quantum.h" // clang-format off #ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_shift_lut[128] PROGMEM = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 1, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 0, 0, 0, 1, - 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 -}; +const bool ascii_to_shift_lut[128] PROGMEM = #else -const uint8_t ascii_to_shift_lutp[16] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, +const uint8_t ascii_to_shift_lutp[16] PROGMEM = +#endif +{ + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), - 0x50, 0x00, 0xff, 0xf1, - 0x7f, 0xff, 0xff, 0xe0, - 0x80, 0x00, 0x00, 0x00 + KCLUT_ENTRY(0, 1, 0, 1, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 0, 0, 0, 1), + KCLUT_ENTRY(0, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 0, 0, 0, 0, 0), + KCLUT_ENTRY(1, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), }; -#endif #ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_altgr_lut[128] PROGMEM = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 0 -}; +const bool ascii_to_altgr_lut[128] PROGMEM = #else -const uint8_t ascii_to_altgr_lutp[16] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, +const uint8_t ascii_to_altgr_lutp[16] PROGMEM = +#endif +{ + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), - 0x02, 0x00, 0x00, 0x0a, - 0x00, 0x00, 0x00, 0x1f, - 0x00, 0x00, 0x00, 0x1e + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 1, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 1, 0, 1, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 1, 1), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 1, 0), }; -#endif const uint8_t ascii_to_keycode_lut[128] PROGMEM = { // NUL SOH STX ETX EOT ENQ ACK BEL diff --git a/quantum/keymap_extras/sendstring_french.h b/quantum/keymap_extras/sendstring_french.h index d550f1e72d14..0a95a946eb9b 100644 --- a/quantum/keymap_extras/sendstring_french.h +++ b/quantum/keymap_extras/sendstring_french.h @@ -19,68 +19,59 @@ #pragma once #include "keymap_french.h" +#include "quantum.h" // clang-format off #ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_shift_lut[128] PROGMEM = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 0, 0, 0, 0, 1, 0, 0, - 0, 0, 0, 1, 0, 0, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 0, 0, 0, 0, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 -}; +const bool ascii_to_shift_lut[128] PROGMEM = #else -const uint8_t ascii_to_shift_lutp[16] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, +const uint8_t ascii_to_shift_lutp[16] PROGMEM = +#endif +{ + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), - 0x04, 0x13, 0xff, 0xc3, - 0x7f, 0xff, 0xff, 0xe0, - 0x00, 0x00, 0x00, 0x00 + KCLUT_ENTRY(0, 0, 0, 0, 0, 1, 0, 0), + KCLUT_ENTRY(0, 0, 0, 1, 0, 0, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 0, 0, 0, 0, 1, 1), + KCLUT_ENTRY(0, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), }; -#endif #ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_altgr_lut[128] PROGMEM = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 0, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 0, - 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 0 -}; +const bool ascii_to_altgr_lut[128] PROGMEM = #else -const uint8_t ascii_to_altgr_lutp[16] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, +const uint8_t ascii_to_altgr_lutp[16] PROGMEM = +#endif +{ + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), - 0x10, 0x00, 0x00, 0x00, - 0x80, 0x00, 0x00, 0x1e, - 0x80, 0x00, 0x00, 0x1e + KCLUT_ENTRY(0, 0, 0, 1, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(1, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 1, 0), + KCLUT_ENTRY(1, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 1, 0), }; -#endif const uint8_t ascii_to_keycode_lut[128] PROGMEM = { // NUL SOH STX ETX EOT ENQ ACK BEL diff --git a/quantum/keymap_extras/sendstring_german.h b/quantum/keymap_extras/sendstring_german.h index 3c8a93440656..79c3baf4f6d8 100644 --- a/quantum/keymap_extras/sendstring_german.h +++ b/quantum/keymap_extras/sendstring_german.h @@ -19,68 +19,59 @@ #pragma once #include "keymap_german.h" +#include "quantum.h" // clang-format off #ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_shift_lut[128] PROGMEM = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 1, 1, 0, 1, 1, 1, 1, - 1, 1, 1, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 1, 0, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 0, 0, 0, 0, 1, - 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 -}; +const bool ascii_to_shift_lut[128] PROGMEM = #else -const uint8_t ascii_to_shift_lutp[16] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, +const uint8_t ascii_to_shift_lutp[16] PROGMEM = +#endif +{ + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), - 0x6f, 0xe1, 0x00, 0x37, - 0x7f, 0xff, 0xff, 0xe1, - 0x80, 0x00, 0x00, 0x00 + KCLUT_ENTRY(0, 1, 1, 0, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 0, 0, 0, 0, 1), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 1, 1, 0, 1, 1, 1), + KCLUT_ENTRY(0, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 0, 0, 0, 0, 1), + KCLUT_ENTRY(1, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), }; -#endif #ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_altgr_lut[128] PROGMEM = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 0 -}; +const bool ascii_to_altgr_lut[128] PROGMEM = #else -const uint8_t ascii_to_altgr_lutp[16] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, +const uint8_t ascii_to_altgr_lutp[16] PROGMEM = +#endif +{ + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), - 0x00, 0x00, 0x00, 0x00, - 0x80, 0x00, 0x00, 0x1c, - 0x00, 0x00, 0x00, 0x1e + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(1, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 1, 0), }; -#endif const uint8_t ascii_to_keycode_lut[128] PROGMEM = { // NUL SOH STX ETX EOT ENQ ACK BEL diff --git a/quantum/keymap_extras/sendstring_jis.h b/quantum/keymap_extras/sendstring_jis.h index 51b7ac30daaa..6009254656e6 100644 --- a/quantum/keymap_extras/sendstring_jis.h +++ b/quantum/keymap_extras/sendstring_jis.h @@ -19,38 +19,34 @@ #pragma once #include "keymap_jp.h" +#include "quantum.h" // clang-format off #ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_shift_lut[128] PROGMEM = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 0, 0, 0, 0, 1, - 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 0 -}; +const bool ascii_to_shift_lut[128] PROGMEM = #else -const uint8_t ascii_to_shift_lutp[16] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, +const uint8_t ascii_to_shift_lutp[16] PROGMEM = +#endif +{ + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), - 0x7f, 0xf0, 0x00, 0x0f, - 0x7f, 0xff, 0xff, 0xe1, - 0x80, 0x00, 0x00, 0x1e + KCLUT_ENTRY(0, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 1, 1, 1, 1), + KCLUT_ENTRY(0, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 0, 0, 0, 0, 1), + KCLUT_ENTRY(1, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 1, 0), }; -#endif const uint8_t ascii_to_keycode_lut[128] PROGMEM = { // NUL SOH STX ETX EOT ENQ ACK BEL diff --git a/quantum/keymap_extras/sendstring_spanish.h b/quantum/keymap_extras/sendstring_spanish.h index dcd237aa2014..357f54af0b57 100644 --- a/quantum/keymap_extras/sendstring_spanish.h +++ b/quantum/keymap_extras/sendstring_spanish.h @@ -19,70 +19,60 @@ #pragma once #include "keymap_spanish.h" +#include "quantum.h" // clang-format off #ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_shift_lut[128] PROGMEM = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 1, 1, 0, 1, 1, 1, 0, - 1, 1, 1, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 1, 0, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 0, 0, 0, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 -}; +const bool ascii_to_shift_lut[128] PROGMEM = #else -const uint8_t ascii_to_shift_lutp[16] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, +const uint8_t ascii_to_shift_lutp[16] PROGMEM = +#endif +{ + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), - 0x6e, 0xe1, 0x00, 0x37, - 0x7f, 0xff, 0xff, 0xe3, - 0x00, 0x00, 0x00, 0x00 + KCLUT_ENTRY(0, 1, 1, 0, 1, 1, 1, 0), + KCLUT_ENTRY(1, 1, 1, 0, 0, 0, 0, 1), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 1, 1, 0, 1, 1, 1), + KCLUT_ENTRY(0, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 0, 0, 0, 1, 1), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), }; -#endif #ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_altgr_lut[128] PROGMEM = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 0, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 0 -}; +const bool ascii_to_altgr_lut[128] PROGMEM = #else -const uint8_t ascii_to_altgr_lutp[16] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, +const uint8_t ascii_to_altgr_lutp[16] PROGMEM = +#endif +{ + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), - 0x10, 0x00, 0x00, 0x00, - 0x80, 0x00, 0x00, 0x1c, - 0x00, 0x00, 0x00, 0x1e + KCLUT_ENTRY(0, 0, 0, 1, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(1, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 1, 0), }; -#endif - const uint8_t ascii_to_keycode_lut[128] PROGMEM = { // NUL SOH STX ETX EOT ENQ ACK BEL XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, diff --git a/quantum/keymap_extras/sendstring_uk.h b/quantum/keymap_extras/sendstring_uk.h index c66386ba0ed1..b78cf2c0e3ef 100644 --- a/quantum/keymap_extras/sendstring_uk.h +++ b/quantum/keymap_extras/sendstring_uk.h @@ -19,38 +19,34 @@ #pragma once #include "keymap_uk.h" +#include "quantum.h" // clang-format off #ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_shift_lut[128] PROGMEM = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 1, 1, 0, 1, 1, 1, 0, - 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 0, 1, 0, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 0, 0, 0, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 0 -}; +const bool ascii_to_shift_lut[128] PROGMEM = #else -const uint8_t ascii_to_shift_lutp[16] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, +const uint8_t ascii_to_shift_lutp[16] PROGMEM = +#endif +{ + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), - 0x6e, 0xf0, 0x00, 0x2b, - 0xff, 0xff, 0xff, 0xe3, - 0x00, 0x00, 0x00, 0x1e + KCLUT_ENTRY(0, 1, 1, 0, 1, 1, 1, 0), + KCLUT_ENTRY(1, 1, 1, 1, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 1, 0, 1, 0, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 0, 0, 0, 1, 1), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 1, 0), }; -#endif const uint8_t ascii_to_keycode_lut[128] PROGMEM = { // NUL SOH STX ETX EOT ENQ ACK BEL diff --git a/quantum/quantum.c b/quantum/quantum.c index 82f510e77b6b..452596bfe265 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -329,64 +329,54 @@ bool process_record_quantum(keyrecord_t *record) { // clang-format off #ifndef USE_PACKED_KEYCODE_LUT -__attribute__((weak)) const bool ascii_to_shift_lut[128] PROGMEM = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 1, 1, 1, 1, 1, 1, 0, - 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 0, 1, 0, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 0, 0, 0, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 0 -}; +__attribute__((weak)) const bool ascii_to_shift_lut[128] PROGMEM = #else -__attribute__((weak)) const uint8_t ascii_to_shift_lutp[16] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, - - 0x7e, 0xf0, 0x00, 0x2b, - 0xff, 0xff, 0xff, 0xe3, - 0x00, 0x00, 0x00, 0x1e +__attribute__((weak)) const uint8_t ascii_to_shift_lutp[16] PROGMEM = +#endif +{ + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + + KCLUT_ENTRY(0, 1, 1, 1, 1, 1, 1, 0), + KCLUT_ENTRY(1, 1, 1, 1, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 1, 0, 1, 0, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 0, 0, 0, 1, 1), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 1, 0), }; -#endif #ifndef USE_PACKED_KEYCODE_LUT -__attribute__((weak)) const bool ascii_to_altgr_lut[128] PROGMEM = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 -}; +__attribute__((weak)) const bool ascii_to_altgr_lut[128] PROGMEM = #else -__attribute__((weak)) const uint8_t ascii_to_altgr_lutp[16] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, - - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 +__attribute__((weak)) const uint8_t ascii_to_altgr_lutp[16] PROGMEM = +#endif +{ + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), }; -#endif __attribute__((weak)) const uint8_t ascii_to_keycode_lut[128] PROGMEM = { // NUL SOH STX ETX EOT ENQ ACK BEL diff --git a/quantum/quantum.h b/quantum/quantum.h index 03ab0ad59fd3..68ebe1cde824 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -210,9 +210,19 @@ typedef ioline_t pin_t; #ifndef USE_PACKED_KEYCODE_LUT extern const bool ascii_to_shift_lut[128]; extern const bool ascii_to_altgr_lut[128]; +#define KCLUT_ENTRY(a, b, c, d, e, f, g, h) (a), (b), (c), (d), (e), (f), (g), (h) #else extern const uint8_t ascii_to_shift_lutp[16]; extern const uint8_t ascii_to_altgr_lutp[16]; +#define KCLUT_ENTRY(a, b, c, d, e, f, g, h) \ + ( ((a) ? 1 : 0) << 7 \ + | ((a) ? 1 : 0) << 6 \ + | ((a) ? 1 : 0) << 5 \ + | ((a) ? 1 : 0) << 4 \ + | ((a) ? 1 : 0) << 3 \ + | ((a) ? 1 : 0) << 2 \ + | ((a) ? 1 : 0) << 1 \ + | ((a) ? 1 : 0) << 0 ) #endif extern const uint8_t ascii_to_keycode_lut[128]; From 90849ae48b5eca47394a73265d292cbf9fd7b352 Mon Sep 17 00:00:00 2001 From: Ted M Lin Date: Fri, 21 Feb 2020 21:12:47 -0500 Subject: [PATCH 3/5] Fix macro typos and improve perf Pack the bits in a more efficient order for extraction. And also fix the copy/paste error in the macro... --- quantum/quantum.c | 2 +- quantum/quantum.h | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/quantum/quantum.c b/quantum/quantum.c index 452596bfe265..c1a0afc7e496 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -415,7 +415,7 @@ __attribute__((weak)) const uint8_t ascii_to_keycode_lut[128] PROGMEM = { }; // clang-format on -#define PGM_LOADBIT(mem, pos) ((pgm_read_byte(&((mem)[(pos) / 8])) >> (7 - ((pos) % 8))) & 0x01) +#define PGM_LOADBIT(mem, pos) ((pgm_read_byte(&((mem)[(pos) / 8])) >> ((pos) % 8)) & 0x01) void send_string(const char *str) { send_string_with_delay(str, 0); } diff --git a/quantum/quantum.h b/quantum/quantum.h index 68ebe1cde824..84e712231d14 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -210,19 +210,21 @@ typedef ioline_t pin_t; #ifndef USE_PACKED_KEYCODE_LUT extern const bool ascii_to_shift_lut[128]; extern const bool ascii_to_altgr_lut[128]; -#define KCLUT_ENTRY(a, b, c, d, e, f, g, h) (a), (b), (c), (d), (e), (f), (g), (h) +# define KCLUT_ENTRY(a, b, c, d, e, f, g, h) (a), (b), (c), (d), (e), (f), (g), (h) #else extern const uint8_t ascii_to_shift_lutp[16]; extern const uint8_t ascii_to_altgr_lutp[16]; -#define KCLUT_ENTRY(a, b, c, d, e, f, g, h) \ - ( ((a) ? 1 : 0) << 7 \ - | ((a) ? 1 : 0) << 6 \ - | ((a) ? 1 : 0) << 5 \ - | ((a) ? 1 : 0) << 4 \ - | ((a) ? 1 : 0) << 3 \ - | ((a) ? 1 : 0) << 2 \ - | ((a) ? 1 : 0) << 1 \ - | ((a) ? 1 : 0) << 0 ) +// clang-format off +# define KCLUT_ENTRY(a, b, c, d, e, f, g, h) \ + ( ((a) ? 1 : 0) << 0 \ + | ((b) ? 1 : 0) << 1 \ + | ((c) ? 1 : 0) << 2 \ + | ((d) ? 1 : 0) << 3 \ + | ((e) ? 1 : 0) << 4 \ + | ((f) ? 1 : 0) << 5 \ + | ((g) ? 1 : 0) << 6 \ + | ((h) ? 1 : 0) << 7 ) +// clang-format on #endif extern const uint8_t ascii_to_keycode_lut[128]; From 258ed07f3143a998ac40b1dc02ed812fbe86da9f Mon Sep 17 00:00:00 2001 From: Ted M Lin Date: Fri, 21 Feb 2020 23:26:58 -0500 Subject: [PATCH 4/5] Switch fully to packed LUT Some minor reformatting. Compile tested all sendstring_xyz.h to make sure they were converted properly. Also checked that an unconverted version would generate a compile error. --- quantum/keymap_extras/sendstring_belgian.h | 14 +--- quantum/keymap_extras/sendstring_bepo.h | 14 +--- quantum/keymap_extras/sendstring_danish.h | 69 ++++++++++---------- quantum/keymap_extras/sendstring_french.h | 14 +--- quantum/keymap_extras/sendstring_german.h | 14 +--- quantum/keymap_extras/sendstring_jis.h | 7 +- quantum/keymap_extras/sendstring_spanish.h | 14 +--- quantum/keymap_extras/sendstring_turkish_f.h | 69 ++++++++++---------- quantum/keymap_extras/sendstring_turkish_q.h | 69 ++++++++++---------- quantum/keymap_extras/sendstring_uk.h | 7 +- quantum/quantum.c | 37 +++++------ quantum/quantum.h | 15 ++--- 12 files changed, 137 insertions(+), 206 deletions(-) diff --git a/quantum/keymap_extras/sendstring_belgian.h b/quantum/keymap_extras/sendstring_belgian.h index c0a48933faa1..ef5a2f049d9d 100644 --- a/quantum/keymap_extras/sendstring_belgian.h +++ b/quantum/keymap_extras/sendstring_belgian.h @@ -23,12 +23,7 @@ // clang-format off -#ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_shift_lut[128] PROGMEM = -#else -const uint8_t ascii_to_shift_lutp[16] PROGMEM = -#endif -{ +const uint8_t ascii_to_shift_lut[16] PROGMEM = { KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), @@ -48,12 +43,7 @@ const uint8_t ascii_to_shift_lutp[16] PROGMEM = KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), }; -#ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_altgr_lut[128] PROGMEM = -#else -const uint8_t ascii_to_altgr_lutp[16] PROGMEM = -#endif -{ +const uint8_t ascii_to_altgr_lut[16] PROGMEM = { KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), diff --git a/quantum/keymap_extras/sendstring_bepo.h b/quantum/keymap_extras/sendstring_bepo.h index 68c37b8f1441..f0cc88bd223a 100644 --- a/quantum/keymap_extras/sendstring_bepo.h +++ b/quantum/keymap_extras/sendstring_bepo.h @@ -23,12 +23,7 @@ // clang-format off -#ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_shift_lut[128] PROGMEM = -#else -const uint8_t ascii_to_shift_lutp[16] PROGMEM = -#endif -{ +const uint8_t ascii_to_shift_lut[16] PROGMEM = { KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), @@ -48,12 +43,7 @@ const uint8_t ascii_to_shift_lutp[16] PROGMEM = KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), }; -#ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_altgr_lut[128] PROGMEM = -#else -const uint8_t ascii_to_altgr_lutp[16] PROGMEM = -#endif -{ +const uint8_t ascii_to_altgr_lut[16] PROGMEM = { KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), diff --git a/quantum/keymap_extras/sendstring_danish.h b/quantum/keymap_extras/sendstring_danish.h index 3505a076bd30..43b6a56cf850 100644 --- a/quantum/keymap_extras/sendstring_danish.h +++ b/quantum/keymap_extras/sendstring_danish.h @@ -19,47 +19,48 @@ #pragma once #include "keymap_danish.h" +#include "quantum.h" // clang-format off -const bool ascii_to_shift_lut[128] PROGMEM = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, +const uint8_t ascii_to_shift_lut[16] PROGMEM = { + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), - 0, 1, 1, 1, 0, 1, 1, 0, - 1, 1, 1, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 1, 0, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 0, 0, 0, 1, 1, - 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 + KCLUT_ENTRY(0, 1, 1, 1, 0, 1, 1, 0), + KCLUT_ENTRY(1, 1, 1, 0, 0, 0, 0, 1), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 1, 1, 0, 1, 1, 1), + KCLUT_ENTRY(0, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 0, 0, 0, 1, 1), + KCLUT_ENTRY(1, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), }; -const bool ascii_to_altgr_lut[128] PROGMEM = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, +const uint8_t ascii_to_altgr_lut[16] PROGMEM = { + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), - 0, 0, 0, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 0 + KCLUT_ENTRY(0, 0, 0, 0, 1, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(1, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 1, 0), }; const uint8_t ascii_to_keycode_lut[128] PROGMEM = { diff --git a/quantum/keymap_extras/sendstring_french.h b/quantum/keymap_extras/sendstring_french.h index 0a95a946eb9b..04b65ee919d2 100644 --- a/quantum/keymap_extras/sendstring_french.h +++ b/quantum/keymap_extras/sendstring_french.h @@ -23,12 +23,7 @@ // clang-format off -#ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_shift_lut[128] PROGMEM = -#else -const uint8_t ascii_to_shift_lutp[16] PROGMEM = -#endif -{ +const uint8_t ascii_to_shift_lut[16] PROGMEM = { KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), @@ -48,12 +43,7 @@ const uint8_t ascii_to_shift_lutp[16] PROGMEM = KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), }; -#ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_altgr_lut[128] PROGMEM = -#else -const uint8_t ascii_to_altgr_lutp[16] PROGMEM = -#endif -{ +const uint8_t ascii_to_altgr_lut[16] PROGMEM = { KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), diff --git a/quantum/keymap_extras/sendstring_german.h b/quantum/keymap_extras/sendstring_german.h index 79c3baf4f6d8..1bbdcce2ca8d 100644 --- a/quantum/keymap_extras/sendstring_german.h +++ b/quantum/keymap_extras/sendstring_german.h @@ -23,12 +23,7 @@ // clang-format off -#ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_shift_lut[128] PROGMEM = -#else -const uint8_t ascii_to_shift_lutp[16] PROGMEM = -#endif -{ +const uint8_t ascii_to_shift_lut[16] PROGMEM = { KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), @@ -48,12 +43,7 @@ const uint8_t ascii_to_shift_lutp[16] PROGMEM = KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), }; -#ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_altgr_lut[128] PROGMEM = -#else -const uint8_t ascii_to_altgr_lutp[16] PROGMEM = -#endif -{ +const uint8_t ascii_to_altgr_lut[16] PROGMEM = { KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), diff --git a/quantum/keymap_extras/sendstring_jis.h b/quantum/keymap_extras/sendstring_jis.h index 6009254656e6..8b0dc99561c4 100644 --- a/quantum/keymap_extras/sendstring_jis.h +++ b/quantum/keymap_extras/sendstring_jis.h @@ -23,12 +23,7 @@ // clang-format off -#ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_shift_lut[128] PROGMEM = -#else -const uint8_t ascii_to_shift_lutp[16] PROGMEM = -#endif -{ +const uint8_t ascii_to_shift_lut[16] PROGMEM = { KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), diff --git a/quantum/keymap_extras/sendstring_spanish.h b/quantum/keymap_extras/sendstring_spanish.h index 357f54af0b57..70e67165396d 100644 --- a/quantum/keymap_extras/sendstring_spanish.h +++ b/quantum/keymap_extras/sendstring_spanish.h @@ -23,12 +23,7 @@ // clang-format off -#ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_shift_lut[128] PROGMEM = -#else -const uint8_t ascii_to_shift_lutp[16] PROGMEM = -#endif -{ +const uint8_t ascii_to_shift_lut[16] PROGMEM = { KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), @@ -48,12 +43,7 @@ const uint8_t ascii_to_shift_lutp[16] PROGMEM = KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), }; -#ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_altgr_lut[128] PROGMEM = -#else -const uint8_t ascii_to_altgr_lutp[16] PROGMEM = -#endif -{ +const uint8_t ascii_to_altgr_lut[16] PROGMEM = { KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), diff --git a/quantum/keymap_extras/sendstring_turkish_f.h b/quantum/keymap_extras/sendstring_turkish_f.h index 82dbbdbcb447..5eec73bdedb8 100644 --- a/quantum/keymap_extras/sendstring_turkish_f.h +++ b/quantum/keymap_extras/sendstring_turkish_f.h @@ -19,47 +19,48 @@ #pragma once #include "keymap_turkish_f.h" +#include "quantum.h" // clang-format off -const bool ascii_to_shift_lut[128] PROGMEM = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, +const uint8_t ascii_to_shift_lut[16] PROGMEM = { + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), - 0, 1, 1, 0, 1, 1, 1, 1, - 1, 1, 1, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 1, 0, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 0, 0, 0, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 + KCLUT_ENTRY(0, 1, 1, 0, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 1, 1, 0, 1, 1, 1), + KCLUT_ENTRY(0, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 0, 0, 0, 1, 1), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), }; -const bool ascii_to_altgr_lut[128] PROGMEM = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, +const uint8_t ascii_to_altgr_lut[16] PROGMEM = { + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), - 0, 0, 0, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 0 + KCLUT_ENTRY(0, 0, 0, 1, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(1, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 0, 0), + KCLUT_ENTRY(1, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 1, 0), }; const uint8_t ascii_to_keycode_lut[128] PROGMEM = { diff --git a/quantum/keymap_extras/sendstring_turkish_q.h b/quantum/keymap_extras/sendstring_turkish_q.h index 58505b84966d..97c990c12aa7 100644 --- a/quantum/keymap_extras/sendstring_turkish_q.h +++ b/quantum/keymap_extras/sendstring_turkish_q.h @@ -19,47 +19,48 @@ #pragma once #include "keymap_turkish_q.h" +#include "quantum.h" // clang-format off -const bool ascii_to_shift_lut[128] PROGMEM = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, +const uint8_t ascii_to_shift_lut[16] PROGMEM = { + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), - 0, 1, 0, 0, 0, 1, 1, 1, - 1, 1, 0, 1, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 1, 0, 1, 1, 1, - 0, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 0, 0, 0, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 + KCLUT_ENTRY(0, 1, 0, 0, 0, 1, 1, 1), + KCLUT_ENTRY(1, 1, 0, 1, 0, 0, 0, 1), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 1, 1, 0, 1, 1, 1), + KCLUT_ENTRY(0, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 1, 1, 1, 1, 1), + KCLUT_ENTRY(1, 1, 1, 0, 0, 0, 1, 1), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), }; -const bool ascii_to_altgr_lut[128] PROGMEM = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, +const uint8_t ascii_to_altgr_lut[16] PROGMEM = { + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), - 0, 0, 0, 1, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 0 + KCLUT_ENTRY(0, 0, 0, 1, 1, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(1, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 0, 0), + KCLUT_ENTRY(1, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), + KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 1, 0), }; const uint8_t ascii_to_keycode_lut[128] PROGMEM = { diff --git a/quantum/keymap_extras/sendstring_uk.h b/quantum/keymap_extras/sendstring_uk.h index b78cf2c0e3ef..733c5f8600e3 100644 --- a/quantum/keymap_extras/sendstring_uk.h +++ b/quantum/keymap_extras/sendstring_uk.h @@ -23,12 +23,7 @@ // clang-format off -#ifndef USE_PACKED_KEYCODE_LUT -const bool ascii_to_shift_lut[128] PROGMEM = -#else -const uint8_t ascii_to_shift_lutp[16] PROGMEM = -#endif -{ +const uint8_t ascii_to_shift_lut[16] PROGMEM = { KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), diff --git a/quantum/quantum.c b/quantum/quantum.c index c1a0afc7e496..abc61fe23412 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -322,17 +322,12 @@ bool process_record_quantum(keyrecord_t *record) { return process_action_kb(record); } -/* Two versions of the keycode conversion: - * fast, but uses more flash - * not-as-fast, as requires a few instructions to do a lookup - */ - // clang-format off -#ifndef USE_PACKED_KEYCODE_LUT -__attribute__((weak)) const bool ascii_to_shift_lut[128] PROGMEM = -#else -__attribute__((weak)) const uint8_t ascii_to_shift_lutp[16] PROGMEM = -#endif + +/* Bit-Packed look-up table to convert an ASCII character to whether + * [Shift] needs to be sent with the keycode. + */ +__attribute__((weak)) const uint8_t ascii_to_shift_lut[16] PROGMEM = { KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), @@ -353,11 +348,10 @@ __attribute__((weak)) const uint8_t ascii_to_shift_lutp[16] PROGMEM = KCLUT_ENTRY(0, 0, 0, 1, 1, 1, 1, 0), }; -#ifndef USE_PACKED_KEYCODE_LUT -__attribute__((weak)) const bool ascii_to_altgr_lut[128] PROGMEM = -#else -__attribute__((weak)) const uint8_t ascii_to_altgr_lutp[16] PROGMEM = -#endif +/* Bit-Packed look-up table to convert an ASCII character to whether + * [AltGr] needs to be sent with the keycode. + */ +__attribute__((weak)) const uint8_t ascii_to_altgr_lut[16] PROGMEM = { KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), @@ -378,6 +372,8 @@ __attribute__((weak)) const uint8_t ascii_to_altgr_lutp[16] PROGMEM = KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), }; +/* Look-up table to convert an ASCII character to a keycode. + */ __attribute__((weak)) const uint8_t ascii_to_keycode_lut[128] PROGMEM = { // NUL SOH STX ETX EOT ENQ ACK BEL XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, @@ -413,8 +409,10 @@ __attribute__((weak)) const uint8_t ascii_to_keycode_lut[128] PROGMEM = { // x y z { | } ~ DEL KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL }; + // clang-format on +// Note: we bit-pack in "reverse" order to optimize loading #define PGM_LOADBIT(mem, pos) ((pgm_read_byte(&((mem)[(pos) / 8])) >> ((pos) % 8)) & 0x01) void send_string(const char *str) { send_string_with_delay(str, 0); } @@ -488,13 +486,8 @@ void send_char(char ascii_code) { #endif uint8_t keycode = pgm_read_byte(&ascii_to_keycode_lut[(uint8_t)ascii_code]); -#ifndef USE_PACKED_KEYCODE_LUT - bool is_shifted = pgm_read_byte(&ascii_to_shift_lut[(uint8_t)ascii_code]); - bool is_altgred = pgm_read_byte(&ascii_to_altgr_lut[(uint8_t)ascii_code]); -#else - bool is_shifted = PGM_LOADBIT(ascii_to_shift_lutp, (uint8_t)ascii_code); - bool is_altgred = PGM_LOADBIT(ascii_to_altgr_lutp, (uint8_t)ascii_code); -#endif + bool is_shifted = PGM_LOADBIT(ascii_to_shift_lut, (uint8_t)ascii_code); + bool is_altgred = PGM_LOADBIT(ascii_to_altgr_lut, (uint8_t)ascii_code); if (is_shifted) { register_code(KC_LSFT); diff --git a/quantum/quantum.h b/quantum/quantum.h index 84e712231d14..1c24a4e87db2 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -207,15 +207,12 @@ typedef ioline_t pin_t; #define SEND_STRING(string) send_string_P(PSTR(string)) #define SEND_STRING_DELAY(string, interval) send_string_with_delay_P(PSTR(string), interval) -#ifndef USE_PACKED_KEYCODE_LUT -extern const bool ascii_to_shift_lut[128]; -extern const bool ascii_to_altgr_lut[128]; -# define KCLUT_ENTRY(a, b, c, d, e, f, g, h) (a), (b), (c), (d), (e), (f), (g), (h) -#else -extern const uint8_t ascii_to_shift_lutp[16]; -extern const uint8_t ascii_to_altgr_lutp[16]; +// Look-Up Tables (LUTs) to convert ASCII character to keycode sequence. +extern const uint8_t ascii_to_keycode_lut[128]; +extern const uint8_t ascii_to_shift_lut[16]; +extern const uint8_t ascii_to_altgr_lut[16]; // clang-format off -# define KCLUT_ENTRY(a, b, c, d, e, f, g, h) \ +#define KCLUT_ENTRY(a, b, c, d, e, f, g, h) \ ( ((a) ? 1 : 0) << 0 \ | ((b) ? 1 : 0) << 1 \ | ((c) ? 1 : 0) << 2 \ @@ -225,8 +222,6 @@ extern const uint8_t ascii_to_altgr_lutp[16]; | ((g) ? 1 : 0) << 6 \ | ((h) ? 1 : 0) << 7 ) // clang-format on -#endif -extern const uint8_t ascii_to_keycode_lut[128]; void send_string(const char *str); void send_string_with_delay(const char *str, uint8_t interval); From c533dee040e094b61d5cd570163742256face10c Mon Sep 17 00:00:00 2001 From: Ted M Lin Date: Mon, 2 Mar 2020 17:18:51 -0500 Subject: [PATCH 5/5] Apply whitespace suggestions from code review Co-Authored-By: Ryan --- quantum/quantum.c | 34 ++++++++++++++++------------------ quantum/quantum.h | 16 ++++++++-------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/quantum/quantum.c b/quantum/quantum.c index abc61fe23412..5de7625ad16a 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -327,8 +327,7 @@ bool process_record_quantum(keyrecord_t *record) { /* Bit-Packed look-up table to convert an ASCII character to whether * [Shift] needs to be sent with the keycode. */ -__attribute__((weak)) const uint8_t ascii_to_shift_lut[16] PROGMEM = -{ +__attribute__((weak)) const uint8_t ascii_to_shift_lut[16] PROGMEM = { KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), @@ -351,8 +350,7 @@ __attribute__((weak)) const uint8_t ascii_to_shift_lut[16] PROGMEM = /* Bit-Packed look-up table to convert an ASCII character to whether * [AltGr] needs to be sent with the keycode. */ -__attribute__((weak)) const uint8_t ascii_to_altgr_lut[16] PROGMEM = -{ +__attribute__((weak)) const uint8_t ascii_to_altgr_lut[16] PROGMEM = { KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), KCLUT_ENTRY(0, 0, 0, 0, 0, 0, 0, 0), @@ -378,36 +376,36 @@ __attribute__((weak)) const uint8_t ascii_to_keycode_lut[128] PROGMEM = { // NUL SOH STX ETX EOT ENQ ACK BEL XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, // BS TAB LF VT FF CR SO SI - KC_BSPC, KC_TAB, KC_ENT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, + KC_BSPC, KC_TAB, KC_ENT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, // DLE DC1 DC2 DC3 DC4 NAK SYN ETB XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, // CAN EM SUB ESC FS GS RS US - XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, + XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, // ! " # $ % & ' - KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT, + KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT, // ( ) * + , - . / - KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH, + KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH, // 0 1 2 3 4 5 6 7 - KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, + KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, // 8 9 : ; < = > ? - KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH, + KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH, // @ A B C D E F G - KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G, + KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G, // H I J K L M N O - KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O, + KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O, // P Q R S T U V W - KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W, + KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W, // X Y Z [ \ ] ^ _ - KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS, + KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS, // ` a b c d e f g - KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G, + KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G, // h i j k l m n o - KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O, + KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O, // p q r s t u v w - KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W, + KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W, // x y z { | } ~ DEL - KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL + KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL }; // clang-format on diff --git a/quantum/quantum.h b/quantum/quantum.h index 1c24a4e87db2..3a8a382b7bd0 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -213,14 +213,14 @@ extern const uint8_t ascii_to_shift_lut[16]; extern const uint8_t ascii_to_altgr_lut[16]; // clang-format off #define KCLUT_ENTRY(a, b, c, d, e, f, g, h) \ - ( ((a) ? 1 : 0) << 0 \ - | ((b) ? 1 : 0) << 1 \ - | ((c) ? 1 : 0) << 2 \ - | ((d) ? 1 : 0) << 3 \ - | ((e) ? 1 : 0) << 4 \ - | ((f) ? 1 : 0) << 5 \ - | ((g) ? 1 : 0) << 6 \ - | ((h) ? 1 : 0) << 7 ) + ( ((a) ? 1 : 0) << 0 \ + | ((b) ? 1 : 0) << 1 \ + | ((c) ? 1 : 0) << 2 \ + | ((d) ? 1 : 0) << 3 \ + | ((e) ? 1 : 0) << 4 \ + | ((f) ? 1 : 0) << 5 \ + | ((g) ? 1 : 0) << 6 \ + | ((h) ? 1 : 0) << 7 ) // clang-format on void send_string(const char *str);