Skip to content

Commit f2ebf6d

Browse files
authored
Merge pull request #27 from lactide/chibios_fixes
- usb specification 2.0: "Interfaces are numbered from zero to one less than the number of concurrent interfaces supported by the configuration", Section 9.2.3, page 244 - the offset to the nkro hid descriptor was incorrectly calculated.
2 parents e5f9940 + e361f36 commit f2ebf6d

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

protocol/chibios/usb_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ static const USBDescriptor extra_hid_report_descriptor = {
363363

364364
#ifdef NKRO_ENABLE
365365
# define NKRO_HID_DESC_NUM (EXTRA_HID_DESC_NUM + 1)
366-
# define NKRO_HID_DESC_OFFSET (9 + (9 + 9 + 7) * EXTRA_HID_DESC_NUM + 9)
366+
# define NKRO_HID_DESC_OFFSET (9 + (9 + 9 + 7) * NKRO_HID_DESC_NUM + 9)
367367
#else /* NKRO_ENABLE */
368368
# define NKRO_HID_DESC_NUM (EXTRA_HID_DESC_NUM + 0)
369369
#endif /* NKRO_ENABLE */

protocol/chibios/usb_main.h

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ void send_remote_wakeup(USBDriver *usbp);
5252

5353
/* secondary keyboard */
5454
#ifdef NKRO_ENABLE
55-
#define NKRO_INTERFACE 4
56-
#define NKRO_ENDPOINT 5
55+
#define NKRO_INTERFACE EXTRA_INTERFACE+1
56+
#define NKRO_ENDPOINT EXTRA_ENDPOINT+1
5757
#define NKRO_EPSIZE 16
5858
#define NKRO_REPORT_KEYS (NKRO_EPSIZE - 1)
59+
#else
60+
#define NKRO_INTERFACE EXTRA_INTERFACE
61+
#define NKRO_ENDPOINT EXTRA_ENDPOINT
5962
#endif
6063

6164
/* extern report_keyboard_t keyboard_report_sent; */
@@ -78,12 +81,15 @@ void nkro_in_cb(USBDriver *usbp, usbep_t ep);
7881

7982
#ifdef MOUSE_ENABLE
8083

81-
#define MOUSE_INTERFACE 1
82-
#define MOUSE_ENDPOINT 2
84+
#define MOUSE_INTERFACE (KBD_INTERFACE+1)
85+
#define MOUSE_ENDPOINT (KBD_ENDPOINT+1)
8386
#define MOUSE_EPSIZE 8
8487

8588
/* mouse IN request callback handler */
8689
void mouse_in_cb(USBDriver *usbp, usbep_t ep);
90+
#else
91+
#define MOUSE_INTERFACE KBD_INTERFACE
92+
#define MOUSE_ENDPOINT KBD_ENDPOINT
8793
#endif /* MOUSE_ENABLE */
8894

8995
/* ---------------
@@ -93,8 +99,8 @@ void mouse_in_cb(USBDriver *usbp, usbep_t ep);
9399

94100
#ifdef EXTRAKEY_ENABLE
95101

96-
#define EXTRA_INTERFACE 3
97-
#define EXTRA_ENDPOINT 4
102+
#define EXTRA_INTERFACE (CONSOLE_INTERFACE+1)
103+
#define EXTRA_ENDPOINT (CONSOLE_ENDPOINT+1)
98104
#define EXTRA_EPSIZE 8
99105

100106
/* extrakey IN request callback handler */
@@ -105,6 +111,9 @@ typedef struct {
105111
uint8_t report_id;
106112
uint16_t usage;
107113
} __attribute__ ((packed)) report_extra_t;
114+
#else
115+
#define EXTRA_INTERFACE CONSOLE_INTERFACE
116+
#define EXTRA_ENDPOINT CONSOLE_ENDPOINT
108117
#endif /* EXTRAKEY_ENABLE */
109118

110119
/* --------------
@@ -114,8 +123,8 @@ typedef struct {
114123

115124
#ifdef CONSOLE_ENABLE
116125

117-
#define CONSOLE_INTERFACE 2
118-
#define CONSOLE_ENDPOINT 3
126+
#define CONSOLE_INTERFACE (MOUSE_INTERFACE+1)
127+
#define CONSOLE_ENDPOINT (MOUSE_ENDPOINT+1)
119128
#define CONSOLE_EPSIZE 16
120129

121130
/* Number of IN reports that can be stored inside the output queue */
@@ -132,6 +141,9 @@ void console_flush_output(void);
132141

133142
/* console IN request callback handler */
134143
void console_in_cb(USBDriver *usbp, usbep_t ep);
144+
#else
145+
#define CONSOLE_INTERFACE MOUSE_INTERFACE
146+
#define CONSOLE_ENDPOINT MOUSE_ENDPOINT
135147
#endif /* CONSOLE_ENABLE */
136148

137149
void sendchar_pf(void *p, char c);

0 commit comments

Comments
 (0)