1 /* Teensyduino Core Library
2 * http://www.pjrc.com/teensy/
3 * Copyright (c) 2013 PJRC.COM, LLC.
4 * Modified by Jacob Alexander (2013-2016)
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:
14 * 1. The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
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.
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
32 // ----- Includes -----
44 #define LSB(n) ((n) & 255)
45 #define MSB(n) (((n) >> 8) & 255)
49 // ----- USB Device Descriptor -----
51 // USB Device Descriptor. The USB host reads this first, to learn
52 // what type of device is connected.
53 static uint8_t device_descriptor[] = {
57 DEVICE_CLASS, // bDeviceClass
58 DEVICE_SUBCLASS, // bDeviceSubClass
59 DEVICE_PROTOCOL, // bDeviceProtocol
60 EP0_SIZE, // bMaxPacketSize0
61 LSB(VENDOR_ID), MSB(VENDOR_ID), // idVendor
62 LSB(PRODUCT_ID), MSB(PRODUCT_ID), // idProduct
63 0x00, 0x01, // bcdDevice
67 1 // bNumConfigurations
70 // USB Device Qualifier Descriptor
71 static uint8_t device_qualifier_descriptor[] = {
72 0 // Indicate only single speed
73 /* Device qualifier example (used for specifying multiple USB speeds)
77 DEVICE_CLASS, // bDeviceClass
78 DEVICE_SUBCLASS, // bDeviceSubClass
79 DEVICE_PROTOCOL, // bDeviceProtocol
80 EP0_SIZE, // bMaxPacketSize0
81 0, // bNumOtherSpeedConfigurations
86 // USB Debug Descriptor
87 // XXX Not sure of exact use, lsusb requests it
88 static uint8_t usb_debug_descriptor[] = {
93 // These descriptors must NOT be "const", because the USB DMA
94 // has trouble accessing flash memory with enough bandwidth
95 // while the processor is executing from flash.
100 // ----- USB HID Report Descriptors -----
102 // Each HID interface needs a special report descriptor that tells
103 // the meaning and format of the data.
105 // Keyboard Protocol 1, HID 1.11 spec, Appendix B, page 59-60
106 static uint8_t keyboard_report_desc[] = {
107 // Keyboard Collection
108 0x05, 0x01, // Usage Page (Generic Desktop),
109 0x09, 0x06, // Usage (Keyboard),
110 0xA1, 0x01, // Collection (Application) - Keyboard,
113 0x75, 0x01, // Report Size (1),
114 0x95, 0x08, // Report Count (8),
115 0x05, 0x07, // Usage Page (Key Codes),
116 0x19, 0xE0, // Usage Minimum (224),
117 0x29, 0xE7, // Usage Maximum (231),
118 0x15, 0x00, // Logical Minimum (0),
119 0x25, 0x01, // Logical Maximum (1),
120 0x81, 0x02, // Input (Data, Variable, Absolute),
123 0x75, 0x08, // Report Size (8),
124 0x95, 0x01, // Report Count (1),
125 0x81, 0x03, // Output (Constant),
128 0x75, 0x01, // Report Size (1),
129 0x95, 0x05, // Report Count (5),
130 0x05, 0x08, // Usage Page (LEDs),
131 0x19, 0x01, // Usage Minimum (1),
132 0x29, 0x05, // Usage Maximum (5),
133 0x91, 0x02, // Output (Data, Variable, Absolute),
135 // LED Report Padding
136 0x75, 0x03, // Report Size (3),
137 0x95, 0x01, // Report Count (1),
138 0x91, 0x03, // Output (Constant),
141 0x75, 0x08, // Report Size (8),
142 0x95, 0x06, // Report Count (6),
143 0x15, 0x00, // Logical Minimum (0),
144 0x25, 0x7F, // Logical Maximum(104),
145 0x05, 0x07, // Usage Page (Key Codes),
146 0x19, 0x00, // Usage Minimum (0),
147 0x29, 0x7F, // Usage Maximum (104),
148 0x81, 0x00, // Input (Data, Array),
149 0xc0, // End Collection - Keyboard
152 // Keyboard Protocol 1, HID 1.11 spec, Appendix B, page 59-60
153 static uint8_t nkro_keyboard_report_desc[] = {
154 // Keyboard Collection
155 0x05, 0x01, // Usage Page (Generic Desktop),
156 0x09, 0x06, // Usage (Keyboard),
157 0xA1, 0x01, // Collection (Application) - Keyboard,
160 0x85, 0x01, // Report ID (1),
161 0x75, 0x01, // Report Size (1),
162 0x95, 0x05, // Report Count (5),
163 0x05, 0x08, // Usage Page (LEDs),
164 0x19, 0x01, // Usage Minimum (1),
165 0x29, 0x05, // Usage Maximum (5),
166 0x91, 0x02, // Output (Data, Variable, Absolute),
168 // LED Report Padding
169 0x75, 0x03, // Report Size (3),
170 0x95, 0x01, // Report Count (1),
171 0x91, 0x03, // Output (Constant),
173 // Normal Keys - Using an NKRO Bitmap
176 // Supports all keys defined by the spec, except 1-3 which define error events
177 // and 0 which is "no keys pressed"
178 // See http://www.usb.org/developers/hidpage/Hut1_12v2.pdf Chapter 10
179 // Or Macros/PartialMap/usb_hid.h
181 // 50 (ISO \ due to \ bug) and 156 (Clear due to Delete bug) must be excluded
182 // due to a Linux bug with bitmaps (not useful anyways)
183 // 165-175 are reserved/unused as well as 222-223 and 232-65535
185 // Compatibility Notes:
186 // - Using a second endpoint for a boot mode device helps with compatibility
187 // - DO NOT use Padding in the descriptor for bitfields
188 // (Mac OSX silently fails... Windows/Linux work correctly)
189 // - DO NOT use Report IDs, Windows 8.1 will not update keyboard correctly (modifiers disappear)
190 // (all other OSs, including OSX work fine...)
191 // (you can use them *iff* you only have 1 per collection)
192 // - Mac OSX and Windows 8.1 are extremely picky about padding
194 // Packing of bitmaps are as follows:
195 // 4-49 : 6 bytes (0x04-0x31) ( 46 bits + 2 padding bits for 6 bytes total)
196 // 51-155 : 14 bytes (0x33-0x9B) (105 bits + 6 padding bits for 15 bytes total)
197 // 157-164 : 1 byte (0x9D-0xA4) ( 8 bits)
198 // 176-221 : 6 bytes (0xB0-0xDD) ( 46 bits + 2 padding bits for 6 bytes total)
199 // 224-231 : 1 byte (0xE0-0xE7) ( 8 bits)
202 0x75, 0x01, // Report Size (1),
203 0x95, 0x08, // Report Count (8),
204 0x15, 0x00, // Logical Minimum (0),
205 0x25, 0x01, // Logical Maximum (1),
206 0x05, 0x07, // Usage Page (Key Codes),
207 0x19, 0xE0, // Usage Minimum (224),
208 0x29, 0xE7, // Usage Maximum (231),
209 0x81, 0x02, // Input (Data, Variable, Absolute),
211 // 4-49 (6 bytes/46 bits) - MainKeys
212 0x75, 0x01, // Report Size (1),
213 0x95, 0x2E, // Report Count (46),
214 0x15, 0x00, // Logical Minimum (0),
215 0x25, 0x01, // Logical Maximum (1),
216 0x05, 0x07, // Usage Page (Key Codes),
217 0x19, 0x04, // Usage Minimum (4),
218 0x29, 0x31, // Usage Maximum (49),
219 0x81, 0x02, // Input (Data, Variable, Absolute, Bitfield),
222 0x75, 0x02, // Report Size (2),
223 0x95, 0x01, // Report Count (1),
224 0x81, 0x03, // Input (Constant),
226 // 51-155 (14 bytes/105 bits) - SecondaryKeys
227 0x75, 0x01, // Report Size (1),
228 0x95, 0x69, // Report Count (105),
229 0x15, 0x00, // Logical Minimum (0),
230 0x25, 0x01, // Logical Maximum (1),
231 0x05, 0x07, // Usage Page (Key Codes),
232 0x19, 0x33, // Usage Minimum (51),
233 0x29, 0x9B, // Usage Maximum (155),
234 0x81, 0x02, // Input (Data, Variable, Absolute, Bitfield),
237 0x75, 0x07, // Report Size (7),
238 0x95, 0x01, // Report Count (1),
239 0x81, 0x03, // Input (Constant),
241 // 157-164 (1 byte/8 bits) - TertiaryKeys
242 0x75, 0x01, // Report Size (1),
243 0x95, 0x08, // Report Count (8),
244 0x15, 0x00, // Logical Minimum (0),
245 0x25, 0x01, // Logical Maximum (1),
246 0x05, 0x07, // Usage Page (Key Codes),
247 0x19, 0x9D, // Usage Minimum (157),
248 0x29, 0xA4, // Usage Maximum (164),
249 0x81, 0x02, // Input (Data, Variable, Absolute, Bitfield),
251 // 176-221 (6 bytes/46 bits) - QuartiaryKeys
252 0x75, 0x01, // Report Size (1),
253 0x95, 0x2E, // Report Count (46),
254 0x15, 0x00, // Logical Minimum (0),
255 0x25, 0x01, // Logical Maximum (1),
256 0x05, 0x07, // Usage Page (Key Codes),
257 0x19, 0xB0, // Usage Minimum (176),
258 0x29, 0xDD, // Usage Maximum (221),
259 0x81, 0x02, // Input (Data, Variable, Absolute, Bitfield),
262 0x75, 0x02, // Report Size (2),
263 0x95, 0x01, // Report Count (1),
264 0x81, 0x03, // Input (Constant),
265 0xc0, // End Collection - Keyboard
268 // System Control and Consumer Control
269 static uint8_t sys_ctrl_report_desc[] = {
270 // System Control Collection (8 bits)
273 // Not bothering with NKRO for this table. If there's need, I can implement it. -HaaTa
274 // Using a 1KRO scheme
275 0x05, 0x01, // Usage Page (Generic Desktop),
276 0x09, 0x80, // Usage (System Control),
277 0xA1, 0x01, // Collection (Application),
278 0x85, 0x02, // Report ID (2),
279 0x75, 0x08, // Report Size (8),
280 0x95, 0x01, // Report Count (1),
281 0x16, 0x81, 0x00, // Logical Minimum (129),
282 0x26, 0xB7, 0x00, // Logical Maximum (183),
283 0x19, 0x81, // Usage Minimum (129),
284 0x29, 0xB7, // Usage Maximum (183),
285 0x81, 0x00, // Input (Data, Array),
286 0xc0, // End Collection - System Control
288 // Consumer Control Collection - Media Keys (16 bits)
291 // Not bothering with NKRO for this table. If there's a need, I can implement it. -HaaTa
292 // Using a 1KRO scheme
293 0x05, 0x0c, // Usage Page (Consumer),
294 0x09, 0x01, // Usage (Consumer Control),
295 0xA1, 0x01, // Collection (Application),
296 0x85, 0x03, // Report ID (3),
297 0x75, 0x10, // Report Size (16),
298 0x95, 0x01, // Report Count (1),
299 0x16, 0x01, 0x00, // Logical Minimum (1),
300 0x26, 0x9D, 0x02, // Logical Maximum (669),
301 0x05, 0x0C, // Usage Page (Consumer),
302 0x19, 0x01, // Usage Minimum (1),
303 0x2A, 0x9D, 0x02, // Usage Maximum (669),
304 0x81, 0x00, // Input (Data, Array),
305 0xc0, // End Collection - Consumer Control
308 // Mouse Protocol 1, HID 1.11 spec, Appendix B, page 59-60, with wheel extension
309 static uint8_t mouse_report_desc[] = {
310 0x05, 0x01, // Usage Page (Generic Desktop)
311 0x09, 0x02, // Usage (Mouse)
312 0xa1, 0x01, // Collection (Application)
313 0x09, 0x02, // Usage (Mouse)
314 0xa1, 0x02, // Collection (Logical)
315 0x09, 0x01, // Usage (Pointer)
318 0xa1, 0x00, // Collection (Physical) - Buttons
319 0x05, 0x09, // Usage Page (Button)
320 0x19, 0x01, // Usage Minimum (Button 1)
321 0x29, 0x08, // Usage Maximum (Button 8)
322 0x15, 0x00, // Logical Minimum (0)
323 0x25, 0x01, // Logical Maximum (1)
324 0x75, 0x01, // Report Size (1)
325 0x95, 0x08, // Report Count (8)
326 0x81, 0x02, // Input (Data,Var,Abs)
329 0x05, 0x01, // Usage PAGE (Generic Desktop)
330 0x09, 0x30, // Usage (X)
331 0x09, 0x31, // Usage (Y)
332 0x15, 0x81, // Logical Minimum (-127)
333 0x25, 0x7f, // Logical Maximum (127)
334 0x75, 0x08, // Report Size (8)
335 0x95, 0x02, // Report Count (2)
336 0x81, 0x06, // Input (Data,Var,Rel)
339 // - Multiplier (2 bits)
340 0xa1, 0x02, // Collection (Logical)
341 0x09, 0x48, // Usage (Resolution Multiplier)
342 0x15, 0x00, // Logical Minimum (0)
343 0x25, 0x01, // Logical Maximum (1)
344 0x35, 0x01, // Physical Minimum (1)
345 0x45, 0x04, // Physical Maximum (4)
346 0x75, 0x02, // Report Size (2)
347 0x95, 0x01, // Report Count (1)
349 0xb1, 0x02, // Feature (Data,Var,Abs)
351 0x09, 0x38, // Usage (Wheel)
352 0x15, 0x81, // Logical Minimum (-127)
353 0x25, 0x7f, // Logical Maximum (127)
354 0x35, 0x00, // Physical Minimum (0) - reset physical
355 0x45, 0x00, // Physical Maximum (0)
356 0x75, 0x08, // Report Size (8)
357 0x81, 0x06, // Input (Data,Var,Rel)
358 0xc0, // End Collection - Vertical Wheel
361 // - Multiplier (2 bits)
362 0xa1, 0x02, // Collection (Logical)
363 0x09, 0x48, // Usage (Resolution Multiplier)
365 0xb1, 0x02, // Feature (Data,Var,Abs)
366 // - Padding (4 bits)
367 0x35, 0x00, // Physical Minimum (0) - reset physical
368 0x45, 0x00, // Physical Maximum (0)
369 0x75, 0x04, // Report Size (4)
370 0xb1, 0x03, // Feature (Cnst,Var,Abs)
372 0x05, 0x0c, // Usage Page (Consumer Devices)
373 0x0a, 0x38, 0x02, // Usage (AC Pan)
374 0x15, 0x81, // Logical Minimum (-127)
375 0x25, 0x7f, // Logical Maximum (127)
376 0x75, 0x08, // Report Size (8)
377 0x81, 0x06, // Input (Data,Var,Rel)
378 0xc0, // End Collection - Horizontal Wheel
380 0xc0, // End Collection - Buttons
381 0xc0, // End Collection - Mouse Logical
382 0xc0 // End Collection - Mouse Application
385 // Joystick Protocol, HID 1.11 spec, Apendix D, page 64-65
386 static uint8_t joystick_report_desc[] = {
387 0x05, 0x01, // Usage Page (Generic Desktop)
388 0x09, 0x04, // Usage (Joystick)
389 0xA1, 0x01, // Collection (Application)
390 0x15, 0x00, // Logical Minimum (0)
391 0x25, 0x01, // Logical Maximum (1)
392 0x75, 0x01, // Report Size (1)
393 0x95, 0x20, // Report Count (32)
394 0x05, 0x09, // Usage Page (Button)
395 0x19, 0x01, // Usage Minimum (Button #1)
396 0x29, 0x20, // Usage Maximum (Button #32)
397 0x81, 0x02, // Input (variable,absolute)
398 0x15, 0x00, // Logical Minimum (0)
399 0x25, 0x07, // Logical Maximum (7)
400 0x35, 0x00, // Physical Minimum (0)
401 0x46, 0x3B, 0x01, // Physical Maximum (315)
402 0x75, 0x04, // Report Size (4)
403 0x95, 0x01, // Report Count (1)
404 0x65, 0x14, // Unit (20)
405 0x05, 0x01, // Usage Page (Generic Desktop)
406 0x09, 0x39, // Usage (Hat switch)
407 0x81, 0x42, // Input (variable,absolute,null_state)
408 0x05, 0x01, // Usage Page (Generic Desktop)
409 0x09, 0x01, // Usage (Pointer)
410 0xA1, 0x00, // Collection ()
411 0x15, 0x00, // Logical Minimum (0)
412 0x26, 0xFF, 0x03, // Logical Maximum (1023)
413 0x75, 0x0A, // Report Size (10)
414 0x95, 0x04, // Report Count (4)
415 0x09, 0x30, // Usage (X)
416 0x09, 0x31, // Usage (Y)
417 0x09, 0x32, // Usage (Z)
418 0x09, 0x35, // Usage (Rz)
419 0x81, 0x02, // Input (variable,absolute)
420 0xC0, // End Collection
421 0x15, 0x00, // Logical Minimum (0)
422 0x26, 0xFF, 0x03, // Logical Maximum (1023)
423 0x75, 0x0A, // Report Size (10)
424 0x95, 0x02, // Report Count (2)
425 0x09, 0x36, // Usage (Slider)
426 0x09, 0x36, // Usage (Slider)
427 0x81, 0x02, // Input (variable,absolute)
428 0xC0 // End Collection
433 // ----- USB Configuration -----
435 // USB Configuration Descriptor. This huge descriptor tells all
436 // of the devices capbilities.
437 static uint8_t config_descriptor[CONFIG_DESC_SIZE] = {
438 // --- Configuration ---
440 // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
442 2, // bDescriptorType;
443 LSB(CONFIG_DESC_SIZE), // wTotalLength
444 MSB(CONFIG_DESC_SIZE),
445 NUM_INTERFACE, // bNumInterfaces
446 1, // bConfigurationValue
448 0xA0, // bmAttributes
449 250, // bMaxPower - Entry Index 8
451 // --- Keyboard HID --- Boot Mode Keyboard Interface
453 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
455 4, // bDescriptorType
456 KEYBOARD_INTERFACE, // bInterfaceNumber
457 0, // bAlternateSetting
459 0x03, // bInterfaceClass (0x03 = HID)
460 0x01, // bInterfaceSubClass (0x00 = Non-Boot, 0x01 = Boot)
461 0x01, // bInterfaceProtocol (0x01 = Keyboard)
462 KEYBOARD_INTERFACE + 4, // iInterface
464 // HID interface descriptor, HID 1.11 spec, section 6.2.1
466 0x21, // bDescriptorType
467 0x11, 0x01, // bcdHID
468 KeyboardLocale_define, // bCountryCode
469 1, // bNumDescriptors
470 0x22, // bDescriptorType
471 LSB(sizeof(keyboard_report_desc)), // wDescriptorLength
472 MSB(sizeof(keyboard_report_desc)),
474 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
476 5, // bDescriptorType
477 KEYBOARD_ENDPOINT | 0x80, // bEndpointAddress
478 0x03, // bmAttributes (0x03=intr)
479 KEYBOARD_SIZE, 0, // wMaxPacketSize
480 KEYBOARD_INTERVAL, // bInterval
482 // --- NKRO Keyboard HID --- OS Mode Keyboard Interface
484 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
486 4, // bDescriptorType
487 NKRO_KEYBOARD_INTERFACE, // bInterfaceNumber
488 0, // bAlternateSetting
490 0x03, // bInterfaceClass (0x03 = HID)
491 0x00, // bInterfaceSubClass (0x00 = Non-Boot, 0x01 = Boot)
492 0x01, // bInterfaceProtocol (0x01 = Keyboard)
493 NKRO_KEYBOARD_INTERFACE + 4, // iInterface
495 // HID interface descriptor, HID 1.11 spec, section 6.2.1
497 0x21, // bDescriptorType
498 0x11, 0x01, // bcdHID
499 KeyboardLocale_define, // bCountryCode
500 1, // bNumDescriptors
501 0x22, // bDescriptorType
502 LSB(sizeof(nkro_keyboard_report_desc)), // wDescriptorLength
503 MSB(sizeof(nkro_keyboard_report_desc)),
505 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
507 5, // bDescriptorType
508 NKRO_KEYBOARD_ENDPOINT | 0x80, // bEndpointAddress
509 0x03, // bmAttributes (0x03=intr)
510 NKRO_KEYBOARD_SIZE, 0, // wMaxPacketSize
511 NKRO_KEYBOARD_INTERVAL, // bInterval
513 // --- Serial CDC --- CDC IAD Descriptor
515 // interface association descriptor, USB ECN, Table 9-Z
517 11, // bDescriptorType
518 CDC_STATUS_INTERFACE, // bFirstInterface
519 2, // bInterfaceCount
520 0x02, // bFunctionClass
521 0x02, // bFunctionSubClass
522 0x01, // bFunctionProtocol
523 CDC_STATUS_INTERFACE + 4, // iFunction
525 // --- Serial CDC --- CDC Data Interface
527 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
529 4, // bDescriptorType
530 CDC_STATUS_INTERFACE, // bInterfaceNumber
531 0, // bAlternateSetting
533 0x02, // bInterfaceClass
534 0x02, // bInterfaceSubClass
535 0x01, // bInterfaceProtocol
536 CDC_STATUS_INTERFACE + 4, // iInterface
538 // CDC Header Functional Descriptor, CDC Spec 5.2.3.1, Table 26
539 5, // bFunctionLength
540 0x24, // bDescriptorType
541 0x00, // bDescriptorSubtype
542 0x10, 0x01, // bcdCDC
544 // Call Management Functional Descriptor, CDC Spec 5.2.3.2, Table 27
545 5, // bFunctionLength
546 0x24, // bDescriptorType
547 0x01, // bDescriptorSubtype
548 0x01, // bmCapabilities
549 CDC_DATA_INTERFACE, // bDataInterface
551 // Abstract Control Management Functional Descriptor, CDC Spec 5.2.3.3, Table 28
552 4, // bFunctionLength
553 0x24, // bDescriptorType
554 0x02, // bDescriptorSubtype
555 0x06, // bmCapabilities
557 // Union Functional Descriptor, CDC Spec 5.2.3.8, Table 33
558 5, // bFunctionLength
559 0x24, // bDescriptorType
560 0x06, // bDescriptorSubtype
561 CDC_STATUS_INTERFACE, // bMasterInterface
562 CDC_DATA_INTERFACE, // bSlaveInterface0
564 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
566 5, // bDescriptorType
567 CDC_ACM_ENDPOINT | 0x80, // bEndpointAddress
568 0x03, // bmAttributes (0x03=intr)
569 CDC_ACM_SIZE, 0, // wMaxPacketSize
572 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
574 4, // bDescriptorType
575 CDC_DATA_INTERFACE, // bInterfaceNumber
576 0, // bAlternateSetting
578 0x0A, // bInterfaceClass
579 0x00, // bInterfaceSubClass
580 0x00, // bInterfaceProtocol
581 CDC_DATA_INTERFACE + 4, // iInterface
583 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
585 5, // bDescriptorType
586 CDC_RX_ENDPOINT, // bEndpointAddress
587 0x02, // bmAttributes (0x02=bulk)
588 CDC_RX_SIZE, 0, // wMaxPacketSize
591 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
593 5, // bDescriptorType
594 CDC_TX_ENDPOINT | 0x80, // bEndpointAddress
595 0x02, // bmAttributes (0x02=bulk)
596 CDC_TX_SIZE, 0, // wMaxPacketSize
599 // --- Mouse Interface ---
601 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
603 4, // bDescriptorType
604 MOUSE_INTERFACE, // bInterfaceNumber
605 0, // bAlternateSetting
607 0x03, // bInterfaceClass (0x03 = HID)
608 0x00, // bInterfaceSubClass (0x01 = Boot)
609 0x02, // bInterfaceProtocol (0x02 = Mouse)
610 MOUSE_INTERFACE + 4, // iInterface
612 // HID interface descriptor, HID 1.11 spec, section 6.2.1
614 0x21, // bDescriptorType
615 0x11, 0x01, // bcdHID
617 1, // bNumDescriptors
618 0x22, // bDescriptorType
619 LSB(sizeof(mouse_report_desc)), // wDescriptorLength
620 MSB(sizeof(mouse_report_desc)),
622 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
624 5, // bDescriptorType
625 MOUSE_ENDPOINT | 0x80, // bEndpointAddress
626 0x03, // bmAttributes (0x03=intr)
627 MOUSE_SIZE, 0, // wMaxPacketSize
628 MOUSE_INTERVAL, // bInterval
630 // --- Joystick Interface ---
632 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
634 4, // bDescriptorType
635 JOYSTICK_INTERFACE, // bInterfaceNumber
636 0, // bAlternateSetting
638 0x03, // bInterfaceClass (0x03 = HID)
639 0x00, // bInterfaceSubClass
640 0x00, // bInterfaceProtocol
641 JOYSTICK_INTERFACE + 4, // iInterface
643 // HID interface descriptor, HID 1.11 spec, section 6.2.1
645 0x21, // bDescriptorType
646 0x11, 0x01, // bcdHID
648 1, // bNumDescriptors
649 0x22, // bDescriptorType
650 LSB(sizeof(joystick_report_desc)), // wDescriptorLength
651 MSB(sizeof(joystick_report_desc)),
653 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
655 5, // bDescriptorType
656 JOYSTICK_ENDPOINT | 0x80, // bEndpointAddress
657 0x03, // bmAttributes (0x03=intr)
658 JOYSTICK_SIZE, 0, // wMaxPacketSize
659 JOYSTICK_INTERVAL, // bInterval
661 // --- System/Consumer Control ---
663 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
665 4, // bDescriptorType
666 SYS_CTRL_INTERFACE, // bInterfaceNumber
667 0, // bAlternateSetting
669 0x03, // bInterfaceClass (0x03 = HID)
670 0x01, // bInterfaceSubClass (0x00 = Non-Boot, 0x01 = Boot)
671 0x00, // bInterfaceProtocol (0x00 = None)
672 SYS_CTRL_INTERFACE + 4, // iInterface
674 // HID interface descriptor, HID 1.11 spec, section 6.2.1
676 0x21, // bDescriptorType
677 0x11, 0x01, // bcdHID
678 KeyboardLocale_define, // bCountryCode
679 1, // bNumDescriptors
680 0x22, // bDescriptorType
681 LSB(sizeof(sys_ctrl_report_desc)), // wDescriptorLength
682 MSB(sizeof(sys_ctrl_report_desc)),
684 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
686 5, // bDescriptorType
687 SYS_CTRL_ENDPOINT | 0x80, // bEndpointAddress
688 0x03, // bmAttributes (0x03=intr)
689 SYS_CTRL_SIZE, 0, // wMaxPacketSize
690 SYS_CTRL_INTERVAL, // bInterval
693 uint8_t *usb_bMaxPower = &config_descriptor[8];
697 // ----- String Descriptors -----
699 // The descriptors above can provide human readable strings,
700 // referenced by index numbers. These descriptors are the
701 // actual string data
703 struct usb_string_descriptor_struct {
705 uint8_t bDescriptorType;
709 extern struct usb_string_descriptor_struct usb_string_manufacturer_name
710 __attribute__ ((weak, alias("usb_string_manufacturer_name_default")));
711 extern struct usb_string_descriptor_struct usb_string_product_name
712 __attribute__ ((weak, alias("usb_string_product_name_default")));
713 extern struct usb_string_descriptor_struct usb_string_serial_number
714 __attribute__ ((weak, alias("usb_string_serial_number_default")));
716 struct usb_string_descriptor_struct string0 = {
722 #define usb_string_descriptor(name, str) \
723 struct usb_string_descriptor_struct name = { \
729 usb_string_descriptor( usb_string_manufacturer_name_default, STR_MANUFACTURER );
730 usb_string_descriptor( usb_string_product_name_default, STR_PRODUCT );
731 usb_string_descriptor( usb_string_serial_number_default, STR_SERIAL );
732 usb_string_descriptor( usb_string_keyboard_name, KEYBOARD_NAME );
733 usb_string_descriptor( usb_string_nkro_keyboard_name, NKRO_KEYBOARD_NAME );
734 usb_string_descriptor( usb_string_cdc_status_name, CDC_STATUS_NAME );
735 usb_string_descriptor( usb_string_cdc_data_name, CDC_DATA_NAME );
736 usb_string_descriptor( usb_string_mouse_name, MOUSE_NAME );
737 usb_string_descriptor( usb_string_joystick_name, JOYSTICK_NAME );
738 usb_string_descriptor( usb_string_sys_ctrl_name, SYS_CTRL_NAME );
742 // ----- Descriptors List -----
744 // This table provides access to all the descriptor data above.
746 const usb_descriptor_list_t usb_descriptor_list[] = {
747 //wValue, wIndex, address, length
748 {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
749 {0x0200, 0x0000, config_descriptor, sizeof(config_descriptor)},
750 {0x0600, 0x0000, device_qualifier_descriptor, sizeof(device_qualifier_descriptor)},
751 {0x0A00, 0x0000, usb_debug_descriptor, sizeof(usb_debug_descriptor)},
753 {0x2200, KEYBOARD_INTERFACE, keyboard_report_desc, sizeof(keyboard_report_desc)},
754 {0x2100, KEYBOARD_INTERFACE, config_descriptor + KEYBOARD_DESC_OFFSET, 9},
756 {0x2200, NKRO_KEYBOARD_INTERFACE, nkro_keyboard_report_desc, sizeof(nkro_keyboard_report_desc)},
757 {0x2100, NKRO_KEYBOARD_INTERFACE, config_descriptor + NKRO_KEYBOARD_DESC_OFFSET, 9},
759 {0x2200, MOUSE_INTERFACE, mouse_report_desc, sizeof(mouse_report_desc)},
760 {0x2100, MOUSE_INTERFACE, config_descriptor + MOUSE_DESC_OFFSET, 9},
762 {0x2200, JOYSTICK_INTERFACE, joystick_report_desc, sizeof(joystick_report_desc)},
763 {0x2100, JOYSTICK_INTERFACE, config_descriptor + JOYSTICK_DESC_OFFSET, 9},
765 {0x2200, SYS_CTRL_INTERFACE, sys_ctrl_report_desc, sizeof(sys_ctrl_report_desc)},
766 {0x2100, SYS_CTRL_INTERFACE, config_descriptor + SYS_CTRL_DESC_OFFSET, 9},
768 #define iInterfaceString(num, var) \
769 {0x0300 + 4 + num, 0x409, (const uint8_t *)&var, 0 }
771 {0x0300, 0x0000, (const uint8_t *)&string0, 0},
772 {0x0301, 0x0409, (const uint8_t *)&usb_string_manufacturer_name, 0},
773 {0x0302, 0x0409, (const uint8_t *)&usb_string_product_name, 0},
774 {0x0303, 0x0409, (const uint8_t *)&usb_string_serial_number, 0},
775 iInterfaceString( KEYBOARD_INTERFACE, usb_string_keyboard_name ),
776 iInterfaceString( NKRO_KEYBOARD_INTERFACE, usb_string_nkro_keyboard_name ),
777 iInterfaceString( CDC_STATUS_INTERFACE, usb_string_cdc_status_name ),
778 iInterfaceString( CDC_DATA_INTERFACE, usb_string_cdc_data_name ),
779 iInterfaceString( MOUSE_INTERFACE, usb_string_mouse_name ),
780 iInterfaceString( JOYSTICK_INTERFACE, usb_string_joystick_name ),
781 iInterfaceString( SYS_CTRL_INTERFACE, usb_string_sys_ctrl_name ),
787 // ----- Endpoint Configuration -----
789 // See usb_desc.h for Endpoint configuration
791 // 0x19 = Recieve only
792 // 0x15 = Transmit only
793 // 0x1D = Transmit & Recieve
795 const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
797 #if (defined(ENDPOINT1_CONFIG) && NUM_ENDPOINTS >= 1)
799 #elif (NUM_ENDPOINTS >= 1)
802 #if (defined(ENDPOINT2_CONFIG) && NUM_ENDPOINTS >= 2)
804 #elif (NUM_ENDPOINTS >= 2)
807 #if (defined(ENDPOINT3_CONFIG) && NUM_ENDPOINTS >= 3)
809 #elif (NUM_ENDPOINTS >= 3)
812 #if (defined(ENDPOINT4_CONFIG) && NUM_ENDPOINTS >= 4)
814 #elif (NUM_ENDPOINTS >= 4)
817 #if (defined(ENDPOINT5_CONFIG) && NUM_ENDPOINTS >= 5)
819 #elif (NUM_ENDPOINTS >= 5)
822 #if (defined(ENDPOINT6_CONFIG) && NUM_ENDPOINTS >= 6)
824 #elif (NUM_ENDPOINTS >= 6)
827 #if (defined(ENDPOINT7_CONFIG) && NUM_ENDPOINTS >= 7)
829 #elif (NUM_ENDPOINTS >= 7)
832 #if (defined(ENDPOINT8_CONFIG) && NUM_ENDPOINTS >= 8)
834 #elif (NUM_ENDPOINTS >= 8)
837 #if (defined(ENDPOINT9_CONFIG) && NUM_ENDPOINTS >= 9)
839 #elif (NUM_ENDPOINTS >= 9)
842 #if (defined(ENDPOINT10_CONFIG) && NUM_ENDPOINTS >= 10)
844 #elif (NUM_ENDPOINTS >= 10)
847 #if (defined(ENDPOINT11_CONFIG) && NUM_ENDPOINTS >= 11)
849 #elif (NUM_ENDPOINTS >= 11)
852 #if (defined(ENDPOINT12_CONFIG) && NUM_ENDPOINTS >= 12)
854 #elif (NUM_ENDPOINTS >= 12)
857 #if (defined(ENDPOINT13_CONFIG) && NUM_ENDPOINTS >= 13)
859 #elif (NUM_ENDPOINTS >= 13)
862 #if (defined(ENDPOINT14_CONFIG) && NUM_ENDPOINTS >= 14)
864 #elif (NUM_ENDPOINTS >= 14)
867 #if (defined(ENDPOINT15_CONFIG) && NUM_ENDPOINTS >= 15)
869 #elif (NUM_ENDPOINTS >= 15)