1 /*
2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
3 * Copyright 2016-2020, 2023-2024 NXP
4 * All rights reserved.
5 *
6 *
7 * SPDX-License-Identifier: BSD-3-Clause
8 */
9
10 #ifndef FSL_LPCMP_H_
11 #define FSL_LPCMP_H_
12
13 #include "fsl_common.h"
14
15 /*!
16 * @addtogroup lpcmp
17 * @{
18 */
19
20 /*******************************************************************************
21 * Definitions
22 ******************************************************************************/
23 /*! @name Driver version */
24 /*! @{ */
25 /*! @brief LPCMP driver version 2.1.3. */
26 #define FSL_LPCMP_DRIVER_VERSION (MAKE_VERSION(2, 1, 3))
27 /*! @} */
28
29 #define LPCMP_CCR1_COUTA_CFG_MASK (LPCMP_CCR1_COUTA_OWEN_MASK | LPCMP_CCR1_COUTA_OW_MASK)
30 #define LPCMP_CCR1_COUTA_CFG_SHIFT LPCMP_CCR1_COUTA_OWEN_SHIFT
31 #define LPCMP_CCR1_COUTA_CFG(x) \
32 (((uint32_t)(((uint32_t)(x)) << LPCMP_CCR1_COUTA_CFG_SHIFT)) & LPCMP_CCR1_COUTA_CFG_MASK)
33
34 #define LPCMP_CCR1_EVT_SEL_CFG_MASK (LPCMP_CCR1_EVT_SEL_MASK | LPCMP_CCR1_WINDOW_CLS_MASK)
35 #define LPCMP_CCR1_EVT_SEL_CFG_SHIFT LPCMP_CCR1_WINDOW_CLS_SHIFT
36 #define LPCMP_CCR1_EVT_SEL_CFG(x) \
37 (((uint32_t)(((uint32_t)(x)) << LPCMP_CCR1_EVT_SEL_CFG_SHIFT)) & LPCMP_CCR1_EVT_SEL_CFG_MASK)
38
39 /*!
40 * @brief LPCMP status falgs mask.
41 */
42 enum _lpcmp_status_flags
43 {
44 kLPCMP_OutputRisingEventFlag = LPCMP_CSR_CFR_MASK, /*!< Rising-edge on the comparison output has occurred. */
45 kLPCMP_OutputFallingEventFlag = LPCMP_CSR_CFF_MASK, /*!< Falling-edge on the comparison output has occurred. */
46 #if defined(FSL_FEATURE_LPCMP_HAS_CSR_RRF) && FSL_FEATURE_LPCMP_HAS_CSR_RRF
47 kLPCMP_OutputRoundRobinEventFlag = LPCMP_CSR_RRF_MASK, /*!< Detects when any channel's last comparison result is
48 different from the pre-set value in trigger mode. */
49 #endif /* FSL_FEATURE_LPCMP_HAS_CSR_RRF */
50 kLPCMP_OutputAssertEventFlag = LPCMP_CSR_COUT_MASK, /*!< Return the current value of the analog comparator output.
51 The flag does not support W1C. */
52 };
53
54 /*!
55 * @brief LPCMP interrupt enable/disable mask.
56 */
57 enum _lpcmp_interrupt_enable
58 {
59 kLPCMP_OutputRisingInterruptEnable = LPCMP_IER_CFR_IE_MASK, /*!< Comparator interrupt enable rising. */
60 kLPCMP_OutputFallingInterruptEnable = LPCMP_IER_CFF_IE_MASK, /*!< Comparator interrupt enable falling. */
61 #if defined(FSL_FEATURE_LPCMP_HAS_IER_RRF_IE) && FSL_FEATURE_LPCMP_HAS_IER_RRF_IE
62 kLPCMP_RoundRobinInterruptEnable = LPCMP_IER_RRF_IE_MASK, /*!< Comparator round robin mode interrupt
63 occurred when the comparison result changes for a given channel. */
64 #endif /* FSL_FEATURE_LPCMP_HAS_IER_RRF_IE */
65 };
66
67 /*!
68 * @brief LPCMP hysteresis mode. See chip data sheet to get the actual hystersis
69 * value with each level
70 */
71 typedef enum _lpcmp_hysteresis_mode
72 {
73 kLPCMP_HysteresisLevel0 = 0U, /*!< The hard block output has level 0 hysteresis internally. */
74 kLPCMP_HysteresisLevel1 = 1U, /*!< The hard block output has level 1 hysteresis internally. */
75 kLPCMP_HysteresisLevel2 = 2U, /*!< The hard block output has level 2 hysteresis internally. */
76 kLPCMP_HysteresisLevel3 = 3U, /*!< The hard block output has level 3 hysteresis internally. */
77 } lpcmp_hysteresis_mode_t;
78
79 /*!
80 * @brief LPCMP nano mode.
81 */
82 typedef enum _lpcmp_power_mode
83 {
84 kLPCMP_LowSpeedPowerMode = 0U, /*!< Low speed comparison mode is selected. */
85 kLPCMP_HighSpeedPowerMode = 1U, /*!< High speed comparison mode is selected. */
86 kLPCMP_NanoPowerMode = 2U, /*!< Nano power comparator is enabled. */
87 } lpcmp_power_mode_t;
88
89 /*!
90 * @brief Internal DAC reference voltage source.
91 */
92 typedef enum _lpcmp_dac_reference_voltage_source
93 {
94 kLPCMP_VrefSourceVin1 = 0U, /*!< vrefh_int is selected as resistor ladder network supply reference Vin. */
95 kLPCMP_VrefSourceVin2 = 1U, /*!< vrefh_ext is selected as resistor ladder network supply reference Vin. */
96 } lpcmp_dac_reference_voltage_source_t;
97
98 #if defined(FSL_FEATURE_LPCMP_HAS_CCR1_FUNC_CLK_SEL) && FSL_FEATURE_LPCMP_HAS_CCR1_FUNC_CLK_SEL
99 /*!
100 * @brief LPCMP functional mode clock source selection.
101 *
102 * Note: In different devices, the functional mode clock source selection is different,
103 * please refer to specific device Reference Manual for details.
104 */
105 typedef enum _lpcmp_functional_source_clock
106 {
107 kLPCMP_FunctionalClockSource0 = 0U, /*!< Select functional mode clock source0. */
108 kLPCMP_FunctionalClockSource1 = 1U, /*!< Select functional mode clock source1. */
109 kLPCMP_FunctionalClockSource2 = 2U, /*!< Select functional mode clock source2. */
110 kLPCMP_FunctionalClockSource3 = 3U, /*!< Select functional mode clock source3. */
111 } lpcmp_functional_source_clock_t;
112 #endif /* FSL_FEATURE_LPCMP_HAS_CCR1_FUNC_CLK_SEL */
113
114 #if defined(FSL_FEATURE_LPCMP_HAS_WINDOW_CONTROL) && FSL_FEATURE_LPCMP_HAS_WINDOW_CONTROL
115 /*!
116 * @brief Set the COUTA signal value when the window is closed.
117 */
118 typedef enum _lpcmp_couta_signal
119 {
120 kLPCMP_COUTASignalNoSet = 0U, /*!< NO set the COUTA signal value when the window is closed. */
121 kLPCMP_COUTASignalLow = 1U, /*!< Set COUTA signal low(0) when the window is closed. */
122 kLPCMP_COUTASignalHigh = 3U, /*!< Set COUTA signal high(1) when the window is closed. */
123 } lpcmp_couta_signal_t;
124
125 /*!
126 * @brief Set COUT event, which can close the active window in window mode.
127 */
128 typedef enum _lpcmp_close_window_event
129 {
130 kLPCMP_CLoseWindowEventNoSet = 0U, /*!< No Set COUT event, which can close the active window in window mode. */
131 kLPCMP_CloseWindowEventRisingEdge = 1U, /*!< Set rising edge COUT signal as COUT event. */
132 kLPCMP_CloseWindowEventFallingEdge = 3U, /*!< Set falling edge COUT signal as COUT event. */
133 kLPCMP_CLoseWindowEventBothEdge = 5U, /*!< Set both rising and falling edge COUT signal as COUT event. */
134 } lpcmp_close_window_event_t;
135 #endif /* FSL_FEATURE_LPCMP_HAS_WINDOW_CONTROL */
136
137 #if defined(FSL_FEATURE_LPCMP_HAS_ROUNDROBIN_MODE) && FSL_FEATURE_LPCMP_HAS_ROUNDROBIN_MODE
138 /*!
139 * @brief LPCMP round robin mode fixed mux port.
140 */
141 typedef enum _lpcmp_roundrobin_fixedmuxport
142 {
143 kLPCMP_FixedPlusMuxPort = 0U, /*!< Fixed plus mux port. */
144 kLPCMP_FixedMinusMuxPort = 1U, /*!< Fixed minus mux port. */
145 } lpcmp_roundrobin_fixedmuxport_t;
146
147 /*!
148 * @brief LPCMP round robin mode clock source selection.
149 *
150 * Note: In different devices,the round robin mode clock source selection is different,
151 * please refer to the specific device Reference Manual for details.
152 */
153 typedef enum _lpcmp_roundrobin_clock_source
154 {
155 kLPCMP_RoundRobinClockSource0 = 0U, /*!< Select roundrobin mode clock source0. */
156 kLPCMP_RoundRobinClockSource1 = 1U, /*!< Select roundrobin mode clock source1. */
157 kLPCMP_RoundRobinClockSource2 = 2U, /*!< Select roundrobin mode clock source2. */
158 kLPCMP_RoundRobinClockSource3 = 3U, /*!< Select roundrobin mode clock source3. */
159 } lpcmp_roundrobin_clock_source_t;
160
161 /*!
162 * @brief LPCMP round robin mode trigger source.
163 */
164 typedef enum _lpcmp_roundrobin_trigger_source
165 {
166 kLPCMP_TriggerSourceExternally = 0U, /*!< Select external trigger source. */
167 kLPCMP_TriggerSourceInternally = 1U, /*!< Select internal trigger source. */
168 } lpcmp_roundrobin_trigger_source_t;
169 #endif /* FSL_FEATURE_LPCMP_HAS_ROUNDROBIN_MODE */
170
171 /*!
172 * @brief Configure the filter.
173 */
174 typedef struct _lpcmp_filter_config
175 {
176 bool enableSample; /*!< Decide whether to use the external SAMPLE as a sampling clock input. */
177 uint8_t filterSampleCount; /*!< Filter Sample Count. Available range is 1-7; 0 disables the filter. */
178 uint8_t filterSamplePeriod; /*!< Filter Sample Period. The divider to the bus clock. Available range is 0-255. The
179 sampling clock must be at least 4 times slower than the system clock to the comparator.
180 So if enableSample is "false", filterSamplePeriod should be set greater than 4.*/
181 } lpcmp_filter_config_t;
182
183 /*!
184 * @brief configure the internal DAC.
185 */
186 typedef struct _lpcmp_dac_config
187 {
188 bool enableLowPowerMode; /*!< Decide whether to enable DAC low power mode. */
189 lpcmp_dac_reference_voltage_source_t referenceVoltageSource; /*!< Internal DAC supply voltage reference source. */
190 uint8_t DACValue; /*!< Value for the DAC Output Voltage. Different devices has different available range,
191 for specific values, please refer to the reference manual.*/
192 } lpcmp_dac_config_t;
193
194 /*!
195 * @brief Configures the comparator.
196 */
197 typedef struct _lpcmp_config
198 {
199 #if !(defined(FSL_FEATURE_LPCMP_HAS_NO_CCR0_CMP_STOP_EN) && FSL_FEATURE_LPCMP_HAS_NO_CCR0_CMP_STOP_EN)
200 bool enableStopMode; /*!< Decide whether to enable the comparator when in STOP modes. */
201 #endif /* !(defined(FSL_FEATURE_LPCMP_HAS_NO_CCR0_CMP_STOP_EN) && FSL_FEATURE_LPCMP_HAS_NO_CCR0_CMP_STOP_EN) */
202
203 bool enableOutputPin; /*!< Decide whether to enable the comparator is available in selected pin. */
204 bool useUnfilteredOutput; /*!< Decide whether to use unfiltered output. */
205 bool enableInvertOutput; /*!< Decide whether to inverts the comparator output. */
206 lpcmp_hysteresis_mode_t hysteresisMode; /*!< LPCMP hysteresis mode. */
207 lpcmp_power_mode_t powerMode; /*!< LPCMP power mode. */
208 #if defined(FSL_FEATURE_LPCMP_HAS_CCR1_FUNC_CLK_SEL) && FSL_FEATURE_LPCMP_HAS_CCR1_FUNC_CLK_SEL
209 lpcmp_functional_source_clock_t functionalSourceClock; /*!< Select LPCMP functional mode clock source. */
210 #endif /* FSL_FEATURE_LPCMP_HAS_CCR1_FUNC_CLK_SEL */
211 } lpcmp_config_t;
212
213 #if defined(FSL_FEATURE_LPCMP_HAS_WINDOW_CONTROL) && FSL_FEATURE_LPCMP_HAS_WINDOW_CONTROL
214 /*!
215 * @brief Configure the window mode control.
216 */
217 typedef struct _lpcmp_window_control_config
218 {
219 bool enableInvertWindowSignal; /*!< True: enable invert window signal, False: disable invert window signal. */
220 lpcmp_couta_signal_t COUTASignal; /*!< Decide whether to define the COUTA signal value when the window is closed. */
221 lpcmp_close_window_event_t closeWindowEvent; /*!< Decide whether to select COUT event signal edge defines
222 a COUT event to close window. */
223 } lpcmp_window_control_config_t;
224 #endif /* FSL_FEATURE_LPCMP_HAS_WINDOW_CONTROL */
225
226 #if defined(FSL_FEATURE_LPCMP_HAS_ROUNDROBIN_MODE) && FSL_FEATURE_LPCMP_HAS_ROUNDROBIN_MODE
227 /*!
228 * @brief Configure the round robin mode.
229 */
230 typedef struct _lpcmp_roundrobin_config
231 {
232 uint8_t initDelayModules; /*!< Comparator and DAC initialization delay modulus, See Reference Manual and DataSheet
233 for specific value. */
234 uint8_t sampleClockNumbers; /*!< Specify the number of the round robin clock cycles(0~3) to wait after scanning the
235 active channel before sampling the channel's comparison result. */
236 uint8_t channelSampleNumbers; /*!< Specify the number of samples for one channel, note that channelSampleNumbers
237 must not smaller than sampleTimeThreshhold. */
238 uint8_t sampleTimeThreshhold; /*!< Specify that for one channel, when (sampleTimeThreshhold + 1) sample results are
239 "1",the final result is "1", otherwise the final result is "0", note that the
240 sampleTimeThreshhold must not be larger than channelSampleNumbers. */
241 lpcmp_roundrobin_clock_source_t roundrobinClockSource; /*!< Decide which clock source to
242 choose in round robin mode. */
243 lpcmp_roundrobin_trigger_source_t roundrobinTriggerSource; /*!< Decide which trigger source to
244 choose in round robin mode. */
245 lpcmp_roundrobin_fixedmuxport_t fixedMuxPort; /*!< Decide which mux port to choose as
246 fixed channel in round robin mode. */
247 uint8_t fixedChannel; /*!< Indicate which channel of the fixed mux port is used in round robin mode. */
248 uint8_t checkerChannelMask; /*!< Indicate which channel of the non-fixed mux port to check its voltage value in
249 round robin mode, for example, if checkerChannelMask set to 0x11U means select
250 channel 0 and channel 4 as checker channel.*/
251 } lpcmp_roundrobin_config_t;
252 #endif /* FSL_FEATURE_LPCMP_HAS_ROUNDROBIN_MODE */
253
254 /*******************************************************************************
255 * API
256 ******************************************************************************/
257
258 #if defined(__cplusplus)
259 extern "C" {
260 #endif
261
262 /*!
263 * @name Initialization and configuration
264 * @{
265 */
266
267 /*!
268 * @brief Initialize the LPCMP
269 *
270 * This function initializes the LPCMP module. The operations included are:
271 * - Enabling the clock for LPCMP module.
272 * - Configuring the comparator.
273 * - Enabling the LPCMP module.
274 * Note: For some devices, multiple LPCMP instance share the same clock gate. In this case, to enable the clock for
275 * any instance enables all the LPCMPs. Check the chip reference manual for the clock assignment of the LPCMP.
276 *
277 * @param base LPCMP peripheral base address.
278 * @param config Pointer to "lpcmp_config_t" structure.
279 */
280 void LPCMP_Init(LPCMP_Type *base, const lpcmp_config_t *config);
281
282 /*!
283 * @brief De-initializes the LPCMP module.
284 *
285 * This function de-initializes the LPCMP module. The operations included are:
286 * - Disabling the LPCMP module.
287 * - Disabling the clock for LPCMP module.
288 *
289 * This function disables the clock for the LPCMP.
290 * Note: For some devices, multiple LPCMP instance shares the same clock gate. In this case, before disabling the
291 * clock for the LPCMP, ensure that all the LPCMP instances are not used.
292 *
293 * @param base LPCMP peripheral base address.
294 */
295 void LPCMP_Deinit(LPCMP_Type *base);
296
297 /*!
298 * @brief Gets an available pre-defined settings for the comparator's configuration.
299 *
300 * This function initializes the comparator configuration structure to these default values:
301 * @code
302 * config->enableStopMode = false;
303 * config->enableOutputPin = false;
304 * config->useUnfilteredOutput = false;
305 * config->enableInvertOutput = false;
306 * config->hysteresisMode = kLPCMP_HysteresisLevel0;
307 * config->powerMode = kLPCMP_LowSpeedPowerMode;
308 * config->functionalSourceClock = kLPCMP_FunctionalClockSource0;
309 * @endcode
310 * @param config Pointer to "lpcmp_config_t" structure.
311 */
312 void LPCMP_GetDefaultConfig(lpcmp_config_t *config);
313
314 /*!
315 * @brief Enable/Disable LPCMP module.
316 *
317 * @param base LPCMP peripheral base address.
318 * @param enable "true" means enable the module, and "false" means disable the module.
319 */
LPCMP_Enable(LPCMP_Type * base,bool enable)320 static inline void LPCMP_Enable(LPCMP_Type *base, bool enable)
321 {
322 if (enable)
323 {
324 base->CCR0 |= LPCMP_CCR0_CMP_EN_MASK;
325 }
326 else
327 {
328 base->CCR0 &= ~LPCMP_CCR0_CMP_EN_MASK;
329 }
330 }
331
332 /*!
333 * @brief Select the input channels for LPCMP. This function determines which input
334 * is selected for the negative and positive mux.
335 *
336 * @param base LPCMP peripheral base address.
337 * @param positiveChannel Positive side input channel number. Available range is 0-7.
338 * @param negativeChannel Negative side input channel number. Available range is 0-7.
339 */
340 void LPCMP_SetInputChannels(LPCMP_Type *base, uint32_t positiveChannel, uint32_t negativeChannel);
341
342 /*!
343 * @brief Enables/disables the DMA request for rising/falling events.
344 * Normally, the LPCMP generates a CPU interrupt if there is a rising/falling event. When
345 * DMA support is enabled and the rising/falling interrupt is enabled , the rising/falling
346 * event forces a DMA transfer request rather than a CPU interrupt instead.
347 *
348 * @param base LPCMP peripheral base address.
349 * @param enable "true" means enable DMA support, and "false" means disable DMA support.
350 */
LPCMP_EnableDMA(LPCMP_Type * base,bool enable)351 static inline void LPCMP_EnableDMA(LPCMP_Type *base, bool enable)
352 {
353 if (enable)
354 {
355 base->CCR1 |= LPCMP_CCR1_DMA_EN_MASK;
356 }
357 else
358 {
359 base->CCR1 &= ~LPCMP_CCR1_DMA_EN_MASK;
360 }
361 }
362
363 /*!
364 * @brief Configures the filter.
365 *
366 * @param base LPCMP peripheral base address.
367 * @param config Pointer to "lpcmp_filter_config_t" structure.
368 */
369 void LPCMP_SetFilterConfig(LPCMP_Type *base, const lpcmp_filter_config_t *config);
370
371 /*!
372 * @brief Configure the internal DAC module.
373 *
374 * @param base LPCMP peripheral base address.
375 * @param config Pointer to "lpcmp_dac_config_t" structure. If config is "NULL", disable internal DAC.
376 */
377 void LPCMP_SetDACConfig(LPCMP_Type *base, const lpcmp_dac_config_t *config);
378
379 /*!
380 * @brief Enable the interrupts.
381 *
382 * @param base LPCMP peripheral base address.
383 * @param mask Mask value for interrupts. See "_lpcmp_interrupt_enable".
384 */
LPCMP_EnableInterrupts(LPCMP_Type * base,uint32_t mask)385 static inline void LPCMP_EnableInterrupts(LPCMP_Type *base, uint32_t mask)
386 {
387 base->IER |= mask;
388 }
389
390 /*!
391 * @brief Disable the interrupts.
392 *
393 * @param base LPCMP peripheral base address.
394 * @param mask Mask value for interrupts. See "_lpcmp_interrupt_enable".
395 */
LPCMP_DisableInterrupts(LPCMP_Type * base,uint32_t mask)396 static inline void LPCMP_DisableInterrupts(LPCMP_Type *base, uint32_t mask)
397 {
398 base->IER &= ~mask;
399 }
400
401 /*!
402 * @brief Get the LPCMP status flags.
403 *
404 * @param base LPCMP peripheral base address.
405 *
406 * @return Mask value for the asserted flags. See "_lpcmp_status_flags".
407 */
LPCMP_GetStatusFlags(LPCMP_Type * base)408 static inline uint32_t LPCMP_GetStatusFlags(LPCMP_Type *base)
409 {
410 return base->CSR;
411 }
412
413 /*!
414 * @brief Clear the LPCMP status flags
415 *
416 * @param base LPCMP peripheral base address.
417 * @param mask Mask value for the flags. See "_lpcmp_status_flags".
418 */
LPCMP_ClearStatusFlags(LPCMP_Type * base,uint32_t mask)419 static inline void LPCMP_ClearStatusFlags(LPCMP_Type *base, uint32_t mask)
420 {
421 base->CSR = mask;
422 }
423
424 /*! @} */
425
426 /*!
427 * @name Window mode
428 * @{
429 */
430
431 /*!
432 * @brief Enable/Disable window mode.When any windowed mode is active, COUTA is clocked by
433 * the bus clock whenever WINDOW = 1. The last latched value is held when WINDOW = 0.
434 * The optionally inverted comparator output COUT_RAW is sampled on every bus clock
435 * when WINDOW=1 to generate COUTA.
436 *
437 * @param base LPCMP peripheral base address.
438 * @param enable "true" means enable window mode, and "false" means disable window mode.
439 */
LPCMP_EnableWindowMode(LPCMP_Type * base,bool enable)440 static inline void LPCMP_EnableWindowMode(LPCMP_Type *base, bool enable)
441 {
442 if (enable)
443 {
444 base->CCR1 |= LPCMP_CCR1_WINDOW_EN_MASK;
445 }
446 else
447 {
448 base->CCR1 &= ~LPCMP_CCR1_WINDOW_EN_MASK;
449 }
450 }
451
452 #if defined(FSL_FEATURE_LPCMP_HAS_WINDOW_CONTROL) && FSL_FEATURE_LPCMP_HAS_WINDOW_CONTROL
453 /*!
454 * @brief Configure the window control, users can use this API to implement operations on the window,
455 * such as inverting the window signal, setting the window closing event(only valid in windowing mode),
456 * and setting the COUTA signal after the window is closed(only valid in windowing mode).
457 *
458 * @param base LPCMP peripheral base address.
459 * @param config Pointer "lpcmp_window_control_config_t" structure.
460 */
461 void LPCMP_SetWindowControl(LPCMP_Type *base, const lpcmp_window_control_config_t *config);
462 #endif /* FSL_FEATURE_LPCMP_HAS_WINDOW_CONTROL */
463
464 /*! @} */
465
466 #if defined(FSL_FEATURE_LPCMP_HAS_ROUNDROBIN_MODE) && FSL_FEATURE_LPCMP_HAS_ROUNDROBIN_MODE
467 /*!
468 * @name RoundRobin mode
469 * @{
470 */
471
472 /*!
473 * @brief Configure the roundrobin mode.
474 *
475 * @param base LPCMP peripheral base address.
476 * @param config Pointer "lpcmp_roundrobin_config_t" structure.
477 */
478 void LPCMP_SetRoundRobinConfig(LPCMP_Type *base, const lpcmp_roundrobin_config_t *config);
479
480 /*!
481 * brief Configure the roundrobin internal timer reload value.
482 *
483 * param base LPCMP peripheral base address.
484 * param value RoundRobin internal timer reload value, allowed range:0x0UL-0xFFFFFFFUL.
485 */
486 void LPCMP_SetRoundRobinInternalTimer(LPCMP_Type *base, uint32_t value);
487
488 /*!
489 * @brief Enable/Disable roundrobin mode.
490 *
491 * @param base LPCMP peripheral base address.
492 * @param enable "true" means enable roundrobin mode, and "false" means disable roundrobin mode.
493 */
LPCMP_EnableRoundRobinMode(LPCMP_Type * base,bool enable)494 static inline void LPCMP_EnableRoundRobinMode(LPCMP_Type *base, bool enable)
495 {
496 if (enable)
497 {
498 base->RRCR0 |= LPCMP_RRCR0_RR_EN_MASK;
499 }
500 else
501 {
502 base->RRCR0 &= ~LPCMP_RRCR0_RR_EN_MASK;
503 }
504 }
505
506 /*!
507 * @brief Enable/Disable roundrobin internal timer, note that this function is only valid
508 * when using the internal trigger source.
509 *
510 * @param base LPCMP peripheral base address.
511 * @param enable "true" means enable roundrobin internal timer, and "false" means disable roundrobin internal timer.
512 */
LPCMP_EnableRoundRobinInternalTimer(LPCMP_Type * base,bool enable)513 static inline void LPCMP_EnableRoundRobinInternalTimer(LPCMP_Type *base, bool enable)
514 {
515 if (enable)
516 {
517 base->RRCR2 |= LPCMP_RRCR2_RR_TIMER_EN_MASK;
518 }
519 else
520 {
521 base->RRCR2 &= ~LPCMP_RRCR2_RR_TIMER_EN_MASK;
522 }
523 }
524
525 /*!
526 * @brief Set preset value for all channels, users can set all channels' preset vaule through this API,
527 * for example, if the mask set to 0x03U means channel0 and channel2's preset value set to 1U and other
528 * channels' preset value set to 0U.
529 *
530 * @param base LPCMP peripheral base address.
531 * @param mask Mask of channel index.
532 */
LPCMP_SetPreSetValue(LPCMP_Type * base,uint8_t mask)533 static inline void LPCMP_SetPreSetValue(LPCMP_Type *base, uint8_t mask)
534 {
535 base->RRCSR = (uint32_t)mask;
536 }
537
538 /*!
539 * @brief Get comparison results for all channels, users can get all channels' comparison
540 * results through this API.
541 *
542 * @param base LPCMP peripheral base address.
543 * @return return All channels' comparison result.
544 */
LPCMP_GetComparisonResult(LPCMP_Type * base)545 static inline uint8_t LPCMP_GetComparisonResult(LPCMP_Type *base)
546 {
547 return (uint8_t)base->RRCSR;
548 }
549
550 /*!
551 * @brief Clear input changed flags for single channel or multiple channels, users can clear
552 * input changed flag of a single channel or multiple channels through this API, for example,
553 * if the mask set to 0x03U means clear channel0 and channel2's input changed flags.
554 *
555 * @param base LPCMP peripheral base address.
556 * @param mask Mask of channel index.
557 */
LPCMP_ClearInputChangedFlags(LPCMP_Type * base,uint8_t mask)558 static inline void LPCMP_ClearInputChangedFlags(LPCMP_Type *base, uint8_t mask)
559 {
560 base->RRSR = (uint32_t)mask;
561 }
562
563 /*!
564 * @brief Get input changed flags for all channels, Users can get all channels' input changed
565 * flags through this API.
566 *
567 * @param base LPCMP peripheral base address.
568 * @return return All channels' changed flag.
569 */
LPCMP_GetInputChangedFlags(LPCMP_Type * base)570 static inline uint8_t LPCMP_GetInputChangedFlags(LPCMP_Type *base)
571 {
572 return (uint8_t)base->RRSR;
573 }
574
575 /*! @} */
576
577 #endif /* FSL_FEATURE_LPCMP_HAS_ROUNDROBIN_MODE */
578
579 #if defined(__cplusplus)
580 }
581 #endif
582
583 /*! @} */
584
585 #endif /* FSL_LPCMP_H_ */
586