Fix code style in the HID parser module.
[pub/USBasp.git] / LUFA / Drivers / USB / Core / StdDescriptors.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2013.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2013 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaims all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 /** \file
32 * \brief Common standard USB Descriptor definitions for all architectures.
33 * \copydetails Group_StdDescriptors
34 *
35 * \note This file should not be included directly. It is automatically included as needed by the USB driver
36 * dispatch header located in LUFA/Drivers/USB/USB.h.
37 */
38
39 /** \ingroup Group_USB
40 * \defgroup Group_StdDescriptors USB Descriptors
41 * \brief Standard USB Descriptor definitions.
42 *
43 * Standard USB device descriptor defines and retrieval routines, for USB devices. This module contains
44 * structures and macros for the easy creation of standard USB descriptors in USB device projects.
45 *
46 * @{
47 */
48
49 #ifndef __USBDESCRIPTORS_H__
50 #define __USBDESCRIPTORS_H__
51
52 /* Includes: */
53 #include "../../../Common/Common.h"
54 #include "USBMode.h"
55 #include "Events.h"
56
57 /* Enable C linkage for C++ Compilers: */
58 #if defined(__cplusplus)
59 extern "C" {
60 #endif
61
62 /* Preprocessor Checks: */
63 #if !defined(__INCLUDE_FROM_USB_DRIVER)
64 #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
65 #endif
66
67 /* Public Interface - May be used in end-application: */
68 /* Macros: */
69 /** Indicates that a given descriptor does not exist in the device. This can be used inside descriptors
70 * for string descriptor indexes, or may be use as a return value for GetDescriptor when the specified
71 * descriptor does not exist.
72 */
73 #define NO_DESCRIPTOR 0
74
75 /** Macro to calculate the power value for the configuration descriptor, from a given number of milliamperes.
76 *
77 * \param[in] mA Maximum number of milliamps the device consumes when the given configuration is selected.
78 */
79 #define USB_CONFIG_POWER_MA(mA) ((mA) >> 1)
80
81 /** Macro to calculate the Unicode length of a string with a given number of Unicode characters.
82 * Should be used in string descriptor's headers for giving the string descriptor's byte length.
83 *
84 * \param[in] UnicodeChars Number of Unicode characters in the string text.
85 */
86 #define USB_STRING_LEN(UnicodeChars) (sizeof(USB_Descriptor_Header_t) + ((UnicodeChars) << 1))
87
88 /** Macro to encode a given four digit floating point version number (e.g. 01.23) into Binary Coded
89 * Decimal format for descriptor fields requiring BCD encoding, such as the USB version number in the
90 * standard device descriptor.
91 *
92 * \note This value is automatically converted into Little Endian, suitable for direct use inside device
93 * descriptors on all architectures without endianness conversion macros.
94 *
95 * \param[in] x Version number to encode as a 16-bit little-endian number, as a floating point number.
96 */
97 #define VERSION_BCD(x) CPU_TO_LE16((VERSION_TENS(x) << 12) | (VERSION_ONES(x) << 8) | \
98 (VERSION_TENTHS(x) << 4) | (VERSION_HUNDREDTHS(x) << 0) )
99
100 /** String language ID for the English language. Should be used in \ref USB_Descriptor_String_t descriptors
101 * to indicate that the English language is supported by the device in its string descriptors.
102 */
103 #define LANGUAGE_ID_ENG 0x0409
104
105 /** \name USB Configuration Descriptor Attribute Masks */
106 //@{
107 /** Mask for the reserved bit in the Configuration Descriptor's \c ConfigAttributes field, which must be set on all
108 * devices for historical purposes.
109 */
110 #define USB_CONFIG_ATTR_RESERVED 0x80
111
112 /** Can be masked with other configuration descriptor attributes for a \ref USB_Descriptor_Configuration_Header_t
113 * descriptor's \c ConfigAttributes value to indicate that the specified configuration can draw its power
114 * from the device's own power source.
115 */
116 #define USB_CONFIG_ATTR_SELFPOWERED 0x40
117
118 /** Can be masked with other configuration descriptor attributes for a \ref USB_Descriptor_Configuration_Header_t
119 * descriptor's \c ConfigAttributes value to indicate that the specified configuration supports the
120 * remote wakeup feature of the USB standard, allowing a suspended USB device to wake up the host upon
121 * request.
122 */
123 #define USB_CONFIG_ATTR_REMOTEWAKEUP 0x20
124 //@}
125
126 /** \name Endpoint Descriptor Attribute Masks */
127 //@{
128 /** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
129 * \c Attributes value to indicate that the specified endpoint is not synchronized.
130 *
131 * \see The USB specification for more details on the possible Endpoint attributes.
132 */
133 #define ENDPOINT_ATTR_NO_SYNC (0 << 2)
134
135 /** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
136 * \c Attributes value to indicate that the specified endpoint is asynchronous.
137 *
138 * \see The USB specification for more details on the possible Endpoint attributes.
139 */
140 #define ENDPOINT_ATTR_ASYNC (1 << 2)
141
142 /** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
143 * \c Attributes value to indicate that the specified endpoint is adaptive.
144 *
145 * \see The USB specification for more details on the possible Endpoint attributes.
146 */
147 #define ENDPOINT_ATTR_ADAPTIVE (2 << 2)
148
149 /** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
150 * \c Attributes value to indicate that the specified endpoint is synchronized.
151 *
152 * \see The USB specification for more details on the possible Endpoint attributes.
153 */
154 #define ENDPOINT_ATTR_SYNC (3 << 2)
155 //@}
156
157 /** \name Endpoint Descriptor Usage Masks */
158 //@{
159 /** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
160 * \c Attributes value to indicate that the specified endpoint is used for data transfers.
161 *
162 * \see The USB specification for more details on the possible Endpoint usage attributes.
163 */
164 #define ENDPOINT_USAGE_DATA (0 << 4)
165
166 /** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
167 * \c Attributes value to indicate that the specified endpoint is used for feedback.
168 *
169 * \see The USB specification for more details on the possible Endpoint usage attributes.
170 */
171 #define ENDPOINT_USAGE_FEEDBACK (1 << 4)
172
173 /** Can be masked with other endpoint descriptor attributes for a \ref USB_Descriptor_Endpoint_t descriptor's
174 * \c Attributes value to indicate that the specified endpoint is used for implicit feedback.
175 *
176 * \see The USB specification for more details on the possible Endpoint usage attributes.
177 */
178 #define ENDPOINT_USAGE_IMPLICIT_FEEDBACK (2 << 4)
179 //@}
180
181 /* Enums: */
182 /** Enum for the possible standard descriptor types, as given in each descriptor's header. */
183 enum USB_DescriptorTypes_t
184 {
185 DTYPE_Device = 0x01, /**< Indicates that the descriptor is a device descriptor. */
186 DTYPE_Configuration = 0x02, /**< Indicates that the descriptor is a configuration descriptor. */
187 DTYPE_String = 0x03, /**< Indicates that the descriptor is a string descriptor. */
188 DTYPE_Interface = 0x04, /**< Indicates that the descriptor is an interface descriptor. */
189 DTYPE_Endpoint = 0x05, /**< Indicates that the descriptor is an endpoint descriptor. */
190 DTYPE_DeviceQualifier = 0x06, /**< Indicates that the descriptor is a device qualifier descriptor. */
191 DTYPE_Other = 0x07, /**< Indicates that the descriptor is of other type. */
192 DTYPE_InterfacePower = 0x08, /**< Indicates that the descriptor is an interface power descriptor. */
193 DTYPE_InterfaceAssociation = 0x0B, /**< Indicates that the descriptor is an interface association descriptor. */
194 DTYPE_CSInterface = 0x24, /**< Indicates that the descriptor is a class specific interface descriptor. */
195 DTYPE_CSEndpoint = 0x25, /**< Indicates that the descriptor is a class specific endpoint descriptor. */
196 };
197
198 /** Enum for possible Class, Subclass and Protocol values of device and interface descriptors. */
199 enum USB_Descriptor_ClassSubclassProtocol_t
200 {
201 USB_CSCP_NoDeviceClass = 0x00, /**< Descriptor Class value indicating that the device does not belong
202 * to a particular class at the device level.
203 */
204 USB_CSCP_NoDeviceSubclass = 0x00, /**< Descriptor Subclass value indicating that the device does not belong
205 * to a particular subclass at the device level.
206 */
207 USB_CSCP_NoDeviceProtocol = 0x00, /**< Descriptor Protocol value indicating that the device does not belong
208 * to a particular protocol at the device level.
209 */
210 USB_CSCP_VendorSpecificClass = 0xFF, /**< Descriptor Class value indicating that the device/interface belongs
211 * to a vendor specific class.
212 */
213 USB_CSCP_VendorSpecificSubclass = 0xFF, /**< Descriptor Subclass value indicating that the device/interface belongs
214 * to a vendor specific subclass.
215 */
216 USB_CSCP_VendorSpecificProtocol = 0xFF, /**< Descriptor Protocol value indicating that the device/interface belongs
217 * to a vendor specific protocol.
218 */
219 USB_CSCP_IADDeviceClass = 0xEF, /**< Descriptor Class value indicating that the device belongs to the
220 * Interface Association Descriptor class.
221 */
222 USB_CSCP_IADDeviceSubclass = 0x02, /**< Descriptor Subclass value indicating that the device belongs to the
223 * Interface Association Descriptor subclass.
224 */
225 USB_CSCP_IADDeviceProtocol = 0x01, /**< Descriptor Protocol value indicating that the device belongs to the
226 * Interface Association Descriptor protocol.
227 */
228 };
229
230 /* Type Defines: */
231 /** \brief Standard USB Descriptor Header (LUFA naming conventions).
232 *
233 * Type define for all descriptors' standard header, indicating the descriptor's length and type. This structure
234 * uses LUFA-specific element names to make each element's purpose clearer.
235 *
236 * \see \ref USB_StdDescriptor_Header_t for the version of this type with standard element names.
237 *
238 * \note Regardless of CPU architecture, these values should be stored as little endian.
239 */
240 typedef struct
241 {
242 uint8_t Size; /**< Size of the descriptor, in bytes. */
243 uint8_t Type; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
244 * given by the specific class.
245 */
246 } ATTR_PACKED USB_Descriptor_Header_t;
247
248 /** \brief Standard USB Descriptor Header (USB-IF naming conventions).
249 *
250 * Type define for all descriptors' standard header, indicating the descriptor's length and type. This structure
251 * uses the relevant standard's given element names to ensure compatibility with the standard.
252 *
253 * \see \ref USB_Descriptor_Header_t for the version of this type with non-standard LUFA specific element names.
254 *
255 * \note Regardless of CPU architecture, these values should be stored as little endian.
256 */
257 typedef struct
258 {
259 uint8_t bLength; /**< Size of the descriptor, in bytes. */
260 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
261 * given by the specific class.
262 */
263 } ATTR_PACKED USB_StdDescriptor_Header_t;
264
265 /** \brief Standard USB Device Descriptor (LUFA naming conventions).
266 *
267 * Type define for a standard Device Descriptor. This structure uses LUFA-specific element names to make each
268 * element's purpose clearer.
269 *
270 * \see \ref USB_StdDescriptor_Device_t for the version of this type with standard element names.
271 *
272 * \note Regardless of CPU architecture, these values should be stored as little endian.
273 */
274 typedef struct
275 {
276 USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
277
278 uint16_t USBSpecification; /**< BCD of the supported USB specification.
279 *
280 * \see \ref VERSION_BCD() utility macro.
281 */
282 uint8_t Class; /**< USB device class. */
283 uint8_t SubClass; /**< USB device subclass. */
284 uint8_t Protocol; /**< USB device protocol. */
285
286 uint8_t Endpoint0Size; /**< Size of the control (address 0) endpoint's bank in bytes. */
287
288 uint16_t VendorID; /**< Vendor ID for the USB product. */
289 uint16_t ProductID; /**< Unique product ID for the USB product. */
290 uint16_t ReleaseNumber; /**< Product release (version) number.
291 *
292 * \see \ref VERSION_BCD() utility macro.
293 */
294 uint8_t ManufacturerStrIndex; /**< String index for the manufacturer's name. The
295 * host will request this string via a separate
296 * control request for the string descriptor.
297 *
298 * \note If no string supplied, use \ref NO_DESCRIPTOR.
299 */
300 uint8_t ProductStrIndex; /**< String index for the product name/details.
301 *
302 * \see ManufacturerStrIndex structure entry.
303 */
304 uint8_t SerialNumStrIndex; /**< String index for the product's globally unique hexadecimal
305 * serial number, in uppercase Unicode ASCII.
306 *
307 * \note On some microcontroller models, there is an embedded serial number
308 * in the chip which can be used for the device serial number.
309 * To use this serial number, set this to \c USE_INTERNAL_SERIAL.
310 * On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR
311 * and will cause the host to generate a pseudo-unique value for the
312 * device upon insertion.
313 *
314 * \see \c ManufacturerStrIndex structure entry.
315 */
316 uint8_t NumberOfConfigurations; /**< Total number of configurations supported by
317 * the device.
318 */
319 } ATTR_PACKED USB_Descriptor_Device_t;
320
321 /** \brief Standard USB Device Descriptor (USB-IF naming conventions).
322 *
323 * Type define for a standard Device Descriptor. This structure uses the relevant standard's given element names
324 * to ensure compatibility with the standard.
325 *
326 * \see \ref USB_Descriptor_Device_t for the version of this type with non-standard LUFA specific element names.
327 *
328 * \note Regardless of CPU architecture, these values should be stored as little endian.
329 */
330 typedef struct
331 {
332 uint8_t bLength; /**< Size of the descriptor, in bytes. */
333 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
334 * given by the specific class.
335 */
336 uint16_t bcdUSB; /**< BCD of the supported USB specification.
337 *
338 * \see \ref VERSION_BCD() utility macro.
339 */
340 uint8_t bDeviceClass; /**< USB device class. */
341 uint8_t bDeviceSubClass; /**< USB device subclass. */
342 uint8_t bDeviceProtocol; /**< USB device protocol. */
343 uint8_t bMaxPacketSize0; /**< Size of the control (address 0) endpoint's bank in bytes. */
344 uint16_t idVendor; /**< Vendor ID for the USB product. */
345 uint16_t idProduct; /**< Unique product ID for the USB product. */
346 uint16_t bcdDevice; /**< Product release (version) number.
347 *
348 * \see \ref VERSION_BCD() utility macro.
349 */
350 uint8_t iManufacturer; /**< String index for the manufacturer's name. The
351 * host will request this string via a separate
352 * control request for the string descriptor.
353 *
354 * \note If no string supplied, use \ref NO_DESCRIPTOR.
355 */
356 uint8_t iProduct; /**< String index for the product name/details.
357 *
358 * \see ManufacturerStrIndex structure entry.
359 */
360 uint8_t iSerialNumber; /**< String index for the product's globally unique hexadecimal
361 * serial number, in uppercase Unicode ASCII.
362 *
363 * \note On some microcontroller models, there is an embedded serial number
364 * in the chip which can be used for the device serial number.
365 * To use this serial number, set this to \c USE_INTERNAL_SERIAL.
366 * On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR
367 * and will cause the host to generate a pseudo-unique value for the
368 * device upon insertion.
369 *
370 * \see \c ManufacturerStrIndex structure entry.
371 */
372 uint8_t bNumConfigurations; /**< Total number of configurations supported by
373 * the device.
374 */
375 } ATTR_PACKED USB_StdDescriptor_Device_t;
376
377 /** \brief Standard USB Device Qualifier Descriptor (LUFA naming conventions).
378 *
379 * Type define for a standard Device Qualifier Descriptor. This structure uses LUFA-specific element names
380 * to make each element's purpose clearer.
381 *
382 * \see \ref USB_StdDescriptor_DeviceQualifier_t for the version of this type with standard element names.
383 */
384 typedef struct
385 {
386 USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
387
388 uint16_t USBSpecification; /**< BCD of the supported USB specification.
389 *
390 * \see \ref VERSION_BCD() utility macro.
391 */
392 uint8_t Class; /**< USB device class. */
393 uint8_t SubClass; /**< USB device subclass. */
394 uint8_t Protocol; /**< USB device protocol. */
395
396 uint8_t Endpoint0Size; /**< Size of the control (address 0) endpoint's bank in bytes. */
397 uint8_t NumberOfConfigurations; /**< Total number of configurations supported by
398 * the device.
399 */
400 uint8_t Reserved; /**< Reserved for future use, must be 0. */
401 } ATTR_PACKED USB_Descriptor_DeviceQualifier_t;
402
403 /** \brief Standard USB Device Qualifier Descriptor (USB-IF naming conventions).
404 *
405 * Type define for a standard Device Qualifier Descriptor. This structure uses the relevant standard's given element names
406 * to ensure compatibility with the standard.
407 *
408 * \see \ref USB_Descriptor_DeviceQualifier_t for the version of this type with non-standard LUFA specific element names.
409 */
410 typedef struct
411 {
412 uint8_t bLength; /**< Size of the descriptor, in bytes. */
413 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
414 * given by the specific class.
415 */
416 uint16_t bcdUSB; /**< BCD of the supported USB specification.
417 *
418 * \see \ref VERSION_BCD() utility macro.
419 */
420 uint8_t bDeviceClass; /**< USB device class. */
421 uint8_t bDeviceSubClass; /**< USB device subclass. */
422 uint8_t bDeviceProtocol; /**< USB device protocol. */
423 uint8_t bMaxPacketSize0; /**< Size of the control (address 0) endpoint's bank in bytes. */
424 uint8_t bNumConfigurations; /**< Total number of configurations supported by
425 * the device.
426 */
427 uint8_t bReserved; /**< Reserved for future use, must be 0. */
428 } ATTR_PACKED USB_StdDescriptor_DeviceQualifier_t;
429
430 /** \brief Standard USB Configuration Descriptor (LUFA naming conventions).
431 *
432 * Type define for a standard Configuration Descriptor header. This structure uses LUFA-specific element names
433 * to make each element's purpose clearer.
434 *
435 * \see \ref USB_StdDescriptor_Configuration_Header_t for the version of this type with standard element names.
436 *
437 * \note Regardless of CPU architecture, these values should be stored as little endian.
438 */
439 typedef struct
440 {
441 USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
442
443 uint16_t TotalConfigurationSize; /**< Size of the configuration descriptor header,
444 * and all sub descriptors inside the configuration.
445 */
446 uint8_t TotalInterfaces; /**< Total number of interfaces in the configuration. */
447
448 uint8_t ConfigurationNumber; /**< Configuration index of the current configuration. */
449 uint8_t ConfigurationStrIndex; /**< Index of a string descriptor describing the configuration. */
450
451 uint8_t ConfigAttributes; /**< Configuration attributes, comprised of a mask of \c USB_CONFIG_ATTR_* masks.
452 * On all devices, this should include USB_CONFIG_ATTR_RESERVED at a minimum.
453 */
454
455 uint8_t MaxPowerConsumption; /**< Maximum power consumption of the device while in the
456 * current configuration, calculated by the \ref USB_CONFIG_POWER_MA()
457 * macro.
458 */
459 } ATTR_PACKED USB_Descriptor_Configuration_Header_t;
460
461 /** \brief Standard USB Configuration Descriptor (USB-IF naming conventions).
462 *
463 * Type define for a standard Configuration Descriptor header. This structure uses the relevant standard's given element names
464 * to ensure compatibility with the standard.
465 *
466 * \see \ref USB_Descriptor_Device_t for the version of this type with non-standard LUFA specific element names.
467 *
468 * \note Regardless of CPU architecture, these values should be stored as little endian.
469 */
470 typedef struct
471 {
472 uint8_t bLength; /**< Size of the descriptor, in bytes. */
473 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
474 * given by the specific class.
475 */
476 uint16_t wTotalLength; /**< Size of the configuration descriptor header,
477 * and all sub descriptors inside the configuration.
478 */
479 uint8_t bNumInterfaces; /**< Total number of interfaces in the configuration. */
480 uint8_t bConfigurationValue; /**< Configuration index of the current configuration. */
481 uint8_t iConfiguration; /**< Index of a string descriptor describing the configuration. */
482 uint8_t bmAttributes; /**< Configuration attributes, comprised of a mask of \c USB_CONFIG_ATTR_* masks.
483 * On all devices, this should include USB_CONFIG_ATTR_RESERVED at a minimum.
484 */
485 uint8_t bMaxPower; /**< Maximum power consumption of the device while in the
486 * current configuration, calculated by the \ref USB_CONFIG_POWER_MA()
487 * macro.
488 */
489 } ATTR_PACKED USB_StdDescriptor_Configuration_Header_t;
490
491 /** \brief Standard USB Interface Descriptor (LUFA naming conventions).
492 *
493 * Type define for a standard Interface Descriptor. This structure uses LUFA-specific element names
494 * to make each element's purpose clearer.
495 *
496 * \see \ref USB_StdDescriptor_Interface_t for the version of this type with standard element names.
497 *
498 * \note Regardless of CPU architecture, these values should be stored as little endian.
499 */
500 typedef struct
501 {
502 USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
503
504 uint8_t InterfaceNumber; /**< Index of the interface in the current configuration. */
505 uint8_t AlternateSetting; /**< Alternate setting for the interface number. The same
506 * interface number can have multiple alternate settings
507 * with different endpoint configurations, which can be
508 * selected by the host.
509 */
510 uint8_t TotalEndpoints; /**< Total number of endpoints in the interface. */
511
512 uint8_t Class; /**< Interface class ID. */
513 uint8_t SubClass; /**< Interface subclass ID. */
514 uint8_t Protocol; /**< Interface protocol ID. */
515
516 uint8_t InterfaceStrIndex; /**< Index of the string descriptor describing the interface. */
517 } ATTR_PACKED USB_Descriptor_Interface_t;
518
519 /** \brief Standard USB Interface Descriptor (USB-IF naming conventions).
520 *
521 * Type define for a standard Interface Descriptor. This structure uses the relevant standard's given element names
522 * to ensure compatibility with the standard.
523 *
524 * \see \ref USB_Descriptor_Interface_t for the version of this type with non-standard LUFA specific element names.
525 *
526 * \note Regardless of CPU architecture, these values should be stored as little endian.
527 */
528 typedef struct
529 {
530 uint8_t bLength; /**< Size of the descriptor, in bytes. */
531 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
532 * given by the specific class.
533 */
534 uint8_t bInterfaceNumber; /**< Index of the interface in the current configuration. */
535 uint8_t bAlternateSetting; /**< Alternate setting for the interface number. The same
536 * interface number can have multiple alternate settings
537 * with different endpoint configurations, which can be
538 * selected by the host.
539 */
540 uint8_t bNumEndpoints; /**< Total number of endpoints in the interface. */
541 uint8_t bInterfaceClass; /**< Interface class ID. */
542 uint8_t bInterfaceSubClass; /**< Interface subclass ID. */
543 uint8_t bInterfaceProtocol; /**< Interface protocol ID. */
544 uint8_t iInterface; /**< Index of the string descriptor describing the
545 * interface.
546 */
547 } ATTR_PACKED USB_StdDescriptor_Interface_t;
548
549 /** \brief Standard USB Interface Association Descriptor (LUFA naming conventions).
550 *
551 * Type define for a standard Interface Association Descriptor. This structure uses LUFA-specific element names
552 * to make each element's purpose clearer.
553 *
554 * This descriptor has been added as a supplement to the USB2.0 standard, in the ECN located at
555 * <a>http://www.usb.org/developers/docs/InterfaceAssociationDescriptor_ecn.pdf</a>. It allows composite
556 * devices with multiple interfaces related to the same function to have the multiple interfaces bound
557 * together at the point of enumeration, loading one generic driver for all the interfaces in the single
558 * function. Read the ECN for more information.
559 *
560 * \see \ref USB_StdDescriptor_Interface_Association_t for the version of this type with standard element names.
561 *
562 * \note Regardless of CPU architecture, these values should be stored as little endian.
563 */
564 typedef struct
565 {
566 USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
567
568 uint8_t FirstInterfaceIndex; /**< Index of the first associated interface. */
569 uint8_t TotalInterfaces; /**< Total number of associated interfaces. */
570
571 uint8_t Class; /**< Interface class ID. */
572 uint8_t SubClass; /**< Interface subclass ID. */
573 uint8_t Protocol; /**< Interface protocol ID. */
574
575 uint8_t IADStrIndex; /**< Index of the string descriptor describing the
576 * interface association.
577 */
578 } ATTR_PACKED USB_Descriptor_Interface_Association_t;
579
580 /** \brief Standard USB Interface Association Descriptor (USB-IF naming conventions).
581 *
582 * Type define for a standard Interface Association Descriptor. This structure uses the relevant standard's given
583 * element names to ensure compatibility with the standard.
584 *
585 * This descriptor has been added as a supplement to the USB2.0 standard, in the ECN located at
586 * <a>http://www.usb.org/developers/docs/InterfaceAssociationDescriptor_ecn.pdf</a>. It allows composite
587 * devices with multiple interfaces related to the same function to have the multiple interfaces bound
588 * together at the point of enumeration, loading one generic driver for all the interfaces in the single
589 * function. Read the ECN for more information.
590 *
591 * \see \ref USB_Descriptor_Interface_Association_t for the version of this type with non-standard LUFA specific
592 * element names.
593 *
594 * \note Regardless of CPU architecture, these values should be stored as little endian.
595 */
596 typedef struct
597 {
598 uint8_t bLength; /**< Size of the descriptor, in bytes. */
599 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
600 * given by the specific class.
601 */
602 uint8_t bFirstInterface; /**< Index of the first associated interface. */
603 uint8_t bInterfaceCount; /**< Total number of associated interfaces. */
604 uint8_t bFunctionClass; /**< Interface class ID. */
605 uint8_t bFunctionSubClass; /**< Interface subclass ID. */
606 uint8_t bFunctionProtocol; /**< Interface protocol ID. */
607 uint8_t iFunction; /**< Index of the string descriptor describing the
608 * interface association.
609 */
610 } ATTR_PACKED USB_StdDescriptor_Interface_Association_t;
611
612 /** \brief Standard USB Endpoint Descriptor (LUFA naming conventions).
613 *
614 * Type define for a standard Endpoint Descriptor. This structure uses LUFA-specific element names
615 * to make each element's purpose clearer.
616 *
617 * \see \ref USB_StdDescriptor_Endpoint_t for the version of this type with standard element names.
618 *
619 * \note Regardless of CPU architecture, these values should be stored as little endian.
620 */
621 typedef struct
622 {
623 USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
624
625 uint8_t EndpointAddress; /**< Logical address of the endpoint within the device for the current
626 * configuration, including direction mask.
627 */
628 uint8_t Attributes; /**< Endpoint attributes, comprised of a mask of the endpoint type (EP_TYPE_*)
629 * and attributes (ENDPOINT_ATTR_*) masks.
630 */
631 uint16_t EndpointSize; /**< Size of the endpoint bank, in bytes. This indicates the maximum packet
632 * size that the endpoint can receive at a time.
633 */
634 uint8_t PollingIntervalMS; /**< Polling interval in milliseconds for the endpoint if it is an INTERRUPT
635 * or ISOCHRONOUS type.
636 */
637 } ATTR_PACKED USB_Descriptor_Endpoint_t;
638
639 /** \brief Standard USB Endpoint Descriptor (USB-IF naming conventions).
640 *
641 * Type define for a standard Endpoint Descriptor. This structure uses the relevant standard's given
642 * element names to ensure compatibility with the standard.
643 *
644 * \see \ref USB_Descriptor_Endpoint_t for the version of this type with non-standard LUFA specific
645 * element names.
646 *
647 * \note Regardless of CPU architecture, these values should be stored as little endian.
648 */
649 typedef struct
650 {
651 uint8_t bLength; /**< Size of the descriptor, in bytes. */
652 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a
653 * value given by the specific class.
654 */
655 uint8_t bEndpointAddress; /**< Logical address of the endpoint within the device for the current
656 * configuration, including direction mask.
657 */
658 uint8_t bmAttributes; /**< Endpoint attributes, comprised of a mask of the endpoint type (EP_TYPE_*)
659 * and attributes (ENDPOINT_ATTR_*) masks.
660 */
661 uint16_t wMaxPacketSize; /**< Size of the endpoint bank, in bytes. This indicates the maximum packet size
662 * that the endpoint can receive at a time.
663 */
664 uint8_t bInterval; /**< Polling interval in milliseconds for the endpoint if it is an INTERRUPT or
665 * ISOCHRONOUS type.
666 */
667 } ATTR_PACKED USB_StdDescriptor_Endpoint_t;
668
669 /** \brief Standard USB String Descriptor (LUFA naming conventions).
670 *
671 * Type define for a standard string descriptor. Unlike other standard descriptors, the length
672 * of the descriptor for placement in the descriptor header must be determined by the \ref USB_STRING_LEN()
673 * macro rather than by the size of the descriptor structure, as the length is not fixed.
674 *
675 * This structure should also be used for string index 0, which contains the supported language IDs for
676 * the device as an array.
677 *
678 * This structure uses LUFA-specific element names to make each element's purpose clearer.
679 *
680 * \see \ref USB_StdDescriptor_String_t for the version of this type with standard element names.
681 *
682 * \note Regardless of CPU architecture, these values should be stored as little endian.
683 */
684 typedef struct
685 {
686 USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */
687
688 #if (((ARCH == ARCH_AVR8) || (ARCH == ARCH_XMEGA)) && !defined(__DOXYGEN__))
689 wchar_t UnicodeString[];
690 #else
691 uint16_t UnicodeString[]; /**< String data, as unicode characters (alternatively,
692 * string language IDs). If normal ASCII characters are
693 * to be used, they must be added as an array of characters
694 * rather than a normal C string so that they are widened to
695 * Unicode size.
696 *
697 * Under GCC, strings prefixed with the "L" character (before
698 * the opening string quotation mark) are considered to be
699 * Unicode strings, and may be used instead of an explicit
700 * array of ASCII characters on little endian devices with
701 * UTF-16-LE \c wchar_t encoding.
702 */
703 #endif
704 } ATTR_PACKED USB_Descriptor_String_t;
705
706 /** \brief Standard USB String Descriptor (USB-IF naming conventions).
707 *
708 * Type define for a standard string descriptor. Unlike other standard descriptors, the length
709 * of the descriptor for placement in the descriptor header must be determined by the \ref USB_STRING_LEN()
710 * macro rather than by the size of the descriptor structure, as the length is not fixed.
711 *
712 * This structure should also be used for string index 0, which contains the supported language IDs for
713 * the device as an array.
714 *
715 * This structure uses the relevant standard's given element names to ensure compatibility with the standard.
716 *
717 * \see \ref USB_Descriptor_String_t for the version of this type with with non-standard LUFA specific
718 * element names.
719 *
720 * \note Regardless of CPU architecture, these values should be stored as little endian.
721 */
722 typedef struct
723 {
724 uint8_t bLength; /**< Size of the descriptor, in bytes. */
725 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t
726 * or a value given by the specific class.
727 */
728 uint16_t bString[]; /**< String data, as unicode characters (alternatively, string language IDs).
729 * If normal ASCII characters are to be used, they must be added as an array
730 * of characters rather than a normal C string so that they are widened to
731 * Unicode size.
732 *
733 * Under GCC, strings prefixed with the "L" character (before the opening string
734 * quotation mark) are considered to be Unicode strings, and may be used instead
735 * of an explicit array of ASCII characters.
736 */
737 } ATTR_PACKED USB_StdDescriptor_String_t;
738
739 /* Private Interface - For use in library only: */
740 #if !defined(__DOXYGEN__)
741 /* Macros: */
742 #define VERSION_TENS(x) (int)((int)(x) / 10)
743 #define VERSION_ONES(x) (int)((int)(x) % 10)
744 #define VERSION_TENTHS(x) (int)((x - (int)x) * 10)
745 #define VERSION_HUNDREDTHS(x) (int)((x * 100) - ((int)(x * 10) * 10))
746 #endif
747
748 /* Disable C linkage for C++ Compilers: */
749 #if defined(__cplusplus)
750 }
751 #endif
752
753 #endif
754
755 /** @} */
756