summaryrefslogtreecommitdiff
path: root/bsp/nuvoton/libraries/m460/StdDriver/inc/nu_otg.h
blob: 274f630423ba68be40f879ad3e5bf5304ca6bab5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/**************************************************************************//**
 * @file     nu_otg.h
 * @version  V3.00
 * @brief    M460 series OTG driver header file
 *
 * @copyright SPDX-License-Identifier: Apache-2.0
 * @copyright Copyright (C) 2021 Nuvoton Technology Corp. All rights reserved.
 ****************************************************************************/
#ifndef __NU_OTG_H__
#define __NU_OTG_H__

#ifdef __cplusplus
extern "C"
{
#endif


/** @addtogroup Standard_Driver Standard Driver
  @{
*/

/** @addtogroup OTG_Driver OTG Driver
  @{
*/


/** @addtogroup OTG_EXPORTED_CONSTANTS OTG Exported Constants
  @{
*/



/*---------------------------------------------------------------------------------------------------------*/
/* OTG constant definitions                                                                                */
/*---------------------------------------------------------------------------------------------------------*/
#define OTG_VBUS_EN_ACTIVE_HIGH      (0UL) /*!< USB VBUS power switch enable signal is active high. \hideinitializer */
#define OTG_VBUS_EN_ACTIVE_LOW       (1UL) /*!< USB VBUS power switch enable signal is active low. \hideinitializer */
#define OTG_VBUS_ST_VALID_HIGH       (0UL) /*!< USB VBUS power switch valid status is high. \hideinitializer */
#define OTG_VBUS_ST_VALID_LOW        (1UL) /*!< USB VBUS power switch valid status is low. \hideinitializer */


/*@}*/ /* end of group OTG_EXPORTED_CONSTANTS */


/** @addtogroup OTG_EXPORTED_FUNCTIONS OTG Exported Functions
  @{
*/

/*---------------------------------------------------------------------------------------------------------*/
/*  Define Macros and functions                                                                            */
/*---------------------------------------------------------------------------------------------------------*/


/**
  * @brief This macro is used to enable OTG function
  * @param None
  * @return None
  * @details This macro will set OTGEN bit of OTG_CTL register to enable OTG function.
  * \hideinitializer
  */
#define OTG_ENABLE() (OTG->CTL |= OTG_CTL_OTGEN_Msk)

/**
  * @brief This macro is used to disable OTG function
  * @param None
  * @return None
  * @details This macro will clear OTGEN bit of OTG_CTL register to disable OTG function.
  * \hideinitializer
  */
#define OTG_DISABLE() (OTG->CTL &= ~OTG_CTL_OTGEN_Msk)

/**
  * @brief This macro is used to enable USB PHY
  * @param None
  * @return None
  * @details When the USB role is selected as OTG device, use this macro to enable USB PHY.
  *          This macro will set OTGPHYEN bit of OTG_PHYCTL register to enable USB PHY.
  * \hideinitializer
  */
#define OTG_ENABLE_PHY() (OTG->PHYCTL |= OTG_PHYCTL_OTGPHYEN_Msk)

/**
  * @brief This macro is used to disable USB PHY
  * @param None
  * @return None
  * @details This macro will clear OTGPHYEN bit of OTG_PHYCTL register to disable USB PHY.
  * \hideinitializer
  */
#define OTG_DISABLE_PHY() (OTG->PHYCTL &= ~OTG_PHYCTL_OTGPHYEN_Msk)

/**
  * @brief This macro is used to enable ID detection function
  * @param None
  * @return None
  * @details This macro will set IDDETEN bit of OTG_PHYCTL register to enable ID detection function.
  * \hideinitializer
  */
#define OTG_ENABLE_ID_DETECT() (OTG->PHYCTL |= OTG_PHYCTL_IDDETEN_Msk)

/**
  * @brief This macro is used to disable ID detection function
  * @param None
  * @return None
  * @details This macro will clear IDDETEN bit of OTG_PHYCTL register to disable ID detection function.
  * \hideinitializer
  */
#define OTG_DISABLE_ID_DETECT() (OTG->PHYCTL &= ~OTG_PHYCTL_IDDETEN_Msk)

/**
  * @brief This macro is used to enable OTG wake-up function
  * @param None
  * @return None
  * @details This macro will set WKEN bit of OTG_CTL register to enable OTG wake-up function.
  * \hideinitializer
  */
#define OTG_ENABLE_WAKEUP() (OTG->CTL |= OTG_CTL_WKEN_Msk)

/**
  * @brief This macro is used to disable OTG wake-up function
  * @param None
  * @return None
  * @details This macro will clear WKEN bit of OTG_CTL register to disable OTG wake-up function.
  * \hideinitializer
  */
#define OTG_DISABLE_WAKEUP() (OTG->CTL &= ~OTG_CTL_WKEN_Msk)

/**
  * @brief This macro is used to set the polarity of USB_VBUS_EN pin
  * @param[in] u32Pol The polarity selection. Valid values are listed below.
  *                    - \ref OTG_VBUS_EN_ACTIVE_HIGH
  *                    - \ref OTG_VBUS_EN_ACTIVE_LOW
  * @return None
  * @details This macro is used to set the polarity of external USB VBUS power switch enable signal.
  * \hideinitializer
  */
#define OTG_SET_VBUS_EN_POL(u32Pol) (OTG->PHYCTL = (OTG->PHYCTL & (~OTG_PHYCTL_VBENPOL_Msk)) | ((u32Pol) << OTG_PHYCTL_VBENPOL_Pos))

/**
  * @brief This macro is used to set the polarity of USB_VBUS_ST pin
  * @param[in] u32Pol The polarity selection. Valid values are listed below.
  *                    - \ref OTG_VBUS_ST_VALID_HIGH
  *                    - \ref OTG_VBUS_ST_VALID_LOW
  * @return None
  * @details This macro is used to set the polarity of external USB VBUS power switch status signal.
  * \hideinitializer
  */
#define OTG_SET_VBUS_STS_POL(u32Pol) (OTG->PHYCTL = (OTG->PHYCTL & (~OTG_PHYCTL_VBSTSPOL_Msk)) | ((u32Pol) << OTG_PHYCTL_VBSTSPOL_Pos))

/**
  * @brief This macro is used to enable OTG related interrupts
  * @param[in] u32Mask The combination of interrupt source. Each bit corresponds to a interrupt source. Valid values are listed below.
  *                    - \ref OTG_INTEN_ROLECHGIEN_Msk
  *                    - \ref OTG_INTEN_VBEIEN_Msk
  *                    - \ref OTG_INTEN_SRPFIEN_Msk
  *                    - \ref OTG_INTEN_HNPFIEN_Msk
  *                    - \ref OTG_INTEN_GOIDLEIEN_Msk
  *                    - \ref OTG_INTEN_IDCHGIEN_Msk
  *                    - \ref OTG_INTEN_PDEVIEN_Msk
  *                    - \ref OTG_INTEN_HOSTIEN_Msk
  *                    - \ref OTG_INTEN_BVLDCHGIEN_Msk
  *                    - \ref OTG_INTEN_AVLDCHGIEN_Msk
  *                    - \ref OTG_INTEN_VBCHGIEN_Msk
  *                    - \ref OTG_INTEN_SECHGIEN_Msk
  *                    - \ref OTG_INTEN_SRPDETIEN_Msk
  * @return None
  * @details This macro will enable OTG related interrupts specified by u32Mask parameter.
  * \hideinitializer
  */
#define OTG_ENABLE_INT(u32Mask) (OTG->INTEN |= (u32Mask))

/**
  * @brief This macro is used to disable OTG related interrupts
  * @param[in] u32Mask The combination of interrupt source. Each bit corresponds to a interrupt source. Valid values are listed below.
  *                    - \ref OTG_INTEN_ROLECHGIEN_Msk
  *                    - \ref OTG_INTEN_VBEIEN_Msk
  *                    - \ref OTG_INTEN_SRPFIEN_Msk
  *                    - \ref OTG_INTEN_HNPFIEN_Msk
  *                    - \ref OTG_INTEN_GOIDLEIEN_Msk
  *                    - \ref OTG_INTEN_IDCHGIEN_Msk
  *                    - \ref OTG_INTEN_PDEVIEN_Msk
  *                    - \ref OTG_INTEN_HOSTIEN_Msk
  *                    - \ref OTG_INTEN_BVLDCHGIEN_Msk
  *                    - \ref OTG_INTEN_AVLDCHGIEN_Msk
  *                    - \ref OTG_INTEN_VBCHGIEN_Msk
  *                    - \ref OTG_INTEN_SECHGIEN_Msk
  *                    - \ref OTG_INTEN_SRPDETIEN_Msk
  * @return None
  * @details This macro will disable OTG related interrupts specified by u32Mask parameter.
  * \hideinitializer
  */
#define OTG_DISABLE_INT(u32Mask) (OTG->INTEN &= ~(u32Mask))

/**
  * @brief This macro is used to get OTG related interrupt flags
  * @param[in] u32Mask The combination of interrupt source. Each bit corresponds to a interrupt source. Valid values are listed below.
  *                    - \ref OTG_INTSTS_ROLECHGIF_Msk
  *                    - \ref OTG_INTSTS_VBEIF_Msk
  *                    - \ref OTG_INTSTS_SRPFIF_Msk
  *                    - \ref OTG_INTSTS_HNPFIF_Msk
  *                    - \ref OTG_INTSTS_GOIDLEIF_Msk
  *                    - \ref OTG_INTSTS_IDCHGIF_Msk
  *                    - \ref OTG_INTSTS_PDEVIF_Msk
  *                    - \ref OTG_INTSTS_HOSTIF_Msk
  *                    - \ref OTG_INTSTS_BVLDCHGIF_Msk
  *                    - \ref OTG_INTSTS_AVLDCHGIF_Msk
  *                    - \ref OTG_INTSTS_VBCHGIF_Msk
  *                    - \ref OTG_INTSTS_SECHGIF_Msk
  *                    - \ref OTG_INTSTS_SRPDETIF_Msk
  * @return Interrupt flags of selected sources.
  * @details This macro will return OTG related interrupt flags specified by u32Mask parameter.
  * \hideinitializer
  */
#define OTG_GET_INT_FLAG(u32Mask) (OTG->INTSTS & (u32Mask))

/**
  * @brief This macro is used to clear OTG related interrupt flags
  * @param[in] u32Mask The combination of interrupt source. Each bit corresponds to a interrupt source. Valid values are listed below.
  *                    - \ref OTG_INTSTS_ROLECHGIF_Msk
  *                    - \ref OTG_INTSTS_VBEIF_Msk
  *                    - \ref OTG_INTSTS_SRPFIF_Msk
  *                    - \ref OTG_INTSTS_HNPFIF_Msk
  *                    - \ref OTG_INTSTS_GOIDLEIF_Msk
  *                    - \ref OTG_INTSTS_IDCHGIF_Msk
  *                    - \ref OTG_INTSTS_PDEVIF_Msk
  *                    - \ref OTG_INTSTS_HOSTIF_Msk
  *                    - \ref OTG_INTSTS_BVLDCHGIF_Msk
  *                    - \ref OTG_INTSTS_AVLDCHGIF_Msk
  *                    - \ref OTG_INTSTS_VBCHGIF_Msk
  *                    - \ref OTG_INTSTS_SECHGIF_Msk
  *                    - \ref OTG_INTSTS_SRPDETIF_Msk
  * @return None
  * @details This macro will clear OTG related interrupt flags specified by u32Mask parameter.
  * \hideinitializer
  */
#define OTG_CLR_INT_FLAG(u32Mask) (OTG->INTSTS = (u32Mask))

/**
  * @brief This macro is used to get OTG related status
  * @param[in] u32Mask The combination of user specified source. Valid values are listed below.
  *                    - \ref OTG_STATUS_OVERCUR_Msk
  *                    - \ref OTG_STATUS_IDSTS_Msk
  *                    - \ref OTG_STATUS_SESSEND_Msk
  *                    - \ref OTG_STATUS_BVLD_Msk
  *                    - \ref OTG_STATUS_AVLD_Msk
  *                    - \ref OTG_STATUS_VBUSVLD_Msk
  *                    - \ref OTG_STATUS_ASPERI_Msk
  *                    - \ref OTG_STATUS_ASHOST_Msk
  * @return The user specified status.
  * @details This macro will return OTG related status specified by u32Mask parameter.
  * \hideinitializer
  */
#define OTG_GET_STATUS(u32Mask) (OTG->STATUS & (u32Mask))



/*@}*/ /* end of group OTG_EXPORTED_FUNCTIONS */

/*@}*/ /* end of group OTG_Driver */

/*@}*/ /* end of group Standard_Driver */

#ifdef __cplusplus
}
#endif

#endif /*__NU_OTG_H__ */