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