2 * @brief Analog comparator driver
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * All rights reserved.
\r
9 * Software that is described herein is for illustrative purposes only
\r
10 * which provides customers with programming information regarding the
\r
11 * LPC products. This software is supplied "AS IS" without any warranties of
\r
12 * any kind, and NXP Semiconductors and its licenser disclaim any and
\r
13 * all warranties, express or implied, including all implied warranties of
\r
14 * merchantability, fitness for a particular purpose and non-infringement of
\r
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
16 * or liability for the use of the software, conveys no license or rights under any
\r
17 * patent, copyright, mask work right, or any other intellectual property rights in
\r
18 * or to any products. NXP Semiconductors reserves the right to make changes
\r
19 * in the software without notification. NXP Semiconductors also makes no
\r
20 * representation or warranty that such application will be suitable for the
\r
21 * specified use without further testing or modification.
\r
24 * Permission to use, copy, modify, and distribute this software and its
\r
25 * documentation is hereby granted, under NXP Semiconductors' and its
\r
26 * licensor's relevant copyrights in the software, without fee, provided that it
\r
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
28 * copyright, permission, and disclaimer notice must appear in all copies of
\r
32 #ifndef __ACMP_001_H_
\r
33 #define __ACMP_001_H_
\r
35 #include "sys_config.h"
\r
42 /** @defgroup IP_ACMP_001 IP: Analog comparator driver
\r
43 * @ingroup IP_Drivers
\r
48 * @brief Analog Comparator register block structure
\r
50 typedef struct { /*!< ACMP Structure */
\r
51 __IO uint32_t CTRL; /*!< Comparator control register */
\r
52 __IO uint32_t LAD; /*!< Voltage ladder register */
\r
55 #define ACMP_COMPSA_BIT (1 << 6) /* Comparator output control bit */
\r
56 #define ACMP_COMPSTAT_BIT (1 << 21) /* Comparator status, reflects the state of the comparator output */
\r
57 #define ACMP_COMPEDGE_BIT (1 << 23) /* Comparator edge-detect status */
\r
58 #define ACMP_LADENAB_BIT (1 << 0) /* Voltage ladder enable bit */
\r
60 /** Edge selection for comparator */
\r
61 typedef enum IP_ACMP_001_EDGESEL {
\r
62 ACMP_EDGESEL_FALLING = (0 << 3), /* Set the COMPEDGE bit on falling edge */
\r
63 ACMP_EDGESEL_RISING = (1 << 3), /* Set the COMPEDGE bit on rising edge */
\r
64 ACMP_EDGESEL_BOTH = (2 << 3) /* Set the COMPEDGE bit on falling and rising edges */
\r
65 } IP_ACMP_001_EDGESEL_T;
\r
67 /** Hysteresis selection for comparator */
\r
68 typedef enum IP_ACMP_HYS_001 {
\r
69 ACMP_HYS_NONE = (0 << 25), /* No hysteresis (the output will switch as the voltages cross) */
\r
70 ACMP_HYS_5MV = (1 << 25), /* 5mV hysteresis */
\r
71 ACMP_HYS_10MV = (2 << 25), /* 10mV hysteresis */
\r
72 ACMP_HYS_20MV = (3 << 25) /* 20mV hysteresis */
\r
73 } IP_ACMP_HYS_001_T;
\r
76 * @brief Initializes the ACMP
\r
77 * @param pACMP : Pointer to Analog Comparator block
\r
80 STATIC INLINE void IP_ACMP_Init(ACMP_001_T *pACMP) {}
\r
83 * @brief De-initializes the ACMP
\r
84 * @param pACMP : Pointer to Analog Comparator block
\r
87 STATIC INLINE void IP_ACMP_Deinit(ACMP_001_T *pACMP) {}
\r
90 * @brief Returns the current comparator status
\r
91 * @param pACMP : Pointer to Analog Comparator block
\r
92 * @return Status is an Or'ed value of ACMP_COMPSTAT_BIT or ACMP_COMPEDGE_BIT
\r
94 STATIC INLINE uint32_t IP_ACMP_GetCompStatus(ACMP_001_T *pACMP)
\r
96 return pACMP->CTRL & (ACMP_COMPSTAT_BIT | ACMP_COMPEDGE_BIT);
\r
100 * @brief Clears the ACMP interrupt (EDGECLR bit)
\r
101 * @param pACMP : Pointer to Analog Comparator block
\r
104 void IP_ACMP_EdgeClear(ACMP_001_T *pACMP);
\r
107 * @brief Sets up ACMP edge selection
\r
108 * @param pACMP : Pointer to Analog Comparator block
\r
109 * @param edgeSel : Edge selection value
\r
112 void IP_ACMP_SetEdgeSelection(ACMP_001_T *pACMP, IP_ACMP_001_EDGESEL_T edgeSel);
\r
115 * @brief Synchronizes Comparator output to bus clock
\r
116 * @param pACMP : Pointer to Analog Comparator block
\r
119 STATIC INLINE void IP_ACMP_EnableSyncCompOut(ACMP_001_T *pACMP)
\r
121 pACMP->CTRL |= ACMP_COMPSA_BIT;
\r
125 * @brief Sets comparator output to be used directly (no sync)
\r
126 * @param pACMP : Pointer to Analog Comparator block
\r
129 STATIC INLINE void IP_ACMP_DisableSyncCompOut(ACMP_001_T *pACMP)
\r
131 pACMP->CTRL &= ~ACMP_COMPSA_BIT;
\r
135 * @brief Selects positive voltage input
\r
136 * @param pACMP : Pointer to Analog Comparator block
\r
137 * @param Posinput : one of the positive input voltage sources
\r
139 * @note The caller must pre-shift the Posinput value to the
\r
140 * correct bitfield location in the CTRL register.
\r
142 void IP_ACMP_SetPosVoltRef(ACMP_001_T *pACMP, uint32_t Posinput);
\r
145 * @brief Selects negative voltage input
\r
146 * @param pACMP : Pointer to Analog Comparator block
\r
147 * @param Neginput : one of the negative input voltage sources
\r
149 * @note The caller must pre-shift the Neginput value to the
\r
150 * correct bitfield location in the CTRL register.
\r
152 void IP_ACMP_SetNegVoltRef(ACMP_001_T *pACMP, uint32_t Neginput);
\r
155 * @brief Selects hysteresis level
\r
156 * @param pACMP : Pointer to Analog Comparator block
\r
157 * @param hys : Selected Hysteresis level
\r
160 void IP_ACMP_SetHysteresis(ACMP_001_T *pACMP, IP_ACMP_HYS_001_T hys);
\r
163 * @brief Helper function for setting up ACMP control
\r
164 * @param pACMP : Pointer to Analog Comparator block
\r
165 * @param edgeSel : Edge selection value
\r
166 * @param Posinput : one of the positive input voltage sources
\r
167 * @param Neginput : one of the negative input voltage sources
\r
168 * @param hys : Selected Hysteresis level
\r
170 * @note The caller must pre-shift the Posinput and Neginput values to the
\r
171 * correct bitfield location in the CTRL register.
\r
173 void IP_ACMP_SetupAMCPRefs(ACMP_001_T *pACMP, IP_ACMP_001_EDGESEL_T edgeSel,
\r
174 uint32_t Posinput, uint32_t Neginput, IP_ACMP_HYS_001_T hys);
\r
177 * @brief Sets up voltage ladder
\r
178 * @param pACMP : Pointer to Analog Comparator block
\r
179 * @param ladsel : Voltage ladder value
\r
180 * @param ladrefVDDCMP : Selects the reference voltage Vref for the voltage ladder
\r
181 * : false for VDD, true for VDDCMP pin
\r
183 * @note The caller must pre-shift the ladsel value to the
\r
184 * correct bitfield location in the LAD register.
\r
186 void IP_ACMP_SetupVoltLadder(ACMP_001_T *pACMP, uint32_t ladsel, bool ladrefVDDCMP);
\r
189 * @brief Enables voltage ladder
\r
190 * @param pACMP : Pointer to Analog Comparator block
\r
193 STATIC INLINE void IP_ACMP_EnableVoltLadder(ACMP_001_T *pACMP)
\r
195 pACMP->LAD |= ACMP_LADENAB_BIT;
\r
199 * @brief Disables voltage ladder
\r
200 * @param pACMP : Pointer to Analog Comparator block
\r
203 STATIC INLINE void IP_ACMP_DisableVoltLadder(ACMP_001_T *pACMP)
\r
205 pACMP->LAD &= ~ACMP_LADENAB_BIT;
\r
216 #endif /* __ACMP_001_H_ */
\r