1 /***************************************************************************//**
2  * @file
3  * @brief Analog Comparator (ACMP) peripheral API
4  *******************************************************************************
5  * # License
6  * <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
7  *******************************************************************************
8  *
9  * SPDX-License-Identifier: Zlib
10  *
11  * The licensor of this software is Silicon Laboratories Inc.
12  *
13  * This software is provided 'as-is', without any express or implied
14  * warranty. In no event will the authors be held liable for any damages
15  * arising from the use of this software.
16  *
17  * Permission is granted to anyone to use this software for any purpose,
18  * including commercial applications, and to alter it and redistribute it
19  * freely, subject to the following restrictions:
20  *
21  * 1. The origin of this software must not be misrepresented; you must not
22  *    claim that you wrote the original software. If you use this software
23  *    in a product, an acknowledgment in the product documentation would be
24  *    appreciated but is not required.
25  * 2. Altered source versions must be plainly marked as such, and must not be
26  *    misrepresented as being the original software.
27  * 3. This notice may not be removed or altered from any source distribution.
28  *
29  ******************************************************************************/
30 
31 #ifndef EM_ACMP_H
32 #define EM_ACMP_H
33 
34 #include "em_device.h"
35 #include "em_gpio.h"
36 
37 #if defined(ACMP_COUNT) && (ACMP_COUNT > 0)
38 
39 #include <stdint.h>
40 #include <stdbool.h>
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /***************************************************************************//**
47  * @addtogroup acmp
48  * @{
49  ******************************************************************************/
50 
51 /*******************************************************************************
52  ********************************   ENUMS   ************************************
53  ******************************************************************************/
54 
55 /** Resistor values used for the internal capacitive sense resistor. See
56  *  data sheet for your device for details on each resistor value. */
57 typedef enum {
58 #if defined(_ACMP_INPUTCTRL_CSRESSEL_MASK)
59   acmpResistor0 = _ACMP_INPUTCTRL_CSRESSEL_RES0,   /**< Resistor value 0 */
60   acmpResistor1 = _ACMP_INPUTCTRL_CSRESSEL_RES1,   /**< Resistor value 1 */
61   acmpResistor2 = _ACMP_INPUTCTRL_CSRESSEL_RES2,   /**< Resistor value 2 */
62   acmpResistor3 = _ACMP_INPUTCTRL_CSRESSEL_RES3,   /**< Resistor value 3 */
63   acmpResistor4 = _ACMP_INPUTCTRL_CSRESSEL_RES4,   /**< Resistor value 4 */
64   acmpResistor5 = _ACMP_INPUTCTRL_CSRESSEL_RES5,   /**< Resistor value 5 */
65   acmpResistor6 = _ACMP_INPUTCTRL_CSRESSEL_RES6,   /**< Resistor value 6 */
66 #else
67   acmpResistor0 = _ACMP_INPUTSEL_CSRESSEL_RES0,   /**< Resistor value 0 */
68   acmpResistor1 = _ACMP_INPUTSEL_CSRESSEL_RES1,   /**< Resistor value 1 */
69   acmpResistor2 = _ACMP_INPUTSEL_CSRESSEL_RES2,   /**< Resistor value 2 */
70   acmpResistor3 = _ACMP_INPUTSEL_CSRESSEL_RES3,   /**< Resistor value 3 */
71 #if defined(_ACMP_INPUTSEL_CSRESSEL_RES4)
72   acmpResistor4 = _ACMP_INPUTSEL_CSRESSEL_RES4,   /**< Resistor value 4 */
73   acmpResistor5 = _ACMP_INPUTSEL_CSRESSEL_RES5,   /**< Resistor value 5 */
74   acmpResistor6 = _ACMP_INPUTSEL_CSRESSEL_RES6,   /**< Resistor value 6 */
75   acmpResistor7 = _ACMP_INPUTSEL_CSRESSEL_RES7,   /**< Resistor value 7 */
76 #endif
77 #endif
78 } ACMP_CapsenseResistor_TypeDef;
79 
80 /** Hysteresis level. See data sheet for your device for details on each
81  *  level. */
82 typedef enum {
83 #if defined(_ACMP_CTRL_HYSTSEL_MASK)
84   acmpHysteresisLevel0 = _ACMP_CTRL_HYSTSEL_HYST0,       /**< Hysteresis level 0 */
85   acmpHysteresisLevel1 = _ACMP_CTRL_HYSTSEL_HYST1,       /**< Hysteresis level 1 */
86   acmpHysteresisLevel2 = _ACMP_CTRL_HYSTSEL_HYST2,       /**< Hysteresis level 2 */
87   acmpHysteresisLevel3 = _ACMP_CTRL_HYSTSEL_HYST3,       /**< Hysteresis level 3 */
88   acmpHysteresisLevel4 = _ACMP_CTRL_HYSTSEL_HYST4,       /**< Hysteresis level 4 */
89   acmpHysteresisLevel5 = _ACMP_CTRL_HYSTSEL_HYST5,       /**< Hysteresis level 5 */
90   acmpHysteresisLevel6 = _ACMP_CTRL_HYSTSEL_HYST6,       /**< Hysteresis level 6 */
91   acmpHysteresisLevel7 = _ACMP_CTRL_HYSTSEL_HYST7        /**< Hysteresis level 7 */
92 #endif
93 #if defined(_ACMP_HYSTERESIS0_HYST_MASK)
94   acmpHysteresisLevel0 = _ACMP_HYSTERESIS0_HYST_HYST0,   /**< Hysteresis level 0 */
95   acmpHysteresisLevel1 = _ACMP_HYSTERESIS0_HYST_HYST1,   /**< Hysteresis level 1 */
96   acmpHysteresisLevel2 = _ACMP_HYSTERESIS0_HYST_HYST2,   /**< Hysteresis level 2 */
97   acmpHysteresisLevel3 = _ACMP_HYSTERESIS0_HYST_HYST3,   /**< Hysteresis level 3 */
98   acmpHysteresisLevel4 = _ACMP_HYSTERESIS0_HYST_HYST4,   /**< Hysteresis level 4 */
99   acmpHysteresisLevel5 = _ACMP_HYSTERESIS0_HYST_HYST5,   /**< Hysteresis level 5 */
100   acmpHysteresisLevel6 = _ACMP_HYSTERESIS0_HYST_HYST6,   /**< Hysteresis level 6 */
101   acmpHysteresisLevel7 = _ACMP_HYSTERESIS0_HYST_HYST7,   /**< Hysteresis level 7 */
102   acmpHysteresisLevel8 = _ACMP_HYSTERESIS0_HYST_HYST8,   /**< Hysteresis level 8 */
103   acmpHysteresisLevel9 = _ACMP_HYSTERESIS0_HYST_HYST9,   /**< Hysteresis level 9 */
104   acmpHysteresisLevel10 = _ACMP_HYSTERESIS0_HYST_HYST10, /**< Hysteresis level 10 */
105   acmpHysteresisLevel11 = _ACMP_HYSTERESIS0_HYST_HYST11, /**< Hysteresis level 11 */
106   acmpHysteresisLevel12 = _ACMP_HYSTERESIS0_HYST_HYST12, /**< Hysteresis level 12 */
107   acmpHysteresisLevel13 = _ACMP_HYSTERESIS0_HYST_HYST13, /**< Hysteresis level 13 */
108   acmpHysteresisLevel14 = _ACMP_HYSTERESIS0_HYST_HYST14, /**< Hysteresis level 14 */
109   acmpHysteresisLevel15 = _ACMP_HYSTERESIS0_HYST_HYST15, /**< Hysteresis level 15 */
110 #endif
111 #if defined(_ACMP_CFG_HYST_MASK)
112   acmpHysteresisDisabled = _ACMP_CFG_HYST_DISABLED,   /**< Mode DISABLED for ACMP_CFG */
113   acmpHysteresis10Sym = _ACMP_CFG_HYST_SYM10MV,     /**< Mode HYST10SYM for ACMP_CFG */
114   acmpHysteresis20Sym = _ACMP_CFG_HYST_SYM20MV,     /**< Mode HYST20SYM for ACMP_CFG */
115   acmpHysteresis30Sym = _ACMP_CFG_HYST_SYM30MV,     /**< Mode HYST30SYM for ACMP_CFG */
116   acmpHysteresis10Pos = _ACMP_CFG_HYST_POS10MV,     /**< Mode HYST10POS for ACMP_CFG */
117   acmpHysteresis20Pos = _ACMP_CFG_HYST_POS20MV,     /**< Mode HYST20POS for ACMP_CFG */
118   acmpHysteresis30Pos = _ACMP_CFG_HYST_POS30MV,     /**< Mode HYST30POS for ACMP_CFG */
119   acmpHysteresis10Neg = _ACMP_CFG_HYST_NEG10MV,     /**< Mode HYST10NEG for ACMP_CFG */
120   acmpHysteresis20Neg = _ACMP_CFG_HYST_NEG20MV,     /**< Mode HYST20NEG for ACMP_CFG */
121   acmpHysteresis30Neg = _ACMP_CFG_HYST_NEG30MV,     /**< Mode HYST30NEG for ACMP_CFG */
122 #endif
123 } ACMP_HysteresisLevel_TypeDef;
124 
125 #if defined(_ACMP_CTRL_WARMTIME_MASK)
126 /** ACMP warmup time. The delay is measured in HFPERCLK / HFPERCCLK cycles and should
127  *  be at least 10 us. */
128 typedef enum {
129   /** 4 cycles warmup */
130   acmpWarmTime4   = _ACMP_CTRL_WARMTIME_4CYCLES,
131   /** 8 cycles warmup */
132   acmpWarmTime8   = _ACMP_CTRL_WARMTIME_8CYCLES,
133   /** 16 cycles warmup */
134   acmpWarmTime16  = _ACMP_CTRL_WARMTIME_16CYCLES,
135   /** 32 cycles warmup */
136   acmpWarmTime32  = _ACMP_CTRL_WARMTIME_32CYCLES,
137   /** 64 cycles warmup */
138   acmpWarmTime64  = _ACMP_CTRL_WARMTIME_64CYCLES,
139   /** 128 cycles warmup */
140   acmpWarmTime128 = _ACMP_CTRL_WARMTIME_128CYCLES,
141   /** 256 cycles warmup */
142   acmpWarmTime256 = _ACMP_CTRL_WARMTIME_256CYCLES,
143   /** 512 cycles warmup */
144   acmpWarmTime512 = _ACMP_CTRL_WARMTIME_512CYCLES
145 } ACMP_WarmTime_TypeDef;
146 #endif
147 
148 #if defined(_ACMP_CTRL_INPUTRANGE_MASK) \
149   || defined(_ACMP_CFG_INPUTRANGE_MASK)
150 /**
151  * Adjust ACMP performance for a given input voltage range.
152  */
153 typedef enum {
154 #if defined(_ACMP_CTRL_INPUTRANGE_MASK)
155   acmpInputRangeFull = _ACMP_CTRL_INPUTRANGE_FULL,      /**< Input can be from 0 to VDD. */
156   acmpInputRangeHigh = _ACMP_CTRL_INPUTRANGE_GTVDDDIV2, /**< Input will always be greater than VDD/2. */
157   acmpInputRangeLow  = _ACMP_CTRL_INPUTRANGE_LTVDDDIV2  /**< Input will always be less than VDD/2. */
158 #elif defined(_ACMP_CFG_INPUTRANGE_MASK)
159   acmpInputRangeFull    = _ACMP_CFG_INPUTRANGE_FULL,    /**< Input can be from 0 to VDD. */
160   acmpInputRangeReduced = _ACMP_CFG_INPUTRANGE_REDUCED, /**< Input can be from 0 to VDD-0.7 V. */
161 #endif
162 } ACMP_InputRange_TypeDef;
163 #endif
164 
165 #if defined(_ACMP_CTRL_PWRSEL_MASK)
166 /**
167  * ACMP Power source.
168  */
169 typedef enum {
170   acmpPowerSourceAvdd      = _ACMP_CTRL_PWRSEL_AVDD,    /**< Power ACMP using the AVDD supply. */
171 #if defined(_ACMP_CTRL_PWRSEL_DVDD)
172   acmpPowerSourceDvdd      = _ACMP_CTRL_PWRSEL_DVDD,    /**< Power ACMP using the DVDD supply. */
173 #endif
174   acmpPowerSourceIOVdd0    = _ACMP_CTRL_PWRSEL_IOVDD0,  /**< Power ACMP using the IOVDD/IOVDD0 supply. */
175   acmpPowerSourceIOVdd1    = _ACMP_CTRL_PWRSEL_IOVDD1,  /**< Power ACMP using the IOVDD1 supply (if the part has two I/O voltages). */
176 } ACMP_PowerSource_TypeDef;
177 #endif
178 
179 #if defined(_ACMP_CTRL_ACCURACY_MASK) \
180   || defined(_ACMP_CFG_ACCURACY_MASK)
181 /**
182  * ACMP accuracy mode.
183  */
184 typedef enum {
185 #if defined(_ACMP_CTRL_ACCURACY_MASK)
186   acmpAccuracyLow = _ACMP_CTRL_ACCURACY_LOW,   /**< Low-accuracy mode which consumes less current. */
187   acmpAccuracyHigh = _ACMP_CTRL_ACCURACY_HIGH  /**< High-accuracy mode which consumes more current. */
188 #elif defined(_ACMP_CFG_ACCURACY_MASK)
189   acmpAccuracyLow = _ACMP_CFG_ACCURACY_LOW,   /**< Low-accuracy mode which consumes less current. */
190   acmpAccuracyHigh = _ACMP_CFG_ACCURACY_HIGH  /**< High-accuracy mode which consumes more current. */
191 #endif
192 } ACMP_Accuracy_TypeDef;
193 #endif
194 
195 #if defined(_ACMP_INPUTSEL_VASEL_MASK)
196 /** ACMP input to the VA divider. This enumeration is used to select the input for
197  *  the VA Divider. */
198 typedef enum {
199   acmpVAInputVDD         = _ACMP_INPUTSEL_VASEL_VDD,         /**< Select VDD for the VA divider. */
200   acmpVAInputAPORT2YCH0  = _ACMP_INPUTSEL_VASEL_APORT2YCH0,  /**< Select APORT2Y CHannel 0 for the VA divider. */
201   acmpVAInputAPORT2YCH2  = _ACMP_INPUTSEL_VASEL_APORT2YCH2,  /**< Select APORT2Y CHannel 2 for the VA divider. */
202   acmpVAInputAPORT2YCH4  = _ACMP_INPUTSEL_VASEL_APORT2YCH4,  /**< Select APORT2Y CHannel 4 for the VA divider. */
203   acmpVAInputAPORT2YCH6  = _ACMP_INPUTSEL_VASEL_APORT2YCH6,  /**< Select APORT2Y CHannel 6 for the VA divider. */
204   acmpVAInputAPORT2YCH8  = _ACMP_INPUTSEL_VASEL_APORT2YCH8,  /**< Select APORT2Y CHannel 8 for the VA divider. */
205   acmpVAInputAPORT2YCH10 = _ACMP_INPUTSEL_VASEL_APORT2YCH10, /**< Select APORT2Y CHannel 10 for the VA divider. */
206   acmpVAInputAPORT2YCH12 = _ACMP_INPUTSEL_VASEL_APORT2YCH12, /**< Select APORT2Y CHannel 12 for the VA divider. */
207   acmpVAInputAPORT2YCH14 = _ACMP_INPUTSEL_VASEL_APORT2YCH14, /**< Select APORT2Y CHannel 14 for the VA divider. */
208   acmpVAInputAPORT2YCH16 = _ACMP_INPUTSEL_VASEL_APORT2YCH16, /**< Select APORT2Y CHannel 16 for the VA divider. */
209   acmpVAInputAPORT2YCH18 = _ACMP_INPUTSEL_VASEL_APORT2YCH18, /**< Select APORT2Y CHannel 18 for the VA divider. */
210   acmpVAInputAPORT2YCH20 = _ACMP_INPUTSEL_VASEL_APORT2YCH20, /**< Select APORT2Y CHannel 20 for the VA divider. */
211   acmpVAInputAPORT2YCH22 = _ACMP_INPUTSEL_VASEL_APORT2YCH22, /**< Select APORT2Y CHannel 22 for the VA divider. */
212   acmpVAInputAPORT2YCH24 = _ACMP_INPUTSEL_VASEL_APORT2YCH24, /**< Select APORT2Y CHannel 24 for the VA divider. */
213   acmpVAInputAPORT2YCH26 = _ACMP_INPUTSEL_VASEL_APORT2YCH26, /**< Select APORT2Y CHannel 26 for the VA divider. */
214   acmpVAInputAPORT2YCH28 = _ACMP_INPUTSEL_VASEL_APORT2YCH28, /**< Select APORT2Y CHannel 28 for the VA divider. */
215   acmpVAInputAPORT2YCH30 = _ACMP_INPUTSEL_VASEL_APORT2YCH30, /**< Select APORT2Y CHannel 30 for the VA divider. */
216   acmpVAInputAPORT1XCH0  = _ACMP_INPUTSEL_VASEL_APORT1XCH0,  /**< Select APORT1X CHannel 0 for the VA divider. */
217   acmpVAInputAPORT1YCH1  = _ACMP_INPUTSEL_VASEL_APORT1YCH1,  /**< Select APORT1Y CHannel 1 for the VA divider. */
218   acmpVAInputAPORT1XCH2  = _ACMP_INPUTSEL_VASEL_APORT1XCH2,  /**< Select APORT1X CHannel 2 for the VA divider. */
219   acmpVAInputAPORT1YCH3  = _ACMP_INPUTSEL_VASEL_APORT1YCH3,  /**< Select APORT1Y CHannel 3 for the VA divider. */
220   acmpVAInputAPORT1XCH4  = _ACMP_INPUTSEL_VASEL_APORT1XCH4,  /**< Select APORT1X CHannel 4 for the VA divider. */
221   acmpVAInputAPORT1YCH5  = _ACMP_INPUTSEL_VASEL_APORT1YCH5,  /**< Select APORT1Y CHannel 5 for the VA divider. */
222   acmpVAInputAPORT1XCH6  = _ACMP_INPUTSEL_VASEL_APORT1XCH6,  /**< Select APORT1X CHannel 6 for the VA divider. */
223   acmpVAInputAPORT1YCH7  = _ACMP_INPUTSEL_VASEL_APORT1YCH7,  /**< Select APORT1Y CHannel 7 for the VA divider. */
224   acmpVAInputAPORT1XCH8  = _ACMP_INPUTSEL_VASEL_APORT1XCH8,  /**< Select APORT1X CHannel 8 for the VA divider. */
225   acmpVAInputAPORT1YCH9  = _ACMP_INPUTSEL_VASEL_APORT1YCH9,  /**< Select APORT1Y CHannel 9 for the VA divider. */
226   acmpVAInputAPORT1XCH10 = _ACMP_INPUTSEL_VASEL_APORT1XCH10, /**< Select APORT1X CHannel 10 for the VA divider. */
227   acmpVAInputAPORT1YCH11 = _ACMP_INPUTSEL_VASEL_APORT1YCH11, /**< Select APORT1Y CHannel 11 for the VA divider. */
228   acmpVAInputAPORT1XCH12 = _ACMP_INPUTSEL_VASEL_APORT1XCH12, /**< Select APORT1X CHannel 12 for the VA divider. */
229   acmpVAInputAPORT1YCH13 = _ACMP_INPUTSEL_VASEL_APORT1YCH13, /**< Select APORT1Y CHannel 13 for the VA divider. */
230   acmpVAInputAPORT1XCH14 = _ACMP_INPUTSEL_VASEL_APORT1XCH14, /**< Select APORT1X CHannel 14 for the VA divider. */
231   acmpVAInputAPORT1YCH15 = _ACMP_INPUTSEL_VASEL_APORT1YCH15, /**< Select APORT1Y CHannel 15 for the VA divider. */
232   acmpVAInputAPORT1XCH16 = _ACMP_INPUTSEL_VASEL_APORT1XCH16, /**< Select APORT1X CHannel 16 for the VA divider. */
233   acmpVAInputAPORT1YCH17 = _ACMP_INPUTSEL_VASEL_APORT1YCH17, /**< Select APORT1Y CHannel 17 for the VA divider. */
234   acmpVAInputAPORT1XCH18 = _ACMP_INPUTSEL_VASEL_APORT1XCH18, /**< Select APORT1X CHannel 18 for the VA divider. */
235   acmpVAInputAPORT1YCH19 = _ACMP_INPUTSEL_VASEL_APORT1YCH19, /**< Select APORT1Y CHannel 19 for the VA divider. */
236   acmpVAInputAPORT1XCH20 = _ACMP_INPUTSEL_VASEL_APORT1XCH20, /**< Select APORT1X CHannel 20 for the VA divider. */
237   acmpVAInputAPORT1YCH21 = _ACMP_INPUTSEL_VASEL_APORT1YCH21, /**< Select APORT1Y CHannel 21 for the VA divider. */
238   acmpVAInputAPORT1XCH22 = _ACMP_INPUTSEL_VASEL_APORT1XCH22, /**< Select APORT1X CHannel 22 for the VA divider. */
239   acmpVAInputAPORT1YCH23 = _ACMP_INPUTSEL_VASEL_APORT1YCH23, /**< Select APORT1Y CHannel 23 for the VA divider. */
240   acmpVAInputAPORT1XCH24 = _ACMP_INPUTSEL_VASEL_APORT1XCH24, /**< Select APORT1X CHannel 24 for the VA divider. */
241   acmpVAInputAPORT1YCH25 = _ACMP_INPUTSEL_VASEL_APORT1YCH25, /**< Select APORT1Y CHannel 25 for the VA divider. */
242   acmpVAInputAPORT1XCH26 = _ACMP_INPUTSEL_VASEL_APORT1XCH26, /**< Select APORT1X CHannel 26 for the VA divider. */
243   acmpVAInputAPORT1YCH27 = _ACMP_INPUTSEL_VASEL_APORT1YCH27, /**< Select APORT1Y CHannel 27 for the VA divider. */
244   acmpVAInputAPORT1XCH28 = _ACMP_INPUTSEL_VASEL_APORT1XCH28, /**< Select APORT1X CHannel 28 for the VA divider. */
245   acmpVAInputAPORT1YCH29 = _ACMP_INPUTSEL_VASEL_APORT1YCH29, /**< Select APORT1Y CHannel 29 for the VA divider. */
246   acmpVAInputAPORT1XCH30 = _ACMP_INPUTSEL_VASEL_APORT1XCH30, /**< Select APORT1X CHannel 30 for the VA divider. */
247   acmpVAInputAPORT1YCH31 = _ACMP_INPUTSEL_VASEL_APORT1YCH31  /**< Select APORT1Y CHannel 31 for the VA divider. */
248 } ACMP_VAInput_TypeDef;
249 #endif
250 
251 #if defined(_ACMP_INPUTSEL_VBSEL_MASK)
252 /**
253  * ACMP input to the VB divider. This enumeration is used to select the input for
254  * the VB divider.
255  */
256 typedef enum {
257   acmpVBInput1V25 = _ACMP_INPUTSEL_VBSEL_1V25, /**< Mode 1V25 for ACMP_INPUTSEL */
258   acmpVBInput2V5  = _ACMP_INPUTSEL_VBSEL_2V5   /**< Mode 2V5 for ACMP_INPUTSEL */
259 } ACMP_VBInput_TypeDef;
260 #endif
261 
262 #if defined(_ACMP_INPUTSEL_VLPSEL_MASK)
263 /**
264  * ACMP Low-Power Input Selection.
265  */
266 typedef enum {
267   acmpVLPInputVADIV = _ACMP_INPUTSEL_VLPSEL_VADIV, /**< Mode VADIV for ACMP_INPUTSEL */
268   acmpVLPInputVBDIV = _ACMP_INPUTSEL_VLPSEL_VBDIV  /**< Mode VBDIV for ACMP_INPUTSEL */
269 } ACMP_VLPInput_Typedef;
270 #endif
271 
272 #if defined(_ACMP_INPUTCTRL_MASK)
273 /** ACMP Input Selection. */
274 typedef enum {
275   acmpInputVSS            = _ACMP_INPUTCTRL_POSSEL_VSS,            /**< Select VSS. */
276   acmpInputVREFDIVAVDD    = _ACMP_INPUTCTRL_POSSEL_VREFDIVAVDD,    /**< Select Divided AVDD. */
277   acmpInputVREFDIVAVDDLP  = _ACMP_INPUTCTRL_POSSEL_VREFDIVAVDDLP,  /**< Select Low-Power Divided AVDD. */
278   acmpInputVREFDIV1V25    = _ACMP_INPUTCTRL_POSSEL_VREFDIV1V25,    /**< Select Divided 1V25 reference. */
279   acmpInputVREFDIV1V25LP  = _ACMP_INPUTCTRL_POSSEL_VREFDIV1V25LP,  /**< Select Low-power Divided 1V25 reference. */
280   acmpInputVREFDIV2V5     = _ACMP_INPUTCTRL_POSSEL_VREFDIV2V5,     /**< Select Divided 2V5 reference. */
281   acmpInputVREFDIV2V5LP   = _ACMP_INPUTCTRL_POSSEL_VREFDIV2V5LP,   /**< Select Low-power Divided 2V5 reference. */
282   acmpInputVSENSE01DIV4   = _ACMP_INPUTCTRL_POSSEL_VSENSE01DIV4,   /**< Select VSENSE0 divided by 4. */
283   acmpInputVSENSE01DIV4LP = _ACMP_INPUTCTRL_POSSEL_VSENSE01DIV4LP, /**< Select Low-power VSENSE0 divided by 4. */
284   acmpInputVSENSE11DIV4   = _ACMP_INPUTCTRL_POSSEL_VSENSE11DIV4,   /**< VSENSE1 divided by 4. */
285   acmpInputVSENSE11DIV4LP = _ACMP_INPUTCTRL_POSSEL_VSENSE11DIV4LP, /**< Low-power VSENSE1 divided by 4. */
286   acmpInputCAPSENSE       = _ACMP_INPUTCTRL_NEGSEL_CAPSENSE,       /**< Select Low-Power Divided AVDD. */
287 #if defined(_ACMP_INPUTCTRL_POSSEL_VDACOUT0)
288   acmpInputVDACOUT0       = _ACMP_INPUTCTRL_POSSEL_VDACOUT0, /**< Select VDAC0 channel 0 output. */
289   acmpInputVDACOUT1       = _ACMP_INPUTCTRL_POSSEL_VDACOUT1, /**< Select VDAC0 channel 1 output. */
290 #endif
291 #if (_SILICON_LABS_32B_SERIES_2_CONFIG > 2)
292   acmpInputEXTPA          = _ACMP_INPUTCTRL_POSSEL_EXTPA,  /**< Select external interface, base is PA0. */
293   acmpInputEXTPB          = _ACMP_INPUTCTRL_POSSEL_EXTPB,  /**< Select external interface, base is PB0. */
294   acmpInputEXTPC          = _ACMP_INPUTCTRL_POSSEL_EXTPC,  /**< Select external interface, base is PC0. */
295   acmpInputEXTPD          = _ACMP_INPUTCTRL_POSSEL_EXTPD,  /**< Select external interface, base is PD0. */
296 #endif
297   acmpInputPA0            = _ACMP_INPUTCTRL_POSSEL_PA0,  /**< Select Port A Pin0. */
298   acmpInputPA1            = _ACMP_INPUTCTRL_POSSEL_PA1,  /**< Select Port A Pin1. */
299   acmpInputPA2            = _ACMP_INPUTCTRL_POSSEL_PA2,  /**< Select Port A Pin2. */
300   acmpInputPA3            = _ACMP_INPUTCTRL_POSSEL_PA3,  /**< Select Port A Pin3. */
301   acmpInputPA4            = _ACMP_INPUTCTRL_POSSEL_PA4,  /**< Select Port A Pin4. */
302   acmpInputPA5            = _ACMP_INPUTCTRL_POSSEL_PA5,  /**< Select Port A Pin5. */
303   acmpInputPA6            = _ACMP_INPUTCTRL_POSSEL_PA6,  /**< Select Port A Pin6. */
304   acmpInputPA7            = _ACMP_INPUTCTRL_POSSEL_PA7,  /**< Select Port A Pin7. */
305   acmpInputPA8            = _ACMP_INPUTCTRL_POSSEL_PA8,  /**< Select Port A Pin8. */
306   acmpInputPA9            = _ACMP_INPUTCTRL_POSSEL_PA9,  /**< Select Port A Pin9. */
307   acmpInputPA10           = _ACMP_INPUTCTRL_POSSEL_PA10, /**< Select Port A Pin10. */
308   acmpInputPA11           = _ACMP_INPUTCTRL_POSSEL_PA11, /**< Select Port A Pin11. */
309   acmpInputPA12           = _ACMP_INPUTCTRL_POSSEL_PA12, /**< Select Port A Pin12. */
310   acmpInputPA13           = _ACMP_INPUTCTRL_POSSEL_PA13, /**< Select Port A Pin13. */
311   acmpInputPA14           = _ACMP_INPUTCTRL_POSSEL_PA14, /**< Select Port A Pin14. */
312   acmpInputPA15           = _ACMP_INPUTCTRL_POSSEL_PA15, /**< Select Port A Pin15. */
313   acmpInputPB0            = _ACMP_INPUTCTRL_POSSEL_PB0,  /**< Select Port B Pin0. */
314   acmpInputPB1            = _ACMP_INPUTCTRL_POSSEL_PB1,  /**< Select Port B Pin1. */
315   acmpInputPB2            = _ACMP_INPUTCTRL_POSSEL_PB2,  /**< Select Port B Pin2. */
316   acmpInputPB3            = _ACMP_INPUTCTRL_POSSEL_PB3,  /**< Select Port B Pin3. */
317   acmpInputPB4            = _ACMP_INPUTCTRL_POSSEL_PB4,  /**< Select Port B Pin4. */
318   acmpInputPB5            = _ACMP_INPUTCTRL_POSSEL_PB5,  /**< Select Port B Pin5. */
319   acmpInputPB6            = _ACMP_INPUTCTRL_POSSEL_PB6,  /**< Select Port B Pin6. */
320   acmpInputPB7            = _ACMP_INPUTCTRL_POSSEL_PB7,  /**< Select Port B Pin7. */
321   acmpInputPB8            = _ACMP_INPUTCTRL_POSSEL_PB8,  /**< Select Port B Pin8. */
322   acmpInputPB9            = _ACMP_INPUTCTRL_POSSEL_PB9,  /**< Select Port B Pin9. */
323   acmpInputPB10           = _ACMP_INPUTCTRL_POSSEL_PB10, /**< Select Port B Pin10. */
324   acmpInputPB11           = _ACMP_INPUTCTRL_POSSEL_PB11, /**< Select Port B Pin11. */
325   acmpInputPB12           = _ACMP_INPUTCTRL_POSSEL_PB12, /**< Select Port B Pin12. */
326   acmpInputPB13           = _ACMP_INPUTCTRL_POSSEL_PB13, /**< Select Port B Pin13. */
327   acmpInputPB14           = _ACMP_INPUTCTRL_POSSEL_PB14, /**< Select Port B Pin14. */
328   acmpInputPB15           = _ACMP_INPUTCTRL_POSSEL_PB15, /**< Select Port B Pin15. */
329   acmpInputPC0            = _ACMP_INPUTCTRL_POSSEL_PC0,  /**< Select Port C Pin0. */
330   acmpInputPC1            = _ACMP_INPUTCTRL_POSSEL_PC1,  /**< Select Port C Pin1. */
331   acmpInputPC2            = _ACMP_INPUTCTRL_POSSEL_PC2,  /**< Select Port C Pin2. */
332   acmpInputPC3            = _ACMP_INPUTCTRL_POSSEL_PC3,  /**< Select Port C Pin3. */
333   acmpInputPC4            = _ACMP_INPUTCTRL_POSSEL_PC4,  /**< Select Port C Pin4. */
334   acmpInputPC5            = _ACMP_INPUTCTRL_POSSEL_PC5,  /**< Select Port C Pin5. */
335   acmpInputPC6            = _ACMP_INPUTCTRL_POSSEL_PC6,  /**< Select Port C Pin6. */
336   acmpInputPC7            = _ACMP_INPUTCTRL_POSSEL_PC7,  /**< Select Port C Pin7. */
337   acmpInputPC8            = _ACMP_INPUTCTRL_POSSEL_PC8,  /**< Select Port C Pin8. */
338   acmpInputPC9            = _ACMP_INPUTCTRL_POSSEL_PC9,  /**< Select Port C Pin9. */
339   acmpInputPC10           = _ACMP_INPUTCTRL_POSSEL_PC10, /**< Select Port C Pin10. */
340   acmpInputPC11           = _ACMP_INPUTCTRL_POSSEL_PC11, /**< Select Port C Pin11. */
341   acmpInputPC12           = _ACMP_INPUTCTRL_POSSEL_PC12, /**< Select Port C Pin12. */
342   acmpInputPC13           = _ACMP_INPUTCTRL_POSSEL_PC13, /**< Select Port C Pin13. */
343   acmpInputPC14           = _ACMP_INPUTCTRL_POSSEL_PC14, /**< Select Port C Pin14. */
344   acmpInputPC15           = _ACMP_INPUTCTRL_POSSEL_PC15, /**< Select Port C Pin15. */
345   acmpInputPD0            = _ACMP_INPUTCTRL_POSSEL_PD0,  /**< Select Port D Pin0. */
346   acmpInputPD1            = _ACMP_INPUTCTRL_POSSEL_PD1,  /**< Select Port D Pin1. */
347   acmpInputPD2            = _ACMP_INPUTCTRL_POSSEL_PD2,  /**< Select Port D Pin2. */
348   acmpInputPD3            = _ACMP_INPUTCTRL_POSSEL_PD3,  /**< Select Port D Pin3. */
349   acmpInputPD4            = _ACMP_INPUTCTRL_POSSEL_PD4,  /**< Select Port D Pin4. */
350   acmpInputPD5            = _ACMP_INPUTCTRL_POSSEL_PD5,  /**< Select Port D Pin5. */
351   acmpInputPD6            = _ACMP_INPUTCTRL_POSSEL_PD6,  /**< Select Port D Pin6. */
352   acmpInputPD7            = _ACMP_INPUTCTRL_POSSEL_PD7,  /**< Select Port D Pin7. */
353   acmpInputPD8            = _ACMP_INPUTCTRL_POSSEL_PD8,  /**< Select Port D Pin8. */
354   acmpInputPD9            = _ACMP_INPUTCTRL_POSSEL_PD9,  /**< Select Port D Pin9. */
355   acmpInputPD10           = _ACMP_INPUTCTRL_POSSEL_PD10, /**< Select Port D Pin10. */
356   acmpInputPD11           = _ACMP_INPUTCTRL_POSSEL_PD11, /**< Select Port D Pin11. */
357   acmpInputPD12           = _ACMP_INPUTCTRL_POSSEL_PD12, /**< Select Port D Pin12. */
358   acmpInputPD13           = _ACMP_INPUTCTRL_POSSEL_PD13, /**< Select Port D Pin13. */
359   acmpInputPD14           = _ACMP_INPUTCTRL_POSSEL_PD14, /**< Select Port D Pin14. */
360   acmpInputPD15           = _ACMP_INPUTCTRL_POSSEL_PD15, /**< Select Port D Pin15. */
361 } ACMP_Channel_TypeDef;
362 #elif defined(_ACMP_INPUTSEL_POSSEL_APORT0XCH0)
363 /** ACMP Input Selection. */
364 typedef enum {
365   acmpInputAPORT0XCH0  = _ACMP_INPUTSEL_POSSEL_APORT0XCH0,  /**< Select Dedicated APORT0X CHannel 0. */
366   acmpInputAPORT0XCH1  = _ACMP_INPUTSEL_POSSEL_APORT0XCH1,  /**< Select Dedicated APORT0X CHannel 1. */
367   acmpInputAPORT0XCH2  = _ACMP_INPUTSEL_POSSEL_APORT0XCH2,  /**< Select Dedicated APORT0X CHannel 2. */
368   acmpInputAPORT0XCH3  = _ACMP_INPUTSEL_POSSEL_APORT0XCH3,  /**< Select Dedicated APORT0X CHannel 3. */
369   acmpInputAPORT0XCH4  = _ACMP_INPUTSEL_POSSEL_APORT0XCH4,  /**< Select Dedicated APORT0X CHannel 4. */
370   acmpInputAPORT0XCH5  = _ACMP_INPUTSEL_POSSEL_APORT0XCH5,  /**< Select Dedicated APORT0X CHannel 5. */
371   acmpInputAPORT0XCH6  = _ACMP_INPUTSEL_POSSEL_APORT0XCH6,  /**< Select Dedicated APORT0X CHannel 6. */
372   acmpInputAPORT0XCH7  = _ACMP_INPUTSEL_POSSEL_APORT0XCH7,  /**< Select Dedicated APORT0X CHannel 7. */
373   acmpInputAPORT0XCH8  = _ACMP_INPUTSEL_POSSEL_APORT0XCH8,  /**< Select Dedicated APORT0X CHannel 8. */
374   acmpInputAPORT0XCH9  = _ACMP_INPUTSEL_POSSEL_APORT0XCH9,  /**< Select Dedicated APORT0X CHannel 9. */
375   acmpInputAPORT0XCH10 = _ACMP_INPUTSEL_POSSEL_APORT0XCH10, /**< Select Dedicated APORT0X CHannel 10. */
376   acmpInputAPORT0XCH11 = _ACMP_INPUTSEL_POSSEL_APORT0XCH11, /**< Select Dedicated APORT0X CHannel 11. */
377   acmpInputAPORT0XCH12 = _ACMP_INPUTSEL_POSSEL_APORT0XCH12, /**< Select Dedicated APORT0X CHannel 12. */
378   acmpInputAPORT0XCH13 = _ACMP_INPUTSEL_POSSEL_APORT0XCH13, /**< Select Dedicated APORT0X CHannel 13. */
379   acmpInputAPORT0XCH14 = _ACMP_INPUTSEL_POSSEL_APORT0XCH14, /**< Select Dedicated APORT0X CHannel 14. */
380   acmpInputAPORT0XCH15 = _ACMP_INPUTSEL_POSSEL_APORT0XCH15, /**< Select Dedicated APORT0X CHannel 15. */
381   acmpInputAPORT0YCH0  = _ACMP_INPUTSEL_POSSEL_APORT0YCH0,  /**< Select Dedicated APORT0Y CHannel 0. */
382   acmpInputAPORT0YCH1  = _ACMP_INPUTSEL_POSSEL_APORT0YCH1,  /**< Select Dedicated APORT0Y CHannel 1. */
383   acmpInputAPORT0YCH2  = _ACMP_INPUTSEL_POSSEL_APORT0YCH2,  /**< Select Dedicated APORT0Y CHannel 2. */
384   acmpInputAPORT0YCH3  = _ACMP_INPUTSEL_POSSEL_APORT0YCH3,  /**< Select Dedicated APORT0Y CHannel 3. */
385   acmpInputAPORT0YCH4  = _ACMP_INPUTSEL_POSSEL_APORT0YCH4,  /**< Select Dedicated APORT0Y CHannel 4. */
386   acmpInputAPORT0YCH5  = _ACMP_INPUTSEL_POSSEL_APORT0YCH5,  /**< Select Dedicated APORT0Y CHannel 5. */
387   acmpInputAPORT0YCH6  = _ACMP_INPUTSEL_POSSEL_APORT0YCH6,  /**< Select Dedicated APORT0Y CHannel 6. */
388   acmpInputAPORT0YCH7  = _ACMP_INPUTSEL_POSSEL_APORT0YCH7,  /**< Select Dedicated APORT0Y CHannel 7. */
389   acmpInputAPORT0YCH8  = _ACMP_INPUTSEL_POSSEL_APORT0YCH8,  /**< Select Dedicated APORT0Y CHannel 8. */
390   acmpInputAPORT0YCH9  = _ACMP_INPUTSEL_POSSEL_APORT0YCH9,  /**< Select Dedicated APORT0Y CHannel 9. */
391   acmpInputAPORT0YCH10 = _ACMP_INPUTSEL_POSSEL_APORT0YCH10, /**< Select Dedicated APORT0Y CHannel 10. */
392   acmpInputAPORT0YCH11 = _ACMP_INPUTSEL_POSSEL_APORT0YCH11, /**< Select Dedicated APORT0Y CHannel 11. */
393   acmpInputAPORT0YCH12 = _ACMP_INPUTSEL_POSSEL_APORT0YCH12, /**< Select Dedicated APORT0Y CHannel 12. */
394   acmpInputAPORT0YCH13 = _ACMP_INPUTSEL_POSSEL_APORT0YCH13, /**< Select Dedicated APORT0Y CHannel 13. */
395   acmpInputAPORT0YCH14 = _ACMP_INPUTSEL_POSSEL_APORT0YCH14, /**< Select Dedicated APORT0Y CHannel 14. */
396   acmpInputAPORT0YCH15 = _ACMP_INPUTSEL_POSSEL_APORT0YCH15, /**< Select Dedicated APORT0Y CHannel 15. */
397   acmpInputAPORT1XCH0  = _ACMP_INPUTSEL_POSSEL_APORT1XCH0,  /**< Select Dedicated APORT1X CHannel 0. */
398   acmpInputAPORT1YCH1  = _ACMP_INPUTSEL_POSSEL_APORT1YCH1,  /**< Select Dedicated APORT1Y CHannel 1. */
399   acmpInputAPORT1XCH2  = _ACMP_INPUTSEL_POSSEL_APORT1XCH2,  /**< Select Dedicated APORT1X CHannel 2. */
400   acmpInputAPORT1YCH3  = _ACMP_INPUTSEL_POSSEL_APORT1YCH3,  /**< Select Dedicated APORT1Y CHannel 3. */
401   acmpInputAPORT1XCH4  = _ACMP_INPUTSEL_POSSEL_APORT1XCH4,  /**< Select Dedicated APORT1X CHannel 4. */
402   acmpInputAPORT1YCH5  = _ACMP_INPUTSEL_POSSEL_APORT1YCH5,  /**< Select Dedicated APORT1Y CHannel 5. */
403   acmpInputAPORT1XCH6  = _ACMP_INPUTSEL_POSSEL_APORT1XCH6,  /**< Select Dedicated APORT1X CHannel 6. */
404   acmpInputAPORT1YCH7  = _ACMP_INPUTSEL_POSSEL_APORT1YCH7,  /**< Select Dedicated APORT1Y CHannel 7. */
405   acmpInputAPORT1XCH8  = _ACMP_INPUTSEL_POSSEL_APORT1XCH8,  /**< Select Dedicated APORT1X CHannel 8. */
406   acmpInputAPORT1YCH9  = _ACMP_INPUTSEL_POSSEL_APORT1YCH9,  /**< Select Dedicated APORT1Y CHannel 9. */
407   acmpInputAPORT1XCH10 = _ACMP_INPUTSEL_POSSEL_APORT1XCH10, /**< Select Dedicated APORT1X CHannel 10. */
408   acmpInputAPORT1YCH11 = _ACMP_INPUTSEL_POSSEL_APORT1YCH11, /**< Select Dedicated APORT1Y CHannel 11. */
409   acmpInputAPORT1XCH12 = _ACMP_INPUTSEL_POSSEL_APORT1XCH12, /**< Select Dedicated APORT1X CHannel 12. */
410   acmpInputAPORT1YCH13 = _ACMP_INPUTSEL_POSSEL_APORT1YCH13, /**< Select Dedicated APORT1Y CHannel 13. */
411   acmpInputAPORT1XCH14 = _ACMP_INPUTSEL_POSSEL_APORT1XCH14, /**< Select Dedicated APORT1X CHannel 14. */
412   acmpInputAPORT1YCH15 = _ACMP_INPUTSEL_POSSEL_APORT1YCH15, /**< Select Dedicated APORT1Y CHannel 15. */
413   acmpInputAPORT1XCH16 = _ACMP_INPUTSEL_POSSEL_APORT1XCH16, /**< Select Dedicated APORT1X CHannel 16. */
414   acmpInputAPORT1YCH17 = _ACMP_INPUTSEL_POSSEL_APORT1YCH17, /**< Select Dedicated APORT1Y CHannel 17. */
415   acmpInputAPORT1XCH18 = _ACMP_INPUTSEL_POSSEL_APORT1XCH18, /**< Select Dedicated APORT1X CHannel 18. */
416   acmpInputAPORT1YCH19 = _ACMP_INPUTSEL_POSSEL_APORT1YCH19, /**< Select Dedicated APORT1Y CHannel 19. */
417   acmpInputAPORT1XCH20 = _ACMP_INPUTSEL_POSSEL_APORT1XCH20, /**< Select Dedicated APORT1X CHannel 20. */
418   acmpInputAPORT1YCH21 = _ACMP_INPUTSEL_POSSEL_APORT1YCH21, /**< Select Dedicated APORT1Y CHannel 21. */
419   acmpInputAPORT1XCH22 = _ACMP_INPUTSEL_POSSEL_APORT1XCH22, /**< Select Dedicated APORT1X CHannel 22. */
420   acmpInputAPORT1YCH23 = _ACMP_INPUTSEL_POSSEL_APORT1YCH23, /**< Select Dedicated APORT1Y CHannel 23. */
421   acmpInputAPORT1XCH24 = _ACMP_INPUTSEL_POSSEL_APORT1XCH24, /**< Select Dedicated APORT1X CHannel 24. */
422   acmpInputAPORT1YCH25 = _ACMP_INPUTSEL_POSSEL_APORT1YCH25, /**< Select Dedicated APORT1Y CHannel 25. */
423   acmpInputAPORT1XCH26 = _ACMP_INPUTSEL_POSSEL_APORT1XCH26, /**< Select Dedicated APORT1X CHannel 26. */
424   acmpInputAPORT1YCH27 = _ACMP_INPUTSEL_POSSEL_APORT1YCH27, /**< Select Dedicated APORT1Y CHannel 27. */
425   acmpInputAPORT1XCH28 = _ACMP_INPUTSEL_POSSEL_APORT1XCH28, /**< Select Dedicated APORT1X CHannel 28. */
426   acmpInputAPORT1YCH29 = _ACMP_INPUTSEL_POSSEL_APORT1YCH29, /**< Select Dedicated APORT1Y CHannel 29. */
427   acmpInputAPORT1XCH30 = _ACMP_INPUTSEL_POSSEL_APORT1XCH30, /**< Select Dedicated APORT1X CHannel 30. */
428   acmpInputAPORT1YCH31 = _ACMP_INPUTSEL_POSSEL_APORT1YCH31, /**< Select Dedicated APORT1Y CHannel 31. */
429   acmpInputAPORT2YCH0  = _ACMP_INPUTSEL_POSSEL_APORT2YCH0,  /**< Select Dedicated APORT2Y CHannel 0. */
430   acmpInputAPORT2XCH1  = _ACMP_INPUTSEL_POSSEL_APORT2XCH1,  /**< Select Dedicated APORT2X CHannel 1. */
431   acmpInputAPORT2YCH2  = _ACMP_INPUTSEL_POSSEL_APORT2YCH2,  /**< Select Dedicated APORT2Y CHannel 2. */
432   acmpInputAPORT2XCH3  = _ACMP_INPUTSEL_POSSEL_APORT2XCH3,  /**< Select Dedicated APORT2X CHannel 3. */
433   acmpInputAPORT2YCH4  = _ACMP_INPUTSEL_POSSEL_APORT2YCH4,  /**< Select Dedicated APORT2Y CHannel 4. */
434   acmpInputAPORT2XCH5  = _ACMP_INPUTSEL_POSSEL_APORT2XCH5,  /**< Select Dedicated APORT2X CHannel 5. */
435   acmpInputAPORT2YCH6  = _ACMP_INPUTSEL_POSSEL_APORT2YCH6,  /**< Select Dedicated APORT2Y CHannel 6. */
436   acmpInputAPORT2XCH7  = _ACMP_INPUTSEL_POSSEL_APORT2XCH7,  /**< Select Dedicated APORT2X CHannel 7. */
437   acmpInputAPORT2YCH8  = _ACMP_INPUTSEL_POSSEL_APORT2YCH8,  /**< Select Dedicated APORT2Y CHannel 8. */
438   acmpInputAPORT2XCH9  = _ACMP_INPUTSEL_POSSEL_APORT2XCH9,  /**< Select Dedicated APORT2X CHannel 9. */
439   acmpInputAPORT2YCH10 = _ACMP_INPUTSEL_POSSEL_APORT2YCH10, /**< Select Dedicated APORT2Y CHannel 10. */
440   acmpInputAPORT2XCH11 = _ACMP_INPUTSEL_POSSEL_APORT2XCH11, /**< Select Dedicated APORT2X CHannel 11. */
441   acmpInputAPORT2YCH12 = _ACMP_INPUTSEL_POSSEL_APORT2YCH12, /**< Select Dedicated APORT2Y CHannel 12. */
442   acmpInputAPORT2XCH13 = _ACMP_INPUTSEL_POSSEL_APORT2XCH13, /**< Select Dedicated APORT2X CHannel 13. */
443   acmpInputAPORT2YCH14 = _ACMP_INPUTSEL_POSSEL_APORT2YCH14, /**< Select Dedicated APORT2Y CHannel 14. */
444   acmpInputAPORT2XCH15 = _ACMP_INPUTSEL_POSSEL_APORT2XCH15, /**< Select Dedicated APORT2X CHannel 15. */
445   acmpInputAPORT2YCH16 = _ACMP_INPUTSEL_POSSEL_APORT2YCH16, /**< Select Dedicated APORT2Y CHannel 16. */
446   acmpInputAPORT2XCH17 = _ACMP_INPUTSEL_POSSEL_APORT2XCH17, /**< Select Dedicated APORT2X CHannel 17. */
447   acmpInputAPORT2YCH18 = _ACMP_INPUTSEL_POSSEL_APORT2YCH18, /**< Select Dedicated APORT2Y CHannel 18. */
448   acmpInputAPORT2XCH19 = _ACMP_INPUTSEL_POSSEL_APORT2XCH19, /**< Select Dedicated APORT2X CHannel 19. */
449   acmpInputAPORT2YCH20 = _ACMP_INPUTSEL_POSSEL_APORT2YCH20, /**< Select Dedicated APORT2Y CHannel 20. */
450   acmpInputAPORT2XCH21 = _ACMP_INPUTSEL_POSSEL_APORT2XCH21, /**< Select Dedicated APORT2X CHannel 21. */
451   acmpInputAPORT2YCH22 = _ACMP_INPUTSEL_POSSEL_APORT2YCH22, /**< Select Dedicated APORT2Y CHannel 22. */
452   acmpInputAPORT2XCH23 = _ACMP_INPUTSEL_POSSEL_APORT2XCH23, /**< Select Dedicated APORT2X CHannel 23. */
453   acmpInputAPORT2YCH24 = _ACMP_INPUTSEL_POSSEL_APORT2YCH24, /**< Select Dedicated APORT2Y CHannel 24. */
454   acmpInputAPORT2XCH25 = _ACMP_INPUTSEL_POSSEL_APORT2XCH25, /**< Select Dedicated APORT2X CHannel 25. */
455   acmpInputAPORT2YCH26 = _ACMP_INPUTSEL_POSSEL_APORT2YCH26, /**< Select Dedicated APORT2Y CHannel 26. */
456   acmpInputAPORT2XCH27 = _ACMP_INPUTSEL_POSSEL_APORT2XCH27, /**< Select Dedicated APORT2X CHannel 27. */
457   acmpInputAPORT2YCH28 = _ACMP_INPUTSEL_POSSEL_APORT2YCH28, /**< Select Dedicated APORT2Y CHannel 28. */
458   acmpInputAPORT2XCH29 = _ACMP_INPUTSEL_POSSEL_APORT2XCH29, /**< Select Dedicated APORT2X CHannel 29. */
459   acmpInputAPORT2YCH30 = _ACMP_INPUTSEL_POSSEL_APORT2YCH30, /**< Select Dedicated APORT2Y CHannel 30. */
460   acmpInputAPORT2XCH31 = _ACMP_INPUTSEL_POSSEL_APORT2XCH31, /**< Select Dedicated APORT2X CHannel 31. */
461   acmpInputAPORT3XCH0  = _ACMP_INPUTSEL_POSSEL_APORT3XCH0,  /**< Select Dedicated APORT3X CHannel 0. */
462   acmpInputAPORT3YCH1  = _ACMP_INPUTSEL_POSSEL_APORT3YCH1,  /**< Select Dedicated APORT3Y CHannel 1. */
463   acmpInputAPORT3XCH2  = _ACMP_INPUTSEL_POSSEL_APORT3XCH2,  /**< Select Dedicated APORT3X CHannel 2. */
464   acmpInputAPORT3YCH3  = _ACMP_INPUTSEL_POSSEL_APORT3YCH3,  /**< Select Dedicated APORT3Y CHannel 3. */
465   acmpInputAPORT3XCH4  = _ACMP_INPUTSEL_POSSEL_APORT3XCH4,  /**< Select Dedicated APORT3X CHannel 4. */
466   acmpInputAPORT3YCH5  = _ACMP_INPUTSEL_POSSEL_APORT3YCH5,  /**< Select Dedicated APORT3Y CHannel 5. */
467   acmpInputAPORT3XCH6  = _ACMP_INPUTSEL_POSSEL_APORT3XCH6,  /**< Select Dedicated APORT3X CHannel 6. */
468   acmpInputAPORT3YCH7  = _ACMP_INPUTSEL_POSSEL_APORT3YCH7,  /**< Select Dedicated APORT3Y CHannel 7. */
469   acmpInputAPORT3XCH8  = _ACMP_INPUTSEL_POSSEL_APORT3XCH8,  /**< Select Dedicated APORT3X CHannel 8. */
470   acmpInputAPORT3YCH9  = _ACMP_INPUTSEL_POSSEL_APORT3YCH9,  /**< Select Dedicated APORT3Y CHannel 9. */
471   acmpInputAPORT3XCH10 = _ACMP_INPUTSEL_POSSEL_APORT3XCH10, /**< Select Dedicated APORT3X CHannel 10. */
472   acmpInputAPORT3YCH11 = _ACMP_INPUTSEL_POSSEL_APORT3YCH11, /**< Select Dedicated APORT3Y CHannel 11. */
473   acmpInputAPORT3XCH12 = _ACMP_INPUTSEL_POSSEL_APORT3XCH12, /**< Select Dedicated APORT3X CHannel 12. */
474   acmpInputAPORT3YCH13 = _ACMP_INPUTSEL_POSSEL_APORT3YCH13, /**< Select Dedicated APORT3Y CHannel 13. */
475   acmpInputAPORT3XCH14 = _ACMP_INPUTSEL_POSSEL_APORT3XCH14, /**< Select Dedicated APORT3X CHannel 14. */
476   acmpInputAPORT3YCH15 = _ACMP_INPUTSEL_POSSEL_APORT3YCH15, /**< Select Dedicated APORT3Y CHannel 15. */
477   acmpInputAPORT3XCH16 = _ACMP_INPUTSEL_POSSEL_APORT3XCH16, /**< Select Dedicated APORT3X CHannel 16. */
478   acmpInputAPORT3YCH17 = _ACMP_INPUTSEL_POSSEL_APORT3YCH17, /**< Select Dedicated APORT3Y CHannel 17. */
479   acmpInputAPORT3XCH18 = _ACMP_INPUTSEL_POSSEL_APORT3XCH18, /**< Select Dedicated APORT3X CHannel 18. */
480   acmpInputAPORT3YCH19 = _ACMP_INPUTSEL_POSSEL_APORT3YCH19, /**< Select Dedicated APORT3Y CHannel 19. */
481   acmpInputAPORT3XCH20 = _ACMP_INPUTSEL_POSSEL_APORT3XCH20, /**< Select Dedicated APORT3X CHannel 20. */
482   acmpInputAPORT3YCH21 = _ACMP_INPUTSEL_POSSEL_APORT3YCH21, /**< Select Dedicated APORT3Y CHannel 21. */
483   acmpInputAPORT3XCH22 = _ACMP_INPUTSEL_POSSEL_APORT3XCH22, /**< Select Dedicated APORT3X CHannel 22. */
484   acmpInputAPORT3YCH23 = _ACMP_INPUTSEL_POSSEL_APORT3YCH23, /**< Select Dedicated APORT3Y CHannel 23. */
485   acmpInputAPORT3XCH24 = _ACMP_INPUTSEL_POSSEL_APORT3XCH24, /**< Select Dedicated APORT3X CHannel 24. */
486   acmpInputAPORT3YCH25 = _ACMP_INPUTSEL_POSSEL_APORT3YCH25, /**< Select Dedicated APORT3Y CHannel 25. */
487   acmpInputAPORT3XCH26 = _ACMP_INPUTSEL_POSSEL_APORT3XCH26, /**< Select Dedicated APORT3X CHannel 26. */
488   acmpInputAPORT3YCH27 = _ACMP_INPUTSEL_POSSEL_APORT3YCH27, /**< Select Dedicated APORT3Y CHannel 27. */
489   acmpInputAPORT3XCH28 = _ACMP_INPUTSEL_POSSEL_APORT3XCH28, /**< Select Dedicated APORT3X CHannel 28. */
490   acmpInputAPORT3YCH29 = _ACMP_INPUTSEL_POSSEL_APORT3YCH29, /**< Select Dedicated APORT3Y CHannel 29. */
491   acmpInputAPORT3XCH30 = _ACMP_INPUTSEL_POSSEL_APORT3XCH30, /**< Select Dedicated APORT3X CHannel 30. */
492   acmpInputAPORT3YCH31 = _ACMP_INPUTSEL_POSSEL_APORT3YCH31, /**< Select Dedicated APORT3Y CHannel 31. */
493   acmpInputAPORT4YCH0  = _ACMP_INPUTSEL_POSSEL_APORT4YCH0,  /**< Select Dedicated APORT4Y CHannel 0. */
494   acmpInputAPORT4XCH1  = _ACMP_INPUTSEL_POSSEL_APORT4XCH1,  /**< Select Dedicated APORT4X CHannel 1. */
495   acmpInputAPORT4YCH2  = _ACMP_INPUTSEL_POSSEL_APORT4YCH2,  /**< Select Dedicated APORT4Y CHannel 2. */
496   acmpInputAPORT4XCH3  = _ACMP_INPUTSEL_POSSEL_APORT4XCH3,  /**< Select Dedicated APORT4X CHannel 3. */
497   acmpInputAPORT4YCH4  = _ACMP_INPUTSEL_POSSEL_APORT4YCH4,  /**< Select Dedicated APORT4Y CHannel 4. */
498   acmpInputAPORT4XCH5  = _ACMP_INPUTSEL_POSSEL_APORT4XCH5,  /**< Select Dedicated APORT4X CHannel 5. */
499   acmpInputAPORT4YCH6  = _ACMP_INPUTSEL_POSSEL_APORT4YCH6,  /**< Select Dedicated APORT4Y CHannel 6. */
500   acmpInputAPORT4XCH7  = _ACMP_INPUTSEL_POSSEL_APORT4XCH7,  /**< Select Dedicated APORT4X CHannel 7. */
501   acmpInputAPORT4YCH8  = _ACMP_INPUTSEL_POSSEL_APORT4YCH8,  /**< Select Dedicated APORT4Y CHannel 8. */
502   acmpInputAPORT4XCH9  = _ACMP_INPUTSEL_POSSEL_APORT4XCH9,  /**< Select Dedicated APORT4X CHannel 9. */
503   acmpInputAPORT4YCH10 = _ACMP_INPUTSEL_POSSEL_APORT4YCH10, /**< Select Dedicated APORT4Y CHannel 10. */
504   acmpInputAPORT4XCH11 = _ACMP_INPUTSEL_POSSEL_APORT4XCH11, /**< Select Dedicated APORT4X CHannel 11. */
505   acmpInputAPORT4YCH12 = _ACMP_INPUTSEL_POSSEL_APORT4YCH12, /**< Select Dedicated APORT4Y CHannel 12. */
506   acmpInputAPORT4XCH13 = _ACMP_INPUTSEL_POSSEL_APORT4XCH13, /**< Select Dedicated APORT4X CHannel 13. */
507   acmpInputAPORT4YCH16 = _ACMP_INPUTSEL_POSSEL_APORT4YCH16, /**< Select Dedicated APORT4Y CHannel 14. */
508   acmpInputAPORT4XCH17 = _ACMP_INPUTSEL_POSSEL_APORT4XCH17, /**< Select Dedicated APORT4X CHannel 15. */
509   acmpInputAPORT4YCH18 = _ACMP_INPUTSEL_POSSEL_APORT4YCH18, /**< Select Dedicated APORT4Y CHannel 16. */
510   acmpInputAPORT4XCH19 = _ACMP_INPUTSEL_POSSEL_APORT4XCH19, /**< Select Dedicated APORT4X CHannel 17. */
511   acmpInputAPORT4YCH20 = _ACMP_INPUTSEL_POSSEL_APORT4YCH20, /**< Select Dedicated APORT4Y CHannel 18. */
512   acmpInputAPORT4XCH21 = _ACMP_INPUTSEL_POSSEL_APORT4XCH21, /**< Select Dedicated APORT4X CHannel 19. */
513   acmpInputAPORT4YCH22 = _ACMP_INPUTSEL_POSSEL_APORT4YCH22, /**< Select Dedicated APORT4Y CHannel 20. */
514   acmpInputAPORT4XCH23 = _ACMP_INPUTSEL_POSSEL_APORT4XCH23, /**< Select Dedicated APORT4X CHannel 21. */
515   acmpInputAPORT4YCH24 = _ACMP_INPUTSEL_POSSEL_APORT4YCH24, /**< Select Dedicated APORT4Y CHannel 22. */
516   acmpInputAPORT4XCH25 = _ACMP_INPUTSEL_POSSEL_APORT4XCH25, /**< Select Dedicated APORT4X CHannel 23. */
517   acmpInputAPORT4YCH26 = _ACMP_INPUTSEL_POSSEL_APORT4YCH26, /**< Select Dedicated APORT4Y CHannel 24. */
518   acmpInputAPORT4XCH27 = _ACMP_INPUTSEL_POSSEL_APORT4XCH27, /**< Select Dedicated APORT4X CHannel 25. */
519   acmpInputAPORT4YCH28 = _ACMP_INPUTSEL_POSSEL_APORT4YCH28, /**< Select Dedicated APORT4Y CHannel 26. */
520   acmpInputAPORT4XCH29 = _ACMP_INPUTSEL_POSSEL_APORT4XCH29, /**< Select Dedicated APORT4X CHannel 27. */
521   acmpInputAPORT4YCH30 = _ACMP_INPUTSEL_POSSEL_APORT4YCH30, /**< Select Dedicated APORT4Y CHannel 28. */
522   acmpInputAPORT4YCH14 = _ACMP_INPUTSEL_POSSEL_APORT4YCH14, /**< Select Dedicated APORT4X CHannel 29. */
523   acmpInputAPORT4XCH15 = _ACMP_INPUTSEL_POSSEL_APORT4XCH15, /**< Select Dedicated APORT4Y CHannel 30. */
524   acmpInputAPORT4XCH31 = _ACMP_INPUTSEL_POSSEL_APORT4XCH31, /**< Select Dedicated APORT4X CHannel 31. */
525 #if defined(_ACMP_INPUTSEL_POSSEL_DACOUT0)
526   acmpInputDACOUT0   = _ACMP_INPUTSEL_POSSEL_DACOUT0, /**< Select DAC Channel 0 Output. */
527 #endif
528 #if defined(_ACMP_INPUTSEL_POSSEL_DACOUT1)
529   acmpInputDACOUT1   = _ACMP_INPUTSEL_POSSEL_DACOUT1, /**< Select DAC Channel 1 Output. */
530 #endif
531   acmpInputVLP       = _ACMP_INPUTSEL_POSSEL_VLP,   /**< Select Low-Power Sampled Voltage. */
532   acmpInputVBDIV     = _ACMP_INPUTSEL_POSSEL_VBDIV, /**< Select Divided VB Voltage. */
533   acmpInputVADIV     = _ACMP_INPUTSEL_POSSEL_VADIV, /**< Select Divided VA Voltage. */
534   acmpInputVDD       = _ACMP_INPUTSEL_POSSEL_VDD,   /**< ACMPVDD as selected via PWRSEL. */
535   acmpInputVSS       = _ACMP_INPUTSEL_POSSEL_VSS,   /**< Select VSS. */
536 } ACMP_Channel_TypeDef;
537 #else
538 /** ACMP inputs. Note that scaled VDD and bandgap references can only be used
539  *  as negative inputs. */
540 typedef enum {
541   /** Channel 0 */
542   acmpChannel0    = _ACMP_INPUTSEL_NEGSEL_CH0,
543   /** Channel 1 */
544   acmpChannel1    = _ACMP_INPUTSEL_NEGSEL_CH1,
545   /** Channel 2 */
546   acmpChannel2    = _ACMP_INPUTSEL_NEGSEL_CH2,
547   /** Channel 3 */
548   acmpChannel3    = _ACMP_INPUTSEL_NEGSEL_CH3,
549   /** Channel 4 */
550   acmpChannel4    = _ACMP_INPUTSEL_NEGSEL_CH4,
551   /** Channel 5 */
552   acmpChannel5    = _ACMP_INPUTSEL_NEGSEL_CH5,
553   /** Channel 6 */
554   acmpChannel6    = _ACMP_INPUTSEL_NEGSEL_CH6,
555   /** Channel 7 */
556   acmpChannel7    = _ACMP_INPUTSEL_NEGSEL_CH7,
557   /** 1.25 V internal reference */
558   acmpChannel1V25 = _ACMP_INPUTSEL_NEGSEL_1V25,
559   /** 2.5 V internal reference */
560   acmpChannel2V5  = _ACMP_INPUTSEL_NEGSEL_2V5,
561   /** Scaled VDD reference */
562   acmpChannelVDD  = _ACMP_INPUTSEL_NEGSEL_VDD,
563 
564 #if defined(_ACMP_INPUTSEL_NEGSEL_DAC0CH0)
565   /** DAC0 channel 0 */
566   acmpChannelDAC0Ch0 = _ACMP_INPUTSEL_NEGSEL_DAC0CH0,
567 #endif
568 
569 #if defined(_ACMP_INPUTSEL_NEGSEL_DAC0CH1)
570   /** DAC0 channel 1 */
571   acmpChannelDAC0Ch1 = _ACMP_INPUTSEL_NEGSEL_DAC0CH1,
572 #endif
573 
574 #if defined(_ACMP_INPUTSEL_NEGSEL_CAPSENSE)
575   /** Capacitive sense mode */
576   acmpChannelCapSense = _ACMP_INPUTSEL_NEGSEL_CAPSENSE,
577 #endif
578 } ACMP_Channel_TypeDef;
579 #endif
580 
581 #if defined(_ACMP_EXTIFCTRL_MASK)
582 /**
583  * ACMP external input select. This type is used to select which APORT is
584  * used by an external module, such as LESENSE, when it's taking control over
585  * the ACMP input.
586  */
587 typedef enum {
588   acmpExternalInputAPORT0X  = _ACMP_EXTIFCTRL_APORTSEL_APORT0X,  /**< Select APORT0X as an external input. */
589   acmpExternalInputAPORT0Y  = _ACMP_EXTIFCTRL_APORTSEL_APORT0Y,  /**< Select APORT0Y as an external input. */
590   acmpExternalInputAPORT1X  = _ACMP_EXTIFCTRL_APORTSEL_APORT1X,  /**< Select APORT1X as an external input. */
591   acmpExternalInputAPORT1Y  = _ACMP_EXTIFCTRL_APORTSEL_APORT1Y,  /**< Select APORT1Y as an external input. */
592   acmpExternalInputAPORT1XY = _ACMP_EXTIFCTRL_APORTSEL_APORT1XY, /**< Select APORT1XY as an external input. */
593   acmpExternalInputAPORT2X  = _ACMP_EXTIFCTRL_APORTSEL_APORT2X,  /**< Select APORT2X as an external input. */
594   acmpExternalInputAPORT2Y  = _ACMP_EXTIFCTRL_APORTSEL_APORT2Y,  /**< Select APORT2Y as an external input. */
595   acmpExternalInputAPORT2YX = _ACMP_EXTIFCTRL_APORTSEL_APORT2YX, /**< Select APORT2YX as an external input. */
596   acmpExternalInputAPORT3X  = _ACMP_EXTIFCTRL_APORTSEL_APORT3X,  /**< Select APORT3X as an external input. */
597   acmpExternalInputAPORT3Y  = _ACMP_EXTIFCTRL_APORTSEL_APORT3Y,  /**< Select APORT3Y as an external input. */
598   acmpExternalInputAPORT3XY = _ACMP_EXTIFCTRL_APORTSEL_APORT3XY, /**< Select APORT3XY as an external input. */
599   acmpExternalInputAPORT4X  = _ACMP_EXTIFCTRL_APORTSEL_APORT4X,  /**< Select APORT4X as an external input. */
600   acmpExternalInputAPORT4Y  = _ACMP_EXTIFCTRL_APORTSEL_APORT4Y,  /**< Select APORT4Y as an external input. */
601   acmpExternalInputAPORT4YX = _ACMP_EXTIFCTRL_APORTSEL_APORT4YX, /**< Select APORT4YX as an external input. */
602 } ACMP_ExternalInput_Typedef;
603 #endif
604 
605 /*******************************************************************************
606  ******************************   STRUCTS   ************************************
607  ******************************************************************************/
608 
609 /** Capsense initialization structure. */
610 typedef struct {
611 #if defined(_ACMP_CTRL_FULLBIAS_MASK)
612   /** Full-bias current. See the ACMP chapter about bias and response time in
613    *  the reference manual for details. */
614   bool                          fullBias;
615 #endif
616 
617 #if defined(_ACMP_CTRL_HALFBIAS_MASK)
618   /** Half-bias current. See the ACMP chapter about bias and response time in
619    *  the reference manual for details. */
620   bool                          halfBias;
621 #endif
622 
623   /** Bias current. See the ACMP chapter about bias and response time in the
624    *  reference manual for details. */
625   uint32_t                      biasProg;
626 
627 #if defined(_ACMP_CTRL_WARMTIME_MASK)
628   /** Warmup time, which is measured in HFPERCLK / HFPERCCLK cycles and should be
629    *  about 10 us in wall clock time. */
630   ACMP_WarmTime_TypeDef         warmTime;
631 #endif
632 
633 #if defined(_ACMP_CTRL_HYSTSEL_MASK) \
634   ||  defined(_ACMP_CFG_HYST_MASK)
635   /** Hysteresis level. */
636   ACMP_HysteresisLevel_TypeDef  hysteresisLevel;
637 #else
638   /** Hysteresis level when ACMP output is 0. */
639   ACMP_HysteresisLevel_TypeDef  hysteresisLevel_0;
640 
641   /** Hysteresis level when ACMP output is 1. */
642   ACMP_HysteresisLevel_TypeDef  hysteresisLevel_1;
643 #endif
644 
645   /** A resistor used in the capacitive sensing circuit. For values see
646    *  the device data sheet. */
647   ACMP_CapsenseResistor_TypeDef resistor;
648 
649 #if defined(_ACMP_INPUTSEL_LPREF_MASK)
650   /** Low-power reference enabled. This setting, if enabled, reduces the
651    *  power used by VDD and bandgap references. */
652   bool                          lowPowerReferenceEnabled;
653 #endif
654 
655 #if defined(_ACMP_INPUTCTRL_VREFDIV_MASK)
656   /** VDD division factor. VREFOUT = VREFIN * (VREFDIV / 63).
657    *  Valid values are in the 0-63 range. */
658   uint32_t                      vrefDiv;
659 #elif defined(_ACMP_INPUTSEL_VDDLEVEL_MASK)
660   /** VDD reference value. VDD_SCALED = (VDD * VDDLEVEL) / 63.
661    *  Valid values are in the 0-63 range. */
662   uint32_t                      vddLevel;
663 #else
664   /**
665    * This value configures the upper voltage threshold of the capsense
666    * oscillation rail.
667    *
668    * The voltage threshold is calculated as follows:
669    *   VDD * (vddLevelHigh + 1) / 64
670    */
671   uint32_t                      vddLevelHigh;
672 
673   /**
674    * This value configures the lower voltage threshold of the capsense
675    * oscillation rail.
676    *
677    * The voltage threshold is calculated as follows:
678    *   VDD * (vddLevelLow + 1) / 64
679    */
680   uint32_t                      vddLevelLow;
681 #endif
682 
683   /** If true, ACMP is enabled after configuration. */
684   bool                          enable;
685 } ACMP_CapsenseInit_TypeDef;
686 
687 /** A default configuration for capacitive sense mode initialization. */
688 #if defined(_ACMP_CFG_MASK)
689 
690 // PM5507: provide default configuration that is functional
691 /** Analog comparator CFG with initial bias value */
692 #define PM5507_ACMP_CFG_BIAS_DEFAULT  0x00000004UL
693 /** Analog comparator reset value */
694 #define PM5507_ACMP_CFG_RESETVALUE    0x00000004UL
695 
696 /** Capacitive sense mode configuration default values. */
697 #define ACMP_CAPSENSE_INIT_DEFAULT                                                \
698   {                                                                               \
699     PM5507_ACMP_CFG_BIAS_DEFAULT, /* Using biasProg default value. */             \
700     acmpHysteresisDisabled,       /* Disable hysteresis. */                       \
701     acmpResistor5,                /* Use internal resistor value 5. */            \
702     0x3F,                         /* Set VREFDIV to maximum to disable divide. */ \
703     true                          /* Enable after init. */                        \
704   }
705 #elif defined(_ACMP_HYSTERESIS0_HYST_MASK)
706 #define ACMP_CAPSENSE_INIT_DEFAULT                                            \
707   {                                                                           \
708     false,              /* Don't use fullBias to lower power consumption. */  \
709     0x20,               /* Using biasProg value of 0x20 (32). */              \
710     acmpHysteresisLevel8, /* Use hysteresis level 8 when ACMP output is 0. */ \
711     acmpHysteresisLevel8, /* Use hysteresis level 8 when ACMP output is 1. */ \
712     acmpResistor5,      /* Use internal resistor value 5. */                  \
713     0x30,               /* VDD level high. */                                 \
714     0x10,               /* VDD level low. */                                  \
715     true                /* Enable after initialization. */                    \
716   }
717 #elif defined(_ACMP_CTRL_WARMTIME_MASK)
718 #define ACMP_CAPSENSE_INIT_DEFAULT                      \
719   {                                                     \
720     false,            /* fullBias */                    \
721     false,            /* halfBias */                    \
722     0x7,              /* biasProg */                    \
723     acmpWarmTime512,  /* 512 cycle warmup to be safe */ \
724     acmpHysteresisLevel5,                               \
725     acmpResistor3,                                      \
726     false,            /* low power reference */         \
727     0x3D,             /* VDD level */                   \
728     true              /* Enable after init. */          \
729   }
730 #else
731 #define ACMP_CAPSENSE_INIT_DEFAULT              \
732   {                                             \
733     false,            /* fullBias */            \
734     false,            /* halfBias */            \
735     0x7,              /* biasProg */            \
736     acmpHysteresisLevel5,                       \
737     acmpResistor3,                              \
738     false,            /* low power reference */ \
739     0x3D,             /* VDD level */           \
740     true              /* Enable after init. */  \
741   }
742 #endif
743 
744 /** ACMP initialization structure. */
745 typedef struct {
746 #if defined(_ACMP_CTRL_FULLBIAS_MASK)
747   /** Full-bias current. See the ACMP chapter about bias and response time in
748    *  the reference manual for details. */
749   bool                         fullBias;
750 #endif
751 
752 #if defined(_ACMP_CTRL_HALFBIAS_MASK)
753   /** Half-bias current. See the ACMP chapter about bias and response time in
754    *  the reference manual for details. */
755   bool                         halfBias;
756 #endif
757 
758   /** Bias current. See the ACMP chapter about bias and response time in the
759    *  reference manual for details. Valid values are in the range 0-7. */
760   uint32_t                     biasProg;
761 
762 #if defined(_ACMP_CTRL_IFALL_SHIFT)
763   /** Enable setting the interrupt flag on the falling edge. */
764   bool                         interruptOnFallingEdge;
765 #endif
766 #if defined(_ACMP_CTRL_IRISE_SHIFT)
767   /** Enable setting the interrupt flag on the rising edge. */
768   bool                         interruptOnRisingEdge;
769 #endif
770 
771 #if defined(_ACMP_CTRL_INPUTRANGE_MASK) \
772   || defined(_ACMP_CFG_INPUTRANGE_MASK)
773   /** Input range. Adjust this setting to optimize the performance for a
774    *  given input voltage range.  */
775   ACMP_InputRange_TypeDef      inputRange;
776 #endif
777 
778 #if defined(_ACMP_CTRL_ACCURACY_MASK) \
779   || defined(_ACMP_CFG_ACCURACY_MASK)
780   /** ACMP accuracy mode. Select the accuracy mode that matches the
781    *  required current usage and accuracy requirement. Low accuracy
782    *  consumes less current while high accuracy consumes more current. */
783   ACMP_Accuracy_TypeDef        accuracy;
784 #endif
785 
786 #if defined(_ACMP_CTRL_PWRSEL_MASK)
787   /** Select the power source for the ACMP. */
788   ACMP_PowerSource_TypeDef     powerSource;
789 #endif
790 
791 #if defined(_ACMP_CTRL_WARMTIME_MASK)
792   /** Warmup time, which is measured in HFPERCLK / HFPERCCLK cycles and should be
793    *  about 10 us in wall clock time. */
794   ACMP_WarmTime_TypeDef        warmTime;
795 #endif
796 
797 #if defined(_ACMP_CTRL_HYSTSEL_MASK) \
798   ||  defined(_ACMP_CFG_HYST_MASK)
799   /** Hysteresis level. */
800   ACMP_HysteresisLevel_TypeDef hysteresisLevel;
801 #else
802   /** Hysteresis when ACMP output is 0. */
803   ACMP_HysteresisLevel_TypeDef hysteresisLevel_0;
804 
805   /** Hysteresis when ACMP output is 1. */
806   ACMP_HysteresisLevel_TypeDef hysteresisLevel_1;
807 #endif
808 
809 #if defined(_ACMP_INPUTSEL_VLPSEL_MASK)
810   /** VLP Input source. Select between using VADIV or VBDIV as the VLP
811    *  source. */
812   ACMP_VLPInput_Typedef        vlpInput;
813 #endif
814 
815   /** Inactive value emitted by ACMP during warmup. */
816   bool                         inactiveValue;
817 
818 #if defined(_ACMP_INPUTSEL_LPREF_MASK)
819   /** Low power reference enabled. This setting, if enabled, reduces the
820    *  power used by the VDD and bandgap references. */
821   bool                         lowPowerReferenceEnabled;
822 #endif
823 
824 #if defined(_ACMP_INPUTCTRL_VREFDIV_MASK)
825   /** VDD division factor. VREFOUT = VREFIN * (VREFDIV / 63).
826    *  Valid values are in the 0-63 range. */
827   uint32_t                     vrefDiv;
828 #elif defined(_ACMP_INPUTSEL_VDDLEVEL_MASK)
829   /** VDD reference value. VDD_SCALED = VDD * VDDLEVEL * 50 mV/3.8 V.
830    *  Valid values are in the 0-63 range. */
831   uint32_t                     vddLevel;
832 #endif
833 
834   /** If true, ACMP is enabled after configuration. */
835   bool                         enable;
836 } ACMP_Init_TypeDef;
837 
838 /** Default configuration for ACMP regular initialization. */
839 #if defined(_ACMP_CFG_MASK)
840 #define ACMP_INIT_DEFAULT                                                         \
841   {                                                                               \
842     PM5507_ACMP_CFG_BIAS_DEFAULT, /* Using biasProg default value. */             \
843     acmpInputRangeFull,           /* Input range from 0 to Vdd. */                \
844     acmpAccuracyLow,              /* Low accuracy, less current usage. */         \
845     acmpHysteresisDisabled,       /* Disable hysteresis. */                       \
846     false,                        /* Output 0 when ACMP is inactive. */           \
847     0x3F,                         /* Set VREFDIV to maximum to disable divide. */ \
848     true                          /* Enable after init. */                        \
849   }
850 #elif defined(_ACMP_HYSTERESIS0_HYST_MASK)
851 #define ACMP_INIT_DEFAULT                                                   \
852   {                                                                         \
853     false,                    /* fullBias */                                \
854     0x7,                      /* biasProg */                                \
855     false,                    /* No interrupt on falling edge. */           \
856     false,                    /* No interrupt on rising edge. */            \
857     acmpInputRangeFull,       /* Input range from 0 to VDD. */              \
858     acmpAccuracyLow,          /* Low accuracy, less current usage. */       \
859     acmpPowerSourceAvdd,      /* Use the AVDD supply. */                    \
860     acmpHysteresisLevel5,     /* Use hysteresis level 5 when output is 0 */ \
861     acmpHysteresisLevel5,     /* Use hysteresis level 5 when output is 1 */ \
862     acmpVLPInputVADIV,        /* Use VADIV as the VLP input source. */      \
863     false,                    /* Output 0 when ACMP is inactive. */         \
864     true                      /* Enable after init. */                      \
865   }
866 #else
867 #define ACMP_INIT_DEFAULT                                                   \
868   {                                                                         \
869     false,            /* fullBias */                                        \
870     false,            /* halfBias */                                        \
871     0x7,              /* biasProg */                                        \
872     false,            /* No interrupt on falling edge. */                   \
873     false,            /* No interrupt on rising edge. */                    \
874     acmpWarmTime512,  /* 512 cycle warmup to be safe */                     \
875     acmpHysteresisLevel5,                                                   \
876     false,            /* Disabled emitting inactive value during warmup. */ \
877     false,            /* low power reference */                             \
878     0x3D,             /* VDD level */                                       \
879     true              /* Enable after init. */                              \
880   }
881 #endif
882 
883 #if defined(_ACMP_INPUTSEL_VASEL_MASK)
884 /** VA Configuration structure. This structure is used to configure the
885  *  VA voltage input source and its dividers. */
886 typedef struct {
887   ACMP_VAInput_TypeDef input; /**< VA voltage input source */
888 
889   /**
890    * A divider for VA voltage input source when ACMP output is 0. This value is
891    * used to divide the VA voltage input source by a specific value. The valid
892    * range is between 0 and 63.
893    *
894    *  VA divided = VA input * (div0 + 1) / 64
895    */
896   uint32_t             div0;
897 
898   /**
899    * A divider for VA voltage input source when ACMP output is 1. This value is
900    * used to divide the VA voltage input source by a specific value. The valid
901    * range is between 0 and 63.
902    *
903    *  VA divided = VA input * (div1 + 1) / 64
904    */
905   uint32_t             div1;
906 } ACMP_VAConfig_TypeDef;
907 
908 /** VA default configuration. */
909 #define ACMP_VACONFIG_DEFAULT                                               \
910   {                                                                         \
911     acmpVAInputVDD, /* Use VDD as VA voltage input source. */               \
912     63,           /* No division of the VA source when ACMP output is 0. */ \
913     63,           /* No division of the VA source when ACMP output is 1. */ \
914   }
915 #endif
916 
917 #if defined(_ACMP_INPUTSEL_VBSEL_MASK)
918 /** VB Configuration structure. This structure is used to configure the
919  *  VB voltage input source and its dividers. */
920 typedef struct {
921   ACMP_VBInput_TypeDef input; /**< VB Voltage input source */
922 
923   /**
924    * A divider for VB voltage input source when ACMP output is 0. This value is
925    * used to divide the VB voltage input source by a specific value. The valid
926    * range is between 0 and 63.
927    *
928    *  VB divided = VB input * (div0 + 1) / 64
929    */
930   uint32_t             div0;
931 
932   /**
933    * A divider for VB voltage input source when ACMP output is 1. This value is
934    * used to divide the VB voltage input source by a specific value. The valid
935    * range is between 0 and 63.
936    *
937    *  VB divided = VB input * (div1 + 1) / 64
938    */
939   uint32_t             div1;
940 } ACMP_VBConfig_TypeDef;
941 
942 /** VB default configuration. */
943 #define ACMP_VBCONFIG_DEFAULT                                                \
944   {                                                                          \
945     acmpVBInput1V25, /* Use 1.25 V as VB voltage input source. */            \
946     63,            /* No division of the VB source when ACMP output is 0. */ \
947     63,            /* No division of the VB source when ACMP output is 1. */ \
948   }
949 #endif
950 
951 /*******************************************************************************
952  *****************************   PROTOTYPES   **********************************
953  ******************************************************************************/
954 
955 void ACMP_CapsenseInit(ACMP_TypeDef *acmp, const ACMP_CapsenseInit_TypeDef *init);
956 void ACMP_CapsenseChannelSet(ACMP_TypeDef *acmp, ACMP_Channel_TypeDef channel);
957 void ACMP_ChannelSet(ACMP_TypeDef *acmp, ACMP_Channel_TypeDef negSel, ACMP_Channel_TypeDef posSel);
958 void ACMP_Disable(ACMP_TypeDef *acmp);
959 void ACMP_Enable(ACMP_TypeDef *acmp);
960 #if defined(_ACMP_EXTIFCTRL_MASK)
961 void ACMP_ExternalInputSelect(ACMP_TypeDef *acmp, ACMP_ExternalInput_Typedef aport);
962 #endif
963 #if defined(_GPIO_ACMP_ROUTEEN_MASK)
964 void ACMP_GPIOSetup(ACMP_TypeDef *acmp, GPIO_Port_TypeDef port, unsigned int pin, bool enable, bool invert);
965 #else
966 void ACMP_GPIOSetup(ACMP_TypeDef *acmp, uint32_t location, bool enable, bool invert);
967 #endif
968 void ACMP_Init(ACMP_TypeDef *acmp, const ACMP_Init_TypeDef *init);
969 void ACMP_Reset(ACMP_TypeDef *acmp);
970 #if defined(_ACMP_INPUTSEL_VASEL_MASK)
971 void ACMP_VASetup(ACMP_TypeDef *acmp, const ACMP_VAConfig_TypeDef *vaconfig);
972 #endif
973 #if defined(_ACMP_INPUTSEL_VBSEL_MASK)
974 void ACMP_VBSetup(ACMP_TypeDef *acmp, const ACMP_VBConfig_TypeDef *vbconfig);
975 #endif
976 
977 /***************************************************************************//**
978  * @brief
979  *   Clear one or more pending ACMP interrupts.
980  *
981  * @param[in] acmp
982  *   A pointer to the ACMP peripheral register block.
983  *
984  * @param[in] flags
985  *   Pending ACMP interrupt source to clear. Use a bitwise logic OR combination
986  *   of valid interrupt flags for the ACMP module. The flags can be, for instance,
987  *   ACMP_IFC_EDGE or ACMP_IFC_WARMUP.
988  ******************************************************************************/
ACMP_IntClear(ACMP_TypeDef * acmp,uint32_t flags)989 __STATIC_INLINE void ACMP_IntClear(ACMP_TypeDef *acmp, uint32_t flags)
990 {
991 #if defined(ACMP_HAS_SET_CLEAR)
992   acmp->IF_CLR = flags;
993 #else
994   acmp->IFC = flags;
995 #endif
996 }
997 
998 /***************************************************************************//**
999  * @brief
1000  *   Disable one or more ACMP interrupts.
1001  *
1002  * @param[in] acmp
1003  *   A pointer to the ACMP peripheral register block.
1004  *
1005  * @param[in] flags
1006  *   ACMP interrupt sources to disable. Use a bitwise logic OR combination of
1007  *   valid interrupt flags for the ACMP module. The flags can be, for instance,
1008  *   ACMP_IEN_EDGE or ACMP_IEN_WARMUP.
1009  ******************************************************************************/
ACMP_IntDisable(ACMP_TypeDef * acmp,uint32_t flags)1010 __STATIC_INLINE void ACMP_IntDisable(ACMP_TypeDef *acmp, uint32_t flags)
1011 {
1012   BUS_RegMaskedClear(&(acmp->IEN), flags);
1013 }
1014 
1015 /***************************************************************************//**
1016  * @brief
1017  *   Enable one or more ACMP interrupts.
1018  *
1019  * @note
1020  *   Depending on the use, a pending interrupt may already be set prior to
1021  *   enabling the interrupt. Consider using ACMP_IntClear() prior to enabling
1022  *   if a pending interrupt should be ignored.
1023  *
1024  * @param[in] acmp
1025  *   A pointer to the ACMP peripheral register block.
1026  *
1027  * @param[in] flags
1028  *   ACMP interrupt sources to enable. Use a bitwise logic OR combination of
1029  *   valid interrupt flags for the ACMP module. The flags can be, for instance,
1030  *   ACMP_IEN_EDGE or ACMP_IEN_WARMUP.
1031  ******************************************************************************/
ACMP_IntEnable(ACMP_TypeDef * acmp,uint32_t flags)1032 __STATIC_INLINE void ACMP_IntEnable(ACMP_TypeDef *acmp, uint32_t flags)
1033 {
1034 #if defined(ACMP_HAS_SET_CLEAR)
1035   acmp->IEN_SET = flags;
1036 #else
1037   acmp->IEN |= flags;
1038 #endif
1039 }
1040 
1041 /***************************************************************************//**
1042  * @brief
1043  *   Get pending ACMP interrupt flags.
1044  *
1045  * @note
1046  *   This function does not clear event bits.
1047  *
1048  * @param[in] acmp
1049  *   A pointer to the ACMP peripheral register block.
1050  *
1051  * @return
1052  *   Pending ACMP interrupt sources. A bitwise logic OR combination of valid
1053  *   interrupt flags for the ACMP module. The pending interrupt sources can be,
1054  *   for instance, ACMP_IF_EDGE or ACMP_IF_WARMUP.
1055  ******************************************************************************/
ACMP_IntGet(ACMP_TypeDef * acmp)1056 __STATIC_INLINE uint32_t ACMP_IntGet(ACMP_TypeDef *acmp)
1057 {
1058   return acmp->IF;
1059 }
1060 
1061 /***************************************************************************//**
1062  * @brief
1063  *   Get enabled and pending ACMP interrupt flags.
1064  *   Useful for handling more interrupt sources in the same interrupt handler.
1065  *
1066  * @param[in] acmp
1067  *   A pointer to the ACMP peripheral register block.
1068  *
1069  * @note
1070  *   This function does not clear interrupt flags.
1071  *
1072  * @return
1073  *   Pending and enabled ACMP interrupt sources.
1074  *   The return value is the bitwise AND combination of
1075  *   - the OR combination of enabled interrupt sources in ACMPx_IEN_nnn
1076  *     register (ACMPx_IEN_nnn) and
1077  *   - the OR combination of valid interrupt flags of the ACMP module
1078  *     (ACMPx_IF_nnn).
1079  ******************************************************************************/
ACMP_IntGetEnabled(ACMP_TypeDef * acmp)1080 __STATIC_INLINE uint32_t ACMP_IntGetEnabled(ACMP_TypeDef *acmp)
1081 {
1082   uint32_t tmp;
1083 
1084   /* Store ACMPx->IEN in a temporary variable to define the explicit order
1085    * of volatile accesses. */
1086   tmp = acmp->IEN;
1087 
1088   /* Bitwise AND of pending and enabled interrupts. */
1089   return acmp->IF & tmp;
1090 }
1091 
1092 /***************************************************************************//**
1093  * @brief
1094  *   Set one or more pending ACMP interrupts from software.
1095  *
1096  * @param[in] acmp
1097  *   A pointer to the ACMP peripheral register block.
1098  *
1099  * @param[in] flags
1100  *   ACMP interrupt sources to set as pending. Use a bitwise logic OR
1101  *   combination of valid interrupt flags for the ACMP module. The flags can be,
1102  *   for instance, ACMP_IFS_EDGE or ACMP_IFS_WARMUP.
1103  ******************************************************************************/
ACMP_IntSet(ACMP_TypeDef * acmp,uint32_t flags)1104 __STATIC_INLINE void ACMP_IntSet(ACMP_TypeDef *acmp, uint32_t flags)
1105 {
1106 #if defined(ACMP_HAS_SET_CLEAR)
1107   acmp->IF_SET = flags;
1108 #else
1109   acmp->IFS = flags;
1110 #endif
1111 }
1112 
1113 #if defined(_ACMP_INPUTCTRL_MASK)
1114 /***************************************************************************//**
1115  * @brief
1116  *   Convert GPIO port/pin to ACMP input selection.
1117  *
1118  * @param[in] port
1119  *   GPIO port
1120  *
1121  * @param[in] pin
1122  *   GPIO pin
1123  *
1124  * @return
1125  *   ACMP input selection
1126  ******************************************************************************/
ACMP_PortPinToInput(GPIO_Port_TypeDef port,uint8_t pin)1127 __STATIC_INLINE ACMP_Channel_TypeDef ACMP_PortPinToInput(GPIO_Port_TypeDef port, uint8_t pin)
1128 {
1129   uint32_t input = (((uint32_t) port + (_ACMP_INPUTCTRL_POSSEL_PA0 >> 4)) << 4) | pin;
1130 
1131   return (ACMP_Channel_TypeDef) input;
1132 }
1133 #endif
1134 
1135 /** @} (end addtogroup acmp) */
1136 
1137 #ifdef __cplusplus
1138 }
1139 #endif
1140 
1141 #endif /* defined(ACMP_COUNT) && (ACMP_COUNT > 0) */
1142 #endif /* EM_ACMP_H */
1143