PageRenderTime 58ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/arduino-board-definitions/Telepoll-1.0.0/cores/arduino/TinyUSB/Adafruit_TinyUSB_ArduinoCore/tinyusb/src/common/tusb_types.h

https://codeberg.org/ccoenen/Telepoll
C Header | 481 lines | 346 code | 72 blank | 63 comment | 1 complexity | d9cad8a91e9679b8b6a8e6fe6f8e2c73 MD5 | raw file
Possible License(s): JSON
  1. /*
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2019 Ha Thach (tinyusb.org)
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. *
  24. * This file is part of the TinyUSB stack.
  25. */
  26. /** \ingroup group_usb_definitions
  27. * \defgroup USBDef_Type USB Types
  28. * @{ */
  29. #ifndef _TUSB_TYPES_H_
  30. #define _TUSB_TYPES_H_
  31. #include <stdbool.h>
  32. #include <stdint.h>
  33. #include "tusb_compiler.h"
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /*------------------------------------------------------------------*/
  38. /* CONSTANTS
  39. *------------------------------------------------------------------*/
  40. /// defined base on EHCI specs value for Endpoint Speed
  41. typedef enum
  42. {
  43. TUSB_SPEED_FULL = 0,
  44. TUSB_SPEED_LOW ,
  45. TUSB_SPEED_HIGH
  46. }tusb_speed_t;
  47. /// defined base on USB Specs Endpoint's bmAttributes
  48. typedef enum
  49. {
  50. TUSB_XFER_CONTROL = 0 ,
  51. TUSB_XFER_ISOCHRONOUS ,
  52. TUSB_XFER_BULK ,
  53. TUSB_XFER_INTERRUPT
  54. }tusb_xfer_type_t;
  55. typedef enum
  56. {
  57. TUSB_DIR_OUT = 0,
  58. TUSB_DIR_IN = 1,
  59. TUSB_DIR_IN_MASK = 0x80
  60. }tusb_dir_t;
  61. /// USB Descriptor Types
  62. typedef enum
  63. {
  64. TUSB_DESC_DEVICE = 0x01,
  65. TUSB_DESC_CONFIGURATION = 0x02,
  66. TUSB_DESC_STRING = 0x03,
  67. TUSB_DESC_INTERFACE = 0x04,
  68. TUSB_DESC_ENDPOINT = 0x05,
  69. TUSB_DESC_DEVICE_QUALIFIER = 0x06,
  70. TUSB_DESC_OTHER_SPEED_CONFIG = 0x07,
  71. TUSB_DESC_INTERFACE_POWER = 0x08,
  72. TUSB_DESC_OTG = 0x09,
  73. TUSB_DESC_DEBUG = 0x0A,
  74. TUSB_DESC_INTERFACE_ASSOCIATION = 0x0B,
  75. TUSB_DESC_BOS = 0x0F,
  76. TUSB_DESC_DEVICE_CAPABILITY = 0x10,
  77. TUSB_DESC_FUNCTIONAL = 0x21,
  78. // Class Specific Descriptor
  79. TUSB_DESC_CS_DEVICE = 0x21,
  80. TUSB_DESC_CS_CONFIGURATION = 0x22,
  81. TUSB_DESC_CS_STRING = 0x23,
  82. TUSB_DESC_CS_INTERFACE = 0x24,
  83. TUSB_DESC_CS_ENDPOINT = 0x25,
  84. TUSB_DESC_SUPERSPEED_ENDPOINT_COMPANION = 0x30,
  85. TUSB_DESC_SUPERSPEED_ISO_ENDPOINT_COMPANION = 0x31
  86. }tusb_desc_type_t;
  87. typedef enum
  88. {
  89. TUSB_REQ_GET_STATUS = 0 ,
  90. TUSB_REQ_CLEAR_FEATURE = 1 ,
  91. TUSB_REQ_RESERVED = 2 ,
  92. TUSB_REQ_SET_FEATURE = 3 ,
  93. TUSB_REQ_RESERVED2 = 4 ,
  94. TUSB_REQ_SET_ADDRESS = 5 ,
  95. TUSB_REQ_GET_DESCRIPTOR = 6 ,
  96. TUSB_REQ_SET_DESCRIPTOR = 7 ,
  97. TUSB_REQ_GET_CONFIGURATION = 8 ,
  98. TUSB_REQ_SET_CONFIGURATION = 9 ,
  99. TUSB_REQ_GET_INTERFACE = 10 ,
  100. TUSB_REQ_SET_INTERFACE = 11 ,
  101. TUSB_REQ_SYNCH_FRAME = 12
  102. }tusb_request_code_t;
  103. typedef enum
  104. {
  105. TUSB_REQ_FEATURE_EDPT_HALT = 0,
  106. TUSB_REQ_FEATURE_REMOTE_WAKEUP = 1,
  107. TUSB_REQ_FEATURE_TEST_MODE = 2
  108. }tusb_request_feature_selector_t;
  109. typedef enum
  110. {
  111. TUSB_REQ_TYPE_STANDARD = 0,
  112. TUSB_REQ_TYPE_CLASS,
  113. TUSB_REQ_TYPE_VENDOR,
  114. TUSB_REQ_TYPE_INVALID
  115. } tusb_request_type_t;
  116. typedef enum
  117. {
  118. TUSB_REQ_RCPT_DEVICE =0,
  119. TUSB_REQ_RCPT_INTERFACE,
  120. TUSB_REQ_RCPT_ENDPOINT,
  121. TUSB_REQ_RCPT_OTHER
  122. } tusb_request_recipient_t;
  123. typedef enum
  124. {
  125. TUSB_CLASS_UNSPECIFIED = 0 ,
  126. TUSB_CLASS_AUDIO = 1 ,
  127. TUSB_CLASS_CDC = 2 ,
  128. TUSB_CLASS_HID = 3 ,
  129. TUSB_CLASS_RESERVED_4 = 4 ,
  130. TUSB_CLASS_PHYSICAL = 5 ,
  131. TUSB_CLASS_IMAGE = 6 ,
  132. TUSB_CLASS_PRINTER = 7 ,
  133. TUSB_CLASS_MSC = 8 ,
  134. TUSB_CLASS_HUB = 9 ,
  135. TUSB_CLASS_CDC_DATA = 10 ,
  136. TUSB_CLASS_SMART_CARD = 11 ,
  137. TUSB_CLASS_RESERVED_12 = 12 ,
  138. TUSB_CLASS_CONTENT_SECURITY = 13 ,
  139. TUSB_CLASS_VIDEO = 14 ,
  140. TUSB_CLASS_PERSONAL_HEALTHCARE = 15 ,
  141. TUSB_CLASS_AUDIO_VIDEO = 16 ,
  142. TUSB_CLASS_DIAGNOSTIC = 0xDC ,
  143. TUSB_CLASS_WIRELESS_CONTROLLER = 0xE0 ,
  144. TUSB_CLASS_MISC = 0xEF ,
  145. TUSB_CLASS_APPLICATION_SPECIFIC = 0xFE ,
  146. TUSB_CLASS_VENDOR_SPECIFIC = 0xFF
  147. }tusb_class_code_t;
  148. typedef enum
  149. {
  150. MISC_SUBCLASS_COMMON = 2
  151. }misc_subclass_type_t;
  152. typedef enum
  153. {
  154. MISC_PROTOCOL_IAD = 1
  155. }misc_protocol_type_t;
  156. typedef enum
  157. {
  158. DEVICE_CAPABILITY_WIRELESS_USB = 0x01,
  159. DEVICE_CAPABILITY_USB20_EXTENSION = 0x02,
  160. DEVICE_CAPABILITY_SUPERSPEED_USB = 0x03,
  161. DEVICE_CAPABILITY_CONTAINER_id = 0x04,
  162. DEVICE_CAPABILITY_PLATFORM = 0x05,
  163. DEVICE_CAPABILITY_POWER_DELIVERY = 0x06,
  164. DEVICE_CAPABILITY_BATTERY_INFO = 0x07,
  165. DEVICE_CAPABILITY_PD_CONSUMER_PORT = 0x08,
  166. DEVICE_CAPABILITY_PD_PROVIDER_PORT = 0x09,
  167. DEVICE_CAPABILITY_SUPERSPEED_PLUS = 0x0A,
  168. DEVICE_CAPABILITY_PRECESION_TIME_MEASUREMENT = 0x0B,
  169. DEVICE_CAPABILITY_WIRELESS_USB_EXT = 0x0C,
  170. DEVICE_CAPABILITY_BILLBOARD = 0x0D,
  171. DEVICE_CAPABILITY_AUTHENTICATION = 0x0E,
  172. DEVICE_CAPABILITY_BILLBOARD_EX = 0x0F,
  173. DEVICE_CAPABILITY_CONFIGURATION_SUMMARY = 0x10
  174. }device_capability_type_t;
  175. enum {
  176. TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP = TU_BIT(5),
  177. TUSB_DESC_CONFIG_ATT_SELF_POWERED = TU_BIT(6),
  178. };
  179. #define TUSB_DESC_CONFIG_POWER_MA(x) ((x)/2)
  180. /// Device State TODO remove
  181. typedef enum
  182. {
  183. TUSB_DEVICE_STATE_UNPLUG = 0 ,
  184. TUSB_DEVICE_STATE_CONFIGURED ,
  185. TUSB_DEVICE_STATE_SUSPENDED ,
  186. }tusb_device_state_t;
  187. typedef enum
  188. {
  189. XFER_RESULT_SUCCESS,
  190. XFER_RESULT_FAILED,
  191. XFER_RESULT_STALLED,
  192. }xfer_result_t;
  193. enum // TODO remove
  194. {
  195. DESC_OFFSET_LEN = 0,
  196. DESC_OFFSET_TYPE = 1
  197. };
  198. enum
  199. {
  200. INTERFACE_INVALID_NUMBER = 0xff
  201. };
  202. typedef enum
  203. {
  204. MS_OS_20_SET_HEADER_DESCRIPTOR = 0x00,
  205. MS_OS_20_SUBSET_HEADER_CONFIGURATION = 0x01,
  206. MS_OS_20_SUBSET_HEADER_FUNCTION = 0x02,
  207. MS_OS_20_FEATURE_COMPATBLE_ID = 0x03,
  208. MS_OS_20_FEATURE_REG_PROPERTY = 0x04,
  209. MS_OS_20_FEATURE_MIN_RESUME_TIME = 0x05,
  210. MS_OS_20_FEATURE_MODEL_ID = 0x06,
  211. MS_OS_20_FEATURE_CCGP_DEVICE = 0x07,
  212. MS_OS_20_FEATURE_VENDOR_REVISION = 0x08
  213. } microsoft_os_20_type_t;
  214. //--------------------------------------------------------------------+
  215. // USB Descriptors
  216. //--------------------------------------------------------------------+
  217. /// USB Device Descriptor
  218. typedef struct TU_ATTR_PACKED
  219. {
  220. uint8_t bLength ; ///< Size of this descriptor in bytes.
  221. uint8_t bDescriptorType ; ///< DEVICE Descriptor Type.
  222. uint16_t bcdUSB ; ///< BUSB Specification Release Number in Binary-Coded Decimal (i.e., 2.10 is 210H). This field identifies the release of the USB Specification with which the device and its descriptors are compliant.
  223. uint8_t bDeviceClass ; ///< Class code (assigned by the USB-IF). \li If this field is reset to zero, each interface within a configuration specifies its own class information and the various interfaces operate independently. \li If this field is set to a value between 1 and FEH, the device supports different class specifications on different interfaces and the interfaces may not operate independently. This value identifies the class definition used for the aggregate interfaces. \li If this field is set to FFH, the device class is vendor-specific.
  224. uint8_t bDeviceSubClass ; ///< Subclass code (assigned by the USB-IF). These codes are qualified by the value of the bDeviceClass field. \li If the bDeviceClass field is reset to zero, this field must also be reset to zero. \li If the bDeviceClass field is not set to FFH, all values are reserved for assignment by the USB-IF.
  225. uint8_t bDeviceProtocol ; ///< Protocol code (assigned by the USB-IF). These codes are qualified by the value of the bDeviceClass and the bDeviceSubClass fields. If a device supports class-specific protocols on a device basis as opposed to an interface basis, this code identifies the protocols that the device uses as defined by the specification of the device class. \li If this field is reset to zero, the device does not use class-specific protocols on a device basis. However, it may use classspecific protocols on an interface basis. \li If this field is set to FFH, the device uses a vendor-specific protocol on a device basis.
  226. uint8_t bMaxPacketSize0 ; ///< Maximum packet size for endpoint zero (only 8, 16, 32, or 64 are valid). For HS devices is fixed to 64.
  227. uint16_t idVendor ; ///< Vendor ID (assigned by the USB-IF).
  228. uint16_t idProduct ; ///< Product ID (assigned by the manufacturer).
  229. uint16_t bcdDevice ; ///< Device release number in binary-coded decimal.
  230. uint8_t iManufacturer ; ///< Index of string descriptor describing manufacturer.
  231. uint8_t iProduct ; ///< Index of string descriptor describing product.
  232. uint8_t iSerialNumber ; ///< Index of string descriptor describing the device's serial number.
  233. uint8_t bNumConfigurations ; ///< Number of possible configurations.
  234. } tusb_desc_device_t;
  235. // USB Binary Device Object Store (BOS) Descriptor
  236. typedef struct TU_ATTR_PACKED
  237. {
  238. uint8_t bLength ; ///< Size of this descriptor in bytes
  239. uint8_t bDescriptorType ; ///< CONFIGURATION Descriptor Type
  240. uint16_t wTotalLength ; ///< Total length of data returned for this descriptor
  241. uint8_t bNumDeviceCaps ; ///< Number of device capability descriptors in the BOS
  242. } tusb_desc_bos_t;
  243. /// USB Configuration Descriptor
  244. typedef struct TU_ATTR_PACKED
  245. {
  246. uint8_t bLength ; ///< Size of this descriptor in bytes
  247. uint8_t bDescriptorType ; ///< CONFIGURATION Descriptor Type
  248. uint16_t wTotalLength ; ///< Total length of data returned for this configuration. Includes the combined length of all descriptors (configuration, interface, endpoint, and class- or vendor-specific) returned for this configuration.
  249. uint8_t bNumInterfaces ; ///< Number of interfaces supported by this configuration
  250. uint8_t bConfigurationValue ; ///< Value to use as an argument to the SetConfiguration() request to select this configuration.
  251. uint8_t iConfiguration ; ///< Index of string descriptor describing this configuration
  252. uint8_t bmAttributes ; ///< Configuration characteristics \n D7: Reserved (set to one)\n D6: Self-powered \n D5: Remote Wakeup \n D4...0: Reserved (reset to zero) \n D7 is reserved and must be set to one for historical reasons. \n A device configuration that uses power from the bus and a local source reports a non-zero value in bMaxPower to indicate the amount of bus power required and sets D6. The actual power source at runtime may be determined using the GetStatus(DEVICE) request (see USB 2.0 spec Section 9.4.5). \n If a device configuration supports remote wakeup, D5 is set to one.
  253. uint8_t bMaxPower ; ///< Maximum power consumption of the USB device from the bus in this specific configuration when the device is fully operational. Expressed in 2 mA units (i.e., 50 = 100 mA).
  254. } tusb_desc_configuration_t;
  255. /// USB Interface Descriptor
  256. typedef struct TU_ATTR_PACKED
  257. {
  258. uint8_t bLength ; ///< Size of this descriptor in bytes
  259. uint8_t bDescriptorType ; ///< INTERFACE Descriptor Type
  260. uint8_t bInterfaceNumber ; ///< Number of this interface. Zero-based value identifying the index in the array of concurrent interfaces supported by this configuration.
  261. uint8_t bAlternateSetting ; ///< Value used to select this alternate setting for the interface identified in the prior field
  262. uint8_t bNumEndpoints ; ///< Number of endpoints used by this interface (excluding endpoint zero). If this value is zero, this interface only uses the Default Control Pipe.
  263. uint8_t bInterfaceClass ; ///< Class code (assigned by the USB-IF). \li A value of zero is reserved for future standardization. \li If this field is set to FFH, the interface class is vendor-specific. \li All other values are reserved for assignment by the USB-IF.
  264. uint8_t bInterfaceSubClass ; ///< Subclass code (assigned by the USB-IF). \n These codes are qualified by the value of the bInterfaceClass field. \li If the bInterfaceClass field is reset to zero, this field must also be reset to zero. \li If the bInterfaceClass field is not set to FFH, all values are reserved for assignment by the USB-IF.
  265. uint8_t bInterfaceProtocol ; ///< Protocol code (assigned by the USB). \n These codes are qualified by the value of the bInterfaceClass and the bInterfaceSubClass fields. If an interface supports class-specific requests, this code identifies the protocols that the device uses as defined by the specification of the device class. \li If this field is reset to zero, the device does not use a class-specific protocol on this interface. \li If this field is set to FFH, the device uses a vendor-specific protocol for this interface.
  266. uint8_t iInterface ; ///< Index of string descriptor describing this interface
  267. } tusb_desc_interface_t;
  268. /// USB Endpoint Descriptor
  269. typedef struct TU_ATTR_PACKED
  270. {
  271. uint8_t bLength ; ///< Size of this descriptor in bytes
  272. uint8_t bDescriptorType ; ///< ENDPOINT Descriptor Type
  273. uint8_t bEndpointAddress ; ///< The address of the endpoint on the USB device described by this descriptor. The address is encoded as follows: \n Bit 3...0: The endpoint number \n Bit 6...4: Reserved, reset to zero \n Bit 7: Direction, ignored for control endpoints 0 = OUT endpoint 1 = IN endpoint.
  274. struct TU_ATTR_PACKED {
  275. uint8_t xfer : 2;
  276. uint8_t sync : 2;
  277. uint8_t usage : 2;
  278. uint8_t : 2;
  279. } bmAttributes ; ///< This field describes the endpoint's attributes when it is configured using the bConfigurationValue. \n Bits 1..0: Transfer Type \n- 00 = Control \n- 01 = Isochronous \n- 10 = Bulk \n- 11 = Interrupt \n If not an isochronous endpoint, bits 5..2 are reserved and must be set to zero. If isochronous, they are defined as follows: \n Bits 3..2: Synchronization Type \n- 00 = No Synchronization \n- 01 = Asynchronous \n- 10 = Adaptive \n- 11 = Synchronous \n Bits 5..4: Usage Type \n- 00 = Data endpoint \n- 01 = Feedback endpoint \n- 10 = Implicit feedback Data endpoint \n- 11 = Reserved \n Refer to Chapter 5 of USB 2.0 specification for more information. \n All other bits are reserved and must be reset to zero. Reserved bits must be ignored by the host.
  280. struct TU_ATTR_PACKED {
  281. uint16_t size : 11; ///< Maximum packet size this endpoint is capable of sending or receiving when this configuration is selected. \n For isochronous endpoints, this value is used to reserve the bus time in the schedule, required for the per-(micro)frame data payloads. The pipe may, on an ongoing basis, actually use less bandwidth than that reserved. The device reports, if necessary, the actual bandwidth used via its normal, non-USB defined mechanisms. \n For all endpoints, bits 10..0 specify the maximum packet size (in bytes). \n For high-speed isochronous and interrupt endpoints: \n Bits 12..11 specify the number of additional transaction opportunities per microframe: \n- 00 = None (1 transaction per microframe) \n- 01 = 1 additional (2 per microframe) \n- 10 = 2 additional (3 per microframe) \n- 11 = Reserved \n Bits 15..13 are reserved and must be set to zero.
  282. uint16_t hs_period_mult : 2;
  283. uint16_t : 0;
  284. }wMaxPacketSize;
  285. uint8_t bInterval ; ///< Interval for polling endpoint for data transfers. Expressed in frames or microframes depending on the device operating speed (i.e., either 1 millisecond or 125 us units). \n- For full-/high-speed isochronous endpoints, this value must be in the range from 1 to 16. The bInterval value is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$). \n- For full-/low-speed interrupt endpoints, the value of this field may be from 1 to 255. \n- For high-speed interrupt endpoints, the bInterval value is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$) . This value must be from 1 to 16. \n- For high-speed bulk/control OUT endpoints, the bInterval must specify the maximum NAK rate of the endpoint. A value of 0 indicates the endpoint never NAKs. Other values indicate at most 1 NAK each bInterval number of microframes. This value must be in the range from 0 to 255. \n Refer to Chapter 5 of USB 2.0 specification for more information.
  286. } tusb_desc_endpoint_t;
  287. /// USB Other Speed Configuration Descriptor
  288. typedef struct TU_ATTR_PACKED
  289. {
  290. uint8_t bLength ; ///< Size of descriptor
  291. uint8_t bDescriptorType ; ///< Other_speed_Configuration Type
  292. uint16_t wTotalLength ; ///< Total length of data returned
  293. uint8_t bNumInterfaces ; ///< Number of interfaces supported by this speed configuration
  294. uint8_t bConfigurationValue ; ///< Value to use to select configuration
  295. uint8_t IConfiguration ; ///< Index of string descriptor
  296. uint8_t bmAttributes ; ///< Same as Configuration descriptor
  297. uint8_t bMaxPower ; ///< Same as Configuration descriptor
  298. } tusb_desc_other_speed_t;
  299. /// USB Device Qualifier Descriptor
  300. typedef struct TU_ATTR_PACKED
  301. {
  302. uint8_t bLength ; ///< Size of descriptor
  303. uint8_t bDescriptorType ; ///< Device Qualifier Type
  304. uint16_t bcdUSB ; ///< USB specification version number (e.g., 0200H for V2.00)
  305. uint8_t bDeviceClass ; ///< Class Code
  306. uint8_t bDeviceSubClass ; ///< SubClass Code
  307. uint8_t bDeviceProtocol ; ///< Protocol Code
  308. uint8_t bMaxPacketSize0 ; ///< Maximum packet size for other speed
  309. uint8_t bNumConfigurations ; ///< Number of Other-speed Configurations
  310. uint8_t bReserved ; ///< Reserved for future use, must be zero
  311. } tusb_desc_device_qualifier_t;
  312. /// USB Interface Association Descriptor (IAD ECN)
  313. typedef struct TU_ATTR_PACKED
  314. {
  315. uint8_t bLength ; ///< Size of descriptor
  316. uint8_t bDescriptorType ; ///< Other_speed_Configuration Type
  317. uint8_t bFirstInterface ; ///< Index of the first associated interface.
  318. uint8_t bInterfaceCount ; ///< Total number of associated interfaces.
  319. uint8_t bFunctionClass ; ///< Interface class ID.
  320. uint8_t bFunctionSubClass ; ///< Interface subclass ID.
  321. uint8_t bFunctionProtocol ; ///< Interface protocol ID.
  322. uint8_t iFunction ; ///< Index of the string descriptor describing the interface association.
  323. } tusb_desc_interface_assoc_t;
  324. // USB String Descriptor
  325. typedef struct TU_ATTR_PACKED
  326. {
  327. uint8_t bLength ; ///< Size of this descriptor in bytes
  328. uint8_t bDescriptorType ; ///< Descriptor Type
  329. uint16_t unicode_string[];
  330. } tusb_desc_string_t;
  331. // USB Binary Device Object Store (BOS)
  332. typedef struct TU_ATTR_PACKED
  333. {
  334. uint8_t bLength;
  335. uint8_t bDescriptorType ;
  336. uint8_t bDevCapabilityType;
  337. uint8_t bReserved;
  338. uint8_t PlatformCapabilityUUID[16];
  339. uint8_t CapabilityData[];
  340. } tusb_desc_bos_platform_t;
  341. // USB WebuSB URL Descriptor
  342. typedef struct TU_ATTR_PACKED
  343. {
  344. uint8_t bLength;
  345. uint8_t bDescriptorType;
  346. uint8_t bScheme;
  347. char url[];
  348. } tusb_desc_webusb_url_t;
  349. /*------------------------------------------------------------------*/
  350. /* Types
  351. *------------------------------------------------------------------*/
  352. typedef struct TU_ATTR_PACKED{
  353. union {
  354. struct TU_ATTR_PACKED {
  355. uint8_t recipient : 5; ///< Recipient type tusb_request_recipient_t.
  356. uint8_t type : 2; ///< Request type tusb_request_type_t.
  357. uint8_t direction : 1; ///< Direction type. tusb_dir_t
  358. } bmRequestType_bit;
  359. uint8_t bmRequestType;
  360. };
  361. uint8_t bRequest;
  362. uint16_t wValue;
  363. uint16_t wIndex;
  364. uint16_t wLength;
  365. } tusb_control_request_t;
  366. TU_VERIFY_STATIC( sizeof(tusb_control_request_t) == 8, "mostly compiler option issue");
  367. // TODO move to somewhere suitable
  368. static inline uint8_t bm_request_type(uint8_t direction, uint8_t type, uint8_t recipient)
  369. {
  370. return ((uint8_t) (direction << 7)) | ((uint8_t) (type << 5)) | (recipient);
  371. }
  372. //--------------------------------------------------------------------+
  373. // Endpoint helper
  374. //--------------------------------------------------------------------+
  375. // Get direction from Endpoint address
  376. static inline tusb_dir_t tu_edpt_dir(uint8_t addr)
  377. {
  378. return (addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT;
  379. }
  380. // Get Endpoint number from address
  381. static inline uint8_t tu_edpt_number(uint8_t addr)
  382. {
  383. return (uint8_t)(addr & (~TUSB_DIR_IN_MASK));
  384. }
  385. static inline uint8_t tu_edpt_addr(uint8_t num, uint8_t dir)
  386. {
  387. return (uint8_t)(num | (dir ? TUSB_DIR_IN_MASK : 0));
  388. }
  389. //--------------------------------------------------------------------+
  390. // Descriptor helper
  391. //--------------------------------------------------------------------+
  392. static inline uint8_t const * tu_desc_next(void const* desc)
  393. {
  394. uint8_t const* desc8 = (uint8_t const*) desc;
  395. return desc8 + desc8[DESC_OFFSET_LEN];
  396. }
  397. static inline uint8_t tu_desc_type(void const* desc)
  398. {
  399. return ((uint8_t const*) desc)[DESC_OFFSET_TYPE];
  400. }
  401. static inline uint8_t tu_desc_len(void const* desc)
  402. {
  403. return ((uint8_t const*) desc)[DESC_OFFSET_LEN];
  404. }
  405. #ifdef __cplusplus
  406. }
  407. #endif
  408. #endif /* _TUSB_TYPES_H_ */
  409. /** @} */