summaryrefslogtreecommitdiff
path: root/quantum/action_util.c
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2023-10-23 14:43:46 +1000
committerGitHub <noreply@github.com>2023-10-23 15:43:46 +1100
commit0c160e1fbafbf477c74e64fd8ab9a9121eb0f42a (patch)
tree7a6e361a5fe396b72029ab03d7e00abe1f19a105 /quantum/action_util.c
parentbf6f13a2b0a185e935b8554e41317ab471a4c0ec (diff)
Separate 6KRO and NKRO report structs (#22267)
Diffstat (limited to 'quantum/action_util.c')
-rw-r--r--quantum/action_util.c57
1 files changed, 45 insertions, 12 deletions
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