4 // USB Descriptors are binary data which the USB host reads to
5 // automatically detect a USB device's capabilities. The format
6 // and meaning of every field is documented in numerous USB
7 // standards. When working with USB descriptors, despite the
8 // complexity of the standards and poor writing quality in many
9 // of those documents, remember descriptors are nothing more
10 // than constant binary data that tells the USB host what the
11 // device can do. Computers will load drivers based on this data.
12 // Those drivers then communicate on the endpoints specified by
15 // To configure a new combination of interfaces or make minor
16 // changes to existing configuration (eg, change the name or ID
17 // numbers), usually you would edit "usb_desc.h". This file
18 // is meant to be configured by the header, so generally it is
19 // only edited to add completely new USB interfaces or features.
23 // **************************************************************
25 // **************************************************************
27 #define LSB(n) ((n) & 255)
28 #define MSB(n) (((n) >> 8) & 255)
30 // USB Device Descriptor. The USB host reads this first, to learn
31 // what type of device is connected.
32 static uint8_t device_descriptor[] = {
37 DEVICE_CLASS, // bDeviceClass
41 #ifdef DEVICE_SUBCLASS
42 DEVICE_SUBCLASS, // bDeviceSubClass
46 #ifdef DEVICE_PROTOCOL
47 DEVICE_PROTOCOL, // bDeviceProtocol
51 EP0_SIZE, // bMaxPacketSize0
52 LSB(VENDOR_ID), MSB(VENDOR_ID), // idVendor
53 LSB(PRODUCT_ID), MSB(PRODUCT_ID), // idProduct
54 0x00, 0x01, // bcdDevice
58 1 // bNumConfigurations
61 // These descriptors must NOT be "const", because the USB DMA
62 // has trouble accessing flash memory with enough bandwidth
63 // while the processor is executing from flash.
67 // **************************************************************
68 // HID Report Descriptors
69 // **************************************************************
71 // Each HID interface needs a special report descriptor that tells
72 // the meaning and format of the data.
74 #ifdef KEYBOARD_INTERFACE
75 // Keyboard Protocol 1, HID 1.11 spec, Appendix B, page 59-60
76 static uint8_t keyboard_report_desc[] = {
77 0x05, 0x01, // Usage Page (Generic Desktop),
78 0x09, 0x06, // Usage (Keyboard),
79 0xA1, 0x01, // Collection (Application),
80 0x75, 0x01, // Report Size (1),
81 0x95, 0x08, // Report Count (8),
82 0x05, 0x07, // Usage Page (Key Codes),
83 0x19, 0xE0, // Usage Minimum (224),
84 0x29, 0xE7, // Usage Maximum (231),
85 0x15, 0x00, // Logical Minimum (0),
86 0x25, 0x01, // Logical Maximum (1),
87 0x81, 0x02, // Input (Data, Variable, Absolute), ;Modifier byte
88 0x95, 0x08, // Report Count (8),
89 0x75, 0x01, // Report Size (1),
90 0x15, 0x00, // Logical Minimum (0),
91 0x25, 0x01, // Logical Maximum (1),
92 0x05, 0x0C, // Usage Page (Consumer),
93 0x09, 0xE9, // Usage (Volume Increment),
94 0x09, 0xEA, // Usage (Volume Decrement),
95 0x09, 0xE2, // Usage (Mute),
96 0x09, 0xCD, // Usage (Play/Pause),
97 0x09, 0xB5, // Usage (Scan Next Track),
98 0x09, 0xB6, // Usage (Scan Previous Track),
99 0x09, 0xB7, // Usage (Stop),
100 0x09, 0xB8, // Usage (Eject),
101 0x81, 0x02, // Input (Data, Variable, Absolute), ;Media keys
102 0x95, 0x05, // Report Count (5),
103 0x75, 0x01, // Report Size (1),
104 0x05, 0x08, // Usage Page (LEDs),
105 0x19, 0x01, // Usage Minimum (1),
106 0x29, 0x05, // Usage Maximum (5),
107 0x91, 0x02, // Output (Data, Variable, Absolute), ;LED report
108 0x95, 0x01, // Report Count (1),
109 0x75, 0x03, // Report Size (3),
110 0x91, 0x03, // Output (Constant), ;LED report padding
111 0x95, 0x06, // Report Count (6),
112 0x75, 0x08, // Report Size (8),
113 0x15, 0x00, // Logical Minimum (0),
114 0x25, 0x7F, // Logical Maximum(104),
115 0x05, 0x07, // Usage Page (Key Codes),
116 0x19, 0x00, // Usage Minimum (0),
117 0x29, 0x7F, // Usage Maximum (104),
118 0x81, 0x00, // Input (Data, Array), ;Normal keys
119 0xc0 // End Collection
123 #ifdef MOUSE_INTERFACE
124 // Mouse Protocol 1, HID 1.11 spec, Appendix B, page 59-60, with wheel extension
125 static uint8_t mouse_report_desc[] = {
126 0x05, 0x01, // Usage Page (Generic Desktop)
127 0x09, 0x02, // Usage (Mouse)
128 0xA1, 0x01, // Collection (Application)
129 0x05, 0x09, // Usage Page (Button)
130 0x19, 0x01, // Usage Minimum (Button #1)
131 0x29, 0x03, // Usage Maximum (Button #3)
132 0x15, 0x00, // Logical Minimum (0)
133 0x25, 0x01, // Logical Maximum (1)
134 0x95, 0x03, // Report Count (3)
135 0x75, 0x01, // Report Size (1)
136 0x81, 0x02, // Input (Data, Variable, Absolute)
137 0x95, 0x01, // Report Count (1)
138 0x75, 0x05, // Report Size (5)
139 0x81, 0x03, // Input (Constant)
140 0x05, 0x01, // Usage Page (Generic Desktop)
141 0x09, 0x30, // Usage (X)
142 0x09, 0x31, // Usage (Y)
143 0x15, 0x81, // Logical Minimum (-127)
144 0x25, 0x7F, // Logical Maximum (127)
145 0x75, 0x08, // Report Size (8),
146 0x95, 0x02, // Report Count (2),
147 0x81, 0x06, // Input (Data, Variable, Relative)
148 0x09, 0x38, // Usage (Wheel)
149 0x95, 0x01, // Report Count (1),
150 0x81, 0x06, // Input (Data, Variable, Relative)
151 0xC0 // End Collection
157 // **************************************************************
159 // **************************************************************
161 // USB Configuration Descriptor. This huge descriptor tells all
162 // of the devices capbilities.
163 static uint8_t config_descriptor[CONFIG_DESC_SIZE] = {
164 // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
166 2, // bDescriptorType;
167 LSB(CONFIG_DESC_SIZE), // wTotalLength
168 MSB(CONFIG_DESC_SIZE),
169 NUM_INTERFACE, // bNumInterfaces
170 1, // bConfigurationValue
172 0xC0, // bmAttributes
175 #ifdef CDC_IAD_DESCRIPTOR
176 // interface association descriptor, USB ECN, Table 9-Z
178 11, // bDescriptorType
179 CDC_STATUS_INTERFACE, // bFirstInterface
180 2, // bInterfaceCount
181 0x02, // bFunctionClass
182 0x02, // bFunctionSubClass
183 0x01, // bFunctionProtocol
187 #ifdef CDC_DATA_INTERFACE
188 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
190 4, // bDescriptorType
191 CDC_STATUS_INTERFACE, // bInterfaceNumber
192 0, // bAlternateSetting
194 0x02, // bInterfaceClass
195 0x02, // bInterfaceSubClass
196 0x01, // bInterfaceProtocol
198 // CDC Header Functional Descriptor, CDC Spec 5.2.3.1, Table 26
199 5, // bFunctionLength
200 0x24, // bDescriptorType
201 0x00, // bDescriptorSubtype
202 0x10, 0x01, // bcdCDC
203 // Call Management Functional Descriptor, CDC Spec 5.2.3.2, Table 27
204 5, // bFunctionLength
205 0x24, // bDescriptorType
206 0x01, // bDescriptorSubtype
207 0x01, // bmCapabilities
209 // Abstract Control Management Functional Descriptor, CDC Spec 5.2.3.3, Table 28
210 4, // bFunctionLength
211 0x24, // bDescriptorType
212 0x02, // bDescriptorSubtype
213 0x06, // bmCapabilities
214 // Union Functional Descriptor, CDC Spec 5.2.3.8, Table 33
215 5, // bFunctionLength
216 0x24, // bDescriptorType
217 0x06, // bDescriptorSubtype
218 CDC_STATUS_INTERFACE, // bMasterInterface
219 CDC_DATA_INTERFACE, // bSlaveInterface0
220 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
222 5, // bDescriptorType
223 CDC_ACM_ENDPOINT | 0x80, // bEndpointAddress
224 0x03, // bmAttributes (0x03=intr)
225 CDC_ACM_SIZE, 0, // wMaxPacketSize
227 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
229 4, // bDescriptorType
230 CDC_DATA_INTERFACE, // bInterfaceNumber
231 0, // bAlternateSetting
233 0x0A, // bInterfaceClass
234 0x00, // bInterfaceSubClass
235 0x00, // bInterfaceProtocol
237 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
239 5, // bDescriptorType
240 CDC_RX_ENDPOINT, // bEndpointAddress
241 0x02, // bmAttributes (0x02=bulk)
242 CDC_RX_SIZE, 0, // wMaxPacketSize
244 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
246 5, // bDescriptorType
247 CDC_TX_ENDPOINT | 0x80, // bEndpointAddress
248 0x02, // bmAttributes (0x02=bulk)
249 CDC_TX_SIZE, 0, // wMaxPacketSize
251 #endif // CDC_DATA_INTERFACE
253 #ifdef KEYBOARD_INTERFACE
254 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
256 4, // bDescriptorType
257 KEYBOARD_INTERFACE, // bInterfaceNumber
258 0, // bAlternateSetting
260 0x03, // bInterfaceClass (0x03 = HID)
261 0x01, // bInterfaceSubClass (0x01 = Boot)
262 0x01, // bInterfaceProtocol (0x01 = Keyboard)
264 // HID interface descriptor, HID 1.11 spec, section 6.2.1
266 0x21, // bDescriptorType
267 0x11, 0x01, // bcdHID
269 1, // bNumDescriptors
270 0x22, // bDescriptorType
271 LSB(sizeof(keyboard_report_desc)), // wDescriptorLength
272 MSB(sizeof(keyboard_report_desc)),
273 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
275 5, // bDescriptorType
276 KEYBOARD_ENDPOINT | 0x80, // bEndpointAddress
277 0x03, // bmAttributes (0x03=intr)
278 KEYBOARD_SIZE, 0, // wMaxPacketSize
279 KEYBOARD_INTERVAL, // bInterval
280 #endif // KEYBOARD_INTERFACE
282 #ifdef MOUSE_INTERFACE
283 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
285 4, // bDescriptorType
286 MOUSE_INTERFACE, // bInterfaceNumber
287 0, // bAlternateSetting
289 0x03, // bInterfaceClass (0x03 = HID)
290 0x01, // bInterfaceSubClass (0x01 = Boot)
291 0x02, // bInterfaceProtocol (0x02 = Mouse)
293 // HID interface descriptor, HID 1.11 spec, section 6.2.1
295 0x21, // bDescriptorType
296 0x11, 0x01, // bcdHID
298 1, // bNumDescriptors
299 0x22, // bDescriptorType
300 LSB(sizeof(mouse_report_desc)), // wDescriptorLength
301 MSB(sizeof(mouse_report_desc)),
302 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
304 5, // bDescriptorType
305 MOUSE_ENDPOINT | 0x80, // bEndpointAddress
306 0x03, // bmAttributes (0x03=intr)
307 MOUSE_SIZE, 0, // wMaxPacketSize
308 MOUSE_INTERVAL, // bInterval
309 #endif // MOUSE_INTERFACE
314 // **************************************************************
315 // String Descriptors
316 // **************************************************************
318 // The descriptors above can provide human readable strings,
319 // referenced by index numbers. These descriptors are the
320 // actual string data
322 struct usb_string_descriptor_struct {
324 uint8_t bDescriptorType;
328 static struct usb_string_descriptor_struct string0 = {
334 static struct usb_string_descriptor_struct string1 = {
335 sizeof(STR_MANUFACTURER),
339 static struct usb_string_descriptor_struct string2 = {
344 static struct usb_string_descriptor_struct string3 = {
351 // **************************************************************
353 // **************************************************************
355 // This table provides access to all the descriptor data above.
357 const usb_descriptor_list_t usb_descriptor_list[] = {
358 //wValue, wIndex, address, length
359 {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
360 {0x0200, 0x0000, config_descriptor, sizeof(config_descriptor)},
361 #ifdef KEYBOARD_INTERFACE
362 {0x2200, KEYBOARD_INTERFACE, keyboard_report_desc, sizeof(keyboard_report_desc)},
363 {0x2100, KEYBOARD_INTERFACE, config_descriptor+KEYBOARD_DESC_OFFSET, 9},
365 #ifdef MOUSE_INTERFACE
366 {0x2200, MOUSE_INTERFACE, mouse_report_desc, sizeof(mouse_report_desc)},
367 {0x2100, MOUSE_INTERFACE, config_descriptor+MOUSE_DESC_OFFSET, 9},
369 {0x0300, 0x0000, (const uint8_t *)&string0, 4},
370 {0x0301, 0x0409, (const uint8_t *)&string1, sizeof(STR_MANUFACTURER)},
371 {0x0302, 0x0409, (const uint8_t *)&string2, sizeof(STR_PRODUCT)},
372 {0x0303, 0x0409, (const uint8_t *)&string3, sizeof(STR_SERIAL)},
377 // **************************************************************
378 // Endpoint Configuration
379 // **************************************************************
383 // 0x19 = Recieve only
384 // 0x15 = Transmit only
385 // 0x1D = Transmit & Recieve
387 const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
389 0x00, 0x15, 0x19, 0x15, 0x00, 0x00, 0x00, 0x00,
390 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
395 const uint8_t usb_endpoint_config_table[NUM_ENDPOINTS] =
397 #if (defined(ENDPOINT1_CONFIG) && NUM_ENDPOINTS >= 1)
399 #elif (NUM_ENDPOINTS >= 1)
402 #if (defined(ENDPOINT2_CONFIG) && NUM_ENDPOINTS >= 2)
404 #elif (NUM_ENDPOINTS >= 2)
407 #if (defined(ENDPOINT3_CONFIG) && NUM_ENDPOINTS >= 3)
409 #elif (NUM_ENDPOINTS >= 3)
412 #if (defined(ENDPOINT4_CONFIG) && NUM_ENDPOINTS >= 4)
414 #elif (NUM_ENDPOINTS >= 4)
417 #if (defined(ENDPOINT5_CONFIG) && NUM_ENDPOINTS >= 5)
419 #elif (NUM_ENDPOINTS >= 5)
422 #if (defined(ENDPOINT6_CONFIG) && NUM_ENDPOINTS >= 6)
424 #elif (NUM_ENDPOINTS >= 6)
427 #if (defined(ENDPOINT7_CONFIG) && NUM_ENDPOINTS >= 7)
429 #elif (NUM_ENDPOINTS >= 7)
432 #if (defined(ENDPOINT8_CONFIG) && NUM_ENDPOINTS >= 8)
434 #elif (NUM_ENDPOINTS >= 8)
437 #if (defined(ENDPOINT9_CONFIG) && NUM_ENDPOINTS >= 9)
439 #elif (NUM_ENDPOINTS >= 9)
442 #if (defined(ENDPOINT10_CONFIG) && NUM_ENDPOINTS >= 10)
444 #elif (NUM_ENDPOINTS >= 10)
447 #if (defined(ENDPOINT11_CONFIG) && NUM_ENDPOINTS >= 11)
449 #elif (NUM_ENDPOINTS >= 11)
452 #if (defined(ENDPOINT12_CONFIG) && NUM_ENDPOINTS >= 12)
454 #elif (NUM_ENDPOINTS >= 12)
457 #if (defined(ENDPOINT13_CONFIG) && NUM_ENDPOINTS >= 13)
459 #elif (NUM_ENDPOINTS >= 13)
462 #if (defined(ENDPOINT14_CONFIG) && NUM_ENDPOINTS >= 14)
464 #elif (NUM_ENDPOINTS >= 14)
467 #if (defined(ENDPOINT15_CONFIG) && NUM_ENDPOINTS >= 15)
469 #elif (NUM_ENDPOINTS >= 15)