From d5d40132a34eae776ee90a801e7690469298b116 Mon Sep 17 00:00:00 2001 From: Ilya Zhuravlev Date: Sun, 12 Sep 2021 14:38:17 -0400 Subject: [PATCH] vial: restore dynamic combo functionality --- common_features.mk | 2 +- quantum/process_keycode/process_combo.c | 8 +++++- quantum/qmk_settings.c | 4 +++ quantum/vial.c | 34 +++++++++++++------------ 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/common_features.mk b/common_features.mk index a009a44ecb..60e968fdc2 100644 --- a/common_features.mk +++ b/common_features.mk @@ -522,7 +522,7 @@ ifeq ($(strip $(QMK_SETTINGS)), yes) endif AUTO_SHIFT_ENABLE := yes SRC += $(QUANTUM_DIR)/qmk_settings.c - OPT_DEFS += -DQMK_SETTINGS -DAUTO_SHIFT_NO_SETUP -DTAPPING_TERM_PER_KEY -DPERMISSIVE_HOLD_PER_KEY -DIGNORE_MOD_TAP_INTERRUPT_PER_KEY -DTAPPING_FORCE_HOLD_PER_KEY -DRETRO_TAPPING_PER_KEY + OPT_DEFS += -DQMK_SETTINGS -DAUTO_SHIFT_NO_SETUP -DTAPPING_TERM_PER_KEY -DPERMISSIVE_HOLD_PER_KEY -DIGNORE_MOD_TAP_INTERRUPT_PER_KEY -DTAPPING_FORCE_HOLD_PER_KEY -DRETRO_TAPPING_PER_KEY -DCOMBO_TERM_PER_COMBO endif ifeq ($(strip $(DIP_SWITCH_ENABLE)), yes) diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index e8661839c7..1c884d1e6f 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c @@ -18,6 +18,12 @@ #include "process_combo.h" #include "action_tapping.h" +#ifdef VIAL_COMBO_ENABLE +#include "dynamic_keymap.h" +/* dynamic combos are stored entirely in ram */ +#undef pgm_read_word +#define pgm_read_word(address_short) *((uint16_t*)(address_short)) +#endif #ifdef COMBO_COUNT __attribute__((weak)) combo_t key_combos[COMBO_COUNT]; @@ -212,8 +218,8 @@ static inline void dump_key_buffer(void) { static inline void _find_key_index_and_count(const uint16_t *keys, uint16_t keycode, uint16_t *key_index, uint8_t *key_count) { while (true) { uint16_t key = pgm_read_word(&keys[*key_count]); - if (keycode == key) *key_index = *key_count; if (COMBO_END == key) break; + if (keycode == key) *key_index = *key_count; (*key_count)++; } } diff --git a/quantum/qmk_settings.c b/quantum/qmk_settings.c index 8e273e65fc..d630dcbe43 100644 --- a/quantum/qmk_settings.c +++ b/quantum/qmk_settings.c @@ -175,3 +175,7 @@ bool get_tapping_force_hold(uint16_t keycode, keyrecord_t *record) { bool get_retro_tapping(uint16_t keycode, keyrecord_t *record) { return QS.tapping & 8; } + +uint16_t get_combo_term(uint16_t index, combo_t *combo) { + return QS.combo_term; +} diff --git a/quantum/vial.c b/quantum/vial.c index 8a43c01423..23968e0093 100644 --- a/quantum/vial.c +++ b/quantum/vial.c @@ -55,7 +55,7 @@ static void reload_tap_dance(void); #endif #ifdef VIAL_COMBO_ENABLE -static void init_combo(void); +static void reload_combo(void); #endif void vial_init(void) { @@ -63,7 +63,7 @@ void vial_init(void) { reload_tap_dance(); #endif #ifdef VIAL_COMBO_ENABLE - init_combo(); + reload_combo(); #endif } @@ -246,6 +246,7 @@ void vial_handle_cmd(uint8_t *msg, uint8_t length) { vial_combo_entry_t entry; memcpy(&entry, &msg[4], sizeof(entry)); msg[0] = dynamic_keymap_set_combo(idx, &entry); + reload_combo(); break; } #endif @@ -493,22 +494,23 @@ static void reload_tap_dance(void) { #ifdef VIAL_COMBO_ENABLE combo_t key_combos[VIAL_COMBO_ENTRIES]; +uint16_t key_combos_keys[VIAL_COMBO_ENTRIES][5]; -static void init_combo(void) { +static void reload_combo(void) { + /* initialize with all keys = COMBO_END */ + memset(key_combos_keys, 0, sizeof(key_combos_keys)); + memset(key_combos, 0, sizeof(key_combos)); + + /* reload from eeprom */ for (size_t i = 0; i < VIAL_COMBO_ENTRIES; ++i) { - key_combos[i].keys = (void*)(uintptr_t)i; + uint16_t *seq = key_combos_keys[i]; + key_combos[i].keys = seq; + + vial_combo_entry_t entry; + if (dynamic_keymap_get_combo(i, &entry) == 0) { + memcpy(seq, entry.input, sizeof(entry.input)); + key_combos[i].keycode = entry.output; + } } } - -void process_combo_event(uint16_t combo_index, bool pressed) { - vial_combo_entry_t entry; - if (dynamic_keymap_get_combo(combo_index, &entry) != 0) - return; - - if (pressed) - vial_keycode_down(entry.output); - else - vial_keycode_up(entry.output); -} - #endif