usb_std.h 29 KB

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