usb_device_dci.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 __USB_DEVICE_DCI_H__
  31. #define __USB_DEVICE_DCI_H__
  32. /*!
  33. * @addtogroup usb_device_controller_driver
  34. * @{
  35. */
  36. /*******************************************************************************
  37. * Definitions
  38. ******************************************************************************/
  39. /*! @brief Macro to define controller handle */
  40. #define usb_device_controller_handle usb_device_handle
  41. /*! @brief Available notify types for device notification */
  42. typedef enum _usb_device_notification
  43. {
  44. kUSB_DeviceNotifyBusReset = 0x10U, /*!< Reset signal detected */
  45. kUSB_DeviceNotifySuspend, /*!< Suspend signal detected */
  46. kUSB_DeviceNotifyResume, /*!< Resume signal detected */
  47. kUSB_DeviceNotifyLPMSleep, /*!< LPM signal detected */
  48. kUSB_DeviceNotifyLPMResume, /*!< Resume signal detected */
  49. kUSB_DeviceNotifyError, /*!< Errors happened in bus */
  50. kUSB_DeviceNotifyDetach, /*!< Device disconnected from a host */
  51. kUSB_DeviceNotifyAttach, /*!< Device connected to a host */
  52. #if (defined(USB_DEVICE_CHARGER_DETECT_ENABLE) && (USB_DEVICE_CHARGER_DETECT_ENABLE > 0U))
  53. kUSB_DeviceNotifyDcdTimeOut, /*!< Device charger detection timeout */
  54. kUSB_DeviceNotifyDcdUnknownPortType, /*!< Device charger detection unknown port type */
  55. kUSB_DeviceNotifySDPDetected, /*!< The SDP facility is detected */
  56. kUSB_DeviceNotifyChargingPortDetected, /*!< The charging port is detected */
  57. kUSB_DeviceNotifyChargingHostDetected, /*!< The CDP facility is detected */
  58. kUSB_DeviceNotifyDedicatedChargerDetected, /*!< The DCP facility is detected */
  59. #endif
  60. } usb_device_notification_t;
  61. /*! @brief Device notification message structure */
  62. typedef struct _usb_device_callback_message_struct
  63. {
  64. uint8_t *buffer; /*!< Transferred buffer */
  65. uint32_t length; /*!< Transferred data length */
  66. uint8_t code; /*!< Notification code */
  67. uint8_t isSetup; /*!< Is in a setup phase */
  68. } usb_device_callback_message_struct_t;
  69. /*! @brief Control type for controller */
  70. typedef enum _usb_device_control_type
  71. {
  72. kUSB_DeviceControlRun = 0U, /*!< Enable the device functionality */
  73. kUSB_DeviceControlStop, /*!< Disable the device functionality */
  74. kUSB_DeviceControlEndpointInit, /*!< Initialize a specified endpoint */
  75. kUSB_DeviceControlEndpointDeinit, /*!< De-initialize a specified endpoint */
  76. kUSB_DeviceControlEndpointStall, /*!< Stall a specified endpoint */
  77. kUSB_DeviceControlEndpointUnstall, /*!< Unstall a specified endpoint */
  78. kUSB_DeviceControlGetDeviceStatus, /*!< Get device status */
  79. kUSB_DeviceControlGetEndpointStatus, /*!< Get endpoint status */
  80. kUSB_DeviceControlSetDeviceAddress, /*!< Set device address */
  81. kUSB_DeviceControlGetSynchFrame, /*!< Get current frame */
  82. kUSB_DeviceControlResume, /*!< Drive controller to generate a resume signal in USB bus */
  83. kUSB_DeviceControlSleepResume, /*!< Drive controller to generate a LPM resume signal in USB bus */
  84. kUSB_DeviceControlSuspend, /*!< Drive controller to enetr into suspend mode */
  85. kUSB_DeviceControlSleep, /*!< Drive controller to enetr into sleep mode */
  86. kUSB_DeviceControlSetDefaultStatus, /*!< Set controller to default status */
  87. kUSB_DeviceControlGetSpeed, /*!< Get current speed */
  88. kUSB_DeviceControlGetOtgStatus, /*!< Get OTG status */
  89. kUSB_DeviceControlSetOtgStatus, /*!< Set OTG status */
  90. kUSB_DeviceControlSetTestMode, /*!< Drive xCHI into test mode */
  91. kUSB_DeviceControlGetRemoteWakeUp, /*!< Get flag of LPM Remote Wake-up Enabled by USB host. */
  92. #if (defined(USB_DEVICE_CHARGER_DETECT_ENABLE) && (USB_DEVICE_CHARGER_DETECT_ENABLE > 0U))
  93. kUSB_DeviceControlDcdInitModule,
  94. kUSB_DeviceControlDcdDeinitModule,
  95. #endif
  96. } usb_device_control_type_t;
  97. /*! @brief USB device controller initialization function typedef */
  98. typedef usb_status_t (*usb_device_controller_init_t)(uint8_t controllerId,
  99. usb_device_handle handle,
  100. usb_device_controller_handle *controllerHandle);
  101. /*! @brief USB device controller de-initialization function typedef */
  102. typedef usb_status_t (*usb_device_controller_deinit_t)(usb_device_controller_handle controllerHandle);
  103. /*! @brief USB device controller send data function typedef */
  104. typedef usb_status_t (*usb_device_controller_send_t)(usb_device_controller_handle controllerHandle,
  105. uint8_t endpointAddress,
  106. uint8_t *buffer,
  107. uint32_t length);
  108. /*! @brief USB device controller receive data function typedef */
  109. typedef usb_status_t (*usb_device_controller_recv_t)(usb_device_controller_handle controllerHandle,
  110. uint8_t endpointAddress,
  111. uint8_t *buffer,
  112. uint32_t length);
  113. /*! @brief USB device controller cancel transfer function in a specified endpoint typedef */
  114. typedef usb_status_t (*usb_device_controller_cancel_t)(usb_device_controller_handle controllerHandle,
  115. uint8_t endpointAddress);
  116. /*! @brief USB device controller control function typedef */
  117. typedef usb_status_t (*usb_device_controller_control_t)(usb_device_controller_handle controllerHandle,
  118. usb_device_control_type_t command,
  119. void *param);
  120. /*! @brief USB device controller interface structure */
  121. typedef struct _usb_device_controller_interface_struct
  122. {
  123. usb_device_controller_init_t deviceInit; /*!< Controller initialization */
  124. usb_device_controller_deinit_t deviceDeinit; /*!< Controller de-initialization */
  125. usb_device_controller_send_t deviceSend; /*!< Controller send data */
  126. usb_device_controller_recv_t deviceRecv; /*!< Controller receive data */
  127. usb_device_controller_cancel_t deviceCancel; /*!< Controller cancel transfer */
  128. usb_device_controller_control_t deviceControl; /*!< Controller control */
  129. } usb_device_controller_interface_struct_t;
  130. /*! @brief USB device status structure */
  131. typedef struct _usb_device_struct
  132. {
  133. #if ((defined(USB_DEVICE_CONFIG_REMOTE_WAKEUP)) && (USB_DEVICE_CONFIG_REMOTE_WAKEUP > 0U))
  134. volatile uint64_t hwTick; /*!< Current hw tick(ms)*/
  135. #endif
  136. usb_device_controller_handle controllerHandle; /*!< Controller handle */
  137. const usb_device_controller_interface_struct_t *controllerInterface; /*!< Controller interface handle */
  138. #if USB_DEVICE_CONFIG_USE_TASK
  139. usb_osa_msgq_handle notificationQueue; /*!< Message queue */
  140. #endif
  141. usb_device_callback_t deviceCallback; /*!< Device callback function pointer */
  142. usb_device_endpoint_callback_struct_t
  143. epCallback[USB_DEVICE_CONFIG_ENDPOINTS << 1U]; /*!< Endpoint callback function structure */
  144. uint8_t deviceAddress; /*!< Current device address */
  145. uint8_t controllerId; /*!< Controller ID */
  146. uint8_t state; /*!< Current device state */
  147. #if ((defined(USB_DEVICE_CONFIG_REMOTE_WAKEUP)) && (USB_DEVICE_CONFIG_REMOTE_WAKEUP > 0U))
  148. uint8_t remotewakeup; /*!< Remote wakeup is enabled or not */
  149. #endif
  150. uint8_t isResetting; /*!< Is doing device reset or not */
  151. #if (defined(USB_DEVICE_CONFIG_USE_TASK) && (USB_DEVICE_CONFIG_USE_TASK > 0U))
  152. uint8_t epCallbackDirectly; /*!< Whether call ep callback directly when the task is enabled */
  153. #endif
  154. } usb_device_struct_t;
  155. /*******************************************************************************
  156. * API
  157. ******************************************************************************/
  158. /*! @}*/
  159. #endif /* __USB_DEVICE_DCI_H__ */