StdDescriptors.h 36 KB

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