1 /**************************************************************************//**
2  * @file     ACMP.h
3  * @version  V1.00
4  * @brief    M480 Series ACMP 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 __ACMP_H__
10 #define __ACMP_H__
11 
12 
13 #ifdef __cplusplus
14 extern "C"
15 {
16 #endif
17 
18 
19 /** @addtogroup Standard_Driver Standard Driver
20   @{
21 */
22 
23 
24 /** @addtogroup ACMP_Driver ACMP Driver
25   @{
26 */
27 
28 
29 /** @addtogroup ACMP_EXPORTED_CONSTANTS ACMP Exported Constants
30   @{
31 */
32 
33 
34 
35 /*---------------------------------------------------------------------------------------------------------*/
36 /* ACMP_CTL constant definitions                                                                           */
37 /*---------------------------------------------------------------------------------------------------------*/
38 #define ACMP_CTL_FILTSEL_OFF         (0UL << ACMP_CTL_FILTSEL_Pos) /*!< ACMP_CTL setting for filter function disabled. \hideinitializer */
39 #define ACMP_CTL_FILTSEL_1PCLK       (1UL << ACMP_CTL_FILTSEL_Pos) /*!< ACMP_CTL setting for 1 PCLK filter count. \hideinitializer */
40 #define ACMP_CTL_FILTSEL_2PCLK       (2UL << ACMP_CTL_FILTSEL_Pos) /*!< ACMP_CTL setting for 2 PCLK filter count. \hideinitializer */
41 #define ACMP_CTL_FILTSEL_4PCLK       (3UL << ACMP_CTL_FILTSEL_Pos) /*!< ACMP_CTL setting for 4 PCLK filter count. \hideinitializer */
42 #define ACMP_CTL_FILTSEL_8PCLK       (4UL << ACMP_CTL_FILTSEL_Pos) /*!< ACMP_CTL setting for 8 PCLK filter count. \hideinitializer */
43 #define ACMP_CTL_FILTSEL_16PCLK      (5UL << ACMP_CTL_FILTSEL_Pos) /*!< ACMP_CTL setting for 16 PCLK filter count. \hideinitializer */
44 #define ACMP_CTL_FILTSEL_32PCLK      (6UL << ACMP_CTL_FILTSEL_Pos) /*!< ACMP_CTL setting for 32 PCLK filter count. \hideinitializer */
45 #define ACMP_CTL_FILTSEL_64PCLK      (7UL << ACMP_CTL_FILTSEL_Pos) /*!< ACMP_CTL setting for 64 PCLK filter count. \hideinitializer */
46 #define ACMP_CTL_INTPOL_RF           (0UL << ACMP_CTL_INTPOL_Pos)  /*!< ACMP_CTL setting for selecting rising edge and falling edge as interrupt condition. \hideinitializer */
47 #define ACMP_CTL_INTPOL_R            (1UL << ACMP_CTL_INTPOL_Pos)  /*!< ACMP_CTL setting for selecting rising edge as interrupt condition. \hideinitializer */
48 #define ACMP_CTL_INTPOL_F            (2UL << ACMP_CTL_INTPOL_Pos)  /*!< ACMP_CTL setting for selecting falling edge as interrupt condition. \hideinitializer */
49 #define ACMP_CTL_POSSEL_P0           (0UL << ACMP_CTL_POSSEL_Pos)  /*!< ACMP_CTL setting for selecting ACMPx_P0 pin as the source of ACMP V+. \hideinitializer */
50 #define ACMP_CTL_POSSEL_P1           (1UL << ACMP_CTL_POSSEL_Pos)  /*!< ACMP_CTL setting for selecting ACMPx_P1 pin as the source of ACMP V+. \hideinitializer */
51 #define ACMP_CTL_POSSEL_P2           (2UL << ACMP_CTL_POSSEL_Pos)  /*!< ACMP_CTL setting for selecting ACMPx_P2 pin as the source of ACMP V+. \hideinitializer */
52 #define ACMP_CTL_POSSEL_P3           (3UL << ACMP_CTL_POSSEL_Pos)  /*!< ACMP_CTL setting for selecting ACMPx_P3 pin as the source of ACMP V+. \hideinitializer */
53 #define ACMP_CTL_NEGSEL_PIN          (0UL << ACMP_CTL_NEGSEL_Pos)  /*!< ACMP_CTL setting for selecting the voltage of ACMP negative input pin as the source of ACMP V-. \hideinitializer */
54 #define ACMP_CTL_NEGSEL_CRV          (1UL << ACMP_CTL_NEGSEL_Pos)  /*!< ACMP_CTL setting for selecting internal comparator reference voltage as the source of ACMP V-. \hideinitializer */
55 #define ACMP_CTL_NEGSEL_VBG          (2UL << ACMP_CTL_NEGSEL_Pos)  /*!< ACMP_CTL setting for selecting internal Band-gap voltage as the source of ACMP V-. \hideinitializer */
56 #define ACMP_CTL_NEGSEL_DAC          (3UL << ACMP_CTL_NEGSEL_Pos)  /*!< ACMP_CTL setting for selecting DAC output voltage as the source of ACMP V-. \hideinitializer */
57 #define ACMP_CTL_HYSTERESIS_30MV     (3UL << ACMP_CTL_HYSSEL_Pos)  /*!< ACMP_CTL setting for enabling the hysteresis function at 30mV. \hideinitializer */
58 #define ACMP_CTL_HYSTERESIS_20MV     (2UL << ACMP_CTL_HYSSEL_Pos)  /*!< ACMP_CTL setting for enabling the hysteresis function at 20mV. \hideinitializer */
59 #define ACMP_CTL_HYSTERESIS_10MV     (1UL << ACMP_CTL_HYSSEL_Pos)  /*!< ACMP_CTL setting for enabling the hysteresis function at 10mV. \hideinitializer */
60 #define ACMP_CTL_HYSTERESIS_DISABLE  (0UL << ACMP_CTL_HYSSEL_Pos)  /*!< ACMP_CTL setting for disabling the hysteresis function. \hideinitializer */
61 
62 /*---------------------------------------------------------------------------------------------------------*/
63 /* ACMP_VREF constant definitions                                                                          */
64 /*---------------------------------------------------------------------------------------------------------*/
65 #define ACMP_VREF_CRV0SSEL_VDDA       (0UL << ACMP_VREF_CRV0SSEL_Pos)  /*!< ACMP_VREF setting for selecting analog supply voltage VDDA as the CRV0 source voltage \hideinitializer */
66 #define ACMP_VREF_CRV0SSEL_INTVREF    (1UL << ACMP_VREF_CRV0SSEL_Pos)  /*!< ACMP_VREF setting for selecting internal reference voltage as the CRV0 source voltage \hideinitializer */
67 #define ACMP_VREF_CRV1SSEL_VDDA       (0UL << ACMP_VREF_CRV1SSEL_Pos)  /*!< ACMP_VREF setting for selecting analog supply voltage VDDA as the CRV1 source voltage \hideinitializer */
68 #define ACMP_VREF_CRV1SSEL_INTVREF    (1UL << ACMP_VREF_CRV1SSEL_Pos)  /*!< ACMP_VREF setting for selecting internal reference voltage as the CRV1 source voltage \hideinitializer */
69 #define ACMP_VREF_CRV2SSEL_VDDA       (0UL << ACMP_VREF_CRV2SSEL_Pos)  /*!< ACMP_VREF setting for selecting analog supply voltage VDDA as the CRV2 source voltage \hideinitializer */
70 #define ACMP_VREF_CRV2SSEL_INTVREF    (1UL << ACMP_VREF_CRV2SSEL_Pos)  /*!< ACMP_VREF setting for selecting internal reference voltage as the CRV2 source voltage \hideinitializer */
71 #define ACMP_VREF_CRV3SSEL_VDDA       (0UL << ACMP_VREF_CRV3SSEL_Pos)  /*!< ACMP_VREF setting for selecting analog supply voltage VDDA as the CRV3 source voltage \hideinitializer */
72 #define ACMP_VREF_CRV3SSEL_INTVREF    (1UL << ACMP_VREF_CRV3SSEL_Pos)  /*!< ACMP_VREF setting for selecting internal reference voltage as the CRV3 source voltage \hideinitializer */
73 
74 
75 /*@}*/ /* end of group ACMP_EXPORTED_CONSTANTS */
76 
77 
78 /** @addtogroup ACMP_EXPORTED_FUNCTIONS ACMP Exported Functions
79   @{
80 */
81 
82 /*---------------------------------------------------------------------------------------------------------*/
83 /*  Define Macros and functions                                                                            */
84 /*---------------------------------------------------------------------------------------------------------*/
85 
86 
87 /**
88   * @brief This macro is used to enable output inverse function
89   * @param[in] acmp The pointer of the specified ACMP module
90   * @param[in] u32ChNum The ACMP number
91   * @return None
92   * @details This macro will set ACMPOINV bit of ACMP_CTL register to enable output inverse function.
93   * \hideinitializer
94   */
95 #define ACMP_ENABLE_OUTPUT_INVERSE(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] |= ACMP_CTL_ACMPOINV_Msk)
96 
97 /**
98   * @brief This macro is used to disable output inverse function
99   * @param[in] acmp The pointer of the specified ACMP module
100   * @param[in] u32ChNum The ACMP number
101   * @return None
102   * @details This macro will clear ACMPOINV bit of ACMP_CTL register to disable output inverse function.
103   * \hideinitializer
104   */
105 #define ACMP_DISABLE_OUTPUT_INVERSE(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] &= ~ACMP_CTL_ACMPOINV_Msk)
106 
107 /**
108   * @brief This macro is used to select ACMP negative input source
109   * @param[in] acmp The pointer of the specified ACMP module
110   * @param[in] u32ChNum The ACMP number
111   * @param[in] u32Src is comparator negative input selection. Including:
112   *                  - \ref ACMP_CTL_NEGSEL_PIN
113   *                  - \ref ACMP_CTL_NEGSEL_CRV
114   *                  - \ref ACMP_CTL_NEGSEL_VBG
115   *                  - \ref ACMP_CTL_NEGSEL_DAC
116   * @return None
117   * @details This macro will set NEGSEL (ACMP_CTL[5:4]) to determine the source of negative input.
118   * \hideinitializer
119   */
120 #define ACMP_SET_NEG_SRC(acmp, u32ChNum, u32Src) ((acmp)->CTL[(u32ChNum)] = ((acmp)->CTL[(u32ChNum)] & ~ACMP_CTL_NEGSEL_Msk) | (u32Src))
121 
122 /**
123   * @brief This macro is used to enable hysteresis function and set hysteresis to 30mV
124   * @param[in] acmp The pointer of the specified ACMP module
125   * @param[in] u32ChNum The ACMP number
126   * @return None
127   * \hideinitializer
128   */
129 #define ACMP_ENABLE_HYSTERESIS(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] |= ACMP_CTL_HYSTERESIS_30MV)
130 
131 /**
132   * @brief This macro is used to disable hysteresis function
133   * @param[in] acmp The pointer of the specified ACMP module
134   * @param[in] u32ChNum The ACMP number
135   * @return None
136   * @details This macro will clear HYSEL bits of ACMP_CTL register to disable hysteresis function.
137   * \hideinitializer
138   */
139 #define ACMP_DISABLE_HYSTERESIS(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] &= ~ACMP_CTL_HYSSEL_Msk)
140 
141 /**
142   * @brief This macro is used to select hysteresis level
143   * @param[in] acmp The pointer of the specified ACMP module
144   * @param[in] u32ChNum The ACMP number
145   * @param[in] u32HysSel The hysteresis function option. Including:
146   *                  - \ref ACMP_CTL_HYSTERESIS_30MV
147   *                  - \ref ACMP_CTL_HYSTERESIS_20MV
148   *                  - \ref ACMP_CTL_HYSTERESIS_10MV
149   *                  - \ref ACMP_CTL_HYSTERESIS_DISABLE
150   * \hideinitializer
151   * @return None
152   */
153 #define ACMP_CONFIG_HYSTERESIS(acmp, u32ChNum, u32HysSel) ((acmp)->CTL[(u32ChNum)] = ((acmp)->CTL[(u32ChNum)] & ~ACMP_CTL_HYSSEL_Msk) | (u32HysSel))
154 
155 /**
156   * @brief This macro is used to enable interrupt
157   * @param[in] acmp The pointer of the specified ACMP module
158   * @param[in] u32ChNum The ACMP number
159   * @return None
160   * @details This macro will set ACMPIE bit of ACMP_CTL register to enable interrupt function.
161   *          If wake-up function is enabled, the wake-up interrupt will be enabled as well.
162   * \hideinitializer
163   */
164 #define ACMP_ENABLE_INT(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] |= ACMP_CTL_ACMPIE_Msk)
165 
166 /**
167   * @brief This macro is used to disable interrupt
168   * @param[in] acmp The pointer of the specified ACMP module
169   * @param[in] u32ChNum The ACMP number
170   * @return None
171   * @details This macro will clear ACMPIE bit of ACMP_CTL register to disable interrupt function.
172   * \hideinitializer
173   */
174 #define ACMP_DISABLE_INT(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] &= ~ACMP_CTL_ACMPIE_Msk)
175 
176 /**
177   * @brief This macro is used to enable ACMP
178   * @param[in] acmp The pointer of the specified ACMP module
179   * @param[in] u32ChNum The ACMP number
180   * @return None
181   * @details This macro will set ACMPEN bit of ACMP_CTL register to enable analog comparator.
182   * \hideinitializer
183   */
184 #define ACMP_ENABLE(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] |= ACMP_CTL_ACMPEN_Msk)
185 
186 /**
187   * @brief This macro is used to disable ACMP
188   * @param[in] acmp The pointer of the specified ACMP module
189   * @param[in] u32ChNum The ACMP number
190   * @return None
191   * @details This macro will clear ACMPEN bit of ACMP_CTL register to disable analog comparator.
192   * \hideinitializer
193   */
194 #define ACMP_DISABLE(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] &= ~ACMP_CTL_ACMPEN_Msk)
195 
196 /**
197   * @brief This macro is used to get ACMP output value
198   * @param[in] acmp The pointer of the specified ACMP module
199   * @param[in] u32ChNum The ACMP number
200   * @return  ACMP output value
201   * @details This macro will return the ACMP output value.
202   * \hideinitializer
203   */
204 #define ACMP_GET_OUTPUT(acmp, u32ChNum) (((acmp)->STATUS & (ACMP_STATUS_ACMPO0_Msk<<((u32ChNum))))?1:0)
205 
206 /**
207   * @brief This macro is used to get ACMP interrupt flag
208   * @param[in] acmp The pointer of the specified ACMP module
209   * @param[in] u32ChNum The ACMP number
210   * @return   ACMP interrupt occurred (1) or not (0)
211   * @details This macro will return the ACMP interrupt flag.
212   * \hideinitializer
213   */
214 #define ACMP_GET_INT_FLAG(acmp, u32ChNum) (((acmp)->STATUS & (ACMP_STATUS_ACMPIF0_Msk<<((u32ChNum))))?1:0)
215 
216 /**
217   * @brief This macro is used to clear ACMP interrupt flag
218   * @param[in] acmp The pointer of the specified ACMP module
219   * @param[in] u32ChNum The ACMP number
220   * @return   None
221   * @details This macro will write 1 to ACMPIFn bit of ACMP_STATUS register to clear interrupt flag.
222   * \hideinitializer
223   */
224 #define ACMP_CLR_INT_FLAG(acmp, u32ChNum) ((acmp)->STATUS = (ACMP_STATUS_ACMPIF0_Msk<<((u32ChNum))))
225 
226 /**
227   * @brief This macro is used to clear ACMP wake-up interrupt flag
228   * @param[in] acmp The pointer of the specified ACMP module
229   * @param[in] u32ChNum The ACMP number
230   * @return   None
231   * @details This macro will write 1 to WKIFn bit of ACMP_STATUS register to clear interrupt flag.
232   * \hideinitializer
233   */
234 #define ACMP_CLR_WAKEUP_INT_FLAG(acmp, u32ChNum) ((acmp)->STATUS = (ACMP_STATUS_WKIF0_Msk<<((u32ChNum))))
235 
236 /**
237   * @brief This macro is used to enable ACMP wake-up function
238   * @param[in] acmp The pointer of the specified ACMP module
239   * @param[in] u32ChNum The ACMP number
240   * @return None
241   * @details This macro will set WKEN (ACMP_CTL[16]) to enable ACMP wake-up function.
242   * \hideinitializer
243   */
244 #define ACMP_ENABLE_WAKEUP(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] |= ACMP_CTL_WKEN_Msk)
245 
246 /**
247   * @brief This macro is used to disable ACMP wake-up function
248   * @param[in] acmp The pointer of the specified ACMP module
249   * @param[in] u32ChNum The ACMP number
250   * @return None
251   * @details This macro will clear WKEN (ACMP_CTL[16]) to disable ACMP wake-up function.
252   * \hideinitializer
253   */
254 #define ACMP_DISABLE_WAKEUP(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] &= ~ACMP_CTL_WKEN_Msk)
255 
256 /**
257   * @brief This macro is used to select ACMP positive input pin
258   * @param[in] acmp The pointer of the specified ACMP module
259   * @param[in] u32ChNum The ACMP number
260   * @param[in] u32Pin Comparator positive pin selection. Including:
261   *                  - \ref ACMP_CTL_POSSEL_P0
262   *                  - \ref ACMP_CTL_POSSEL_P1
263   *                  - \ref ACMP_CTL_POSSEL_P2
264   *                  - \ref ACMP_CTL_POSSEL_P3
265   * @return None
266   * @details This macro will set POSSEL (ACMP_CTL[7:6]) to determine the comparator positive input pin.
267   * \hideinitializer
268   */
269 #define ACMP_SELECT_P(acmp, u32ChNum, u32Pin) ((acmp)->CTL[(u32ChNum)] = ((acmp)->CTL[(u32ChNum)] & ~ACMP_CTL_POSSEL_Msk) | (u32Pin))
270 
271 /**
272   * @brief This macro is used to enable ACMP filter function
273   * @param[in] acmp The pointer of the specified ACMP module
274   * @param[in] u32ChNum The ACMP number
275   * @return None
276   * @details This macro will set OUTSEL (ACMP_CTL[12]) to enable output filter function.
277   * \hideinitializer
278   */
279 #define ACMP_ENABLE_FILTER(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] |= ACMP_CTL_OUTSEL_Msk)
280 
281 /**
282   * @brief This macro is used to disable ACMP filter function
283   * @param[in] acmp The pointer of the specified ACMP module
284   * @param[in] u32ChNum The ACMP number
285   * @return None
286   * @details This macro will clear OUTSEL (ACMP_CTL[12]) to disable output filter function.
287   * \hideinitializer
288   */
289 #define ACMP_DISABLE_FILTER(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] &= ~ACMP_CTL_OUTSEL_Msk)
290 
291 /**
292   * @brief This macro is used to set ACMP filter function
293   * @param[in] acmp The pointer of the specified ACMP module
294   * @param[in] u32ChNum The ACMP number
295   * @param[in] u32Cnt is comparator filter count setting.
296   *                  - \ref ACMP_CTL_FILTSEL_OFF
297   *                  - \ref ACMP_CTL_FILTSEL_1PCLK
298   *                  - \ref ACMP_CTL_FILTSEL_2PCLK
299   *                  - \ref ACMP_CTL_FILTSEL_4PCLK
300   *                  - \ref ACMP_CTL_FILTSEL_8PCLK
301   *                  - \ref ACMP_CTL_FILTSEL_16PCLK
302   *                  - \ref ACMP_CTL_FILTSEL_32PCLK
303   *                  - \ref ACMP_CTL_FILTSEL_64PCLK
304   * @return None
305   * @details When ACMP output filter function is enabled, the output sampling count is determined by FILTSEL (ACMP_CTL[15:13]).
306   * \hideinitializer
307   */
308 #define ACMP_SET_FILTER(acmp, u32ChNum, u32Cnt) ((acmp)->CTL[(u32ChNum)] = ((acmp)->CTL[(u32ChNum)] & ~ACMP_CTL_FILTSEL_Msk) | (u32Cnt))
309 
310 /**
311   * @brief This macro is used to select comparator reference voltage
312   * @param[in] acmp The pointer of the specified ACMP module
313   * @param[in] u32Level  The comparator reference voltage setting.
314   *             The formula is:
315   *                       comparator reference voltage = CRV source voltage x (1/6 + u32Level/24)
316   *             The range of u32Level is 0 ~ 15.
317   * @return   None
318   * @details  When CRV is selected as ACMP negative input source, the CRV level is determined by CRVCTL (ACMP_VREF[3:0]).
319   * \hideinitializer
320   */
321 #define ACMP_CRV_SEL(acmp, u32Level) ((acmp)->VREF = ((acmp)->VREF & ~ACMP_VREF_CRV0SEL_Msk) | ((u32Level)<<ACMP_VREF_CRV0SEL_Pos))
322 #define ACMP_CRV0_SEL(acmp, u32Level) ((acmp)->VREF = ((acmp)->VREF & ~ACMP_VREF_CRV0SEL_Msk) | ((u32Level)<<ACMP_VREF_CRV0SEL_Pos))
323 #define ACMP_CRV1_SEL(acmp, u32Level) ((acmp)->VREF = ((acmp)->VREF & ~ACMP_VREF_CRV1SEL_Msk) | ((u32Level)<<ACMP_VREF_CRV1SEL_Pos))
324 
325 
326 /**
327   * @brief This macro is used to enable comparator reference voltage
328   * @param[in] acmp The pointer of the specified ACMP module
329   * @return   None
330   * @details  CRV must be enabled before using it.
331   * \hideinitializer
332   */
333 #define ACMP_ENABLE_CRV0(acmp) ((acmp)->VREF |= ACMP_VREF_CRV0EN_Msk)
334 #define ACMP_ENABLE_CRV1(acmp) ((acmp)->VREF |= ACMP_VREF_CRV1EN_Msk)
335 
336 
337   /**
338     * @brief This macro is used to disable comparator reference voltage
339     * @param[in] acmp The pointer of the specified ACMP module
340     * @return   None
341     * @details  Disable CRV.
342     * \hideinitializer
343     */
344 #define ACMP_DISABLE_CRV0(acmp) ((acmp)->VREF &= ~ACMP_VREF_CRV0EN_Msk)
345 #define ACMP_DISABLE_CRV1(acmp) ((acmp)->VREF &= ~ACMP_VREF_CRV1EN_Msk)
346 
347 /**
348   * @brief This macro is used to select the source of CRV
349   * @param[in] acmp The pointer of the specified ACMP module
350   * @param[in] u32Src is the source of CRV. Including:
351   *                  - \ref ACMP_VREF_CRV0SSEL_VDDA
352   *                  - \ref ACMP_VREF_CRV0SSEL_INTVREF
353   *                  - \ref ACMP_VREF_CRV1SSEL_VDDA
354   *                  - \ref ACMP_VREF_CRV1SSEL_INTVREF
355   *                  - \ref ACMP_VREF_CRV2SSEL_VDDA
356   *                  - \ref ACMP_VREF_CRV2SSEL_INTVREF
357   *                  - \ref ACMP_VREF_CRV3SSEL_VDDA
358   *                  - \ref ACMP_VREF_CRV3SSEL_INTVREF
359   * @return None
360   * @details The source of CRV can be VDDA or internal reference voltage. The internal reference voltage level is determined by SYS_VREFCTL register.
361   * \hideinitializer
362   */
363 #define ACMP_SELECT_CRV_SRC(acmp, u32Src) ((acmp)->VREF = ((acmp)->VREF & ~ACMP_VREF_CRV0SSEL_Msk) | (u32Src))
364 #define ACMP_SELECT_CRV0_SRC(acmp, u32Src) ((acmp)->VREF = ((acmp)->VREF & ~ACMP_VREF_CRV0SSEL_Msk) | (u32Src))
365 #define ACMP_SELECT_CRV1_SRC(acmp, u32Src) ((acmp)->VREF = ((acmp)->VREF & ~ACMP_VREF_CRV1SSEL_Msk) | (u32Src))
366 #define ACMP_SELECT_CRV2_SRC(acmp, u32Src) ((acmp)->VREF = ((acmp)->VREF & ~ACMP_VREF_CRV0SSEL_Msk) | (u32Src))
367 #define ACMP_SELECT_CRV3_SRC(acmp, u32Src) ((acmp)->VREF = ((acmp)->VREF & ~ACMP_VREF_CRV1SSEL_Msk) | (u32Src))
368 
369 /**
370   * @brief This macro is used to select ACMP interrupt condition
371   * @param[in] acmp The pointer of the specified ACMP module
372   * @param[in] u32ChNum The ACMP number
373   * @param[in] u32Cond Comparator interrupt condition selection. Including:
374   *                  - \ref ACMP_CTL_INTPOL_RF
375   *                  - \ref ACMP_CTL_INTPOL_R
376   *                  - \ref ACMP_CTL_INTPOL_F
377   * @return None
378   * @details The ACMP output interrupt condition can be rising edge, falling edge or any edge.
379   * \hideinitializer
380   */
381 #define ACMP_SELECT_INT_COND(acmp, u32ChNum, u32Cond) ((acmp)->CTL[(u32ChNum)] = ((acmp)->CTL[(u32ChNum)] & ~ACMP_CTL_INTPOL_Msk) | (u32Cond))
382 
383 /**
384   * @brief This macro is used to enable ACMP window latch mode
385   * @param[in] acmp The pointer of the specified ACMP module
386   * @param[in] u32ChNum The ACMP number
387   * @return None
388   * @details This macro will set WLATEN (ACMP_CTL[17]) to enable ACMP window latch mode.
389   *          When ACMP0/1_WLAT pin is at high level, ACMPO0/1 passes through window latch
390   *          block; when ACMP0/1_WLAT pin is at low level, the output of window latch block,
391   *          WLATOUT, is frozen.
392   * \hideinitializer
393   */
394 #define ACMP_ENABLE_WINDOW_LATCH(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] |= ACMP_CTL_WLATEN_Msk)
395 
396 /**
397   * @brief This macro is used to disable ACMP window latch mode
398   * @param[in] acmp The pointer of the specified ACMP module
399   * @param[in] u32ChNum The ACMP number
400   * @return None
401   * @details This macro will clear WLATEN (ACMP_CTL[17]) to disable ACMP window latch mode.
402   * \hideinitializer
403   */
404 #define ACMP_DISABLE_WINDOW_LATCH(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] &= ~ACMP_CTL_WLATEN_Msk)
405 
406 /**
407   * @brief This macro is used to enable ACMP window compare mode
408   * @param[in] acmp The pointer of the specified ACMP module
409   * @param[in] u32ChNum The ACMP number
410   * @return None
411   * @details This macro will set WCMPSEL (ACMP_CTL[18]) to enable ACMP window compare mode.
412   *          When window compare mode is enabled, user can connect the specific analog voltage
413   *          source to either the positive inputs of both comparators or the negative inputs of
414   *          both comparators. The upper bound and lower bound of the designated range are
415   *          determined by the voltages applied to the other inputs of both comparators. If the
416   *          output of a comparator is low and the other comparator outputs high, which means two
417   *          comparators implies the upper and lower bound. User can directly monitor a specific
418   *          analog voltage source via ACMPWO (ACMP_STATUS[16]).
419   * \hideinitializer
420   */
421 #define ACMP_ENABLE_WINDOW_COMPARE(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] |= ACMP_CTL_WCMPSEL_Msk)
422 
423 /**
424   * @brief This macro is used to disable ACMP window compare mode
425   * @param[in] acmp The pointer of the specified ACMP module
426   * @param[in] u32ChNum The ACMP number
427   * @return None
428   * @details This macro will clear WCMPSEL (ACMP_CTL[18]) to disable ACMP window compare mode.
429   * \hideinitializer
430   */
431 #define ACMP_DISABLE_WINDOW_COMPARE(acmp, u32ChNum) ((acmp)->CTL[(u32ChNum)] &= ~ACMP_CTL_WCMPSEL_Msk)
432 
433 
434 
435 
436 /* Function prototype declaration */
437 void ACMP_Open(ACMP_T *acmp, uint32_t u32ChNum, uint32_t u32NegSrc, uint32_t u32HysSel);
438 void ACMP_Close(ACMP_T *acmp, uint32_t u32ChNum);
439 
440 
441 
442 /*@}*/ /* end of group ACMP_EXPORTED_FUNCTIONS */
443 
444 /*@}*/ /* end of group ACMP_Driver */
445 
446 /*@}*/ /* end of group Standard_Driver */
447 
448 #ifdef __cplusplus
449 }
450 #endif
451 
452 
453 #endif /* __ACMP_H__ */
454 
455 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
456