]> git.donarmstrong.com Git - kiibohd-controller.git/blob - Output/pjrcUSB/arm/usb_desc.c
0a44d5cb32ff6375439fba333a6d6a3129869260
[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         // LED Report
157         0x85, 0x01,          //   Report ID (1),
158         0x75, 0x01,          //   Report Size (1),
159         0x95, 0x05,          //   Report Count (5),
160         0x05, 0x08,          //   Usage Page (LEDs),
161         0x19, 0x01,          //   Usage Minimum (1),
162         0x29, 0x05,          //   Usage Maximum (5),
163         0x91, 0x02,          //   Output (Data, Variable, Absolute),
164
165         // LED Report Padding
166         0x75, 0x03,          //   Report Size (3),
167         0x95, 0x01,          //   Report Count (1),
168         0x91, 0x03,          //   Output (Constant),
169
170         // Normal Keys - Using an NKRO Bitmap
171         //
172         // NOTES:
173         // Supports all keys defined by the spec, except 1-3 which define error events
174         //  and 0 which is "no keys pressed"
175         // See http://www.usb.org/developers/hidpage/Hut1_12v2.pdf Chapter 10
176         // Or Macros/PartialMap/usb_hid.h
177         //
178         // 50 (ISO \ due to \ bug) and 156 (Clear due to Delete bug) must be excluded
179         //  due to a Linux bug with bitmaps (not useful anyways)
180         // 165-175 are reserved/unused as well as 222-223 and 232-65535
181         //
182         // Compatibility Notes:
183         //  - Using a second endpoint for a boot mode device helps with compatibility
184         //  - DO NOT use Padding in the descriptor for bitfields
185         //    (Mac OSX silently fails... Windows/Linux work correctly)
186         //  - DO NOT use Report IDs, Windows 8.1 will not update keyboard correctly (modifiers disappear)
187         //    (all other OSs, including OSX work fine...)
188         //    (you can use them *iff* you only have 1 per collection)
189         //  - Mac OSX and Windows 8.1 are extremely picky about padding
190         //
191         // Packing of bitmaps are as follows:
192         //   4-49  :  6 bytes (0x04-0x31) ( 46 bits + 2 padding bits for 6 bytes total)
193         //  51-155 : 14 bytes (0x33-0x9B) (105 bits + 6 padding bits for 15 bytes total)
194         // 157-164 :  1 byte  (0x9D-0xA4) (  8 bits)
195         // 176-221 :  6 bytes (0xB0-0xDD) ( 46 bits + 2 padding bits for 6 bytes total)
196         // 224-231 :  1 byte  (0xE0-0xE7) (  8 bits)
197
198         // Modifier Byte
199         0x75, 0x01,          //   Report Size (1),
200         0x95, 0x08,          //   Report Count (8),
201         0x15, 0x00,          //   Logical Minimum (0),
202         0x25, 0x01,          //   Logical Maximum (1),
203         0x05, 0x07,          //   Usage Page (Key Codes),
204         0x19, 0xE0,          //   Usage Minimum (224),
205         0x29, 0xE7,          //   Usage Maximum (231),
206         0x81, 0x02,          //   Input (Data, Variable, Absolute),
207
208         // 4-49 (6 bytes/46 bits) - MainKeys
209         0x75, 0x01,          //   Report Size (1),
210         0x95, 0x2E,          //   Report Count (46),
211         0x15, 0x00,          //   Logical Minimum (0),
212         0x25, 0x01,          //   Logical Maximum (1),
213         0x05, 0x07,          //   Usage Page (Key Codes),
214         0x19, 0x04,          //   Usage Minimum (4),
215         0x29, 0x31,          //   Usage Maximum (49),
216         0x81, 0x02,          //   Input (Data, Variable, Absolute, Bitfield),
217
218         // Padding (2 bits)
219         0x75, 0x02,          //   Report Size (2),
220         0x95, 0x01,          //   Report Count (1),
221         0x81, 0x03,          //   Input (Constant),
222
223         // 51-155 (14 bytes/105 bits) - SecondaryKeys
224         0x75, 0x01,          //   Report Size (1),
225         0x95, 0x69,          //   Report Count (105),
226         0x15, 0x00,          //   Logical Minimum (0),
227         0x25, 0x01,          //   Logical Maximum (1),
228         0x05, 0x07,          //   Usage Page (Key Codes),
229         0x19, 0x33,          //   Usage Minimum (51),
230         0x29, 0x9B,          //   Usage Maximum (155),
231         0x81, 0x02,          //   Input (Data, Variable, Absolute, Bitfield),
232
233         // Padding (7 bits)
234         0x75, 0x07,          //   Report Size (7),
235         0x95, 0x01,          //   Report Count (1),
236         0x81, 0x03,          //   Input (Constant),
237
238         // 157-164 (1 byte/8 bits) - TertiaryKeys
239         0x75, 0x01,          //   Report Size (1),
240         0x95, 0x08,          //   Report Count (8),
241         0x15, 0x00,          //   Logical Minimum (0),
242         0x25, 0x01,          //   Logical Maximum (1),
243         0x05, 0x07,          //   Usage Page (Key Codes),
244         0x19, 0x9D,          //   Usage Minimum (157),
245         0x29, 0xA4,          //   Usage Maximum (164),
246         0x81, 0x02,          //   Input (Data, Variable, Absolute, Bitfield),
247
248         // 176-221 (6 bytes/46 bits) - QuartiaryKeys
249         0x75, 0x01,          //   Report Size (1),
250         0x95, 0x2E,          //   Report Count (46),
251         0x15, 0x00,          //   Logical Minimum (0),
252         0x25, 0x01,          //   Logical Maximum (1),
253         0x05, 0x07,          //   Usage Page (Key Codes),
254         0x19, 0xB0,          //   Usage Minimum (176),
255         0x29, 0xDD,          //   Usage Maximum (221),
256         0x81, 0x02,          //   Input (Data, Variable, Absolute, Bitfield),
257
258         // Padding (2 bits)
259         0x75, 0x02,          //   Report Size (2),
260         0x95, 0x01,          //   Report Count (1),
261         0x81, 0x03,          //   Input (Constant),
262         0xc0,                // End Collection - Keyboard
263
264         // System Control Collection
265         //
266         // NOTES:
267         // Not bothering with NKRO for this table. If there's need, I can implement it. -HaaTa
268         // Using a 1KRO scheme
269         0x05, 0x01,          // Usage Page (Generic Desktop),
270         0x09, 0x80,          // Usage (System Control),
271         0xA1, 0x01,          // Collection (Application),
272         0x85, 0x02,          //   Report ID (2),
273         0x75, 0x08,          //   Report Size (8),
274         0x95, 0x01,          //   Report Count (1),
275         0x16, 0x81, 0x00,    //   Logical Minimum (129),
276         0x26, 0xB7, 0x00,    //   Logical Maximum (183),
277         0x19, 0x81,          //   Usage Minimum (129),
278         0x29, 0xB7,          //   Usage Maximum (183),
279         0x81, 0x00,          //   Input (Data, Array),
280         0xc0,                // End Collection - System Control
281
282         // Consumer Control Collection - Media Keys
283         //
284         // NOTES:
285         // Not bothering with NKRO for this table. If there's a need, I can implement it. -HaaTa
286         // Using a 1KRO scheme
287         0x05, 0x0c,          // Usage Page (Consumer),
288         0x09, 0x01,          // Usage (Consumer Control),
289         0xA1, 0x01,          // Collection (Application),
290         0x85, 0x03,          //   Report ID (3),
291         0x75, 0x10,          //   Report Size (16),
292         0x95, 0x01,          //   Report Count (1),
293         0x16, 0x20, 0x00,    //   Logical Minimum (32),
294         0x26, 0x9C, 0x02,    //   Logical Maximum (668),
295         0x05, 0x0C,          //   Usage Page (Consumer),
296         0x19, 0x20,          //   Usage Minimum (32),
297         0x2A, 0x9C, 0x02,    //   Usage Maximum (668),
298         0x81, 0x00,          //   Input (Data, Array),
299         0xc0,                // End Collection - Consumer Control
300 };
301
302 /* MOUSE
303 // Mouse Protocol 1, HID 1.11 spec, Appendix B, page 59-60, with wheel extension
304 static uint8_t mouse_report_desc[] = {
305         0x05, 0x01,                     // Usage Page (Generic Desktop)
306         0x09, 0x02,                     // Usage (Mouse)
307         0xA1, 0x01,                     // Collection (Application)
308         0x05, 0x09,                     //   Usage Page (Button)
309         0x19, 0x01,                     //   Usage Minimum (Button #1)
310         0x29, 0x03,                     //   Usage Maximum (Button #3)
311         0x15, 0x00,                     //   Logical Minimum (0)
312         0x25, 0x01,                     //   Logical Maximum (1)
313         0x95, 0x03,                     //   Report Count (3)
314         0x75, 0x01,                     //   Report Size (1)
315         0x81, 0x02,                     //   Input (Data, Variable, Absolute)
316         0x95, 0x01,                     //   Report Count (1)
317         0x75, 0x05,                     //   Report Size (5)
318         0x81, 0x03,                     //   Input (Constant)
319         0x05, 0x01,                     //   Usage Page (Generic Desktop)
320         0x09, 0x30,                     //   Usage (X)
321         0x09, 0x31,                     //   Usage (Y)
322         0x15, 0x00,                     //   Logical Minimum (0)
323         0x26, 0xFF, 0x7F,               //   Logical Maximum (32767)
324         0x75, 0x10,                     //   Report Size (16),
325         0x95, 0x02,                     //   Report Count (2),
326         0x81, 0x02,                     //   Input (Data, Variable, Absolute)
327         0x09, 0x38,                     //   Usage (Wheel)
328         0x15, 0x81,                     //   Logical Minimum (-127)
329         0x25, 0x7F,                     //   Logical Maximum (127)
330         0x75, 0x08,                     //   Report Size (8),
331         0x95, 0x01,                     //   Report Count (1),
332         0x81, 0x06,                     //   Input (Data, Variable, Relative)
333         0xC0                            // End Collection
334 };
335 */
336
337
338
339 // ----- USB Configuration -----
340
341 // USB Configuration Descriptor.  This huge descriptor tells all
342 // of the devices capbilities.
343 static uint8_t config_descriptor[CONFIG_DESC_SIZE] = {
344 // --- Configuration ---
345 // - 9 bytes -
346         // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
347         9,                                      // bLength;
348         2,                                      // bDescriptorType;
349         LSB(CONFIG_DESC_SIZE),                  // wTotalLength
350         MSB(CONFIG_DESC_SIZE),
351         NUM_INTERFACE,                          // bNumInterfaces
352         1,                                      // bConfigurationValue
353         0,                                      // iConfiguration
354         0xA0,                                   // bmAttributes
355         250,                                    // bMaxPower
356
357 // --- Keyboard HID --- Boot Mode Keyboard Interface
358 // - 9 bytes -
359         // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
360         9,                                      // bLength
361         4,                                      // bDescriptorType
362         KEYBOARD_INTERFACE,                     // bInterfaceNumber
363         0,                                      // bAlternateSetting
364         1,                                      // bNumEndpoints
365         0x03,                                   // bInterfaceClass (0x03 = HID)
366         0x01,                                   // bInterfaceSubClass (0x00 = Non-Boot, 0x01 = Boot)
367         0x01,                                   // bInterfaceProtocol (0x01 = Keyboard)
368         0,                                      // iInterface
369 // - 9 bytes -
370         // HID interface descriptor, HID 1.11 spec, section 6.2.1
371         9,                                      // bLength
372         0x21,                                   // bDescriptorType
373         0x11, 0x01,                             // bcdHID
374         0,                                      // bCountryCode
375         1,                                      // bNumDescriptors
376         0x22,                                   // bDescriptorType
377         LSB(sizeof(keyboard_report_desc)),      // wDescriptorLength
378         MSB(sizeof(keyboard_report_desc)),
379 // - 7 bytes -
380         // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
381         7,                                      // bLength
382         5,                                      // bDescriptorType
383         KEYBOARD_ENDPOINT | 0x80,               // bEndpointAddress
384         0x03,                                   // bmAttributes (0x03=intr)
385         KEYBOARD_SIZE, 0,                       // wMaxPacketSize
386         KEYBOARD_INTERVAL,                      // bInterval
387
388 // --- NKRO Keyboard HID --- OS Mode Keyboard Interface
389 // - 9 bytes -
390         // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
391         9,                                      // bLength
392         4,                                      // bDescriptorType
393         NKRO_KEYBOARD_INTERFACE,                // bInterfaceNumber
394         0,                                      // bAlternateSetting
395         1,                                      // bNumEndpoints
396         0x03,                                   // bInterfaceClass (0x03 = HID)
397         0x00,                                   // bInterfaceSubClass (0x00 = Non-Boot, 0x01 = Boot)
398         0x01,                                   // bInterfaceProtocol (0x01 = Keyboard)
399         0,                                      // iInterface
400 // - 9 bytes -
401         // HID interface descriptor, HID 1.11 spec, section 6.2.1
402         9,                                      // bLength
403         0x21,                                   // bDescriptorType
404         0x11, 0x01,                             // bcdHID
405         0,                                      // bCountryCode
406         1,                                      // bNumDescriptors
407         0x22,                                   // bDescriptorType
408         LSB(sizeof(nkro_keyboard_report_desc)), // wDescriptorLength
409         MSB(sizeof(nkro_keyboard_report_desc)),
410 // - 7 bytes -
411         // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
412         7,                                      // bLength
413         5,                                      // bDescriptorType
414         NKRO_KEYBOARD_ENDPOINT | 0x80,          // bEndpointAddress
415         0x03,                                   // bmAttributes (0x03=intr)
416         NKRO_KEYBOARD_SIZE, 0,                  // wMaxPacketSize
417         NKRO_KEYBOARD_INTERVAL,                 // bInterval
418
419 // --- Serial CDC --- CDC IAD Descriptor
420 // - 8 bytes -
421         // interface association descriptor, USB ECN, Table 9-Z
422         8,                                      // bLength
423         11,                                     // bDescriptorType
424         CDC_STATUS_INTERFACE,                   // bFirstInterface
425         2,                                      // bInterfaceCount
426         0x02,                                   // bFunctionClass
427         0x02,                                   // bFunctionSubClass
428         0x01,                                   // bFunctionProtocol
429         0,                                      // iFunction
430
431 // --- Serial CDC --- CDC Data Interface
432 // - 9 bytes -
433         // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
434         9,                                      // bLength
435         4,                                      // bDescriptorType
436         CDC_STATUS_INTERFACE,                   // bInterfaceNumber
437         0,                                      // bAlternateSetting
438         1,                                      // bNumEndpoints
439         0x02,                                   // bInterfaceClass
440         0x02,                                   // bInterfaceSubClass
441         0x01,                                   // bInterfaceProtocol
442         0,                                      // iInterface
443 // - 5 bytes -
444         // CDC Header Functional Descriptor, CDC Spec 5.2.3.1, Table 26
445         5,                                      // bFunctionLength
446         0x24,                                   // bDescriptorType
447         0x00,                                   // bDescriptorSubtype
448         0x10, 0x01,                             // bcdCDC
449 // - 5 bytes -
450         // Call Management Functional Descriptor, CDC Spec 5.2.3.2, Table 27
451         5,                                      // bFunctionLength
452         0x24,                                   // bDescriptorType
453         0x01,                                   // bDescriptorSubtype
454         0x01,                                   // bmCapabilities
455         CDC_DATA_INTERFACE,                     // bDataInterface
456 // - 4 bytes -
457         // Abstract Control Management Functional Descriptor, CDC Spec 5.2.3.3, Table 28
458         4,                                      // bFunctionLength
459         0x24,                                   // bDescriptorType
460         0x02,                                   // bDescriptorSubtype
461         0x06,                                   // bmCapabilities
462 // - 5 bytes -
463         // Union Functional Descriptor, CDC Spec 5.2.3.8, Table 33
464         5,                                      // bFunctionLength
465         0x24,                                   // bDescriptorType
466         0x06,                                   // bDescriptorSubtype
467         CDC_STATUS_INTERFACE,                   // bMasterInterface
468         CDC_DATA_INTERFACE,                     // bSlaveInterface0
469 // - 7 bytes -
470         // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
471         7,                                      // bLength
472         5,                                      // bDescriptorType
473         CDC_ACM_ENDPOINT | 0x80,                // bEndpointAddress
474         0x03,                                   // bmAttributes (0x03=intr)
475         CDC_ACM_SIZE, 0,                        // wMaxPacketSize
476         64,                                     // bInterval
477 // - 9 bytes -
478         // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
479         9,                                      // bLength
480         4,                                      // bDescriptorType
481         CDC_DATA_INTERFACE,                     // bInterfaceNumber
482         0,                                      // bAlternateSetting
483         2,                                      // bNumEndpoints
484         0x0A,                                   // bInterfaceClass
485         0x00,                                   // bInterfaceSubClass
486         0x00,                                   // bInterfaceProtocol
487         0,                                      // iInterface
488 // - 7 bytes -
489         // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
490         7,                                      // bLength
491         5,                                      // bDescriptorType
492         CDC_RX_ENDPOINT,                        // bEndpointAddress
493         0x02,                                   // bmAttributes (0x02=bulk)
494         CDC_RX_SIZE, 0,                         // wMaxPacketSize
495         0,                                      // bInterval
496 // - 7 bytes -
497         // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
498         7,                                      // bLength
499         5,                                      // bDescriptorType
500         CDC_TX_ENDPOINT | 0x80,                 // bEndpointAddress
501         0x02,                                   // bmAttributes (0x02=bulk)
502         CDC_TX_SIZE, 0,                         // wMaxPacketSize
503         0,                                      // bInterval
504
505 /*
506 // Mouse Interface
507 // - 9 bytes -
508         // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
509         9,                                      // bLength
510         4,                                      // bDescriptorType
511         MOUSE_INTERFACE,                        // bInterfaceNumber
512         0,                                      // bAlternateSetting
513         1,                                      // bNumEndpoints
514         0x03,                                   // bInterfaceClass (0x03 = HID)
515         0x00,                                   // bInterfaceSubClass (0x01 = Boot)
516         0x00,                                   // bInterfaceProtocol (0x02 = Mouse)
517         0,                                      // iInterface
518 // - 9 bytes -
519         // HID interface descriptor, HID 1.11 spec, section 6.2.1
520         9,                                      // bLength
521         0x21,                                   // bDescriptorType
522         0x11, 0x01,                             // bcdHID
523         0,                                      // bCountryCode
524         1,                                      // bNumDescriptors
525         0x22,                                   // bDescriptorType
526         LSB(sizeof(mouse_report_desc)),         // wDescriptorLength
527         MSB(sizeof(mouse_report_desc)),
528 // - 7 bytes -
529         // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
530         7,                                      // bLength
531         5,                                      // bDescriptorType
532         MOUSE_ENDPOINT | 0x80,                  // bEndpointAddress
533         0x03,                                   // bmAttributes (0x03=intr)
534         MOUSE_SIZE, 0,                          // wMaxPacketSize
535         MOUSE_INTERVAL,                         // bInterval
536 #endif // MOUSE_INTERFACE
537 */
538 };
539
540
541
542 // ----- String Descriptors -----
543
544 // The descriptors above can provide human readable strings,
545 // referenced by index numbers.  These descriptors are the
546 // actual string data
547
548 struct usb_string_descriptor_struct {
549         uint8_t bLength;
550         uint8_t bDescriptorType;
551         uint16_t wString[];
552 };
553
554 extern struct usb_string_descriptor_struct usb_string_manufacturer_name
555         __attribute__ ((weak, alias("usb_string_manufacturer_name_default")));
556 extern struct usb_string_descriptor_struct usb_string_product_name
557         __attribute__ ((weak, alias("usb_string_product_name_default")));
558 extern struct usb_string_descriptor_struct usb_string_serial_number
559         __attribute__ ((weak, alias("usb_string_serial_number_default")));
560
561 struct usb_string_descriptor_struct string0 = {
562         4,
563         3,
564         {0x0409}
565 };
566
567 struct usb_string_descriptor_struct usb_string_manufacturer_name_default = {
568         sizeof(STR_MANUFACTURER),
569         3,
570         {STR_MANUFACTURER}
571 };
572 struct usb_string_descriptor_struct usb_string_product_name_default = {
573         sizeof(STR_PRODUCT),
574         3,
575         {STR_PRODUCT}
576 };
577 struct usb_string_descriptor_struct usb_string_serial_number_default = {
578         sizeof(STR_SERIAL),
579         3,
580         {STR_SERIAL}
581 };
582
583
584
585 // ----- Descriptors List -----
586
587 // This table provides access to all the descriptor data above.
588
589 const usb_descriptor_list_t usb_descriptor_list[] = {
590         //wValue, wIndex, address,          length
591         {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
592         {0x0200, 0x0000, config_descriptor, sizeof(config_descriptor)},
593         {0x0600, 0x0000, device_qualifier_descriptor, sizeof(device_qualifier_descriptor)},
594         {0x0A00, 0x0000, usb_debug_descriptor, sizeof(usb_debug_descriptor)},
595         {0x2200, KEYBOARD_INTERFACE, keyboard_report_desc, sizeof(keyboard_report_desc)},
596         {0x2100, KEYBOARD_INTERFACE, config_descriptor + KEYBOARD_DESC_OFFSET, 9},
597         {0x2200, NKRO_KEYBOARD_INTERFACE, nkro_keyboard_report_desc, sizeof(nkro_keyboard_report_desc)},
598         {0x2100, NKRO_KEYBOARD_INTERFACE, config_descriptor + NKRO_KEYBOARD_DESC_OFFSET, 9},
599 /* MOUSE
600         {0x2200, MOUSE_INTERFACE, mouse_report_desc, sizeof(mouse_report_desc)},
601         {0x2100, MOUSE_INTERFACE, config_descriptor+MOUSE_DESC_OFFSET, 9},
602 */
603         {0x0300, 0x0000, (const uint8_t *)&string0, 0},
604         {0x0301, 0x0409, (const uint8_t *)&usb_string_manufacturer_name, 0},
605         {0x0302, 0x0409, (const uint8_t *)&usb_string_product_name, 0},
606         {0x0303, 0x0409, (const uint8_t *)&usb_string_serial_number, 0},
607         {0, 0, NULL, 0}
608 };
609
610
611
612 // ----- Endpoint Configuration -----
613
614 // See usb_desc.h for Endpoint configuration
615 // 0x00 = not used
616 // 0x19 = Recieve only
617 // 0x15 = Transmit only
618 // 0x1D = Transmit & Recieve
619 //
620 const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
621 {
622 #if (defined(ENDPOINT1_CONFIG) && NUM_ENDPOINTS >= 1)
623         ENDPOINT1_CONFIG,
624 #elif (NUM_ENDPOINTS >= 1)
625         ENDPOINT_UNUSED,
626 #endif
627 #if (defined(ENDPOINT2_CONFIG) && NUM_ENDPOINTS >= 2)
628         ENDPOINT2_CONFIG,
629 #elif (NUM_ENDPOINTS >= 2)
630         ENDPOINT_UNUSED,
631 #endif
632 #if (defined(ENDPOINT3_CONFIG) && NUM_ENDPOINTS >= 3)
633         ENDPOINT3_CONFIG,
634 #elif (NUM_ENDPOINTS >= 3)
635         ENDPOINT_UNUSED,
636 #endif
637 #if (defined(ENDPOINT4_CONFIG) && NUM_ENDPOINTS >= 4)
638         ENDPOINT4_CONFIG,
639 #elif (NUM_ENDPOINTS >= 4)
640         ENDPOINT_UNUSED,
641 #endif
642 #if (defined(ENDPOINT5_CONFIG) && NUM_ENDPOINTS >= 5)
643         ENDPOINT5_CONFIG,
644 #elif (NUM_ENDPOINTS >= 5)
645         ENDPOINT_UNUSED,
646 #endif
647 #if (defined(ENDPOINT6_CONFIG) && NUM_ENDPOINTS >= 6)
648         ENDPOINT6_CONFIG,
649 #elif (NUM_ENDPOINTS >= 6)
650         ENDPOINT_UNUSED,
651 #endif
652 #if (defined(ENDPOINT7_CONFIG) && NUM_ENDPOINTS >= 7)
653         ENDPOINT7_CONFIG,
654 #elif (NUM_ENDPOINTS >= 7)
655         ENDPOINT_UNUSED,
656 #endif
657 #if (defined(ENDPOINT8_CONFIG) && NUM_ENDPOINTS >= 8)
658         ENDPOINT8_CONFIG,
659 #elif (NUM_ENDPOINTS >= 8)
660         ENDPOINT_UNUSED,
661 #endif
662 #if (defined(ENDPOINT9_CONFIG) && NUM_ENDPOINTS >= 9)
663         ENDPOINT9_CONFIG,
664 #elif (NUM_ENDPOINTS >= 9)
665         ENDPOINT_UNUSED,
666 #endif
667 #if (defined(ENDPOINT10_CONFIG) && NUM_ENDPOINTS >= 10)
668         ENDPOINT10_CONFIG,
669 #elif (NUM_ENDPOINTS >= 10)
670         ENDPOINT_UNUSED,
671 #endif
672 #if (defined(ENDPOINT11_CONFIG) && NUM_ENDPOINTS >= 11)
673         ENDPOINT11_CONFIG,
674 #elif (NUM_ENDPOINTS >= 11)
675         ENDPOINT_UNUSED,
676 #endif
677 #if (defined(ENDPOINT12_CONFIG) && NUM_ENDPOINTS >= 12)
678         ENDPOINT12_CONFIG,
679 #elif (NUM_ENDPOINTS >= 12)
680         ENDPOINT_UNUSED,
681 #endif
682 #if (defined(ENDPOINT13_CONFIG) && NUM_ENDPOINTS >= 13)
683         ENDPOINT13_CONFIG,
684 #elif (NUM_ENDPOINTS >= 13)
685         ENDPOINT_UNUSED,
686 #endif
687 #if (defined(ENDPOINT14_CONFIG) && NUM_ENDPOINTS >= 14)
688         ENDPOINT14_CONFIG,
689 #elif (NUM_ENDPOINTS >= 14)
690         ENDPOINT_UNUSED,
691 #endif
692 #if (defined(ENDPOINT15_CONFIG) && NUM_ENDPOINTS >= 15)
693         ENDPOINT15_CONFIG,
694 #elif (NUM_ENDPOINTS >= 15)
695         ENDPOINT_UNUSED,
696 #endif
697 };
698
699