summaryrefslogtreecommitdiffstats
path: root/tmk_core/protocol/usb_descriptor.h
diff options
context:
space:
mode:
authorJames Laird-Wah <james@laird-wah.net>2018-11-16 07:22:05 +0100
committerDrashna Jaelre <drashna@live.com>2018-11-16 07:22:05 +0100
commit39bd760faf2666e91d6dc5b199f02fa3206c6acd (patch)
tree12db265881a0d358bb0e186689a7b20a81c37bc6 /tmk_core/protocol/usb_descriptor.h
parent46cf8cc9b33a3c8bdbb0ce7df7f48f28e4d979a5 (diff)
downloadqmk_firmware-39bd760faf2666e91d6dc5b199f02fa3206c6acd.tar.gz
qmk_firmware-39bd760faf2666e91d6dc5b199f02fa3206c6acd.tar.xz
Use a single endpoint for HID reports (#3951)
* Unify multiple HID interfaces into one This reduces the number of USB endpoints required, which frees them up for other things. NKRO and EXTRAKEY always use the shared endpoint. By default, MOUSEKEY also uses it. This means it won't work as a Boot Procotol mouse in some BIOSes, etc. If you really think your keyboard needs to work as a mouse in your BIOS, set MOUSE_SHARED_EP = no in your rules.mk. By default, the core keyboard does not use the shared endpoint, as not all BIOSes are standards compliant and that's one place you don't want to find out your keyboard doesn't work.. If you are really confident, you can set KEYBOARD_SHARED_EP = yes to use the shared endpoint here too. * unify endpoints: ChibiOS protocol implementation * fixup: missing #ifdef EXTRAKEY_ENABLEs broke build on AVR with EXTRAKEY disabled * endpoints: restore error when too many endpoints required * lufa: wait up to 10ms to send keyboard input This avoids packets being dropped when two reports are sent in quick succession (eg. releasing a dual role key). * endpoints: fix compile on ARM_ATSAM * endpoint: ARM_ATSAM fixes No longer use wrong or unexpected endpoint IDs * endpoints: accommodate VUSB protocol V-USB has its own, understandably simple ideas about the report formats. It already blasts the mouse and extrakeys through one endpoint with report IDs. We just stay out of its way. * endpoints: document new endpoint configuration options * endpoints: respect keyboard_report->mods in NKRO The caller(s) of host_keyboard_send expect to be able to just drop modifiers in the mods field and not worry about whether NKRO is in use. This is a good thing. So we just shift it over if needs be. * endpoints: report.c: update for new keyboard_report format
Diffstat (limited to 'tmk_core/protocol/usb_descriptor.h')
-rw-r--r--tmk_core/protocol/usb_descriptor.h170
1 files changed, 68 insertions, 102 deletions
diff --git a/tmk_core/protocol/usb_descriptor.h b/tmk_core/protocol/usb_descriptor.h
index 586d07df6..3ca0c00b3 100644
--- a/tmk_core/protocol/usb_descriptor.h
+++ b/tmk_core/protocol/usb_descriptor.h
@@ -53,26 +53,27 @@ typedef struct
{
USB_Descriptor_Configuration_Header_t Config;
+#ifndef KEYBOARD_SHARED_EP
// Keyboard HID Interface
USB_Descriptor_Interface_t Keyboard_Interface;
USB_HID_Descriptor_HID_t Keyboard_HID;
USB_Descriptor_Endpoint_t Keyboard_INEndpoint;
+#endif
-#ifdef MOUSE_ENABLE
+#if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
// Mouse HID Interface
USB_Descriptor_Interface_t Mouse_Interface;
USB_HID_Descriptor_HID_t Mouse_HID;
USB_Descriptor_Endpoint_t Mouse_INEndpoint;
#endif
-#ifdef EXTRAKEY_ENABLE
- // Extrakey HID Interface
- USB_Descriptor_Interface_t Extrakey_Interface;
- USB_HID_Descriptor_HID_t Extrakey_HID;
- USB_Descriptor_Endpoint_t Extrakey_INEndpoint;
+#if defined(SHARED_EP_ENABLE)
+ USB_Descriptor_Interface_t Shared_Interface;
+ USB_HID_Descriptor_HID_t Shared_HID;
+ USB_Descriptor_Endpoint_t Shared_INEndpoint;
#endif
-#ifdef RAW_ENABLE
+#if defined(RAW_ENABLE)
// Raw HID Interface
USB_Descriptor_Interface_t Raw_Interface;
USB_HID_Descriptor_HID_t Raw_HID;
@@ -88,13 +89,6 @@ typedef struct
USB_Descriptor_Endpoint_t Console_OUTEndpoint;
#endif
-#ifdef NKRO_ENABLE
- // NKRO HID Interface
- USB_Descriptor_Interface_t NKRO_Interface;
- USB_HID_Descriptor_HID_t NKRO_HID;
- USB_Descriptor_Endpoint_t NKRO_INEndpoint;
-#endif
-
#ifdef MIDI_ENABLE
USB_Descriptor_Interface_Association_t Audio_Interface_Association;
// MIDI Audio Control Interface
@@ -133,133 +127,105 @@ typedef struct
/* index of interface */
-#define KEYBOARD_INTERFACE 0
-
+enum usb_interfaces {
+#if !defined(KEYBOARD_SHARED_EP)
+ KEYBOARD_INTERFACE,
+#else
+# define KEYBOARD_INTERFACE SHARED_INTERFACE
+#endif
// It is important that the Raw HID interface is at a constant
// interface number, to support Linux/OSX platforms and chrome.hid
// If Raw HID is enabled, let it be always 1.
-#ifdef RAW_ENABLE
-# define RAW_INTERFACE (KEYBOARD_INTERFACE + 1)
-#else
-# define RAW_INTERFACE KEYBOARD_INTERFACE
+#if defined(RAW_ENABLE)
+ RAW_INTERFACE,
#endif
-
-#ifdef MOUSE_ENABLE
-# define MOUSE_INTERFACE (RAW_INTERFACE + 1)
-#else
-# define MOUSE_INTERFACE RAW_INTERFACE
+#if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
+ MOUSE_INTERFACE,
#endif
-
-#ifdef EXTRAKEY_ENABLE
-# define EXTRAKEY_INTERFACE (MOUSE_INTERFACE + 1)
-#else
-# define EXTRAKEY_INTERFACE MOUSE_INTERFACE
+#if defined(SHARED_EP_ENABLE)
+ SHARED_INTERFACE,
#endif
-
-#ifdef CONSOLE_ENABLE
-# define CONSOLE_INTERFACE (EXTRAKEY_INTERFACE + 1)
-#else
-# define CONSOLE_INTERFACE EXTRAKEY_INTERFACE
-#endif
-
-#ifdef NKRO_ENABLE
-# define NKRO_INTERFACE (CONSOLE_INTERFACE + 1)
-#else
-# define NKRO_INTERFACE CONSOLE_INTERFACE
+#if defined(CONSOLE_ENABLE)
+ CONSOLE_INTERFACE,
#endif
-
-#ifdef MIDI_ENABLE
-# define AC_INTERFACE (NKRO_INTERFACE + 1)
-# define AS_INTERFACE (NKRO_INTERFACE + 2)
-#else
-# define AS_INTERFACE NKRO_INTERFACE
+#if defined(MIDI_ENABLE)
+ AC_INTERFACE,
+ AS_INTERFACE,
#endif
-
-#ifdef VIRTSER_ENABLE
-# define CCI_INTERFACE (AS_INTERFACE + 1)
-# define CDI_INTERFACE (AS_INTERFACE + 2)
-#else
-# define CDI_INTERFACE AS_INTERFACE
+#if defined(VIRTSER_ENABLE)
+ CCI_INTERFACE,
+ CDI_INTERFACE,
#endif
+ TOTAL_INTERFACES
+};
-/* nubmer of interfaces */
-#define TOTAL_INTERFACES (CDI_INTERFACE + 1)
-
+#define NEXT_EPNUM __COUNTER__
-// Endopoint number and size
-#define KEYBOARD_IN_EPNUM 1
-
-#ifdef MOUSE_ENABLE
-# define MOUSE_IN_EPNUM (KEYBOARD_IN_EPNUM + 1)
+enum usb_endpoints {
+ __unused_epnum__ = NEXT_EPNUM, /* EP numbering starts at 1 */
+#if !defined(KEYBOARD_SHARED_EP)
+ KEYBOARD_IN_EPNUM = NEXT_EPNUM,
#else
-# define MOUSE_IN_EPNUM KEYBOARD_IN_EPNUM
+# define KEYBOARD_IN_EPNUM SHARED_IN_EPNUM
#endif
-
-#ifdef EXTRAKEY_ENABLE
-# define EXTRAKEY_IN_EPNUM (MOUSE_IN_EPNUM + 1)
+#if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
+ MOUSE_IN_EPNUM = NEXT_EPNUM,
#else
-# define EXTRAKEY_IN_EPNUM MOUSE_IN_EPNUM
+# define MOUSE_IN_EPNUM SHARED_IN_EPNUM
#endif
-
-#ifdef RAW_ENABLE
-# define RAW_IN_EPNUM (EXTRAKEY_IN_EPNUM + 1)
-# define RAW_OUT_EPNUM (EXTRAKEY_IN_EPNUM + 2)
-#else
-# define RAW_OUT_EPNUM EXTRAKEY_IN_EPNUM
+#if defined(RAW_ENABLE)
+ RAW_IN_EPNUM = NEXT_EPNUM,
+ RAW_OUT_EPNUM = NEXT_EPNUM,
#endif
-
-#ifdef CONSOLE_ENABLE
-# define CONSOLE_IN_EPNUM (RAW_OUT_EPNUM + 1)
+#if defined(SHARED_EP_ENABLE)
+ SHARED_IN_EPNUM = NEXT_EPNUM,
+#endif
+#if defined(CONSOLE_ENABLE)
+ CONSOLE_IN_EPNUM = NEXT_EPNUM,
#ifdef PROTOCOL_CHIBIOS
// ChibiOS has enough memory and descriptor to actually enable the endpoint
// It could use the same endpoint numbers, as that's supported by ChibiOS
// But the QMK code currently assumes that the endpoint numbers are different
-# define CONSOLE_OUT_EPNUM (RAW_OUT_EPNUM + 2)
+ CONSOLE_OUT_EPNUM = NEXT_EPNUM,
#else
-# define CONSOLE_OUT_EPNUM (RAW_OUT_EPNUM + 1)
+#define CONSOLE_OUT_EPNUM CONSOLE_IN_EPNUM
#endif
-#else
-# define CONSOLE_OUT_EPNUM RAW_OUT_EPNUM
#endif
-
-#ifdef NKRO_ENABLE
-# define NKRO_IN_EPNUM (CONSOLE_OUT_EPNUM + 1)
-#else
-# define NKRO_IN_EPNUM CONSOLE_OUT_EPNUM
-#endif
-
#ifdef MIDI_ENABLE
-# define MIDI_STREAM_IN_EPNUM (NKRO_IN_EPNUM + 1)
-// # define MIDI_STREAM_OUT_EPNUM (NKRO_IN_EPNUM + 1)
-# define MIDI_STREAM_OUT_EPNUM (NKRO_IN_EPNUM + 2)
+ MIDI_STREAM_IN_EPNUM = NEXT_EPNUM,
+ MIDI_STREAM_OUT_EPNUM = NEXT_EPNUM,
# define MIDI_STREAM_IN_EPADDR (ENDPOINT_DIR_IN | MIDI_STREAM_IN_EPNUM)
# define MIDI_STREAM_OUT_EPADDR (ENDPOINT_DIR_OUT | MIDI_STREAM_OUT_EPNUM)
-#else
-# define MIDI_STREAM_OUT_EPNUM NKRO_IN_EPNUM
#endif
-
#ifdef VIRTSER_ENABLE
-# define CDC_NOTIFICATION_EPNUM (MIDI_STREAM_OUT_EPNUM + 1)
-# define CDC_IN_EPNUM (MIDI_STREAM_OUT_EPNUM + 2)
-# define CDC_OUT_EPNUM (MIDI_STREAM_OUT_EPNUM + 3)
+ CDC_NOTIFICATION_EPNUM = NEXT_EPNUM,
+ CDC_IN_EPNUM = NEXT_EPNUM,
+ CDC_OUT_EPNUM = NEXT_EPNUM,
# define CDC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | CDC_NOTIFICATION_EPNUM)
# define CDC_IN_EPADDR (ENDPOINT_DIR_IN | CDC_IN_EPNUM)
# define CDC_OUT_EPADDR (ENDPOINT_DIR_OUT | CDC_OUT_EPNUM)
-#else
-# define CDC_OUT_EPNUM MIDI_STREAM_OUT_EPNUM
#endif
+};
+
+#if defined(PROTOCOL_LUFA)
+/* LUFA tells us total endpoints including control */
+#define MAX_ENDPOINTS (ENDPOINT_TOTAL_ENDPOINTS - 1)
+#elif defined(PROTOCOL_CHIBIOS)
+/* ChibiOS gives us number of available user endpoints, not control */
+#define MAX_ENDPOINTS USB_MAX_ENDPOINTS
+#endif
+/* TODO - ARM_ATSAM */
+
-#if (defined(PROTOCOL_LUFA) && CDC_OUT_EPNUM > (ENDPOINT_TOTAL_ENDPOINTS - 1)) || \
- (defined(PROTOCOL_CHIBIOS) && CDC_OUT_EPNUM > USB_MAX_ENDPOINTS)
-# error "There are not enough available endpoints to support all functions. Remove some in the rules.mk file.(MOUSEKEY, EXTRAKEY, CONSOLE, NKRO, MIDI, SERIAL, STENO)"
+#if (NEXT_EPNUM - 1) > MAX_ENDPOINTS
+# error There are not enough available endpoints to support all functions. Remove some in the rules.mk file. (MOUSEKEY, EXTRAKEY, CONSOLE, NKRO, MIDI, SERIAL, STENO)
#endif
#define KEYBOARD_EPSIZE 8
+#define SHARED_EPSIZE 32
#define MOUSE_EPSIZE 8
-#define EXTRAKEY_EPSIZE 8
#define RAW_EPSIZE 32
#define CONSOLE_EPSIZE 32
-#define NKRO_EPSIZE 32
#define MIDI_STREAM_EPSIZE 64
#define CDC_NOTIFICATION_EPSIZE 8
#define CDC_EPSIZE 16