1 /***************************************************************************//**
2 * \file cy_lpcomp.h
3 * \version 1.30
4 *
5 * This file provides constants and parameter values for the Low Power Comparator driver.
6 *
7 ********************************************************************************
8 * \copyright
9 * Copyright 2016-2020 Cypress Semiconductor Corporation
10 * SPDX-License-Identifier: Apache-2.0
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *******************************************************************************/
24
25 /**
26 * \addtogroup group_lpcomp
27 * \{
28 * Provides access to the low-power comparators implemented using the fixed-function
29 * LP comparator block that is present in PSoC 6.
30 *
31 * The functions and other declarations used in this driver are in cy_lpcomp.h.
32 * You can include cy_pdl.h to get access to all functions
33 * and declarations in the PDL.
34 *
35 * These comparators can perform fast analog signal comparison of internal
36 * and external analog signals in all system power modes. Low-power comparator
37 * output can be inspected by the CPU, used as an interrupt/wakeup source to the
38 * CPU when in low-power mode (Sleep, Low-Power Sleep, or Deep-Sleep), used as
39 * a wakeup source to system resources when in Hibernate mode, or fed to DSI as
40 * an asynchronous or synchronous signal (level or pulse).
41 *
42 * \section group_lpcomp_section_Configuration_Considerations Configuration Considerations
43 * To set up an LPComp, the inputs, the output, the mode, the interrupts and
44 * other configuration parameters should be configured. Power the LPComp to operate.
45 *
46 * The sequence recommended for the LPComp operation:
47 *
48 * 1) To initialize the driver, call the Cy_LPComp_Init() function providing
49 * the filled cy_stc_lpcomp_config_t structure, the LPComp channel number,
50 * and the LPCOMP registers structure pointer.
51 *
52 * 2) Optionally, configure the interrupt requests if the interrupt event
53 * triggering is needed. Use the Cy_LPComp_SetInterruptMask() function with
54 * the parameter for the mask available in the configuration file.
55 * Additionally, enable the Global interrupts and initialize the referenced
56 * interrupt by setting the priority and the interrupt vector using
57 * the \ref Cy_SysInt_Init() function of the sysint driver.
58 *
59 * 3) Configure the inputs and the output using the \ref Cy_GPIO_Pin_Init()
60 * functions of the GPIO driver.
61 * The High Impedance Analog drive mode is for the inputs and
62 * the Strong drive mode is for the output.
63 * Use the Cy_LPComp_SetInputs() function to connect the comparator inputs
64 * to the dedicated IO pins, AMUXBUSA/AMUXBUSB or Vref:
65 * \image html lpcomp_inputs.png
66 *
67 * 4) Power on the comparator using the Cy_LPComp_Enable() function.
68 *
69 * 5) The comparator output can be monitored using
70 * the Cy_LPComp_GetCompare() function or using the LPComp interrupt
71 * (if the interrupt is enabled).
72 *
73 * \note The interrupt is not cleared automatically.
74 * It is the user's responsibility to do that.
75 * The interrupt is cleared by writing a 1 in the corresponding interrupt
76 * register bit position. The preferred way to clear interrupt sources
77 * is using the Cy_LPComp_ClearInterrupt() function.
78 *
79 * \note Individual comparator interrupt outputs are ORed together
80 * as a single asynchronous interrupt source before it is sent out and
81 * used to wake up the system in the low-power mode.
82 * For PSoC 6 devices, the individual comparator interrupt is masked
83 * by the INTR_MASK register. The masked result is captured in
84 * the INTR_MASKED register.
85 * Writing a 1 to the INTR register bit will clear the interrupt.
86 *
87 * \section group_lpcomp_lp Low Power Support
88 * The LPComp provides the callback functions to facilitate
89 * the low-power mode transition. The callback
90 * \ref Cy_LPComp_DeepSleepCallback must be called during execution
91 * of \ref Cy_SysPm_CpuEnterDeepSleep; \ref Cy_LPComp_HibernateCallback must be
92 * called during execution of \ref Cy_SysPm_SystemEnterHibernate.
93 * To trigger the callback execution, the callback must be registered
94 * before calling the mode transition function.
95 * Refer to \ref group_syspm driver for more
96 * information about low-power mode transitions.
97 *
98 * The example below shows the entering into Hibernate mode.
99 * The positive LPComp input connects to dedicated GPIO pin and the
100 * negative LPComp input connects to the local reference.
101 * The LED blinks twice after device reset and goes into Hibernate mode.
102 * When the voltage on the positive input great than the local reference
103 * voltage (0.45V - 0.75V) the device wakes up and LED begins blinking.
104 * \snippet lpcomp/snippet/main.c LP_COMP_CFG_HIBERNATE
105 *
106 * \section group_lpcomp_more_information More Information
107 *
108 * Refer to the appropriate device technical reference manual (TRM) for
109 * a detailed description of the registers.
110 *
111 * \section group_lpcomp_Changelog Changelog
112 * <table class="doxtable">
113 * <tr><th>Version</th><th>Changes</th><th>Reason for Change</th></tr>
114 * <tr>
115 * <td>1.30</td>
116 * <td>Fixed/documented MISRA 2012 violations.</td>
117 * <td>MISRA 2012 compliance.</td>
118 * </tr>
119 * <tr>
120 * <td>1.20.1</td>
121 * <td>Minor documentation updates.</td>
122 * <td>Documentation enhancement.</td>
123 * </tr>
124 * <tr>
125 * <td rowspan="2">1.20</td>
126 * <td>Flattened the organization of the driver source code into the single
127 * source directory and the single include directory.
128 * </td>
129 * <td>Driver library directory-structure simplification.</td>
130 * </tr>
131 * <tr>
132 * <td>Added register access layer. Use register access macros instead
133 * of direct register access using dereferenced pointers.</td>
134 * <td>Makes register access device-independent, so that the PDL does
135 * not need to be recompiled for each supported part number.</td>
136 * </tr>
137 * <tr>
138 * <td>1.10.1</td>
139 * <td>Added Low Power Callback section</td>
140 * <td>Documentation update and clarification</td>
141 * </tr>
142 * <tr>
143 * <td>1.10</td>
144 * <td>The CY_WEAK keyword is removed from Cy_LPComp_DeepSleepCallback()
145 * and Cy_LPComp_HibernateCallback() functions<br>
146 * Added input parameter validation to the API functions.</td>
147 * <td></td>
148 * </tr>
149 * <tr>
150 * <td>1.0</td>
151 * <td>Initial version</td>
152 * <td></td>
153 * </tr>
154 * </table>
155 *
156 * \defgroup group_lpcomp_macros Macros
157 * \defgroup group_lpcomp_functions Functions
158 * \{
159 * \defgroup group_lpcomp_functions_syspm_callback Low Power Callback
160 * \}
161 * \defgroup group_lpcomp_data_structures Data Structures
162 * \defgroup group_lpcomp_enums Enumerated Types
163 */
164
165 #ifndef CY_LPCOMP_PDL_H
166 #define CY_LPCOMP_PDL_H
167
168 /******************************************************************************/
169 /* Include files */
170 /******************************************************************************/
171
172 #include "cy_device.h"
173
174 #if defined (CY_IP_MXLPCOMP)
175
176 #include <stdbool.h>
177 #include <stddef.h>
178 #include "cy_syslib.h"
179 #include "cy_syspm.h"
180
181 #ifdef __cplusplus
182 extern "C"
183 {
184 #endif
185
186 /**
187 * \addtogroup group_lpcomp_macros
188 * \{
189 */
190
191 /** Driver major version */
192 #define CY_LPCOMP_DRV_VERSION_MAJOR 1
193
194 /** Driver minor version */
195 #define CY_LPCOMP_DRV_VERSION_MINOR 30
196
197 /******************************************************************************
198 * API Constants
199 ******************************************************************************/
200
201 /**< LPCOMP PDL ID */
202 #define CY_LPCOMP_ID CY_PDL_DRV_ID(0x23u)
203
204 /** The LPCOMP's number of channels. */
205 #define CY_LPCOMP_MAX_CHANNEL_NUM (2u)
206
207 /** LPCOMP's comparator 1 interrupt mask. */
208 #define CY_LPCOMP_COMP0 (0x01u)
209 /** LPCOMP's comparator 2 interrupt mask. */
210 #define CY_LPCOMP_COMP1 (0x02u)
211
212 /** \cond INTERNAL_MACROS */
213
214
215 /******************************************************************************
216 * Registers Constants
217 ******************************************************************************/
218
219 #define CY_LPCOMP_MODE_ULP_Pos (0x0uL)
220 #define CY_LPCOMP_MODE_ULP_Msk (0x1uL)
221
222 #define CY_LPCOMP_INTR_Pos (LPCOMP_INTR_COMP0_Pos)
223 #define CY_LPCOMP_INTR_Msk (LPCOMP_INTR_COMP0_Msk | LPCOMP_INTR_COMP1_Msk)
224
225 #define CY_LPCOMP_CMP0_SW_POS_Msk (LPCOMP_CMP0_SW_CMP0_IP0_Msk | \
226 LPCOMP_CMP0_SW_CMP0_AP0_Msk | \
227 LPCOMP_CMP0_SW_CMP0_BP0_Msk)
228 #define CY_LPCOMP_CMP0_SW_NEG_Msk (LPCOMP_CMP0_SW_CMP0_IN0_Msk | \
229 LPCOMP_CMP0_SW_CMP0_AN0_Msk | \
230 LPCOMP_CMP0_SW_CMP0_BN0_Msk | \
231 LPCOMP_CMP0_SW_CMP0_VN0_Msk)
232 #define CY_LPCOMP_CMP1_SW_POS_Msk (LPCOMP_CMP1_SW_CMP1_IP1_Msk | \
233 LPCOMP_CMP1_SW_CMP1_AP1_Msk | \
234 LPCOMP_CMP1_SW_CMP1_BP1_Msk)
235 #define CY_LPCOMP_CMP1_SW_NEG_Msk (LPCOMP_CMP1_SW_CMP1_IN1_Msk | \
236 LPCOMP_CMP1_SW_CMP1_AN1_Msk | \
237 LPCOMP_CMP1_SW_CMP1_BN1_Msk | \
238 LPCOMP_CMP1_SW_CMP1_VN1_Msk)
239
240 #define CY_LPCOMP_CMP0_OUTPUT_CONFIG_Pos LPCOMP_CMP0_CTRL_DSI_BYPASS0_Pos
241 #define CY_LPCOMP_CMP1_OUTPUT_CONFIG_Pos LPCOMP_CMP1_CTRL_DSI_BYPASS1_Pos
242
243 #define CY_LPCOMP_CMP0_OUTPUT_CONFIG_Msk (LPCOMP_CMP0_CTRL_DSI_BYPASS0_Msk | \
244 LPCOMP_CMP0_CTRL_DSI_LEVEL0_Msk)
245
246 #define CY_LPCOMP_CMP1_OUTPUT_CONFIG_Msk (LPCOMP_CMP1_CTRL_DSI_BYPASS1_Msk | \
247 LPCOMP_CMP1_CTRL_DSI_LEVEL1_Msk)
248
249 #define CY_HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_SR_Pos HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_Pos
250
251 #define CY_HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_SR_Msk (HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SL_Msk | \
252 HSIOM_AMUX_SPLIT_CTL_SWITCH_AA_SR_Msk)
253
254 #define CY_HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_SR_Pos HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_Pos
255
256 #define CY_HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_SR_Msk (HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SL_Msk | \
257 HSIOM_AMUX_SPLIT_CTL_SWITCH_BB_SR_Msk)
258
259 #define CY_LPCOMP_REF_CONNECTED (1u)
260
261 #define CY_LPCOMP_WAKEUP_PIN0_Msk CY_SYSPM_WAKEUP_LPCOMP0
262 #define CY_LPCOMP_WAKEUP_PIN1_Msk CY_SYSPM_WAKEUP_LPCOMP1
263
264 /* Internal constants for Cy_LPComp_Enable() */
265 #define CY_LPCOMP_NORMAL_POWER_DELAY (3u)
266 #define CY_LPCOMP_LP_POWER_DELAY (6u)
267 #define CY_LPCOMP_ULP_POWER_DELAY (50u)
268
269 /** \endcond */
270 /** \} group_lpcomp_macros */
271
272 /**
273 * \addtogroup group_lpcomp_enums
274 * \{
275 */
276
277 /******************************************************************************
278 * Enumerations
279 *****************************************************************************/
280 /** The LPCOMP output modes. */
281 typedef enum
282 {
283 CY_LPCOMP_OUT_PULSE = 0u, /**< The LPCOMP DSI output with the pulse option, no bypass. */
284 CY_LPCOMP_OUT_DIRECT = 1u, /**< The LPCOMP bypass mode, the direct output of a comparator. */
285 CY_LPCOMP_OUT_SYNC = 2u /**< The LPCOMP DSI output with the level option, it is similar
286 to the bypass mode but it is 1 cycle slow than the bypass. */
287 } cy_en_lpcomp_out_t;
288
289 /** The LPCOMP hysteresis modes. */
290 typedef enum
291 {
292 CY_LPCOMP_HYST_ENABLE = 1u, /**< The LPCOMP enable hysteresis. */
293 CY_LPCOMP_HYST_DISABLE = 0u /**< The LPCOMP disable hysteresis. */
294 } cy_en_lpcomp_hyst_t;
295
296 /** The LPCOMP's channel number. */
297 typedef enum
298 {
299 CY_LPCOMP_CHANNEL_0 = 0x1u, /**< The LPCOMP Comparator 0. */
300 CY_LPCOMP_CHANNEL_1 = 0x2u /**< The LPCOMP Comparator 1. */
301 } cy_en_lpcomp_channel_t;
302
303 /** The LPCOMP interrupt modes. */
304 typedef enum
305 {
306 CY_LPCOMP_INTR_DISABLE = 0u, /**< The LPCOMP interrupt disabled, no interrupt will be detected. */
307 CY_LPCOMP_INTR_RISING = 1u, /**< The LPCOMP interrupt on the rising edge. */
308 CY_LPCOMP_INTR_FALLING = 2u, /**< The LPCOMP interrupt on the falling edge. */
309 CY_LPCOMP_INTR_BOTH = 3u /**< The LPCOMP interrupt on both rising and falling edges. */
310 } cy_en_lpcomp_int_t;
311
312 /** The LPCOMP power-mode selection. */
313 typedef enum
314 {
315 CY_LPCOMP_MODE_OFF = 0u, /**< The LPCOMP's channel power-off. */
316 CY_LPCOMP_MODE_ULP = 1u, /**< The LPCOMP's channel ULP mode. */
317 CY_LPCOMP_MODE_LP = 2u, /**< The LPCOMP's channel LP mode. */
318 CY_LPCOMP_MODE_NORMAL = 3u /**< The LPCOMP's channel normal mode. */
319 } cy_en_lpcomp_pwr_t;
320
321 /** The LPCOMP inputs. */
322 typedef enum
323 {
324 CY_LPCOMP_SW_GPIO = 0x01u, /**< The LPCOMP input connects to GPIO pin. */
325 CY_LPCOMP_SW_AMUXBUSA = 0x02u, /**< The LPCOMP input connects to AMUXBUSA. */
326 CY_LPCOMP_SW_AMUXBUSB = 0x04u, /**< The LPCOMP input connects to AMUXBUSB. */
327 CY_LPCOMP_SW_LOCAL_VREF = 0x08u /**< The LPCOMP input connects to local VREF. */
328 } cy_en_lpcomp_inputs_t;
329
330 /** The LPCOMP error codes. */
331 typedef enum
332 {
333 CY_LPCOMP_SUCCESS = 0x00u, /**< Successful */
334 CY_LPCOMP_BAD_PARAM = CY_LPCOMP_ID | CY_PDL_STATUS_ERROR | 0x01u, /**< One or more invalid parameters */
335 CY_LPCOMP_TIMEOUT = CY_LPCOMP_ID | CY_PDL_STATUS_ERROR | 0x02u, /**< Operation timed out */
336 CY_LPCOMP_INVALID_STATE = CY_LPCOMP_ID | CY_PDL_STATUS_ERROR | 0x03u, /**< Operation not setup or is in an improper state */
337 CY_LPCOMP_UNKNOWN = CY_LPCOMP_ID | CY_PDL_STATUS_ERROR | 0xFFu, /**< Unknown failure */
338 } cy_en_lpcomp_status_t;
339
340 /** \} group_lpcomp_enums */
341
342 /**
343 * \addtogroup group_lpcomp_data_structures
344 * \{
345 */
346
347 /******************************************************************************
348 * Structures
349 *****************************************************************************/
350
351 /** The LPCOMP configuration structure. */
352 typedef struct {
353 cy_en_lpcomp_out_t outputMode; /**< The LPCOMP's outputMode: Direct output,
354 Synchronized output or Pulse output */
355 cy_en_lpcomp_hyst_t hysteresis; /**< Enables or disables the LPCOMP's hysteresis */
356 cy_en_lpcomp_pwr_t power; /**< Sets the LPCOMP power mode */
357 cy_en_lpcomp_int_t intType; /**< Sets the LPCOMP interrupt mode */
358 } cy_stc_lpcomp_config_t;
359
360 /** \cond CONTEXT_STRUCTURE */
361
362 typedef struct {
363 cy_en_lpcomp_int_t intType[CY_LPCOMP_MAX_CHANNEL_NUM];
364 cy_en_lpcomp_pwr_t power[CY_LPCOMP_MAX_CHANNEL_NUM];
365 } cy_stc_lpcomp_context_t;
366
367 /** \endcond */
368
369 /** \} group_lpcomp_data_structures */
370
371 /** \cond INTERNAL_MACROS */
372
373 /******************************************************************************
374 * Macros
375 *****************************************************************************/
376 #define CY_LPCOMP_IS_CHANNEL_VALID(channel) (((channel) == CY_LPCOMP_CHANNEL_0) || \
377 ((channel) == CY_LPCOMP_CHANNEL_1))
378 #define CY_LPCOMP_IS_OUT_MODE_VALID(mode) (((mode) == CY_LPCOMP_OUT_PULSE) || \
379 ((mode) == CY_LPCOMP_OUT_DIRECT) || \
380 ((mode) == CY_LPCOMP_OUT_SYNC))
381 #define CY_LPCOMP_IS_HYSTERESIS_VALID(hyst) (((hyst) == CY_LPCOMP_HYST_ENABLE) || \
382 ((hyst) == CY_LPCOMP_HYST_DISABLE))
383 #define CY_LPCOMP_IS_INTR_MODE_VALID(intr) (((intr) == CY_LPCOMP_INTR_DISABLE) || \
384 ((intr) == CY_LPCOMP_INTR_RISING) || \
385 ((intr) == CY_LPCOMP_INTR_FALLING) || \
386 ((intr) == CY_LPCOMP_INTR_BOTH))
387 #define CY_LPCOMP_IS_POWER_VALID(power) (((power) == CY_LPCOMP_MODE_OFF) || \
388 ((power) == CY_LPCOMP_MODE_ULP) || \
389 ((power) == CY_LPCOMP_MODE_LP) || \
390 ((power) == CY_LPCOMP_MODE_NORMAL))
391 #define CY_LPCOMP_IS_INTR_VALID(intr) (((intr) == CY_LPCOMP_COMP0) || \
392 ((intr) == CY_LPCOMP_COMP1) || \
393 ((intr) == (CY_LPCOMP_COMP0 | CY_LPCOMP_COMP1)))
394 #define CY_LPCOMP_IS_INPUT_P_VALID(input) (((input) == CY_LPCOMP_SW_GPIO) || \
395 ((input) == CY_LPCOMP_SW_AMUXBUSA) || \
396 ((input) == CY_LPCOMP_SW_AMUXBUSB))
397 #define CY_LPCOMP_IS_INPUT_N_VALID(input) (((input) == CY_LPCOMP_SW_GPIO) || \
398 ((input) == CY_LPCOMP_SW_AMUXBUSA) || \
399 ((input) == CY_LPCOMP_SW_AMUXBUSB) || \
400 ((input) == CY_LPCOMP_SW_LOCAL_VREF))
401
402 /** \endcond */
403
404 /**
405 * \addtogroup group_lpcomp_functions
406 * \{
407 */
408
409 /******************************************************************************
410 * Functions
411 *******************************************************************************/
412
413 cy_en_lpcomp_status_t Cy_LPComp_Init(LPCOMP_Type *base, cy_en_lpcomp_channel_t channel, const cy_stc_lpcomp_config_t *config);
414 void Cy_LPComp_Enable(LPCOMP_Type* base, cy_en_lpcomp_channel_t channel);
415 void Cy_LPComp_Disable(LPCOMP_Type* base, cy_en_lpcomp_channel_t channel);
416 __STATIC_INLINE void Cy_LPComp_GlobalEnable(LPCOMP_Type *base);
417 __STATIC_INLINE void Cy_LPComp_GlobalDisable(LPCOMP_Type *base);
418 __STATIC_INLINE void Cy_LPComp_UlpReferenceEnable(LPCOMP_Type *base);
419 __STATIC_INLINE void Cy_LPComp_UlpReferenceDisable(LPCOMP_Type *base);
420 __STATIC_INLINE uint32_t Cy_LPComp_GetCompare(LPCOMP_Type const * base, cy_en_lpcomp_channel_t channel);
421 void Cy_LPComp_SetPower(LPCOMP_Type* base, cy_en_lpcomp_channel_t channel, cy_en_lpcomp_pwr_t power);
422 void Cy_LPComp_SetHysteresis(LPCOMP_Type* base, cy_en_lpcomp_channel_t channel, cy_en_lpcomp_hyst_t hysteresis);
423 void Cy_LPComp_SetInputs(LPCOMP_Type* base, cy_en_lpcomp_channel_t channel, cy_en_lpcomp_inputs_t inputP, cy_en_lpcomp_inputs_t inputN);
424 void Cy_LPComp_SetOutputMode(LPCOMP_Type* base, cy_en_lpcomp_channel_t channel, cy_en_lpcomp_out_t outType);
425 void Cy_LPComp_SetInterruptTriggerMode(LPCOMP_Type* base, cy_en_lpcomp_channel_t channel, cy_en_lpcomp_int_t intType);
426 __STATIC_INLINE uint32_t Cy_LPComp_GetInterruptStatus(LPCOMP_Type const * base);
427 __STATIC_INLINE void Cy_LPComp_ClearInterrupt(LPCOMP_Type* base, uint32_t interrupt);
428 __STATIC_INLINE void Cy_LPComp_SetInterrupt(LPCOMP_Type* base, uint32_t interrupt);
429 __STATIC_INLINE uint32_t Cy_LPComp_GetInterruptMask(LPCOMP_Type const * base);
430 __STATIC_INLINE void Cy_LPComp_SetInterruptMask(LPCOMP_Type* base, uint32_t interrupt);
431 __STATIC_INLINE uint32_t Cy_LPComp_GetInterruptStatusMasked(LPCOMP_Type const * base);
432 __STATIC_INLINE void Cy_LPComp_ConnectULPReference(LPCOMP_Type *base, cy_en_lpcomp_channel_t channel);
433 /** \addtogroup group_lpcomp_functions_syspm_callback
434 * The driver supports SysPm callback for Deep Sleep and Hibernate transition.
435 * \{
436 */
437 cy_en_syspm_status_t Cy_LPComp_DeepSleepCallback(cy_stc_syspm_callback_params_t *callbackParams, cy_en_syspm_callback_mode_t mode);
438 cy_en_syspm_status_t Cy_LPComp_HibernateCallback(cy_stc_syspm_callback_params_t *callbackParams, cy_en_syspm_callback_mode_t mode);
439 /** \} */
440
441
442 /*******************************************************************************
443 * Function Name: Cy_LPComp_GlobalEnable
444 ****************************************************************************//**
445 *
446 * Activates the IP of the LPCOMP hardware block. This API should be enabled
447 * before operating any channel of comparators.
448 * Note: Interrupts can be enabled after the block is enabled and the appropriate
449 * start-up time has elapsed:
450 * 3 us for the normal power mode;
451 * 6 us for the LP mode;
452 * 50 us for the ULP mode.
453 *
454 * \param *base
455 * The structure of the channel pointer.
456 *
457 * \return None
458 *
459 *******************************************************************************/
Cy_LPComp_GlobalEnable(LPCOMP_Type * base)460 __STATIC_INLINE void Cy_LPComp_GlobalEnable(LPCOMP_Type* base)
461 {
462 LPCOMP_CONFIG(base) |= LPCOMP_CONFIG_ENABLED_Msk;
463 }
464
465
466 /*******************************************************************************
467 * Function Name: Cy_LPComp_GlobalDisable
468 ****************************************************************************//**
469 *
470 * Deactivates the IP of the LPCOMP hardware block.
471 * (Analog in power down, open all switches, all clocks off).
472 *
473 * \param *base
474 * The structure of the channel pointer.
475 *
476 * \return None
477 *
478 *******************************************************************************/
Cy_LPComp_GlobalDisable(LPCOMP_Type * base)479 __STATIC_INLINE void Cy_LPComp_GlobalDisable(LPCOMP_Type *base)
480 {
481 LPCOMP_CONFIG(base) &= (uint32_t) ~LPCOMP_CONFIG_ENABLED_Msk;
482 }
483
484
485 /*******************************************************************************
486 * Function Name: Cy_LPComp_UlpReferenceEnable
487 ****************************************************************************//**
488 *
489 * Enables the local reference-generator circuit.
490 *
491 * \param *base
492 * The structure of the channel pointer.
493 *
494 * \return None
495 *
496 *******************************************************************************/
Cy_LPComp_UlpReferenceEnable(LPCOMP_Type * base)497 __STATIC_INLINE void Cy_LPComp_UlpReferenceEnable(LPCOMP_Type *base)
498 {
499 LPCOMP_CONFIG(base) |= LPCOMP_CONFIG_LPREF_EN_Msk;
500 }
501
502
503 /*******************************************************************************
504 * Function Name: Cy_LPComp_UlpReferenceDisable
505 ****************************************************************************//**
506 *
507 * Disables the local reference-generator circuit.
508 *
509 * \param *base
510 * The structure of the channel pointer.
511 *
512 * \return None
513 *
514 *******************************************************************************/
Cy_LPComp_UlpReferenceDisable(LPCOMP_Type * base)515 __STATIC_INLINE void Cy_LPComp_UlpReferenceDisable(LPCOMP_Type *base)
516 {
517 LPCOMP_CONFIG(base) &= (uint32_t) ~LPCOMP_CONFIG_LPREF_EN_Msk;
518 }
519
520
521 /*******************************************************************************
522 * Function Name: Cy_LPComp_GetCompare
523 ****************************************************************************//**
524 *
525 * This function returns a nonzero value when the voltage connected to the
526 * positive input is greater than the negative input voltage.
527 *
528 * \param *base
529 * The LPComp register structure pointer.
530 *
531 * \param channel
532 * The LPComp channel index.
533 *
534 * \return LPComp compare result.
535 * The value is a nonzero value when the voltage connected to the positive
536 * input is greater than the negative input voltage.
537 *
538 *******************************************************************************/
Cy_LPComp_GetCompare(LPCOMP_Type const * base,cy_en_lpcomp_channel_t channel)539 __STATIC_INLINE uint32_t Cy_LPComp_GetCompare(LPCOMP_Type const * base, cy_en_lpcomp_channel_t channel)
540 {
541 uint32_t result;
542
543 CY_ASSERT_L3(CY_LPCOMP_IS_CHANNEL_VALID(channel));
544
545 if (CY_LPCOMP_CHANNEL_0 == channel)
546 {
547 result = _FLD2VAL(LPCOMP_STATUS_OUT0, LPCOMP_STATUS(base));
548 }
549 else
550 {
551 result = _FLD2VAL(LPCOMP_STATUS_OUT1, LPCOMP_STATUS(base));
552 }
553
554 return (result);
555 }
556
557
558 /*******************************************************************************
559 * Function Name: Cy_LPComp_SetInterruptMask
560 ****************************************************************************//**
561 *
562 * Configures which bits of the interrupt request register will trigger an
563 * interrupt event.
564 *
565 * \param *base
566 * The LPCOMP register structure pointer.
567 *
568 * \param interrupt
569 * uint32_t interruptMask: Bit Mask of interrupts to set.
570 * Bit 0: COMP0 Interrupt Mask
571 * Bit 1: COMP1 Interrupt Mask
572 *
573 * \return None
574 *
575 *******************************************************************************/
Cy_LPComp_SetInterruptMask(LPCOMP_Type * base,uint32_t interrupt)576 __STATIC_INLINE void Cy_LPComp_SetInterruptMask(LPCOMP_Type* base, uint32_t interrupt)
577 {
578 CY_ASSERT_L2(CY_LPCOMP_IS_INTR_VALID(interrupt));
579
580 LPCOMP_INTR_MASK(base) |= interrupt;
581 }
582
583
584 /*******************************************************************************
585 * Function Name: Cy_LPComp_GetInterruptMask
586 ****************************************************************************//**
587 *
588 * Returns an interrupt mask.
589 *
590 * \param *base
591 * The LPCOMP register structure pointer.
592 *
593 * \return bit mapping information
594 * Bit 0: COMP0 Interrupt Mask
595 * Bit 1: COMP1 Interrupt Mask
596 *
597 *******************************************************************************/
Cy_LPComp_GetInterruptMask(LPCOMP_Type const * base)598 __STATIC_INLINE uint32_t Cy_LPComp_GetInterruptMask(LPCOMP_Type const * base)
599 {
600 return (LPCOMP_INTR_MASK(base));
601 }
602
603
604 /*******************************************************************************
605 * Function Name: Cy_LPComp_GetInterruptStatusMasked
606 ****************************************************************************//**
607 *
608 * Returns an interrupt request register masked by an interrupt mask.
609 * Returns the result of the bitwise AND operation between the corresponding
610 * interrupt request and mask bits.
611 *
612 * \param *base
613 * The LPCOMP register structure pointer.
614 *
615 * \return bit mapping information
616 * Bit 0: COMP0 Interrupt Masked
617 * Bit 1: COMP1 Interrupt Masked
618 *
619 *******************************************************************************/
Cy_LPComp_GetInterruptStatusMasked(LPCOMP_Type const * base)620 __STATIC_INLINE uint32_t Cy_LPComp_GetInterruptStatusMasked(LPCOMP_Type const * base)
621 {
622 return (LPCOMP_INTR_MASKED(base));
623 }
624
625
626 /*******************************************************************************
627 * Function Name: Cy_LPComp_GetInterruptStatus
628 ****************************************************************************//**
629 *
630 * Returns the status of 2 different LPCOMP interrupt requests.
631 *
632 * \param *base
633 * The LPCOMP register structure pointer.
634 *
635 * \return bit mapping information
636 * Bit 0: COMP0 Interrupt status
637 * Bit 1: COMP1 Interrupt status
638 *
639 *******************************************************************************/
Cy_LPComp_GetInterruptStatus(LPCOMP_Type const * base)640 __STATIC_INLINE uint32_t Cy_LPComp_GetInterruptStatus(LPCOMP_Type const * base)
641 {
642 return (_FLD2VAL(CY_LPCOMP_INTR, LPCOMP_INTR(base)));
643 }
644
645
646 /*******************************************************************************
647 * Function Name: Cy_LPComp_ClearInterrupt
648 ****************************************************************************//**
649 *
650 * Clears LPCOMP interrupts by setting each bit.
651 *
652 * \param *base
653 * The LPCOMP register structure pointer.
654 *
655 * \param interrupt
656 * Bit 0: COMP0 Interrupt status
657 * Bit 1: COMP1 Interrupt status
658 *
659 * \return None
660 *
661 *******************************************************************************/
Cy_LPComp_ClearInterrupt(LPCOMP_Type * base,uint32_t interrupt)662 __STATIC_INLINE void Cy_LPComp_ClearInterrupt(LPCOMP_Type* base, uint32_t interrupt)
663 {
664 CY_ASSERT_L2(CY_LPCOMP_IS_INTR_VALID(interrupt));
665 LPCOMP_INTR(base) |= interrupt;
666 (void) LPCOMP_INTR(base);
667 }
668
669
670 /*******************************************************************************
671 * Function Name: Cy_LPComp_SetInterrupt
672 ****************************************************************************//**
673 *
674 * Sets a software interrupt request.
675 * This function is used in the case of combined interrupt signal from the global
676 * signal reference. This function from either component instance can be used
677 * to trigger either or both software interrupts. It sets the INTR_SET interrupt mask.
678 *
679 * \param *base
680 * The LPCOMP register structure pointer.
681 *
682 * \param interrupt
683 * Bit 0: COMP0 Interrupt status
684 * Bit 1: COMP1 Interrupt status
685 *
686 * \return None
687 *
688 *******************************************************************************/
Cy_LPComp_SetInterrupt(LPCOMP_Type * base,uint32_t interrupt)689 __STATIC_INLINE void Cy_LPComp_SetInterrupt(LPCOMP_Type* base, uint32_t interrupt)
690 {
691 CY_ASSERT_L2(CY_LPCOMP_IS_INTR_VALID(interrupt));
692 LPCOMP_INTR_SET(base) = interrupt;
693 }
694
695
696 /*******************************************************************************
697 * Function Name: Cy_LPComp_ConnectULPReference
698 ****************************************************************************//**
699 *
700 * Connects the local reference generator output to the comparator negative input.
701 *
702 * \param *base
703 * The LPCOMP register structure pointer.
704 *
705 * \param channel
706 * The LPCOMP channel index.
707 *
708 * \return None
709 *
710 *******************************************************************************/
Cy_LPComp_ConnectULPReference(LPCOMP_Type * base,cy_en_lpcomp_channel_t channel)711 __STATIC_INLINE void Cy_LPComp_ConnectULPReference(LPCOMP_Type *base, cy_en_lpcomp_channel_t channel)
712 {
713 CY_ASSERT_L3(CY_LPCOMP_IS_CHANNEL_VALID(channel));
714
715 if (CY_LPCOMP_CHANNEL_0 == channel)
716 {
717 LPCOMP_CMP0_SW_CLEAR(base) = CY_LPCOMP_CMP0_SW_NEG_Msk;
718 LPCOMP_CMP0_SW(base) = _CLR_SET_FLD32U(LPCOMP_CMP0_SW(base), LPCOMP_CMP0_SW_CMP0_VN0, CY_LPCOMP_REF_CONNECTED);
719 }
720 else
721 {
722 LPCOMP_CMP1_SW_CLEAR(base) = CY_LPCOMP_CMP1_SW_NEG_Msk;
723 LPCOMP_CMP1_SW(base) = _CLR_SET_FLD32U(LPCOMP_CMP1_SW(base), LPCOMP_CMP1_SW_CMP1_VN1, CY_LPCOMP_REF_CONNECTED);
724 }
725 }
726
727 /** \} group_lpcomp_functions */
728
729 #ifdef __cplusplus
730 }
731 #endif
732
733 #endif /* CY_IP_MXLPCOMP */
734
735 #endif /* CY_LPCOMP_PDL_H */
736
737 /** \} group_lpcomp */
738
739 /* [] END OF FILE */
740