aboutsummaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/keymap_introspection.c43
-rw-r--r--quantum/keymap_introspection.h21
-rw-r--r--quantum/process_keycode/process_key_override.c10
-rw-r--r--quantum/process_keycode/process_key_override.h5
4 files changed, 64 insertions, 15 deletions
diff --git a/quantum/keymap_introspection.c b/quantum/keymap_introspection.c
index 4e95125335..327df6e277 100644
--- a/quantum/keymap_introspection.c
+++ b/quantum/keymap_introspection.c
@@ -10,6 +10,7 @@
#endif // INTROSPECTION_KEYMAP_C
#include "keymap_introspection.h"
+#include "util.h"
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Key mapping
@@ -83,7 +84,7 @@ uint16_t keycode_at_dip_switch_map_location_raw(uint8_t switch_idx, bool on) {
return KC_TRNS;
}
-uint16_t keycode_at_dip_switch_map_location(uint8_t switch_idx, bool on) {
+__attribute__((weak)) uint16_t keycode_at_dip_switch_map_location(uint8_t switch_idx, bool on) {
return keycode_at_dip_switch_map_location_raw(switch_idx, on);
}
@@ -95,13 +96,16 @@ uint16_t keycode_at_dip_switch_map_location(uint8_t switch_idx, bool on) {
#if defined(COMBO_ENABLE)
uint16_t combo_count_raw(void) {
- return sizeof(key_combos) / sizeof(combo_t);
+ return ARRAY_SIZE(key_combos);
}
__attribute__((weak)) uint16_t combo_count(void) {
return combo_count_raw();
}
combo_t* combo_get_raw(uint16_t combo_idx) {
+ if (combo_idx >= combo_count_raw()) {
+ return NULL;
+ }
return &key_combos[combo_idx];
}
__attribute__((weak)) combo_t* combo_get(uint16_t combo_idx) {
@@ -116,19 +120,48 @@ __attribute__((weak)) combo_t* combo_get(uint16_t combo_idx) {
#if defined(TAP_DANCE_ENABLE)
uint16_t tap_dance_count_raw(void) {
- return sizeof(tap_dance_actions) / sizeof(tap_dance_action_t);
+ return ARRAY_SIZE(tap_dance_actions);
}
-uint16_t tap_dance_count(void) {
+__attribute__((weak)) uint16_t tap_dance_count(void) {
return tap_dance_count_raw();
}
tap_dance_action_t* tap_dance_get_raw(uint16_t tap_dance_idx) {
+ if (tap_dance_idx >= tap_dance_count_raw()) {
+ return NULL;
+ }
return &tap_dance_actions[tap_dance_idx];
}
-tap_dance_action_t* tap_dance_get(uint16_t tap_dance_idx) {
+__attribute__((weak)) tap_dance_action_t* tap_dance_get(uint16_t tap_dance_idx) {
return tap_dance_get_raw(tap_dance_idx);
}
#endif // defined(TAP_DANCE_ENABLE)
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Key Overrides
+
+#if defined(KEY_OVERRIDE_ENABLE)
+
+uint16_t key_override_count_raw(void) {
+ return ARRAY_SIZE(key_overrides);
+}
+
+__attribute__((weak)) uint16_t key_override_count(void) {
+ return key_override_count_raw();
+}
+
+const key_override_t* key_override_get_raw(uint16_t key_override_idx) {
+ if (key_override_idx >= key_override_count_raw()) {
+ return NULL;
+ }
+ return key_overrides[key_override_idx];
+}
+
+__attribute__((weak)) const key_override_t* key_override_get(uint16_t key_override_idx) {
+ return key_override_get_raw(key_override_idx);
+}
+
+#endif // defined(KEY_OVERRIDE_ENABLE)
diff --git a/quantum/keymap_introspection.h b/quantum/keymap_introspection.h
index bc4dd93b4c..719825c674 100644
--- a/quantum/keymap_introspection.h
+++ b/quantum/keymap_introspection.h
@@ -88,3 +88,24 @@ tap_dance_action_t* tap_dance_get_raw(uint16_t tap_dance_idx);
tap_dance_action_t* tap_dance_get(uint16_t tap_dance_idx);
#endif // defined(TAP_DANCE_ENABLE)
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Key Overrides
+
+#if defined(KEY_OVERRIDE_ENABLE)
+
+// Forward declaration of key_override_t so we don't need to deal with header reordering
+struct key_override_t;
+typedef struct key_override_t key_override_t;
+
+// Get the number of key overrides defined in the user's keymap, stored in firmware rather than any other persistent storage
+uint16_t key_override_count_raw(void);
+// Get the number of key overrides defined in the user's keymap, potentially stored dynamically
+uint16_t key_override_count(void);
+
+// Get the key override definitions, stored in firmware rather than any other persistent storage
+const key_override_t* key_override_get_raw(uint16_t key_override_idx);
+// Get the key override definitions, potentially stored dynamically
+const key_override_t* key_override_get(uint16_t key_override_idx);
+
+#endif // defined(KEY_OVERRIDE_ENABLE)
diff --git a/quantum/process_keycode/process_key_override.c b/quantum/process_keycode/process_key_override.c
index 264e2562b8..ce30477ee8 100644
--- a/quantum/process_keycode/process_key_override.c
+++ b/quantum/process_keycode/process_key_override.c
@@ -23,6 +23,7 @@
#include "action_util.h"
#include "quantum.h"
#include "quantum_keycodes.h"
+#include "keymap_introspection.h"
#ifndef KEY_OVERRIDE_REPEAT_DELAY
# define KEY_OVERRIDE_REPEAT_DELAY 500
@@ -83,9 +84,6 @@ static uint16_t deferred_register = 0;
// TODO: in future maybe save in EEPROM?
static bool enabled = true;
-// Public variables
-__attribute__((weak)) const key_override_t **key_overrides = NULL;
-
// Forward decls
static const key_override_t *clear_active_override(const bool allow_reregister);
@@ -247,12 +245,12 @@ static bool check_activation_event(const key_override_t *override, const bool ke
/** Iterates through the list of key overrides and tries activating each, until it finds one that activates or reaches the end of overrides. Returns true if the key action for `keycode` should be sent */
static bool try_activating_override(const uint16_t keycode, const uint8_t layer, const bool key_down, const bool is_mod, const uint8_t active_mods, bool *activated) {
- if (key_overrides == NULL) {
+ if (key_override_count() == 0) {
return true;
}
- for (uint8_t i = 0;; i++) {
- const key_override_t *const override = key_overrides[i];
+ for (uint8_t i = 0; i < key_override_count(); i++) {
+ const key_override_t *const override = key_override_get(i);
// End of array
if (override == NULL) {
diff --git a/quantum/process_keycode/process_key_override.h b/quantum/process_keycode/process_key_override.h
index 3e37c7e63a..9ec84dbe6e 100644
--- a/quantum/process_keycode/process_key_override.h
+++ b/quantum/process_keycode/process_key_override.h
@@ -55,7 +55,7 @@ typedef enum {
} ko_option_t;
/** Defines a single key override */
-typedef struct {
+typedef struct key_override_t {
// The non-modifier keycode that triggers the override. This keycode, and the necessary modifiers (trigger_mods) must be pressed to activate this override. Set this to the keycode of the key that should activate the override. Set to KC_NO to require only the necessary modifiers to be pressed and no non-modifier.
uint16_t trigger;
@@ -87,9 +87,6 @@ typedef struct {
bool *enabled;
} key_override_t;
-/** Define this as a null-terminated array of pointers to key overrides. These key overrides will be used by qmk. */
-extern const key_override_t **key_overrides;
-
/** Turns key overrides on */
void key_override_on(void);