usb_host_devices.h 6.8 KB

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