1
0

usb_std.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. /* This file is the part of the LUS32 project
  2. *
  3. * Copyright ©2016 Dmitry Filimonchuk <dmitrystu[at]gmail[dot]com>
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #ifndef _USB_STD_H_
  16. #define _USB_STD_H_
  17. #if defined(__cplusplus)
  18. extern "C" {
  19. #endif
  20. /**\addtogroup USB_STD USB Standard
  21. * \brief This module contains generic USB device framework definitions
  22. * \details This module based on
  23. * + Chapter 9 of the [Universal Serial Bus Specification Revision 2.0](http://www.usb.org/developers/docs/usb20_docs/usb_20_080416.zip)
  24. * + [LUFA - the Lightweight USB Framework for AVRs.](https://github.com/abcminiuser/lufa)
  25. * @{
  26. *\name Utility functional macros
  27. * @{ */
  28. /** Macro to encode major/minor/version number into BCD code
  29. * \param maj Major version
  30. * \param min Minor version
  31. * \param rev Revision
  32. */
  33. #define VERSION_BCD(maj, min, rev) (((maj & 0xFF) << 8) | ((min & 0x0F) << 4) | (rev & 0x0F))
  34. /** Macro to create \ref usb_string_descriptor from array of characters */
  35. #define USB_STRING_DESC(...) {.bLength = 2 + sizeof((uint16_t[]){__VA_ARGS__}), .bDescriptorType = USB_DTYPE_STRING, .wString = {__VA_ARGS__}}
  36. /**\brief Macro to */
  37. #define USB_CFG_POWER_MA(mA) ((mA) >> 1)
  38. /** @} */
  39. /**\name USB device configuration definitions
  40. * @{ */
  41. #define USB_CFG_ATTR_RESERVED 0x80
  42. #define USB_CFG_ATTR_SELFPOWERED 0x40
  43. /** @} */
  44. /** \anchor USB_ENDPOINT_DEF
  45. * \name USB endpoint attributes definitions
  46. * @{ */
  47. #define USB_EPTYPE_CONTROL 0x00
  48. #define USB_EPTYPE_ISOCHRONUS 0x01
  49. #define USB_EPTYPE_BULK 0x02
  50. #define USB_EPTYPE_INTERRUPT 0x03
  51. #define USB_EPATTR_NO_SYNC 0x00
  52. #define USB_EPATTR_ASYNC 0x04
  53. #define USB_EPATTR_ADAPTIVE 0x08
  54. #define USB_EPATTR_SYNC 0x0C
  55. #define USB_EPUSAGE_DATA 0x00
  56. #define USB_EPUSAGE_FEEDBACK 0x10
  57. #define USB_EPUSAGE_IMP_FEEDBACK 0x20
  58. /** @} */
  59. /**\name Special string descriptor indexes
  60. * @{ */
  61. #define NO_DESCRIPTOR 0x00 /**< \brief Indicates that a given string descriptor doesn't exists in the device */
  62. #define INTSERIALNO_DESCRIPTOR 0xFE /**< \brief Indicates that a given string descriptor is a internal serial number provided by hardware driver */
  63. /** @} */
  64. /**\name USB class definitions
  65. * @{ */
  66. #define USB_CLASS_PER_INTERFACE 0x00 /**< Class defined on interface level */
  67. #define USB_SUBCLASS_NONE 0x00
  68. #define USB_PROTO_NONE 0x00
  69. #define USB_CLASS_AUDIO 0x01 /**< Interface belongs to the Audio device class. */
  70. #define USB_CLASS_PHYSICAL 0x05 /**< Interface belongs to the Physical device class. */
  71. #define USB_CLASS_STILL_IMAGE 0x06 /**< Interface belongs to the Still Imaging device class. */
  72. #define USB_CLASS_PRINTER 0x07 /**< Interface belongs to the Printer device class. */
  73. #define USB_CLASS_MASS_STORAGE 0x08 /**< Interface belongs to the Mass Storage device class. */
  74. #define USB_CLASS_HUB 0x09 /**< Device belongs to the HUB device class. */
  75. #define USB_CLASS_CSCID 0x0B /**< Interface belongs to the Smart Card device class. */
  76. #define USB_CLASS_CONTENT_SEC 0x0D /**< Interface belongs to the Content Security device class. */
  77. #define USB_CLASS_VIDEO 0x0E /**< Interface belongs to the Video device class. */
  78. #define USB_CLASS_HEALTHCARE 0x0F /**< Interface belongs to the Personal Healthcare device class. */
  79. #define USB_CLASS_AV 0x10 /**< Interface belongs to the Audio/Video device class. */
  80. #define USB_CLASS_BILLBOARD 0x11 /**< Device belongs to the Billboard device class. */
  81. #define USB_CLASS_CBRIDGE 0x12 /**< Interface belongs to the USB Type-C Bridge device class. */
  82. #define USB_CLASS_DIAGNOSTIC 0xDC /**< Device/Interface belongs to the Diagnostic device class. */
  83. #define USB_CLASS_WIRELESS 0xE0 /**< Interface belongs to the Wireless controller class. */
  84. #define USB_CLASS_MISC 0xEF /**< Device/Interface belongs to the Miscellanious device class. */
  85. #define USB_CLASS_APP_SPEC 0xFE /**< Interface belongs to the Application Specific class. */
  86. #define USB_CLASS_VENDOR 0xFF /**< Device belongs to a vendor specific class. */
  87. #define USB_SUBCLASS_VENDOR 0xFF /**< Subclass belongs to a vendor specific subclass. */
  88. #define USB_PROTO_VENDOR 0xFF /**< Protocol belongs to a vendor specific protocol. */
  89. /** @} */
  90. /**\name USB Standard descriptor types
  91. * @{ */
  92. #define USB_DTYPE_DEVICE 0x01 /**< Indicates that the descriptor is a \ref usb_device_descriptor*/
  93. #define USB_DTYPE_CONFIGURATION 0x02 /**< Indicates that the descriptor is a \ref usb_config_descriptor */
  94. #define USB_DTYPE_STRING 0x03 /**< Indicates that the descriptor is a \ref usb_string_descriptor */
  95. #define USB_DTYPE_INTERFACE 0x04 /**< Indicates that the descriptor is a \ref usb_interface_descriptor */
  96. #define USB_DTYPE_ENDPOINT 0x05 /**< Indicates that the descriptor is an endpoint descriptor. */
  97. #define USB_DTYPE_QUALIFIER 0x06 /**< Indicates that the descriptor is a \ref usb_qualifier_descriptor */
  98. #define USB_DTYPE_OTHER 0x07 /**< Indicates that the descriptor is of other type. */
  99. #define USB_DTYPE_INTERFACEPOWER 0x08 /**< Indicates that the descriptor is an interface power descriptor. */
  100. #define USB_DTYPE_OTG 0x09 /**< Indicates that the descroptor is an OTG descriptor */
  101. #define USB_DTYPE_DEBUG 0x0A /**< Indicates that the descriptor is a Debug descriptor */
  102. #define USB_DTYPE_INTERFASEASSOC 0x0B /**< Indicates that the descriptor is an interface association descriptor. */
  103. #define USB_DTYPE_CS_INTERFACE 0x24 /**< Indicates that the descriptor is a class specific interface descriptor. */
  104. #define USB_DTYPE_CS_ENDPOINT 0x25 /**< Indicates that the descriptor is a class specific endpoint descriptor. */
  105. /** @} */
  106. /**\name USB Standard requests
  107. * @{ */
  108. #define USB_STD_GET_STATUS 0x00 /**< This request returns status for the specified recipient */
  109. #define USB_STD_CLEAR_FEATURE 0x01 /**< This request is used to clear or disable a specific feature */
  110. #define USB_STD_SET_FEATURE 0x03 /**< This request is used to set or enable a specific feature */
  111. #define USB_STD_SET_ADDRESS 0x05 /**< This request sets the device address for all future device accesses */
  112. #define USB_STD_GET_DESCRIPTOR 0x06 /**< This request returns the specified descriptor if the descriptor exists */
  113. #define USB_STD_SET_DESCRIPTOR 0x07 /**< This request is optional and may be used to update existing descriptors or new descriptors may be added */
  114. #define USB_STD_GET_CONFIG 0x08 /**< This request returns the current device configuration value */
  115. #define USB_STD_SET_CONFIG 0x09 /**< This request sets the device configuration */
  116. #define USB_STD_GET_INTERFACE 0x0A /**< This request returns the selected alternate setting for the specified interface */
  117. #define USB_STD_SET_INTERFACE 0x0B /**< This request allows the host to select an alternate setting for the specified interface */
  118. #define USB_STD_SYNCH_FRAME 0x0C /**< This request is used to set and then report an endpoint's synchronization frame */
  119. /** @} */
  120. /** \brief USB standard LANGID codes */
  121. enum usb_std_langid_codes {
  122. USB_LANGID_AFR = 0x0436, /**< Afrikaans */
  123. USB_LANGID_SQI = 0x041c, /**< Albanian */
  124. USB_LANGID_ARA_SA = 0x0401, /**< Arabic (Saudi Arabia) */
  125. USB_LANGID_ARA_IQ = 0x0801, /**< Arabic (Iraq) */
  126. USB_LANGID_ARA_EG = 0x0c01, /**< Arabic (Egypt) */
  127. USB_LANGID_ARA_LY = 0x1001, /**< Arabic (Libya) */
  128. USB_LANGID_ARA_DZ = 0x1401, /**< Arabic (Algeria) */
  129. USB_LANGID_ARA_MA = 0x1801, /**< Arabic (Morocco) */
  130. USB_LANGID_ARA_TN = 0x1c01, /**< Arabic (Tunisia) */
  131. USB_LANGID_ARA_OM = 0x2001, /**< Arabic (Oman) */
  132. USB_LANGID_ARA_YE = 0x2401, /**< Arabic (Yemen) */
  133. USB_LANGID_ARA_SY = 0x2801, /**< Arabic (Syria) */
  134. USB_LANGID_ARA_JO = 0x2c01, /**< Arabic (Jordan) */
  135. USB_LANGID_ARA_LB = 0x3001, /**< Arabic (Lebanon) */
  136. USB_LANGID_ARA_KW = 0x3401, /**< Arabic (Kuwait) */
  137. USB_LANGID_ARA_AE = 0x3801, /**< Arabic (U.A.E.) */
  138. USB_LANGID_ARA_BH = 0x3c01, /**< Arabic (Bahrain) */
  139. USB_LANGID_ARA_QA = 0x4001, /**< Arabic (Qatar) */
  140. USB_LANGID_HYE = 0x042b, /**< Armenian */
  141. USB_LANGID_ASM = 0x044d, /**< Assamese */
  142. USB_LANGID_AZE_LAT = 0x042c, /**< Azeri (Latin) */
  143. USB_LANGID_AZE_CYR = 0x082c, /**< Azeri (Cyrillic) */
  144. USB_LANGID_EUS = 0x042d, /**< Basque */
  145. USB_LANGID_BEL = 0x0423, /**< Belarussian */
  146. USB_LANGID_BEN = 0x0445, /**< Bengali */
  147. USB_LANGID_BUL = 0x0402, /**< Bulgarian */
  148. USB_LANGID_MYA = 0x0455, /**< Burmese */
  149. USB_LANGID_CAT = 0x0403, /**< Catalan */
  150. USB_LANGID_ZHO_TW = 0x0404, /**< Chinese (Taiwan) */
  151. USB_LANGID_ZHO_CN = 0x0804, /**< Chinese (PRC) */
  152. USB_LANGID_ZHO_HK = 0x0c04, /**< Chinese (Hong Kong SAR, PRC) */
  153. USB_LANGID_ZHO_SG = 0x1004, /**< Chinese (Singapore) */
  154. USB_LANGID_ZHO_MO = 0x1404, /**< Chinese (Macau SAR) */
  155. USB_LANGID_HRV = 0x041a, /**< Croatian */
  156. USB_LANGID_CZE = 0x0405, /**< Czech */
  157. USB_LANGID_DAN = 0x0406, /**< Danish */
  158. USB_LANGID_NLD_NL = 0x0413, /**< Dutch (Netherlands) */
  159. USB_LANGID_NLD_BE = 0x0813, /**< Dutch (Belgium) */
  160. USB_LANGID_ENG_US = 0x0409, /**< English (United States) */
  161. USB_LANGID_ENG_UK = 0x0809, /**< English (United Kingdom) */
  162. USB_LANGID_ENG_AU = 0x0c09, /**< English (Australian) */
  163. USB_LANGID_ENG_CA = 0x1009, /**< English (Canadian) */
  164. USB_LANGID_ENG_NZ = 0x1409, /**< English (New Zealand) */
  165. USB_LANGID_ENG_IE = 0x1809, /**< English (Ireland) */
  166. USB_LANGID_ENG_ZA = 0x1c09, /**< English (South Africa) */
  167. USB_LANGID_ENG_JM = 0x2009, /**< English (Jamaica) */
  168. USB_LANGID_ENG_CAR = 0x2409, /**< English (Caribbean) */
  169. USB_LANGID_ENG_BZ = 0x2809, /**< English (Belize) */
  170. USB_LANGID_ENG_TH = 0x2c09, /**< English (Trinidad) */
  171. USB_LANGID_ENG_ZW = 0x3009, /**< English (Zimbabwe) */
  172. USB_LANGID_ENG_PH = 0x3409, /**< English (Philippines) */
  173. USB_LANGID_EST = 0x0425, /**< Estonian */
  174. USB_LANGID_FAO = 0x0438, /**< Faeroese */
  175. USB_LANGID_FAS = 0x0429, /**< Farsi */
  176. USB_LANGID_FIN = 0x040b, /**< Finnish */
  177. USB_LANGID_FRA = 0x040c, /**< French (Standard) */
  178. USB_LANGID_FRA_BE = 0x080c, /**< French (Belgian) */
  179. USB_LANGID_FRA_CA = 0x0c0c, /**< French (Canadian) */
  180. USB_LANGID_FRA_SZ = 0x100c, /**< French (Switzerland) */
  181. USB_LANGID_FRA_LU = 0x140c, /**< French (Luxembourg) */
  182. USB_LANGID_FRA_MC = 0x180c, /**< French (Monaco) */
  183. USB_LANGID_KAT = 0x0437, /**< Georgian */
  184. USB_LANGID_DEU = 0x0407, /**< German (Standard) */
  185. USB_LANGID_DEU_SZ = 0x0807, /**< German (Switzerland) */
  186. USB_LANGID_DEU_AT = 0x0c07, /**< German (Austria) */
  187. USB_LANGID_DEU_LU = 0x1007, /**< German (Luxembourg) */
  188. USB_LANGID_DEU_LI = 0x1407, /**< German (Liechtenstein) */
  189. USB_LANGID_ELL = 0x0408, /**< Greek */
  190. USB_LANGID_GUJ = 0x0447, /**< Gujarati */
  191. USB_LANGID_HEB = 0x040d, /**< Hebrew */
  192. USB_LANGID_HIN = 0x0439, /**< Hindi */
  193. USB_LANGID_HUN = 0x040e, /**< Hungarian */
  194. USB_LANGID_ISL = 0x040f, /**< Icelandic */
  195. USB_LANGID_IND = 0x0421, /**< Indonesian */
  196. USB_LANGID_ITA = 0x0410, /**< Italian (Standard) */
  197. USB_LANGID_ITA_SZ = 0x0810, /**< Italian (Switzerland) */
  198. USB_LANGID_JPN = 0x0411, /**< Japanese */
  199. USB_LANGID_KAN = 0x044b, /**< Kannada */
  200. USB_LANGID_KAS = 0x0860, /**< Kashmiri (India) */
  201. USB_LANGID_KAZ = 0x043f, /**< Kazakh */
  202. USB_LANGID_KOK = 0x0457, /**< Konkani */
  203. USB_LANGID_KOR = 0x0412, /**< Korean */
  204. USB_LANGID_KOR_JOH = 0x0812, /**< Korean (Johab) */
  205. USB_LANGID_LAV = 0x0426, /**< Latvian */
  206. USB_LANGID_LIT = 0x0427, /**< Lithuanian */
  207. USB_LANGID_LIT_CLS = 0x0827, /**< Lithuanian (Classic) */
  208. USB_LANGID_MKD = 0x042f, /**< Macedonian */
  209. USB_LANGID_MSA = 0x043e, /**< Malay (Malaysian) */
  210. USB_LANGID_MSA_BN = 0x083e, /**< Malay (Brunei Darussalam) */
  211. USB_LANGID_MAL = 0x044c, /**< Malayalam */
  212. USB_LANGID_MNI = 0x0458, /**< Manipuri */
  213. USB_LANGID_MAR = 0x044e, /**< Marathi */
  214. USB_LANGID_NEP = 0x0861, /**< Nepali (India) */
  215. USB_LANGID_NOB = 0x0414, /**< Norwegian (Bokmal) */
  216. USB_LANGID_NNO = 0x0814, /**< Norwegian (Nynorsk) */
  217. USB_LANGID_ORI = 0x0448, /**< Oriya */
  218. USB_LANGID_POL = 0x0415, /**< Polish */
  219. USB_LANGID_POR_BR = 0x0416, /**< Portuguese (Brazil) */
  220. USB_LANGID_POR = 0x0816, /**< Portuguese (Standard) */
  221. USB_LANGID_PAN = 0x0446, /**< Punjabi */
  222. USB_LANGID_RON = 0x0418, /**< Romanian */
  223. USB_LANGID_RUS = 0x0419, /**< Russian */
  224. USB_LANGID_SAN = 0x044f, /**< Sanskrit */
  225. USB_LANGID_SRB_CYR = 0x0c1a, /**< Serbian (Cyrillic) */
  226. USB_LANGID_SRB_LAT = 0x081a, /**< Serbian (Latin) */
  227. USB_LANGID_SND = 0x0459, /**< Sindhi */
  228. USB_LANGID_SLK = 0x041b, /**< Slovak */
  229. USB_LANGID_SLV = 0x0424, /**< Slovenian */
  230. USB_LANGID_SPA = 0x040a, /**< Spanish (Traditional Sort) */
  231. USB_LANGID_SPA_MX = 0x080a, /**< Spanish (Mexican) */
  232. USB_LANGID_SPA_MDN = 0x0c0a, /**< Spanish (Modern Sort) */
  233. USB_LANGID_SPA_GT = 0x100a, /**< Spanish (Guatemala) */
  234. USB_LANGID_SPA_CR = 0x140a, /**< Spanish (Costa Rica) */
  235. USB_LANGID_SPA_PA = 0x180a, /**< Spanish (Panama) */
  236. USB_LANGID_SPA_DO = 0x1c0a, /**< Spanish (Dominican Republic) */
  237. USB_LANGID_SPA_VE = 0x200a, /**< Spanish (Venezuela) */
  238. USB_LANGID_SPA_CO = 0x240a, /**< Spanish (Colombia) */
  239. USB_LANGID_SPA_PE = 0x280a, /**< Spanish (Peru) */
  240. USB_LANGID_SPA_AR = 0x2c0a, /**< Spanish (Argentina) */
  241. USB_LANGID_SPA_EC = 0x300a, /**< Spanish (Ecuador) */
  242. USB_LANGID_SPA_CL = 0x340a, /**< Spanish (Chile) */
  243. USB_LANGID_SPA_UY = 0x380a, /**< Spanish (Uruguay) */
  244. USB_LANGID_SPA_PY = 0x3c0a, /**< Spanish (Paraguay) */
  245. USB_LANGID_SPA_BO = 0x400a, /**< Spanish (Bolivia) */
  246. USB_LANGID_SPA_SV = 0x440a, /**< Spanish (El Salvador) */
  247. USB_LANGID_SPA_HN = 0x480a, /**< Spanish (Honduras) */
  248. USB_LANGID_SPA_NI = 0x4c0a, /**< Spanish (Nicaragua) */
  249. USB_LANGID_SPA_PR = 0x500a, /**< Spanish (Puerto Rico) */
  250. USB_LANGID_NSO = 0x0430, /**< Sutu, Sotho. */
  251. USB_LANGID_SWA = 0x0441, /**< Swahili (Kenya) */
  252. USB_LANGID_SWE = 0x041d, /**< Swedish */
  253. USB_LANGID_SWE_FI = 0x081d, /**< Swedish (Finland) */
  254. USB_LANGID_TAM = 0x0449, /**< Tamil */
  255. USB_LANGID_TAT = 0x0444, /**< Tatar (Tatarstan) */
  256. USB_LANGID_TEL = 0x044a, /**< Telugu */
  257. USB_LANGID_THA = 0x041e, /**< Thai */
  258. USB_LANGID_TUR = 0x041f, /**< Turkish */
  259. USB_LANGIG_UKR = 0x0422, /**< Ukrainian */
  260. USB_LANGID_URD_PK = 0x0420, /**< Urdu (Pakistan) */
  261. USB_LANGID_URD_IN = 0x0820, /**< Urdu (India) */
  262. USB_LANGID_UZB_LAT = 0x0443, /**< Uzbek (Latin) */
  263. USB_LANGID_UZB_CYR = 0x0843, /**< Uzbek (Cyrillic) */
  264. USB_LANGID_VIE = 0x042a, /**< Vietnamese. */
  265. };
  266. /** \brief common USB descriptor header */
  267. struct usb_header_descriptor {
  268. uint8_t bLength; /**< Size of the descriptor, in bytes. */
  269. uint8_t bDescriptorType; /**< Type of the descriptor. */
  270. } __attribute__((packed));
  271. /** \brief Represents a USB device descriptor
  272. * \details A device descriptor describes general information about a USB device. It includes information that applies
  273. * globally to the device and all of the device’s configurations. A USB device has only one device descriptor.
  274. * A high-speed capable device that has different device information for full-speed and high-speed must also
  275. * have a \ref usb_qualifier_descriptor
  276. */
  277. struct usb_device_descriptor {
  278. uint8_t bLength; /**< Size of the descriptor, in bytes. */
  279. uint8_t bDescriptorType; /**< Type of the descriptor, must be a \ref USB_DTYPE_DEVICE. */
  280. uint16_t bcdUSB; /**< BCD of the supported USB specification. \ref VERSION_BCD utility macro. */
  281. uint8_t bDeviceClass; /**< USB device class. */
  282. uint8_t bDeviceSubClass; /**< USB device subclass. */
  283. uint8_t bDeviceProtocol; /**< USB device protocol. */
  284. uint8_t bMaxPacketSize0; /**< Size of the control (address 0) endpoint's bank in bytes. */
  285. uint16_t idVendor; /**< Vendor ID for the USB product. */
  286. uint16_t idProduct; /**< Unique product ID for the USB product. */
  287. uint16_t bcdDevice; /**< Product release (version) number. \ref VERSION_BCD utility macro. */
  288. uint8_t iManufacturer; /**< String index for the manufacturer's name. */
  289. uint8_t iProduct; /**< String index for the product name/details. */
  290. uint8_t iSerialNumber; /**< String index for the product serial number, \ref INTSERIALNO_DESCRIPTOR can be used*/
  291. uint8_t bNumConfigurations; /**< Total number of configurations supported by the device. */
  292. } __attribute__((packed));
  293. /** \brief USB device qualifier descriptor
  294. * \details The device_qualifier descriptor describes information about a high-speed capable device that would
  295. * change if the device were operating at the other speed. For example, if the device is currently operating
  296. * at full-speed, the device qualifier returns information about how it would operate at high-speed and vice-versa.
  297. */
  298. struct usb_qualifier_descriptor {
  299. uint8_t bLength; /**< Size of the descriptor, in bytes. */
  300. uint8_t bDescriptorType; /**< Type of the descriptor, must be a \ref USB_DTYPE_QUALIFIER. */
  301. uint16_t bcdUSB; /**< BCD of the supported USB specification. \ref VERSION_BCD utility macro. */
  302. uint8_t bDeviceClass; /**< USB device class. */
  303. uint8_t bDeviceSubClass; /**< USB device subclass. */
  304. uint8_t bDeviceProtocol; /**< USB device protocol. */
  305. uint8_t bMaxPacketSize0; /**< Size of the control (address 0) endpoint's bank in bytes. */
  306. uint8_t bNumConfigurations; /**< Total number of configurations supported by the device. */
  307. uint8_t bReserved; /**< Reserved for future use, must be 0. */
  308. } __attribute__((packed));
  309. /** \brief USB device configuration descriptor
  310. * \details The configuration descriptor describes information about a specific device configuration. The descriptor
  311. * contains a bConfigurationValue field with a value that, when used as a parameter to the SetConfiguration()
  312. * request, causes the device to assume the described configuration.
  313. */
  314. struct usb_config_descriptor {
  315. uint8_t bLength; /**< Size of the descriptor, in bytes. */
  316. uint8_t bDescriptorType; /**< Type of the descriptor, must be a \ref USB_DTYPE_CONFIGURATION. */
  317. uint16_t wTotalLength; /**< Size of the configuration descriptor header, and all sub descriptors inside the configuration. */
  318. uint8_t bNumInterfaces; /**< Total number of interfaces in the configuration. */
  319. uint8_t bConfigurationValue; /**< Configuration index of the current configuration. */
  320. uint8_t iConfiguration; /**< Index of a string descriptor describing the configuration. */
  321. uint8_t bmAttributes; /**< Configuration attributes, comprised of a mask of \c USB_CONFIG_ATTR_* masks. On all devices, this should include USB_CONFIG_ATTR_RESERVED at a minimum. */
  322. uint8_t bMaxPower; /**< Maximum power consumption of the device while in the current configuration, calculated by the \ref USB_CFG_POWER_MA() macro. */
  323. } __attribute__((packed));
  324. /** \brief USB interface descriptor
  325. * \details The interface descriptor describes a specific interface within a configuration. A configuration provides one or more interfaces,
  326. * each with zero or more endpoint descriptors describing a unique set of endpoints within the configuration.
  327. */
  328. struct usb_interface_descriptor {
  329. uint8_t bLength; /**< Size of the descriptor, in bytes. */
  330. uint8_t bDescriptorType; /**< Type of the descriptor, must be \ref USB_DTYPE_INTERFACE */
  331. uint8_t bInterfaceNumber; /**< Index of the interface in the current configuration. */
  332. uint8_t bAlternateSetting; /**< Alternate setting for the interface number. */
  333. uint8_t bNumEndpoints; /**< Total number of endpoints in the interface. */
  334. uint8_t bInterfaceClass; /**< Interface class ID. */
  335. uint8_t bInterfaceSubClass; /**< Interface subclass ID. */
  336. uint8_t bInterfaceProtocol; /**< Interface protocol ID. */
  337. uint8_t iInterface; /**< Index of the string descriptor describing the interface. */
  338. } __attribute__((packed));
  339. struct usb_iad_descriptor {
  340. uint8_t bLength; /**< Size of the descriptor, in bytes. */
  341. uint8_t bDescriptorType; /**< Type of the descriptor, either a value in */
  342. uint8_t bFirstInterface; /**< Index of the first associated interface. */
  343. uint8_t bInterfaceCount; /**< Total number of associated interfaces. */
  344. uint8_t bFunctionClass; /**< Interface class ID. */
  345. uint8_t bFunctionSubClass; /**< Interface subclass ID. */
  346. uint8_t bFunctionProtocol; /**< Interface protocol ID. */
  347. uint8_t iFunction; /**< Index of the string descriptor describing the interface association. */
  348. } __attribute__((packed));
  349. /** \brief USB endpoint descriptor
  350. * \details This descriptor contains the information required by the host to determine the bandwidth requirements of each endpoint.
  351. */
  352. struct usb_endpoint_descriptor {
  353. uint8_t bLength; /**< Size of the descriptor, in bytes. */
  354. uint8_t bDescriptorType; /**< Type of the descriptor, must be \ref USB_DTYPE_ENDPOINT */
  355. uint8_t bEndpointAddress; /**< Logical address of the endpoint within the device for the current configuration, including direction mask. */
  356. uint8_t bmAttributes; /**< Endpoint attributes, \ref USB_ENDPOINT_DEF. */
  357. uint16_t wMaxPacketSize; /**< Size of the endpoint bank, in bytes. This indicates the maximum packet size that the endpoint can receive at a time. */
  358. uint8_t bInterval; /**< Polling interval in milliseconds for the endpoint if it is an INTERRUPT or ISOCHRONOUS type. */
  359. } __attribute__((packed));
  360. /** \brief USB string descriptor
  361. * \details String descriptors are referenced by their one-based index number. A string descriptor contains one or more not NULL-terminated Unicode strings.
  362. * \note String descriptors are optional. if a device does not support string descriptors, all references to string descriptors within device, configuration,
  363. * and interface descriptors must be reset to zero.
  364. */
  365. struct usb_string_descriptor {
  366. uint8_t bLength; /**< Size of the descriptor, in bytes. */
  367. uint8_t bDescriptorType; /**< Type of the descriptor, must be \ref USB_DTYPE_STRING */
  368. uint16_t wString[]; /**< String data, as unicode characters (alternatively, array of \ref USB_STD_LANGIDS ). */
  369. } __attribute__((packed));
  370. struct usb_debug_descriptor {
  371. uint8_t bLength;
  372. uint8_t bDescriptorType;
  373. uint8_t bDebugInEndpoint; /**< Endpoint number of the Debug Data IN endpoint. This is a Bulk-type endpoint with a maximum packet size of 8 bytes. */
  374. uint8_t bDebugOutEndpoint; /**< Endpoint number of the Debug Data OUTendpoint. This is a Bulk-type endpoint with a maximum packet size of 8 bytes. */
  375. } __attribute__((packed));
  376. /** @} */
  377. #if defined (__cplusplus)
  378. }
  379. #endif
  380. #endif //_USB_STD_H_