diff options
Diffstat (limited to 'tmk_core/common')
-rw-r--r-- | tmk_core/common/host.c | 22 | ||||
-rw-r--r-- | tmk_core/common/report.c | 21 | ||||
-rw-r--r-- | tmk_core/common/report.h | 46 |
3 files changed, 69 insertions, 20 deletions
diff --git a/tmk_core/common/host.c b/tmk_core/common/host.c index e12b62216..f5d041699 100644 --- a/tmk_core/common/host.c +++ b/tmk_core/common/host.c | |||
@@ -22,6 +22,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
22 | #include "util.h" | 22 | #include "util.h" |
23 | #include "debug.h" | 23 | #include "debug.h" |
24 | 24 | ||
25 | #ifdef NKRO_ENABLE | ||
26 | #include "keycode_config.h" | ||
27 | extern keymap_config_t keymap_config; | ||
28 | #endif | ||
29 | |||
25 | static host_driver_t *driver; | 30 | static host_driver_t *driver; |
26 | static uint16_t last_system_report = 0; | 31 | static uint16_t last_system_report = 0; |
27 | static uint16_t last_consumer_report = 0; | 32 | static uint16_t last_consumer_report = 0; |
@@ -46,6 +51,20 @@ uint8_t host_keyboard_leds(void) | |||
46 | void host_keyboard_send(report_keyboard_t *report) | 51 | void host_keyboard_send(report_keyboard_t *report) |
47 | { | 52 | { |
48 | if (!driver) return; | 53 | if (!driver) return; |
54 | #if defined(NKRO_ENABLE) && defined(NKRO_SHARED_EP) | ||
55 | if (keyboard_protocol && keymap_config.nkro) { | ||
56 | /* The callers of this function assume that report->mods is where mods go in. | ||
57 | * But report->nkro.mods can be at a different offset if core keyboard does not have a report ID. | ||
58 | */ | ||
59 | report->nkro.mods = report->mods; | ||
60 | report->nkro.report_id = REPORT_ID_NKRO; | ||
61 | } else | ||
62 | #endif | ||
63 | { | ||
64 | #ifdef KEYBOARD_SHARED_EP | ||
65 | report->report_id = REPORT_ID_KEYBOARD; | ||
66 | #endif | ||
67 | } | ||
49 | (*driver->send_keyboard)(report); | 68 | (*driver->send_keyboard)(report); |
50 | 69 | ||
51 | if (debug_keyboard) { | 70 | if (debug_keyboard) { |
@@ -60,6 +79,9 @@ void host_keyboard_send(report_keyboard_t *report) | |||
60 | void host_mouse_send(report_mouse_t *report) | 79 | void host_mouse_send(report_mouse_t *report) |
61 | { | 80 | { |
62 | if (!driver) return; | 81 | if (!driver) return; |
82 | #ifdef MOUSE_SHARED_EP | ||
83 | report->report_id = REPORT_ID_MOUSE; | ||
84 | #endif | ||
63 | (*driver->send_mouse)(report); | 85 | (*driver->send_mouse)(report); |
64 | } | 86 | } |
65 | 87 | ||
diff --git a/tmk_core/common/report.c b/tmk_core/common/report.c index eb3b44312..6a06b70c6 100644 --- a/tmk_core/common/report.c +++ b/tmk_core/common/report.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include "keycode_config.h" | 19 | #include "keycode_config.h" |
20 | #include "debug.h" | 20 | #include "debug.h" |
21 | #include "util.h" | 21 | #include "util.h" |
22 | #include <string.h> | ||
22 | 23 | ||
23 | /** \brief has_anykey | 24 | /** \brief has_anykey |
24 | * | 25 | * |
@@ -27,8 +28,16 @@ | |||
27 | uint8_t has_anykey(report_keyboard_t* keyboard_report) | 28 | uint8_t has_anykey(report_keyboard_t* keyboard_report) |
28 | { | 29 | { |
29 | uint8_t cnt = 0; | 30 | uint8_t cnt = 0; |
30 | for (uint8_t i = 1; i < KEYBOARD_REPORT_SIZE; i++) { | 31 | uint8_t *p = keyboard_report->keys; |
31 | if (keyboard_report->raw[i]) | 32 | uint8_t lp = sizeof(keyboard_report->keys); |
33 | #ifdef NKRO_ENABLE | ||
34 | if (keyboard_protocol && keymap_config.nkro) { | ||
35 | p = keyboard_report->nkro.bits; | ||
36 | lp = sizeof(keyboard_report->nkro.bits); | ||
37 | } | ||
38 | #endif | ||
39 | while (lp--) { | ||
40 | if (*p++) | ||
32 | cnt++; | 41 | cnt++; |
33 | } | 42 | } |
34 | return cnt; | 43 | return cnt; |
@@ -237,7 +246,11 @@ void del_key_from_report(report_keyboard_t* keyboard_report, uint8_t key) | |||
237 | void clear_keys_from_report(report_keyboard_t* keyboard_report) | 246 | void clear_keys_from_report(report_keyboard_t* keyboard_report) |
238 | { | 247 | { |
239 | // not clear mods | 248 | // not clear mods |
240 | for (int8_t i = 1; i < KEYBOARD_REPORT_SIZE; i++) { | 249 | #ifdef NKRO_ENABLE |
241 | keyboard_report->raw[i] = 0; | 250 | if (keyboard_protocol && keymap_config.nkro) { |
251 | memset(keyboard_report->nkro.bits, 0, sizeof(keyboard_report->nkro.bits)); | ||
252 | return; | ||
242 | } | 253 | } |
254 | #endif | ||
255 | memset(keyboard_report->keys, 0, sizeof(keyboard_report->keys)); | ||
243 | } | 256 | } |
diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h index 167f38275..5a1a6b19c 100644 --- a/tmk_core/common/report.h +++ b/tmk_core/common/report.h | |||
@@ -23,9 +23,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
23 | 23 | ||
24 | 24 | ||
25 | /* report id */ | 25 | /* report id */ |
26 | #define REPORT_ID_MOUSE 1 | 26 | #define REPORT_ID_KEYBOARD 1 |
27 | #define REPORT_ID_SYSTEM 2 | 27 | #define REPORT_ID_MOUSE 2 |
28 | #define REPORT_ID_CONSUMER 3 | 28 | #define REPORT_ID_SYSTEM 3 |
29 | #define REPORT_ID_CONSUMER 4 | ||
30 | #define REPORT_ID_NKRO 5 | ||
29 | 31 | ||
30 | /* mouse buttons */ | 32 | /* mouse buttons */ |
31 | #define MOUSE_BTN1 (1<<0) | 33 | #define MOUSE_BTN1 (1<<0) |
@@ -72,32 +74,35 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
72 | #define SYSTEM_WAKE_UP 0x0083 | 74 | #define SYSTEM_WAKE_UP 0x0083 |
73 | 75 | ||
74 | 76 | ||
77 | #define NKRO_SHARED_EP | ||
75 | /* key report size(NKRO or boot mode) */ | 78 | /* key report size(NKRO or boot mode) */ |
76 | #if defined(NKRO_ENABLE) | 79 | #if defined(NKRO_ENABLE) |
77 | #if defined(PROTOCOL_PJRC) | 80 | #if defined(PROTOCOL_LUFA) || defined(PROTOCOL_CHIBIOS) |
78 | #include "usb.h" | ||
79 | #define KEYBOARD_REPORT_SIZE KBD2_SIZE | ||
80 | #define KEYBOARD_REPORT_KEYS (KBD2_SIZE - 2) | ||
81 | #define KEYBOARD_REPORT_BITS (KBD2_SIZE - 1) | ||
82 | #elif defined(PROTOCOL_LUFA) || defined(PROTOCOL_CHIBIOS) | ||
83 | #include "protocol/usb_descriptor.h" | 81 | #include "protocol/usb_descriptor.h" |
84 | #define KEYBOARD_REPORT_SIZE NKRO_EPSIZE | 82 | #define KEYBOARD_REPORT_BITS (SHARED_EPSIZE - 2) |
85 | #define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2) | ||
86 | #define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1) | ||
87 | #elif defined(PROTOCOL_ARM_ATSAM) | 83 | #elif defined(PROTOCOL_ARM_ATSAM) |
88 | #include "protocol/arm_atsam/usb/udi_device_epsize.h" | 84 | #include "protocol/arm_atsam/usb/udi_device_epsize.h" |
89 | #define KEYBOARD_REPORT_SIZE NKRO_EPSIZE | ||
90 | #define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2) | ||
91 | #define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1) | 85 | #define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1) |
86 | #undef NKRO_SHARED_EP | ||
87 | #undef MOUSE_SHARED_EP | ||
92 | #else | 88 | #else |
93 | #error "NKRO not supported with this protocol" | 89 | #error "NKRO not supported with this protocol" |
90 | #endif | ||
94 | #endif | 91 | #endif |
95 | 92 | ||
93 | #ifdef KEYBOARD_SHARED_EP | ||
94 | # define KEYBOARD_REPORT_SIZE 9 | ||
96 | #else | 95 | #else |
97 | # define KEYBOARD_REPORT_SIZE 8 | 96 | # define KEYBOARD_REPORT_SIZE 8 |
98 | # define KEYBOARD_REPORT_KEYS 6 | ||
99 | #endif | 97 | #endif |
100 | 98 | ||
99 | #define KEYBOARD_REPORT_KEYS 6 | ||
100 | |||
101 | /* VUSB hardcodes keyboard and mouse+extrakey only */ | ||
102 | #if defined(PROTOCOL_VUSB) | ||
103 | #undef KEYBOARD_SHARED_EP | ||
104 | #undef MOUSE_SHARED_EP | ||
105 | #endif | ||
101 | 106 | ||
102 | #ifdef __cplusplus | 107 | #ifdef __cplusplus |
103 | extern "C" { | 108 | extern "C" { |
@@ -126,12 +131,18 @@ extern "C" { | |||
126 | typedef union { | 131 | typedef union { |
127 | uint8_t raw[KEYBOARD_REPORT_SIZE]; | 132 | uint8_t raw[KEYBOARD_REPORT_SIZE]; |
128 | struct { | 133 | struct { |
134 | #ifdef KEYBOARD_SHARED_EP | ||
135 | uint8_t report_id; | ||
136 | #endif | ||
129 | uint8_t mods; | 137 | uint8_t mods; |
130 | uint8_t reserved; | 138 | uint8_t reserved; |
131 | uint8_t keys[KEYBOARD_REPORT_KEYS]; | 139 | uint8_t keys[KEYBOARD_REPORT_KEYS]; |
132 | }; | 140 | }; |
133 | #ifdef NKRO_ENABLE | 141 | #ifdef NKRO_ENABLE |
134 | struct { | 142 | struct nkro_report { |
143 | #ifdef NKRO_SHARED_EP | ||
144 | uint8_t report_id; | ||
145 | #endif | ||
135 | uint8_t mods; | 146 | uint8_t mods; |
136 | uint8_t bits[KEYBOARD_REPORT_BITS]; | 147 | uint8_t bits[KEYBOARD_REPORT_BITS]; |
137 | } nkro; | 148 | } nkro; |
@@ -139,6 +150,9 @@ typedef union { | |||
139 | } __attribute__ ((packed)) report_keyboard_t; | 150 | } __attribute__ ((packed)) report_keyboard_t; |
140 | 151 | ||
141 | typedef struct { | 152 | typedef struct { |
153 | #ifdef MOUSE_SHARED_EP | ||
154 | uint8_t report_id; | ||
155 | #endif | ||
142 | uint8_t buttons; | 156 | uint8_t buttons; |
143 | int8_t x; | 157 | int8_t x; |
144 | int8_t y; | 158 | int8_t y; |