1 /*
2  * Copyright (c) 2022 - 2024, 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 SAADC_EXAMPLES_COMMON_H__
35 #define SAADC_EXAMPLES_COMMON_H__
36 
37 #include <nrfx_gpiote.h>
38 
39 /**
40  * @defgroup nrfx_saadc_examples_common Common SAADC module
41  * @{
42  * @ingroup nrfx_saadc_examples
43  *
44  * @brief Module with common functionalities used in nrfx_saadc examples.
45  */
46 
47 /**
48  * @brief SAADC channel configuration for the single-ended mode with 3 us sample acquisition time.
49  *        The 3 us acquisition time will work correctly when the source resistance of @p _pin_p input
50  *        analog pin is less than 10 kOhm.
51  *
52  * This configuration sets up single-ended SAADC channel with the following options:
53  * - resistor ladder disabled
54  * - gain: 1/6
55  * - reference voltage: internal 0.6 V
56  * - sample acquisition time: 3 us
57  * - burst disabled
58  *
59  * @param[in] _pin_p Positive input analog pin.
60  * @param[in] _index Channel index.
61  *
62  * @sa nrfx_saadc_channel_t
63  */
64 #define SAADC_CHANNEL_SE_ACQ_3US(_pin_p, _index)        \
65 {                                                       \
66     .channel_config =                                   \
67     {                                                   \
68         .resistor_p = NRF_SAADC_RESISTOR_DISABLED,      \
69         .resistor_n = NRF_SAADC_RESISTOR_DISABLED,      \
70         .gain       = NRF_SAADC_GAIN1_6,                \
71         .reference  = NRF_SAADC_REFERENCE_INTERNAL,     \
72         .acq_time   = NRF_SAADC_ACQTIME_3US,            \
73         .mode       = NRF_SAADC_MODE_SINGLE_ENDED,      \
74         .burst      = NRF_SAADC_BURST_DISABLED,         \
75     },                                                  \
76     .pin_p          = (nrf_saadc_input_t)_pin_p,        \
77     .pin_n          = NRF_SAADC_INPUT_DISABLED,         \
78     .channel_index  = _index,                           \
79 }
80 
81 /**
82  * @brief Function for setting up a GPIOTE task that toggles a given pin.
83  *
84  * @param[in] p_gpiote Pointer to the GPIOTE driver instance structure.
85  * @param[in] pin      The pin to toggle.
86  */
87 void gpiote_pin_toggle_task_setup(nrfx_gpiote_t const * p_gpiote, nrfx_gpiote_pin_t pin);
88 
89 /**
90  * @brief Function for setting up a pin to be toggled once specified event is triggered.
91  *
92  * @param[in] p_gpiote Pointer to the GPIOTE driver instance structure.
93  * @param[in] pin      The pin to toggle.
94  * @param[in] eep      Address of the event register. This event will trigger the @p pin to toggle.
95  */
96 void pin_on_event_toggle_setup(nrfx_gpiote_t const * p_gpiote, nrfx_gpiote_pin_t pin, uint32_t eep);
97 
98 /** @} */
99 
100 #endif // SAADC_EXAMPLES_COMMON_H__
101