xref: /nrf52832-nimble/nordic/nrfx/drivers/include/nrfx_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 NRFX_LPCOMP_H__
33 #define NRFX_LPCOMP_H__
34 
35 #include <nrfx.h>
36 #include <hal/nrf_lpcomp.h>
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 /**
43  * @defgroup nrfx_lpcomp LPCOMP driver
44  * @{
45  * @ingroup nrf_lpcomp
46  * @brief   Low Power Comparator (LPCOMP) peripheral driver.
47  */
48 
49 /**
50  * @brief LPCOMP event handler function type.
51  * @param[in] event  LPCOMP event.
52  */
53 typedef void (* nrfx_lpcomp_event_handler_t)(nrf_lpcomp_event_t event);
54 
55 /** @brief LPCOMP configuration. */
56 typedef struct
57 {
58     nrf_lpcomp_config_t hal;                /**< LPCOMP HAL configuration. */
59     nrf_lpcomp_input_t  input;              /**< Input to be monitored. */
60     uint8_t             interrupt_priority; /**< LPCOMP interrupt priority. */
61 } nrfx_lpcomp_config_t;
62 
63 /** @brief LPCOMP driver default configuration including the LPCOMP HAL configuration. */
64 #ifdef NRF52_SERIES
65 #define NRFX_LPCOMP_DEFAULT_CONFIG                                      \
66     {                                                                   \
67         .hal    = { (nrf_lpcomp_ref_t)NRFX_LPCOMP_CONFIG_REFERENCE ,    \
68                     (nrf_lpcomp_detect_t)NRFX_LPCOMP_CONFIG_DETECTION,  \
69                     (nrf_lpcomp_hysteresis_t)NRFX_LPCOMP_CONFIG_HYST }, \
70         .input  = (nrf_lpcomp_input_t)NRFX_LPCOMP_CONFIG_INPUT,         \
71         .interrupt_priority = NRFX_LPCOMP_CONFIG_IRQ_PRIORITY           \
72     }
73 #else
74 #define NRFX_LPCOMP_DEFAULT_CONFIG                                       \
75     {                                                                    \
76         .hal    = { (nrf_lpcomp_ref_t)NRFX_LPCOMP_CONFIG_REFERENCE ,     \
77                     (nrf_lpcomp_detect_t)NRFX_LPCOMP_CONFIG_DETECTION }, \
78         .input  = (nrf_lpcomp_input_t)NRFX_LPCOMP_CONFIG_INPUT,          \
79         .interrupt_priority = NRFX_LPCOMP_CONFIG_IRQ_PRIORITY            \
80     }
81 #endif
82 
83 /**
84  * @brief Function for initializing the LPCOMP driver.
85  *
86  * This function initializes the LPCOMP driver, but does not enable the peripheral or any interrupts.
87  * To start the driver, call the function nrfx_lpcomp_enable() after initialization.
88  *
89  * @param[in] p_config      Pointer to the structure with initial configuration.
90  * @param[in] event_handler Event handler provided by the user.
91  *                          Must not be NULL.
92  *
93  * @retval NRFX_SUCCESS             If initialization was successful.
94  * @retval NRFX_ERROR_INVALID_STATE If the driver has already been initialized.
95  * @retval NRFX_ERROR_BUSY          If the COMP peripheral is already in use.
96  *                                  This is possible only if @ref nrfx_prs module
97  *                                  is enabled.
98  */
99 nrfx_err_t nrfx_lpcomp_init(nrfx_lpcomp_config_t const * p_config,
100                             nrfx_lpcomp_event_handler_t  event_handler);
101 
102 /**
103  *  @brief Function for uninitializing the LCOMP driver.
104  *
105  *  This function uninitializes the LPCOMP driver. The LPCOMP peripheral and
106  *  its interrupts are disabled, and local variables are cleaned. After this call, you must
107  *  initialize the driver again by calling nrfx_lpcomp_init() if you want to use it.
108  *
109  *  @sa nrfx_lpcomp_disable()
110  *  @sa nrfx_lpcomp_init()
111  */
112 void  nrfx_lpcomp_uninit(void);
113 
114 /**@brief Function for enabling the LPCOMP peripheral and interrupts.
115  *
116  * Before calling this function, the driver must be initialized. This function
117  * enables the LPCOMP peripheral and its interrupts.
118  *
119  * @sa nrfx_lpcomp_disable()
120  */
121 void nrfx_lpcomp_enable(void);
122 
123 /**@brief Function for disabling the LPCOMP peripheral.
124  *
125  * Before calling this function, the driver must be initialized. This function disables the LPCOMP
126  * peripheral and its interrupts.
127  *
128  * @sa nrfx_lpcomp_enable()
129  */
130 void nrfx_lpcomp_disable(void);
131 
132 
133 void nrfx_lpcomp_irq_handler(void);
134 
135 /** @} **/
136 
137 #ifdef __cplusplus
138 }
139 #endif
140 
141 #endif // NRFX_LPCOMP_H__
142