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