| Nano103 BSP V3.01.002 The Board Support Package for Nano103 Series

acmp.h
Go to the documentation of this file.
1 /**************************************************************************/
12 #ifndef __ACMP_H__
13 #define __ACMP_H__
14
15 #ifdef __cplusplus
16 extern "C"
17 {
18 #endif
19
20
32 #define ACMP_HYSTERESIS_ENABLE ACMP_CTL0_HYSEN_Msk
33 #define ACMP_HYSTERESIS_DISABLE 0
34
35 #define ACMP_VNEG_PIN ~(0 << ACMP_CTL0_NEGSEL_Pos)
36 #define ACMP_VNEG_IREF ~(2 << ACMP_CTL0_NEGSEL_Pos)
37 #define ACMP_VNEG_AVSS ~(3 << ACMP_CTL0_NEGSEL_Pos)
38 #define ACMP_VNEG_4_OVER_24_VDD (0x0UL)
39 #define ACMP_VNEG_5_OVER_24_VDD (0x1UL)
40 #define ACMP_VNEG_6_OVER_24_VDD (0x2UL)
41 #define ACMP_VNEG_7_OVER_24_VDD (0x3UL)
42 #define ACMP_VNEG_8_OVER_24_VDD (0x4UL)
43 #define ACMP_VNEG_9_OVER_24_VDD (0x5UL)
44 #define ACMP_VNEG_10_OVER_24_VDD (0x6UL)
45 #define ACMP_VNEG_11_OVER_24_VDD (0x7UL)
46 #define ACMP_VNEG_12_OVER_24_VDD (0x8UL)
47 #define ACMP_VNEG_13_OVER_24_VDD (0x9UL)
48 #define ACMP_VNEG_14_OVER_24_VDD (0xAUL)
49 #define ACMP_VNEG_15_OVER_24_VDD (0xBUL)
50 #define ACMP_VNEG_16_OVER_24_VDD (0xCUL)
51 #define ACMP_VNEG_17_OVER_24_VDD (0xDUL)
52 #define ACMP_VNEG_18_OVER_24_VDD (0xEUL)
53 #define ACMP_VNEG_19_OVER_24_VDD (0xFUL)
54 #define ACMP_VNEG_4_OVER_24_IREF (ACMP_VREF_CRVSSEL_Msk | 0x0UL)
55 #define ACMP_VNEG_5_OVER_24_IREF (ACMP_VREF_CRVSSEL_Msk | 0x1UL)
56 #define ACMP_VNEG_6_OVER_24_IREF (ACMP_VREF_CRVSSEL_Msk | 0x2UL)
57 #define ACMP_VNEG_7_OVER_24_IREF (ACMP_VREF_CRVSSEL_Msk | 0x3UL)
58 #define ACMP_VNEG_8_OVER_24_IREF (ACMP_VREF_CRVSSEL_Msk | 0x4UL)
59 #define ACMP_VNEG_9_OVER_24_IREF (ACMP_VREF_CRVSSEL_Msk | 0x5UL)
60 #define ACMP_VNEG_10_OVER_24_IREF (ACMP_VREF_CRVSSEL_Msk | 0x6UL)
61 #define ACMP_VNEG_11_OVER_24_IREF (ACMP_VREF_CRVSSEL_Msk | 0x7UL)
62 #define ACMP_VNEG_12_OVER_24_IREF (ACMP_VREF_CRVSSEL_Msk | 0x8UL)
63 #define ACMP_VNEG_13_OVER_24_IREF (ACMP_VREF_CRVSSEL_Msk | 0x9UL)
64 #define ACMP_VNEG_14_OVER_24_IREF (ACMP_VREF_CRVSSEL_Msk | 0xAUL)
65 #define ACMP_VNEG_15_OVER_24_IREF (ACMP_VREF_CRVSSEL_Msk | 0xBUL)
66 #define ACMP_VNEG_16_OVER_24_IREF (ACMP_VREF_CRVSSEL_Msk | 0xCUL)
67 #define ACMP_VNEG_17_OVER_24_IREF (ACMP_VREF_CRVSSEL_Msk | 0xDUL)
68 #define ACMP_VNEG_18_OVER_24_IREF (ACMP_VREF_CRVSSEL_Msk | 0xEUL)
69 #define ACMP_VNEG_19_OVER_24_IREF (ACMP_VREF_CRVSSEL_Msk | 0xFUL)
70
71 /* end of group NANO103_ACMP_EXPORTED_CONSTANTS */
72
73
121 #define ACMP_SET_NEG_SRC(acmp, u32ChNum, u32Src) do{\
122 if(u32Src & 0x80000000) {\
123 ACMP->CTL0 = (~u32Src);\
124 ACMP->CTL0 |= ACMP_CTL0_ACMPEN_Msk;\
125 }\
126 else {\
127 ACMP->CTL0 = ((1 << ACMP_CTL0_NEGSEL_Pos));\
128 ACMP->CTL0 |= ACMP_CTL0_ACMPEN_Msk;\
129 ACMP->VREF = (u32Src | ACMP_VREF_CRVEN_Msk);\
130 }\
131 }while(0)
132
133
141 #define ACMP_ENABLE_HYSTERESIS(acmp,u32ChNum) (ACMP->CTL0 |= ACMP_CTL0_HYSEN_Msk)
142
150 #define ACMP_DISABLE_HYSTERESIS(acmp,u32ChNum) (ACMP->CTL0 &= ~ACMP_CTL0_HYSEN_Msk)
151
159 #define ACMP_ENABLE_INT(acmp,u32ChNum) (ACMP->CTL0 |= ACMP_CTL0_ACMPIE_Msk)
160
168 #define ACMP_DISABLE_INT(acmp,u32ChNum) (ACMP->CTL0 &= ~ACMP_CTL0_ACMPIE_Msk)
169
170
178 #define ACMP_ENABLE(acmp,u32ChNum) (ACMP->CTL0 |= ACMP_CTL0_ACMPEN_Msk)
179
187 #define ACMP_DISABLE(acmp,u32ChNum) (ACMP->CTL0 &= ~ACMP_CTL0_ACMPEN_Msk)
188
196 #define ACMP_GET_OUTPUT(acmp,u32ChNum) ((ACMP->STATUS & ACMP_STATUS_ACMPO_Msk) ? 1 : 0)
197
205 #define ACMP_GET_INT_FLAG(acmp,u32ChNum) (ACMP->STATUS & ACMP_STATUS_ACMPIF_Msk)
206
214 #define ACMP_CLR_INT_FLAG(acmp,u32ChNum) (ACMP->STATUS = ACMP_STATUS_ACMPIF_Msk)
215
223 #define ACMP_ENABLE_WAKEUP(acmp,u32ChNum) (ACMP->CTL0 |= ACMP_CTL0_WKEN_Msk)
224
232 #define ACMP_DISABLE_WAKEUP(acmp,u32ChNum) (ACMP->CTL0 &= ~ACMP_CTL0_WKEN_Msk)
233
273 #define ACMP_CRV_SEL(u32Level) (ACMP->VREF = (ACMP->VREF & ~(ACMP_VREF_CRVSSEL_Msk | ACMP_VREF_CRVCTL_Msk))| u32Level)
274
281 #define ACMP_ENABLE_CRV(acmp) (ACMP->VREF |= ACMP_VREF_CRVEN_Msk)
282
289 #define ACMP_DISABLE_CRV(acmp) (ACMP->VREF &= ~ACMP_VREF_CRVEN_Msk)
290
291
292
293 void ACMP_Open(ACMP_T *acmp, uint32_t u32ChNum, uint32_t u32NegSrc, uint32_t u32HysteresisEn);
294 void ACMP_Close(ACMP_T *acmp, uint32_t u32ChNum);
295
296 /* end of group NANO103_ACMP_EXPORTED_FUNCTIONS */
298 /* end of group NANO103_ACMP_Driver */
300 /* end of group NANO103_Device_Driver */
302
303 #ifdef __cplusplus
304 }
305 #endif
306
307 #endif //__ACMP_H__
308
309 /*** (C) COPYRIGHT 2015 Nuvoton Technology Corp. ***/
ACMP_T
Definition: Nano103.h:24621
ACMP_Open
void ACMP_Open(ACMP_T *acmp, uint32_t u32ChNum, uint32_t u32NegSrc, uint32_t u32HysteresisEn)
This function open and configure comparator parameters.
Definition: acmp.c:80
ACMP_Close
void ACMP_Close(ACMP_T *acmp, uint32_t u32ChNum)
This function close comparator.
Definition: acmp.c:98