usb.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (c) 2015, 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_H__
  31. #define __USB_H__
  32. #include <stdint.h>
  33. #include <stdio.h>
  34. #include <fsl_common.h>
  35. #include <fsl_os_abstraction.h>
  36. #include "usb_misc.h"
  37. #include "usb_spec.h"
  38. /*!
  39. * @addtogroup usb_drv
  40. * @{
  41. */
  42. /*******************************************************************************
  43. * Definitions
  44. ******************************************************************************/
  45. /*! @brief Defines USB stack major version */
  46. #define USB_STACK_VERSION_MAJOR (1U)
  47. /*! @brief Defines USB stack minor version */
  48. #define USB_STACK_VERSION_MINOR (6U)
  49. /*! @brief Defines USB stack bugfix version */
  50. #define USB_STACK_VERSION_BUGFIX (3U)
  51. /*! @brief USB stack version definition */
  52. #define USB_MAKE_VERSION(major, minor, bugfix) (((major) << 16) | ((minor) << 8) | (bugfix))
  53. /*! @brief USB stack component version definition, changed with component in yaml together */
  54. #define USB_STACK_COMPONENT_VERSION \
  55. MAKE_VERSION(USB_STACK_VERSION_MAJOR, USB_STACK_VERSION_MINOR, USB_STACK_VERSION_BUGFIX)
  56. /*
  57. * Component ID used by tools
  58. *
  59. * FSL_COMPONENT_ID "middleware.usb.stack_common"
  60. */
  61. /*! @brief USB error code */
  62. typedef enum _usb_status
  63. {
  64. kStatus_USB_Success = 0x00U, /*!< Success */
  65. kStatus_USB_Error, /*!< Failed */
  66. kStatus_USB_Busy, /*!< Busy */
  67. kStatus_USB_InvalidHandle, /*!< Invalid handle */
  68. kStatus_USB_InvalidParameter, /*!< Invalid parameter */
  69. kStatus_USB_InvalidRequest, /*!< Invalid request */
  70. kStatus_USB_ControllerNotFound, /*!< Controller cannot be found */
  71. kStatus_USB_InvalidControllerInterface, /*!< Invalid controller interface */
  72. kStatus_USB_NotSupported, /*!< Configuration is not supported */
  73. kStatus_USB_Retry, /*!< Enumeration get configuration retry */
  74. kStatus_USB_TransferStall, /*!< Transfer stalled */
  75. kStatus_USB_TransferFailed, /*!< Transfer failed */
  76. kStatus_USB_AllocFail, /*!< Allocation failed */
  77. kStatus_USB_LackSwapBuffer, /*!< Insufficient swap buffer for KHCI */
  78. kStatus_USB_TransferCancel, /*!< The transfer cancelled */
  79. kStatus_USB_BandwidthFail, /*!< Allocate bandwidth failed */
  80. kStatus_USB_MSDStatusFail, /*!< For MSD, the CSW status means fail */
  81. kStatus_USB_EHCIAttached,
  82. kStatus_USB_EHCIDetached,
  83. kStatus_USB_DataOverRun, /*!< The amount of data returned by the endpoint exceeded
  84. either the size of the maximum data packet allowed
  85. from the endpoint or the remaining buffer size. */
  86. } usb_status_t;
  87. /*! @brief USB host handle type define */
  88. typedef void *usb_host_handle;
  89. /*! @brief USB device handle type define. For device stack it is the whole device handle; for host stack it is the
  90. * attached device instance handle*/
  91. typedef void *usb_device_handle;
  92. /*! @brief USB OTG handle type define */
  93. typedef void *usb_otg_handle;
  94. /*! @brief USB controller ID */
  95. typedef enum _usb_controller_index
  96. {
  97. kUSB_ControllerKhci0 = 0U, /*!< KHCI 0U */
  98. kUSB_ControllerKhci1 = 1U, /*!< KHCI 1U, Currently, there are no platforms which have two KHCI IPs, this is reserved
  99. to be used in the future. */
  100. kUSB_ControllerEhci0 = 2U, /*!< EHCI 0U */
  101. kUSB_ControllerEhci1 = 3U, /*!< EHCI 1U, Currently, there are no platforms which have two EHCI IPs, this is reserved
  102. to be used in the future. */
  103. kUSB_ControllerLpcIp3511Fs0 = 4U, /*!< LPC USB IP3511 FS controller 0 */
  104. kUSB_ControllerLpcIp3511Fs1 = 5U, /*!< LPC USB IP3511 FS controller 1, there are no platforms which have two IP3511
  105. IPs, this is reserved to be used in the future. */
  106. kUSB_ControllerLpcIp3511Hs0 = 6U, /*!< LPC USB IP3511 HS controller 0 */
  107. kUSB_ControllerLpcIp3511Hs1 = 7U, /*!< LPC USB IP3511 HS controller 1, there are no platforms which have two IP3511
  108. IPs, this is reserved to be used in the future. */
  109. kUSB_ControllerOhci0 = 8U, /*!< OHCI 0U */
  110. kUSB_ControllerOhci1 = 9U, /*!< OHCI 1U, Currently, there are no platforms which have two OHCI IPs, this is reserved
  111. to be used in the future. */
  112. kUSB_ControllerIp3516Hs0 = 10U, /*!< IP3516HS 0U */
  113. kUSB_ControllerIp3516Hs1 = 11U, /*!< IP3516HS 1U, Currently, there are no platforms which have two IP3516HS IPs,
  114. this is reserved to be used in the future. */
  115. kUSB_ControllerDwc30 = 12U, /*!< DWC3 0U */
  116. kUSB_ControllerDwc31 = 13U, /*!< DWC3 1U Currently, there are no platforms which have two Dwc IPs, this is reserved
  117. to be used in the future.*/
  118. } usb_controller_index_t;
  119. /**
  120. * @brief USB stack version fields
  121. */
  122. typedef struct _usb_version
  123. {
  124. uint8_t major; /*!< Major */
  125. uint8_t minor; /*!< Minor */
  126. uint8_t bugfix; /*!< Bug fix */
  127. } usb_version_t;
  128. /*******************************************************************************
  129. * API
  130. ******************************************************************************/
  131. /*! @} */
  132. #endif /* __USB_H__ */