]> git.donarmstrong.com Git - kiibohd-controller.git/blob - Output/pjrcUSB/arm/usb_desc.c
Fixed Linux NKRO bitmap bug.
[kiibohd-controller.git] / Output / pjrcUSB / arm / usb_desc.c
1 /* Teensyduino Core Library
2  * http://www.pjrc.com/teensy/
3  * Copyright (c) 2013 PJRC.COM, LLC.
4  * Modified by Jacob Alexander (2013-2014)
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * 1. The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * 2. If the Software is incorporated into a build system that allows
18  * selection among a list of target devices, then similar target
19  * devices manufactured by PJRC.COM must be included in the list of
20  * target devices and selectable in the same manner.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
26  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
28  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29  * SOFTWARE.
30  */
31
32 // ----- Includes -----
33
34 // Local Includes
35 #include "usb_desc.h"
36
37
38
39 // ----- Macros -----
40
41 #define LSB(n) ((n) & 255)
42 #define MSB(n) (((n) >> 8) & 255)
43
44
45
46 // ----- USB Device Descriptor -----
47
48 // USB Device Descriptor.  The USB host reads this first, to learn
49 // what type of device is connected.
50 static uint8_t device_descriptor[] = {
51         18,                                     // bLength
52         1,                                      // bDescriptorType
53         0x00, 0x02,                             // bcdUSB
54         DEVICE_CLASS,                           // bDeviceClass
55         DEVICE_SUBCLASS,                        // bDeviceSubClass
56         DEVICE_PROTOCOL,                        // bDeviceProtocol
57         EP0_SIZE,                               // bMaxPacketSize0
58         LSB(VENDOR_ID), MSB(VENDOR_ID),         // idVendor
59         LSB(PRODUCT_ID), MSB(PRODUCT_ID),       // idProduct
60         0x00, 0x01,                             // bcdDevice
61         1,                                      // iManufacturer
62         2,                                      // iProduct
63         3,                                      // iSerialNumber
64         1                                       // bNumConfigurations
65 };
66
67 // USB Device Qualifier Descriptor
68 static uint8_t device_qualifier_descriptor[] = {
69         0                                       // Indicate only single speed
70         /* Device qualifier example (used for specifying multiple USB speeds)
71         10,                                     // bLength
72         6,                                      // bDescriptorType
73         0x00, 0x02,                             // bcdUSB
74         DEVICE_CLASS,                           // bDeviceClass
75         DEVICE_SUBCLASS,                        // bDeviceSubClass
76         DEVICE_PROTOCOL,                        // bDeviceProtocol
77         EP0_SIZE,                               // bMaxPacketSize0
78         0,                                      // bNumOtherSpeedConfigurations
79         0                                       // bReserved
80         */
81 };
82
83 // USB Debug Descriptor
84 // XXX Not sure of exact use, lsusb requests it
85 static uint8_t usb_debug_descriptor[] = {
86         0
87 };
88
89 // XXX
90 // These descriptors must NOT be "const", because the USB DMA
91 // has trouble accessing flash memory with enough bandwidth
92 // while the processor is executing from flash.
93 // XXX
94
95
96
97 // ----- USB HID Report Descriptsors -----
98
99 // Each HID interface needs a special report descriptor that tells
100 // the meaning and format of the data.
101
102 // Keyboard Protocol 1, HID 1.11 spec, Appendix B, page 59-60
103 static uint8_t keyboard_report_desc[] = {
104         // Keyboard Collection
105         0x05, 0x01,          // Usage Page (Generic Desktop),
106         0x09, 0x06,          // Usage (Keyboard),
107         0xA1, 0x01,          // Collection (Application) - Keyboard,
108
109         // Modifier Byte
110         0x75, 0x01,          //   Report Size (1),
111         0x95, 0x08,          //   Report Count (8),
112         0x05, 0x07,          //   Usage Page (Key Codes),
113         0x19, 0xE0,          //   Usage Minimum (224),
114         0x29, 0xE7,          //   Usage Maximum (231),
115         0x15, 0x00,          //   Logical Minimum (0),
116         0x25, 0x01,          //   Logical Maximum (1),
117         0x81, 0x02,          //   Input (Data, Variable, Absolute),
118
119         // Reserved Byte
120         0x75, 0x08,          //   Report Size (8),
121         0x95, 0x01,          //   Report Count (1),
122         0x81, 0x03,          //   Output (Constant),
123
124         // LED Report
125         0x75, 0x01,          //   Report Size (1),
126         0x95, 0x05,          //   Report Count (5),
127         0x05, 0x08,          //   Usage Page (LEDs),
128         0x19, 0x01,          //   Usage Minimum (1),
129         0x29, 0x05,          //   Usage Maximum (5),
130         0x91, 0x02,          //   Output (Data, Variable, Absolute),
131
132         // LED Report Padding
133         0x75, 0x03,          //   Report Size (3),
134         0x95, 0x01,          //   Report Count (1),
135         0x91, 0x03,          //   Output (Constant),
136
137         // Normal Keys
138         0x75, 0x08,          //   Report Size (8),
139         0x95, 0x06,          //   Report Count (6),
140         0x15, 0x00,          //   Logical Minimum (0),
141         0x25, 0x7F,          //   Logical Maximum(104),
142         0x05, 0x07,          //   Usage Page (Key Codes),
143         0x19, 0x00,          //   Usage Minimum (0),
144         0x29, 0x7F,          //   Usage Maximum (104),
145         0x81, 0x00,          //   Input (Data, Array),
146         0xc0,                // End Collection - Keyboard
147 };
148
149 // Keyboard Protocol 1, HID 1.11 spec, Appendix B, page 59-60
150 static uint8_t nkro_keyboard_report_desc[] = {
151         // Keyboard Collection
152         0x05, 0x01,          // Usage Page (Generic Desktop),
153         0x09, 0x06,          // Usage (Keyboard),
154         0xA1, 0x01,          // Collection (Application) - Keyboard,
155
156         // Modifier Byte
157         0x85, 0x01,          //   Report ID (1),
158         0x75, 0x01,          //   Report Size (1),
159         0x95, 0x08,          //   Report Count (8),
160         0x15, 0x00,          //   Logical Minimum (0),
161         0x25, 0x01,          //   Logical Maximum (1),
162         0x05, 0x07,          //   Usage Page (Key Codes),
163         0x19, 0xE0,          //   Usage Minimum (224),
164         0x29, 0xE7,          //   Usage Maximum (231),
165         0x81, 0x02,          //   Input (Data, Variable, Absolute),
166
167         // LED Report
168         0x85, 0x02,          //   Report ID (2),
169         0x75, 0x01,          //   Report Size (1),
170         0x95, 0x05,          //   Report Count (5),
171         0x05, 0x08,          //   Usage Page (LEDs),
172         0x19, 0x01,          //   Usage Minimum (1),
173         0x29, 0x05,          //   Usage Maximum (5),
174         0x91, 0x02,          //   Output (Data, Variable, Absolute),
175
176         // LED Report Padding
177         0x75, 0x03,          //   Report Size (3),
178         0x95, 0x01,          //   Report Count (1),
179         0x91, 0x03,          //   Output (Constant),
180
181         // Normal Keys - Using an NKRO Bitmap
182         //
183         // NOTES:
184         // Supports all keys defined by the spec, except 1-3 which define error events
185         //  and 0 which is "no keys pressed"
186         // See http://www.usb.org/developers/hidpage/Hut1_12v2.pdf Chapter 10
187         // Or Macros/PartialMap/usb_hid.h
188         //
189         // 50 must be excluded due to a Linux bug with bitmaps (not useful anyways)
190         // 165-175 are reserved/unused as well as 222-223 and 232-65535
191         // 224-231 are used for modifiers (see above)
192         //
193         // Packing of bitmaps are as follows:
194         //   4-49  :  6 bytes + 1 Report ID byte (0x04-0x31) ( 46 bits + 2 padding bits for 6 bytes total)
195         //  51-164 : 20 bytes + 1 Report ID byte (0x33-0xA4) (114 bits + 6 padding bits for 15 bytes total)
196         // 176-221 :  6 bytes + 1 Report ID byte (0xB0-0xDD) ( 46 bits + 2 padding bits for 6 bytes total)
197         //
198         // 4-49 (6 bytes/46 bits)
199         0x85, 0x03,          //   Report ID (3),
200         0x75, 0x01,          //   Report Size (1),
201         0x95, 0xA0,          //   Report Count (160),
202         0x15, 0x00,          //   Logical Minimum (0),
203         0x25, 0x01,          //   Logical Maximum (1),
204         0x05, 0x07,          //   Usage Page (Key Codes),
205         0x19, 0x04,          //   Usage Minimum (4),
206         0x29, 0x31,          //   Usage Maximum (49),
207         0x81, 0x02,          //   Input (Data, Variable, Absolute, Bitfield),
208
209         // Padding (2 bits)
210         0x75, 0x02,          //   Report Size (2),
211         0x95, 0x01,          //   Report Count (1),
212         0x81, 0x03,          //   Input (Constant),
213
214         // 51-164 (15 bytes/160 bits)
215         0x85, 0x04,          //   Report ID (4),
216         0x75, 0x01,          //   Report Size (1),
217         0x95, 0xA0,          //   Report Count (160),
218         0x15, 0x00,          //   Logical Minimum (0),
219         0x25, 0x01,          //   Logical Maximum (1),
220         0x05, 0x07,          //   Usage Page (Key Codes),
221         0x19, 0x33,          //   Usage Minimum (51),
222         0x29, 0xA4,          //   Usage Maximum (164),
223         0x81, 0x02,          //   Input (Data, Variable, Absolute, Bitfield),
224
225         // Padding (6 bits)
226         0x75, 0x06,          //   Report Size (6),
227         0x95, 0x01,          //   Report Count (1),
228         0x81, 0x03,          //   Input (Constant),
229
230         // 176-221 (6 bytes/46 bits)
231         0x85, 0x05,          //   Report ID (5),
232         0x75, 0x01,          //   Report Size (1),
233         0x95, 0x2D,          //   Report Count (45),
234         0x15, 0x00,          //   Logical Minimum (0),
235         0x25, 0x01,          //   Logical Maximum (1),
236         0x05, 0x07,          //   Usage Page (Key Codes),
237         0x19, 0xB0,          //   Usage Minimum (176),
238         0x29, 0xDD,          //   Usage Maximum (221),
239         0x81, 0x02,          //   Input (Data, Variable, Absolute, Bitfield),
240
241         // Padding (2 bits)
242         0x75, 0x02,          //   Report Size (2),
243         0x95, 0x01,          //   Report Count (1),
244         0x81, 0x03,          //   Input (Constant),
245         0xc0,                // End Collection - Keyboard
246
247         // System Control Collection
248         //
249         // NOTES:
250         // Not bothering with NKRO for this table. If there's need, I can implement it. -HaaTa
251         // Using a 1KRO scheme
252         0x05, 0x01,          // Usage Page (Generic Desktop),
253         0x09, 0x80,          // Usage (System Control),
254         0xA1, 0x01,          // Collection (Application),
255         0x85, 0x06,          //   Report ID (6),
256         0x75, 0x08,          //   Report Size (8),
257         0x95, 0x01,          //   Report Count (1),
258         0x16, 0x81, 0x00,    //   Logical Minimum (129),
259         0x26, 0xB7, 0x00,    //   Logical Maximum (183),
260         0x19, 0x81,          //   Usage Minimum (129),
261         0x29, 0xB7,          //   Usage Maximum (183),
262         0x81, 0x00,          //   Input (Data, Array),
263         0xc0,                // End Collection - System Control
264
265         // Consumer Control Collection - Media Keys
266         //
267         // NOTES:
268         // Not bothering with NKRO for this table. If there's a need, I can implement it. -HaaTa
269         // Using a 1KRO scheme
270         0x05, 0x0c,          // Usage Page (Consumer),
271         0x09, 0x01,          // Usage (Consumer Control),
272         0xA1, 0x01,          // Collection (Application),
273         0x85, 0x07,          //   Report ID (7),
274         0x75, 0x10,          //   Report Size (16),
275         0x95, 0x01,          //   Report Count (1),
276         0x16, 0x20, 0x00,    //   Logical Minimum (32),
277         0x26, 0x9C, 0x02,    //   Logical Maximum (668),
278         0x05, 0x0C,          //   Usage Page (Consumer),
279         0x19, 0x20,          //   Usage Minimum (32),
280         0x2A, 0x9C, 0x02,    //   Usage Maximum (668),
281         0x81, 0x00,          //   Input (Data, Array),
282         0xc0,                // End Collection - Consumer Control
283 };
284
285 /* MOUSE
286 // Mouse Protocol 1, HID 1.11 spec, Appendix B, page 59-60, with wheel extension
287 static uint8_t mouse_report_desc[] = {
288         0x05, 0x01,                     // Usage Page (Generic Desktop)
289         0x09, 0x02,                     // Usage (Mouse)
290         0xA1, 0x01,                     // Collection (Application)
291         0x05, 0x09,                     //   Usage Page (Button)
292         0x19, 0x01,                     //   Usage Minimum (Button #1)
293         0x29, 0x03,                     //   Usage Maximum (Button #3)
294         0x15, 0x00,                     //   Logical Minimum (0)
295         0x25, 0x01,                     //   Logical Maximum (1)
296         0x95, 0x03,                     //   Report Count (3)
297         0x75, 0x01,                     //   Report Size (1)
298         0x81, 0x02,                     //   Input (Data, Variable, Absolute)
299         0x95, 0x01,                     //   Report Count (1)
300         0x75, 0x05,                     //   Report Size (5)
301         0x81, 0x03,                     //   Input (Constant)
302         0x05, 0x01,                     //   Usage Page (Generic Desktop)
303         0x09, 0x30,                     //   Usage (X)
304         0x09, 0x31,                     //   Usage (Y)
305         0x15, 0x00,                     //   Logical Minimum (0)
306         0x26, 0xFF, 0x7F,               //   Logical Maximum (32767)
307         0x75, 0x10,                     //   Report Size (16),
308         0x95, 0x02,                     //   Report Count (2),
309         0x81, 0x02,                     //   Input (Data, Variable, Absolute)
310         0x09, 0x38,                     //   Usage (Wheel)
311         0x15, 0x81,                     //   Logical Minimum (-127)
312         0x25, 0x7F,                     //   Logical Maximum (127)
313         0x75, 0x08,                     //   Report Size (8),
314         0x95, 0x01,                     //   Report Count (1),
315         0x81, 0x06,                     //   Input (Data, Variable, Relative)
316         0xC0                            // End Collection
317 };
318 */
319
320
321
322 // ----- USB Configuration -----
323
324 // USB Configuration Descriptor.  This huge descriptor tells all
325 // of the devices capbilities.
326 static uint8_t config_descriptor[CONFIG_DESC_SIZE] = {
327 // --- Configuration ---
328 // - 9 bytes -
329         // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
330         9,                                      // bLength;
331         2,                                      // bDescriptorType;
332         LSB(CONFIG_DESC_SIZE),                  // wTotalLength
333         MSB(CONFIG_DESC_SIZE),
334         NUM_INTERFACE,                          // bNumInterfaces
335         1,                                      // bConfigurationValue
336         0,                                      // iConfiguration
337         0xA0,                                   // bmAttributes
338         250,                                    // bMaxPower
339
340 // --- Keyboard HID --- Boot Mode Keyboard Interface
341 // - 9 bytes -
342         // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
343         9,                                      // bLength
344         4,                                      // bDescriptorType
345         KEYBOARD_INTERFACE,                     // bInterfaceNumber
346         0,                                      // bAlternateSetting
347         1,                                      // bNumEndpoints
348         0x03,                                   // bInterfaceClass (0x03 = HID)
349         0x01,                                   // bInterfaceSubClass (0x00 = Non-Boot, 0x01 = Boot)
350         0x01,                                   // bInterfaceProtocol (0x01 = Keyboard)
351         0,                                      // iInterface
352 // - 9 bytes -
353         // HID interface descriptor, HID 1.11 spec, section 6.2.1
354         9,                                      // bLength
355         0x21,                                   // bDescriptorType
356         0x11, 0x01,                             // bcdHID
357         0,                                      // bCountryCode
358         1,                                      // bNumDescriptors
359         0x22,                                   // bDescriptorType
360         LSB(sizeof(keyboard_report_desc)),      // wDescriptorLength
361         MSB(sizeof(keyboard_report_desc)),
362 // - 7 bytes -
363         // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
364         7,                                      // bLength
365         5,                                      // bDescriptorType
366         KEYBOARD_ENDPOINT | 0x80,               // bEndpointAddress
367         0x03,                                   // bmAttributes (0x03=intr)
368         KEYBOARD_SIZE, 0,                       // wMaxPacketSize
369         KEYBOARD_INTERVAL,                      // bInterval
370
371 // --- NKRO Keyboard HID --- OS Mode Keyboard Interface
372 // - 9 bytes -
373         // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
374         9,                                      // bLength
375         4,                                      // bDescriptorType
376         NKRO_KEYBOARD_INTERFACE,                // bInterfaceNumber
377         0,                                      // bAlternateSetting
378         1,                                      // bNumEndpoints
379         0x03,                                   // bInterfaceClass (0x03 = HID)
380         0x00,                                   // bInterfaceSubClass (0x00 = Non-Boot, 0x01 = Boot)
381         0x01,                                   // bInterfaceProtocol (0x01 = Keyboard)
382         0,                                      // iInterface
383 // - 9 bytes -
384         // HID interface descriptor, HID 1.11 spec, section 6.2.1
385         9,                                      // bLength
386         0x21,                                   // bDescriptorType
387         0x11, 0x01,                             // bcdHID
388         0,                                      // bCountryCode
389         1,                                      // bNumDescriptors
390         0x22,                                   // bDescriptorType
391         LSB(sizeof(nkro_keyboard_report_desc)), // wDescriptorLength
392         MSB(sizeof(nkro_keyboard_report_desc)),
393 // - 7 bytes -
394         // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
395         7,                                      // bLength
396         5,                                      // bDescriptorType
397         NKRO_KEYBOARD_ENDPOINT | 0x80,          // bEndpointAddress
398         0x03,                                   // bmAttributes (0x03=intr)
399         NKRO_KEYBOARD_SIZE, 0,                  // wMaxPacketSize
400         NKRO_KEYBOARD_INTERVAL,                 // bInterval
401
402 // --- Serial CDC --- CDC IAD Descriptor
403 // - 8 bytes -
404         // interface association descriptor, USB ECN, Table 9-Z
405         8,                                      // bLength
406         11,                                     // bDescriptorType
407         CDC_STATUS_INTERFACE,                   // bFirstInterface
408         2,                                      // bInterfaceCount
409         0x02,                                   // bFunctionClass
410         0x02,                                   // bFunctionSubClass
411         0x01,                                   // bFunctionProtocol
412         0,                                      // iFunction
413
414 // --- Serial CDC --- CDC Data Interface
415 // - 9 bytes -
416         // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
417         9,                                      // bLength
418         4,                                      // bDescriptorType
419         CDC_STATUS_INTERFACE,                   // bInterfaceNumber
420         0,                                      // bAlternateSetting
421         1,                                      // bNumEndpoints
422         0x02,                                   // bInterfaceClass
423         0x02,                                   // bInterfaceSubClass
424         0x01,                                   // bInterfaceProtocol
425         0,                                      // iInterface
426 // - 5 bytes -
427         // CDC Header Functional Descriptor, CDC Spec 5.2.3.1, Table 26
428         5,                                      // bFunctionLength
429         0x24,                                   // bDescriptorType
430         0x00,                                   // bDescriptorSubtype
431         0x10, 0x01,                             // bcdCDC
432 // - 5 bytes -
433         // Call Management Functional Descriptor, CDC Spec 5.2.3.2, Table 27
434         5,                                      // bFunctionLength
435         0x24,                                   // bDescriptorType
436         0x01,                                   // bDescriptorSubtype
437         0x01,                                   // bmCapabilities
438         1,                                      // bDataInterface
439 // - 4 bytes -
440         // Abstract Control Management Functional Descriptor, CDC Spec 5.2.3.3, Table 28
441         4,                                      // bFunctionLength
442         0x24,                                   // bDescriptorType
443         0x02,                                   // bDescriptorSubtype
444         0x06,                                   // bmCapabilities
445 // - 5 bytes -
446         // Union Functional Descriptor, CDC Spec 5.2.3.8, Table 33
447         5,                                      // bFunctionLength
448         0x24,                                   // bDescriptorType
449         0x06,                                   // bDescriptorSubtype
450         CDC_STATUS_INTERFACE,                   // bMasterInterface
451         CDC_DATA_INTERFACE,                     // bSlaveInterface0
452 // - 7 bytes -
453         // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
454         7,                                      // bLength
455         5,                                      // bDescriptorType
456         CDC_ACM_ENDPOINT | 0x80,                // bEndpointAddress
457         0x03,                                   // bmAttributes (0x03=intr)
458         CDC_ACM_SIZE, 0,                        // wMaxPacketSize
459         64,                                     // bInterval
460 // - 9 bytes -
461         // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
462         9,                                      // bLength
463         4,                                      // bDescriptorType
464         CDC_DATA_INTERFACE,                     // bInterfaceNumber
465         0,                                      // bAlternateSetting
466         2,                                      // bNumEndpoints
467         0x0A,                                   // bInterfaceClass
468         0x00,                                   // bInterfaceSubClass
469         0x00,                                   // bInterfaceProtocol
470         0,                                      // iInterface
471 // - 7 bytes -
472         // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
473         7,                                      // bLength
474         5,                                      // bDescriptorType
475         CDC_RX_ENDPOINT,                        // bEndpointAddress
476         0x02,                                   // bmAttributes (0x02=bulk)
477         CDC_RX_SIZE, 0,                         // wMaxPacketSize
478         0,                                      // bInterval
479 // - 7 bytes -
480         // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
481         7,                                      // bLength
482         5,                                      // bDescriptorType
483         CDC_TX_ENDPOINT | 0x80,                 // bEndpointAddress
484         0x02,                                   // bmAttributes (0x02=bulk)
485         CDC_TX_SIZE, 0,                         // wMaxPacketSize
486         0,                                      // bInterval
487
488 /*
489 // Mouse Interface
490 // - 9 bytes -
491         // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
492         9,                                      // bLength
493         4,                                      // bDescriptorType
494         MOUSE_INTERFACE,                        // bInterfaceNumber
495         0,                                      // bAlternateSetting
496         1,                                      // bNumEndpoints
497         0x03,                                   // bInterfaceClass (0x03 = HID)
498         0x00,                                   // bInterfaceSubClass (0x01 = Boot)
499         0x00,                                   // bInterfaceProtocol (0x02 = Mouse)
500         0,                                      // iInterface
501 // - 9 bytes -
502         // HID interface descriptor, HID 1.11 spec, section 6.2.1
503         9,                                      // bLength
504         0x21,                                   // bDescriptorType
505         0x11, 0x01,                             // bcdHID
506         0,                                      // bCountryCode
507         1,                                      // bNumDescriptors
508         0x22,                                   // bDescriptorType
509         LSB(sizeof(mouse_report_desc)),         // wDescriptorLength
510         MSB(sizeof(mouse_report_desc)),
511 // - 7 bytes -
512         // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
513         7,                                      // bLength
514         5,                                      // bDescriptorType
515         MOUSE_ENDPOINT | 0x80,                  // bEndpointAddress
516         0x03,                                   // bmAttributes (0x03=intr)
517         MOUSE_SIZE, 0,                          // wMaxPacketSize
518         MOUSE_INTERVAL,                         // bInterval
519 #endif // MOUSE_INTERFACE
520 */
521 };
522
523
524
525 // ----- String Descriptors -----
526
527 // The descriptors above can provide human readable strings,
528 // referenced by index numbers.  These descriptors are the
529 // actual string data
530
531 struct usb_string_descriptor_struct {
532         uint8_t bLength;
533         uint8_t bDescriptorType;
534         uint16_t wString[];
535 };
536
537 extern struct usb_string_descriptor_struct usb_string_manufacturer_name
538         __attribute__ ((weak, alias("usb_string_manufacturer_name_default")));
539 extern struct usb_string_descriptor_struct usb_string_product_name
540         __attribute__ ((weak, alias("usb_string_product_name_default")));
541 extern struct usb_string_descriptor_struct usb_string_serial_number
542         __attribute__ ((weak, alias("usb_string_serial_number_default")));
543
544 struct usb_string_descriptor_struct string0 = {
545         4,
546         3,
547         {0x0409}
548 };
549
550 struct usb_string_descriptor_struct usb_string_manufacturer_name_default = {
551         sizeof(STR_MANUFACTURER),
552         3,
553         STR_MANUFACTURER
554 };
555 struct usb_string_descriptor_struct usb_string_product_name_default = {
556         sizeof(STR_PRODUCT),
557         3,
558         STR_PRODUCT
559 };
560 struct usb_string_descriptor_struct usb_string_serial_number_default = {
561         sizeof(STR_SERIAL),
562         3,
563         STR_SERIAL
564 };
565
566
567
568 // ----- Descriptors List -----
569
570 // This table provides access to all the descriptor data above.
571
572 const usb_descriptor_list_t usb_descriptor_list[] = {
573         //wValue, wIndex, address,          length
574         {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
575         {0x0200, 0x0000, config_descriptor, sizeof(config_descriptor)},
576         {0x0600, 0x0000, device_qualifier_descriptor, sizeof(device_qualifier_descriptor)},
577         {0x0A00, 0x0000, usb_debug_descriptor, sizeof(usb_debug_descriptor)},
578         {0x2200, KEYBOARD_INTERFACE, keyboard_report_desc, sizeof(keyboard_report_desc)},
579         {0x2100, KEYBOARD_INTERFACE, config_descriptor + KEYBOARD_DESC_OFFSET, 9},
580         {0x2200, NKRO_KEYBOARD_INTERFACE, nkro_keyboard_report_desc, sizeof(nkro_keyboard_report_desc)},
581         {0x2100, NKRO_KEYBOARD_INTERFACE, config_descriptor + NKRO_KEYBOARD_DESC_OFFSET, 9},
582 /* MOUSE
583         {0x2200, MOUSE_INTERFACE, mouse_report_desc, sizeof(mouse_report_desc)},
584         {0x2100, MOUSE_INTERFACE, config_descriptor+MOUSE_DESC_OFFSET, 9},
585 */
586         {0x0300, 0x0000, (const uint8_t *)&string0, 0},
587         {0x0301, 0x0409, (const uint8_t *)&usb_string_manufacturer_name, 0},
588         {0x0302, 0x0409, (const uint8_t *)&usb_string_product_name, 0},
589         {0x0303, 0x0409, (const uint8_t *)&usb_string_serial_number, 0},
590         {0, 0, NULL, 0}
591 };
592
593
594
595 // ----- Endpoint Configuration -----
596
597 // See usb_desc.h for Endpoint configuration
598 // 0x00 = not used
599 // 0x19 = Recieve only
600 // 0x15 = Transmit only
601 // 0x1D = Transmit & Recieve
602 //
603 const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
604 {
605 #if (defined(ENDPOINT1_CONFIG) && NUM_ENDPOINTS >= 1)
606         ENDPOINT1_CONFIG,
607 #elif (NUM_ENDPOINTS >= 1)
608         ENDPOINT_UNUSED,
609 #endif
610 #if (defined(ENDPOINT2_CONFIG) && NUM_ENDPOINTS >= 2)
611         ENDPOINT2_CONFIG,
612 #elif (NUM_ENDPOINTS >= 2)
613         ENDPOINT_UNUSED,
614 #endif
615 #if (defined(ENDPOINT3_CONFIG) && NUM_ENDPOINTS >= 3)
616         ENDPOINT3_CONFIG,
617 #elif (NUM_ENDPOINTS >= 3)
618         ENDPOINT_UNUSED,
619 #endif
620 #if (defined(ENDPOINT4_CONFIG) && NUM_ENDPOINTS >= 4)
621         ENDPOINT4_CONFIG,
622 #elif (NUM_ENDPOINTS >= 4)
623         ENDPOINT_UNUSED,
624 #endif
625 #if (defined(ENDPOINT5_CONFIG) && NUM_ENDPOINTS >= 5)
626         ENDPOINT5_CONFIG,
627 #elif (NUM_ENDPOINTS >= 5)
628         ENDPOINT_UNUSED,
629 #endif
630 #if (defined(ENDPOINT6_CONFIG) && NUM_ENDPOINTS >= 6)
631         ENDPOINT6_CONFIG,
632 #elif (NUM_ENDPOINTS >= 6)
633         ENDPOINT_UNUSED,
634 #endif
635 #if (defined(ENDPOINT7_CONFIG) && NUM_ENDPOINTS >= 7)
636         ENDPOINT7_CONFIG,
637 #elif (NUM_ENDPOINTS >= 7)
638         ENDPOINT_UNUSED,
639 #endif
640 #if (defined(ENDPOINT8_CONFIG) && NUM_ENDPOINTS >= 8)
641         ENDPOINT8_CONFIG,
642 #elif (NUM_ENDPOINTS >= 8)
643         ENDPOINT_UNUSED,
644 #endif
645 #if (defined(ENDPOINT9_CONFIG) && NUM_ENDPOINTS >= 9)
646         ENDPOINT9_CONFIG,
647 #elif (NUM_ENDPOINTS >= 9)
648         ENDPOINT_UNUSED,
649 #endif
650 #if (defined(ENDPOINT10_CONFIG) && NUM_ENDPOINTS >= 10)
651         ENDPOINT10_CONFIG,
652 #elif (NUM_ENDPOINTS >= 10)
653         ENDPOINT_UNUSED,
654 #endif
655 #if (defined(ENDPOINT11_CONFIG) && NUM_ENDPOINTS >= 11)
656         ENDPOINT11_CONFIG,
657 #elif (NUM_ENDPOINTS >= 11)
658         ENDPOINT_UNUSED,
659 #endif
660 #if (defined(ENDPOINT12_CONFIG) && NUM_ENDPOINTS >= 12)
661         ENDPOINT12_CONFIG,
662 #elif (NUM_ENDPOINTS >= 12)
663         ENDPOINT_UNUSED,
664 #endif
665 #if (defined(ENDPOINT13_CONFIG) && NUM_ENDPOINTS >= 13)
666         ENDPOINT13_CONFIG,
667 #elif (NUM_ENDPOINTS >= 13)
668         ENDPOINT_UNUSED,
669 #endif
670 #if (defined(ENDPOINT14_CONFIG) && NUM_ENDPOINTS >= 14)
671         ENDPOINT14_CONFIG,
672 #elif (NUM_ENDPOINTS >= 14)
673         ENDPOINT_UNUSED,
674 #endif
675 #if (defined(ENDPOINT15_CONFIG) && NUM_ENDPOINTS >= 15)
676         ENDPOINT15_CONFIG,
677 #elif (NUM_ENDPOINTS >= 15)
678         ENDPOINT_UNUSED,
679 #endif
680 };
681