usb_phy.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #include <stdbool.h>
  9. #include "soc/soc_caps.h"
  10. #include "hal/usb_phy_types.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. /**
  15. * @brief USB PHY status
  16. */
  17. typedef enum {
  18. USB_PHY_STATUS_FREE, /**< PHY is not being used */
  19. USB_PHY_STATUS_IN_USE, /**< PHY is in use */
  20. } usb_phy_status_t;
  21. /**
  22. * @brief USB PHY available actions
  23. */
  24. typedef enum {
  25. USB_PHY_ACTION_HOST_ALLOW_CONN, /**< Enable physical connection when operating as an OTG Host */
  26. USB_PHY_ACTION_HOST_FORCE_DISCONN, /**< Disable physical connection when operating as an OTG Host */
  27. USB_PHY_ACTION_MAX,
  28. } usb_phy_action_t;
  29. /**
  30. * @brief USB external PHY iopins configure struct
  31. */
  32. typedef struct {
  33. int vp_io_num; /**< GPIO pin to USB_EXTPHY_VP_IDX */
  34. int vm_io_num; /**< GPIO pin to USB_EXTPHY_VM_IDX */
  35. int rcv_io_num; /**< GPIO pin to USB_EXTPHY_RCV_IDX */
  36. int oen_io_num; /**< GPIO pin to USB_EXTPHY_OEN_IDX */
  37. int vpo_io_num; /**< GPIO pin to USB_EXTPHY_VPO_IDX */
  38. int vmo_io_num; /**< GPIO pin to USB_EXTPHY_VMO_IDX */
  39. } usb_phy_gpio_conf_t;
  40. /**
  41. * @brief USB PHY configure struct
  42. *
  43. * At minimum the PHY controller and PHY target must be initialized.
  44. */
  45. typedef struct {
  46. usb_phy_controller_t controller; /**< USB PHY controller */
  47. usb_phy_target_t target; /**< USB PHY target INT/EXT */
  48. usb_otg_mode_t otg_mode; /**< USB OTG mode */
  49. usb_phy_speed_t otg_speed; /**< USB OTG speed */
  50. usb_phy_gpio_conf_t *gpio_conf; /**< USB external PHY iopins configure */
  51. } usb_phy_config_t;
  52. typedef struct phy_context_t *usb_phy_handle_t; /**< USB PHY context handle */
  53. /**
  54. * @brief Initialize a new USB PHY
  55. * Configure at least PHY source.
  56. *
  57. * @param[in] config USB PHY configurtion struct
  58. * @param[out] handle_ret USB PHY context handle
  59. *
  60. * @return
  61. * - ESP_OK Success
  62. * - ESP_FAIL USB PHY init error.
  63. * - ESP_ERR_INVALID_STATE USB PHY not installed.
  64. * - ESP_ERR_NO_MEM USB_OTG installation failed due to no mem.
  65. */
  66. esp_err_t usb_new_phy(const usb_phy_config_t *config, usb_phy_handle_t *handle_ret);
  67. /**
  68. * @brief Configure OTG mode for a USB PHY
  69. *
  70. * @param handle Pointer of USB PHY context handle
  71. * @param mode USB OTG mode
  72. *
  73. * @return
  74. * - ESP_OK Success
  75. * - ESP_ERR_INVALID_ARG Parameter error.
  76. * - ESP_FAIL OTG set mode fail.
  77. */
  78. esp_err_t usb_phy_otg_set_mode(usb_phy_handle_t handle, usb_otg_mode_t mode);
  79. /**
  80. * @brief Configure USB speed for a USB PHY that is operating as an OTG Device
  81. *
  82. * @param handle Pointer of USB PHY context handle
  83. * @param mode USB speed
  84. *
  85. * @return
  86. * - ESP_OK Success
  87. * - ESP_ERR_INVALID_ARG Parameter error.
  88. * - ESP_FAIL OTG set speed fail.
  89. */
  90. esp_err_t usb_phy_otg_dev_set_speed(usb_phy_handle_t handle, usb_phy_speed_t speed);
  91. /**
  92. * @brief Take a action for a USB PHY
  93. *
  94. * @param handle Pointer of USB PHY context handle
  95. * @param action USB PHY action
  96. *
  97. * @return
  98. * - ESP_OK Success
  99. * - ESP_ERR_INVALID_ARG Parameter error.
  100. * - ESP_FAIL Action cannot be performed.
  101. */
  102. esp_err_t usb_phy_action(usb_phy_handle_t handle, usb_phy_action_t action);
  103. /**
  104. * @brief Delete a USB PHY
  105. *
  106. * @param handle Pointer of USB PHY context handle
  107. *
  108. * @return
  109. * - ESP_OK Success
  110. * - ESP_ERR_INVALID_ARG Parameter error.
  111. */
  112. esp_err_t usb_del_phy(usb_phy_handle_t handle);
  113. /**
  114. * @brief Get status of a USB PHY
  115. *
  116. * @param[in] target The specific PHY target to check
  117. * @param[out] status Status of the PHY
  118. *
  119. * @return
  120. * - ESP_OK Success
  121. * - ESP_ERR_INVALID_ARG Parameter error.
  122. * - ESP_ERR_INVALID_STATE USB PHY not installed.
  123. */
  124. esp_err_t usb_phy_get_phy_status(usb_phy_target_t target, usb_phy_status_t *status);
  125. #ifdef __cplusplus
  126. }
  127. #endif