summaryrefslogtreecommitdiffstats
path: root/tmk_core/common
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common')
-rw-r--r--tmk_core/common/host.c22
-rw-r--r--tmk_core/common/report.c21
-rw-r--r--tmk_core/common/report.h46
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/>.
#include "util.h"
#include "debug.h"
+#ifdef NKRO_ENABLE
+ #include "keycode_config.h"
+ extern keymap_config_t keymap_config;
+#endif
+
static host_driver_t *driver;
static uint16_t last_system_report = 0;
static uint16_t last_consumer_report = 0;
@@ -46,6 +51,20 @@ uint8_t host_keyboard_leds(void)
void host_keyboard_send(report_keyboard_t *report)
{
if (!driver) return;
+#if defined(NKRO_ENABLE) && defined(NKRO_SHARED_EP)
+ if (keyboard_protocol && keymap_config.nkro) {
+ /* The callers of this function assume that report->mods is where mods go in.
+ * But report->nkro.mods can be at a different offset if core keyboard does not have a report ID.
+ */
+ report->nkro.mods = report->mods;
+ report->nkro.report_id = REPORT_ID_NKRO;
+ } else
+#endif
+ {
+#ifdef KEYBOARD_SHARED_EP
+ report->report_id = REPORT_ID_KEYBOARD;
+#endif
+ }
(*driver->send_keyboard)(report);
if (debug_keyboard) {
@@ -60,6 +79,9 @@ void host_keyboard_send(report_keyboard_t *report)
void host_mouse_send(report_mouse_t *report)
{
if (!driver) return;
+#ifdef MOUSE_SHARED_EP
+ report->report_id = REPORT_ID_MOUSE;
+#endif
(*driver->send_mouse)(report);
}
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 @@
#include "keycode_config.h"
#include "debug.h"
#include "util.h"
+#include <string.h>
/** \brief has_anykey
*
@@ -27,8 +28,16 @@
uint8_t has_anykey(report_keyboard_t* keyboard_report)
{
uint8_t cnt = 0;
- for (uint8_t i = 1; i < KEYBOARD_REPORT_SIZE; i++) {
- if (keyboard_report->raw[i])
+ uint8_t *p = keyboard_report->keys;
+ uint8_t lp = sizeof(keyboard_report->keys);
+#ifdef NKRO_ENABLE
+ if (keyboard_protocol && keymap_config.nkro) {
+ p = keyboard_report->nkro.bits;
+ lp = sizeof(keyboard_report->nkro.bits);
+ }
+#endif
+ while (lp--) {
+ if (*p++)
cnt++;
}
return cnt;
@@ -237,7 +246,11 @@ void del_key_from_report(report_keyboard_t* keyboard_report, uint8_t key)
void clear_keys_from_report(report_keyboard_t* keyboard_report)
{
// not clear mods
- for (int8_t i = 1; i < KEYBOARD_REPORT_SIZE; i++) {
- keyboard_report->raw[i] = 0;
+#ifdef NKRO_ENABLE
+ if (keyboard_protocol && keymap_config.nkro) {
+ memset(keyboard_report->nkro.bits, 0, sizeof(keyboard_report->nkro.bits));
+ return;
}
+#endif
+ memset(keyboard_report->keys, 0, sizeof(keyboard_report->keys));
}
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/>.
/* report id */
-#define REPORT_ID_MOUSE 1
-#define REPORT_ID_SYSTEM 2
-#define REPORT_ID_CONSUMER 3
+#define REPORT_ID_KEYBOARD 1
+#define REPORT_ID_MOUSE 2
+#define REPORT_ID_SYSTEM 3
+#define REPORT_ID_CONSUMER 4
+#define REPORT_ID_NKRO 5
/* mouse buttons */
#define MOUSE_BTN1 (1<<0)
@@ -72,32 +74,35 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define SYSTEM_WAKE_UP 0x0083
+#define NKRO_SHARED_EP
/* key report size(NKRO or boot mode) */
#if defined(NKRO_ENABLE)
- #if defined(PROTOCOL_PJRC)
- #include "usb.h"
- #define KEYBOARD_REPORT_SIZE KBD2_SIZE
- #define KEYBOARD_REPORT_KEYS (KBD2_SIZE - 2)
- #define KEYBOARD_REPORT_BITS (KBD2_SIZE - 1)
- #elif defined(PROTOCOL_LUFA) || defined(PROTOCOL_CHIBIOS)
+ #if defined(PROTOCOL_LUFA) || defined(PROTOCOL_CHIBIOS)
#include "protocol/usb_descriptor.h"
- #define KEYBOARD_REPORT_SIZE NKRO_EPSIZE
- #define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2)
- #define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1)
+ #define KEYBOARD_REPORT_BITS (SHARED_EPSIZE - 2)
#elif defined(PROTOCOL_ARM_ATSAM)
#include "protocol/arm_atsam/usb/udi_device_epsize.h"
- #define KEYBOARD_REPORT_SIZE NKRO_EPSIZE
- #define KEYBOARD_REPORT_KEYS (NKRO_EPSIZE - 2)
#define KEYBOARD_REPORT_BITS (NKRO_EPSIZE - 1)
+ #undef NKRO_SHARED_EP
+ #undef MOUSE_SHARED_EP
#else
#error "NKRO not supported with this protocol"
+ #endif
#endif
+#ifdef KEYBOARD_SHARED_EP
+# define KEYBOARD_REPORT_SIZE 9
#else
# define KEYBOARD_REPORT_SIZE 8
-# define KEYBOARD_REPORT_KEYS 6
#endif
+#define KEYBOARD_REPORT_KEYS 6
+
+/* VUSB hardcodes keyboard and mouse+extrakey only */
+#if defined(PROTOCOL_VUSB)
+ #undef KEYBOARD_SHARED_EP
+ #undef MOUSE_SHARED_EP
+#endif
#ifdef __cplusplus
extern "C" {
@@ -126,12 +131,18 @@ extern "C" {
typedef union {
uint8_t raw[KEYBOARD_REPORT_SIZE];
struct {
+#ifdef KEYBOARD_SHARED_EP
+ uint8_t report_id;
+#endif
uint8_t mods;
uint8_t reserved;
uint8_t keys[KEYBOARD_REPORT_KEYS];
};
#ifdef NKRO_ENABLE
- struct {
+ struct nkro_report {
+#ifdef NKRO_SHARED_EP
+ uint8_t report_id;
+#endif
uint8_t mods;
uint8_t bits[KEYBOARD_REPORT_BITS];
} nkro;
@@ -139,6 +150,9 @@ typedef union {
} __attribute__ ((packed)) report_keyboard_t;
typedef struct {
+#ifdef MOUSE_SHARED_EP
+ uint8_t report_id;
+#endif
uint8_t buttons;
int8_t x;
int8_t y;