nu_otg.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /**************************************************************************//**
  2. * @file nu_otg.h
  3. * @version V0.10
  4. * @brief M480 Series OTG Driver Header File
  5. *
  6. * SPDX-License-Identifier: Apache-2.0
  7. * @copyright (C) 2016-2020 Nuvoton Technology Corp. All rights reserved.
  8. ******************************************************************************/
  9. #ifndef __NU_OTG_H__
  10. #define __NU_OTG_H__
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif
  15. /** @addtogroup Standard_Driver Standard Driver
  16. @{
  17. */
  18. /** @addtogroup OTG_Driver OTG Driver
  19. @{
  20. */
  21. /** @addtogroup OTG_EXPORTED_CONSTANTS OTG Exported Constants
  22. @{
  23. */
  24. /*---------------------------------------------------------------------------------------------------------*/
  25. /* OTG constant definitions */
  26. /*---------------------------------------------------------------------------------------------------------*/
  27. #define OTG_VBUS_EN_ACTIVE_HIGH (0UL) /*!< USB VBUS power switch enable signal is active high. \hideinitializer */
  28. #define OTG_VBUS_EN_ACTIVE_LOW (1UL) /*!< USB VBUS power switch enable signal is active low. \hideinitializer */
  29. #define OTG_VBUS_ST_VALID_HIGH (0UL) /*!< USB VBUS power switch valid status is high. \hideinitializer */
  30. #define OTG_VBUS_ST_VALID_LOW (1UL) /*!< USB VBUS power switch valid status is low. \hideinitializer */
  31. /*@}*/ /* end of group OTG_EXPORTED_CONSTANTS */
  32. /** @addtogroup OTG_EXPORTED_FUNCTIONS OTG Exported Functions
  33. @{
  34. */
  35. /*---------------------------------------------------------------------------------------------------------*/
  36. /* Define Macros and functions */
  37. /*---------------------------------------------------------------------------------------------------------*/
  38. /**
  39. * @brief This macro is used to enable OTG function
  40. * @param None
  41. * @return None
  42. * @details This macro will set OTGEN bit of OTG_CTL register to enable OTG function.
  43. * \hideinitializer
  44. */
  45. #define OTG_ENABLE() (OTG->CTL |= OTG_CTL_OTGEN_Msk)
  46. /**
  47. * @brief This macro is used to disable OTG function
  48. * @param None
  49. * @return None
  50. * @details This macro will clear OTGEN bit of OTG_CTL register to disable OTG function.
  51. * \hideinitializer
  52. */
  53. #define OTG_DISABLE() (OTG->CTL &= ~OTG_CTL_OTGEN_Msk)
  54. /**
  55. * @brief This macro is used to enable USB PHY
  56. * @param None
  57. * @return None
  58. * @details When the USB role is selected as OTG device, use this macro to enable USB PHY.
  59. * This macro will set OTGPHYEN bit of OTG_PHYCTL register to enable USB PHY.
  60. * \hideinitializer
  61. */
  62. #define OTG_ENABLE_PHY() (OTG->PHYCTL |= OTG_PHYCTL_OTGPHYEN_Msk)
  63. /**
  64. * @brief This macro is used to disable USB PHY
  65. * @param None
  66. * @return None
  67. * @details This macro will clear OTGPHYEN bit of OTG_PHYCTL register to disable USB PHY.
  68. * \hideinitializer
  69. */
  70. #define OTG_DISABLE_PHY() (OTG->PHYCTL &= ~OTG_PHYCTL_OTGPHYEN_Msk)
  71. /**
  72. * @brief This macro is used to enable ID detection function
  73. * @param None
  74. * @return None
  75. * @details This macro will set IDDETEN bit of OTG_PHYCTL register to enable ID detection function.
  76. * \hideinitializer
  77. */
  78. #define OTG_ENABLE_ID_DETECT() (OTG->PHYCTL |= OTG_PHYCTL_IDDETEN_Msk)
  79. /**
  80. * @brief This macro is used to disable ID detection function
  81. * @param None
  82. * @return None
  83. * @details This macro will clear IDDETEN bit of OTG_PHYCTL register to disable ID detection function.
  84. * \hideinitializer
  85. */
  86. #define OTG_DISABLE_ID_DETECT() (OTG->PHYCTL &= ~OTG_PHYCTL_IDDETEN_Msk)
  87. /**
  88. * @brief This macro is used to enable OTG wake-up function
  89. * @param None
  90. * @return None
  91. * @details This macro will set WKEN bit of OTG_CTL register to enable OTG wake-up function.
  92. * \hideinitializer
  93. */
  94. #define OTG_ENABLE_WAKEUP() (OTG->CTL |= OTG_CTL_WKEN_Msk)
  95. /**
  96. * @brief This macro is used to disable OTG wake-up function
  97. * @param None
  98. * @return None
  99. * @details This macro will clear WKEN bit of OTG_CTL register to disable OTG wake-up function.
  100. * \hideinitializer
  101. */
  102. #define OTG_DISABLE_WAKEUP() (OTG->CTL &= ~OTG_CTL_WKEN_Msk)
  103. /**
  104. * @brief This macro is used to set the polarity of USB_VBUS_EN pin
  105. * @param[in] u32Pol The polarity selection. Valid values are listed below.
  106. * - \ref OTG_VBUS_EN_ACTIVE_HIGH
  107. * - \ref OTG_VBUS_EN_ACTIVE_LOW
  108. * @return None
  109. * @details This macro is used to set the polarity of external USB VBUS power switch enable signal.
  110. * \hideinitializer
  111. */
  112. #define OTG_SET_VBUS_EN_POL(u32Pol) (OTG->PHYCTL = (OTG->PHYCTL & (~OTG_PHYCTL_VBENPOL_Msk)) | ((u32Pol)<<OTG_PHYCTL_VBENPOL_Pos))
  113. /**
  114. * @brief This macro is used to set the polarity of USB_VBUS_ST pin
  115. * @param[in] u32Pol The polarity selection. Valid values are listed below.
  116. * - \ref OTG_VBUS_ST_VALID_HIGH
  117. * - \ref OTG_VBUS_ST_VALID_LOW
  118. * @return None
  119. * @details This macro is used to set the polarity of external USB VBUS power switch status signal.
  120. * \hideinitializer
  121. */
  122. #define OTG_SET_VBUS_STS_POL(u32Pol) (OTG->PHYCTL = (OTG->PHYCTL & (~OTG_PHYCTL_VBSTSPOL_Msk)) | ((u32Pol)<<OTG_PHYCTL_VBSTSPOL_Pos))
  123. /**
  124. * @brief This macro is used to enable OTG related interrupts
  125. * @param[in] u32Mask The combination of interrupt source. Each bit corresponds to a interrupt source. Valid values are listed below.
  126. * - \ref OTG_INTEN_ROLECHGIEN_Msk
  127. * - \ref OTG_INTEN_VBEIEN_Msk
  128. * - \ref OTG_INTEN_SRPFIEN_Msk
  129. * - \ref OTG_INTEN_HNPFIEN_Msk
  130. * - \ref OTG_INTEN_GOIDLEIEN_Msk
  131. * - \ref OTG_INTEN_IDCHGIEN_Msk
  132. * - \ref OTG_INTEN_PDEVIEN_Msk
  133. * - \ref OTG_INTEN_HOSTIEN_Msk
  134. * - \ref OTG_INTEN_BVLDCHGIEN_Msk
  135. * - \ref OTG_INTEN_AVLDCHGIEN_Msk
  136. * - \ref OTG_INTEN_VBCHGIEN_Msk
  137. * - \ref OTG_INTEN_SECHGIEN_Msk
  138. * - \ref OTG_INTEN_SRPDETIEN_Msk
  139. * @return None
  140. * @details This macro will enable OTG related interrupts specified by u32Mask parameter.
  141. * \hideinitializer
  142. */
  143. #define OTG_ENABLE_INT(u32Mask) (OTG->INTEN |= (u32Mask))
  144. /**
  145. * @brief This macro is used to disable OTG related interrupts
  146. * @param[in] u32Mask The combination of interrupt source. Each bit corresponds to a interrupt source. Valid values are listed below.
  147. * - \ref OTG_INTEN_ROLECHGIEN_Msk
  148. * - \ref OTG_INTEN_VBEIEN_Msk
  149. * - \ref OTG_INTEN_SRPFIEN_Msk
  150. * - \ref OTG_INTEN_HNPFIEN_Msk
  151. * - \ref OTG_INTEN_GOIDLEIEN_Msk
  152. * - \ref OTG_INTEN_IDCHGIEN_Msk
  153. * - \ref OTG_INTEN_PDEVIEN_Msk
  154. * - \ref OTG_INTEN_HOSTIEN_Msk
  155. * - \ref OTG_INTEN_BVLDCHGIEN_Msk
  156. * - \ref OTG_INTEN_AVLDCHGIEN_Msk
  157. * - \ref OTG_INTEN_VBCHGIEN_Msk
  158. * - \ref OTG_INTEN_SECHGIEN_Msk
  159. * - \ref OTG_INTEN_SRPDETIEN_Msk
  160. * @return None
  161. * @details This macro will disable OTG related interrupts specified by u32Mask parameter.
  162. * \hideinitializer
  163. */
  164. #define OTG_DISABLE_INT(u32Mask) (OTG->INTEN &= ~(u32Mask))
  165. /**
  166. * @brief This macro is used to get OTG related interrupt flags
  167. * @param[in] u32Mask The combination of interrupt source. Each bit corresponds to a interrupt source. Valid values are listed below.
  168. * - \ref OTG_INTSTS_ROLECHGIF_Msk
  169. * - \ref OTG_INTSTS_VBEIF_Msk
  170. * - \ref OTG_INTSTS_SRPFIF_Msk
  171. * - \ref OTG_INTSTS_HNPFIF_Msk
  172. * - \ref OTG_INTSTS_GOIDLEIF_Msk
  173. * - \ref OTG_INTSTS_IDCHGIF_Msk
  174. * - \ref OTG_INTSTS_PDEVIF_Msk
  175. * - \ref OTG_INTSTS_HOSTIF_Msk
  176. * - \ref OTG_INTSTS_BVLDCHGIF_Msk
  177. * - \ref OTG_INTSTS_AVLDCHGIF_Msk
  178. * - \ref OTG_INTSTS_VBCHGIF_Msk
  179. * - \ref OTG_INTSTS_SECHGIF_Msk
  180. * - \ref OTG_INTSTS_SRPDETIF_Msk
  181. * @return Interrupt flags of selected sources.
  182. * @details This macro will return OTG related interrupt flags specified by u32Mask parameter.
  183. * \hideinitializer
  184. */
  185. #define OTG_GET_INT_FLAG(u32Mask) (OTG->INTSTS & (u32Mask))
  186. /**
  187. * @brief This macro is used to clear OTG related interrupt flags
  188. * @param[in] u32Mask The combination of interrupt source. Each bit corresponds to a interrupt source. Valid values are listed below.
  189. * - \ref OTG_INTSTS_ROLECHGIF_Msk
  190. * - \ref OTG_INTSTS_VBEIF_Msk
  191. * - \ref OTG_INTSTS_SRPFIF_Msk
  192. * - \ref OTG_INTSTS_HNPFIF_Msk
  193. * - \ref OTG_INTSTS_GOIDLEIF_Msk
  194. * - \ref OTG_INTSTS_IDCHGIF_Msk
  195. * - \ref OTG_INTSTS_PDEVIF_Msk
  196. * - \ref OTG_INTSTS_HOSTIF_Msk
  197. * - \ref OTG_INTSTS_BVLDCHGIF_Msk
  198. * - \ref OTG_INTSTS_AVLDCHGIF_Msk
  199. * - \ref OTG_INTSTS_VBCHGIF_Msk
  200. * - \ref OTG_INTSTS_SECHGIF_Msk
  201. * - \ref OTG_INTSTS_SRPDETIF_Msk
  202. * @return None
  203. * @details This macro will clear OTG related interrupt flags specified by u32Mask parameter.
  204. * \hideinitializer
  205. */
  206. #define OTG_CLR_INT_FLAG(u32Mask) (OTG->INTSTS = (u32Mask))
  207. /**
  208. * @brief This macro is used to get OTG related status
  209. * @param[in] u32Mask The combination of user specified source. Valid values are listed below.
  210. * - \ref OTG_STATUS_OVERCUR_Msk
  211. * - \ref OTG_STATUS_IDSTS_Msk
  212. * - \ref OTG_STATUS_SESSEND_Msk
  213. * - \ref OTG_STATUS_BVLD_Msk
  214. * - \ref OTG_STATUS_AVLD_Msk
  215. * - \ref OTG_STATUS_VBUSVLD_Msk
  216. * @return The user specified status.
  217. * @details This macro will return OTG related status specified by u32Mask parameter.
  218. * \hideinitializer
  219. */
  220. #define OTG_GET_STATUS(u32Mask) (OTG->STATUS & (u32Mask))
  221. /*@}*/ /* end of group OTG_EXPORTED_FUNCTIONS */
  222. /*@}*/ /* end of group OTG_Driver */
  223. /*@}*/ /* end of group Standard_Driver */
  224. #ifdef __cplusplus
  225. }
  226. #endif
  227. #endif /*__NU_OTG_H__ */
  228. /*** (C) COPYRIGHT 2017 Nuvoton Technology Corp. ***/