1 /* Teensyduino Core Library
2 * http://www.pjrc.com/teensy/
3 * Copyright (c) 2013 PJRC.COM, LLC.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * 1. The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * 2. If the Software is incorporated into a build system that allows
17 * selection among a list of target devices, then similar target
18 * devices manufactured by PJRC.COM must be included in the list of
19 * target devices and selectable in the same manner.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
25 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
26 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 // USB Descriptors are binary data which the USB host reads to
35 // automatically detect a USB device's capabilities. The format
36 // and meaning of every field is documented in numerous USB
37 // standards. When working with USB descriptors, despite the
38 // complexity of the standards and poor writing quality in many
39 // of those documents, remember descriptors are nothing more
40 // than constant binary data that tells the USB host what the
41 // device can do. Computers will load drivers based on this data.
42 // Those drivers then communicate on the endpoints specified by
45 // To configure a new combination of interfaces or make minor
46 // changes to existing configuration (eg, change the name or ID
47 // numbers), usually you would edit "usb_desc.h". This file
48 // is meant to be configured by the header, so generally it is
49 // only edited to add completely new USB interfaces or features.
53 // **************************************************************
55 // **************************************************************
57 #define LSB(n) ((n) & 255)
58 #define MSB(n) (((n) >> 8) & 255)
60 // USB Device Descriptor. The USB host reads this first, to learn
61 // what type of device is connected.
62 static uint8_t device_descriptor[] = {
67 DEVICE_CLASS, // bDeviceClass
71 #ifdef DEVICE_SUBCLASS
72 DEVICE_SUBCLASS, // bDeviceSubClass
76 #ifdef DEVICE_PROTOCOL
77 DEVICE_PROTOCOL, // bDeviceProtocol
81 EP0_SIZE, // bMaxPacketSize0
82 LSB(VENDOR_ID), MSB(VENDOR_ID), // idVendor
83 LSB(PRODUCT_ID), MSB(PRODUCT_ID), // idProduct
84 0x00, 0x01, // bcdDevice
88 1 // bNumConfigurations
91 // These descriptors must NOT be "const", because the USB DMA
92 // has trouble accessing flash memory with enough bandwidth
93 // while the processor is executing from flash.
97 // **************************************************************
98 // HID Report Descriptors
99 // **************************************************************
101 // Each HID interface needs a special report descriptor that tells
102 // the meaning and format of the data.
104 #ifdef KEYBOARD_INTERFACE
105 // Keyboard Protocol 1, HID 1.11 spec, Appendix B, page 59-60
106 static uint8_t keyboard_report_desc[] = {
107 0x05, 0x01, // Usage Page (Generic Desktop),
108 0x09, 0x06, // Usage (Keyboard),
109 0xA1, 0x01, // Collection (Application),
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), ;Modifier byte
118 0x95, 0x08, // Report Count (8),
119 0x75, 0x01, // Report Size (1),
120 0x15, 0x00, // Logical Minimum (0),
121 0x25, 0x01, // Logical Maximum (1),
122 0x05, 0x0C, // Usage Page (Consumer),
123 0x09, 0xE9, // Usage (Volume Increment),
124 0x09, 0xEA, // Usage (Volume Decrement),
125 0x09, 0xE2, // Usage (Mute),
126 0x09, 0xCD, // Usage (Play/Pause),
127 0x09, 0xB5, // Usage (Scan Next Track),
128 0x09, 0xB6, // Usage (Scan Previous Track),
129 0x09, 0xB7, // Usage (Stop),
130 0x09, 0xB8, // Usage (Eject),
131 0x81, 0x02, // Input (Data, Variable, Absolute), ;Media keys
132 0x95, 0x05, // Report Count (5),
133 0x75, 0x01, // Report Size (1),
134 0x05, 0x08, // Usage Page (LEDs),
135 0x19, 0x01, // Usage Minimum (1),
136 0x29, 0x05, // Usage Maximum (5),
137 0x91, 0x02, // Output (Data, Variable, Absolute), ;LED report
138 0x95, 0x01, // Report Count (1),
139 0x75, 0x03, // Report Size (3),
140 0x91, 0x03, // Output (Constant), ;LED report padding
141 0x95, 0x06, // Report Count (6),
142 0x75, 0x08, // Report Size (8),
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), ;Normal keys
149 0xc0 // End Collection
153 #ifdef MOUSE_INTERFACE
154 // Mouse Protocol 1, HID 1.11 spec, Appendix B, page 59-60, with wheel extension
155 static uint8_t mouse_report_desc[] = {
156 0x05, 0x01, // Usage Page (Generic Desktop)
157 0x09, 0x02, // Usage (Mouse)
158 0xA1, 0x01, // Collection (Application)
159 0x05, 0x09, // Usage Page (Button)
160 0x19, 0x01, // Usage Minimum (Button #1)
161 0x29, 0x03, // Usage Maximum (Button #3)
162 0x15, 0x00, // Logical Minimum (0)
163 0x25, 0x01, // Logical Maximum (1)
164 0x95, 0x03, // Report Count (3)
165 0x75, 0x01, // Report Size (1)
166 0x81, 0x02, // Input (Data, Variable, Absolute)
167 0x95, 0x01, // Report Count (1)
168 0x75, 0x05, // Report Size (5)
169 0x81, 0x03, // Input (Constant)
170 0x05, 0x01, // Usage Page (Generic Desktop)
171 0x09, 0x30, // Usage (X)
172 0x09, 0x31, // Usage (Y)
173 0x15, 0x00, // Logical Minimum (0)
174 0x26, 0xFF, 0x7F, // Logical Maximum (32767)
175 0x75, 0x10, // Report Size (16),
176 0x95, 0x02, // Report Count (2),
177 0x81, 0x02, // Input (Data, Variable, Absolute)
178 0x09, 0x38, // Usage (Wheel)
179 0x15, 0x81, // Logical Minimum (-127)
180 0x25, 0x7F, // Logical Maximum (127)
181 0x75, 0x08, // Report Size (8),
182 0x95, 0x01, // Report Count (1),
183 0x81, 0x06, // Input (Data, Variable, Relative)
184 0xC0 // End Collection
190 // **************************************************************
192 // **************************************************************
194 // USB Configuration Descriptor. This huge descriptor tells all
195 // of the devices capbilities.
196 static uint8_t config_descriptor[CONFIG_DESC_SIZE] = {
197 // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
199 2, // bDescriptorType;
200 LSB(CONFIG_DESC_SIZE), // wTotalLength
201 MSB(CONFIG_DESC_SIZE),
202 NUM_INTERFACE, // bNumInterfaces
203 1, // bConfigurationValue
205 0xC0, // bmAttributes
208 #ifdef CDC_IAD_DESCRIPTOR
209 // interface association descriptor, USB ECN, Table 9-Z
211 11, // bDescriptorType
212 CDC_STATUS_INTERFACE, // bFirstInterface
213 2, // bInterfaceCount
214 0x02, // bFunctionClass
215 0x02, // bFunctionSubClass
216 0x01, // bFunctionProtocol
220 #ifdef CDC_DATA_INTERFACE
221 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
223 4, // bDescriptorType
224 CDC_STATUS_INTERFACE, // bInterfaceNumber
225 0, // bAlternateSetting
227 0x02, // bInterfaceClass
228 0x02, // bInterfaceSubClass
229 0x01, // bInterfaceProtocol
231 // CDC Header Functional Descriptor, CDC Spec 5.2.3.1, Table 26
232 5, // bFunctionLength
233 0x24, // bDescriptorType
234 0x00, // bDescriptorSubtype
235 0x10, 0x01, // bcdCDC
236 // Call Management Functional Descriptor, CDC Spec 5.2.3.2, Table 27
237 5, // bFunctionLength
238 0x24, // bDescriptorType
239 0x01, // bDescriptorSubtype
240 0x01, // bmCapabilities
242 // Abstract Control Management Functional Descriptor, CDC Spec 5.2.3.3, Table 28
243 4, // bFunctionLength
244 0x24, // bDescriptorType
245 0x02, // bDescriptorSubtype
246 0x06, // bmCapabilities
247 // Union Functional Descriptor, CDC Spec 5.2.3.8, Table 33
248 5, // bFunctionLength
249 0x24, // bDescriptorType
250 0x06, // bDescriptorSubtype
251 CDC_STATUS_INTERFACE, // bMasterInterface
252 CDC_DATA_INTERFACE, // bSlaveInterface0
253 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
255 5, // bDescriptorType
256 CDC_ACM_ENDPOINT | 0x80, // bEndpointAddress
257 0x03, // bmAttributes (0x03=intr)
258 CDC_ACM_SIZE, 0, // wMaxPacketSize
260 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
262 4, // bDescriptorType
263 CDC_DATA_INTERFACE, // bInterfaceNumber
264 0, // bAlternateSetting
266 0x0A, // bInterfaceClass
267 0x00, // bInterfaceSubClass
268 0x00, // bInterfaceProtocol
270 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
272 5, // bDescriptorType
273 CDC_RX_ENDPOINT, // bEndpointAddress
274 0x02, // bmAttributes (0x02=bulk)
275 CDC_RX_SIZE, 0, // wMaxPacketSize
277 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
279 5, // bDescriptorType
280 CDC_TX_ENDPOINT | 0x80, // bEndpointAddress
281 0x02, // bmAttributes (0x02=bulk)
282 CDC_TX_SIZE, 0, // wMaxPacketSize
284 #endif // CDC_DATA_INTERFACE
286 #ifdef KEYBOARD_INTERFACE
287 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
289 4, // bDescriptorType
290 KEYBOARD_INTERFACE, // bInterfaceNumber
291 0, // bAlternateSetting
293 0x03, // bInterfaceClass (0x03 = HID)
294 0x01, // bInterfaceSubClass (0x01 = Boot)
295 0x01, // bInterfaceProtocol (0x01 = Keyboard)
297 // HID interface descriptor, HID 1.11 spec, section 6.2.1
299 0x21, // bDescriptorType
300 0x11, 0x01, // bcdHID
302 1, // bNumDescriptors
303 0x22, // bDescriptorType
304 LSB(sizeof(keyboard_report_desc)), // wDescriptorLength
305 MSB(sizeof(keyboard_report_desc)),
306 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
308 5, // bDescriptorType
309 KEYBOARD_ENDPOINT | 0x80, // bEndpointAddress
310 0x03, // bmAttributes (0x03=intr)
311 KEYBOARD_SIZE, 0, // wMaxPacketSize
312 KEYBOARD_INTERVAL, // bInterval
313 #endif // KEYBOARD_INTERFACE
315 #ifdef MOUSE_INTERFACE
316 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
318 4, // bDescriptorType
319 MOUSE_INTERFACE, // bInterfaceNumber
320 0, // bAlternateSetting
322 0x03, // bInterfaceClass (0x03 = HID)
323 0x00, // bInterfaceSubClass (0x01 = Boot)
324 0x00, // bInterfaceProtocol (0x02 = Mouse)
326 // HID interface descriptor, HID 1.11 spec, section 6.2.1
328 0x21, // bDescriptorType
329 0x11, 0x01, // bcdHID
331 1, // bNumDescriptors
332 0x22, // bDescriptorType
333 LSB(sizeof(mouse_report_desc)), // wDescriptorLength
334 MSB(sizeof(mouse_report_desc)),
335 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
337 5, // bDescriptorType
338 MOUSE_ENDPOINT | 0x80, // bEndpointAddress
339 0x03, // bmAttributes (0x03=intr)
340 MOUSE_SIZE, 0, // wMaxPacketSize
341 MOUSE_INTERVAL, // bInterval
342 #endif // MOUSE_INTERFACE
347 // **************************************************************
348 // String Descriptors
349 // **************************************************************
351 // The descriptors above can provide human readable strings,
352 // referenced by index numbers. These descriptors are the
353 // actual string data
355 struct usb_string_descriptor_struct {
357 uint8_t bDescriptorType;
361 static struct usb_string_descriptor_struct string0 = {
367 static struct usb_string_descriptor_struct string1 = {
368 sizeof(STR_MANUFACTURER),
372 static struct usb_string_descriptor_struct string2 = {
377 static struct usb_string_descriptor_struct string3 = {
384 // **************************************************************
386 // **************************************************************
388 // This table provides access to all the descriptor data above.
390 const usb_descriptor_list_t usb_descriptor_list[] = {
391 //wValue, wIndex, address, length
392 {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
393 {0x0200, 0x0000, config_descriptor, sizeof(config_descriptor)},
394 #ifdef KEYBOARD_INTERFACE
395 {0x2200, KEYBOARD_INTERFACE, keyboard_report_desc, sizeof(keyboard_report_desc)},
396 {0x2100, KEYBOARD_INTERFACE, config_descriptor+KEYBOARD_DESC_OFFSET, 9},
398 #ifdef MOUSE_INTERFACE
399 {0x2200, MOUSE_INTERFACE, mouse_report_desc, sizeof(mouse_report_desc)},
400 {0x2100, MOUSE_INTERFACE, config_descriptor+MOUSE_DESC_OFFSET, 9},
402 {0x0300, 0x0000, (const uint8_t *)&string0, 4},
403 {0x0301, 0x0409, (const uint8_t *)&string1, sizeof(STR_MANUFACTURER)},
404 {0x0302, 0x0409, (const uint8_t *)&string2, sizeof(STR_PRODUCT)},
405 {0x0303, 0x0409, (const uint8_t *)&string3, sizeof(STR_SERIAL)},
410 // **************************************************************
411 // Endpoint Configuration
412 // **************************************************************
416 // 0x19 = Recieve only
417 // 0x15 = Transmit only
418 // 0x1D = Transmit & Recieve
420 const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
422 0x00, 0x15, 0x19, 0x15, 0x00, 0x00, 0x00, 0x00,
423 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
428 const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
430 #if (defined(ENDPOINT1_CONFIG) && NUM_ENDPOINTS >= 1)
432 #elif (NUM_ENDPOINTS >= 1)
435 #if (defined(ENDPOINT2_CONFIG) && NUM_ENDPOINTS >= 2)
437 #elif (NUM_ENDPOINTS >= 2)
440 #if (defined(ENDPOINT3_CONFIG) && NUM_ENDPOINTS >= 3)
442 #elif (NUM_ENDPOINTS >= 3)
445 #if (defined(ENDPOINT4_CONFIG) && NUM_ENDPOINTS >= 4)
447 #elif (NUM_ENDPOINTS >= 4)
450 #if (defined(ENDPOINT5_CONFIG) && NUM_ENDPOINTS >= 5)
452 #elif (NUM_ENDPOINTS >= 5)
455 #if (defined(ENDPOINT6_CONFIG) && NUM_ENDPOINTS >= 6)
457 #elif (NUM_ENDPOINTS >= 6)
460 #if (defined(ENDPOINT7_CONFIG) && NUM_ENDPOINTS >= 7)
462 #elif (NUM_ENDPOINTS >= 7)
465 #if (defined(ENDPOINT8_CONFIG) && NUM_ENDPOINTS >= 8)
467 #elif (NUM_ENDPOINTS >= 8)
470 #if (defined(ENDPOINT9_CONFIG) && NUM_ENDPOINTS >= 9)
472 #elif (NUM_ENDPOINTS >= 9)
475 #if (defined(ENDPOINT10_CONFIG) && NUM_ENDPOINTS >= 10)
477 #elif (NUM_ENDPOINTS >= 10)
480 #if (defined(ENDPOINT11_CONFIG) && NUM_ENDPOINTS >= 11)
482 #elif (NUM_ENDPOINTS >= 11)
485 #if (defined(ENDPOINT12_CONFIG) && NUM_ENDPOINTS >= 12)
487 #elif (NUM_ENDPOINTS >= 12)
490 #if (defined(ENDPOINT13_CONFIG) && NUM_ENDPOINTS >= 13)
492 #elif (NUM_ENDPOINTS >= 13)
495 #if (defined(ENDPOINT14_CONFIG) && NUM_ENDPOINTS >= 14)
497 #elif (NUM_ENDPOINTS >= 14)
500 #if (defined(ENDPOINT15_CONFIG) && NUM_ENDPOINTS >= 15)
502 #elif (NUM_ENDPOINTS >= 15)