1*150812a8SEvalZero /*
2*150812a8SEvalZero * Copyright (c) 2015 - 2018, Nordic Semiconductor ASA
3*150812a8SEvalZero * All rights reserved.
4*150812a8SEvalZero *
5*150812a8SEvalZero * Redistribution and use in source and binary forms, with or without
6*150812a8SEvalZero * modification, are permitted provided that the following conditions are met:
7*150812a8SEvalZero *
8*150812a8SEvalZero * 1. Redistributions of source code must retain the above copyright notice, this
9*150812a8SEvalZero * list of conditions and the following disclaimer.
10*150812a8SEvalZero *
11*150812a8SEvalZero * 2. Redistributions in binary form must reproduce the above copyright
12*150812a8SEvalZero * notice, this list of conditions and the following disclaimer in the
13*150812a8SEvalZero * documentation and/or other materials provided with the distribution.
14*150812a8SEvalZero *
15*150812a8SEvalZero * 3. Neither the name of the copyright holder nor the names of its
16*150812a8SEvalZero * contributors may be used to endorse or promote products derived from this
17*150812a8SEvalZero * software without specific prior written permission.
18*150812a8SEvalZero *
19*150812a8SEvalZero * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20*150812a8SEvalZero * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*150812a8SEvalZero * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*150812a8SEvalZero * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23*150812a8SEvalZero * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*150812a8SEvalZero * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*150812a8SEvalZero * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*150812a8SEvalZero * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*150812a8SEvalZero * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*150812a8SEvalZero * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*150812a8SEvalZero * POSSIBILITY OF SUCH DAMAGE.
30*150812a8SEvalZero */
31*150812a8SEvalZero
32*150812a8SEvalZero #ifndef NRF_GPIO_H__
33*150812a8SEvalZero #define NRF_GPIO_H__
34*150812a8SEvalZero
35*150812a8SEvalZero #include <nrfx.h>
36*150812a8SEvalZero
37*150812a8SEvalZero #ifdef __cplusplus
38*150812a8SEvalZero extern "C" {
39*150812a8SEvalZero #endif
40*150812a8SEvalZero
41*150812a8SEvalZero /**
42*150812a8SEvalZero * @defgroup nrf_gpio_hal GPIO HAL
43*150812a8SEvalZero * @{
44*150812a8SEvalZero * @ingroup nrf_gpio
45*150812a8SEvalZero * @brief Hardware access layer for managing the GPIO peripheral.
46*150812a8SEvalZero */
47*150812a8SEvalZero
48*150812a8SEvalZero #ifndef NRF_P0
49*150812a8SEvalZero #define NRF_P0 NRF_GPIO
50*150812a8SEvalZero #endif
51*150812a8SEvalZero
52*150812a8SEvalZero #if (GPIO_COUNT == 1)
53*150812a8SEvalZero #define NUMBER_OF_PINS (P0_PIN_NUM)
54*150812a8SEvalZero #define GPIO_REG_LIST {NRF_P0}
55*150812a8SEvalZero #elif (GPIO_COUNT == 2)
56*150812a8SEvalZero #define NUMBER_OF_PINS (P0_PIN_NUM + P1_PIN_NUM)
57*150812a8SEvalZero #define GPIO_REG_LIST {NRF_P0, NRF_P1}
58*150812a8SEvalZero #else
59*150812a8SEvalZero #error "Not supported."
60*150812a8SEvalZero #endif
61*150812a8SEvalZero
62*150812a8SEvalZero
63*150812a8SEvalZero /**
64*150812a8SEvalZero * @brief Macro for mapping port and pin numbers to values understandable for nrf_gpio functions.
65*150812a8SEvalZero */
66*150812a8SEvalZero #define NRF_GPIO_PIN_MAP(port, pin) (((port) << 5) | ((pin) & 0x1F))
67*150812a8SEvalZero
68*150812a8SEvalZero /**
69*150812a8SEvalZero * @brief Pin direction definitions.
70*150812a8SEvalZero */
71*150812a8SEvalZero typedef enum
72*150812a8SEvalZero {
73*150812a8SEvalZero NRF_GPIO_PIN_DIR_INPUT = GPIO_PIN_CNF_DIR_Input, ///< Input.
74*150812a8SEvalZero NRF_GPIO_PIN_DIR_OUTPUT = GPIO_PIN_CNF_DIR_Output ///< Output.
75*150812a8SEvalZero } nrf_gpio_pin_dir_t;
76*150812a8SEvalZero
77*150812a8SEvalZero /**
78*150812a8SEvalZero * @brief Connection of input buffer.
79*150812a8SEvalZero */
80*150812a8SEvalZero typedef enum
81*150812a8SEvalZero {
82*150812a8SEvalZero NRF_GPIO_PIN_INPUT_CONNECT = GPIO_PIN_CNF_INPUT_Connect, ///< Connect input buffer.
83*150812a8SEvalZero NRF_GPIO_PIN_INPUT_DISCONNECT = GPIO_PIN_CNF_INPUT_Disconnect ///< Disconnect input buffer.
84*150812a8SEvalZero } nrf_gpio_pin_input_t;
85*150812a8SEvalZero
86*150812a8SEvalZero /**
87*150812a8SEvalZero * @brief Enumerator used for selecting the pin to be pulled down or up at the time of pin configuration.
88*150812a8SEvalZero */
89*150812a8SEvalZero typedef enum
90*150812a8SEvalZero {
91*150812a8SEvalZero NRF_GPIO_PIN_NOPULL = GPIO_PIN_CNF_PULL_Disabled, ///< Pin pull-up resistor disabled.
92*150812a8SEvalZero NRF_GPIO_PIN_PULLDOWN = GPIO_PIN_CNF_PULL_Pulldown, ///< Pin pull-down resistor enabled.
93*150812a8SEvalZero NRF_GPIO_PIN_PULLUP = GPIO_PIN_CNF_PULL_Pullup, ///< Pin pull-up resistor enabled.
94*150812a8SEvalZero } nrf_gpio_pin_pull_t;
95*150812a8SEvalZero
96*150812a8SEvalZero /**
97*150812a8SEvalZero * @brief Enumerator used for selecting output drive mode.
98*150812a8SEvalZero */
99*150812a8SEvalZero typedef enum
100*150812a8SEvalZero {
101*150812a8SEvalZero NRF_GPIO_PIN_S0S1 = GPIO_PIN_CNF_DRIVE_S0S1, ///< !< Standard '0', standard '1'.
102*150812a8SEvalZero NRF_GPIO_PIN_H0S1 = GPIO_PIN_CNF_DRIVE_H0S1, ///< !< High-drive '0', standard '1'.
103*150812a8SEvalZero NRF_GPIO_PIN_S0H1 = GPIO_PIN_CNF_DRIVE_S0H1, ///< !< Standard '0', high-drive '1'.
104*150812a8SEvalZero NRF_GPIO_PIN_H0H1 = GPIO_PIN_CNF_DRIVE_H0H1, ///< !< High drive '0', high-drive '1'.
105*150812a8SEvalZero NRF_GPIO_PIN_D0S1 = GPIO_PIN_CNF_DRIVE_D0S1, ///< !< Disconnect '0' standard '1'.
106*150812a8SEvalZero NRF_GPIO_PIN_D0H1 = GPIO_PIN_CNF_DRIVE_D0H1, ///< !< Disconnect '0', high-drive '1'.
107*150812a8SEvalZero NRF_GPIO_PIN_S0D1 = GPIO_PIN_CNF_DRIVE_S0D1, ///< !< Standard '0', disconnect '1'.
108*150812a8SEvalZero NRF_GPIO_PIN_H0D1 = GPIO_PIN_CNF_DRIVE_H0D1, ///< !< High-drive '0', disconnect '1'.
109*150812a8SEvalZero } nrf_gpio_pin_drive_t;
110*150812a8SEvalZero
111*150812a8SEvalZero /**
112*150812a8SEvalZero * @brief Enumerator used for selecting the pin to sense high or low level on the pin input.
113*150812a8SEvalZero */
114*150812a8SEvalZero typedef enum
115*150812a8SEvalZero {
116*150812a8SEvalZero NRF_GPIO_PIN_NOSENSE = GPIO_PIN_CNF_SENSE_Disabled, ///< Pin sense level disabled.
117*150812a8SEvalZero NRF_GPIO_PIN_SENSE_LOW = GPIO_PIN_CNF_SENSE_Low, ///< Pin sense low level.
118*150812a8SEvalZero NRF_GPIO_PIN_SENSE_HIGH = GPIO_PIN_CNF_SENSE_High, ///< Pin sense high level.
119*150812a8SEvalZero } nrf_gpio_pin_sense_t;
120*150812a8SEvalZero
121*150812a8SEvalZero /**
122*150812a8SEvalZero * @brief Function for configuring the GPIO pin range as output pins with normal drive strength.
123*150812a8SEvalZero * This function can be used to configure pin range as simple output with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
124*150812a8SEvalZero *
125*150812a8SEvalZero * @param pin_range_start Specifies the start number (inclusive) in the range of pin numbers to be configured (allowed values 0-30).
126*150812a8SEvalZero *
127*150812a8SEvalZero * @param pin_range_end Specifies the end number (inclusive) in the range of pin numbers to be configured (allowed values 0-30).
128*150812a8SEvalZero *
129*150812a8SEvalZero * @note For configuring only one pin as output, use @ref nrf_gpio_cfg_output.
130*150812a8SEvalZero * Sense capability on the pin is disabled and input is disconnected from the buffer as the pins are configured as output.
131*150812a8SEvalZero */
132*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_range_cfg_output(uint32_t pin_range_start, uint32_t pin_range_end);
133*150812a8SEvalZero
134*150812a8SEvalZero /**
135*150812a8SEvalZero * @brief Function for configuring the GPIO pin range as input pins with given initial value set, hiding inner details.
136*150812a8SEvalZero * This function can be used to configure pin range as simple input.
137*150812a8SEvalZero *
138*150812a8SEvalZero * @param pin_range_start Specifies the start number (inclusive) in the range of pin numbers to be configured (allowed values 0-30).
139*150812a8SEvalZero *
140*150812a8SEvalZero * @param pin_range_end Specifies the end number (inclusive) in the range of pin numbers to be configured (allowed values 0-30).
141*150812a8SEvalZero *
142*150812a8SEvalZero * @param pull_config State of the pin range pull resistor (no pull, pulled down, or pulled high).
143*150812a8SEvalZero *
144*150812a8SEvalZero * @note For configuring only one pin as input, use @ref nrf_gpio_cfg_input.
145*150812a8SEvalZero * Sense capability on the pin is disabled and input is connected to buffer so that the GPIO->IN register is readable.
146*150812a8SEvalZero */
147*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_range_cfg_input(uint32_t pin_range_start,
148*150812a8SEvalZero uint32_t pin_range_end,
149*150812a8SEvalZero nrf_gpio_pin_pull_t pull_config);
150*150812a8SEvalZero
151*150812a8SEvalZero /**
152*150812a8SEvalZero * @brief Pin configuration function.
153*150812a8SEvalZero *
154*150812a8SEvalZero * The main pin configuration function.
155*150812a8SEvalZero * This function allows to set any aspect in PIN_CNF register.
156*150812a8SEvalZero * @param pin_number Specifies the pin number.
157*150812a8SEvalZero * @param dir Pin direction.
158*150812a8SEvalZero * @param input Connect or disconnect the input buffer.
159*150812a8SEvalZero * @param pull Pull configuration.
160*150812a8SEvalZero * @param drive Drive configuration.
161*150812a8SEvalZero * @param sense Pin sensing mechanism.
162*150812a8SEvalZero */
163*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_cfg(
164*150812a8SEvalZero uint32_t pin_number,
165*150812a8SEvalZero nrf_gpio_pin_dir_t dir,
166*150812a8SEvalZero nrf_gpio_pin_input_t input,
167*150812a8SEvalZero nrf_gpio_pin_pull_t pull,
168*150812a8SEvalZero nrf_gpio_pin_drive_t drive,
169*150812a8SEvalZero nrf_gpio_pin_sense_t sense);
170*150812a8SEvalZero
171*150812a8SEvalZero /**
172*150812a8SEvalZero * @brief Function for configuring the given GPIO pin number as output, hiding inner details.
173*150812a8SEvalZero * This function can be used to configure a pin as simple output with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
174*150812a8SEvalZero *
175*150812a8SEvalZero * @param pin_number Specifies the pin number.
176*150812a8SEvalZero *
177*150812a8SEvalZero * @note Sense capability on the pin is disabled and input is disconnected from the buffer as the pins are configured as output.
178*150812a8SEvalZero */
179*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_cfg_output(uint32_t pin_number);
180*150812a8SEvalZero
181*150812a8SEvalZero /**
182*150812a8SEvalZero * @brief Function for configuring the given GPIO pin number as input, hiding inner details.
183*150812a8SEvalZero * This function can be used to configure a pin as simple input.
184*150812a8SEvalZero *
185*150812a8SEvalZero * @param pin_number Specifies the pin number.
186*150812a8SEvalZero * @param pull_config State of the pin range pull resistor (no pull, pulled down, or pulled high).
187*150812a8SEvalZero *
188*150812a8SEvalZero * @note Sense capability on the pin is disabled and input is connected to buffer so that the GPIO->IN register is readable.
189*150812a8SEvalZero */
190*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config);
191*150812a8SEvalZero
192*150812a8SEvalZero /**
193*150812a8SEvalZero * @brief Function for resetting pin configuration to its default state.
194*150812a8SEvalZero *
195*150812a8SEvalZero * @param pin_number Specifies the pin number.
196*150812a8SEvalZero */
197*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_cfg_default(uint32_t pin_number);
198*150812a8SEvalZero
199*150812a8SEvalZero /**
200*150812a8SEvalZero * @brief Function for configuring the given GPIO pin number as a watcher. Only input is connected.
201*150812a8SEvalZero *
202*150812a8SEvalZero * @param pin_number Specifies the pin number.
203*150812a8SEvalZero *
204*150812a8SEvalZero */
205*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_cfg_watcher(uint32_t pin_number);
206*150812a8SEvalZero
207*150812a8SEvalZero /**
208*150812a8SEvalZero * @brief Function for disconnecting input for the given GPIO.
209*150812a8SEvalZero *
210*150812a8SEvalZero * @param pin_number Specifies the pin number.
211*150812a8SEvalZero *
212*150812a8SEvalZero */
213*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_input_disconnect(uint32_t pin_number);
214*150812a8SEvalZero
215*150812a8SEvalZero /**
216*150812a8SEvalZero * @brief Function for configuring the given GPIO pin number as input, hiding inner details.
217*150812a8SEvalZero * This function can be used to configure pin range as simple input.
218*150812a8SEvalZero * Sense capability on the pin is configurable and input is connected to buffer so that the GPIO->IN register is readable.
219*150812a8SEvalZero *
220*150812a8SEvalZero * @param pin_number Specifies the pin number.
221*150812a8SEvalZero * @param pull_config State of the pin pull resistor (no pull, pulled down, or pulled high).
222*150812a8SEvalZero * @param sense_config Sense level of the pin (no sense, sense low, or sense high).
223*150812a8SEvalZero */
224*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_cfg_sense_input(uint32_t pin_number,
225*150812a8SEvalZero nrf_gpio_pin_pull_t pull_config,
226*150812a8SEvalZero nrf_gpio_pin_sense_t sense_config);
227*150812a8SEvalZero
228*150812a8SEvalZero /**
229*150812a8SEvalZero * @brief Function for configuring sense level for the given GPIO.
230*150812a8SEvalZero *
231*150812a8SEvalZero * @param pin_number Specifies the pin number.
232*150812a8SEvalZero * @param sense_config Sense configuration.
233*150812a8SEvalZero *
234*150812a8SEvalZero */
235*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_cfg_sense_set(uint32_t pin_number, nrf_gpio_pin_sense_t sense_config);
236*150812a8SEvalZero
237*150812a8SEvalZero /**
238*150812a8SEvalZero * @brief Function for setting the direction for a GPIO pin.
239*150812a8SEvalZero *
240*150812a8SEvalZero * @param pin_number Specifies the pin number for which to set the direction.
241*150812a8SEvalZero *
242*150812a8SEvalZero * @param direction Specifies the direction.
243*150812a8SEvalZero */
244*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_pin_dir_set(uint32_t pin_number, nrf_gpio_pin_dir_t direction);
245*150812a8SEvalZero
246*150812a8SEvalZero /**
247*150812a8SEvalZero * @brief Function for setting a GPIO pin.
248*150812a8SEvalZero *
249*150812a8SEvalZero * Note that the pin must be configured as an output for this function to have any effect.
250*150812a8SEvalZero *
251*150812a8SEvalZero * @param pin_number Specifies the pin number to set.
252*150812a8SEvalZero */
253*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_pin_set(uint32_t pin_number);
254*150812a8SEvalZero
255*150812a8SEvalZero /**
256*150812a8SEvalZero * @brief Function for clearing a GPIO pin.
257*150812a8SEvalZero *
258*150812a8SEvalZero * Note that the pin must be configured as an output for this
259*150812a8SEvalZero * function to have any effect.
260*150812a8SEvalZero *
261*150812a8SEvalZero * @param pin_number Specifies the pin number to clear.
262*150812a8SEvalZero */
263*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_pin_clear(uint32_t pin_number);
264*150812a8SEvalZero
265*150812a8SEvalZero /**
266*150812a8SEvalZero * @brief Function for toggling a GPIO pin.
267*150812a8SEvalZero *
268*150812a8SEvalZero * Note that the pin must be configured as an output for this
269*150812a8SEvalZero * function to have any effect.
270*150812a8SEvalZero *
271*150812a8SEvalZero * @param pin_number Specifies the pin number to toggle.
272*150812a8SEvalZero */
273*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_pin_toggle(uint32_t pin_number);
274*150812a8SEvalZero
275*150812a8SEvalZero /**
276*150812a8SEvalZero * @brief Function for writing a value to a GPIO pin.
277*150812a8SEvalZero *
278*150812a8SEvalZero * Note that the pin must be configured as an output for this
279*150812a8SEvalZero * function to have any effect.
280*150812a8SEvalZero *
281*150812a8SEvalZero * @param pin_number Specifies the pin number to write.
282*150812a8SEvalZero *
283*150812a8SEvalZero * @param value Specifies the value to be written to the pin.
284*150812a8SEvalZero * @arg 0 Clears the pin.
285*150812a8SEvalZero * @arg >=1 Sets the pin.
286*150812a8SEvalZero */
287*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_pin_write(uint32_t pin_number, uint32_t value);
288*150812a8SEvalZero
289*150812a8SEvalZero /**
290*150812a8SEvalZero * @brief Function for reading the input level of a GPIO pin.
291*150812a8SEvalZero *
292*150812a8SEvalZero * Note that the pin must have input connected for the value
293*150812a8SEvalZero * returned from this function to be valid.
294*150812a8SEvalZero *
295*150812a8SEvalZero * @param pin_number Specifies the pin number to read.
296*150812a8SEvalZero *
297*150812a8SEvalZero * @return 0 if the pin input level is low. Positive value if the pin is high.
298*150812a8SEvalZero */
299*150812a8SEvalZero __STATIC_INLINE uint32_t nrf_gpio_pin_read(uint32_t pin_number);
300*150812a8SEvalZero
301*150812a8SEvalZero /**
302*150812a8SEvalZero * @brief Function for reading the output level of a GPIO pin.
303*150812a8SEvalZero *
304*150812a8SEvalZero * @param pin_number Specifies the pin number to read.
305*150812a8SEvalZero *
306*150812a8SEvalZero * @return 0 if the pin output level is low. Positive value if pin output is high.
307*150812a8SEvalZero */
308*150812a8SEvalZero __STATIC_INLINE uint32_t nrf_gpio_pin_out_read(uint32_t pin_number);
309*150812a8SEvalZero
310*150812a8SEvalZero /**
311*150812a8SEvalZero * @brief Function for reading the sense configuration of a GPIO pin.
312*150812a8SEvalZero *
313*150812a8SEvalZero * @param pin_number Specifies the pin number to read.
314*150812a8SEvalZero *
315*150812a8SEvalZero * @retval Sense configuration.
316*150812a8SEvalZero */
317*150812a8SEvalZero __STATIC_INLINE nrf_gpio_pin_sense_t nrf_gpio_pin_sense_get(uint32_t pin_number);
318*150812a8SEvalZero
319*150812a8SEvalZero /**
320*150812a8SEvalZero * @brief Function for reading the direction configuration of a GPIO pin.
321*150812a8SEvalZero *
322*150812a8SEvalZero * @param pin_number Specifies the pin number to read.
323*150812a8SEvalZero *
324*150812a8SEvalZero * @retval Direction configuration.
325*150812a8SEvalZero */
326*150812a8SEvalZero __STATIC_INLINE nrf_gpio_pin_dir_t nrf_gpio_pin_dir_get(uint32_t pin_number);
327*150812a8SEvalZero
328*150812a8SEvalZero /**
329*150812a8SEvalZero * @brief Function for reading the pull configuration of a GPIO pin.
330*150812a8SEvalZero *
331*150812a8SEvalZero * @param pin_number Specifies the pin number to read.
332*150812a8SEvalZero *
333*150812a8SEvalZero * @retval Pull configuration.
334*150812a8SEvalZero */
335*150812a8SEvalZero __STATIC_INLINE nrf_gpio_pin_pull_t nrf_gpio_pin_pull_get(uint32_t pin_number);
336*150812a8SEvalZero
337*150812a8SEvalZero /**
338*150812a8SEvalZero * @brief Function for setting output direction on selected pins on a given port.
339*150812a8SEvalZero *
340*150812a8SEvalZero * @param p_reg Pointer to the peripheral registers structure.
341*150812a8SEvalZero * @param out_mask Mask specifying the pins to set as output.
342*150812a8SEvalZero *
343*150812a8SEvalZero */
344*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_port_dir_output_set(NRF_GPIO_Type * p_reg, uint32_t out_mask);
345*150812a8SEvalZero
346*150812a8SEvalZero /**
347*150812a8SEvalZero * @brief Function for setting input direction on selected pins on a given port.
348*150812a8SEvalZero *
349*150812a8SEvalZero * @param p_reg Pointer to the peripheral registers structure.
350*150812a8SEvalZero * @param in_mask Mask specifying the pins to set as input.
351*150812a8SEvalZero *
352*150812a8SEvalZero */
353*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_port_dir_input_set(NRF_GPIO_Type * p_reg, uint32_t in_mask);
354*150812a8SEvalZero
355*150812a8SEvalZero /**
356*150812a8SEvalZero * @brief Function for writing the direction configuration of GPIO pins in a given port.
357*150812a8SEvalZero *
358*150812a8SEvalZero * @param p_reg Pointer to the peripheral registers structure.
359*150812a8SEvalZero * @param dir_mask Mask specifying the direction of pins. Bit set means that the given pin is configured as output.
360*150812a8SEvalZero *
361*150812a8SEvalZero */
362*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_port_dir_write(NRF_GPIO_Type * p_reg, uint32_t dir_mask);
363*150812a8SEvalZero
364*150812a8SEvalZero /**
365*150812a8SEvalZero * @brief Function for reading the direction configuration of a GPIO port.
366*150812a8SEvalZero *
367*150812a8SEvalZero * @param p_reg Pointer to the peripheral registers structure.
368*150812a8SEvalZero *
369*150812a8SEvalZero * @retval Pin configuration of the current direction settings. Bit set means that the given pin is configured as output.
370*150812a8SEvalZero */
371*150812a8SEvalZero __STATIC_INLINE uint32_t nrf_gpio_port_dir_read(NRF_GPIO_Type const * p_reg);
372*150812a8SEvalZero
373*150812a8SEvalZero /**
374*150812a8SEvalZero * @brief Function for reading the input signals of GPIO pins on a given port.
375*150812a8SEvalZero *
376*150812a8SEvalZero * @param p_reg Pointer to the peripheral registers structure.
377*150812a8SEvalZero *
378*150812a8SEvalZero * @retval Port input values.
379*150812a8SEvalZero */
380*150812a8SEvalZero __STATIC_INLINE uint32_t nrf_gpio_port_in_read(NRF_GPIO_Type const * p_reg);
381*150812a8SEvalZero
382*150812a8SEvalZero /**
383*150812a8SEvalZero * @brief Function for reading the output signals of GPIO pins of a given port.
384*150812a8SEvalZero *
385*150812a8SEvalZero * @param p_reg Pointer to the peripheral registers structure.
386*150812a8SEvalZero *
387*150812a8SEvalZero * @retval Port output values.
388*150812a8SEvalZero */
389*150812a8SEvalZero __STATIC_INLINE uint32_t nrf_gpio_port_out_read(NRF_GPIO_Type const * p_reg);
390*150812a8SEvalZero
391*150812a8SEvalZero /**
392*150812a8SEvalZero * @brief Function for writing the GPIO pins output on a given port.
393*150812a8SEvalZero *
394*150812a8SEvalZero * @param p_reg Pointer to the peripheral registers structure.
395*150812a8SEvalZero * @param value Output port mask.
396*150812a8SEvalZero *
397*150812a8SEvalZero */
398*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_port_out_write(NRF_GPIO_Type * p_reg, uint32_t value);
399*150812a8SEvalZero
400*150812a8SEvalZero /**
401*150812a8SEvalZero * @brief Function for setting high level on selected GPIO pins of a given port.
402*150812a8SEvalZero *
403*150812a8SEvalZero * @param p_reg Pointer to the peripheral registers structure.
404*150812a8SEvalZero * @param set_mask Mask with pins to set as logical high level.
405*150812a8SEvalZero *
406*150812a8SEvalZero */
407*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_port_out_set(NRF_GPIO_Type * p_reg, uint32_t set_mask);
408*150812a8SEvalZero
409*150812a8SEvalZero /**
410*150812a8SEvalZero * @brief Function for setting low level on selected GPIO pins of a given port.
411*150812a8SEvalZero *
412*150812a8SEvalZero * @param p_reg Pointer to the peripheral registers structure.
413*150812a8SEvalZero * @param clr_mask Mask with pins to set as logical low level.
414*150812a8SEvalZero *
415*150812a8SEvalZero */
416*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_port_out_clear(NRF_GPIO_Type * p_reg, uint32_t clr_mask);
417*150812a8SEvalZero
418*150812a8SEvalZero /**
419*150812a8SEvalZero * @brief Function for reading pins state of multiple consecutive ports.
420*150812a8SEvalZero *
421*150812a8SEvalZero * @param start_port Index of the first port to read.
422*150812a8SEvalZero * @param length Number of ports to read.
423*150812a8SEvalZero * @param p_masks Pointer to output array where port states will be stored.
424*150812a8SEvalZero */
425*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_ports_read(uint32_t start_port, uint32_t length, uint32_t * p_masks);
426*150812a8SEvalZero
427*150812a8SEvalZero #if defined(GPIO_DETECTMODE_DETECTMODE_LDETECT) || defined(__NRF_DOXYGEN__)
428*150812a8SEvalZero /**
429*150812a8SEvalZero * @brief Function for reading latch state of multiple consecutive ports.
430*150812a8SEvalZero *
431*150812a8SEvalZero * @param start_port Index of the first port to read.
432*150812a8SEvalZero * @param length Number of ports to read.
433*150812a8SEvalZero * @param p_masks Pointer to output array where latch states will be stored.
434*150812a8SEvalZero */
435*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_latches_read(uint32_t start_port, uint32_t length,
436*150812a8SEvalZero uint32_t * p_masks);
437*150812a8SEvalZero
438*150812a8SEvalZero /**
439*150812a8SEvalZero * @brief Function for reading latch state of single pin.
440*150812a8SEvalZero *
441*150812a8SEvalZero * @param pin_number Pin number.
442*150812a8SEvalZero * @return 0 if latch is not set. Positive value otherwise.
443*150812a8SEvalZero *
444*150812a8SEvalZero */
445*150812a8SEvalZero __STATIC_INLINE uint32_t nrf_gpio_pin_latch_get(uint32_t pin_number);
446*150812a8SEvalZero
447*150812a8SEvalZero /**
448*150812a8SEvalZero * @brief Function for clearing latch state of a single pin.
449*150812a8SEvalZero *
450*150812a8SEvalZero * @param pin_number Pin number.
451*150812a8SEvalZero *
452*150812a8SEvalZero */
453*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_pin_latch_clear(uint32_t pin_number);
454*150812a8SEvalZero #endif
455*150812a8SEvalZero
456*150812a8SEvalZero #ifndef SUPPRESS_INLINE_IMPLEMENTATION
457*150812a8SEvalZero
458*150812a8SEvalZero /**
459*150812a8SEvalZero * @brief Function for extracting port and relative pin number from absolute pin number.
460*150812a8SEvalZero *
461*150812a8SEvalZero * @param[inout] Pointer to absolute pin number which is overriden by relative to port pin number.
462*150812a8SEvalZero *
463*150812a8SEvalZero * @return Pointer to port register set.
464*150812a8SEvalZero *
465*150812a8SEvalZero */
nrf_gpio_pin_port_decode(uint32_t * p_pin)466*150812a8SEvalZero __STATIC_INLINE NRF_GPIO_Type * nrf_gpio_pin_port_decode(uint32_t * p_pin)
467*150812a8SEvalZero {
468*150812a8SEvalZero NRFX_ASSERT(*p_pin < NUMBER_OF_PINS);
469*150812a8SEvalZero #if (GPIO_COUNT == 1)
470*150812a8SEvalZero return NRF_P0;
471*150812a8SEvalZero #else
472*150812a8SEvalZero if (*p_pin < P0_PIN_NUM)
473*150812a8SEvalZero {
474*150812a8SEvalZero return NRF_P0;
475*150812a8SEvalZero }
476*150812a8SEvalZero else
477*150812a8SEvalZero {
478*150812a8SEvalZero *p_pin = *p_pin & (P0_PIN_NUM - 1);
479*150812a8SEvalZero return NRF_P1;
480*150812a8SEvalZero }
481*150812a8SEvalZero #endif
482*150812a8SEvalZero }
483*150812a8SEvalZero
484*150812a8SEvalZero
nrf_gpio_range_cfg_output(uint32_t pin_range_start,uint32_t pin_range_end)485*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_range_cfg_output(uint32_t pin_range_start, uint32_t pin_range_end)
486*150812a8SEvalZero {
487*150812a8SEvalZero /*lint -e{845} // A zero has been given as right argument to operator '|'" */
488*150812a8SEvalZero for (; pin_range_start <= pin_range_end; pin_range_start++)
489*150812a8SEvalZero {
490*150812a8SEvalZero nrf_gpio_cfg_output(pin_range_start);
491*150812a8SEvalZero }
492*150812a8SEvalZero }
493*150812a8SEvalZero
494*150812a8SEvalZero
nrf_gpio_range_cfg_input(uint32_t pin_range_start,uint32_t pin_range_end,nrf_gpio_pin_pull_t pull_config)495*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_range_cfg_input(uint32_t pin_range_start,
496*150812a8SEvalZero uint32_t pin_range_end,
497*150812a8SEvalZero nrf_gpio_pin_pull_t pull_config)
498*150812a8SEvalZero {
499*150812a8SEvalZero /*lint -e{845} // A zero has been given as right argument to operator '|'" */
500*150812a8SEvalZero for (; pin_range_start <= pin_range_end; pin_range_start++)
501*150812a8SEvalZero {
502*150812a8SEvalZero nrf_gpio_cfg_input(pin_range_start, pull_config);
503*150812a8SEvalZero }
504*150812a8SEvalZero }
505*150812a8SEvalZero
506*150812a8SEvalZero
nrf_gpio_cfg(uint32_t pin_number,nrf_gpio_pin_dir_t dir,nrf_gpio_pin_input_t input,nrf_gpio_pin_pull_t pull,nrf_gpio_pin_drive_t drive,nrf_gpio_pin_sense_t sense)507*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_cfg(
508*150812a8SEvalZero uint32_t pin_number,
509*150812a8SEvalZero nrf_gpio_pin_dir_t dir,
510*150812a8SEvalZero nrf_gpio_pin_input_t input,
511*150812a8SEvalZero nrf_gpio_pin_pull_t pull,
512*150812a8SEvalZero nrf_gpio_pin_drive_t drive,
513*150812a8SEvalZero nrf_gpio_pin_sense_t sense)
514*150812a8SEvalZero {
515*150812a8SEvalZero NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
516*150812a8SEvalZero
517*150812a8SEvalZero reg->PIN_CNF[pin_number] = ((uint32_t)dir << GPIO_PIN_CNF_DIR_Pos)
518*150812a8SEvalZero | ((uint32_t)input << GPIO_PIN_CNF_INPUT_Pos)
519*150812a8SEvalZero | ((uint32_t)pull << GPIO_PIN_CNF_PULL_Pos)
520*150812a8SEvalZero | ((uint32_t)drive << GPIO_PIN_CNF_DRIVE_Pos)
521*150812a8SEvalZero | ((uint32_t)sense << GPIO_PIN_CNF_SENSE_Pos);
522*150812a8SEvalZero }
523*150812a8SEvalZero
524*150812a8SEvalZero
nrf_gpio_cfg_output(uint32_t pin_number)525*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_cfg_output(uint32_t pin_number)
526*150812a8SEvalZero {
527*150812a8SEvalZero nrf_gpio_cfg(
528*150812a8SEvalZero pin_number,
529*150812a8SEvalZero NRF_GPIO_PIN_DIR_OUTPUT,
530*150812a8SEvalZero NRF_GPIO_PIN_INPUT_DISCONNECT,
531*150812a8SEvalZero NRF_GPIO_PIN_NOPULL,
532*150812a8SEvalZero NRF_GPIO_PIN_S0S1,
533*150812a8SEvalZero NRF_GPIO_PIN_NOSENSE);
534*150812a8SEvalZero }
535*150812a8SEvalZero
536*150812a8SEvalZero
nrf_gpio_cfg_input(uint32_t pin_number,nrf_gpio_pin_pull_t pull_config)537*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config)
538*150812a8SEvalZero {
539*150812a8SEvalZero nrf_gpio_cfg(
540*150812a8SEvalZero pin_number,
541*150812a8SEvalZero NRF_GPIO_PIN_DIR_INPUT,
542*150812a8SEvalZero NRF_GPIO_PIN_INPUT_CONNECT,
543*150812a8SEvalZero pull_config,
544*150812a8SEvalZero NRF_GPIO_PIN_S0S1,
545*150812a8SEvalZero NRF_GPIO_PIN_NOSENSE);
546*150812a8SEvalZero }
547*150812a8SEvalZero
548*150812a8SEvalZero
nrf_gpio_cfg_default(uint32_t pin_number)549*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_cfg_default(uint32_t pin_number)
550*150812a8SEvalZero {
551*150812a8SEvalZero nrf_gpio_cfg(
552*150812a8SEvalZero pin_number,
553*150812a8SEvalZero NRF_GPIO_PIN_DIR_INPUT,
554*150812a8SEvalZero NRF_GPIO_PIN_INPUT_DISCONNECT,
555*150812a8SEvalZero NRF_GPIO_PIN_NOPULL,
556*150812a8SEvalZero NRF_GPIO_PIN_S0S1,
557*150812a8SEvalZero NRF_GPIO_PIN_NOSENSE);
558*150812a8SEvalZero }
559*150812a8SEvalZero
560*150812a8SEvalZero
nrf_gpio_cfg_watcher(uint32_t pin_number)561*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_cfg_watcher(uint32_t pin_number)
562*150812a8SEvalZero {
563*150812a8SEvalZero NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
564*150812a8SEvalZero /*lint -e{845} // A zero has been given as right argument to operator '|'" */
565*150812a8SEvalZero uint32_t cnf = reg->PIN_CNF[pin_number] & ~GPIO_PIN_CNF_INPUT_Msk;
566*150812a8SEvalZero
567*150812a8SEvalZero reg->PIN_CNF[pin_number] = cnf | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos);
568*150812a8SEvalZero }
569*150812a8SEvalZero
570*150812a8SEvalZero
nrf_gpio_input_disconnect(uint32_t pin_number)571*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_input_disconnect(uint32_t pin_number)
572*150812a8SEvalZero {
573*150812a8SEvalZero NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
574*150812a8SEvalZero /*lint -e{845} // A zero has been given as right argument to operator '|'" */
575*150812a8SEvalZero uint32_t cnf = reg->PIN_CNF[pin_number] & ~GPIO_PIN_CNF_INPUT_Msk;
576*150812a8SEvalZero
577*150812a8SEvalZero reg->PIN_CNF[pin_number] = cnf | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos);
578*150812a8SEvalZero }
579*150812a8SEvalZero
580*150812a8SEvalZero
nrf_gpio_cfg_sense_input(uint32_t pin_number,nrf_gpio_pin_pull_t pull_config,nrf_gpio_pin_sense_t sense_config)581*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_cfg_sense_input(uint32_t pin_number,
582*150812a8SEvalZero nrf_gpio_pin_pull_t pull_config,
583*150812a8SEvalZero nrf_gpio_pin_sense_t sense_config)
584*150812a8SEvalZero {
585*150812a8SEvalZero nrf_gpio_cfg(
586*150812a8SEvalZero pin_number,
587*150812a8SEvalZero NRF_GPIO_PIN_DIR_INPUT,
588*150812a8SEvalZero NRF_GPIO_PIN_INPUT_CONNECT,
589*150812a8SEvalZero pull_config,
590*150812a8SEvalZero NRF_GPIO_PIN_S0S1,
591*150812a8SEvalZero sense_config);
592*150812a8SEvalZero }
593*150812a8SEvalZero
594*150812a8SEvalZero
nrf_gpio_cfg_sense_set(uint32_t pin_number,nrf_gpio_pin_sense_t sense_config)595*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_cfg_sense_set(uint32_t pin_number, nrf_gpio_pin_sense_t sense_config)
596*150812a8SEvalZero {
597*150812a8SEvalZero NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
598*150812a8SEvalZero
599*150812a8SEvalZero /*lint -e{845} // A zero has been given as right argument to operator '|'" */
600*150812a8SEvalZero reg->PIN_CNF[pin_number] &= ~GPIO_PIN_CNF_SENSE_Msk;
601*150812a8SEvalZero reg->PIN_CNF[pin_number] |= (sense_config << GPIO_PIN_CNF_SENSE_Pos);
602*150812a8SEvalZero }
603*150812a8SEvalZero
604*150812a8SEvalZero
nrf_gpio_pin_dir_set(uint32_t pin_number,nrf_gpio_pin_dir_t direction)605*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_pin_dir_set(uint32_t pin_number, nrf_gpio_pin_dir_t direction)
606*150812a8SEvalZero {
607*150812a8SEvalZero if (direction == NRF_GPIO_PIN_DIR_INPUT)
608*150812a8SEvalZero {
609*150812a8SEvalZero nrf_gpio_cfg(
610*150812a8SEvalZero pin_number,
611*150812a8SEvalZero NRF_GPIO_PIN_DIR_INPUT,
612*150812a8SEvalZero NRF_GPIO_PIN_INPUT_CONNECT,
613*150812a8SEvalZero NRF_GPIO_PIN_NOPULL,
614*150812a8SEvalZero NRF_GPIO_PIN_S0S1,
615*150812a8SEvalZero NRF_GPIO_PIN_NOSENSE);
616*150812a8SEvalZero }
617*150812a8SEvalZero else
618*150812a8SEvalZero {
619*150812a8SEvalZero NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
620*150812a8SEvalZero reg->DIRSET = (1UL << pin_number);
621*150812a8SEvalZero }
622*150812a8SEvalZero }
623*150812a8SEvalZero
624*150812a8SEvalZero
nrf_gpio_pin_set(uint32_t pin_number)625*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_pin_set(uint32_t pin_number)
626*150812a8SEvalZero {
627*150812a8SEvalZero NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
628*150812a8SEvalZero
629*150812a8SEvalZero nrf_gpio_port_out_set(reg, 1UL << pin_number);
630*150812a8SEvalZero }
631*150812a8SEvalZero
632*150812a8SEvalZero
nrf_gpio_pin_clear(uint32_t pin_number)633*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_pin_clear(uint32_t pin_number)
634*150812a8SEvalZero {
635*150812a8SEvalZero NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
636*150812a8SEvalZero
637*150812a8SEvalZero nrf_gpio_port_out_clear(reg, 1UL << pin_number);
638*150812a8SEvalZero }
639*150812a8SEvalZero
640*150812a8SEvalZero
nrf_gpio_pin_toggle(uint32_t pin_number)641*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_pin_toggle(uint32_t pin_number)
642*150812a8SEvalZero {
643*150812a8SEvalZero NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
644*150812a8SEvalZero uint32_t pins_state = reg->OUT;
645*150812a8SEvalZero
646*150812a8SEvalZero reg->OUTSET = (~pins_state & (1UL << pin_number));
647*150812a8SEvalZero reg->OUTCLR = (pins_state & (1UL << pin_number));
648*150812a8SEvalZero }
649*150812a8SEvalZero
650*150812a8SEvalZero
nrf_gpio_pin_write(uint32_t pin_number,uint32_t value)651*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_pin_write(uint32_t pin_number, uint32_t value)
652*150812a8SEvalZero {
653*150812a8SEvalZero if (value == 0)
654*150812a8SEvalZero {
655*150812a8SEvalZero nrf_gpio_pin_clear(pin_number);
656*150812a8SEvalZero }
657*150812a8SEvalZero else
658*150812a8SEvalZero {
659*150812a8SEvalZero nrf_gpio_pin_set(pin_number);
660*150812a8SEvalZero }
661*150812a8SEvalZero }
662*150812a8SEvalZero
663*150812a8SEvalZero
nrf_gpio_pin_read(uint32_t pin_number)664*150812a8SEvalZero __STATIC_INLINE uint32_t nrf_gpio_pin_read(uint32_t pin_number)
665*150812a8SEvalZero {
666*150812a8SEvalZero NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
667*150812a8SEvalZero
668*150812a8SEvalZero return ((nrf_gpio_port_in_read(reg) >> pin_number) & 1UL);
669*150812a8SEvalZero }
670*150812a8SEvalZero
671*150812a8SEvalZero
nrf_gpio_pin_out_read(uint32_t pin_number)672*150812a8SEvalZero __STATIC_INLINE uint32_t nrf_gpio_pin_out_read(uint32_t pin_number)
673*150812a8SEvalZero {
674*150812a8SEvalZero NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
675*150812a8SEvalZero
676*150812a8SEvalZero return ((nrf_gpio_port_out_read(reg) >> pin_number) & 1UL);
677*150812a8SEvalZero }
678*150812a8SEvalZero
679*150812a8SEvalZero
nrf_gpio_pin_sense_get(uint32_t pin_number)680*150812a8SEvalZero __STATIC_INLINE nrf_gpio_pin_sense_t nrf_gpio_pin_sense_get(uint32_t pin_number)
681*150812a8SEvalZero {
682*150812a8SEvalZero NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
683*150812a8SEvalZero
684*150812a8SEvalZero return (nrf_gpio_pin_sense_t)((reg->PIN_CNF[pin_number] &
685*150812a8SEvalZero GPIO_PIN_CNF_SENSE_Msk) >> GPIO_PIN_CNF_SENSE_Pos);
686*150812a8SEvalZero }
687*150812a8SEvalZero
688*150812a8SEvalZero
nrf_gpio_pin_dir_get(uint32_t pin_number)689*150812a8SEvalZero __STATIC_INLINE nrf_gpio_pin_dir_t nrf_gpio_pin_dir_get(uint32_t pin_number)
690*150812a8SEvalZero {
691*150812a8SEvalZero NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
692*150812a8SEvalZero
693*150812a8SEvalZero return (nrf_gpio_pin_dir_t)((reg->PIN_CNF[pin_number] &
694*150812a8SEvalZero GPIO_PIN_CNF_DIR_Msk) >> GPIO_PIN_CNF_DIR_Pos);
695*150812a8SEvalZero }
696*150812a8SEvalZero
697*150812a8SEvalZero
nrf_gpio_pin_pull_get(uint32_t pin_number)698*150812a8SEvalZero __STATIC_INLINE nrf_gpio_pin_pull_t nrf_gpio_pin_pull_get(uint32_t pin_number)
699*150812a8SEvalZero {
700*150812a8SEvalZero NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
701*150812a8SEvalZero
702*150812a8SEvalZero return (nrf_gpio_pin_pull_t)((reg->PIN_CNF[pin_number] &
703*150812a8SEvalZero GPIO_PIN_CNF_PULL_Msk) >> GPIO_PIN_CNF_PULL_Pos);
704*150812a8SEvalZero }
705*150812a8SEvalZero
706*150812a8SEvalZero
nrf_gpio_port_dir_output_set(NRF_GPIO_Type * p_reg,uint32_t out_mask)707*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_port_dir_output_set(NRF_GPIO_Type * p_reg, uint32_t out_mask)
708*150812a8SEvalZero {
709*150812a8SEvalZero p_reg->DIRSET = out_mask;
710*150812a8SEvalZero }
711*150812a8SEvalZero
712*150812a8SEvalZero
nrf_gpio_port_dir_input_set(NRF_GPIO_Type * p_reg,uint32_t in_mask)713*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_port_dir_input_set(NRF_GPIO_Type * p_reg, uint32_t in_mask)
714*150812a8SEvalZero {
715*150812a8SEvalZero p_reg->DIRCLR = in_mask;
716*150812a8SEvalZero }
717*150812a8SEvalZero
718*150812a8SEvalZero
nrf_gpio_port_dir_write(NRF_GPIO_Type * p_reg,uint32_t value)719*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_port_dir_write(NRF_GPIO_Type * p_reg, uint32_t value)
720*150812a8SEvalZero {
721*150812a8SEvalZero p_reg->DIR = value;
722*150812a8SEvalZero }
723*150812a8SEvalZero
724*150812a8SEvalZero
nrf_gpio_port_dir_read(NRF_GPIO_Type const * p_reg)725*150812a8SEvalZero __STATIC_INLINE uint32_t nrf_gpio_port_dir_read(NRF_GPIO_Type const * p_reg)
726*150812a8SEvalZero {
727*150812a8SEvalZero return p_reg->DIR;
728*150812a8SEvalZero }
729*150812a8SEvalZero
730*150812a8SEvalZero
nrf_gpio_port_in_read(NRF_GPIO_Type const * p_reg)731*150812a8SEvalZero __STATIC_INLINE uint32_t nrf_gpio_port_in_read(NRF_GPIO_Type const * p_reg)
732*150812a8SEvalZero {
733*150812a8SEvalZero return p_reg->IN;
734*150812a8SEvalZero }
735*150812a8SEvalZero
736*150812a8SEvalZero
nrf_gpio_port_out_read(NRF_GPIO_Type const * p_reg)737*150812a8SEvalZero __STATIC_INLINE uint32_t nrf_gpio_port_out_read(NRF_GPIO_Type const * p_reg)
738*150812a8SEvalZero {
739*150812a8SEvalZero return p_reg->OUT;
740*150812a8SEvalZero }
741*150812a8SEvalZero
742*150812a8SEvalZero
nrf_gpio_port_out_write(NRF_GPIO_Type * p_reg,uint32_t value)743*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_port_out_write(NRF_GPIO_Type * p_reg, uint32_t value)
744*150812a8SEvalZero {
745*150812a8SEvalZero p_reg->OUT = value;
746*150812a8SEvalZero }
747*150812a8SEvalZero
748*150812a8SEvalZero
nrf_gpio_port_out_set(NRF_GPIO_Type * p_reg,uint32_t set_mask)749*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_port_out_set(NRF_GPIO_Type * p_reg, uint32_t set_mask)
750*150812a8SEvalZero {
751*150812a8SEvalZero p_reg->OUTSET = set_mask;
752*150812a8SEvalZero }
753*150812a8SEvalZero
754*150812a8SEvalZero
nrf_gpio_port_out_clear(NRF_GPIO_Type * p_reg,uint32_t clr_mask)755*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_port_out_clear(NRF_GPIO_Type * p_reg, uint32_t clr_mask)
756*150812a8SEvalZero {
757*150812a8SEvalZero p_reg->OUTCLR = clr_mask;
758*150812a8SEvalZero }
759*150812a8SEvalZero
760*150812a8SEvalZero
nrf_gpio_ports_read(uint32_t start_port,uint32_t length,uint32_t * p_masks)761*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_ports_read(uint32_t start_port, uint32_t length, uint32_t * p_masks)
762*150812a8SEvalZero {
763*150812a8SEvalZero NRF_GPIO_Type * gpio_regs[GPIO_COUNT] = GPIO_REG_LIST;
764*150812a8SEvalZero
765*150812a8SEvalZero NRFX_ASSERT(start_port + length <= GPIO_COUNT);
766*150812a8SEvalZero uint32_t i;
767*150812a8SEvalZero
768*150812a8SEvalZero for (i = start_port; i < (start_port + length); i++)
769*150812a8SEvalZero {
770*150812a8SEvalZero *p_masks = nrf_gpio_port_in_read(gpio_regs[i]);
771*150812a8SEvalZero p_masks++;
772*150812a8SEvalZero }
773*150812a8SEvalZero }
774*150812a8SEvalZero
775*150812a8SEvalZero
776*150812a8SEvalZero #ifdef GPIO_DETECTMODE_DETECTMODE_LDETECT
nrf_gpio_latches_read(uint32_t start_port,uint32_t length,uint32_t * p_masks)777*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_latches_read(uint32_t start_port, uint32_t length, uint32_t * p_masks)
778*150812a8SEvalZero {
779*150812a8SEvalZero NRF_GPIO_Type * gpio_regs[GPIO_COUNT] = GPIO_REG_LIST;
780*150812a8SEvalZero uint32_t i;
781*150812a8SEvalZero
782*150812a8SEvalZero for (i = start_port; i < (start_port + length); i++)
783*150812a8SEvalZero {
784*150812a8SEvalZero *p_masks = gpio_regs[i]->LATCH;
785*150812a8SEvalZero p_masks++;
786*150812a8SEvalZero }
787*150812a8SEvalZero }
788*150812a8SEvalZero
789*150812a8SEvalZero
nrf_gpio_pin_latch_get(uint32_t pin_number)790*150812a8SEvalZero __STATIC_INLINE uint32_t nrf_gpio_pin_latch_get(uint32_t pin_number)
791*150812a8SEvalZero {
792*150812a8SEvalZero NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
793*150812a8SEvalZero
794*150812a8SEvalZero return (reg->LATCH & (1 << pin_number)) ? 1 : 0;
795*150812a8SEvalZero }
796*150812a8SEvalZero
797*150812a8SEvalZero
nrf_gpio_pin_latch_clear(uint32_t pin_number)798*150812a8SEvalZero __STATIC_INLINE void nrf_gpio_pin_latch_clear(uint32_t pin_number)
799*150812a8SEvalZero {
800*150812a8SEvalZero NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
801*150812a8SEvalZero
802*150812a8SEvalZero reg->LATCH = (1 << pin_number);
803*150812a8SEvalZero }
804*150812a8SEvalZero
805*150812a8SEvalZero
806*150812a8SEvalZero #endif
807*150812a8SEvalZero #endif // SUPPRESS_INLINE_IMPLEMENTATION
808*150812a8SEvalZero
809*150812a8SEvalZero /** @} */
810*150812a8SEvalZero
811*150812a8SEvalZero #ifdef __cplusplus
812*150812a8SEvalZero }
813*150812a8SEvalZero #endif
814*150812a8SEvalZero
815*150812a8SEvalZero #endif // NRF_GPIO_H__
816