usb_host_devices.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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_HOST_DEV_MNG_H_
  31. #define _USB_HOST_DEV_MNG_H_
  32. #include "usb_host.h"
  33. /*******************************************************************************
  34. * Definitions
  35. ******************************************************************************/
  36. /*!
  37. * @addtogroup usb_host_drv
  38. * @{
  39. */
  40. /*! @brief States of device instances enumeration */
  41. typedef enum _usb_host_device_enumeration_status
  42. {
  43. kStatus_DEV_Notinit = 0, /*!< Device is invalid */
  44. kStatus_DEV_Initial, /*!< Device has been processed by host driver */
  45. kStatus_DEV_GetDes8, /*!< Enumeration process: get 8 bytes' device descriptor */
  46. kStatus_DEV_SetAddress, /*!< Enumeration process: set device address */
  47. kStatus_DEV_GetDes, /*!< Enumeration process: get device descriptor */
  48. kStatus_DEV_GetCfg9, /*!< Enumeration process: get 9 bytes' configuration descriptor */
  49. kStatus_DEV_GetCfg, /*!< Enumeration process: get configuration descriptor */
  50. kStatus_DEV_SetCfg, /*!< Enumeration process: set configuration */
  51. kStatus_DEV_EnumDone, /*!< Enumeration is done */
  52. kStatus_DEV_AppUsed, /*!< This device has been used by application */
  53. } usb_host_device_enumeration_status_t;
  54. /*! @brief States of device's interface */
  55. typedef enum _usb_host_interface_state
  56. {
  57. kStatus_interface_Attached = 1, /*!< Interface's default status */
  58. kStatus_interface_Opened, /*!< Interface is used by application */
  59. kStatus_interface_Detached, /*!< Interface is not used by application */
  60. } usb_host_interface_state_t;
  61. /*! @brief States of device */
  62. typedef enum _usb_host_device_state
  63. {
  64. kStatus_device_Detached = 0, /*!< Device is used by application */
  65. kStatus_device_Attached, /*!< Device's default status */
  66. } usb_host_device_state_t;
  67. /*! @brief Device instance */
  68. typedef struct _usb_host_device_instance
  69. {
  70. struct _usb_host_device_instance *next; /*!< Next device, or NULL */
  71. usb_host_handle hostHandle; /*!< Host handle */
  72. usb_host_configuration_t configuration; /*!< Parsed configuration information for the device */
  73. usb_descriptor_device_t *deviceDescriptor; /*!< Standard device descriptor */
  74. usb_host_pipe_handle controlPipe; /*!< Device's control pipe */
  75. uint8_t *configurationDesc; /*!< Configuration descriptor pointer */
  76. uint16_t configurationLen; /*!< Configuration descriptor length */
  77. uint16_t configurationValue; /*!< Configuration index */
  78. uint8_t interfaceStatus[USB_HOST_CONFIG_CONFIGURATION_MAX_INTERFACE]; /*!< Interfaces' status, please reference to
  79. #usb_host_interface_state_t */
  80. uint8_t *enumBuffer; /*!< Buffer for enumeration */
  81. uint8_t state; /*!< Device state for enumeration */
  82. uint8_t enumRetries; /*!< Re-enumeration when error in control transfer */
  83. uint8_t stallRetries; /*!< Re-transfer when stall */
  84. uint8_t speed; /*!< Device speed */
  85. uint8_t allocatedAddress; /*!< Temporary address for the device. When set address request succeeds, setAddress is
  86. a value, 1 - 127 */
  87. uint8_t setAddress; /*!< The address has been set to the device successfully, 1 - 127 */
  88. uint8_t deviceAttachState; /*!< See the usb_host_device_state_t */
  89. #if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB))
  90. /* hub related */
  91. uint8_t hubNumber; /*!< Device's first connected hub address (root hub = 0) */
  92. uint8_t portNumber; /*!< Device's first connected hub's port no (1 - 8) */
  93. uint8_t hsHubNumber; /*!< Device's first connected high-speed hub's address (1 - 8) */
  94. uint8_t hsHubPort; /*!< Device's first connected high-speed hub's port no (1 - 8) */
  95. uint8_t level; /*!< Device's level (root device = 0) */
  96. #endif
  97. } usb_host_device_instance_t;
  98. typedef struct _usb_host_enum_process_entry
  99. {
  100. uint8_t successState; /*!< When the last step is successful, the next state value */
  101. uint8_t retryState; /*!< When the last step need retry, the next state value */
  102. usb_status_t (*process)(usb_host_device_instance_t *deviceInstance); /*!< When the last step transfer is done, the
  103. function is used to process the transfer
  104. data */
  105. } usb_host_enum_process_entry_t;
  106. /*******************************************************************************
  107. * API
  108. ******************************************************************************/
  109. /*!
  110. * @brief Calls this function when device attach.
  111. *
  112. * @param hostHandle Host instance handle.
  113. * @param speed Device speed.
  114. * @param hubNumber Device hub no. root device's hub no. is 0.
  115. * @param portNumber Device port no. root device's port no. is 0.
  116. * @param level Device level. root device's level is 1.
  117. * @param deviceHandle Return device handle.
  118. *
  119. * @return kStatus_USB_Success or error codes.
  120. */
  121. extern usb_status_t USB_HostAttachDevice(usb_host_handle hostHandle,
  122. uint8_t speed,
  123. uint8_t hubNumber,
  124. uint8_t portNumber,
  125. uint8_t level,
  126. usb_device_handle *deviceHandle);
  127. /*!
  128. * @brief Call this function when device detaches.
  129. *
  130. * @param hostHandle Host instance handle.
  131. * @param hubNumber Device hub no. root device's hub no. is 0.
  132. * @param portNumber Device port no. root device's port no. is 0.
  133. *
  134. * @return kStatus_USB_Success or error codes.
  135. */
  136. extern usb_status_t USB_HostDetachDevice(usb_host_handle hostHandle, uint8_t hubNumber, uint8_t portNumber);
  137. /*!
  138. * @brief Call this function when device detaches.
  139. *
  140. * @param hostHandle Host instance handle.
  141. * @param deviceHandle Device handle.
  142. *
  143. * @return kStatus_USB_Success or error codes.
  144. */
  145. extern usb_status_t USB_HostDetachDeviceInternal(usb_host_handle hostHandle, usb_device_handle deviceHandle);
  146. /*!
  147. * @brief Gets the device attach/detach state.
  148. *
  149. * @param deviceHandle Device handle.
  150. *
  151. * @return 0x01 - attached; 0x00 - detached.
  152. */
  153. extern uint8_t USB_HostGetDeviceAttachState(usb_device_handle deviceHandle);
  154. /*!
  155. * @brief Determine whether the device is attached.
  156. *
  157. * @param hostHandle Host instance pointer.
  158. * @param deviceHandle Device handle.
  159. *
  160. * @return kStatus_USB_Success or error codes.
  161. */
  162. extern usb_status_t USB_HostValidateDevice(usb_host_handle hostHandle, usb_device_handle deviceHandle);
  163. /*! @}*/
  164. #endif /* _USB_HOST_DEV_MNG_H_ */