usb_device.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /*
  2. * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
  3. * Copyright 2016 NXP
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of the copyright holder nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef __FSL_USB_DEVICE_H__
  31. #define __FSL_USB_DEVICE_H__
  32. /*!
  33. * @addtogroup usb_device_driver
  34. * @{
  35. */
  36. /*******************************************************************************
  37. * Definitions
  38. ******************************************************************************/
  39. /*! @brief Defines Get/Set status Types */
  40. typedef enum _usb_device_status
  41. {
  42. kUSB_DeviceStatusTestMode = 1U, /*!< Test mode */
  43. kUSB_DeviceStatusSpeed, /*!< Current speed */
  44. kUSB_DeviceStatusOtg, /*!< OTG status */
  45. kUSB_DeviceStatusDevice, /*!< Device status */
  46. kUSB_DeviceStatusEndpoint, /*!< Endpoint state usb_device_endpoint_status_t */
  47. kUSB_DeviceStatusDeviceState, /*!< Device state */
  48. kUSB_DeviceStatusAddress, /*!< Device address */
  49. kUSB_DeviceStatusSynchFrame, /*!< Current frame */
  50. kUSB_DeviceStatusBus, /*!< Bus status */
  51. kUSB_DeviceStatusBusSuspend, /*!< Bus suspend */
  52. kUSB_DeviceStatusBusSleep, /*!< Bus suspend */
  53. kUSB_DeviceStatusBusResume, /*!< Bus resume */
  54. kUSB_DeviceStatusRemoteWakeup, /*!< Remote wakeup state */
  55. kUSB_DeviceStatusBusSleepResume, /*!< Bus resume */
  56. } usb_device_status_t;
  57. /*! @brief Defines USB 2.0 device state */
  58. typedef enum _usb_device_state
  59. {
  60. kUSB_DeviceStateConfigured = 0U, /*!< Device state, Configured*/
  61. kUSB_DeviceStateAddress, /*!< Device state, Address*/
  62. kUSB_DeviceStateDefault, /*!< Device state, Default*/
  63. kUSB_DeviceStateAddressing, /*!< Device state, Address setting*/
  64. kUSB_DeviceStateTestMode, /*!< Device state, Test mode*/
  65. } usb_device_state_t;
  66. #if (defined(USB_DEVICE_CHARGER_DETECT_ENABLE) && (USB_DEVICE_CHARGER_DETECT_ENABLE > 0U))
  67. typedef enum _usb_dcd_detection_sequence_status
  68. {
  69. kUSB_DcdDetectionNotEnabled = 0x0U,
  70. kUSB_DcdDataPinDetectionCompleted = 0x01U,
  71. kUSB_DcdChargingPortDetectionCompleted = 0x02U,
  72. kUSB_DcdChargerTypeDetectionCompleted = 0x03U,
  73. } usb_dcd_detection_sequence_status_t;
  74. typedef enum _usb_dcd_detection_sequence_results
  75. {
  76. kUSB_DcdDetectionNoResults = 0x0U,
  77. kUSB_DcdDetectionStandardHost = 0x01U,
  78. kUSB_DcdDetectionChargingPort = 0x02U,
  79. kUSB_DcdDetectionDedicatedCharger = 0x03U,
  80. } usb_dcd_detection_sequence_results_t;
  81. #endif
  82. /*! @brief Defines endpoint state */
  83. typedef enum _usb_endpoint_status
  84. {
  85. kUSB_DeviceEndpointStateIdle = 0U, /*!< Endpoint state, idle*/
  86. kUSB_DeviceEndpointStateStalled, /*!< Endpoint state, stalled*/
  87. } usb_device_endpoint_status_t;
  88. /*! @brief Control endpoint index */
  89. #define USB_CONTROL_ENDPOINT (0U)
  90. /*! @brief Control endpoint maxPacketSize */
  91. #define USB_CONTROL_MAX_PACKET_SIZE (64U)
  92. #if (USB_DEVICE_CONFIG_EHCI && (USB_CONTROL_MAX_PACKET_SIZE != (64U)))
  93. #error For high speed, USB_CONTROL_MAX_PACKET_SIZE must be 64!!!
  94. #endif
  95. /*! @brief The setup packet size of USB control transfer. */
  96. #define USB_SETUP_PACKET_SIZE (8U)
  97. /*! @brief USB endpoint mask */
  98. #define USB_ENDPOINT_NUMBER_MASK (0x0FU)
  99. /*! @brief Default invalid value or the endpoint callback length of cancelled transfer */
  100. #define USB_UNINITIALIZED_VAL_32 (0xFFFFFFFFU)
  101. /*! @brief Available common EVENT types in device callback */
  102. typedef enum _usb_device_event
  103. {
  104. kUSB_DeviceEventBusReset = 1U, /*!< USB bus reset signal detected */
  105. kUSB_DeviceEventSuspend, /*!< USB bus suspend signal detected */
  106. kUSB_DeviceEventResume, /*!< USB bus resume signal detected. The resume signal is driven by itself or a host */
  107. kUSB_DeviceEventSleeped, /*!< USB bus LPM suspend signal detected */
  108. kUSB_DeviceEventLPMResume, /*!< USB bus LPM resume signal detected. The resume signal is driven by itself or a host
  109. */
  110. kUSB_DeviceEventError, /*!< An error is happened in the bus. */
  111. kUSB_DeviceEventDetach, /*!< USB device is disconnected from a host. */
  112. kUSB_DeviceEventAttach, /*!< USB device is connected to a host. */
  113. kUSB_DeviceEventSetConfiguration, /*!< Set configuration. */
  114. kUSB_DeviceEventSetInterface, /*!< Set interface. */
  115. kUSB_DeviceEventGetDeviceDescriptor, /*!< Get device descriptor. */
  116. kUSB_DeviceEventGetConfigurationDescriptor, /*!< Get configuration descriptor. */
  117. kUSB_DeviceEventGetStringDescriptor, /*!< Get string descriptor. */
  118. kUSB_DeviceEventGetHidDescriptor, /*!< Get HID descriptor. */
  119. kUSB_DeviceEventGetHidReportDescriptor, /*!< Get HID report descriptor. */
  120. kUSB_DeviceEventGetHidPhysicalDescriptor, /*!< Get HID physical descriptor. */
  121. kUSB_DeviceEventGetBOSDescriptor, /*!< Get configuration descriptor. */
  122. kUSB_DeviceEventGetDeviceQualifierDescriptor, /*!< Get device qualifier descriptor. */
  123. kUSB_DeviceEventVendorRequest, /*!< Vendor request. */
  124. kUSB_DeviceEventSetRemoteWakeup, /*!< Enable or disable remote wakeup function. */
  125. kUSB_DeviceEventGetConfiguration, /*!< Get current configuration index */
  126. kUSB_DeviceEventGetInterface, /*!< Get current interface alternate setting value */
  127. kUSB_DeviceEventSetBHNPEnable,
  128. #if (defined(USB_DEVICE_CHARGER_DETECT_ENABLE) && (USB_DEVICE_CHARGER_DETECT_ENABLE > 0U))
  129. kUSB_DeviceEventDcdTimeOut, /*!< Dcd detect result is timeout */
  130. kUSB_DeviceEventDcdUnknownType, /*!< Dcd detect result is unknown type */
  131. kUSB_DeviceEventSDPDetected, /*!< The SDP facility is detected */
  132. kUSB_DeviceEventChargingPortDetected, /*!< The charging port is detected */
  133. kUSB_DeviceEventChargingHostDetected, /*!< The CDP facility is detected */
  134. kUSB_DeviceEventDedicatedChargerDetected, /*!< The DCP facility is detected */
  135. #endif
  136. } usb_device_event_t;
  137. /*! @brief Endpoint callback message structure */
  138. typedef struct _usb_device_endpoint_callback_message_struct
  139. {
  140. uint8_t *buffer; /*!< Transferred buffer */
  141. uint32_t length; /*!< Transferred data length */
  142. uint8_t isSetup; /*!< Is in a setup phase */
  143. } usb_device_endpoint_callback_message_struct_t;
  144. /*!
  145. * @brief Endpoint callback function typedef.
  146. *
  147. * This callback function is used to notify the upper layer what the transfer result is.
  148. * This callback pointer is passed when a specified endpoint is initialized by calling API #USB_DeviceInitEndpoint.
  149. *
  150. * @param handle The device handle. It equals to the value returned from #USB_DeviceInit.
  151. * @param message The result of a transfer, which includes transfer buffer, transfer length, and whether is in a
  152. * setup phase.
  153. * phase for control pipe.
  154. * @param callbackParam The parameter for this callback. It is same with
  155. * usb_device_endpoint_callback_struct_t::callbackParam.
  156. *
  157. * @return A USB error code or kStatus_USB_Success.
  158. */
  159. typedef usb_status_t (*usb_device_endpoint_callback_t)(usb_device_handle handle,
  160. usb_device_endpoint_callback_message_struct_t *message,
  161. void *callbackParam);
  162. /*!
  163. * @brief Device callback function typedef.
  164. *
  165. * This callback function is used to notify the upper layer that the device status has changed.
  166. * This callback pointer is passed by calling API #USB_DeviceInit.
  167. *
  168. * @param handle The device handle. It equals the value returned from #USB_DeviceInit.
  169. * @param callbackEvent The callback event type. See enumeration #usb_device_event_t.
  170. * @param eventParam The event parameter for this callback. The parameter type is determined by the callback event.
  171. *
  172. * @return A USB error code or kStatus_USB_Success.
  173. */
  174. typedef usb_status_t (*usb_device_callback_t)(usb_device_handle handle, uint32_t callbackEvent, void *eventParam);
  175. /*! @brief Endpoint callback structure */
  176. typedef struct _usb_device_endpoint_callback_struct
  177. {
  178. usb_device_endpoint_callback_t callbackFn; /*!< Endpoint callback function*/
  179. void *callbackParam; /*!< Parameter for callback function*/
  180. uint8_t isBusy;
  181. } usb_device_endpoint_callback_struct_t;
  182. /*! @brief Endpoint initialization structure */
  183. typedef struct _usb_device_endpoint_init_struct
  184. {
  185. uint16_t maxPacketSize; /*!< Endpoint maximum packet size */
  186. uint8_t endpointAddress; /*!< Endpoint address*/
  187. uint8_t transferType; /*!< Endpoint transfer type*/
  188. uint8_t zlt; /*!< ZLT flag*/
  189. } usb_device_endpoint_init_struct_t;
  190. /*! @brief Endpoint status structure */
  191. typedef struct _usb_device_endpoint_status_struct
  192. {
  193. uint8_t endpointAddress; /*!< Endpoint address */
  194. uint16_t endpointStatus; /*!< Endpoint status : idle or stalled */
  195. } usb_device_endpoint_status_struct_t;
  196. #if (defined(USB_DEVICE_CHARGER_DETECT_ENABLE) && (USB_DEVICE_CHARGER_DETECT_ENABLE > 0U))
  197. /*! @brief USB DCD charge timing specification structure */
  198. typedef struct _usb_device_dcd_charging_time
  199. {
  200. uint16_t dcdSeqInitTime; /*!< The dcd sequence init time */
  201. uint16_t dcdDbncTime; /*!< The debounce time period on DP signal */
  202. uint16_t dcdDpSrcOnTime; /*!< The time period comparator enabled */
  203. uint16_t dcdTimeWaitAfterPrD; /*!< The time period between primary and secondary detection */
  204. uint8_t dcdTimeDMSrcOn; /*!< The amount of time that the modules enable the Vdm_src */
  205. } usb_device_dcd_charging_time_t;
  206. #endif
  207. #if defined(__cplusplus)
  208. extern "C" {
  209. #endif /* __cplusplus*/
  210. /*!
  211. * @name USB device APIs
  212. * @{
  213. */
  214. /*******************************************************************************
  215. * API
  216. ******************************************************************************/
  217. /*!
  218. * @brief Initializes the USB device stack.
  219. *
  220. * This function initializes the USB device module specified by the controllerId.
  221. *
  222. * @param[in] controllerId The controller ID of the USB IP. See the enumeration #usb_controller_index_t.
  223. * @param[in] deviceCallback Function pointer of the device callback.
  224. * @param[out] handle It is an out parameter used to return the pointer of the device handle to the caller.
  225. *
  226. * @retval kStatus_USB_Success The device is initialized successfully.
  227. * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer.
  228. * @retval kStatus_USB_Busy Cannot allocate a device handle.
  229. * @retval kStatus_USB_ControllerNotFound Cannot find the controller according to the controller id.
  230. * @retval kStatus_USB_InvalidControllerInterface The controller driver interfaces is invalid. There is an empty
  231. * interface entity.
  232. * @retval kStatus_USB_Error The macro USB_DEVICE_CONFIG_ENDPOINTS is more than the IP's endpoint number.
  233. * Or, the device has been initialized.
  234. * Or, the mutex or message queue is created failed.
  235. */
  236. extern usb_status_t USB_DeviceInit(uint8_t controllerId,
  237. usb_device_callback_t deviceCallback,
  238. usb_device_handle *handle);
  239. /*!
  240. * @brief Enables the device functionality.
  241. *
  242. * The function enables the device functionality, so that the device can be recognized by the host when the device
  243. * detects that it has been connected to a host.
  244. *
  245. * @param[in] handle The device handle got from #USB_DeviceInit.
  246. *
  247. * @retval kStatus_USB_Success The device is run successfully.
  248. * @retval kStatus_USB_ControllerNotFound Cannot find the controller.
  249. * @retval kStatus_USB_InvalidHandle The device handle is a NULL pointer. Or the controller handle is invalid.
  250. *
  251. */
  252. extern usb_status_t USB_DeviceRun(usb_device_handle handle);
  253. /*!
  254. * @brief Disables the device functionality.
  255. *
  256. * The function disables the device functionality. After this function called, even if the device is detached to the
  257. * host,
  258. * it can't work.
  259. *
  260. * @param[in] handle The device handle received from #USB_DeviceInit.
  261. *
  262. * @retval kStatus_USB_Success The device is stopped successfully.
  263. * @retval kStatus_USB_ControllerNotFound Cannot find the controller.
  264. * @retval kStatus_USB_InvalidHandle The device handle is a NULL pointer or the controller handle is invalid.
  265. */
  266. extern usb_status_t USB_DeviceStop(usb_device_handle handle);
  267. /*!
  268. * @brief De-initializes the device controller.
  269. *
  270. * The function de-initializes the device controller specified by the handle.
  271. *
  272. * @param[in] handle The device handle got from #USB_DeviceInit.
  273. *
  274. * @retval kStatus_USB_Success The device is stopped successfully.
  275. * @retval kStatus_USB_InvalidHandle The device handle is a NULL pointer or the controller handle is invalid.
  276. */
  277. extern usb_status_t USB_DeviceDeinit(usb_device_handle handle);
  278. /*!
  279. * @brief Sends data through a specified endpoint.
  280. *
  281. * The function is used to send data through a specified endpoint.
  282. *
  283. * @param[in] handle The device handle got from #USB_DeviceInit.
  284. * @param[in] endpointAddress Endpoint index.
  285. * @param[in] buffer The memory address to hold the data need to be sent. The function is not reentrant.
  286. * @param[in] length The data length need to be sent.
  287. *
  288. * @retval kStatus_USB_Success The send request is sent successfully.
  289. * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid.
  290. * @retval kStatus_USB_Busy Cannot allocate DTDS for current transfer in EHCI driver.
  291. * @retval kStatus_USB_ControllerNotFound Cannot find the controller.
  292. * @retval kStatus_USB_Error The device is doing reset.
  293. *
  294. * @note The return value indicates whether the sending request is successful or not. The transfer done is notified by
  295. * the
  296. * corresponding callback function.
  297. * Currently, only one transfer request can be supported for one specific endpoint.
  298. * If there is a specific requirement to support multiple transfer requests for one specific endpoint, the application
  299. * should implement a queue on the application level.
  300. * The subsequent transfer can begin only when the previous transfer is done (get notification through the endpoint
  301. * callback).
  302. */
  303. extern usb_status_t USB_DeviceSendRequest(usb_device_handle handle,
  304. uint8_t endpointAddress,
  305. uint8_t *buffer,
  306. uint32_t length);
  307. /*!
  308. * @brief Receives data through a specified endpoint.
  309. *
  310. * The function is used to receive data through a specified endpoint. The function is not reentrant.
  311. *
  312. * @param[in] handle The device handle got from #USB_DeviceInit.
  313. * @param[in] endpointAddress Endpoint index.
  314. * @param[in] buffer The memory address to save the received data.
  315. * @param[in] length The data length want to be received.
  316. *
  317. * @retval kStatus_USB_Success The receive request is sent successfully.
  318. * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid.
  319. * @retval kStatus_USB_Busy Cannot allocate DTDS for current transfer in EHCI driver.
  320. * @retval kStatus_USB_ControllerNotFound Cannot find the controller.
  321. * @retval kStatus_USB_Error The device is doing reset.
  322. *
  323. * @note The return value indicates whether the receiving request is successful or not. The transfer done is notified by
  324. * the
  325. * corresponding callback function.
  326. * Currently, only one transfer request can be supported for one specific endpoint.
  327. * If there is a specific requirement to support multiple transfer requests for one specific endpoint, the application
  328. * should implement a queue on the application level.
  329. * The subsequent transfer can begin only when the previous transfer is done (get notification through the endpoint
  330. * callback).
  331. */
  332. extern usb_status_t USB_DeviceRecvRequest(usb_device_handle handle,
  333. uint8_t endpointAddress,
  334. uint8_t *buffer,
  335. uint32_t length);
  336. /*!
  337. * @brief Cancels the pending transfer in a specified endpoint.
  338. *
  339. * The function is used to cancel the pending transfer in a specified endpoint.
  340. *
  341. * @param[in] handle The device handle got from #USB_DeviceInit.
  342. * @param[in] endpointAddress Endpoint address, bit7 is the direction of endpoint, 1U - IN, and 0U - OUT.
  343. *
  344. * @retval kStatus_USB_Success The transfer is cancelled.
  345. * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer or the controller handle is invalid.
  346. * @retval kStatus_USB_ControllerNotFound Cannot find the controller.
  347. */
  348. extern usb_status_t USB_DeviceCancel(usb_device_handle handle, uint8_t endpointAddress);
  349. /*!
  350. * @brief Initializes a specified endpoint.
  351. *
  352. * The function is used to initialize a specified endpoint. The corresponding endpoint callback is also initialized.
  353. *
  354. * @param[in] handle The device handle received from #USB_DeviceInit.
  355. * @param[in] epInit Endpoint initialization structure. See the structure usb_device_endpoint_init_struct_t.
  356. * @param[in] epCallback Endpoint callback structure. See the structure
  357. * usb_device_endpoint_callback_struct_t.
  358. *
  359. * @retval kStatus_USB_Success The endpoint is initialized successfully.
  360. * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid.
  361. * @retval kStatus_USB_InvalidParameter The epInit or epCallback is NULL pointer. Or the endpoint number is
  362. * more than USB_DEVICE_CONFIG_ENDPOINTS.
  363. * @retval kStatus_USB_Busy The endpoint is busy in EHCI driver.
  364. * @retval kStatus_USB_ControllerNotFound Cannot find the controller.
  365. */
  366. extern usb_status_t USB_DeviceInitEndpoint(usb_device_handle handle,
  367. usb_device_endpoint_init_struct_t *epInit,
  368. usb_device_endpoint_callback_struct_t *epCallback);
  369. /*!
  370. * @brief Deinitializes a specified endpoint.
  371. *
  372. * The function is used to deinitializes a specified endpoint.
  373. *
  374. * @param[in] handle The device handle got from #USB_DeviceInit.
  375. * @param[in] endpointAddress Endpoint address, bit7 is the direction of endpoint, 1U - IN, and 0U - OUT.
  376. *
  377. * @retval kStatus_USB_Success The endpoint is de-initialized successfully.
  378. * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid.
  379. * @retval kStatus_USB_InvalidParameter The endpoint number is more than USB_DEVICE_CONFIG_ENDPOINTS.
  380. * @retval kStatus_USB_Busy The endpoint is busy in EHCI driver.
  381. * @retval kStatus_USB_ControllerNotFound Cannot find the controller.
  382. */
  383. extern usb_status_t USB_DeviceDeinitEndpoint(usb_device_handle handle, uint8_t endpointAddress);
  384. /*!
  385. * @brief Stalls a specified endpoint.
  386. *
  387. * The function is used to stall a specified endpoint.
  388. *
  389. * @param[in] handle The device handle received from #USB_DeviceInit.
  390. * @param[in] endpointAddress Endpoint address, bit7 is the direction of endpoint, 1U - IN, and 0U - OUT.
  391. *
  392. * @retval kStatus_USB_Success The endpoint is stalled successfully.
  393. * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid.
  394. * @retval kStatus_USB_InvalidParameter The endpoint number is more than USB_DEVICE_CONFIG_ENDPOINTS.
  395. * @retval kStatus_USB_ControllerNotFound Cannot find the controller.
  396. */
  397. extern usb_status_t USB_DeviceStallEndpoint(usb_device_handle handle, uint8_t endpointAddress);
  398. /*!
  399. * @brief Unstalls a specified endpoint.
  400. *
  401. * The function is used to unstall a specified endpoint.
  402. *
  403. * @param[in] handle The device handle received from #USB_DeviceInit.
  404. * @param[in] endpointAddress Endpoint address, bit7 is the direction of endpoint, 1U - IN, and 0U - OUT.
  405. *
  406. * @retval kStatus_USB_Success The endpoint is unstalled successfully.
  407. * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid.
  408. * @retval kStatus_USB_InvalidParameter The endpoint number is more than USB_DEVICE_CONFIG_ENDPOINTS.
  409. * @retval kStatus_USB_ControllerNotFound Cannot find the controller.
  410. */
  411. extern usb_status_t USB_DeviceUnstallEndpoint(usb_device_handle handle, uint8_t endpointAddress);
  412. /*!
  413. * @brief Gets the status of the selected item.
  414. *
  415. * The function is used to get the status of the selected item.
  416. *
  417. * @param[in] handle The device handle got from #USB_DeviceInit.
  418. * @param[in] type The selected item. See the structure #usb_device_status_t.
  419. * @param[out] param The parameter type is determined by the selected item.
  420. *
  421. * @retval kStatus_USB_Success Get status successfully.
  422. * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid.
  423. * @retval kStatus_USB_InvalidParameter The parameter is NULL pointer.
  424. * @retval kStatus_USB_ControllerNotFound Cannot find the controller.
  425. * @retval kStatus_USB_Error Unsupported type.
  426. */
  427. extern usb_status_t USB_DeviceGetStatus(usb_device_handle handle, usb_device_status_t type, void *param);
  428. /*!
  429. * @brief Sets the status of the selected item.
  430. *
  431. * The function is used to set the status of the selected item.
  432. *
  433. * @param[in] handle The device handle got from #USB_DeviceInit.
  434. * @param[in] type The selected item. See the structure #usb_device_status_t.
  435. * @param[in] param The parameter type is determined by the selected item.
  436. *
  437. * @retval kStatus_USB_Success Set status successfully.
  438. * @retval kStatus_USB_InvalidHandle The handle is a NULL pointer. Or the controller handle is invalid.
  439. * @retval kStatus_USB_ControllerNotFound Cannot find the controller.
  440. * @retval kStatus_USB_Error Unsupported type or the parameter is NULL pointer.
  441. */
  442. extern usb_status_t USB_DeviceSetStatus(usb_device_handle handle, usb_device_status_t type, void *param);
  443. #if (defined(USB_DEVICE_CHARGER_DETECT_ENABLE) && (USB_DEVICE_CHARGER_DETECT_ENABLE > 0U))
  444. /*!
  445. * @brief Initializes the device dcd module.
  446. *
  447. * The function initializes the device dcd module.
  448. *
  449. * @param[in] handle The device handle got from #USB_DeviceInit.
  450. * @param[in] time_param The time parameter used to config the dcd timing registers.
  451. *
  452. * @retval kStatus_USB_Success The device is run successfully.
  453. * @retval kStatus_USB_ControllerNotFound Cannot find the controller.
  454. * @retval kStatus_USB_InvalidHandle The device handle is a NULL pointer. Or the controller handle is invalid.
  455. *
  456. */
  457. extern usb_status_t USB_DeviceDcdInitModule(usb_device_handle handle, void *time_param);
  458. /*!
  459. * @brief De-initializes the device dcd module.
  460. *
  461. * The function de-initializes the device dcd module specified by the handle.
  462. *
  463. * @param[in] handle The device handle got from #USB_DeviceInit.
  464. *
  465. * @retval kStatus_USB_Success The device is stopped successfully.
  466. * @retval kStatus_USB_InvalidHandle The device handle is a NULL pointer or the controller handle is invalid.
  467. */
  468. extern usb_status_t USB_DeviceDcdDeinitModule(usb_device_handle handle);
  469. #endif
  470. /*!
  471. * @brief Device task function.
  472. *
  473. * The function is used to handle the controller message.
  474. * This function should not be called in the application directly.
  475. *
  476. * @param[in] deviceHandle The device handle got from #USB_DeviceInit.
  477. */
  478. extern void USB_DeviceTaskFunction(void *deviceHandle);
  479. #if ((defined(USB_DEVICE_CONFIG_KHCI)) && (USB_DEVICE_CONFIG_KHCI > 0U))
  480. /*!
  481. * @brief Device KHCI task function.
  482. *
  483. * The function is used to handle the KHCI controller message.
  484. * In the bare metal environment, this function should be called periodically in the main function.
  485. * In the RTOS environment, this function should be used as a function entry to create a task.
  486. *
  487. * @param[in] deviceHandle The device handle got from #USB_DeviceInit.
  488. */
  489. #define USB_DeviceKhciTaskFunction(deviceHandle) USB_DeviceTaskFunction(deviceHandle)
  490. #endif
  491. #if ((defined(USB_DEVICE_CONFIG_EHCI)) && (USB_DEVICE_CONFIG_EHCI > 0U))
  492. /*!
  493. * @brief Device EHCI task function.
  494. *
  495. * The function is used to handle the EHCI controller message.
  496. * In the bare metal environment, this function should be called periodically in the main function.
  497. * In the RTOS environment, this function should be used as a function entry to create a task.
  498. *
  499. * @param[in] deviceHandle The device handle got from #USB_DeviceInit.
  500. */
  501. #define USB_DeviceEhciTaskFunction(deviceHandle) USB_DeviceTaskFunction(deviceHandle)
  502. #if (defined(USB_DEVICE_CHARGER_DETECT_ENABLE) && (USB_DEVICE_CHARGER_DETECT_ENABLE > 0U))
  503. /*!
  504. * @brief Device EHCI DCD ISR function.
  505. *
  506. * The function is the EHCI DCD interrupt service routine.
  507. *
  508. * @param[in] deviceHandle The device handle got from #USB_DeviceInit.
  509. */
  510. extern void USB_DeviceDcdHSIsrFunction(void *deviceHandle);
  511. #endif
  512. #endif
  513. #if (((defined(USB_DEVICE_CONFIG_LPCIP3511FS)) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)) || \
  514. ((defined(USB_DEVICE_CONFIG_LPCIP3511HS)) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U)))
  515. /*!
  516. * @brief Device LPC ip3511 controller task function.
  517. *
  518. * The function is used to handle the LPC ip3511 controller message.
  519. * In the bare metal environment, this function should be called periodically in the main function.
  520. * In the RTOS environment, this function should be used as a function entry to create a task.
  521. *
  522. * @param[in] deviceHandle The device handle got from #USB_DeviceInit.
  523. */
  524. #define USB_DeviceLpcIp3511TaskFunction(deviceHandle) USB_DeviceTaskFunction(deviceHandle)
  525. #endif
  526. #if ((defined(USB_DEVICE_CONFIG_KHCI)) && (USB_DEVICE_CONFIG_KHCI > 0U))
  527. /*!
  528. * @brief Device KHCI ISR function.
  529. *
  530. * The function is the KHCI interrupt service routine.
  531. *
  532. * @param[in] deviceHandle The device handle got from #USB_DeviceInit.
  533. */
  534. extern void USB_DeviceKhciIsrFunction(void *deviceHandle);
  535. #if (defined(USB_DEVICE_CHARGER_DETECT_ENABLE) && (USB_DEVICE_CHARGER_DETECT_ENABLE > 0U))
  536. /*!
  537. * @brief Device KHCI DCD ISR function.
  538. *
  539. * The function is the KHCI DCD interrupt service routine.
  540. *
  541. * @param[in] deviceHandle The device handle got from #USB_DeviceInit.
  542. */
  543. extern void USB_DeviceDcdIsrFunction(void *deviceHandle);
  544. #endif
  545. #endif
  546. #if ((defined(USB_DEVICE_CONFIG_EHCI)) && (USB_DEVICE_CONFIG_EHCI > 0U))
  547. /*!
  548. * @brief Device EHCI ISR function.
  549. *
  550. * The function is the EHCI interrupt service routine.
  551. *
  552. * @param[in] deviceHandle The device handle got from #USB_DeviceInit.
  553. */
  554. extern void USB_DeviceEhciIsrFunction(void *deviceHandle);
  555. #endif
  556. #if (((defined(USB_DEVICE_CONFIG_LPCIP3511FS)) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)) || \
  557. ((defined(USB_DEVICE_CONFIG_LPCIP3511HS)) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U)))
  558. /*!
  559. * @brief Device LPC USB ISR function.
  560. *
  561. * The function is the LPC USB interrupt service routine.
  562. *
  563. * @param[in] deviceHandle The device handle got from #USB_DeviceInit.
  564. */
  565. extern void USB_DeviceLpcIp3511IsrFunction(void *deviceHandle);
  566. #endif
  567. /*!
  568. * @brief Gets the device stack version function.
  569. *
  570. * The function is used to get the device stack version.
  571. *
  572. * @param[out] version The version structure pointer to keep the device stack version.
  573. *
  574. */
  575. extern void USB_DeviceGetVersion(uint32_t *version);
  576. #if ((defined(USB_DEVICE_CONFIG_REMOTE_WAKEUP)) && (USB_DEVICE_CONFIG_REMOTE_WAKEUP > 0U))
  577. /*!
  578. * @brief Update the hardware tick.
  579. *
  580. * The function is used to update the hardware tick.
  581. *
  582. * @param[in] handle The device handle got from #USB_DeviceInit.
  583. * @param[in] tick Current hardware tick(uint is ms).
  584. *
  585. */
  586. extern usb_status_t USB_DeviceUpdateHwTick(usb_device_handle handle, uint64_t tick);
  587. #endif
  588. /*! @}*/
  589. #if defined(__cplusplus)
  590. }
  591. #endif /* __cplusplus*/
  592. /*! @}*/
  593. #endif /* __USB_DEVICE_H__ */