1 /*
2 * Copyright (c) 2014 - 2023, Nordic Semiconductor ASA
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * 3. Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #ifndef NRF_LPCOMP_H_
35 #define NRF_LPCOMP_H_
36
37 #include <nrfx.h>
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 /**
44 * @defgroup nrf_lpcomp_hal LPCOMP HAL
45 * @{
46 * @ingroup nrf_lpcomp
47 * @brief Hardware access layer for managing the Low Power Comparator (LPCOMP) peripheral.
48 */
49
50 #if defined(LPCOMP_PSEL_PIN_Msk) || defined(__NRFX_DOXYGEN__)
51 /** @brief Symbol indicating whether the configuration of analog input using pin number is present. */
52 #define NRF_LPCOMP_HAS_AIN_AS_PIN 1
53 #else
54 #define NRF_LPCOMP_HAS_AIN_AS_PIN 0
55 #endif
56
57 /** @brief LPCOMP reference selection. */
58 typedef enum
59 {
60 #if (LPCOMP_REFSEL_RESOLUTION == 8) || defined(__NRFX_DOXYGEN__)
61 NRF_LPCOMP_REF_SUPPLY_1_8 = LPCOMP_REFSEL_REFSEL_SupplyOneEighthPrescaling, /**< Use supply with a 1/8 prescaler as reference. */
62 NRF_LPCOMP_REF_SUPPLY_2_8 = LPCOMP_REFSEL_REFSEL_SupplyTwoEighthsPrescaling, /**< Use supply with a 2/8 prescaler as reference. */
63 NRF_LPCOMP_REF_SUPPLY_3_8 = LPCOMP_REFSEL_REFSEL_SupplyThreeEighthsPrescaling, /**< Use supply with a 3/8 prescaler as reference. */
64 NRF_LPCOMP_REF_SUPPLY_4_8 = LPCOMP_REFSEL_REFSEL_SupplyFourEighthsPrescaling, /**< Use supply with a 4/8 prescaler as reference. */
65 NRF_LPCOMP_REF_SUPPLY_5_8 = LPCOMP_REFSEL_REFSEL_SupplyFiveEighthsPrescaling, /**< Use supply with a 5/8 prescaler as reference. */
66 NRF_LPCOMP_REF_SUPPLY_6_8 = LPCOMP_REFSEL_REFSEL_SupplySixEighthsPrescaling, /**< Use supply with a 6/8 prescaler as reference. */
67 NRF_LPCOMP_REF_SUPPLY_7_8 = LPCOMP_REFSEL_REFSEL_SupplySevenEighthsPrescaling, /**< Use supply with a 7/8 prescaler as reference. */
68 #elif (LPCOMP_REFSEL_RESOLUTION == 16) || defined(__NRFX_DOXYGEN__)
69 NRF_LPCOMP_REF_SUPPLY_1_8 = LPCOMP_REFSEL_REFSEL_Ref1_8Vdd, /**< Use supply with a 1/8 prescaler as reference. */
70 NRF_LPCOMP_REF_SUPPLY_2_8 = LPCOMP_REFSEL_REFSEL_Ref2_8Vdd, /**< Use supply with a 2/8 prescaler as reference. */
71 NRF_LPCOMP_REF_SUPPLY_3_8 = LPCOMP_REFSEL_REFSEL_Ref3_8Vdd, /**< Use supply with a 3/8 prescaler as reference. */
72 NRF_LPCOMP_REF_SUPPLY_4_8 = LPCOMP_REFSEL_REFSEL_Ref4_8Vdd, /**< Use supply with a 4/8 prescaler as reference. */
73 NRF_LPCOMP_REF_SUPPLY_5_8 = LPCOMP_REFSEL_REFSEL_Ref5_8Vdd, /**< Use supply with a 5/8 prescaler as reference. */
74 NRF_LPCOMP_REF_SUPPLY_6_8 = LPCOMP_REFSEL_REFSEL_Ref6_8Vdd, /**< Use supply with a 6/8 prescaler as reference. */
75 NRF_LPCOMP_REF_SUPPLY_7_8 = LPCOMP_REFSEL_REFSEL_Ref7_8Vdd, /**< Use supply with a 7/8 prescaler as reference. */
76 NRF_LPCOMP_REF_SUPPLY_1_16 = LPCOMP_REFSEL_REFSEL_Ref1_16Vdd, /**< Use supply with a 1/16 prescaler as reference. */
77 NRF_LPCOMP_REF_SUPPLY_3_16 = LPCOMP_REFSEL_REFSEL_Ref3_16Vdd, /**< Use supply with a 3/16 prescaler as reference. */
78 NRF_LPCOMP_REF_SUPPLY_5_16 = LPCOMP_REFSEL_REFSEL_Ref5_16Vdd, /**< Use supply with a 5/16 prescaler as reference. */
79 NRF_LPCOMP_REF_SUPPLY_7_16 = LPCOMP_REFSEL_REFSEL_Ref7_16Vdd, /**< Use supply with a 7/16 prescaler as reference. */
80 NRF_LPCOMP_REF_SUPPLY_9_16 = LPCOMP_REFSEL_REFSEL_Ref9_16Vdd, /**< Use supply with a 9/16 prescaler as reference. */
81 NRF_LPCOMP_REF_SUPPLY_11_16 = LPCOMP_REFSEL_REFSEL_Ref11_16Vdd, /**< Use supply with a 11/16 prescaler as reference. */
82 NRF_LPCOMP_REF_SUPPLY_13_16 = LPCOMP_REFSEL_REFSEL_Ref13_16Vdd, /**< Use supply with a 13/16 prescaler as reference. */
83 NRF_LPCOMP_REF_SUPPLY_15_16 = LPCOMP_REFSEL_REFSEL_Ref15_16Vdd, /**< Use supply with a 15/16 prescaler as reference. */
84 #endif
85 #if !NRF_LPCOMP_HAS_AIN_AS_PIN
86 NRF_LPCOMP_REF_EXT_REF0 = LPCOMP_REFSEL_REFSEL_ARef |
87 (LPCOMP_EXTREFSEL_EXTREFSEL_AnalogReference0 << 16), /**< External reference 0. */
88 NRF_LPCOMP_REF_EXT_REF1 = LPCOMP_REFSEL_REFSEL_ARef |
89 (LPCOMP_EXTREFSEL_EXTREFSEL_AnalogReference1 << 16), /**< External reference 1. */
90 #endif
91 } nrf_lpcomp_ref_t;
92
93 /** @brief LPCOMP input selection. */
94 #if NRF_LPCOMP_HAS_AIN_AS_PIN
95 typedef uint32_t nrf_lpcomp_input_t;
96 #else
97 typedef enum
98 {
99 NRF_LPCOMP_INPUT_0 = LPCOMP_PSEL_PSEL_AnalogInput0, /**< Input 0. */
100 NRF_LPCOMP_INPUT_1 = LPCOMP_PSEL_PSEL_AnalogInput1, /**< Input 1. */
101 NRF_LPCOMP_INPUT_2 = LPCOMP_PSEL_PSEL_AnalogInput2, /**< Input 2. */
102 NRF_LPCOMP_INPUT_3 = LPCOMP_PSEL_PSEL_AnalogInput3, /**< Input 3. */
103 NRF_LPCOMP_INPUT_4 = LPCOMP_PSEL_PSEL_AnalogInput4, /**< Input 4. */
104 NRF_LPCOMP_INPUT_5 = LPCOMP_PSEL_PSEL_AnalogInput5, /**< Input 5. */
105 NRF_LPCOMP_INPUT_6 = LPCOMP_PSEL_PSEL_AnalogInput6, /**< Input 6. */
106 NRF_LPCOMP_INPUT_7 = LPCOMP_PSEL_PSEL_AnalogInput7 /**< Input 7. */
107 } nrf_lpcomp_input_t;
108 #endif
109
110 /** @brief LPCOMP detection type selection. */
111 typedef enum
112 {
113 NRF_LPCOMP_DETECT_CROSS = LPCOMP_ANADETECT_ANADETECT_Cross, /**< Generate ANADETEC on crossing, both upwards and downwards crossing. */
114 NRF_LPCOMP_DETECT_UP = LPCOMP_ANADETECT_ANADETECT_Up, /**< Generate ANADETEC on upwards crossing only. */
115 NRF_LPCOMP_DETECT_DOWN = LPCOMP_ANADETECT_ANADETECT_Down /**< Generate ANADETEC on downwards crossing only. */
116 } nrf_lpcomp_detect_t;
117
118 /** @brief LPCOMP tasks. */
119 typedef enum
120 {
121 NRF_LPCOMP_TASK_START = offsetof(NRF_LPCOMP_Type, TASKS_START), /**< LPCOMP start sampling task. */
122 NRF_LPCOMP_TASK_STOP = offsetof(NRF_LPCOMP_Type, TASKS_STOP), /**< LPCOMP stop sampling task. */
123 NRF_LPCOMP_TASK_SAMPLE = offsetof(NRF_LPCOMP_Type, TASKS_SAMPLE) /**< Sample comparator value. */
124 } nrf_lpcomp_task_t;
125
126
127 /** @brief LPCOMP events. */
128 typedef enum
129 {
130 NRF_LPCOMP_EVENT_READY = offsetof(NRF_LPCOMP_Type, EVENTS_READY), /**< LPCOMP is ready and output is valid. */
131 NRF_LPCOMP_EVENT_DOWN = offsetof(NRF_LPCOMP_Type, EVENTS_DOWN), /**< Input voltage crossed the threshold going down. */
132 NRF_LPCOMP_EVENT_UP = offsetof(NRF_LPCOMP_Type, EVENTS_UP), /**< Input voltage crossed the threshold going up. */
133 NRF_LPCOMP_EVENT_CROSS = offsetof(NRF_LPCOMP_Type, EVENTS_CROSS) /**< Input voltage crossed the threshold in any direction. */
134 } nrf_lpcomp_event_t;
135
136 /** @brief LPCOMP interrupts. */
137 typedef enum
138 {
139 NRF_LPCOMP_INT_READY_MASK = LPCOMP_INTENSET_READY_Msk, /**< Interrupt on READY event. */
140 NRF_LPCOMP_INT_DOWN_MASK = LPCOMP_INTENSET_DOWN_Msk, /**< Interrupt on DOWN event. */
141 NRF_LPCOMP_INT_UP_MASK = LPCOMP_INTENSET_UP_Msk, /**< Interrupt on UP event. */
142 NRF_LPCOMP_INT_CROSS_MASK = LPCOMP_INTENSET_CROSS_Msk /**< Interrupt on CROSS event. */
143 } nrf_lpcomp_int_mask_t;
144
145 /** @brief LPCOMP shortcut masks. */
146 typedef enum
147 {
148 NRF_LPCOMP_SHORT_CROSS_STOP_MASK = LPCOMP_SHORTS_CROSS_STOP_Msk, /*!< Shortcut between CROSS event and STOP task. */
149 NRF_LPCOMP_SHORT_UP_STOP_MASK = LPCOMP_SHORTS_UP_STOP_Msk, /*!< Shortcut between UP event and STOP task. */
150 NRF_LPCOMP_SHORT_DOWN_STOP_MASK = LPCOMP_SHORTS_DOWN_STOP_Msk, /*!< Shortcut between DOWN event and STOP task. */
151 NRF_LPCOMP_SHORT_READY_STOP_MASK = LPCOMP_SHORTS_READY_STOP_Msk, /*!< Shortcut between READY event and STOP task. */
152 NRF_LPCOMP_SHORT_READY_SAMPLE_MASK = LPCOMP_SHORTS_READY_SAMPLE_Msk /*!< Shortcut between READY event and SAMPLE task. */
153 } nrf_lpcomp_short_mask_t;
154
155 #if defined(LPCOMP_FEATURE_HYST_PRESENT) || defined(__NRFX_DOXYGEN__)
156 /** @brief LPCOMP hysteresis. */
157 typedef enum
158 {
159 #ifdef LPCOMP_HYST_HYST_NoHyst
160 NRF_LPCOMP_HYST_NOHYST = LPCOMP_HYST_HYST_NoHyst, /**< Comparator hysteresis disabled. */
161 #else
162 NRF_LPCOMP_HYST_NOHYST = LPCOMP_HYST_HYST_Disabled, /**< Comparator hysteresis disabled. */
163 #endif
164 #ifdef LPCOMP_HYST_HYST_Hyst50mV
165 NRF_LPCOMP_HYST_ENABLED = LPCOMP_HYST_HYST_Hyst50mV /**< Comparator hysteresis enabled (typically 50 mV). */
166 #else
167 NRF_LPCOMP_HYST_ENABLED = LPCOMP_HYST_HYST_Enabled /**< Comparator hysteresis enabled (typically 50 mV). */
168 #endif
169 }nrf_lpcomp_hysteresis_t;
170 #endif // LPCOMP_FEATURE_HYST_PRESENT
171
172 /** @brief LPCOMP configuration. */
173 typedef struct
174 {
175 nrf_lpcomp_ref_t reference; /**< LPCOMP reference. */
176 nrf_lpcomp_detect_t detection; /**< LPCOMP detection type. */
177 #if defined(LPCOMP_FEATURE_HYST_PRESENT) || defined(__NRFX_DOXYGEN__)
178 nrf_lpcomp_hysteresis_t hyst; /**< LPCOMP hysteresis. */
179 #endif // LPCOMP_FEATURE_HYST_PRESENT
180 } nrf_lpcomp_config_t;
181
182 /**
183 * @brief Function for configuring LPCOMP.
184 *
185 * This function powers on LPCOMP and configures it. LPCOMP is in DISABLE state after configuration,
186 * so it must be enabled before using it. All shorts are inactive, events are cleared, and LPCOMP is stopped.
187 *
188 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
189 * @param[in] p_config Configuration.
190 */
191 NRF_STATIC_INLINE void nrf_lpcomp_configure(NRF_LPCOMP_Type * p_reg,
192 nrf_lpcomp_config_t const * p_config);
193
194 /**
195 * @brief Function for selecting the LPCOMP input.
196 *
197 * This function selects the active input of LPCOMP.
198 *
199 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
200 * @param[in] input Input to be selected.
201 */
202 NRF_STATIC_INLINE void nrf_lpcomp_input_select(NRF_LPCOMP_Type * p_reg, nrf_lpcomp_input_t input);
203
204 /**
205 * @brief Function for enabling the Low Power Comparator.
206 *
207 * This function enables LPCOMP.
208 *
209 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
210 */
211 NRF_STATIC_INLINE void nrf_lpcomp_enable(NRF_LPCOMP_Type * p_reg);
212
213 /**
214 * @brief Function for disabling the Low Power Comparator.
215 *
216 * This function disables LPCOMP.
217 *
218 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
219 */
220 NRF_STATIC_INLINE void nrf_lpcomp_disable(NRF_LPCOMP_Type * p_reg);
221
222 /**
223 * @brief Function for getting the last LPCOMP compare result.
224 *
225 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
226 *
227 * @return The last compare result. If 0 then VIN+ < VIN-, if 1 then the opposite.
228 */
229 NRF_STATIC_INLINE uint32_t nrf_lpcomp_result_get(NRF_LPCOMP_Type const * p_reg);
230
231 /**
232 * @brief Function for enabling interrupts from LPCOMP.
233 *
234 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
235 * @param[in] mask Mask of interrupts to be enabled.
236 *
237 * @sa nrf_lpcomp_int_disable
238 * @sa nrf_lpcomp_int_enable_check
239 */
240 NRF_STATIC_INLINE void nrf_lpcomp_int_enable(NRF_LPCOMP_Type * p_reg, uint32_t mask);
241
242 /**
243 * @brief Function for disabling interrupts from LPCOMP.
244 *
245 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
246 * @param[in] mask Mask of interrupts to be disabled.
247 *
248 * @sa nrf_lpcomp_int_enable
249 * @sa nrf_lpcomp_int_enable_check
250 */
251 NRF_STATIC_INLINE void nrf_lpcomp_int_disable(NRF_LPCOMP_Type * p_reg, uint32_t mask);
252
253 /**
254 * @brief Function for checking if the specified interrupts are enabled.
255 *
256 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
257 * @param[in] mask Mask of interrupts to be checked.
258 *
259 * @return Mask of enabled interrupts.
260 */
261 NRF_STATIC_INLINE uint32_t nrf_lpcomp_int_enable_check(NRF_LPCOMP_Type const * p_reg,
262 uint32_t mask);
263
264 /**
265 * @brief Function for getting the address of the specified LPCOMP task register.
266 *
267 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
268 * @param[in] task LPCOMP task.
269 *
270 * @return The address of the specified LPCOMP task.
271 */
272 NRF_STATIC_INLINE uint32_t nrf_lpcomp_task_address_get(NRF_LPCOMP_Type const * p_reg,
273 nrf_lpcomp_task_t task);
274
275 /**
276 * @brief Function for getting the address of the specified LPCOMP event register.
277 *
278 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
279 * @param[in] event LPCOMP event.
280 *
281 * @return The address of the specified LPCOMP event.
282 */
283 NRF_STATIC_INLINE uint32_t nrf_lpcomp_event_address_get(NRF_LPCOMP_Type const * p_reg,
284 nrf_lpcomp_event_t event);
285
286 /**
287 * @brief Function for setting LPCOMP shorts.
288 *
289 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
290 * @param[in] mask Mask of shortcuts.
291 */
292 NRF_STATIC_INLINE void nrf_lpcomp_shorts_enable(NRF_LPCOMP_Type * p_reg, uint32_t mask);
293
294 /**
295 * @brief Function for clearing LPCOMP shorts by mask.
296 *
297 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
298 * @param[in] mask Mask of shortcuts.
299 */
300 NRF_STATIC_INLINE void nrf_lpcomp_shorts_disable(NRF_LPCOMP_Type * p_reg, uint32_t mask);
301
302 /**
303 * @brief Function for setting the specified LPCOMP task.
304 *
305 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
306 * @param[in] task LPCOMP task to be set.
307 */
308 NRF_STATIC_INLINE void nrf_lpcomp_task_trigger(NRF_LPCOMP_Type * p_reg, nrf_lpcomp_task_t task);
309
310 /**
311 * @brief Function for clearing the specified LPCOMP event.
312 *
313 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
314 * @param[in] event LPCOMP event to be cleared.
315 */
316 NRF_STATIC_INLINE void nrf_lpcomp_event_clear(NRF_LPCOMP_Type * p_reg, nrf_lpcomp_event_t event);
317
318 /**
319 * @brief Function for retrieving the state of the LPCOMP event.
320 *
321 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
322 * @param[in] event Event to be checked.
323 *
324 * @retval true The event has been generated.
325 * @retval false The event has not been generated.
326 */
327 NRF_STATIC_INLINE bool nrf_lpcomp_event_check(NRF_LPCOMP_Type const * p_reg,
328 nrf_lpcomp_event_t event);
329
330 #ifndef NRF_DECLARE_ONLY
331
nrf_lpcomp_configure(NRF_LPCOMP_Type * p_reg,nrf_lpcomp_config_t const * p_config)332 NRF_STATIC_INLINE void nrf_lpcomp_configure(NRF_LPCOMP_Type * p_reg,
333 nrf_lpcomp_config_t const * p_config)
334 {
335 p_reg->REFSEL = (p_config->reference << LPCOMP_REFSEL_REFSEL_Pos) & LPCOMP_REFSEL_REFSEL_Msk;
336
337 #if !NRF_LPCOMP_HAS_AIN_AS_PIN
338 //If external source is choosen extract analog reference index.
339 if ((p_config->reference & LPCOMP_REFSEL_REFSEL_ARef)==LPCOMP_REFSEL_REFSEL_ARef)
340 {
341 uint32_t extref = p_config->reference >> 16;
342 p_reg->EXTREFSEL = (extref << LPCOMP_EXTREFSEL_EXTREFSEL_Pos) &
343 LPCOMP_EXTREFSEL_EXTREFSEL_Msk;
344 }
345 #endif
346
347 p_reg->ANADETECT = (p_config->detection << LPCOMP_ANADETECT_ANADETECT_Pos) &
348 LPCOMP_ANADETECT_ANADETECT_Msk;
349 #ifdef LPCOMP_FEATURE_HYST_PRESENT
350 p_reg->HYST = ((p_config->hyst) << LPCOMP_HYST_HYST_Pos) & LPCOMP_HYST_HYST_Msk;
351 #endif //LPCOMP_FEATURE_HYST_PRESENT
352 }
353
nrf_lpcomp_input_select(NRF_LPCOMP_Type * p_reg,nrf_lpcomp_input_t input)354 NRF_STATIC_INLINE void nrf_lpcomp_input_select(NRF_LPCOMP_Type * p_reg, nrf_lpcomp_input_t input)
355 {
356 #if NRF_LPCOMP_HAS_AIN_AS_PIN
357 p_reg->PSEL = (NRF_PIN_NUMBER_TO_PORT(input) << LPCOMP_PSEL_PORT_Pos) |
358 (NRF_PIN_NUMBER_TO_PIN(input) << LPCOMP_PSEL_PIN_Pos) |
359 (p_reg->PSEL & ~(LPCOMP_PSEL_PORT_Msk | LPCOMP_PSEL_PIN_Msk));
360 #else
361 p_reg->PSEL = ((uint32_t)input << LPCOMP_PSEL_PSEL_Pos) | (p_reg->PSEL & ~LPCOMP_PSEL_PSEL_Msk);
362 #endif
363 }
364
nrf_lpcomp_enable(NRF_LPCOMP_Type * p_reg)365 NRF_STATIC_INLINE void nrf_lpcomp_enable(NRF_LPCOMP_Type * p_reg)
366 {
367 p_reg->ENABLE = LPCOMP_ENABLE_ENABLE_Enabled << LPCOMP_ENABLE_ENABLE_Pos;
368 }
369
nrf_lpcomp_disable(NRF_LPCOMP_Type * p_reg)370 NRF_STATIC_INLINE void nrf_lpcomp_disable(NRF_LPCOMP_Type * p_reg)
371 {
372 p_reg->ENABLE = LPCOMP_ENABLE_ENABLE_Disabled << LPCOMP_ENABLE_ENABLE_Pos;
373 }
374
nrf_lpcomp_result_get(NRF_LPCOMP_Type const * p_reg)375 NRF_STATIC_INLINE uint32_t nrf_lpcomp_result_get(NRF_LPCOMP_Type const * p_reg)
376 {
377 return (uint32_t)p_reg->RESULT;
378 }
379
nrf_lpcomp_int_enable(NRF_LPCOMP_Type * p_reg,uint32_t mask)380 NRF_STATIC_INLINE void nrf_lpcomp_int_enable(NRF_LPCOMP_Type * p_reg, uint32_t mask)
381 {
382 p_reg->INTENSET = mask;
383 }
384
nrf_lpcomp_int_disable(NRF_LPCOMP_Type * p_reg,uint32_t mask)385 NRF_STATIC_INLINE void nrf_lpcomp_int_disable(NRF_LPCOMP_Type * p_reg, uint32_t mask)
386 {
387 p_reg->INTENCLR = mask;
388 }
389
nrf_lpcomp_int_enable_check(NRF_LPCOMP_Type const * p_reg,uint32_t mask)390 NRF_STATIC_INLINE uint32_t nrf_lpcomp_int_enable_check(NRF_LPCOMP_Type const * p_reg,
391 uint32_t mask)
392 {
393 return p_reg->INTENSET & mask; // when read this register will return the value of INTEN.
394 }
395
nrf_lpcomp_task_address_get(NRF_LPCOMP_Type const * p_reg,nrf_lpcomp_task_t task)396 NRF_STATIC_INLINE uint32_t nrf_lpcomp_task_address_get(NRF_LPCOMP_Type const * p_reg,
397 nrf_lpcomp_task_t task)
398 {
399 return (uint32_t)((uint8_t *)p_reg + task);
400 }
401
nrf_lpcomp_event_address_get(NRF_LPCOMP_Type const * p_reg,nrf_lpcomp_event_t event)402 NRF_STATIC_INLINE uint32_t nrf_lpcomp_event_address_get(NRF_LPCOMP_Type const * p_reg,
403 nrf_lpcomp_event_t event)
404 {
405 return (uint32_t)((uint8_t *)p_reg + event);
406 }
407
nrf_lpcomp_shorts_enable(NRF_LPCOMP_Type * p_reg,uint32_t short_mask)408 NRF_STATIC_INLINE void nrf_lpcomp_shorts_enable(NRF_LPCOMP_Type * p_reg, uint32_t short_mask)
409 {
410 p_reg->SHORTS |= short_mask;
411 }
412
nrf_lpcomp_shorts_disable(NRF_LPCOMP_Type * p_reg,uint32_t short_mask)413 NRF_STATIC_INLINE void nrf_lpcomp_shorts_disable(NRF_LPCOMP_Type * p_reg, uint32_t short_mask)
414 {
415 p_reg->SHORTS &= ~short_mask;
416 }
417
nrf_lpcomp_task_trigger(NRF_LPCOMP_Type * p_reg,nrf_lpcomp_task_t task)418 NRF_STATIC_INLINE void nrf_lpcomp_task_trigger(NRF_LPCOMP_Type * p_reg, nrf_lpcomp_task_t task)
419 {
420 *( (volatile uint32_t *)( (uint8_t *)p_reg + (uint32_t)task) ) = 1;
421 }
422
nrf_lpcomp_event_clear(NRF_LPCOMP_Type * p_reg,nrf_lpcomp_event_t event)423 NRF_STATIC_INLINE void nrf_lpcomp_event_clear(NRF_LPCOMP_Type * p_reg, nrf_lpcomp_event_t event)
424 {
425 *( (volatile uint32_t *)( (uint8_t *)p_reg + (uint32_t)event) ) = 0;
426 nrf_event_readback((uint8_t *)p_reg + (uint32_t)event);
427 }
428
nrf_lpcomp_event_check(NRF_LPCOMP_Type const * p_reg,nrf_lpcomp_event_t event)429 NRF_STATIC_INLINE bool nrf_lpcomp_event_check(NRF_LPCOMP_Type const * p_reg,
430 nrf_lpcomp_event_t event)
431 {
432 return (bool) (*(volatile uint32_t *)( (uint8_t *)p_reg + (uint32_t)event));
433 }
434
435 #endif // NRF_DECLARE_ONLY
436
437 /** @} */
438
439 #ifdef __cplusplus
440 }
441 #endif
442
443 #endif // NRF_LPCOMP_H_
444