nu_hsotg.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /**************************************************************************//**
  2. * @file nu_hsotg.h
  3. * @version V3.00
  4. * @brief M460 series HSOTG driver header file
  5. *
  6. * @copyright SPDX-License-Identifier: Apache-2.0
  7. * @copyright Copyright (C) 2021 Nuvoton Technology Corp. All rights reserved.
  8. ****************************************************************************/
  9. #ifndef __NU_HSOTG_H__
  10. #define __NU_HSOTG_H__
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif
  15. /** @addtogroup Standard_Driver Standard Driver
  16. @{
  17. */
  18. /** @addtogroup HSOTG_Driver HSOTG Driver
  19. @{
  20. */
  21. /** @addtogroup HSOTG_EXPORTED_CONSTANTS HSOTG Exported Constants
  22. @{
  23. */
  24. /*---------------------------------------------------------------------------------------------------------*/
  25. /* HSOTG constant definitions */
  26. /*---------------------------------------------------------------------------------------------------------*/
  27. #define HSOTG_VBUS_EN_ACTIVE_HIGH (0UL) /*!< USB VBUS power switch enable signal is active high. \hideinitializer */
  28. #define HSOTG_VBUS_EN_ACTIVE_LOW (1UL) /*!< USB VBUS power switch enable signal is active low. \hideinitializer */
  29. #define HSOTG_VBUS_ST_VALID_HIGH (0UL) /*!< USB VBUS power switch valid status is high. \hideinitializer */
  30. #define HSOTG_VBUS_ST_VALID_LOW (1UL) /*!< USB VBUS power switch valid status is low. \hideinitializer */
  31. #define HSOTG_PHYCTL_FSEL_9_6M (0UL << HSOTG_PHYCTL_FSEL_Pos) /*!< Setting OTG PHY reference clock frequency as 9.6 MHz. \hideinitializer */
  32. #define HSOTG_PHYCTL_FSEL_10_0M (1UL << HSOTG_PHYCTL_FSEL_Pos) /*!< Setting OTG PHY reference clock frequency as 10 MHz. \hideinitializer */
  33. #define HSOTG_PHYCTL_FSEL_12_0M (2UL << HSOTG_PHYCTL_FSEL_Pos) /*!< Setting OTG PHY reference clock frequency as 12 MHz. \hideinitializer */
  34. #define HSOTG_PHYCTL_FSEL_19_2M (3UL << HSOTG_PHYCTL_FSEL_Pos) /*!< Setting OTG PHY reference clock frequency as 19.2 MHz. \hideinitializer */
  35. #define HSOTG_PHYCTL_FSEL_20_0M (4UL << HSOTG_PHYCTL_FSEL_Pos) /*!< Setting OTG PHY reference clock frequency as 20 MHz. \hideinitializer */
  36. #define HSOTG_PHYCTL_FSEL_24_0M (5UL << HSOTG_PHYCTL_FSEL_Pos) /*!< Setting OTG PHY reference clock frequency as 24 MHz. \hideinitializer */
  37. #define HSOTG_PHYCTL_FSEL_50_0M (7UL << HSOTG_PHYCTL_FSEL_Pos) /*!< Setting OTG PHY reference clock frequency as 50 MHz. \hideinitializer */
  38. /*@}*/ /* end of group HSOTG_EXPORTED_CONSTANTS */
  39. /** @addtogroup HSOTG_EXPORTED_FUNCTIONS HSOTG Exported Functions
  40. @{
  41. */
  42. /*---------------------------------------------------------------------------------------------------------*/
  43. /* Define Macros and functions */
  44. /*---------------------------------------------------------------------------------------------------------*/
  45. /**
  46. * @brief This macro is used to enable HSOTG function
  47. * @param None
  48. * @return None
  49. * @details This macro will set OTGEN bit of HSOTG_CTL register to enable HSOTG function.
  50. * \hideinitializer
  51. */
  52. #define HSOTG_ENABLE() (HSOTG->CTL |= HSOTG_CTL_OTGEN_Msk)
  53. /**
  54. * @brief This macro is used to disable HSOTG function
  55. * @param None
  56. * @return None
  57. * @details This macro will clear OTGEN bit of HSOTG_CTL register to disable HSOTG function.
  58. * \hideinitializer
  59. */
  60. #define HSOTG_DISABLE() (HSOTG->CTL &= ~HSOTG_CTL_OTGEN_Msk)
  61. /**
  62. * @brief This macro is used to enable USB PHY
  63. * @param None
  64. * @return None
  65. * @details When the USB role is selected as HSOTG device, use this macro to enable USB PHY.
  66. * This macro will set OTGPHYEN bit of HSOTG_PHYCTL register to enable USB PHY.
  67. * \hideinitializer
  68. */
  69. #define HSOTG_ENABLE_PHY() (HSOTG->PHYCTL |= HSOTG_PHYCTL_OTGPHYEN_Msk)
  70. /**
  71. * @brief This macro is used to disable USB PHY
  72. * @param None
  73. * @return None
  74. * @details This macro will clear OTGPHYEN bit of HSOTG_PHYCTL register to disable USB PHY.
  75. * \hideinitializer
  76. */
  77. #define HSOTG_DISABLE_PHY() (HSOTG->PHYCTL &= ~HSOTG_PHYCTL_OTGPHYEN_Msk)
  78. /**
  79. * @brief This macro is used to enable ID detection function
  80. * @param None
  81. * @return None
  82. * @details This macro will set IDDETEN bit of HSOTG_PHYCTL register to enable ID detection function.
  83. * \hideinitializer
  84. */
  85. #define HSOTG_ENABLE_ID_DETECT() (HSOTG->PHYCTL |= HSOTG_PHYCTL_IDDETEN_Msk)
  86. /**
  87. * @brief This macro is used to disable ID detection function
  88. * @param None
  89. * @return None
  90. * @details This macro will clear IDDETEN bit of HSOTG_PHYCTL register to disable ID detection function.
  91. * \hideinitializer
  92. */
  93. #define HSOTG_DISABLE_ID_DETECT() (HSOTG->PHYCTL &= ~HSOTG_PHYCTL_IDDETEN_Msk)
  94. /**
  95. * @brief This macro is used to enable HSOTG wake-up function
  96. * @param None
  97. * @return None
  98. * @details This macro will set WKEN bit of HSOTG_CTL register to enable HSOTG wake-up function.
  99. * \hideinitializer
  100. */
  101. #define HSOTG_ENABLE_WAKEUP() (HSOTG->CTL |= HSOTG_CTL_WKEN_Msk)
  102. /**
  103. * @brief This macro is used to disable HSOTG wake-up function
  104. * @param None
  105. * @return None
  106. * @details This macro will clear WKEN bit of HSOTG_CTL register to disable HSOTG wake-up function.
  107. * \hideinitializer
  108. */
  109. #define HSOTG_DISABLE_WAKEUP() (HSOTG->CTL &= ~HSOTG_CTL_WKEN_Msk)
  110. /**
  111. * @brief This macro is used to set the polarity of USB_VBUS_EN pin
  112. * @param[in] u32Pol The polarity selection. Valid values are listed below.
  113. * - \ref HSOTG_VBUS_EN_ACTIVE_HIGH
  114. * - \ref HSOTG_VBUS_EN_ACTIVE_LOW
  115. * @return None
  116. * @details This macro is used to set the polarity of external USB VBUS power switch enable signal.
  117. * \hideinitializer
  118. */
  119. #define HSOTG_SET_VBUS_EN_POL(u32Pol) (HSOTG->PHYCTL = (HSOTG->PHYCTL & (~HSOTG_PHYCTL_VBENPOL_Msk)) | ((u32Pol) << HSOTG_PHYCTL_VBENPOL_Pos))
  120. /**
  121. * @brief This macro is used to set the polarity of USB_VBUS_ST pin
  122. * @param[in] u32Pol The polarity selection. Valid values are listed below.
  123. * - \ref HSOTG_VBUS_ST_VALID_HIGH
  124. * - \ref HSOTG_VBUS_ST_VALID_LOW
  125. * @return None
  126. * @details This macro is used to set the polarity of external USB VBUS power switch status signal.
  127. * \hideinitializer
  128. */
  129. #define HSOTG_SET_VBUS_STS_POL(u32Pol) (HSOTG->PHYCTL = (HSOTG->PHYCTL & (~HSOTG_PHYCTL_VBSTSPOL_Msk)) | ((u32Pol) << HSOTG_PHYCTL_VBSTSPOL_Pos))
  130. /**
  131. * @brief This macro is used to enable HSOTG related interrupts
  132. * @param[in] u32Mask The combination of interrupt source. Each bit corresponds to a interrupt source. Valid values are listed below.
  133. * - \ref HSOTG_INTEN_ROLECHGIEN_Msk
  134. * - \ref HSOTG_INTEN_VBEIEN_Msk
  135. * - \ref HSOTG_INTEN_SRPFIEN_Msk
  136. * - \ref HSOTG_INTEN_HNPFIEN_Msk
  137. * - \ref HSOTG_INTEN_GOIDLEIEN_Msk
  138. * - \ref HSOTG_INTEN_IDCHGIEN_Msk
  139. * - \ref HSOTG_INTEN_PDEVIEN_Msk
  140. * - \ref HSOTG_INTEN_HOSTIEN_Msk
  141. * - \ref HSOTG_INTEN_BVLDCHGIEN_Msk
  142. * - \ref HSOTG_INTEN_AVLDCHGIEN_Msk
  143. * - \ref HSOTG_INTEN_VBCHGIEN_Msk
  144. * - \ref HSOTG_INTEN_SECHGIEN_Msk
  145. * - \ref HSOTG_INTEN_SRPDETIEN_Msk
  146. * @return None
  147. * @details This macro will enable HSOTG related interrupts specified by u32Mask parameter.
  148. * \hideinitializer
  149. */
  150. #define HSOTG_ENABLE_INT(u32Mask) (HSOTG->INTEN |= (u32Mask))
  151. /**
  152. * @brief This macro is used to disable HSOTG related interrupts
  153. * @param[in] u32Mask The combination of interrupt source. Each bit corresponds to a interrupt source. Valid values are listed below.
  154. * - \ref HSOTG_INTEN_ROLECHGIEN_Msk
  155. * - \ref HSOTG_INTEN_VBEIEN_Msk
  156. * - \ref HSOTG_INTEN_SRPFIEN_Msk
  157. * - \ref HSOTG_INTEN_HNPFIEN_Msk
  158. * - \ref HSOTG_INTEN_GOIDLEIEN_Msk
  159. * - \ref HSOTG_INTEN_IDCHGIEN_Msk
  160. * - \ref HSOTG_INTEN_PDEVIEN_Msk
  161. * - \ref HSOTG_INTEN_HOSTIEN_Msk
  162. * - \ref HSOTG_INTEN_BVLDCHGIEN_Msk
  163. * - \ref HSOTG_INTEN_AVLDCHGIEN_Msk
  164. * - \ref HSOTG_INTEN_VBCHGIEN_Msk
  165. * - \ref HSOTG_INTEN_SECHGIEN_Msk
  166. * - \ref HSOTG_INTEN_SRPDETIEN_Msk
  167. * @return None
  168. * @details This macro will disable HSOTG related interrupts specified by u32Mask parameter.
  169. * \hideinitializer
  170. */
  171. #define HSOTG_DISABLE_INT(u32Mask) (HSOTG->INTEN &= ~(u32Mask))
  172. /**
  173. * @brief This macro is used to get HSOTG related interrupt flags
  174. * @param[in] u32Mask The combination of interrupt source. Each bit corresponds to a interrupt source. Valid values are listed below.
  175. * - \ref HSOTG_INTSTS_ROLECHGIF_Msk
  176. * - \ref HSOTG_INTSTS_VBEIF_Msk
  177. * - \ref HSOTG_INTSTS_SRPFIF_Msk
  178. * - \ref HSOTG_INTSTS_HNPFIF_Msk
  179. * - \ref HSOTG_INTSTS_GOIDLEIF_Msk
  180. * - \ref HSOTG_INTSTS_IDCHGIF_Msk
  181. * - \ref HSOTG_INTSTS_PDEVIF_Msk
  182. * - \ref HSOTG_INTSTS_HOSTIF_Msk
  183. * - \ref HSOTG_INTSTS_BVLDCHGIF_Msk
  184. * - \ref HSOTG_INTSTS_AVLDCHGIF_Msk
  185. * - \ref HSOTG_INTSTS_VBCHGIF_Msk
  186. * - \ref HSOTG_INTSTS_SECHGIF_Msk
  187. * - \ref HSOTG_INTSTS_SRPDETIF_Msk
  188. * @return Interrupt flags of selected sources.
  189. * @details This macro will return HSOTG related interrupt flags specified by u32Mask parameter.
  190. * \hideinitializer
  191. */
  192. #define HSOTG_GET_INT_FLAG(u32Mask) (HSOTG->INTSTS & (u32Mask))
  193. /**
  194. * @brief This macro is used to clear HSOTG related interrupt flags
  195. * @param[in] u32Mask The combination of interrupt source. Each bit corresponds to a interrupt source. Valid values are listed below.
  196. * - \ref HSOTG_INTSTS_ROLECHGIF_Msk
  197. * - \ref HSOTG_INTSTS_VBEIF_Msk
  198. * - \ref HSOTG_INTSTS_SRPFIF_Msk
  199. * - \ref HSOTG_INTSTS_HNPFIF_Msk
  200. * - \ref HSOTG_INTSTS_GOIDLEIF_Msk
  201. * - \ref HSOTG_INTSTS_IDCHGIF_Msk
  202. * - \ref HSOTG_INTSTS_PDEVIF_Msk
  203. * - \ref HSOTG_INTSTS_HOSTIF_Msk
  204. * - \ref HSOTG_INTSTS_BVLDCHGIF_Msk
  205. * - \ref HSOTG_INTSTS_AVLDCHGIF_Msk
  206. * - \ref HSOTG_INTSTS_VBCHGIF_Msk
  207. * - \ref HSOTG_INTSTS_SECHGIF_Msk
  208. * - \ref HSOTG_INTSTS_SRPDETIF_Msk
  209. * @return None
  210. * @details This macro will clear HSOTG related interrupt flags specified by u32Mask parameter.
  211. * \hideinitializer
  212. */
  213. #define HSOTG_CLR_INT_FLAG(u32Mask) (HSOTG->INTSTS = (u32Mask))
  214. /**
  215. * @brief This macro is used to get HSOTG related status
  216. * @param[in] u32Mask The combination of user specified source. Valid values are listed below.
  217. * - \ref HSOTG_STATUS_OVERCUR_Msk
  218. * - \ref HSOTG_STATUS_IDSTS_Msk
  219. * - \ref HSOTG_STATUS_SESSEND_Msk
  220. * - \ref HSOTG_STATUS_BVLD_Msk
  221. * - \ref HSOTG_STATUS_AVLD_Msk
  222. * - \ref HSOTG_STATUS_VBUSVLD_Msk
  223. * - \ref HSOTG_STATUS_ASPERI_Msk
  224. * - \ref HSOTG_STATUS_ASHOST_Msk
  225. * @return The user specified status.
  226. * @details This macro will return HSOTG related status specified by u32Mask parameter.
  227. * \hideinitializer
  228. */
  229. #define HSOTG_GET_STATUS(u32Mask) (HSOTG->STATUS & (u32Mask))
  230. /**
  231. * @brief Set OTG PHY reference clock frequency
  232. * @param[in] u32RefClock The reference clock selection. Valid values are listed below.
  233. * - \ref HSOTG_PHYCTL_FSEL_9_6M
  234. * - \ref HSOTG_PHYCTL_FSEL_10_0M
  235. * - \ref HSOTG_PHYCTL_FSEL_12_0M
  236. * - \ref HSOTG_PHYCTL_FSEL_19_2M
  237. * - \ref HSOTG_PHYCTL_FSEL_20_0M
  238. * - \ref HSOTG_PHYCTL_FSEL_24_0M
  239. * - \ref HSOTG_PHYCTL_FSEL_50_0M
  240. * @return None
  241. * @details This macro set OTG PHY reference clock frequency.
  242. * \hideinitializer
  243. */
  244. #define HSOTG_SET_PHY_REF_CLK(u32RefClock) (HSOTG->PHYCTL = (HSOTG->PHYCTL & ~HSOTG_PHYCTL_FSEL_Msk) | (u32RefClock))
  245. /*@}*/ /* end of group HSOTG_EXPORTED_FUNCTIONS */
  246. /*@}*/ /* end of group HSOTG_Driver */
  247. /*@}*/ /* end of group Standard_Driver */
  248. #ifdef __cplusplus
  249. }
  250. #endif
  251. #endif /* __NU_HSOTG_H__ */