usb_device_descriptor.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _USB_DEVICE_DESCRIPTOR_H_
  35. #define _USB_DEVICE_DESCRIPTOR_H_ 1
  36. /*******************************************************************************
  37. * Definitions
  38. ******************************************************************************/
  39. #define USB_DEVICE_SPECIFIC_BCD_VERSION (0x0200)
  40. #define USB_DEVICE_DEMO_BCD_VERSION (0x0101U)
  41. /* Communication Class Codes */
  42. #define CDC_COMM_CLASS (0x02)
  43. /* Data Class Codes */
  44. #define CDC_DATA_CLASS (0x0A)
  45. /* Communication Class SubClass Codes */
  46. #define USB_CDC_DIRECT_LINE_CONTROL_MODEL (0x01)
  47. #define USB_CDC_ABSTRACT_CONTROL_MODEL (0x02)
  48. #define USB_CDC_TELEPHONE_CONTROL_MODEL (0x03)
  49. #define USB_CDC_MULTI_CHANNEL_CONTROL_MODEL (0x04)
  50. #define USB_CDC_CAPI_CONTROL_MOPDEL (0x05)
  51. #define USB_CDC_ETHERNET_NETWORKING_CONTROL_MODEL (0x06)
  52. #define USB_CDC_ATM_NETWORKING_CONTROL_MODEL (0x07)
  53. #define USB_CDC_WIRELESS_HANDSET_CONTROL_MODEL (0x08)
  54. #define USB_CDC_DEVICE_MANAGEMENT (0x09)
  55. #define USB_CDC_MOBILE_DIRECT_LINE_MODEL (0x0A)
  56. #define USB_CDC_OBEX (0x0B)
  57. #define USB_CDC_ETHERNET_EMULATION_MODEL (0x0C)
  58. /* Communication Class Protocol Codes */
  59. #define USB_CDC_NO_CLASS_SPECIFIC_PROTOCOL (0x00) /*also for Data Class Protocol Code */
  60. #define USB_CDC_AT_250_PROTOCOL (0x01)
  61. #define USB_CDC_AT_PCCA_101_PROTOCOL (0x02)
  62. #define USB_CDC_AT_PCCA_101_ANNEX_O (0x03)
  63. #define USB_CDC_AT_GSM_7_07 (0x04)
  64. #define USB_CDC_AT_3GPP_27_007 (0x05)
  65. #define USB_CDC_AT_TIA_CDMA (0x06)
  66. #define USB_CDC_ETHERNET_EMULATION_PROTOCOL (0x07)
  67. #define USB_CDC_EXTERNAL_PROTOCOL (0xFE)
  68. #define USB_CDC_VENDOR_SPECIFIC (0xFF) /*also for Data Class Protocol Code */
  69. /* Data Class Protocol Codes */
  70. #define USB_CDC_PYHSICAL_INTERFACE_PROTOCOL (0x30)
  71. #define USB_CDC_HDLC_PROTOCOL (0x31)
  72. #define USB_CDC_TRANSPARENT_PROTOCOL (0x32)
  73. #define USB_CDC_MANAGEMENT_PROTOCOL (0x50)
  74. #define USB_CDC_DATA_LINK_Q931_PROTOCOL (0x51)
  75. #define USB_CDC_DATA_LINK_Q921_PROTOCOL (0x52)
  76. #define USB_CDC_DATA_COMPRESSION_V42BIS (0x90)
  77. #define USB_CDC_EURO_ISDN_PROTOCOL (0x91)
  78. #define USB_CDC_RATE_ADAPTION_ISDN_V24 (0x92)
  79. #define USB_CDC_CAPI_COMMANDS (0x93)
  80. #define USB_CDC_HOST_BASED_DRIVER (0xFD)
  81. #define USB_CDC_UNIT_FUNCTIONAL (0xFE)
  82. /* Descriptor SubType in Communications Class Functional Descriptors */
  83. #define USB_CDC_HEADER_FUNC_DESC (0x00)
  84. #define USB_CDC_CALL_MANAGEMENT_FUNC_DESC (0x01)
  85. #define USB_CDC_ABSTRACT_CONTROL_FUNC_DESC (0x02)
  86. #define USB_CDC_DIRECT_LINE_FUNC_DESC (0x03)
  87. #define USB_CDC_TELEPHONE_RINGER_FUNC_DESC (0x04)
  88. #define USB_CDC_TELEPHONE_REPORT_FUNC_DESC (0x05)
  89. #define USB_CDC_UNION_FUNC_DESC (0x06)
  90. #define USB_CDC_COUNTRY_SELECT_FUNC_DESC (0x07)
  91. #define USB_CDC_TELEPHONE_MODES_FUNC_DESC (0x08)
  92. #define USB_CDC_TERMINAL_FUNC_DESC (0x09)
  93. #define USB_CDC_NETWORK_CHANNEL_FUNC_DESC (0x0A)
  94. #define USB_CDC_PROTOCOL_UNIT_FUNC_DESC (0x0B)
  95. #define USB_CDC_EXTENSION_UNIT_FUNC_DESC (0x0C)
  96. #define USB_CDC_MULTI_CHANNEL_FUNC_DESC (0x0D)
  97. #define USB_CDC_CAPI_CONTROL_FUNC_DESC (0x0E)
  98. #define USB_CDC_ETHERNET_NETWORKING_FUNC_DESC (0x0F)
  99. #define USB_CDC_ATM_NETWORKING_FUNC_DESC (0x10)
  100. #define USB_CDC_WIRELESS_CONTROL_FUNC_DESC (0x11)
  101. #define USB_CDC_MOBILE_DIRECT_LINE_FUNC_DESC (0x12)
  102. #define USB_CDC_MDLM_DETAIL_FUNC_DESC (0x13)
  103. #define USB_CDC_DEVICE_MANAGEMENT_FUNC_DESC (0x14)
  104. #define USB_CDC_OBEX_FUNC_DESC (0x15)
  105. #define USB_CDC_COMMAND_SET_FUNC_DESC (0x16)
  106. #define USB_CDC_COMMAND_SET_DETAIL_FUNC_DESC (0x17)
  107. #define USB_CDC_TELEPHONE_CONTROL_FUNC_DESC (0x18)
  108. #define USB_CDC_OBEX_SERVICE_ID_FUNC_DESC (0x19)
  109. /* usb descritpor length */
  110. #define USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL (67)
  111. #define USB_DESCRIPTOR_LENGTH_CDC_HEADER_FUNC (5)
  112. #define USB_DESCRIPTOR_LENGTH_CDC_CALL_MANAG (5)
  113. #define USB_DESCRIPTOR_LENGTH_CDC_ABSTRACT (4)
  114. #define USB_DESCRIPTOR_LENGTH_CDC_UNION_FUNC (5)
  115. #define USB_DEVICE_CONFIGURATION_COUNT (1)
  116. #define USB_DEVICE_STRING_COUNT (3)
  117. #define USB_DEVICE_LANGUAGE_COUNT (1)
  118. #define USB_CDC_VCOM_CONFIGURE_INDEX (1)
  119. #define USB_CDC_VCOM_ENDPOINT_CIC_COUNT (1)
  120. #define USB_CDC_VCOM_ENDPOINT_DIC_COUNT (2)
  121. #define USB_CDC_VCOM_INTERRUPT_IN_ENDPOINT (1)
  122. #define USB_CDC_VCOM_BULK_IN_ENDPOINT (2)
  123. #define USB_CDC_VCOM_BULK_OUT_ENDPOINT (3)
  124. #define USB_CDC_VCOM_INTERFACE_COUNT (2)
  125. #define USB_CDC_VCOM_COMM_INTERFACE_INDEX (0)
  126. #define USB_CDC_VCOM_DATA_INTERFACE_INDEX (1)
  127. #define HS_CDC_VCOM_INTERRUPT_IN_PACKET_SIZE (16)
  128. #define FS_CDC_VCOM_INTERRUPT_IN_PACKET_SIZE (16)
  129. #define HS_CDC_VCOM_INTERRUPT_IN_INTERVAL (0x07) /* 2^(7-1) = 8ms */
  130. #define FS_CDC_VCOM_INTERRUPT_IN_INTERVAL (0x08)
  131. #define HS_CDC_VCOM_BULK_IN_PACKET_SIZE (512)
  132. #define FS_CDC_VCOM_BULK_IN_PACKET_SIZE (64)
  133. #define HS_CDC_VCOM_BULK_OUT_PACKET_SIZE (512)
  134. #define FS_CDC_VCOM_BULK_OUT_PACKET_SIZE (64)
  135. #define USB_DESCRIPTOR_LENGTH_STRING0 (4)
  136. #define USB_DESCRIPTOR_LENGTH_STRING1 (38)
  137. #define USB_DESCRIPTOR_LENGTH_STRING2 (42)
  138. #define USB_DESCRIPTOR_TYPE_CDC_CS_INTERFACE (0x24)
  139. #define USB_DESCRIPTOR_TYPE_CDC_CS_ENDPOINT (0x25)
  140. #define USB_DEVICE_CLASS (0x02)
  141. #define USB_DEVICE_SUBCLASS (0x00)
  142. #define USB_DEVICE_PROTOCOL (0x00)
  143. #define USB_DEVICE_MAX_POWER (0x32)
  144. #define USB_CDC_VCOM_CIC_CLASS (CDC_COMM_CLASS)
  145. #define USB_CDC_VCOM_CIC_SUBCLASS (USB_CDC_ABSTRACT_CONTROL_MODEL)
  146. #define USB_CDC_VCOM_CIC_PROTOCOL (USB_CDC_NO_CLASS_SPECIFIC_PROTOCOL)
  147. #define USB_CDC_VCOM_DIC_CLASS (CDC_DATA_CLASS)
  148. #define USB_CDC_VCOM_DIC_SUBCLASS (0x00)
  149. #define USB_CDC_VCOM_DIC_PROTOCOL (USB_CDC_NO_CLASS_SPECIFIC_PROTOCOL)
  150. /*******************************************************************************
  151. * API
  152. ******************************************************************************/
  153. /*!
  154. * @brief USB device callback function.
  155. *
  156. * This function handles the usb device specific requests.
  157. *
  158. * @param handle The USB device handle.
  159. * @param event The USB device event type.
  160. * @param param The parameter of the device specific request.
  161. *
  162. * @return A USB error code or kStatus_USB_Success.
  163. */
  164. extern usb_status_t USB_DeviceCallback(usb_device_handle handle, uint32_t event, void *param);
  165. /*!
  166. * @brief USB device set speed function.
  167. *
  168. * This function sets the speed of the USB device.
  169. *
  170. * Due to the difference of HS and FS descriptors, the device descriptors and configurations need to be updated to match
  171. * current speed.
  172. * As the default, the device descriptors and configurations are configured by using FS parameters for both EHCI and
  173. * KHCI.
  174. * When the EHCI is enabled, the application needs to call this fucntion to update device by using current speed.
  175. * The updated information includes endpoint max packet size, endpoint interval, etc.
  176. *
  177. * @param handle The USB device handle.
  178. * @param speed Speed type. USB_SPEED_HIGH/USB_SPEED_FULL/USB_SPEED_LOW.
  179. *
  180. * @return A USB error code or kStatus_USB_Success.
  181. */
  182. extern usb_status_t USB_DeviceSetSpeed(usb_device_handle handle, uint8_t speed);
  183. #endif /* _USB_DEVICE_DESCRIPTOR_H_ */