aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/protocol/report.c
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2024-11-27 21:29:12 +1100
committerNick Brassel <nick@tzarc.org>2024-11-27 21:29:12 +1100
commit9f76541b29056150cf57d69569a14a59e13995c7 (patch)
tree66c7398d873fcda88aebe3090603aefe045ff52e /tmk_core/protocol/report.c
parent57be4871616ee9a8fe042f6186010d436ec7d4b1 (diff)
parenteb04b94eecbb9b3e64ca9c74f937b5f762440b17 (diff)
Merge branch 'develop'
Diffstat (limited to 'tmk_core/protocol/report.c')
-rw-r--r--tmk_core/protocol/report.c106
1 files changed, 7 insertions, 99 deletions
diff --git a/tmk_core/protocol/report.c b/tmk_core/protocol/report.c
index 0166bf654f..6203a3116b 100644
--- a/tmk_core/protocol/report.c
+++ b/tmk_core/protocol/report.c
@@ -19,19 +19,10 @@
#include "host.h"
#include "keycode_config.h"
#include "debug.h"
+#include "usb_device_state.h"
#include "util.h"
#include <string.h>
-#ifdef RING_BUFFERED_6KRO_REPORT_ENABLE
-# define RO_ADD(a, b) ((a + b) % KEYBOARD_REPORT_KEYS)
-# define RO_SUB(a, b) ((a - b + KEYBOARD_REPORT_KEYS) % KEYBOARD_REPORT_KEYS)
-# define RO_INC(a) RO_ADD(a, 1)
-# define RO_DEC(a) RO_SUB(a, 1)
-static int8_t cb_head = 0;
-static int8_t cb_tail = 0;
-static int8_t cb_count = 0;
-#endif
-
/** \brief has_anykey
*
* FIXME: Needs doc
@@ -41,7 +32,7 @@ uint8_t has_anykey(void) {
uint8_t* p = keyboard_report->keys;
uint8_t lp = sizeof(keyboard_report->keys);
#ifdef NKRO_ENABLE
- if (keyboard_protocol && keymap_config.nkro) {
+ if (usb_device_state_get_protocol() == USB_PROTOCOL_REPORT && keymap_config.nkro) {
p = nkro_report->bits;
lp = sizeof(nkro_report->bits);
}
@@ -58,25 +49,14 @@ uint8_t has_anykey(void) {
*/
uint8_t get_first_key(void) {
#ifdef NKRO_ENABLE
- if (keyboard_protocol && keymap_config.nkro) {
+ if (usb_device_state_get_protocol() == USB_PROTOCOL_REPORT && keymap_config.nkro) {
uint8_t i = 0;
for (; i < NKRO_REPORT_BITS && !nkro_report->bits[i]; i++)
;
return i << 3 | biton(nkro_report->bits[i]);
}
#endif
-#ifdef RING_BUFFERED_6KRO_REPORT_ENABLE
- uint8_t i = cb_head;
- do {
- if (keyboard_report->keys[i] != 0) {
- break;
- }
- i = RO_INC(i);
- } while (i != cb_tail);
- return keyboard_report->keys[i];
-#else
return keyboard_report->keys[0];
-#endif
}
/** \brief Checks if a key is pressed in the report
@@ -89,7 +69,7 @@ bool is_key_pressed(uint8_t key) {
return false;
}
#ifdef NKRO_ENABLE
- if (keyboard_protocol && keymap_config.nkro) {
+ if (usb_device_state_get_protocol() == USB_PROTOCOL_REPORT && keymap_config.nkro) {
if ((key >> 3) < NKRO_REPORT_BITS) {
return nkro_report->bits[key >> 3] & 1 << (key & 7);
} else {
@@ -110,50 +90,6 @@ bool is_key_pressed(uint8_t key) {
* FIXME: Needs doc
*/
void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code) {
-#ifdef RING_BUFFERED_6KRO_REPORT_ENABLE
- int8_t i = cb_head;
- int8_t empty = -1;
- if (cb_count) {
- do {
- if (keyboard_report->keys[i] == code) {
- return;
- }
- if (empty == -1 && keyboard_report->keys[i] == 0) {
- empty = i;
- }
- i = RO_INC(i);
- } while (i != cb_tail);
- if (i == cb_tail) {
- if (cb_tail == cb_head) {
- // buffer is full
- if (empty == -1) {
- // pop head when has no empty space
- cb_head = RO_INC(cb_head);
- cb_count--;
- } else {
- // left shift when has empty space
- uint8_t offset = 1;
- i = RO_INC(empty);
- do {
- if (keyboard_report->keys[i] != 0) {
- keyboard_report->keys[empty] = keyboard_report->keys[i];
- keyboard_report->keys[i] = 0;
- empty = RO_INC(empty);
- } else {
- offset++;
- }
- i = RO_INC(i);
- } while (i != cb_tail);
- cb_tail = RO_SUB(cb_tail, offset);
- }
- }
- }
- }
- // add to tail
- keyboard_report->keys[cb_tail] = code;
- cb_tail = RO_INC(cb_tail);
- cb_count++;
-#else
int8_t i = 0;
int8_t empty = -1;
for (; i < KEYBOARD_REPORT_KEYS; i++) {
@@ -169,7 +105,6 @@ void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code) {
keyboard_report->keys[empty] = code;
}
}
-#endif
}
/** \brief del key byte
@@ -177,38 +112,11 @@ void add_key_byte(report_keyboard_t* keyboard_report, uint8_t code) {
* FIXME: Needs doc
*/
void del_key_byte(report_keyboard_t* keyboard_report, uint8_t code) {
-#ifdef RING_BUFFERED_6KRO_REPORT_ENABLE
- uint8_t i = cb_head;
- if (cb_count) {
- do {
- if (keyboard_report->keys[i] == code) {
- keyboard_report->keys[i] = 0;
- cb_count--;
- if (cb_count == 0) {
- // reset head and tail
- cb_tail = cb_head = 0;
- }
- if (i == RO_DEC(cb_tail)) {
- // left shift when next to tail
- do {
- cb_tail = RO_DEC(cb_tail);
- if (keyboard_report->keys[RO_DEC(cb_tail)] != 0) {
- break;
- }
- } while (cb_tail != cb_head);
- }
- break;
- }
- i = RO_INC(i);
- } while (i != cb_tail);
- }
-#else
for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
if (keyboard_report->keys[i] == code) {
keyboard_report->keys[i] = 0;
}
}
-#endif
}
#ifdef NKRO_ENABLE
@@ -243,7 +151,7 @@ void del_key_bit(report_nkro_t* nkro_report, uint8_t code) {
*/
void add_key_to_report(uint8_t key) {
#ifdef NKRO_ENABLE
- if (keyboard_protocol && keymap_config.nkro) {
+ if (usb_device_state_get_protocol() == USB_PROTOCOL_REPORT && keymap_config.nkro) {
add_key_bit(nkro_report, key);
return;
}
@@ -257,7 +165,7 @@ void add_key_to_report(uint8_t key) {
*/
void del_key_from_report(uint8_t key) {
#ifdef NKRO_ENABLE
- if (keyboard_protocol && keymap_config.nkro) {
+ if (usb_device_state_get_protocol() == USB_PROTOCOL_REPORT && keymap_config.nkro) {
del_key_bit(nkro_report, key);
return;
}
@@ -272,7 +180,7 @@ void del_key_from_report(uint8_t key) {
void clear_keys_from_report(void) {
// not clear mods
#ifdef NKRO_ENABLE
- if (keyboard_protocol && keymap_config.nkro) {
+ if (usb_device_state_get_protocol() == USB_PROTOCOL_REPORT && keymap_config.nkro) {
memset(nkro_report->bits, 0, sizeof(nkro_report->bits));
return;
}