1 /*
2  * @brief LPC15xx Analog comparator driver
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2014
6  * All rights reserved.
7  *
8  * @par
9  * Software that is described herein is for illustrative purposes only
10  * which provides customers with programming information regarding the
11  * LPC products.  This software is supplied "AS IS" without any warranties of
12  * any kind, and NXP Semiconductors and its licenser disclaim any and
13  * all warranties, express or implied, including all implied warranties of
14  * merchantability, fitness for a particular purpose and non-infringement of
15  * intellectual property rights.  NXP Semiconductors assumes no responsibility
16  * or liability for the use of the software, conveys no license or rights under any
17  * patent, copyright, mask work right, or any other intellectual property rights in
18  * or to any products. NXP Semiconductors reserves the right to make changes
19  * in the software without notification. NXP Semiconductors also makes no
20  * representation or warranty that such application will be suitable for the
21  * specified use without further testing or modification.
22  *
23  * @par
24  * Permission to use, copy, modify, and distribute this software and its
25  * documentation is hereby granted, under NXP Semiconductors' and its
26  * licensor's relevant copyrights in the software, without fee, provided that it
27  * is used in conjunction with NXP Semiconductors microcontrollers.  This
28  * copyright, permission, and disclaimer notice must appear in all copies of
29  * this code.
30  */
31 
32 #ifndef __ACMP_15XX_H_
33 #define __ACMP_15XX_H_
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 /** @defgroup ACMP_15XX CHIP: LPC15xx Analog Comparator driver
40  * @ingroup CHIP_15XX_Drivers
41  * @{
42  */
43 
44 /**
45  * @brief Analog Comparator channel register block structure
46  */
47 typedef struct {
48 	__IO uint32_t  CMP;			/*!< Individual Comparator control register */
49 	__IO uint32_t  CMPFILTR;	/*!< Individual Comparator Filter registers */
50 } CMP_REG_T;
51 
52 /**
53  * @brief Analog Comparator register block structure
54  */
55 typedef struct {					/*!< ACMP Structure */
56 	__IO uint32_t  CTRL;		/*!< Comparator block control register */
57 	__IO CMP_REG_T ACMP[4];		/*!< Individual Comparator registers */
58 } LPC_CMP_T;
59 
60 /* Bit definitions for block control register */
61 #define ACMP_ROSCCTL_BIT     (1 << 8)		/* Ring Oscillator control bit */
62 #define ACMP_EXTRESET_BIT    (1 << 9)		/* Reset source for ring oscillator 0 - Internal, 1 - External pin */
63 
64 /* Bit definitions for compare register */
65 #define ACMP_CMPEN_BIT       (1 << 0)		/* Comparator enable bit */
66 #define ACMP_INTEN_BIT       (1 << 2)		/* Comparator Interrupt enable bit */
67 #define ACMP_STATUS_BIT      (1 << 3)		/* Comparator status, reflects the state of the comparator output */
68 #define ACMP_COMPVMSEL_MASK  (0x7 << 4)		/* Mask for VM Input selection */
69 #define ACMP_COMPVPSEL_MASK  (0x7 << 8)		/* Mask for VP Input selection */
70 #define ACMP_HYSTERESIS_MASK (0x3 << 13)	/* Mask for Hysterisis Control */
71 #define ACMP_INTPOL_BIT      (1 << 15)		/* Polarity of CMP output for interrupt 0 - Not Inverted, 1 - Inverted */
72 #define ACMP_INTTYPE_BIT     (1 << 16)		/* Interrupt Type 0 - Edge, 1 - Level */
73 #define ACMP_INTEDGE_MASK    (0x3 << 17)	/* Mask for Interrupt edge selection */
74 #define ACMP_INTFLAG_BIT     (1 << 19)		/* Interrupt Flag bit */
75 #define ACMP_LADENAB_BIT     (1 << 20)		/* Voltage ladder enable bit */
76 #define ACMP_LADREF_BIT      (1 << 22)		/* Voltage reference select bit for voltage ladder */
77 #define ACMP_LADSEL_MASK     (0x1F << 24)	/* Reference voltage selection mask for ladder */
78 #define ACMP_PROPDLY_MASK    (0x3 << 29)	/* Propogation delay mask */
79 
80 /* Bit definitions for comparator filter register */
81 #define ACMP_SMODE_MASK      (0x3 << 0)		/* Mask for digital filter sample mode */
82 #define ACMP_CLKDIV_MASK     (0x7 << 2)		/* Mask for comparator clock */
83 
84 /** Edge selection for comparator */
85 typedef enum {
86 	ACMP_EDGESEL_FALLING = (0 << 17),	/* Set the COMPEDGE bit on falling edge */
87 	ACMP_EDGESEL_RISING  = (1 << 17),	/* Set the COMPEDGE bit on rising edge */
88 	ACMP_EDGESEL_BOTH    = (2 << 17)	/* Set the COMPEDGE bit on falling and rising edges */
89 } CHIP_ACMP_EDGESEL_T;
90 
91 /** Hysteresis selection for comparator */
92 typedef enum {
93 	ACMP_HYS_NONE = (0 << 13),	/* No hysteresis (the output will switch as the voltages cross) */
94 	ACMP_HYS_5MV  = (1 << 13),	/* 5mV hysteresis */
95 	ACMP_HYS_10MV = (2 << 13),	/* 10mV hysteresis */
96 	ACMP_HYS_15MV = (3 << 13)	/* 20mV hysteresis */
97 } CHIP_ACMP_HYS_T;
98 
99 /**
100  * Analog Comparator positive input values
101  */
102 typedef enum CHIP_ACMP_POS_INPUT {
103 	ACMP_POSIN_VREF_DIV  = (0 << 8),	/*!< Voltage ladder output */
104 	ACMP_POSIN_ACMP_I1   = (1 << 8),	/*!< ACMP_I1 pin */
105 	ACMP_POSIN_ACMP_I2   = (2 << 8),	/*!< ACMP_I2 pin */
106 	ACMP_POSIN_ACMP_I3   = (3 << 8),	/*!< ACMP_I3 pin */
107 	ACMP_POSIN_ACMP_I4   = (4 << 8),	/*!< ACMP_I4 pin */
108 	ACMP_POSIN_INT_REF   = (5 << 8),	/*!< Internal reference voltage */
109 	ACMP_POSIN_ADCIN_1   = (6 << 8),	/*!< ADC Input or Temperature sensor varies with comparator */
110 	ACMP_POSIN_ADCIN_2   = (7 << 8)		/*!< ADC Input varies with comparator */
111 } CHIP_ACMP_POS_INPUT_T;
112 
113 /**
114  * Analog Comparator negative input values
115  */
116 typedef enum CHIP_ACMP_NEG_INPUT {
117 	ACMP_NEGIN_VREF_DIV  = (0 << 4),	/*!< Voltage ladder output */
118 	ACMP_NEGIN_ACMP_I1   = (1 << 4),	/*!< ACMP_I1 pin */
119 	ACMP_NEGIN_ACMP_I2   = (2 << 4),	/*!< ACMP_I2 pin */
120 	ACMP_NEGIN_ACMP_I3   = (3 << 4),	/*!< ACMP_I3 pin */
121 	ACMP_NEGIN_ACMP_I4   = (4 << 4),	/*!< ACMP_I4 pin */
122 	ACMP_NEGIN_INT_REF   = (5 << 4),	/*!< Internal reference voltage */
123 	ACMP_NEGIN_ADCIN_1   = (6 << 4),	/*!< ADC Input or Temperature sensor varies with comparator */
124 	ACMP_NEGIN_ADCIN_2   = (7 << 4)		/*!< ADC Input varies with comparator */
125 } CHIP_ACMP_NEG_INPUT_T;
126 
127 /**
128  * Analog Comparator sample mode values
129  */
130 typedef enum {
131 	ACMP_SMODE_0 = 0,	/*!< Bypass filter */
132 	ACMP_SMODE_1,		/*!< Reject pulses shorter than 1 filter clock cycle */
133 	ACMP_SMODE_2,		/*!< Reject pulses shorter than 2 filter clock cycle */
134 	ACMP_SMODE_3		/*!< Reject pulses shorter than 3 filter clock cycle */
135 } CHIP_ACMP_SMODE_T;
136 
137 /**
138  * Analog Comparator clock divider values
139  */
140 typedef enum {
141 	ACMP_CLKDIV_1  =  (0x0 << 2),	/*!< Use CMP_PCLK */
142 	ACMP_CLKDIV_2  =  (0x1 << 2),	/*!< Use CMP_PCLK/2 */
143 	ACMP_CLKDIV_4  =  (0x2 << 2),	/*!< Use CMP_PCLK/4 */
144 	ACMP_CLKDIV_8  =  (0x3 << 2),	/*!< Use CMP_PCLK/8 */
145 	ACMP_CLKDIV_16 =  (0x4 << 2),	/*!< Use CMP_PCLK/16 */
146 	ACMP_CLKDIV_32 =  (0x5 << 2),	/*!< Use CMP_PCLK/32 */
147 	ACMP_CLKDIV_64 =  (0x6 << 2)	/*!< Use CMP_PCLK/64 */
148 } CHIP_ACMP_CLKDIV_T;
149 
150 /**
151  * @brief	Initializes the ACMP
152  * @param	pACMP	: Pointer to Analog Comparator block
153  * @return	Nothing
154  */
155 void Chip_ACMP_Init(LPC_CMP_T *pACMP);
156 
157 /**
158  * @brief	Deinitializes the ACMP
159  * @param	pACMP	: Pointer to Analog Comparator block
160  * @return	Nothing
161  */
162 void Chip_ACMP_Deinit(LPC_CMP_T *pACMP);
163 
164 /**
165  * @brief	Enable the comparator
166  * @param	pACMP	: Pointer to Analog Comparator block
167  * @param	index	: index to the comparator (0 - 3)
168  * @return	Nothing
169  */
Chip_ACMP_EnableComp(LPC_CMP_T * pACMP,uint8_t index)170 STATIC INLINE void Chip_ACMP_EnableComp(LPC_CMP_T *pACMP, uint8_t index)
171 {
172 	/* Make sure interrupt flag is not set during read write operation */
173 	pACMP->ACMP[index].CMP = (pACMP->ACMP[index].CMP & ~ACMP_INTFLAG_BIT) | ACMP_CMPEN_BIT;
174 }
175 
176 /**
177  * @brief	Disable the comparator
178  * @param	pACMP	: Pointer to Analog Comparator block
179  * @param	index	: index to the comparator (0 - 3)
180  * @return	Nothing
181  */
Chip_ACMP_DisableComp(LPC_CMP_T * pACMP,uint8_t index)182 STATIC INLINE void Chip_ACMP_DisableComp(LPC_CMP_T *pACMP, uint8_t index)
183 {
184 	pACMP->ACMP[index].CMP = (pACMP->ACMP[index].CMP & ~ACMP_INTFLAG_BIT) & ~ACMP_CMPEN_BIT;
185 }
186 
187 /**
188  * @brief	Enable the interrupt for the comparator
189  * @param	pACMP	: Pointer to Analog Comparator block
190  * @param	index	: index to the comparator (0 - 3)
191  * @return	Nothing
192  */
Chip_ACMP_EnableCompInt(LPC_CMP_T * pACMP,uint8_t index)193 STATIC INLINE void Chip_ACMP_EnableCompInt(LPC_CMP_T *pACMP, uint8_t index)
194 {
195 	/* Make sure interrupt flag is not set during read write operation */
196 	pACMP->ACMP[index].CMP = (pACMP->ACMP[index].CMP & ~ACMP_INTFLAG_BIT) | ACMP_INTEN_BIT;
197 }
198 
199 /**
200  * @brief	Disable the interrupt for the comparator
201  * @param	pACMP	: Pointer to Analog Comparator block
202  * @param	index	: index to the comparator (0 - 3)
203  * @return	Nothing
204  */
Chip_ACMP_DisableCompInt(LPC_CMP_T * pACMP,uint8_t index)205 STATIC INLINE void Chip_ACMP_DisableCompInt(LPC_CMP_T *pACMP, uint8_t index)
206 {
207 	/* Make sure interrupt flag is not set during read write operation */
208 	pACMP->ACMP[index].CMP = (pACMP->ACMP[index].CMP & ~ACMP_INTFLAG_BIT) & ~ACMP_INTEN_BIT;
209 }
210 
211 /**
212  * @brief	Returns the current comparator status
213  * @param	pACMP	: Pointer to Analog Comparator block
214  * @param	index	: index to the comparator (0 - 3)
215  * @return TRUE if ACMP_STATUS_BIT is set else returns FALSE
216  */
Chip_ACMP_GetCompStatus(LPC_CMP_T * pACMP,uint8_t index)217 STATIC INLINE bool Chip_ACMP_GetCompStatus(LPC_CMP_T *pACMP, uint8_t index)
218 {
219 	return (pACMP->ACMP[index].CMP & ACMP_STATUS_BIT) != 0;
220 }
221 
222 /**
223  * @brief	Selects positive voltage input
224  * @param	pACMP	: Pointer to Analog Comparator block
225  * @param	index	: index to the comparator (0 - 3)
226  * @param	Posinput: one of the positive input voltage sources
227  * @return	Nothing
228  */
229 void Chip_ACMP_SetPosVoltRef(LPC_CMP_T *pACMP, uint8_t index, CHIP_ACMP_POS_INPUT_T Posinput);
230 
231 /**
232  * @brief	Selects negative voltage input
233  * @param	pACMP	: Pointer to Analog Comparator block
234  * @param	index	: index to the comparator (0 - 3)
235  * @param	Neginput: one of the negative input voltage sources
236  * @return	Nothing
237  */
238 void Chip_ACMP_SetNegVoltRef(LPC_CMP_T *pACMP, uint8_t index, CHIP_ACMP_NEG_INPUT_T Neginput);
239 
240 /**
241  * @brief	Selects hysteresis level
242  * @param	pACMP	: Pointer to Analog Comparator block
243  * @param	index	: index to the comparator (0 - 3)
244  * @param   hys : Selected Hysteresis level
245  * @return	Nothing
246  */
247 void Chip_ACMP_SetHysteresis(LPC_CMP_T *pACMP, uint8_t index, CHIP_ACMP_HYS_T hys);
248 
249 /**
250  * @brief	Set the ACMP interrupt polarity (INTPOL bit)
251  * @param	pACMP	: Pointer to Analog Comparator block
252  * @param	index	: index to the comparator (0 - 3)
253  * @return	Nothing
254  */
Chip_ACMP_SetIntPolarity(LPC_CMP_T * pACMP,uint8_t index)255 STATIC INLINE void Chip_ACMP_SetIntPolarity(LPC_CMP_T *pACMP, uint8_t index)
256 {
257 	/* Make sure interrupt flag is not set during read write operation */
258 	pACMP->ACMP[index].CMP = (pACMP->ACMP[index].CMP & ~ACMP_INTFLAG_BIT) | ACMP_INTPOL_BIT;
259 }
260 
261 /**
262  * @brief	Clear the ACMP interrupt polarity (INTPOL bit)
263  * @param	pACMP	: Pointer to Analog Comparator block
264  * @param	index	: index to the comparator (0 - 3)
265  * @return	Nothing
266  */
Chip_ACMP_ClearIntPolarity(LPC_CMP_T * pACMP,uint8_t index)267 STATIC INLINE void Chip_ACMP_ClearIntPolarity(LPC_CMP_T *pACMP, uint8_t index)
268 {
269 	/* Make sure interrupt flag is not set during read write operation */
270 	pACMP->ACMP[index].CMP = (pACMP->ACMP[index].CMP & ~ACMP_INTFLAG_BIT) & ~ACMP_INTPOL_BIT;
271 }
272 
273 /**
274  * @brief	Set the ACMP interrupt type as edge (INTTYPE bit)
275  * @param	pACMP	: Pointer to Analog Comparator block
276  * @param	index	: index to the comparator (0 - 3)
277  * @return	Nothing
278  */
Chip_ACMP_SetIntTypeEdge(LPC_CMP_T * pACMP,uint8_t index)279 STATIC INLINE void Chip_ACMP_SetIntTypeEdge(LPC_CMP_T *pACMP, uint8_t index)
280 {
281 	/* Make sure interrupt flag is not set during read write operation */
282 	pACMP->ACMP[index].CMP = (pACMP->ACMP[index].CMP & ~ACMP_INTFLAG_BIT) & ~ACMP_INTTYPE_BIT;
283 }
284 
285 /**
286  * @brief	Set the ACMP interrupt type as level (INTTYPE bit)
287  * @param	pACMP	: Pointer to Analog Comparator block
288  * @param	index	: index to the comparator (0 - 3)
289  * @return	Nothing
290  */
Chip_ACMP_SetIntTypeLevel(LPC_CMP_T * pACMP,uint8_t index)291 STATIC INLINE void Chip_ACMP_SetIntTypeLevel(LPC_CMP_T *pACMP, uint8_t index)
292 {
293 	/* Make sure interrupt flag is not set during read write operation */
294 	pACMP->ACMP[index].CMP = (pACMP->ACMP[index].CMP & ~ACMP_INTFLAG_BIT) | ACMP_INTTYPE_BIT;
295 }
296 
297 /**
298  * @brief	Sets up ACMP edge selection
299  * @param	pACMP	: Pointer to Analog Comparator block
300  * @param	index	: index to the comparator (0 - 3)
301  * @param	edgeSel	: Edge selection value
302  * @return	Nothing
303  */
304 void Chip_ACMP_SetIntEdgeSelection(LPC_CMP_T *pACMP, uint8_t index, CHIP_ACMP_EDGESEL_T edgeSel);
305 
306 /**
307  * @brief	Get the ACMP interrupt flag bit(INTFLAG bit)
308  * @param	pACMP	: Pointer to Analog Comparator block
309  * @param	index	: index to the comparator (0 - 3)
310  * @return	TRUE if ACMP_INTFLAG_BIT is set else returns FALSE
311  */
Chip_ACMP_GetIntFlag(LPC_CMP_T * pACMP,uint8_t index)312 STATIC INLINE bool Chip_ACMP_GetIntFlag(LPC_CMP_T *pACMP, uint8_t index)
313 {
314 	return (pACMP->ACMP[index].CMP & ACMP_INTFLAG_BIT) != 0;
315 }
316 
317 /**
318  * @brief	Clears the ACMP interrupt flag bit (INTFLAG bit)
319  * @param	pACMP	: Pointer to Analog Comparator block
320  * @param	index	: index to the comparator (0 - 3)
321  * @return	Nothing
322  */
Chip_ACMP_ClearIntFlag(LPC_CMP_T * pACMP,uint8_t index)323 STATIC INLINE void Chip_ACMP_ClearIntFlag(LPC_CMP_T *pACMP, uint8_t index)
324 {
325 	pACMP->ACMP[index].CMP |= ACMP_INTFLAG_BIT;
326 }
327 
328 /**
329  * @brief	Helper function for setting up ACMP voltage settings
330  * @param	pACMP		: Pointer to Analog Comparator block
331  * @param	index		: index to the comparator (0 - 3)
332  * @param	Posinput	: one of the positive input voltage sources
333  * @param	Neginput	: one of the negative input voltage sources
334  * @param	hys			: Selected Hysteresis level
335  * @return	Nothing
336  */
337 void Chip_ACMP_SetupACMPRefs(LPC_CMP_T *pACMP, uint8_t index,
338 							 CHIP_ACMP_POS_INPUT_T Posinput, CHIP_ACMP_NEG_INPUT_T Neginput,
339 							 CHIP_ACMP_HYS_T hys);
340 
341 /**
342  * @brief	Helper function for setting up ACMP interrupt settings
343  * @param	pACMP	: Pointer to Analog Comparator block
344  * @param	index	: index to the comparator (0 - 3)
345  * @param	level	: interrupt type false - edge, true - level
346  * @param	invert	: polarity of CMP output for interrupt, false - Not Inverted, true - Inverted
347  * @param	edgeSel	: Edge selection value
348  * @return	Nothing
349  */
350 void Chip_ACMP_SetupACMPInt(LPC_CMP_T *pACMP, uint8_t index, bool level,
351 							bool invert, CHIP_ACMP_EDGESEL_T edgeSel);
352 
353 /**
354  * @brief	Sets up voltage ladder
355  * @param	pACMP			: Pointer to Analog Comparator block
356  * @param	index			: index to the comparator (0 - 3)
357  * @param	ladsel			: Voltage ladder value (0 .. 31)
358  * @param	ladrefVDDCMP	: Selects the reference voltage Vref for the voltage ladder
359  *							        true for VDD, false for VDDCMP pin
360  * @return	Nothing
361  */
362 void Chip_ACMP_SetupVoltLadder(LPC_CMP_T *pACMP, uint8_t index, uint32_t ladsel, bool ladrefVDDCMP);
363 
364 /**
365  * @brief	Enables voltage ladder
366  * @param	pACMP	: Pointer to Analog Comparator block
367  * @param	index	: index to the comparator (0 - 3)
368  * @return	Nothing
369  */
Chip_ACMP_EnableVoltLadder(LPC_CMP_T * pACMP,uint8_t index)370 STATIC INLINE void Chip_ACMP_EnableVoltLadder(LPC_CMP_T *pACMP, uint8_t index)
371 {
372 	/* Make sure interrupt flag is not set during read write operation */
373 	pACMP->ACMP[index].CMP = (pACMP->ACMP[index].CMP & ~ACMP_INTFLAG_BIT) | ACMP_LADENAB_BIT;
374 }
375 
376 /**
377  * @brief	Disables voltage ladder
378  * @param	pACMP	: Pointer to Analog Comparator block
379  * @param	index	: index to the comparator (0 - 3)
380  * @return	Nothing
381  */
Chip_ACMP_DisableVoltLadder(LPC_CMP_T * pACMP,uint8_t index)382 STATIC INLINE void Chip_ACMP_DisableVoltLadder(LPC_CMP_T *pACMP, uint8_t index)
383 {
384 	/* Make sure interrupt flag is not set during read write operation */
385 	pACMP->ACMP[index].CMP = (pACMP->ACMP[index].CMP & ~ACMP_INTFLAG_BIT) & ~ACMP_LADENAB_BIT;
386 }
387 
388 /**
389  * @brief	Set propogation delay for comparator output
390  * @param	pACMP	: Pointer to Analog Comparator block
391  * @param	index	: index to the comparator (0 - 3)
392  * @param	delay	: propogation delay (0 - 2), 0 is short delay more power consumption
393  * @return	Nothing
394  */
Chip_ACMP_SetPropagationDelay(LPC_CMP_T * pACMP,uint8_t index,uint8_t delay)395 STATIC INLINE void Chip_ACMP_SetPropagationDelay(LPC_CMP_T *pACMP, uint8_t index, uint8_t delay)
396 {
397 	/* Make sure interrupt flag is not set during read write operation */
398 	pACMP->ACMP[index].CMP =
399 		((pACMP->ACMP[index].CMP & ~ACMP_INTFLAG_BIT) & ~ACMP_PROPDLY_MASK) | ((uint32_t) delay << 29);
400 }
401 
402 /**
403  * @brief	Set filter sample mode
404  * @param	pACMP	: Pointer to Analog Comparator block
405  * @param	index	: index to the comparator (0 - 3)
406  * @param	mode	: sample mode enum value
407  * @return	Nothing
408  */
Chip_ACMP_SetSampleMode(LPC_CMP_T * pACMP,uint8_t index,CHIP_ACMP_SMODE_T mode)409 STATIC INLINE void Chip_ACMP_SetSampleMode(LPC_CMP_T *pACMP, uint8_t index, CHIP_ACMP_SMODE_T mode)
410 {
411 	pACMP->ACMP[index].CMPFILTR = (pACMP->ACMP[index].CMPFILTR & ~ACMP_SMODE_MASK) | (uint32_t) mode;
412 }
413 
414 /**
415  * @brief	Set clock divider
416  * @param	pACMP	: Pointer to Analog Comparator block
417  * @param	index	: index to the comparator (0 - 3)
418  * @param	div		: SysClk divider enum value
419  * @return	Nothing
420  */
Chip_ACMP_SetClockDiv(LPC_CMP_T * pACMP,uint8_t index,CHIP_ACMP_CLKDIV_T div)421 STATIC INLINE void Chip_ACMP_SetClockDiv(LPC_CMP_T *pACMP, uint8_t index, CHIP_ACMP_CLKDIV_T div)
422 {
423 	pACMP->ACMP[index].CMPFILTR = (pACMP->ACMP[index].CMPFILTR & ~ACMP_CLKDIV_MASK) | (uint32_t) div;
424 }
425 
426 /**
427  * @brief	Setup Comparator filter register
428  * @param	pACMP	: Pointer to Analog Comparator block
429  * @param	index	: index to the comparator (0 - 3)
430  * @param	mode	: sample mode enum value
431  * @param	div		: SysClk divider enum value
432  * @return	Nothing
433  */
Chip_ACMP_SetCompFiltReg(LPC_CMP_T * pACMP,uint8_t index,CHIP_ACMP_SMODE_T mode,CHIP_ACMP_CLKDIV_T div)434 STATIC INLINE void Chip_ACMP_SetCompFiltReg(LPC_CMP_T *pACMP,
435 											uint8_t index,
436 											CHIP_ACMP_SMODE_T mode,
437 											CHIP_ACMP_CLKDIV_T div)
438 {
439 	pACMP->ACMP[index].CMPFILTR = (uint32_t) mode | (uint32_t) div;
440 }
441 
442 /**
443  * @brief	Set Ring Oscillator control bit, ROSC output is set by ACMP1 and reset by ACMP0
444  * @param	pACMP	: Pointer to Analog Comparator block
445  * @return	Nothing
446  */
Chip_ACMP_SetRingOscCtl(LPC_CMP_T * pACMP)447 STATIC INLINE void Chip_ACMP_SetRingOscCtl(LPC_CMP_T *pACMP)
448 {
449 	pACMP->CTRL |= ACMP_ROSCCTL_BIT;
450 }
451 
452 /**
453  * @brief	Clear Ring Oscillator control bit, ROSC output is set by ACMP0 and reset by ACMP1
454  * @param	pACMP	: Pointer to Analog Comparator block
455  * @return	Nothing
456  */
Chip_ACMP_ClearRingOscCtl(LPC_CMP_T * pACMP)457 STATIC INLINE void Chip_ACMP_ClearRingOscCtl(LPC_CMP_T *pACMP)
458 {
459 	pACMP->CTRL &= ~ACMP_ROSCCTL_BIT;
460 }
461 
462 /**
463  * @brief	Set Ring Oscillator Reset Source to Internal
464  * @param	pACMP	: Pointer to Analog Comparator block
465  * @return	Nothing
466  */
Chip_ACMP_SetROscResetSrcInternal(LPC_CMP_T * pACMP)467 STATIC INLINE void Chip_ACMP_SetROscResetSrcInternal(LPC_CMP_T *pACMP)
468 {
469 	pACMP->CTRL &= ~ACMP_EXTRESET_BIT;
470 }
471 
472 /**
473  * @brief	Set Ring Oscillator Reset Source to External
474  * @param	pACMP	: Pointer to Analog Comparator block
475  * @return	Nothing
476  */
Chip_ACMP_SetROscResetSrcExternal(LPC_CMP_T * pACMP)477 STATIC INLINE void Chip_ACMP_SetROscResetSrcExternal(LPC_CMP_T *pACMP)
478 {
479 	pACMP->CTRL |= ACMP_EXTRESET_BIT;
480 }
481 
482 /**
483  * @}
484  */
485 
486 #ifdef __cplusplus
487 }
488 #endif
489 
490 #endif /* __ACMP_15XX_H_ */
491