Branch data Line data Source code
1 : : /*
2 : : * Copyright (c) 2015 - 2022, 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_GPIOTE_H__
35 : : #define NRF_GPIOTE_H__
36 : :
37 : : #include <nrfx.h>
38 : :
39 : : #ifdef __cplusplus
40 : : extern "C" {
41 : : #endif
42 : :
43 : : /**
44 : : * @defgroup nrf_gpiote_hal GPIOTE HAL
45 : : * @{
46 : : * @ingroup nrf_gpiote
47 : : * @brief Hardware access layer (HAL) for managing the GPIOTE peripheral.
48 : : */
49 : :
50 : : #if defined(GPIOTE_CONFIG_PORT_Msk) || defined(__NRFX_DOXYGEN__)
51 : : /** @brief Mask for covering port and pin bits in registers. */
52 : : #define GPIOTE_CONFIG_PORT_PIN_Msk (GPIOTE_CONFIG_PORT_Msk | GPIOTE_CONFIG_PSEL_Msk)
53 : : #else
54 : : #define GPIOTE_CONFIG_PORT_PIN_Msk GPIOTE_CONFIG_PSEL_Msk
55 : : #endif
56 : :
57 : : #if defined(GPIOTE_LATENCY_LATENCY_Msk) || defined(__NRFX_DOXYGEN__)
58 : : /** @brief Presence of the latency setting. */
59 : : #define NRF_GPIOTE_HAS_LATENCY 1
60 : : #else
61 : : #define NRF_GPIOTE_HAS_LATENCY 0
62 : : #endif
63 : :
64 : : /** @brief Polarity for the GPIOTE channel. */
65 : : typedef enum
66 : : {
67 : : NRF_GPIOTE_POLARITY_NONE = GPIOTE_CONFIG_POLARITY_None, /**< None. */
68 : : NRF_GPIOTE_POLARITY_LOTOHI = GPIOTE_CONFIG_POLARITY_LoToHi, /**< Low to high. */
69 : : NRF_GPIOTE_POLARITY_HITOLO = GPIOTE_CONFIG_POLARITY_HiToLo, /**< High to low. */
70 : : NRF_GPIOTE_POLARITY_TOGGLE = GPIOTE_CONFIG_POLARITY_Toggle, /**< Toggle. */
71 : : } nrf_gpiote_polarity_t;
72 : :
73 : : /** @brief Initial output value for the GPIOTE channel. */
74 : : typedef enum
75 : : {
76 : : NRF_GPIOTE_INITIAL_VALUE_LOW = GPIOTE_CONFIG_OUTINIT_Low, /**< Low to high. */
77 : : NRF_GPIOTE_INITIAL_VALUE_HIGH = GPIOTE_CONFIG_OUTINIT_High, /**< High to low. */
78 : : } nrf_gpiote_outinit_t;
79 : :
80 : : #if NRF_GPIOTE_HAS_LATENCY
81 : : /** @brief Latency setting. */
82 : : typedef enum
83 : : {
84 : : NRF_GPIOTE_LATENCY_LOWPOWER = GPIOTE_LATENCY_LATENCY_LowPower, /**< Low Power. */
85 : : NRF_GPIOTE_LATENCY_LOWLATENCY = GPIOTE_LATENCY_LATENCY_LowLatency, /**< Low Latency. */
86 : : } nrf_gpiote_latency_t;
87 : : #endif
88 : :
89 : : /** @brief GPIOTE tasks. */
90 : : typedef enum
91 : : {
92 : : NRF_GPIOTE_TASK_OUT_0 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[0]), /**< Out task 0. */
93 : : NRF_GPIOTE_TASK_OUT_1 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[1]), /**< Out task 1. */
94 : : NRF_GPIOTE_TASK_OUT_2 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[2]), /**< Out task 2. */
95 : : NRF_GPIOTE_TASK_OUT_3 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[3]), /**< Out task 3. */
96 : : #if (GPIOTE_CH_NUM > 4) || defined(__NRFX_DOXYGEN__)
97 : : NRF_GPIOTE_TASK_OUT_4 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[4]), /**< Out task 4. */
98 : : NRF_GPIOTE_TASK_OUT_5 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[5]), /**< Out task 5. */
99 : : NRF_GPIOTE_TASK_OUT_6 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[6]), /**< Out task 6. */
100 : : NRF_GPIOTE_TASK_OUT_7 = offsetof(NRF_GPIOTE_Type, TASKS_OUT[7]), /**< Out task 7. */
101 : : #endif
102 : : #if defined(GPIOTE_FEATURE_SET_PRESENT) || defined(__NRFX_DOXYGEN__)
103 : : NRF_GPIOTE_TASK_SET_0 = offsetof(NRF_GPIOTE_Type, TASKS_SET[0]), /**< Set task 0. */
104 : : NRF_GPIOTE_TASK_SET_1 = offsetof(NRF_GPIOTE_Type, TASKS_SET[1]), /**< Set task 1. */
105 : : NRF_GPIOTE_TASK_SET_2 = offsetof(NRF_GPIOTE_Type, TASKS_SET[2]), /**< Set task 2. */
106 : : NRF_GPIOTE_TASK_SET_3 = offsetof(NRF_GPIOTE_Type, TASKS_SET[3]), /**< Set task 3. */
107 : : NRF_GPIOTE_TASK_SET_4 = offsetof(NRF_GPIOTE_Type, TASKS_SET[4]), /**< Set task 4. */
108 : : NRF_GPIOTE_TASK_SET_5 = offsetof(NRF_GPIOTE_Type, TASKS_SET[5]), /**< Set task 5. */
109 : : NRF_GPIOTE_TASK_SET_6 = offsetof(NRF_GPIOTE_Type, TASKS_SET[6]), /**< Set task 6. */
110 : : NRF_GPIOTE_TASK_SET_7 = offsetof(NRF_GPIOTE_Type, TASKS_SET[7]), /**< Set task 7. */
111 : : #endif
112 : : #if defined(GPIOTE_FEATURE_CLR_PRESENT) || defined(__NRFX_DOXYGEN__)
113 : : NRF_GPIOTE_TASK_CLR_0 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[0]), /**< Clear task 0. */
114 : : NRF_GPIOTE_TASK_CLR_1 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[1]), /**< Clear task 1. */
115 : : NRF_GPIOTE_TASK_CLR_2 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[2]), /**< Clear task 2. */
116 : : NRF_GPIOTE_TASK_CLR_3 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[3]), /**< Clear task 3. */
117 : : NRF_GPIOTE_TASK_CLR_4 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[4]), /**< Clear task 4. */
118 : : NRF_GPIOTE_TASK_CLR_5 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[5]), /**< Clear task 5. */
119 : : NRF_GPIOTE_TASK_CLR_6 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[6]), /**< Clear task 6. */
120 : : NRF_GPIOTE_TASK_CLR_7 = offsetof(NRF_GPIOTE_Type, TASKS_CLR[7]), /**< Clear task 7. */
121 : : #endif
122 : : } nrf_gpiote_task_t;
123 : :
124 : : /** @brief GPIOTE events. */
125 : : typedef enum
126 : : {
127 : : NRF_GPIOTE_EVENT_IN_0 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[0]), /**< In event 0. */
128 : : NRF_GPIOTE_EVENT_IN_1 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[1]), /**< In event 1. */
129 : : NRF_GPIOTE_EVENT_IN_2 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[2]), /**< In event 2. */
130 : : NRF_GPIOTE_EVENT_IN_3 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[3]), /**< In event 3. */
131 : : #if (GPIOTE_CH_NUM > 4) || defined(__NRFX_DOXYGEN__)
132 : : NRF_GPIOTE_EVENT_IN_4 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[4]), /**< In event 4. */
133 : : NRF_GPIOTE_EVENT_IN_5 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[5]), /**< In event 5. */
134 : : NRF_GPIOTE_EVENT_IN_6 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[6]), /**< In event 6. */
135 : : NRF_GPIOTE_EVENT_IN_7 = offsetof(NRF_GPIOTE_Type, EVENTS_IN[7]), /**< In event 7. */
136 : : #endif
137 : : NRF_GPIOTE_EVENT_PORT = offsetof(NRF_GPIOTE_Type, EVENTS_PORT), /**< Port event. */
138 : : } nrf_gpiote_event_t;
139 : :
140 : : /** @brief GPIOTE interrupts. */
141 : : typedef enum
142 : : {
143 : : NRF_GPIOTE_INT_IN0_MASK = GPIOTE_INTENSET_IN0_Msk, /**< GPIOTE interrupt from IN0. */
144 : : NRF_GPIOTE_INT_IN1_MASK = GPIOTE_INTENSET_IN1_Msk, /**< GPIOTE interrupt from IN1. */
145 : : NRF_GPIOTE_INT_IN2_MASK = GPIOTE_INTENSET_IN2_Msk, /**< GPIOTE interrupt from IN2. */
146 : : NRF_GPIOTE_INT_IN3_MASK = GPIOTE_INTENSET_IN3_Msk, /**< GPIOTE interrupt from IN3. */
147 : : #if (GPIOTE_CH_NUM > 4) || defined(__NRFX_DOXYGEN__)
148 : : NRF_GPIOTE_INT_IN4_MASK = GPIOTE_INTENSET_IN4_Msk, /**< GPIOTE interrupt from IN4. */
149 : : NRF_GPIOTE_INT_IN5_MASK = GPIOTE_INTENSET_IN5_Msk, /**< GPIOTE interrupt from IN5. */
150 : : NRF_GPIOTE_INT_IN6_MASK = GPIOTE_INTENSET_IN6_Msk, /**< GPIOTE interrupt from IN6. */
151 : : NRF_GPIOTE_INT_IN7_MASK = GPIOTE_INTENSET_IN7_Msk, /**< GPIOTE interrupt from IN7. */
152 : : #endif
153 : : NRF_GPIOTE_INT_PORT_MASK = (int)GPIOTE_INTENSET_PORT_Msk, /**< GPIOTE interrupt from PORT event. */
154 : : } nrf_gpiote_int_t;
155 : :
156 : : #if (GPIOTE_CH_NUM == 4) || defined(__NRFX_DOXYGEN__)
157 : : /** @brief Mask holding positions of available GPIOTE input interrupts. */
158 : : #define NRF_GPIOTE_INT_IN_MASK (NRF_GPIOTE_INT_IN0_MASK | NRF_GPIOTE_INT_IN1_MASK |\
159 : : NRF_GPIOTE_INT_IN2_MASK | NRF_GPIOTE_INT_IN3_MASK)
160 : : #else
161 : : #define NRF_GPIOTE_INT_IN_MASK (NRF_GPIOTE_INT_IN0_MASK | NRF_GPIOTE_INT_IN1_MASK |\
162 : : NRF_GPIOTE_INT_IN2_MASK | NRF_GPIOTE_INT_IN3_MASK |\
163 : : NRF_GPIOTE_INT_IN4_MASK | NRF_GPIOTE_INT_IN5_MASK |\
164 : : NRF_GPIOTE_INT_IN6_MASK | NRF_GPIOTE_INT_IN7_MASK)
165 : : #endif
166 : :
167 : : /**
168 : : * @brief Function for activating the specified GPIOTE task.
169 : : *
170 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
171 : : * @param[in] task Task.
172 : : */
173 : : NRF_STATIC_INLINE void nrf_gpiote_task_trigger(NRF_GPIOTE_Type * p_reg, nrf_gpiote_task_t task);
174 : :
175 : : /**
176 : : * @brief Function for getting the address of the specified GPIOTE task.
177 : : *
178 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
179 : : * @param[in] task Task.
180 : : *
181 : : * @return Address of the specified task.
182 : : */
183 : : NRF_STATIC_INLINE uint32_t nrf_gpiote_task_address_get(NRF_GPIOTE_Type const * p_reg,
184 : : nrf_gpiote_task_t task);
185 : :
186 : : /**
187 : : * @brief Function for getting the state of the specified GPIOTE event.
188 : : *
189 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
190 : : * @param[in] event Event.
191 : : *
192 : : * @retval true The event is set.
193 : : * @retval false The event is not set.
194 : : */
195 : : NRF_STATIC_INLINE bool nrf_gpiote_event_check(NRF_GPIOTE_Type const * p_reg,
196 : : nrf_gpiote_event_t event);
197 : :
198 : : /**
199 : : * @brief Function for clearing the specified GPIOTE event.
200 : : *
201 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
202 : : * @param[in] event Event.
203 : : */
204 : : NRF_STATIC_INLINE void nrf_gpiote_event_clear(NRF_GPIOTE_Type * p_reg, nrf_gpiote_event_t event);
205 : :
206 : : /**
207 : : * @brief Function for getting the address of the specified GPIOTE event.
208 : : *
209 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
210 : : * @param[in] event Event.
211 : : *
212 : : * @return Address of the specified event.
213 : : */
214 : : NRF_STATIC_INLINE uint32_t nrf_gpiote_event_address_get(NRF_GPIOTE_Type const * p_reg,
215 : : nrf_gpiote_event_t event);
216 : :
217 : : /**
218 : : * @brief Function for enabling interrupts.
219 : : *
220 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
221 : : * @param[in] mask Mask of interrupts to be enabled.
222 : : */
223 : : NRF_STATIC_INLINE void nrf_gpiote_int_enable(NRF_GPIOTE_Type * p_reg, uint32_t mask);
224 : :
225 : : /**
226 : : * @brief Function for disabling interrupts.
227 : : *
228 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
229 : : * @param[in] mask Mask of interrupts to be disabled.
230 : : */
231 : : NRF_STATIC_INLINE void nrf_gpiote_int_disable(NRF_GPIOTE_Type * p_reg, uint32_t mask);
232 : :
233 : : /**
234 : : * @brief Function for checking if the specified interrupts are enabled.
235 : : *
236 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
237 : : * @param[in] mask Mask of interrupts to be checked.
238 : : *
239 : : * @return Mask of enabled interrupts.
240 : : */
241 : : NRF_STATIC_INLINE uint32_t nrf_gpiote_int_enable_check(NRF_GPIOTE_Type const * p_reg,
242 : : uint32_t mask);
243 : :
244 : : #if defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
245 : : /**
246 : : * @brief Function for setting the subscribe configuration for a given
247 : : * GPIOTE task.
248 : : *
249 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
250 : : * @param[in] task Task for which to set the configuration.
251 : : * @param[in] channel Channel through which to subscribe events.
252 : : */
253 : : NRF_STATIC_INLINE void nrf_gpiote_subscribe_set(NRF_GPIOTE_Type * p_reg,
254 : : nrf_gpiote_task_t task,
255 : : uint8_t channel);
256 : :
257 : : /**
258 : : * @brief Function for clearing the subscribe configuration for a given
259 : : * GPIOTE task.
260 : : *
261 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
262 : : * @param[in] task Task for which to clear the configuration.
263 : : */
264 : : NRF_STATIC_INLINE void nrf_gpiote_subscribe_clear(NRF_GPIOTE_Type * p_reg, nrf_gpiote_task_t task);
265 : :
266 : : /**
267 : : * @brief Function for setting the publish configuration for a given
268 : : * GPIOTE event.
269 : : *
270 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
271 : : * @param[in] event Event for which to set the configuration.
272 : : * @param[in] channel Channel through which to publish the event.
273 : : */
274 : : NRF_STATIC_INLINE void nrf_gpiote_publish_set(NRF_GPIOTE_Type * p_reg,
275 : : nrf_gpiote_event_t event,
276 : : uint8_t channel);
277 : :
278 : : /**
279 : : * @brief Function for clearing the publish configuration for a given
280 : : * GPIOTE event.
281 : : *
282 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
283 : : * @param[in] event Event for which to clear the configuration.
284 : : */
285 : : NRF_STATIC_INLINE void nrf_gpiote_publish_clear(NRF_GPIOTE_Type * p_reg, nrf_gpiote_event_t event);
286 : : #endif // defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
287 : :
288 : : /**
289 : : * @brief Function for enabling a GPIOTE event.
290 : : *
291 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
292 : : * @param[in] idx Task-Event index.
293 : : */
294 : : NRF_STATIC_INLINE void nrf_gpiote_event_enable(NRF_GPIOTE_Type * p_reg, uint32_t idx);
295 : :
296 : : /**
297 : : * @brief Function for disabling a GPIOTE event.
298 : : *
299 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
300 : : * @param[in] idx Task-Event index.
301 : : */
302 : : NRF_STATIC_INLINE void nrf_gpiote_event_disable(NRF_GPIOTE_Type * p_reg, uint32_t idx);
303 : :
304 : : /**
305 : : * @brief Function for configuring a GPIOTE event.
306 : : *
307 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
308 : : * @param[in] idx Task-Event index.
309 : : * @param[in] pin Pin associated with event.
310 : : * @param[in] polarity Transition that should generate an event.
311 : : */
312 : : NRF_STATIC_INLINE void nrf_gpiote_event_configure(NRF_GPIOTE_Type * p_reg,
313 : : uint32_t idx,
314 : : uint32_t pin,
315 : : nrf_gpiote_polarity_t polarity);
316 : :
317 : : /**
318 : : * @brief Function for getting the pin associated with a GPIOTE event.
319 : : *
320 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
321 : : * @param[in] idx Task-Event index.
322 : : *
323 : : * @return Pin number.
324 : : */
325 : : NRF_STATIC_INLINE uint32_t nrf_gpiote_event_pin_get(NRF_GPIOTE_Type const * p_reg, uint32_t idx);
326 : :
327 : : /**
328 : : * @brief Function for getting the polarity associated with a GPIOTE event.
329 : : *
330 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
331 : : * @param[in] idx Task-Event index.
332 : : *
333 : : * @return Polarity.
334 : : */
335 : : NRF_STATIC_INLINE nrf_gpiote_polarity_t nrf_gpiote_event_polarity_get(NRF_GPIOTE_Type const * p_reg,
336 : : uint32_t idx);
337 : :
338 : : /**
339 : : * @brief Function for enabling a GPIOTE task.
340 : : *
341 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
342 : : * @param[in] idx Task-Event index.
343 : : */
344 : : NRF_STATIC_INLINE void nrf_gpiote_task_enable(NRF_GPIOTE_Type * p_reg, uint32_t idx);
345 : :
346 : : /**
347 : : * @brief Function for disabling a GPIOTE task.
348 : : *
349 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
350 : : * @param[in] idx Task-Event index.
351 : : */
352 : : NRF_STATIC_INLINE void nrf_gpiote_task_disable(NRF_GPIOTE_Type * p_reg, uint32_t idx);
353 : :
354 : : /**
355 : : * @brief Function for configuring a GPIOTE task.
356 : : *
357 : : * @note Function is not configuring mode field so task is disabled after this function is called.
358 : : *
359 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
360 : : * @param[in] idx Task-Event index.
361 : : * @param[in] pin Pin associated with event.
362 : : * @param[in] polarity Transition that should generate an event.
363 : : * @param[in] init_val Initial value of the pin.
364 : : */
365 : : NRF_STATIC_INLINE void nrf_gpiote_task_configure(NRF_GPIOTE_Type * p_reg,
366 : : uint32_t idx,
367 : : uint32_t pin,
368 : : nrf_gpiote_polarity_t polarity,
369 : : nrf_gpiote_outinit_t init_val);
370 : :
371 : : /**
372 : : * @brief Function for forcing the specified state on the pin connected to GPIOTE.
373 : : *
374 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
375 : : * @param[in] idx Task-Event index.
376 : : * @param[in] init_val Pin state.
377 : : */
378 : : NRF_STATIC_INLINE void nrf_gpiote_task_force(NRF_GPIOTE_Type * p_reg,
379 : : uint32_t idx,
380 : : nrf_gpiote_outinit_t init_val);
381 : :
382 : : /**
383 : : * @brief Function for resetting a GPIOTE task event configuration to the default state.
384 : : *
385 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
386 : : * @param[in] idx Task-Event index.
387 : : */
388 : : NRF_STATIC_INLINE void nrf_gpiote_te_default(NRF_GPIOTE_Type * p_reg, uint32_t idx);
389 : :
390 : : /**@brief Function for checking if particular Task-Event is enabled.
391 : : *
392 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
393 : : * @param[in] idx Task-Event index.
394 : : *
395 : : * @retval true The Task-Event mode is set to Task or Event.
396 : : * @retval false The Task-Event mode is set to Disabled.
397 : : */
398 : : NRF_STATIC_INLINE bool nrf_gpiote_te_is_enabled(NRF_GPIOTE_Type const * p_reg, uint32_t idx);
399 : :
400 : : /**
401 : : * @brief Function for getting the OUT task associated with the specified GPIOTE channel.
402 : : *
403 : : * @param[in] index Channel index.
404 : : *
405 : : * @return Requested OUT task.
406 : : */
407 : : NRF_STATIC_INLINE nrf_gpiote_task_t nrf_gpiote_out_task_get(uint8_t index);
408 : :
409 : : #if defined(GPIOTE_FEATURE_SET_PRESENT) || defined(__NRFX_DOXYGEN__)
410 : : /**
411 : : * @brief Function for getting the SET task associated with the specified GPIOTE channel.
412 : : *
413 : : * @param[in] index Channel index.
414 : : *
415 : : * @return Requested SET task.
416 : : */
417 : : NRF_STATIC_INLINE nrf_gpiote_task_t nrf_gpiote_set_task_get(uint8_t index);
418 : : #endif
419 : :
420 : : #if defined(GPIOTE_FEATURE_CLR_PRESENT) || defined(__NRFX_DOXYGEN__)
421 : : /**
422 : : * @brief Function for getting the CLR task associated with the specified GPIOTE channel.
423 : : *
424 : : * @param[in] index Channel index.
425 : : *
426 : : * @return Requested CLR task.
427 : : */
428 : : NRF_STATIC_INLINE nrf_gpiote_task_t nrf_gpiote_clr_task_get(uint8_t index);
429 : : #endif
430 : :
431 : : /**
432 : : * @brief Function for getting the IN event associated with the specified GPIOTE channel.
433 : : *
434 : : * @param[in] index Channel index.
435 : : *
436 : : * @return Requested IN event.
437 : : */
438 : : NRF_STATIC_INLINE nrf_gpiote_event_t nrf_gpiote_in_event_get(uint8_t index);
439 : :
440 : : #if NRF_GPIOTE_HAS_LATENCY
441 : : /**
442 : : * @brief Function for setting the latency setting.
443 : : *
444 : : * @note Available for event mode with rising or falling edge detection on the pin.
445 : : * Toggle task mode can only be used with low latency setting.
446 : : *
447 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
448 : : * @param[in] latency Latency setting to be set.
449 : : */
450 : : NRF_STATIC_INLINE void nrf_gpiote_latency_set(NRF_GPIOTE_Type * p_reg,
451 : : nrf_gpiote_latency_t latency);
452 : :
453 : : /**
454 : : * @brief Function for retrieving the latency setting.
455 : : *
456 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
457 : : *
458 : : * @return Latency setting.
459 : : */
460 : : NRF_STATIC_INLINE nrf_gpiote_latency_t nrf_gpiote_latency_get(NRF_GPIOTE_Type const * p_reg);
461 : : #endif
462 : :
463 : : #ifndef NRF_DECLARE_ONLY
464 : :
465 : 0 : NRF_STATIC_INLINE void nrf_gpiote_task_trigger(NRF_GPIOTE_Type * p_reg, nrf_gpiote_task_t task)
466 : : {
467 : 0 : *(volatile uint32_t *)((uint32_t)p_reg + task) = 0x1UL;
468 : 0 : }
469 : :
470 : 0 : NRF_STATIC_INLINE uint32_t nrf_gpiote_task_address_get(NRF_GPIOTE_Type const * p_reg,
471 : : nrf_gpiote_task_t task)
472 : : {
473 : 0 : return ((uint32_t)p_reg + task);
474 : : }
475 : :
476 : 0 : NRF_STATIC_INLINE bool nrf_gpiote_event_check(NRF_GPIOTE_Type const * p_reg,
477 : : nrf_gpiote_event_t event)
478 : : {
479 : 0 : return (bool)*(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event);
480 : : }
481 : :
482 : 1 : NRF_STATIC_INLINE void nrf_gpiote_event_clear(NRF_GPIOTE_Type * p_reg, nrf_gpiote_event_t event)
483 : : {
484 : 1 : *((volatile uint32_t *)nrf_gpiote_event_address_get(p_reg, event)) = 0;
485 : 1 : nrf_event_readback((void *)nrf_gpiote_event_address_get(p_reg, event));
486 : 1 : }
487 : :
488 : 2 : NRF_STATIC_INLINE uint32_t nrf_gpiote_event_address_get(NRF_GPIOTE_Type const * p_reg,
489 : : nrf_gpiote_event_t event)
490 : : {
491 : 2 : return ((uint32_t)p_reg + event);
492 : : }
493 : :
494 : 1 : NRF_STATIC_INLINE void nrf_gpiote_int_enable(NRF_GPIOTE_Type * p_reg, uint32_t mask)
495 : : {
496 : 1 : p_reg->INTENSET = mask;
497 : 1 : }
498 : :
499 : 0 : NRF_STATIC_INLINE void nrf_gpiote_int_disable(NRF_GPIOTE_Type * p_reg, uint32_t mask)
500 : : {
501 : 0 : p_reg->INTENCLR = mask;
502 : 0 : }
503 : :
504 : 0 : NRF_STATIC_INLINE uint32_t nrf_gpiote_int_enable_check(NRF_GPIOTE_Type const * p_reg, uint32_t mask)
505 : : {
506 : 0 : return p_reg->INTENSET & mask;
507 : : }
508 : :
509 : : #if defined(DPPI_PRESENT)
510 : : NRF_STATIC_INLINE void nrf_gpiote_subscribe_set(NRF_GPIOTE_Type * p_reg,
511 : : nrf_gpiote_task_t task,
512 : : uint8_t channel)
513 : : {
514 : : *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) =
515 : : ((uint32_t)channel | GPIOTE_SUBSCRIBE_OUT_EN_Msk);
516 : : }
517 : :
518 : : NRF_STATIC_INLINE void nrf_gpiote_subscribe_clear(NRF_GPIOTE_Type * p_reg, nrf_gpiote_task_t task)
519 : : {
520 : : *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0;
521 : : }
522 : :
523 : : NRF_STATIC_INLINE void nrf_gpiote_publish_set(NRF_GPIOTE_Type * p_reg,
524 : : nrf_gpiote_event_t event,
525 : : uint8_t channel)
526 : : {
527 : : *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) event + 0x80uL)) =
528 : : ((uint32_t)channel | GPIOTE_PUBLISH_IN_EN_Msk);
529 : : }
530 : :
531 : : NRF_STATIC_INLINE void nrf_gpiote_publish_clear(NRF_GPIOTE_Type * p_reg, nrf_gpiote_event_t event)
532 : : {
533 : : *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) event + 0x80uL)) = 0;
534 : : }
535 : : #endif // defined(DPPI_PRESENT)
536 : :
537 : 0 : NRF_STATIC_INLINE void nrf_gpiote_event_enable(NRF_GPIOTE_Type * p_reg, uint32_t idx)
538 : : {
539 : 0 : p_reg->CONFIG[idx] |= GPIOTE_CONFIG_MODE_Event;
540 : 0 : }
541 : :
542 : 0 : NRF_STATIC_INLINE void nrf_gpiote_event_disable(NRF_GPIOTE_Type * p_reg, uint32_t idx)
543 : : {
544 : 0 : p_reg->CONFIG[idx] &= ~GPIOTE_CONFIG_MODE_Msk;
545 : 0 : }
546 : :
547 : 0 : NRF_STATIC_INLINE void nrf_gpiote_event_configure(NRF_GPIOTE_Type * p_reg,
548 : : uint32_t idx,
549 : : uint32_t pin,
550 : : nrf_gpiote_polarity_t polarity)
551 : : {
552 : 0 : p_reg->CONFIG[idx] &= ~(GPIOTE_CONFIG_PORT_PIN_Msk | GPIOTE_CONFIG_POLARITY_Msk);
553 : 0 : p_reg->CONFIG[idx] |= ((pin << GPIOTE_CONFIG_PSEL_Pos) & GPIOTE_CONFIG_PORT_PIN_Msk) |
554 : 0 : ((polarity << GPIOTE_CONFIG_POLARITY_Pos) & GPIOTE_CONFIG_POLARITY_Msk);
555 : 0 : }
556 : :
557 : 0 : NRF_STATIC_INLINE uint32_t nrf_gpiote_event_pin_get(NRF_GPIOTE_Type const * p_reg, uint32_t idx)
558 : : {
559 : 0 : return ((p_reg->CONFIG[idx] & GPIOTE_CONFIG_PORT_PIN_Msk) >> GPIOTE_CONFIG_PSEL_Pos);
560 : : }
561 : :
562 : 0 : NRF_STATIC_INLINE nrf_gpiote_polarity_t nrf_gpiote_event_polarity_get(NRF_GPIOTE_Type const * p_reg,
563 : : uint32_t idx)
564 : : {
565 : 0 : return (nrf_gpiote_polarity_t)((p_reg->CONFIG[idx] & GPIOTE_CONFIG_POLARITY_Msk) >>
566 : : GPIOTE_CONFIG_POLARITY_Pos);
567 : : }
568 : :
569 : 0 : NRF_STATIC_INLINE void nrf_gpiote_task_enable(NRF_GPIOTE_Type * p_reg, uint32_t idx)
570 : : {
571 : 0 : uint32_t final_config = p_reg->CONFIG[idx] | GPIOTE_CONFIG_MODE_Task;
572 : : #ifdef NRF51
573 : : /* Workaround for the OUTINIT PAN. When nrf_gpiote_task_config() is called a glitch happens
574 : : on the GPIO if the GPIO in question is already assigned to GPIOTE and the pin is in the
575 : : correct state in GPIOTE, but not in the OUT register.
576 : : Configure channel to not existing, not connected to the pin,
577 : : and configure as a tasks that will set it to proper level */
578 : : p_reg->CONFIG[idx] = final_config |
579 : : (((31) << GPIOTE_CONFIG_PSEL_Pos) & GPIOTE_CONFIG_PORT_PIN_Msk);
580 : : __NOP();
581 : : __NOP();
582 : : __NOP();
583 : : #endif
584 : 0 : p_reg->CONFIG[idx] = final_config;
585 : 0 : }
586 : :
587 : 0 : NRF_STATIC_INLINE void nrf_gpiote_task_disable(NRF_GPIOTE_Type * p_reg, uint32_t idx)
588 : : {
589 : 0 : p_reg->CONFIG[idx] &= ~GPIOTE_CONFIG_MODE_Msk;
590 : 0 : }
591 : :
592 : 0 : NRF_STATIC_INLINE void nrf_gpiote_task_configure(NRF_GPIOTE_Type * p_reg,
593 : : uint32_t idx,
594 : : uint32_t pin,
595 : : nrf_gpiote_polarity_t polarity,
596 : : nrf_gpiote_outinit_t init_val)
597 : : {
598 : 0 : p_reg->CONFIG[idx] &= ~(GPIOTE_CONFIG_PORT_PIN_Msk |
599 : : GPIOTE_CONFIG_POLARITY_Msk |
600 : : GPIOTE_CONFIG_OUTINIT_Msk);
601 : :
602 : 0 : p_reg->CONFIG[idx] |= ((pin << GPIOTE_CONFIG_PSEL_Pos) & GPIOTE_CONFIG_PORT_PIN_Msk) |
603 : 0 : ((polarity << GPIOTE_CONFIG_POLARITY_Pos) & GPIOTE_CONFIG_POLARITY_Msk) |
604 : 0 : ((init_val << GPIOTE_CONFIG_OUTINIT_Pos) & GPIOTE_CONFIG_OUTINIT_Msk);
605 : 0 : }
606 : :
607 : 0 : NRF_STATIC_INLINE void nrf_gpiote_task_force(NRF_GPIOTE_Type * p_reg,
608 : : uint32_t idx,
609 : : nrf_gpiote_outinit_t init_val)
610 : : {
611 : 0 : p_reg->CONFIG[idx] = (p_reg->CONFIG[idx] & ~GPIOTE_CONFIG_OUTINIT_Msk) |
612 : 0 : ((init_val << GPIOTE_CONFIG_OUTINIT_Pos) & GPIOTE_CONFIG_OUTINIT_Msk);
613 : 0 : }
614 : :
615 : 0 : NRF_STATIC_INLINE void nrf_gpiote_te_default(NRF_GPIOTE_Type * p_reg, uint32_t idx)
616 : : {
617 : 0 : p_reg->CONFIG[idx] = 0;
618 : : #if defined(NRF9160_XXAA) || defined(NRF5340_XXAA)
619 : 0 : p_reg->CONFIG[idx] = 0;
620 : : #endif
621 : 0 : }
622 : :
623 : : NRF_STATIC_INLINE bool nrf_gpiote_te_is_enabled(NRF_GPIOTE_Type const * p_reg, uint32_t idx)
624 : : {
625 : : return (p_reg->CONFIG[idx] & GPIOTE_CONFIG_MODE_Msk) != GPIOTE_CONFIG_MODE_Disabled;
626 : : }
627 : :
628 : 0 : NRF_STATIC_INLINE nrf_gpiote_task_t nrf_gpiote_out_task_get(uint8_t index)
629 : : {
630 [ # # ]: 0 : NRFX_ASSERT(index < GPIOTE_CH_NUM);
631 : 0 : return (nrf_gpiote_task_t)NRFX_OFFSETOF(NRF_GPIOTE_Type, TASKS_OUT[index]);
632 : : }
633 : :
634 : : #if defined(GPIOTE_FEATURE_SET_PRESENT)
635 : 0 : NRF_STATIC_INLINE nrf_gpiote_task_t nrf_gpiote_set_task_get(uint8_t index)
636 : : {
637 [ # # ]: 0 : NRFX_ASSERT(index < GPIOTE_CH_NUM);
638 : 0 : return (nrf_gpiote_task_t)NRFX_OFFSETOF(NRF_GPIOTE_Type, TASKS_SET[index]);
639 : : }
640 : : #endif
641 : :
642 : : #if defined(GPIOTE_FEATURE_CLR_PRESENT)
643 : 0 : NRF_STATIC_INLINE nrf_gpiote_task_t nrf_gpiote_clr_task_get(uint8_t index)
644 : : {
645 [ # # ]: 0 : NRFX_ASSERT(index < GPIOTE_CH_NUM);
646 : 0 : return (nrf_gpiote_task_t)NRFX_OFFSETOF(NRF_GPIOTE_Type, TASKS_CLR[index]);
647 : : }
648 : : #endif
649 : :
650 : 0 : NRF_STATIC_INLINE nrf_gpiote_event_t nrf_gpiote_in_event_get(uint8_t index)
651 : : {
652 [ # # ]: 0 : NRFX_ASSERT(index < GPIOTE_CH_NUM);
653 : 0 : return (nrf_gpiote_event_t)NRFX_OFFSETOF(NRF_GPIOTE_Type, EVENTS_IN[index]);
654 : : }
655 : :
656 : : #if NRF_GPIOTE_HAS_LATENCY
657 : : NRF_STATIC_INLINE void nrf_gpiote_latency_set(NRF_GPIOTE_Type * p_reg,
658 : : nrf_gpiote_latency_t latency)
659 : : {
660 : : p_reg->LATENCY = (latency << GPIOTE_LATENCY_LATENCY_Pos) & GPIOTE_LATENCY_LATENCY_Msk;
661 : : }
662 : :
663 : : NRF_STATIC_INLINE nrf_gpiote_latency_t nrf_gpiote_latency_get(NRF_GPIOTE_Type const * p_reg)
664 : : {
665 : : return (nrf_gpiote_latency_t)((p_reg->LATENCY & GPIOTE_LATENCY_LATENCY_Msk) >>
666 : : GPIOTE_LATENCY_LATENCY_Pos);
667 : : }
668 : : #endif // NRF_GPIOTE_HAS_LATENCY
669 : : #endif // NRF_DECLARE_ONLY
670 : :
671 : : /** @} */
672 : :
673 : : #ifdef __cplusplus
674 : : }
675 : : #endif
676 : :
677 : : #endif
|