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