1 /* Teensyduino Core Library
2 * http://www.pjrc.com/teensy/
3 * Copyright (c) 2013 PJRC.COM, LLC.
4 * Modified by Jacob Alexander (2013-2014)
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
35 // USB Descriptors are binary data which the USB host reads to
36 // automatically detect a USB device's capabilities. The format
37 // and meaning of every field is documented in numerous USB
38 // standards. When working with USB descriptors, despite the
39 // complexity of the standards and poor writing quality in many
40 // of those documents, remember descriptors are nothing more
41 // than constant binary data that tells the USB host what the
42 // device can do. Computers will load drivers based on this data.
43 // Those drivers then communicate on the endpoints specified by
46 // To configure a new combination of interfaces or make minor
47 // changes to existing configuration (eg, change the name or ID
48 // numbers), usually you would edit "usb_desc.h". This file
49 // is meant to be configured by the header, so generally it is
50 // only edited to add completely new USB interfaces or features.
54 // **************************************************************
56 // **************************************************************
58 #define LSB(n) ((n) & 255)
59 #define MSB(n) (((n) >> 8) & 255)
61 // USB Device Descriptor. The USB host reads this first, to learn
62 // what type of device is connected.
63 static uint8_t device_descriptor[] = {
68 DEVICE_CLASS, // bDeviceClass
72 #ifdef DEVICE_SUBCLASS
73 DEVICE_SUBCLASS, // bDeviceSubClass
77 #ifdef DEVICE_PROTOCOL
78 DEVICE_PROTOCOL, // bDeviceProtocol
82 EP0_SIZE, // bMaxPacketSize0
83 LSB(VENDOR_ID), MSB(VENDOR_ID), // idVendor
84 LSB(PRODUCT_ID), MSB(PRODUCT_ID), // idProduct
85 0x00, 0x01, // bcdDevice
89 1 // bNumConfigurations
92 // These descriptors must NOT be "const", because the USB DMA
93 // has trouble accessing flash memory with enough bandwidth
94 // while the processor is executing from flash.
98 // **************************************************************
99 // HID Report Descriptors
100 // **************************************************************
102 // Each HID interface needs a special report descriptor that tells
103 // the meaning and format of the data.
105 #ifdef KEYBOARD_INTERFACE
106 // Keyboard Protocol 1, HID 1.11 spec, Appendix B, page 59-60
107 static uint8_t keyboard_report_desc[] = {
108 0x05, 0x01, // Usage Page (Generic Desktop),
109 0x09, 0x06, // Usage (Keyboard),
110 0xA1, 0x01, // Collection (Application),
111 0x75, 0x01, // Report Size (1),
112 0x95, 0x08, // Report Count (8),
113 0x05, 0x07, // Usage Page (Key Codes),
114 0x19, 0xE0, // Usage Minimum (224),
115 0x29, 0xE7, // Usage Maximum (231),
116 0x15, 0x00, // Logical Minimum (0),
117 0x25, 0x01, // Logical Maximum (1),
118 0x81, 0x02, // Input (Data, Variable, Absolute), ;Modifier byte
119 0x95, 0x08, // Report Count (8),
120 0x75, 0x01, // Report Size (1),
121 0x15, 0x00, // Logical Minimum (0),
122 0x25, 0x01, // Logical Maximum (1),
123 0x05, 0x0C, // Usage Page (Consumer),
124 0x09, 0xE9, // Usage (Volume Increment),
125 0x09, 0xEA, // Usage (Volume Decrement),
126 0x09, 0xE2, // Usage (Mute),
127 0x09, 0xCD, // Usage (Play/Pause),
128 0x09, 0xB5, // Usage (Scan Next Track),
129 0x09, 0xB6, // Usage (Scan Previous Track),
130 0x09, 0xB7, // Usage (Stop),
131 0x09, 0xB8, // Usage (Eject),
132 0x81, 0x02, // Input (Data, Variable, Absolute), ;Media keys
133 0x95, 0x05, // Report Count (5),
134 0x75, 0x01, // Report Size (1),
135 0x05, 0x08, // Usage Page (LEDs),
136 0x19, 0x01, // Usage Minimum (1),
137 0x29, 0x05, // Usage Maximum (5),
138 0x91, 0x02, // Output (Data, Variable, Absolute), ;LED report
139 0x95, 0x01, // Report Count (1),
140 0x75, 0x03, // Report Size (3),
141 0x91, 0x03, // Output (Constant), ;LED report padding
142 0x95, 0x06, // Report Count (6),
143 0x75, 0x08, // Report Size (8),
144 0x15, 0x00, // Logical Minimum (0),
145 0x25, 0x7F, // Logical Maximum(104),
146 0x05, 0x07, // Usage Page (Key Codes),
147 0x19, 0x00, // Usage Minimum (0),
148 0x29, 0x7F, // Usage Maximum (104),
149 0x81, 0x00, // Input (Data, Array), ;Normal keys
150 0xc0 // End Collection
154 #ifdef MOUSE_INTERFACE
155 // Mouse Protocol 1, HID 1.11 spec, Appendix B, page 59-60, with wheel extension
156 static uint8_t mouse_report_desc[] = {
157 0x05, 0x01, // Usage Page (Generic Desktop)
158 0x09, 0x02, // Usage (Mouse)
159 0xA1, 0x01, // Collection (Application)
160 0x05, 0x09, // Usage Page (Button)
161 0x19, 0x01, // Usage Minimum (Button #1)
162 0x29, 0x03, // Usage Maximum (Button #3)
163 0x15, 0x00, // Logical Minimum (0)
164 0x25, 0x01, // Logical Maximum (1)
165 0x95, 0x03, // Report Count (3)
166 0x75, 0x01, // Report Size (1)
167 0x81, 0x02, // Input (Data, Variable, Absolute)
168 0x95, 0x01, // Report Count (1)
169 0x75, 0x05, // Report Size (5)
170 0x81, 0x03, // Input (Constant)
171 0x05, 0x01, // Usage Page (Generic Desktop)
172 0x09, 0x30, // Usage (X)
173 0x09, 0x31, // Usage (Y)
174 0x15, 0x00, // Logical Minimum (0)
175 0x26, 0xFF, 0x7F, // Logical Maximum (32767)
176 0x75, 0x10, // Report Size (16),
177 0x95, 0x02, // Report Count (2),
178 0x81, 0x02, // Input (Data, Variable, Absolute)
179 0x09, 0x38, // Usage (Wheel)
180 0x15, 0x81, // Logical Minimum (-127)
181 0x25, 0x7F, // Logical Maximum (127)
182 0x75, 0x08, // Report Size (8),
183 0x95, 0x01, // Report Count (1),
184 0x81, 0x06, // Input (Data, Variable, Relative)
185 0xC0 // End Collection
191 // **************************************************************
193 // **************************************************************
195 // USB Configuration Descriptor. This huge descriptor tells all
196 // of the devices capbilities.
197 static uint8_t config_descriptor[CONFIG_DESC_SIZE] = {
198 // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
200 2, // bDescriptorType;
201 LSB(CONFIG_DESC_SIZE), // wTotalLength
202 MSB(CONFIG_DESC_SIZE),
203 NUM_INTERFACE, // bNumInterfaces
204 1, // bConfigurationValue
206 0xC0, // bmAttributes
209 #ifdef CDC_IAD_DESCRIPTOR
210 // interface association descriptor, USB ECN, Table 9-Z
212 11, // bDescriptorType
213 CDC_STATUS_INTERFACE, // bFirstInterface
214 2, // bInterfaceCount
215 0x02, // bFunctionClass
216 0x02, // bFunctionSubClass
217 0x01, // bFunctionProtocol
221 #ifdef CDC_DATA_INTERFACE
222 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
224 4, // bDescriptorType
225 CDC_STATUS_INTERFACE, // bInterfaceNumber
226 0, // bAlternateSetting
228 0x02, // bInterfaceClass
229 0x02, // bInterfaceSubClass
230 0x01, // bInterfaceProtocol
232 // CDC Header Functional Descriptor, CDC Spec 5.2.3.1, Table 26
233 5, // bFunctionLength
234 0x24, // bDescriptorType
235 0x00, // bDescriptorSubtype
236 0x10, 0x01, // bcdCDC
237 // Call Management Functional Descriptor, CDC Spec 5.2.3.2, Table 27
238 5, // bFunctionLength
239 0x24, // bDescriptorType
240 0x01, // bDescriptorSubtype
241 0x01, // bmCapabilities
243 // Abstract Control Management Functional Descriptor, CDC Spec 5.2.3.3, Table 28
244 4, // bFunctionLength
245 0x24, // bDescriptorType
246 0x02, // bDescriptorSubtype
247 0x06, // bmCapabilities
248 // Union Functional Descriptor, CDC Spec 5.2.3.8, Table 33
249 5, // bFunctionLength
250 0x24, // bDescriptorType
251 0x06, // bDescriptorSubtype
252 CDC_STATUS_INTERFACE, // bMasterInterface
253 CDC_DATA_INTERFACE, // bSlaveInterface0
254 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
256 5, // bDescriptorType
257 CDC_ACM_ENDPOINT | 0x80, // bEndpointAddress
258 0x03, // bmAttributes (0x03=intr)
259 CDC_ACM_SIZE, 0, // wMaxPacketSize
261 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
263 4, // bDescriptorType
264 CDC_DATA_INTERFACE, // bInterfaceNumber
265 0, // bAlternateSetting
267 0x0A, // bInterfaceClass
268 0x00, // bInterfaceSubClass
269 0x00, // bInterfaceProtocol
271 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
273 5, // bDescriptorType
274 CDC_RX_ENDPOINT, // bEndpointAddress
275 0x02, // bmAttributes (0x02=bulk)
276 CDC_RX_SIZE, 0, // wMaxPacketSize
278 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
280 5, // bDescriptorType
281 CDC_TX_ENDPOINT | 0x80, // bEndpointAddress
282 0x02, // bmAttributes (0x02=bulk)
283 CDC_TX_SIZE, 0, // wMaxPacketSize
285 #endif // CDC_DATA_INTERFACE
287 #ifdef KEYBOARD_INTERFACE
288 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
290 4, // bDescriptorType
291 KEYBOARD_INTERFACE, // bInterfaceNumber
292 0, // bAlternateSetting
294 0x03, // bInterfaceClass (0x03 = HID)
295 0x01, // bInterfaceSubClass (0x01 = Boot)
296 0x01, // bInterfaceProtocol (0x01 = Keyboard)
298 // HID interface descriptor, HID 1.11 spec, section 6.2.1
300 0x21, // bDescriptorType
301 0x11, 0x01, // bcdHID
303 1, // bNumDescriptors
304 0x22, // bDescriptorType
305 LSB(sizeof(keyboard_report_desc)), // wDescriptorLength
306 MSB(sizeof(keyboard_report_desc)),
307 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
309 5, // bDescriptorType
310 KEYBOARD_ENDPOINT | 0x80, // bEndpointAddress
311 0x03, // bmAttributes (0x03=intr)
312 KEYBOARD_SIZE, 0, // wMaxPacketSize
313 KEYBOARD_INTERVAL, // bInterval
314 #endif // KEYBOARD_INTERFACE
316 #ifdef MOUSE_INTERFACE
317 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
319 4, // bDescriptorType
320 MOUSE_INTERFACE, // bInterfaceNumber
321 0, // bAlternateSetting
323 0x03, // bInterfaceClass (0x03 = HID)
324 0x00, // bInterfaceSubClass (0x01 = Boot)
325 0x00, // bInterfaceProtocol (0x02 = Mouse)
327 // HID interface descriptor, HID 1.11 spec, section 6.2.1
329 0x21, // bDescriptorType
330 0x11, 0x01, // bcdHID
332 1, // bNumDescriptors
333 0x22, // bDescriptorType
334 LSB(sizeof(mouse_report_desc)), // wDescriptorLength
335 MSB(sizeof(mouse_report_desc)),
336 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
338 5, // bDescriptorType
339 MOUSE_ENDPOINT | 0x80, // bEndpointAddress
340 0x03, // bmAttributes (0x03=intr)
341 MOUSE_SIZE, 0, // wMaxPacketSize
342 MOUSE_INTERVAL, // bInterval
343 #endif // MOUSE_INTERFACE
348 // **************************************************************
349 // String Descriptors
350 // **************************************************************
352 // The descriptors above can provide human readable strings,
353 // referenced by index numbers. These descriptors are the
354 // actual string data
356 struct usb_string_descriptor_struct {
358 uint8_t bDescriptorType;
362 extern struct usb_string_descriptor_struct usb_string_manufacturer_name
363 __attribute__ ((weak, alias("usb_string_manufacturer_name_default")));
364 extern struct usb_string_descriptor_struct usb_string_product_name
365 __attribute__ ((weak, alias("usb_string_product_name_default")));
366 extern struct usb_string_descriptor_struct usb_string_serial_number
367 __attribute__ ((weak, alias("usb_string_serial_number_default")));
369 struct usb_string_descriptor_struct string0 = {
375 struct usb_string_descriptor_struct usb_string_manufacturer_name_default = {
376 sizeof(STR_MANUFACTURER),
380 struct usb_string_descriptor_struct usb_string_product_name_default = {
385 struct usb_string_descriptor_struct usb_string_serial_number_default = {
392 // **************************************************************
394 // **************************************************************
396 // This table provides access to all the descriptor data above.
398 const usb_descriptor_list_t usb_descriptor_list[] = {
399 //wValue, wIndex, address, length
400 {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
401 {0x0200, 0x0000, config_descriptor, sizeof(config_descriptor)},
402 #ifdef KEYBOARD_INTERFACE
403 {0x2200, KEYBOARD_INTERFACE, keyboard_report_desc, sizeof(keyboard_report_desc)},
404 {0x2100, KEYBOARD_INTERFACE, config_descriptor+KEYBOARD_DESC_OFFSET, 9},
406 #ifdef MOUSE_INTERFACE
407 {0x2200, MOUSE_INTERFACE, mouse_report_desc, sizeof(mouse_report_desc)},
408 {0x2100, MOUSE_INTERFACE, config_descriptor+MOUSE_DESC_OFFSET, 9},
410 {0x0300, 0x0000, (const uint8_t *)&string0, 0},
411 {0x0301, 0x0409, (const uint8_t *)&usb_string_manufacturer_name, 0},
412 {0x0302, 0x0409, (const uint8_t *)&usb_string_product_name, 0},
413 {0x0303, 0x0409, (const uint8_t *)&usb_string_serial_number, 0},
418 // **************************************************************
419 // Endpoint Configuration
420 // **************************************************************
424 // 0x19 = Recieve only
425 // 0x15 = Transmit only
426 // 0x1D = Transmit & Recieve
428 const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
430 0x00, 0x15, 0x19, 0x15, 0x00, 0x00, 0x00, 0x00,
431 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
436 const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
438 #if (defined(ENDPOINT1_CONFIG) && NUM_ENDPOINTS >= 1)
440 #elif (NUM_ENDPOINTS >= 1)
443 #if (defined(ENDPOINT2_CONFIG) && NUM_ENDPOINTS >= 2)
445 #elif (NUM_ENDPOINTS >= 2)
448 #if (defined(ENDPOINT3_CONFIG) && NUM_ENDPOINTS >= 3)
450 #elif (NUM_ENDPOINTS >= 3)
453 #if (defined(ENDPOINT4_CONFIG) && NUM_ENDPOINTS >= 4)
455 #elif (NUM_ENDPOINTS >= 4)
458 #if (defined(ENDPOINT5_CONFIG) && NUM_ENDPOINTS >= 5)
460 #elif (NUM_ENDPOINTS >= 5)
463 #if (defined(ENDPOINT6_CONFIG) && NUM_ENDPOINTS >= 6)
465 #elif (NUM_ENDPOINTS >= 6)
468 #if (defined(ENDPOINT7_CONFIG) && NUM_ENDPOINTS >= 7)
470 #elif (NUM_ENDPOINTS >= 7)
473 #if (defined(ENDPOINT8_CONFIG) && NUM_ENDPOINTS >= 8)
475 #elif (NUM_ENDPOINTS >= 8)
478 #if (defined(ENDPOINT9_CONFIG) && NUM_ENDPOINTS >= 9)
480 #elif (NUM_ENDPOINTS >= 9)
483 #if (defined(ENDPOINT10_CONFIG) && NUM_ENDPOINTS >= 10)
485 #elif (NUM_ENDPOINTS >= 10)
488 #if (defined(ENDPOINT11_CONFIG) && NUM_ENDPOINTS >= 11)
490 #elif (NUM_ENDPOINTS >= 11)
493 #if (defined(ENDPOINT12_CONFIG) && NUM_ENDPOINTS >= 12)
495 #elif (NUM_ENDPOINTS >= 12)
498 #if (defined(ENDPOINT13_CONFIG) && NUM_ENDPOINTS >= 13)
500 #elif (NUM_ENDPOINTS >= 13)
503 #if (defined(ENDPOINT14_CONFIG) && NUM_ENDPOINTS >= 14)
505 #elif (NUM_ENDPOINTS >= 14)
508 #if (defined(ENDPOINT15_CONFIG) && NUM_ENDPOINTS >= 15)
510 #elif (NUM_ENDPOINTS >= 15)