summaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/action.c2
-rw-r--r--quantum/action_util.c57
-rw-r--r--quantum/action_util.h9
3 files changed, 52 insertions, 16 deletions
diff --git a/quantum/action.c b/quantum/action.c
index 349250472b..29822c39e9 100644
--- a/quantum/action.c
+++ b/quantum/action.c
@@ -925,7 +925,7 @@ __attribute__((weak)) void register_code(uint8_t code) {
// Force a new key press if the key is already pressed
// without this, keys with the same keycode, but different
// modifiers will be reported incorrectly, see issue #1708
- if (is_key_pressed(keyboard_report, code)) {
+ if (is_key_pressed(code)) {
del_key(code);
send_keyboard_report();
}
diff --git a/quantum/action_util.c b/quantum/action_util.c
index 909dea0595..52171b5050 100644
--- a/quantum/action_util.c
+++ b/quantum/action_util.c
@@ -35,6 +35,9 @@ static uint8_t suppressed_mods = 0;
// TODO: pointer variable is not needed
// report_keyboard_t keyboard_report = {};
report_keyboard_t *keyboard_report = &(report_keyboard_t){};
+#ifdef NKRO_ENABLE
+report_nkro_t *nkro_report = &(report_nkro_t){};
+#endif
extern inline void add_key(uint8_t key);
extern inline void del_key(uint8_t key);
@@ -252,13 +255,8 @@ bool is_oneshot_enabled(void) {
#endif
-/** \brief Send keyboard report
- *
- * FIXME: needs doc
- */
-void send_keyboard_report(void) {
- keyboard_report->mods = real_mods;
- keyboard_report->mods |= weak_mods;
+static uint8_t get_mods_for_report(void) {
+ uint8_t mods = real_mods | weak_mods;
#ifndef NO_ACTION_ONESHOT
if (oneshot_mods) {
@@ -268,20 +266,25 @@ void send_keyboard_report(void) {
clear_oneshot_mods();
}
# endif
- keyboard_report->mods |= oneshot_mods;
- if (has_anykey(keyboard_report)) {
+ mods |= oneshot_mods;
+ if (has_anykey()) {
clear_oneshot_mods();
}
}
-
#endif
#ifdef KEY_OVERRIDE_ENABLE
// These need to be last to be able to properly control key overrides
- keyboard_report->mods &= ~suppressed_mods;
- keyboard_report->mods |= weak_override_mods;
+ mods &= ~suppressed_mods;
+ mods |= weak_override_mods;
#endif
+ return mods;
+}
+
+void send_6kro_report(void) {
+ keyboard_report->mods = get_mods_for_report();
+
#ifdef PROTOCOL_VUSB
host_keyboard_send(keyboard_report);
#else
@@ -295,6 +298,36 @@ void send_keyboard_report(void) {
#endif
}
+#ifdef NKRO_ENABLE
+void send_nkro_report(void) {
+ nkro_report->mods = get_mods_for_report();
+
+ static report_nkro_t last_report;
+
+ /* Only send the report if there are changes to propagate to the host. */
+ if (memcmp(nkro_report, &last_report, sizeof(report_nkro_t)) != 0) {
+ memcpy(&last_report, nkro_report, sizeof(report_nkro_t));
+ host_nkro_send(nkro_report);
+ }
+}
+#endif
+
+/** \brief Send keyboard report
+ *
+ * FIXME: needs doc
+ */
+void send_keyboard_report(void) {
+#ifdef NKRO_ENABLE
+ if (keyboard_protocol && keymap_config.nkro) {
+ send_nkro_report();
+ } else {
+ send_6kro_report();
+ }
+#else
+ send_6kro_report();
+#endif
+}
+
/** \brief Get mods
*
* FIXME: needs doc
diff --git a/quantum/action_util.h b/quantum/action_util.h
index 831caf3c0a..d2ecb145be 100644
--- a/quantum/action_util.h
+++ b/quantum/action_util.h
@@ -26,20 +26,23 @@ extern "C" {
#endif
extern report_keyboard_t *keyboard_report;
+#ifdef NKRO_ENABLE
+extern report_nkro_t *nkro_report;
+#endif
void send_keyboard_report(void);
/* key */
inline void add_key(uint8_t key) {
- add_key_to_report(keyboard_report, key);
+ add_key_to_report(key);
}
inline void del_key(uint8_t key) {
- del_key_from_report(keyboard_report, key);
+ del_key_from_report(key);
}
inline void clear_keys(void) {
- clear_keys_from_report(keyboard_report);
+ clear_keys_from_report();
}
/* modifier */