From 54b14e8a7fba08a30d510312f77d78083d531576 Mon Sep 17 00:00:00 2001 From: Ilya Zhuravlev Date: Mon, 3 Jan 2022 08:51:14 -0500 Subject: [PATCH] dynamic_keymap: support vial 2-byte macros --- quantum/dynamic_keymap.c | 28 ++++++++++++++++++++++++++++ quantum/vial.c | 8 +++----- quantum/vial.h | 8 ++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/quantum/dynamic_keymap.c b/quantum/dynamic_keymap.c index 12df47244a..5a183339c1 100644 --- a/quantum/dynamic_keymap.c +++ b/quantum/dynamic_keymap.c @@ -480,6 +480,13 @@ void dynamic_keymap_macro_reset(void) { } } +static uint16_t decode_keycode(uint16_t kc) { + /* map 0xFF01 => 0x0100; 0xFF02 => 0x0200, etc */ + if (kc > 0xFF00) + return (kc & 0xFF) << 8; + return kc; +} + void dynamic_keymap_macro_send(uint8_t id) { if (id >= DYNAMIC_KEYMAP_MACRO_COUNT) { return; @@ -534,6 +541,27 @@ void dynamic_keymap_macro_send(uint8_t id) { data[2] = eeprom_read_byte(p++); if (data[2] != 0) send_string(data); + } else if (data[1] == VIAL_MACRO_EXT_TAP || data[1] == VIAL_MACRO_EXT_DOWN || data[1] == VIAL_MACRO_EXT_UP) { + data[2] = eeprom_read_byte(p++); + if (data[2] != 0) { + data[3] = eeprom_read_byte(p++); + if (data[3] != 0) { + uint16_t kc; + memcpy(&kc, &data[2], sizeof(kc)); + kc = decode_keycode(kc); + switch (data[1]) { + case VIAL_MACRO_EXT_TAP: + vial_keycode_tap(kc); + break; + case VIAL_MACRO_EXT_DOWN: + vial_keycode_down(kc); + break; + case VIAL_MACRO_EXT_UP: + vial_keycode_up(kc); + break; + } + } + } } else if (data[1] == SS_DELAY_CODE) { // For delay, decode the delay and wait_ms for that amount uint8_t d0 = eeprom_read_byte(p++); diff --git a/quantum/vial.c b/quantum/vial.c index 6684cc856c..b67c168737 100644 --- a/quantum/vial.c +++ b/quantum/vial.c @@ -284,7 +284,7 @@ void vial_handle_cmd(uint8_t *msg, uint8_t length) { uint16_t g_vial_magic_keycode_override; -static void vial_keycode_down(uint16_t keycode) { +void vial_keycode_down(uint16_t keycode) { g_vial_magic_keycode_override = keycode; if (keycode <= QK_MODS_MAX) { @@ -296,7 +296,7 @@ static void vial_keycode_down(uint16_t keycode) { } } -static void vial_keycode_up(uint16_t keycode) { +void vial_keycode_up(uint16_t keycode) { g_vial_magic_keycode_override = keycode; if (keycode <= QK_MODS_MAX) { @@ -308,9 +308,7 @@ static void vial_keycode_up(uint16_t keycode) { } } -static void vial_keycode_tap(uint16_t keycode) __attribute__((unused)); - -static void vial_keycode_tap(uint16_t keycode) { +void vial_keycode_tap(uint16_t keycode) { vial_keycode_down(keycode); qs_wait_ms(QS_tap_code_delay); vial_keycode_up(keycode); diff --git a/quantum/vial.h b/quantum/vial.h index feb074ee39..f7add46348 100644 --- a/quantum/vial.h +++ b/quantum/vial.h @@ -63,6 +63,14 @@ enum { dynamic_vial_key_override_set = 0x06, }; +#define VIAL_MACRO_EXT_TAP 5 +#define VIAL_MACRO_EXT_DOWN 6 +#define VIAL_MACRO_EXT_UP 7 + +void vial_keycode_down(uint16_t keycode); +void vial_keycode_up(uint16_t keycode); +void vial_keycode_tap(uint16_t keycode); + /* Fake position in keyboard matrix, can't use 255 as that is immediately rejected by IS_NOEVENT used to send arbitrary keycodes thru process_record_quantum_helper */ #define VIAL_MATRIX_MAGIC 254