summaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2023-05-15 22:27:37 +1000
committerGitHub <noreply@github.com>2023-05-15 22:27:37 +1000
commit5faa23d54ca1e3ab83097f2a07922f48800616e6 (patch)
tree6ed05e5492f3fc8dda210a75b897dd9d4ed8df38 /quantum
parent433dc6068603e61d466e755aedcea0be96664f95 (diff)
Keymap introspection for combos. (#19670)
Diffstat (limited to 'quantum')
-rw-r--r--quantum/keymap_introspection.c21
-rw-r--r--quantum/keymap_introspection.h21
-rw-r--r--quantum/process_keycode/process_combo.c23
-rw-r--r--quantum/process_keycode/process_combo.h2
4 files changed, 51 insertions, 16 deletions
diff --git a/quantum/keymap_introspection.c b/quantum/keymap_introspection.c
index 977b949340..e4a01d2e9a 100644
--- a/quantum/keymap_introspection.c
+++ b/quantum/keymap_introspection.c
@@ -70,3 +70,24 @@ __attribute__((weak)) uint16_t keycode_at_encodermap_location(uint8_t layer_num,
}
#endif // defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Combos
+
+#if defined(COMBO_ENABLE)
+
+uint16_t combo_count_raw(void) {
+ return sizeof(key_combos) / sizeof(combo_t);
+}
+__attribute__((weak)) uint16_t combo_count(void) {
+ return combo_count_raw();
+}
+
+combo_t* combo_get_raw(uint16_t combo_idx) {
+ return &key_combos[combo_idx];
+}
+__attribute__((weak)) combo_t* combo_get(uint16_t combo_idx) {
+ return combo_get_raw(combo_idx);
+}
+
+#endif // defined(COMBO_ENABLE)
diff --git a/quantum/keymap_introspection.h b/quantum/keymap_introspection.h
index 201de937cb..2012a2b8cc 100644
--- a/quantum/keymap_introspection.h
+++ b/quantum/keymap_introspection.h
@@ -34,3 +34,24 @@ uint16_t keycode_at_encodermap_location_raw(uint8_t layer_num, uint8_t encoder_i
uint16_t keycode_at_encodermap_location(uint8_t layer_num, uint8_t encoder_idx, bool clockwise);
#endif // defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Combos
+
+#if defined(COMBO_ENABLE)
+
+// Forward declaration of combo_t so we don't need to deal with header reordering
+struct combo_t;
+typedef struct combo_t combo_t;
+
+// Get the number of combos defined in the user's keymap, stored in firmware rather than any other persistent storage
+uint16_t combo_count_raw(void);
+// Get the number of combos defined in the user's keymap, potentially stored dynamically
+uint16_t combo_count(void);
+
+// Get the keycode for the encoder mapping location, stored in firmware rather than any other persistent storage
+combo_t* combo_get_raw(uint16_t combo_idx);
+// Get the keycode for the encoder mapping location, potentially stored dynamically
+combo_t* combo_get(uint16_t combo_idx);
+
+#endif // defined(COMBO_ENABLE)
diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c
index 2670ccabed..bbee560be9 100644
--- a/quantum/process_keycode/process_combo.c
+++ b/quantum/process_keycode/process_combo.c
@@ -19,14 +19,7 @@
#include "process_combo.h"
#include "action_tapping.h"
#include "action.h"
-
-#ifdef COMBO_COUNT
-__attribute__((weak)) combo_t key_combos[COMBO_COUNT];
-uint16_t COMBO_LEN = COMBO_COUNT;
-#else
-extern combo_t key_combos[];
-extern uint16_t COMBO_LEN;
-#endif
+#include "keymap_introspection.h"
__attribute__((weak)) void process_combo_event(uint16_t combo_index, bool pressed) {}
@@ -195,8 +188,8 @@ static inline uint16_t _get_combo_term(uint16_t combo_index, combo_t *combo) {
void clear_combos(void) {
uint16_t index = 0;
longest_term = 0;
- for (index = 0; index < COMBO_LEN; ++index) {
- combo_t *combo = &key_combos[index];
+ for (index = 0; index < combo_count(); ++index) {
+ combo_t *combo = combo_get(index);
if (!COMBO_ACTIVE(combo)) {
RESET_COMBO_STATE(combo);
}
@@ -287,7 +280,7 @@ void drop_combo_from_buffer(uint16_t combo_index) {
queued_combo_t *qcombo = &combo_buffer[i];
if (qcombo->combo_index == combo_index) {
- combo_t *combo = &key_combos[combo_index];
+ combo_t *combo = combo_get(combo_index);
DISABLE_COMBO(combo);
if (i == combo_buffer_read) {
@@ -354,7 +347,7 @@ static inline void apply_combos(void) {
// Apply all buffered normal combos.
for (uint8_t i = combo_buffer_read; i != combo_buffer_write; INCREMENT_MOD(i)) {
queued_combo_t *buffered_combo = &combo_buffer[i];
- combo_t * combo = &key_combos[buffered_combo->combo_index];
+ combo_t * combo = combo_get(buffered_combo->combo_index);
#ifdef COMBO_MUST_TAP_PER_COMBO
if (get_combo_must_tap(buffered_combo->combo_index, combo)) {
@@ -459,7 +452,7 @@ static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t *
combo_t *drop = NULL;
for (uint8_t combo_buffer_i = combo_buffer_read; combo_buffer_i != combo_buffer_write; INCREMENT_MOD(combo_buffer_i)) {
queued_combo_t *qcombo = &combo_buffer[combo_buffer_i];
- combo_t * buffered_combo = &key_combos[qcombo->combo_index];
+ combo_t * buffered_combo = combo_get(qcombo->combo_index);
if ((drop = overlaps(buffered_combo, combo))) {
DISABLE_COMBO(drop);
@@ -565,8 +558,8 @@ bool process_combo(uint16_t keycode, keyrecord_t *record) {
}
#endif
- for (uint16_t idx = 0; idx < COMBO_LEN; ++idx) {
- combo_t *combo = &key_combos[idx];
+ for (uint16_t idx = 0; idx < combo_count(); ++idx) {
+ combo_t *combo = combo_get(idx);
is_combo_key |= process_single_combo(combo, keycode, record, idx);
no_combo_keys_pressed = no_combo_keys_pressed && (NO_COMBO_KEYS_ARE_DOWN || COMBO_ACTIVE(combo) || COMBO_DISABLED(combo));
}
diff --git a/quantum/process_keycode/process_combo.h b/quantum/process_keycode/process_combo.h
index e430c4a5f7..bba5d5ee63 100644
--- a/quantum/process_keycode/process_combo.h
+++ b/quantum/process_keycode/process_combo.h
@@ -37,7 +37,7 @@
# define COMBO_BUFFER_LENGTH 4
#endif
-typedef struct {
+typedef struct combo_t {
const uint16_t *keys;
uint16_t keycode;
#ifdef EXTRA_SHORT_COMBOS