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 #include <saadc_examples_common.h>
35 #include <helpers/nrfx_gppi.h>
36 #include <nrfx_gpiote.h>
37
gpiote_pin_toggle_task_setup(nrfx_gpiote_t const * p_gpiote,nrfx_gpiote_pin_t pin)38 void gpiote_pin_toggle_task_setup(nrfx_gpiote_t const * p_gpiote, nrfx_gpiote_pin_t pin)
39 {
40 nrfx_err_t status;
41 (void)status;
42
43 uint8_t gpiote_channel;
44 status = nrfx_gpiote_channel_alloc(p_gpiote, &gpiote_channel);
45 NRFX_ASSERT(status == NRFX_SUCCESS);
46
47 static const nrfx_gpiote_output_config_t output_config =
48 {
49 .drive = NRF_GPIO_PIN_H0H1,
50 .input_connect = NRF_GPIO_PIN_INPUT_DISCONNECT,
51 .pull = NRF_GPIO_PIN_NOPULL,
52 };
53
54 const nrfx_gpiote_task_config_t task_config =
55 {
56 .task_ch = gpiote_channel,
57 .polarity = NRF_GPIOTE_POLARITY_TOGGLE,
58 .init_val = NRF_GPIOTE_INITIAL_VALUE_LOW,
59 };
60
61 status = nrfx_gpiote_output_configure(p_gpiote, pin, &output_config, &task_config);
62 NRFX_ASSERT(status == NRFX_SUCCESS);
63
64 nrfx_gpiote_out_task_enable(p_gpiote, pin);
65 }
66
pin_on_event_toggle_setup(nrfx_gpiote_t const * p_gpiote,nrfx_gpiote_pin_t pin,uint32_t eep)67 void pin_on_event_toggle_setup(nrfx_gpiote_t const * p_gpiote, nrfx_gpiote_pin_t pin, uint32_t eep)
68 {
69 nrfx_err_t status;
70 (void)status;
71
72 uint8_t gppi_channel;
73
74 gpiote_pin_toggle_task_setup(p_gpiote, pin);
75
76 status = nrfx_gppi_channel_alloc(&gppi_channel);
77 NRFX_ASSERT(status == NRFX_SUCCESS);
78
79 nrfx_gppi_channel_endpoints_setup(gppi_channel,
80 eep,
81 nrfx_gpiote_out_task_address_get(p_gpiote, pin));
82
83 nrfx_gppi_channels_enable(NRFX_BIT(gppi_channel));
84 }
85