Michael Galis / nRF51822

Fork of nRF51822 by Nordic Semiconductor

Committer:
vcoubard
Date:
Mon Jan 11 10:29:13 2016 +0000
Revision:
607:e98331f1d6b5
Import nordic sdk from https://github.com/ARMmbed/nrf51-sdk.git#a0faa63aae1f6351ac36cd70f28ce037d6f4ae11

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vcoubard 607:e98331f1d6b5 1 /*
vcoubard 607:e98331f1d6b5 2 * Copyright (c) Nordic Semiconductor ASA
vcoubard 607:e98331f1d6b5 3 * All rights reserved.
vcoubard 607:e98331f1d6b5 4 *
vcoubard 607:e98331f1d6b5 5 * Redistribution and use in source and binary forms, with or without modification,
vcoubard 607:e98331f1d6b5 6 * are permitted provided that the following conditions are met:
vcoubard 607:e98331f1d6b5 7 *
vcoubard 607:e98331f1d6b5 8 * 1. Redistributions of source code must retain the above copyright notice, this
vcoubard 607:e98331f1d6b5 9 * list of conditions and the following disclaimer.
vcoubard 607:e98331f1d6b5 10 *
vcoubard 607:e98331f1d6b5 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this
vcoubard 607:e98331f1d6b5 12 * list of conditions and the following disclaimer in the documentation and/or
vcoubard 607:e98331f1d6b5 13 * other materials provided with the distribution.
vcoubard 607:e98331f1d6b5 14 *
vcoubard 607:e98331f1d6b5 15 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other
vcoubard 607:e98331f1d6b5 16 * contributors to this software may be used to endorse or promote products
vcoubard 607:e98331f1d6b5 17 * derived from this software without specific prior written permission.
vcoubard 607:e98331f1d6b5 18 *
vcoubard 607:e98331f1d6b5 19 *
vcoubard 607:e98331f1d6b5 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
vcoubard 607:e98331f1d6b5 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
vcoubard 607:e98331f1d6b5 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
vcoubard 607:e98331f1d6b5 23 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
vcoubard 607:e98331f1d6b5 24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
vcoubard 607:e98331f1d6b5 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
vcoubard 607:e98331f1d6b5 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
vcoubard 607:e98331f1d6b5 27 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
vcoubard 607:e98331f1d6b5 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
vcoubard 607:e98331f1d6b5 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
vcoubard 607:e98331f1d6b5 30 *
vcoubard 607:e98331f1d6b5 31 */
vcoubard 607:e98331f1d6b5 32 #ifndef NRF_GPIO_H__
vcoubard 607:e98331f1d6b5 33 #define NRF_GPIO_H__
vcoubard 607:e98331f1d6b5 34
vcoubard 607:e98331f1d6b5 35 #include "nrf.h"
vcoubard 607:e98331f1d6b5 36 #include <stdbool.h>
vcoubard 607:e98331f1d6b5 37
vcoubard 607:e98331f1d6b5 38 /**
vcoubard 607:e98331f1d6b5 39 * @defgroup nrf_gpio GPIO abstraction
vcoubard 607:e98331f1d6b5 40 * @{
vcoubard 607:e98331f1d6b5 41 * @ingroup nrf_drivers
vcoubard 607:e98331f1d6b5 42 * @brief GPIO pin abstraction and port abstraction for reading and writing byte-wise to GPIO ports.
vcoubard 607:e98331f1d6b5 43 *
vcoubard 607:e98331f1d6b5 44 * Here, the GPIO ports are defined as follows:
vcoubard 607:e98331f1d6b5 45 * - Port 0 -> pin 0-7
vcoubard 607:e98331f1d6b5 46 * - Port 1 -> pin 8-15
vcoubard 607:e98331f1d6b5 47 * - Port 2 -> pin 16-23
vcoubard 607:e98331f1d6b5 48 * - Port 3 -> pin 24-31
vcoubard 607:e98331f1d6b5 49 */
vcoubard 607:e98331f1d6b5 50
vcoubard 607:e98331f1d6b5 51 #define NUMBER_OF_PINS 32
vcoubard 607:e98331f1d6b5 52
vcoubard 607:e98331f1d6b5 53 /**
vcoubard 607:e98331f1d6b5 54 * @brief Enumerator used for selecting between port 0 - 3.
vcoubard 607:e98331f1d6b5 55 */
vcoubard 607:e98331f1d6b5 56 typedef enum
vcoubard 607:e98331f1d6b5 57 {
vcoubard 607:e98331f1d6b5 58 NRF_GPIO_PORT_SELECT_PORT0 = 0, ///< Port 0 (GPIO pin 0-7)
vcoubard 607:e98331f1d6b5 59 NRF_GPIO_PORT_SELECT_PORT1, ///< Port 1 (GPIO pin 8-15)
vcoubard 607:e98331f1d6b5 60 NRF_GPIO_PORT_SELECT_PORT2, ///< Port 2 (GPIO pin 16-23)
vcoubard 607:e98331f1d6b5 61 NRF_GPIO_PORT_SELECT_PORT3, ///< Port 3 (GPIO pin 24-31)
vcoubard 607:e98331f1d6b5 62 } nrf_gpio_port_select_t;
vcoubard 607:e98331f1d6b5 63
vcoubard 607:e98331f1d6b5 64 /**
vcoubard 607:e98331f1d6b5 65 * @brief Enumerator used for setting the direction of a GPIO port.
vcoubard 607:e98331f1d6b5 66 */
vcoubard 607:e98331f1d6b5 67 typedef enum
vcoubard 607:e98331f1d6b5 68 {
vcoubard 607:e98331f1d6b5 69 NRF_GPIO_PORT_DIR_OUTPUT, ///< Output
vcoubard 607:e98331f1d6b5 70 NRF_GPIO_PORT_DIR_INPUT ///< Input
vcoubard 607:e98331f1d6b5 71 } nrf_gpio_port_dir_t;
vcoubard 607:e98331f1d6b5 72
vcoubard 607:e98331f1d6b5 73 /**
vcoubard 607:e98331f1d6b5 74 * @brief Pin direction definitions.
vcoubard 607:e98331f1d6b5 75 */
vcoubard 607:e98331f1d6b5 76 typedef enum
vcoubard 607:e98331f1d6b5 77 {
vcoubard 607:e98331f1d6b5 78 NRF_GPIO_PIN_DIR_INPUT = GPIO_PIN_CNF_DIR_Input, ///< Input
vcoubard 607:e98331f1d6b5 79 NRF_GPIO_PIN_DIR_OUTPUT = GPIO_PIN_CNF_DIR_Output ///< Output
vcoubard 607:e98331f1d6b5 80 } nrf_gpio_pin_dir_t;
vcoubard 607:e98331f1d6b5 81
vcoubard 607:e98331f1d6b5 82 /**
vcoubard 607:e98331f1d6b5 83 * @brief Connection of input buffer
vcoubard 607:e98331f1d6b5 84 */
vcoubard 607:e98331f1d6b5 85 typedef enum
vcoubard 607:e98331f1d6b5 86 {
vcoubard 607:e98331f1d6b5 87 NRF_GPIO_PIN_INPUT_CONNECT = GPIO_PIN_CNF_INPUT_Connect, ///< Connect input buffer
vcoubard 607:e98331f1d6b5 88 NRF_GPIO_PIN_INPUT_DISCONNECT = GPIO_PIN_CNF_INPUT_Disconnect ///< Disconnect input buffer
vcoubard 607:e98331f1d6b5 89 } nrf_gpio_pin_input_t;
vcoubard 607:e98331f1d6b5 90
vcoubard 607:e98331f1d6b5 91 /**
vcoubard 607:e98331f1d6b5 92 * @brief Enumerator used for selecting the pin to be pulled down or up at the time of pin configuration
vcoubard 607:e98331f1d6b5 93 */
vcoubard 607:e98331f1d6b5 94 typedef enum
vcoubard 607:e98331f1d6b5 95 {
vcoubard 607:e98331f1d6b5 96 NRF_GPIO_PIN_NOPULL = GPIO_PIN_CNF_PULL_Disabled, ///< Pin pullup resistor disabled
vcoubard 607:e98331f1d6b5 97 NRF_GPIO_PIN_PULLDOWN = GPIO_PIN_CNF_PULL_Pulldown, ///< Pin pulldown resistor enabled
vcoubard 607:e98331f1d6b5 98 NRF_GPIO_PIN_PULLUP = GPIO_PIN_CNF_PULL_Pullup, ///< Pin pullup resistor enabled
vcoubard 607:e98331f1d6b5 99 } nrf_gpio_pin_pull_t;
vcoubard 607:e98331f1d6b5 100
vcoubard 607:e98331f1d6b5 101 /**
vcoubard 607:e98331f1d6b5 102 * @brief Enumerator used for selecting output drive mode
vcoubard 607:e98331f1d6b5 103 */
vcoubard 607:e98331f1d6b5 104 typedef enum
vcoubard 607:e98331f1d6b5 105 {
vcoubard 607:e98331f1d6b5 106 NRF_GPIO_PIN_S0S1 = GPIO_PIN_CNF_DRIVE_S0S1, ///< !< Standard '0', standard '1'
vcoubard 607:e98331f1d6b5 107 NRF_GPIO_PIN_H0S1 = GPIO_PIN_CNF_DRIVE_H0S1, ///< !< High drive '0', standard '1'
vcoubard 607:e98331f1d6b5 108 NRF_GPIO_PIN_S0H1 = GPIO_PIN_CNF_DRIVE_S0H1, ///< !< Standard '0', high drive '1'
vcoubard 607:e98331f1d6b5 109 NRF_GPIO_PIN_H0H1 = GPIO_PIN_CNF_DRIVE_H0H1, ///< !< High drive '0', high 'drive '1''
vcoubard 607:e98331f1d6b5 110 NRF_GPIO_PIN_D0S1 = GPIO_PIN_CNF_DRIVE_D0S1, ///< !< Disconnect '0' standard '1'
vcoubard 607:e98331f1d6b5 111 NRF_GPIO_PIN_D0H1 = GPIO_PIN_CNF_DRIVE_D0H1, ///< !< Disconnect '0', high drive '1'
vcoubard 607:e98331f1d6b5 112 NRF_GPIO_PIN_S0D1 = GPIO_PIN_CNF_DRIVE_S0D1, ///< !< Standard '0'. disconnect '1'
vcoubard 607:e98331f1d6b5 113 NRF_GPIO_PIN_H0D1 = GPIO_PIN_CNF_DRIVE_H0D1, ///< !< High drive '0', disconnect '1'
vcoubard 607:e98331f1d6b5 114 } nrf_gpio_pin_drive_t;
vcoubard 607:e98331f1d6b5 115
vcoubard 607:e98331f1d6b5 116 /**
vcoubard 607:e98331f1d6b5 117 * @brief Enumerator used for selecting the pin to sense high or low level on the pin input.
vcoubard 607:e98331f1d6b5 118 */
vcoubard 607:e98331f1d6b5 119 typedef enum
vcoubard 607:e98331f1d6b5 120 {
vcoubard 607:e98331f1d6b5 121 NRF_GPIO_PIN_NOSENSE = GPIO_PIN_CNF_SENSE_Disabled, ///< Pin sense level disabled.
vcoubard 607:e98331f1d6b5 122 NRF_GPIO_PIN_SENSE_LOW = GPIO_PIN_CNF_SENSE_Low, ///< Pin sense low level.
vcoubard 607:e98331f1d6b5 123 NRF_GPIO_PIN_SENSE_HIGH = GPIO_PIN_CNF_SENSE_High, ///< Pin sense high level.
vcoubard 607:e98331f1d6b5 124 } nrf_gpio_pin_sense_t;
vcoubard 607:e98331f1d6b5 125
vcoubard 607:e98331f1d6b5 126
vcoubard 607:e98331f1d6b5 127 /**
vcoubard 607:e98331f1d6b5 128 * @brief Function for configuring the GPIO pin range as outputs with normal drive strength.
vcoubard 607:e98331f1d6b5 129 * This function can be used to configure pin range as simple output with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
vcoubard 607:e98331f1d6b5 130 *
vcoubard 607:e98331f1d6b5 131 * @param pin_range_start specifies the start number (inclusive) in the range of pin numbers to be configured (allowed values 0-30)
vcoubard 607:e98331f1d6b5 132 *
vcoubard 607:e98331f1d6b5 133 * @param pin_range_end specifies the end number (inclusive) in the range of pin numbers to be configured (allowed values 0-30)
vcoubard 607:e98331f1d6b5 134 *
vcoubard 607:e98331f1d6b5 135 * @note For configuring only one pin as output use @ref nrf_gpio_cfg_output
vcoubard 607:e98331f1d6b5 136 * Sense capability on the pin is disabled, and input is disconnected from the buffer as the pins are configured as output.
vcoubard 607:e98331f1d6b5 137 */
vcoubard 607:e98331f1d6b5 138 __STATIC_INLINE void nrf_gpio_range_cfg_output(uint32_t pin_range_start, uint32_t pin_range_end);
vcoubard 607:e98331f1d6b5 139
vcoubard 607:e98331f1d6b5 140 /**
vcoubard 607:e98331f1d6b5 141 * @brief Function for configuring the GPIO pin range as inputs with given initial value set, hiding inner details.
vcoubard 607:e98331f1d6b5 142 * This function can be used to configure pin range as simple input.
vcoubard 607:e98331f1d6b5 143 *
vcoubard 607:e98331f1d6b5 144 * @param pin_range_start specifies the start number (inclusive) in the range of pin numbers to be configured (allowed values 0-30)
vcoubard 607:e98331f1d6b5 145 *
vcoubard 607:e98331f1d6b5 146 * @param pin_range_end specifies the end number (inclusive) in the range of pin numbers to be configured (allowed values 0-30)
vcoubard 607:e98331f1d6b5 147 *
vcoubard 607:e98331f1d6b5 148 * @param pull_config State of the pin range pull resistor (no pull, pulled down or pulled high)
vcoubard 607:e98331f1d6b5 149 *
vcoubard 607:e98331f1d6b5 150 * @note For configuring only one pin as input use @ref nrf_gpio_cfg_input
vcoubard 607:e98331f1d6b5 151 * Sense capability on the pin is disabled, and input is connected to buffer so that the GPIO->IN register is readable
vcoubard 607:e98331f1d6b5 152 */
vcoubard 607:e98331f1d6b5 153 __STATIC_INLINE void nrf_gpio_range_cfg_input(uint32_t pin_range_start, uint32_t pin_range_end, nrf_gpio_pin_pull_t pull_config);
vcoubard 607:e98331f1d6b5 154
vcoubard 607:e98331f1d6b5 155 /**
vcoubard 607:e98331f1d6b5 156 * @brief Pin configuration function
vcoubard 607:e98331f1d6b5 157 *
vcoubard 607:e98331f1d6b5 158 * The main pin configuration function.
vcoubard 607:e98331f1d6b5 159 * This function allows to set any aspect in PIN_CNF register.
vcoubard 607:e98331f1d6b5 160 * @param pin_number Specifies the pin number (allowed values 0-31).
vcoubard 607:e98331f1d6b5 161 * @param dir Pin direction
vcoubard 607:e98331f1d6b5 162 * @param input Connect or disconnect input buffer
vcoubard 607:e98331f1d6b5 163 * @param pull Pull configuration
vcoubard 607:e98331f1d6b5 164 * @param drive Drive configuration
vcoubard 607:e98331f1d6b5 165 * @param sense Pin sensing mechanism
vcoubard 607:e98331f1d6b5 166 */
vcoubard 607:e98331f1d6b5 167 __STATIC_INLINE void nrf_gpio_cfg(
vcoubard 607:e98331f1d6b5 168 uint32_t pin_number,
vcoubard 607:e98331f1d6b5 169 nrf_gpio_pin_dir_t dir,
vcoubard 607:e98331f1d6b5 170 nrf_gpio_pin_input_t input,
vcoubard 607:e98331f1d6b5 171 nrf_gpio_pin_pull_t pull,
vcoubard 607:e98331f1d6b5 172 nrf_gpio_pin_drive_t drive,
vcoubard 607:e98331f1d6b5 173 nrf_gpio_pin_sense_t sense);
vcoubard 607:e98331f1d6b5 174
vcoubard 607:e98331f1d6b5 175 /**
vcoubard 607:e98331f1d6b5 176 * @brief Function for configuring the given GPIO pin number as output with given initial value set, hiding inner details.
vcoubard 607:e98331f1d6b5 177 * This function can be used to configure pin range as simple input with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
vcoubard 607:e98331f1d6b5 178 *
vcoubard 607:e98331f1d6b5 179 * @param pin_number specifies the pin number (allowed values 0-31)
vcoubard 607:e98331f1d6b5 180 *
vcoubard 607:e98331f1d6b5 181 * @note Sense capability on the pin is disabled, and input is disconnected from the buffer as the pins are configured as output.
vcoubard 607:e98331f1d6b5 182 */
vcoubard 607:e98331f1d6b5 183 __STATIC_INLINE void nrf_gpio_cfg_output(uint32_t pin_number);
vcoubard 607:e98331f1d6b5 184
vcoubard 607:e98331f1d6b5 185 /**
vcoubard 607:e98331f1d6b5 186 * @brief Function for configuring the given GPIO pin number as input with given initial value set, hiding inner details.
vcoubard 607:e98331f1d6b5 187 * This function can be used to configure pin range as simple input with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
vcoubard 607:e98331f1d6b5 188 *
vcoubard 607:e98331f1d6b5 189 * @param pin_number Specifies the pin number (allowed values 0-30).
vcoubard 607:e98331f1d6b5 190 * @param pull_config State of the pin range pull resistor (no pull, pulled down or pulled high).
vcoubard 607:e98331f1d6b5 191 *
vcoubard 607:e98331f1d6b5 192 * @note Sense capability on the pin is disabled, and input is connected to buffer so that the GPIO->IN register is readable
vcoubard 607:e98331f1d6b5 193 */
vcoubard 607:e98331f1d6b5 194 __STATIC_INLINE void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config);
vcoubard 607:e98331f1d6b5 195
vcoubard 607:e98331f1d6b5 196 /**
vcoubard 607:e98331f1d6b5 197 * @brief Function for reseting pin configuration to its default state.
vcoubard 607:e98331f1d6b5 198 *
vcoubard 607:e98331f1d6b5 199 * @param pin_number Specifies the pin number (allowed values 0-31).
vcoubard 607:e98331f1d6b5 200 */
vcoubard 607:e98331f1d6b5 201 __STATIC_INLINE void nrf_gpio_cfg_default(uint32_t pin_number);
vcoubard 607:e98331f1d6b5 202
vcoubard 607:e98331f1d6b5 203 /**
vcoubard 607:e98331f1d6b5 204 * @brief Function for configuring the given GPIO pin number as a watcher. Only input is connected.
vcoubard 607:e98331f1d6b5 205 *
vcoubard 607:e98331f1d6b5 206 * @param pin_number Specifies the pin number (allowed values 0-31).
vcoubard 607:e98331f1d6b5 207 *
vcoubard 607:e98331f1d6b5 208 */
vcoubard 607:e98331f1d6b5 209 __STATIC_INLINE void nrf_gpio_cfg_watcher(uint32_t pin_number);
vcoubard 607:e98331f1d6b5 210
vcoubard 607:e98331f1d6b5 211 /**
vcoubard 607:e98331f1d6b5 212 * @brief Function for disconnecting input for the given GPIO.
vcoubard 607:e98331f1d6b5 213 *
vcoubard 607:e98331f1d6b5 214 * @param pin_number Specifies the pin number (allowed values 0-31).
vcoubard 607:e98331f1d6b5 215 *
vcoubard 607:e98331f1d6b5 216 */
vcoubard 607:e98331f1d6b5 217 __STATIC_INLINE void nrf_gpio_input_disconnect(uint32_t pin_number);
vcoubard 607:e98331f1d6b5 218
vcoubard 607:e98331f1d6b5 219 /**
vcoubard 607:e98331f1d6b5 220 * @brief Function for configuring the given GPIO pin number as input with given initial value set, hiding inner details.
vcoubard 607:e98331f1d6b5 221 * This function can be used to configure pin range as simple input with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
vcoubard 607:e98331f1d6b5 222 * Sense capability on the pin is configurable, and input is connected to buffer so that the GPIO->IN register is readable.
vcoubard 607:e98331f1d6b5 223 *
vcoubard 607:e98331f1d6b5 224 * @param pin_number Specifies the pin number (allowed values 0-30).
vcoubard 607:e98331f1d6b5 225 * @param pull_config State of the pin pull resistor (no pull, pulled down or pulled high).
vcoubard 607:e98331f1d6b5 226 * @param sense_config Sense level of the pin (no sense, sense low or sense high).
vcoubard 607:e98331f1d6b5 227 */
vcoubard 607:e98331f1d6b5 228 __STATIC_INLINE void nrf_gpio_cfg_sense_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config, nrf_gpio_pin_sense_t sense_config);
vcoubard 607:e98331f1d6b5 229
vcoubard 607:e98331f1d6b5 230 /**
vcoubard 607:e98331f1d6b5 231 * @brief Function for configuring sense level for the given GPIO.
vcoubard 607:e98331f1d6b5 232 *
vcoubard 607:e98331f1d6b5 233 * @param pin_number Specifies the pin number of gpio pin numbers to be configured (allowed values 0-30).
vcoubard 607:e98331f1d6b5 234 * @param sense_config Sense configuration.
vcoubard 607:e98331f1d6b5 235 *
vcoubard 607:e98331f1d6b5 236 */
vcoubard 607:e98331f1d6b5 237 __STATIC_INLINE void nrf_gpio_cfg_sense_set(uint32_t pin_number, nrf_gpio_pin_sense_t sense_config);
vcoubard 607:e98331f1d6b5 238
vcoubard 607:e98331f1d6b5 239 /**
vcoubard 607:e98331f1d6b5 240 * @brief Function for setting the direction for a GPIO pin.
vcoubard 607:e98331f1d6b5 241 *
vcoubard 607:e98331f1d6b5 242 * @param pin_number specifies the pin number [0:31] for which to
vcoubard 607:e98331f1d6b5 243 * set the direction.
vcoubard 607:e98331f1d6b5 244 *
vcoubard 607:e98331f1d6b5 245 * @param direction specifies the direction
vcoubard 607:e98331f1d6b5 246 */
vcoubard 607:e98331f1d6b5 247 __STATIC_INLINE void nrf_gpio_pin_dir_set(uint32_t pin_number, nrf_gpio_pin_dir_t direction);
vcoubard 607:e98331f1d6b5 248
vcoubard 607:e98331f1d6b5 249 /**
vcoubard 607:e98331f1d6b5 250 * @brief Function for setting a GPIO pin.
vcoubard 607:e98331f1d6b5 251 *
vcoubard 607:e98331f1d6b5 252 * Note that the pin must be configured as an output for this
vcoubard 607:e98331f1d6b5 253 * function to have any effect.
vcoubard 607:e98331f1d6b5 254 *
vcoubard 607:e98331f1d6b5 255 * @param pin_number specifies the pin number [0:31] to
vcoubard 607:e98331f1d6b5 256 * set.
vcoubard 607:e98331f1d6b5 257 */
vcoubard 607:e98331f1d6b5 258 __STATIC_INLINE void nrf_gpio_pin_set(uint32_t pin_number);
vcoubard 607:e98331f1d6b5 259
vcoubard 607:e98331f1d6b5 260 /**
vcoubard 607:e98331f1d6b5 261 * @brief Function for setting GPIO pins.
vcoubard 607:e98331f1d6b5 262 *
vcoubard 607:e98331f1d6b5 263 * Note that pins must be configured as an output for this
vcoubard 607:e98331f1d6b5 264 * function to have any effect.
vcoubard 607:e98331f1d6b5 265 *
vcoubard 607:e98331f1d6b5 266 * @param pin_mask Specifies the pins to set.
vcoubard 607:e98331f1d6b5 267 * set.
vcoubard 607:e98331f1d6b5 268 */
vcoubard 607:e98331f1d6b5 269 __STATIC_INLINE void nrf_gpio_pins_set(uint32_t pin_mask);
vcoubard 607:e98331f1d6b5 270
vcoubard 607:e98331f1d6b5 271 /**
vcoubard 607:e98331f1d6b5 272 * @brief Function for clearing a GPIO pin.
vcoubard 607:e98331f1d6b5 273 *
vcoubard 607:e98331f1d6b5 274 * Note that the pin must be configured as an output for this
vcoubard 607:e98331f1d6b5 275 * function to have any effect.
vcoubard 607:e98331f1d6b5 276 *
vcoubard 607:e98331f1d6b5 277 * @param pin_number specifies the pin number [0:31] to
vcoubard 607:e98331f1d6b5 278 * clear.
vcoubard 607:e98331f1d6b5 279 */
vcoubard 607:e98331f1d6b5 280 __STATIC_INLINE void nrf_gpio_pin_clear(uint32_t pin_number);
vcoubard 607:e98331f1d6b5 281
vcoubard 607:e98331f1d6b5 282 /**
vcoubard 607:e98331f1d6b5 283 * @brief Function for clearing GPIO pins.
vcoubard 607:e98331f1d6b5 284 *
vcoubard 607:e98331f1d6b5 285 * Note that pins must be configured as an output for this
vcoubard 607:e98331f1d6b5 286 * function to have any effect.
vcoubard 607:e98331f1d6b5 287 *
vcoubard 607:e98331f1d6b5 288 * @param pin_mask Specifies the pins to clear.
vcoubard 607:e98331f1d6b5 289 * set.
vcoubard 607:e98331f1d6b5 290 */
vcoubard 607:e98331f1d6b5 291 __STATIC_INLINE void nrf_gpio_pins_clear(uint32_t pin_mask);
vcoubard 607:e98331f1d6b5 292
vcoubard 607:e98331f1d6b5 293 /**
vcoubard 607:e98331f1d6b5 294 * @brief Function for toggling a GPIO pin.
vcoubard 607:e98331f1d6b5 295 *
vcoubard 607:e98331f1d6b5 296 * Note that the pin must be configured as an output for this
vcoubard 607:e98331f1d6b5 297 * function to have any effect.
vcoubard 607:e98331f1d6b5 298 *
vcoubard 607:e98331f1d6b5 299 * @param pin_number specifies the pin number [0:31] to
vcoubard 607:e98331f1d6b5 300 * toggle.
vcoubard 607:e98331f1d6b5 301 */
vcoubard 607:e98331f1d6b5 302 __STATIC_INLINE void nrf_gpio_pin_toggle(uint32_t pin_number);
vcoubard 607:e98331f1d6b5 303
vcoubard 607:e98331f1d6b5 304 /**
vcoubard 607:e98331f1d6b5 305 * @brief Function for writing a value to a GPIO pin.
vcoubard 607:e98331f1d6b5 306 *
vcoubard 607:e98331f1d6b5 307 * Note that the pin must be configured as an output for this
vcoubard 607:e98331f1d6b5 308 * function to have any effect.
vcoubard 607:e98331f1d6b5 309 *
vcoubard 607:e98331f1d6b5 310 * @param pin_number specifies the pin number [0:31] to
vcoubard 607:e98331f1d6b5 311 * write.
vcoubard 607:e98331f1d6b5 312 *
vcoubard 607:e98331f1d6b5 313 * @param value specifies the value to be written to the pin.
vcoubard 607:e98331f1d6b5 314 * @arg 0 clears the pin
vcoubard 607:e98331f1d6b5 315 * @arg >=1 sets the pin.
vcoubard 607:e98331f1d6b5 316 */
vcoubard 607:e98331f1d6b5 317 __STATIC_INLINE void nrf_gpio_pin_write(uint32_t pin_number, uint32_t value);
vcoubard 607:e98331f1d6b5 318
vcoubard 607:e98331f1d6b5 319 /**
vcoubard 607:e98331f1d6b5 320 * @brief Function for reading the input level of a GPIO pin.
vcoubard 607:e98331f1d6b5 321 *
vcoubard 607:e98331f1d6b5 322 * Note that the pin must have input connected for the value
vcoubard 607:e98331f1d6b5 323 * returned from this function to be valid.
vcoubard 607:e98331f1d6b5 324 *
vcoubard 607:e98331f1d6b5 325 * @param pin_number specifies the pin number [0:31] to
vcoubard 607:e98331f1d6b5 326 * read.
vcoubard 607:e98331f1d6b5 327 *
vcoubard 607:e98331f1d6b5 328 * @return
vcoubard 607:e98331f1d6b5 329 * @retval 0 if the pin input level is low.
vcoubard 607:e98331f1d6b5 330 * @retval 1 if the pin input level is high.
vcoubard 607:e98331f1d6b5 331 * @retval > 1 should never occur.
vcoubard 607:e98331f1d6b5 332 */
vcoubard 607:e98331f1d6b5 333 __STATIC_INLINE uint32_t nrf_gpio_pin_read(uint32_t pin_number);
vcoubard 607:e98331f1d6b5 334
vcoubard 607:e98331f1d6b5 335 /**
vcoubard 607:e98331f1d6b5 336 * @brief Function for reading the input level of all GPIO pins.
vcoubard 607:e98331f1d6b5 337 *
vcoubard 607:e98331f1d6b5 338 * Note that the pin must have input connected for the value
vcoubard 607:e98331f1d6b5 339 * returned from this function to be valid.
vcoubard 607:e98331f1d6b5 340 *
vcoubard 607:e98331f1d6b5 341 * @retval Status of input of all pins
vcoubard 607:e98331f1d6b5 342 */
vcoubard 607:e98331f1d6b5 343 __STATIC_INLINE uint32_t nrf_gpio_pins_read(void);
vcoubard 607:e98331f1d6b5 344
vcoubard 607:e98331f1d6b5 345 /**
vcoubard 607:e98331f1d6b5 346 * @brief Function for reading the sense configuration of a GPIO pin.
vcoubard 607:e98331f1d6b5 347 *
vcoubard 607:e98331f1d6b5 348 * @param pin_number specifies the pin number [0:31] to
vcoubard 607:e98331f1d6b5 349 * read.
vcoubard 607:e98331f1d6b5 350 *
vcoubard 607:e98331f1d6b5 351 * @retval Sense configuration
vcoubard 607:e98331f1d6b5 352 */
vcoubard 607:e98331f1d6b5 353 __STATIC_INLINE nrf_gpio_pin_sense_t nrf_gpio_pin_sense_get(uint32_t pin_number);
vcoubard 607:e98331f1d6b5 354
vcoubard 607:e98331f1d6b5 355 /**
vcoubard 607:e98331f1d6b5 356 * @brief Generic function for writing a single byte of a 32 bit word at a given
vcoubard 607:e98331f1d6b5 357 * address.
vcoubard 607:e98331f1d6b5 358 *
vcoubard 607:e98331f1d6b5 359 * This function should not be called from outside the nrf_gpio
vcoubard 607:e98331f1d6b5 360 * abstraction layer.
vcoubard 607:e98331f1d6b5 361 *
vcoubard 607:e98331f1d6b5 362 * @param word_address is the address of the word to be written.
vcoubard 607:e98331f1d6b5 363 *
vcoubard 607:e98331f1d6b5 364 * @param byte_no is the word byte number (0-3) to be written.
vcoubard 607:e98331f1d6b5 365 *
vcoubard 607:e98331f1d6b5 366 * @param value is the value to be written to byte "byte_no" of word
vcoubard 607:e98331f1d6b5 367 * at address "word_address"
vcoubard 607:e98331f1d6b5 368 */
vcoubard 607:e98331f1d6b5 369 __STATIC_INLINE void nrf_gpio_word_byte_write(volatile uint32_t * word_address, uint8_t byte_no, uint8_t value);
vcoubard 607:e98331f1d6b5 370
vcoubard 607:e98331f1d6b5 371 /**
vcoubard 607:e98331f1d6b5 372 * @brief Generic function for reading a single byte of a 32 bit word at a given
vcoubard 607:e98331f1d6b5 373 * address.
vcoubard 607:e98331f1d6b5 374 *
vcoubard 607:e98331f1d6b5 375 * This function should not be called from outside the nrf_gpio
vcoubard 607:e98331f1d6b5 376 * abstraction layer.
vcoubard 607:e98331f1d6b5 377 *
vcoubard 607:e98331f1d6b5 378 * @param word_address is the address of the word to be read.
vcoubard 607:e98331f1d6b5 379 *
vcoubard 607:e98331f1d6b5 380 * @param byte_no is the byte number (0-3) of the word to be read.
vcoubard 607:e98331f1d6b5 381 *
vcoubard 607:e98331f1d6b5 382 * @return byte "byte_no" of word at address "word_address".
vcoubard 607:e98331f1d6b5 383 */
vcoubard 607:e98331f1d6b5 384 __STATIC_INLINE uint8_t nrf_gpio_word_byte_read(const volatile uint32_t* word_address, uint8_t byte_no);
vcoubard 607:e98331f1d6b5 385
vcoubard 607:e98331f1d6b5 386 /**
vcoubard 607:e98331f1d6b5 387 * @brief Function for setting the direction of a port.
vcoubard 607:e98331f1d6b5 388 *
vcoubard 607:e98331f1d6b5 389 * @param port is the port for which to set the direction.
vcoubard 607:e98331f1d6b5 390 *
vcoubard 607:e98331f1d6b5 391 * @param dir direction to be set for this port.
vcoubard 607:e98331f1d6b5 392 */
vcoubard 607:e98331f1d6b5 393 __STATIC_INLINE void nrf_gpio_port_dir_set(nrf_gpio_port_select_t port, nrf_gpio_port_dir_t dir);
vcoubard 607:e98331f1d6b5 394
vcoubard 607:e98331f1d6b5 395 /**
vcoubard 607:e98331f1d6b5 396 * @brief Function for reading a GPIO port.
vcoubard 607:e98331f1d6b5 397 *
vcoubard 607:e98331f1d6b5 398 * @param port is the port to read.
vcoubard 607:e98331f1d6b5 399 *
vcoubard 607:e98331f1d6b5 400 * @return the input value on this port.
vcoubard 607:e98331f1d6b5 401 */
vcoubard 607:e98331f1d6b5 402 __STATIC_INLINE uint8_t nrf_gpio_port_read(nrf_gpio_port_select_t port);
vcoubard 607:e98331f1d6b5 403
vcoubard 607:e98331f1d6b5 404 /**
vcoubard 607:e98331f1d6b5 405 * @brief Function for writing to a GPIO port.
vcoubard 607:e98331f1d6b5 406 *
vcoubard 607:e98331f1d6b5 407 * @param port is the port to write.
vcoubard 607:e98331f1d6b5 408 *
vcoubard 607:e98331f1d6b5 409 * @param value is the value to write to this port.
vcoubard 607:e98331f1d6b5 410 *
vcoubard 607:e98331f1d6b5 411 * @sa nrf_gpio_port_dir_set()
vcoubard 607:e98331f1d6b5 412 */
vcoubard 607:e98331f1d6b5 413 __STATIC_INLINE void nrf_gpio_port_write(nrf_gpio_port_select_t port, uint8_t value);
vcoubard 607:e98331f1d6b5 414
vcoubard 607:e98331f1d6b5 415 /**
vcoubard 607:e98331f1d6b5 416 * @brief Function for setting individual pins on GPIO port.
vcoubard 607:e98331f1d6b5 417 *
vcoubard 607:e98331f1d6b5 418 * @param port is the port for which to set the pins.
vcoubard 607:e98331f1d6b5 419 *
vcoubard 607:e98331f1d6b5 420 * @param set_mask is a mask specifying which pins to set. A bit
vcoubard 607:e98331f1d6b5 421 * set to 1 indicates that the corresponding port pin shall be
vcoubard 607:e98331f1d6b5 422 * set.
vcoubard 607:e98331f1d6b5 423 *
vcoubard 607:e98331f1d6b5 424 * @sa nrf_gpio_port_dir_set()
vcoubard 607:e98331f1d6b5 425 */
vcoubard 607:e98331f1d6b5 426 __STATIC_INLINE void nrf_gpio_port_set(nrf_gpio_port_select_t port, uint8_t set_mask);
vcoubard 607:e98331f1d6b5 427
vcoubard 607:e98331f1d6b5 428 /**
vcoubard 607:e98331f1d6b5 429 * @brief Function for clearing individual pins on GPIO port.
vcoubard 607:e98331f1d6b5 430 *
vcoubard 607:e98331f1d6b5 431 * @param port is the port for which to clear the pins.
vcoubard 607:e98331f1d6b5 432 *
vcoubard 607:e98331f1d6b5 433 * @param clr_mask is a mask specifying which pins to clear. A bit
vcoubard 607:e98331f1d6b5 434 * set to 1 indicates that the corresponding port pin shall be
vcoubard 607:e98331f1d6b5 435 * cleared.
vcoubard 607:e98331f1d6b5 436 *
vcoubard 607:e98331f1d6b5 437 * @sa nrf_gpio_port_dir_set()
vcoubard 607:e98331f1d6b5 438 */
vcoubard 607:e98331f1d6b5 439 __STATIC_INLINE void nrf_gpio_port_clear(nrf_gpio_port_select_t port, uint8_t clr_mask);
vcoubard 607:e98331f1d6b5 440
vcoubard 607:e98331f1d6b5 441 #ifndef SUPPRESS_INLINE_IMPLEMENTATION
vcoubard 607:e98331f1d6b5 442 __STATIC_INLINE void nrf_gpio_range_cfg_output(uint32_t pin_range_start, uint32_t pin_range_end)
vcoubard 607:e98331f1d6b5 443 {
vcoubard 607:e98331f1d6b5 444 /*lint -e{845} // A zero has been given as right argument to operator '|'" */
vcoubard 607:e98331f1d6b5 445 for (; pin_range_start <= pin_range_end; pin_range_start++)
vcoubard 607:e98331f1d6b5 446 {
vcoubard 607:e98331f1d6b5 447 nrf_gpio_cfg_output(pin_range_start);
vcoubard 607:e98331f1d6b5 448 }
vcoubard 607:e98331f1d6b5 449 }
vcoubard 607:e98331f1d6b5 450
vcoubard 607:e98331f1d6b5 451 __STATIC_INLINE void nrf_gpio_range_cfg_input(uint32_t pin_range_start, uint32_t pin_range_end, nrf_gpio_pin_pull_t pull_config)
vcoubard 607:e98331f1d6b5 452 {
vcoubard 607:e98331f1d6b5 453 /*lint -e{845} // A zero has been given as right argument to operator '|'" */
vcoubard 607:e98331f1d6b5 454 for (; pin_range_start <= pin_range_end; pin_range_start++)
vcoubard 607:e98331f1d6b5 455 {
vcoubard 607:e98331f1d6b5 456 nrf_gpio_cfg_input(pin_range_start, pull_config);
vcoubard 607:e98331f1d6b5 457 }
vcoubard 607:e98331f1d6b5 458 }
vcoubard 607:e98331f1d6b5 459
vcoubard 607:e98331f1d6b5 460 __STATIC_INLINE void nrf_gpio_cfg(
vcoubard 607:e98331f1d6b5 461 uint32_t pin_number,
vcoubard 607:e98331f1d6b5 462 nrf_gpio_pin_dir_t dir,
vcoubard 607:e98331f1d6b5 463 nrf_gpio_pin_input_t input,
vcoubard 607:e98331f1d6b5 464 nrf_gpio_pin_pull_t pull,
vcoubard 607:e98331f1d6b5 465 nrf_gpio_pin_drive_t drive,
vcoubard 607:e98331f1d6b5 466 nrf_gpio_pin_sense_t sense)
vcoubard 607:e98331f1d6b5 467 {
vcoubard 607:e98331f1d6b5 468 NRF_GPIO->PIN_CNF[pin_number] = ((uint32_t)dir << GPIO_PIN_CNF_DIR_Pos)
vcoubard 607:e98331f1d6b5 469 | ((uint32_t)input << GPIO_PIN_CNF_INPUT_Pos)
vcoubard 607:e98331f1d6b5 470 | ((uint32_t)pull << GPIO_PIN_CNF_PULL_Pos)
vcoubard 607:e98331f1d6b5 471 | ((uint32_t)drive << GPIO_PIN_CNF_DRIVE_Pos)
vcoubard 607:e98331f1d6b5 472 | ((uint32_t)sense << GPIO_PIN_CNF_SENSE_Pos);
vcoubard 607:e98331f1d6b5 473 }
vcoubard 607:e98331f1d6b5 474
vcoubard 607:e98331f1d6b5 475 __STATIC_INLINE void nrf_gpio_cfg_output(uint32_t pin_number)
vcoubard 607:e98331f1d6b5 476 {
vcoubard 607:e98331f1d6b5 477 nrf_gpio_cfg(
vcoubard 607:e98331f1d6b5 478 pin_number,
vcoubard 607:e98331f1d6b5 479 NRF_GPIO_PIN_DIR_OUTPUT,
vcoubard 607:e98331f1d6b5 480 NRF_GPIO_PIN_INPUT_DISCONNECT,
vcoubard 607:e98331f1d6b5 481 NRF_GPIO_PIN_NOPULL,
vcoubard 607:e98331f1d6b5 482 NRF_GPIO_PIN_S0S1,
vcoubard 607:e98331f1d6b5 483 NRF_GPIO_PIN_NOSENSE);
vcoubard 607:e98331f1d6b5 484 }
vcoubard 607:e98331f1d6b5 485
vcoubard 607:e98331f1d6b5 486 __STATIC_INLINE void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config)
vcoubard 607:e98331f1d6b5 487 {
vcoubard 607:e98331f1d6b5 488 nrf_gpio_cfg(
vcoubard 607:e98331f1d6b5 489 pin_number,
vcoubard 607:e98331f1d6b5 490 NRF_GPIO_PIN_DIR_INPUT,
vcoubard 607:e98331f1d6b5 491 NRF_GPIO_PIN_INPUT_CONNECT,
vcoubard 607:e98331f1d6b5 492 pull_config,
vcoubard 607:e98331f1d6b5 493 NRF_GPIO_PIN_S0S1,
vcoubard 607:e98331f1d6b5 494 NRF_GPIO_PIN_NOSENSE);
vcoubard 607:e98331f1d6b5 495 }
vcoubard 607:e98331f1d6b5 496
vcoubard 607:e98331f1d6b5 497 __STATIC_INLINE void nrf_gpio_cfg_default(uint32_t pin_number)
vcoubard 607:e98331f1d6b5 498 {
vcoubard 607:e98331f1d6b5 499 nrf_gpio_cfg(
vcoubard 607:e98331f1d6b5 500 pin_number,
vcoubard 607:e98331f1d6b5 501 NRF_GPIO_PIN_DIR_INPUT,
vcoubard 607:e98331f1d6b5 502 NRF_GPIO_PIN_INPUT_DISCONNECT,
vcoubard 607:e98331f1d6b5 503 NRF_GPIO_PIN_NOPULL,
vcoubard 607:e98331f1d6b5 504 NRF_GPIO_PIN_S0S1,
vcoubard 607:e98331f1d6b5 505 NRF_GPIO_PIN_NOSENSE);
vcoubard 607:e98331f1d6b5 506 }
vcoubard 607:e98331f1d6b5 507
vcoubard 607:e98331f1d6b5 508 __STATIC_INLINE void nrf_gpio_cfg_watcher(uint32_t pin_number)
vcoubard 607:e98331f1d6b5 509 {
vcoubard 607:e98331f1d6b5 510 /*lint -e{845} // A zero has been given as right argument to operator '|'" */
vcoubard 607:e98331f1d6b5 511 uint32_t cnf = NRF_GPIO->PIN_CNF[pin_number] & ~GPIO_PIN_CNF_INPUT_Msk;
vcoubard 607:e98331f1d6b5 512 NRF_GPIO->PIN_CNF[pin_number] = cnf | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos);
vcoubard 607:e98331f1d6b5 513 }
vcoubard 607:e98331f1d6b5 514
vcoubard 607:e98331f1d6b5 515 __STATIC_INLINE void nrf_gpio_input_disconnect(uint32_t pin_number)
vcoubard 607:e98331f1d6b5 516 {
vcoubard 607:e98331f1d6b5 517 /*lint -e{845} // A zero has been given as right argument to operator '|'" */
vcoubard 607:e98331f1d6b5 518 uint32_t cnf = NRF_GPIO->PIN_CNF[pin_number] & ~GPIO_PIN_CNF_INPUT_Msk;
vcoubard 607:e98331f1d6b5 519 NRF_GPIO->PIN_CNF[pin_number] = cnf | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos);
vcoubard 607:e98331f1d6b5 520 }
vcoubard 607:e98331f1d6b5 521
vcoubard 607:e98331f1d6b5 522 __STATIC_INLINE void nrf_gpio_cfg_sense_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config, nrf_gpio_pin_sense_t sense_config)
vcoubard 607:e98331f1d6b5 523 {
vcoubard 607:e98331f1d6b5 524 nrf_gpio_cfg(
vcoubard 607:e98331f1d6b5 525 pin_number,
vcoubard 607:e98331f1d6b5 526 NRF_GPIO_PIN_DIR_INPUT,
vcoubard 607:e98331f1d6b5 527 NRF_GPIO_PIN_INPUT_CONNECT,
vcoubard 607:e98331f1d6b5 528 pull_config,
vcoubard 607:e98331f1d6b5 529 NRF_GPIO_PIN_S0S1,
vcoubard 607:e98331f1d6b5 530 sense_config);
vcoubard 607:e98331f1d6b5 531 }
vcoubard 607:e98331f1d6b5 532
vcoubard 607:e98331f1d6b5 533 __STATIC_INLINE void nrf_gpio_cfg_sense_set(uint32_t pin_number, nrf_gpio_pin_sense_t sense_config)
vcoubard 607:e98331f1d6b5 534 {
vcoubard 607:e98331f1d6b5 535 /*lint -e{845} // A zero has been given as right argument to operator '|'" */
vcoubard 607:e98331f1d6b5 536 //uint32_t cnf = NRF_GPIO->PIN_CNF[pin_number] & ~GPIO_PIN_CNF_SENSE_Msk;
vcoubard 607:e98331f1d6b5 537 NRF_GPIO->PIN_CNF[pin_number] &= ~GPIO_PIN_CNF_SENSE_Msk;
vcoubard 607:e98331f1d6b5 538 NRF_GPIO->PIN_CNF[pin_number] |= (sense_config << GPIO_PIN_CNF_SENSE_Pos);
vcoubard 607:e98331f1d6b5 539 }
vcoubard 607:e98331f1d6b5 540
vcoubard 607:e98331f1d6b5 541 __STATIC_INLINE void nrf_gpio_pin_dir_set(uint32_t pin_number, nrf_gpio_pin_dir_t direction)
vcoubard 607:e98331f1d6b5 542 {
vcoubard 607:e98331f1d6b5 543 if(direction == NRF_GPIO_PIN_DIR_INPUT)
vcoubard 607:e98331f1d6b5 544 {
vcoubard 607:e98331f1d6b5 545 nrf_gpio_cfg(
vcoubard 607:e98331f1d6b5 546 pin_number,
vcoubard 607:e98331f1d6b5 547 NRF_GPIO_PIN_DIR_INPUT,
vcoubard 607:e98331f1d6b5 548 NRF_GPIO_PIN_INPUT_CONNECT,
vcoubard 607:e98331f1d6b5 549 NRF_GPIO_PIN_NOPULL,
vcoubard 607:e98331f1d6b5 550 NRF_GPIO_PIN_S0S1,
vcoubard 607:e98331f1d6b5 551 NRF_GPIO_PIN_NOSENSE);
vcoubard 607:e98331f1d6b5 552 }
vcoubard 607:e98331f1d6b5 553 else
vcoubard 607:e98331f1d6b5 554 {
vcoubard 607:e98331f1d6b5 555 NRF_GPIO->DIRSET = (1UL << pin_number);
vcoubard 607:e98331f1d6b5 556 }
vcoubard 607:e98331f1d6b5 557 }
vcoubard 607:e98331f1d6b5 558
vcoubard 607:e98331f1d6b5 559 __STATIC_INLINE void nrf_gpio_pin_set(uint32_t pin_number)
vcoubard 607:e98331f1d6b5 560 {
vcoubard 607:e98331f1d6b5 561 NRF_GPIO->OUTSET = (1UL << pin_number);
vcoubard 607:e98331f1d6b5 562 }
vcoubard 607:e98331f1d6b5 563
vcoubard 607:e98331f1d6b5 564 __STATIC_INLINE void nrf_gpio_pins_set(uint32_t pin_mask)
vcoubard 607:e98331f1d6b5 565 {
vcoubard 607:e98331f1d6b5 566 NRF_GPIO->OUTSET = pin_mask;
vcoubard 607:e98331f1d6b5 567 }
vcoubard 607:e98331f1d6b5 568
vcoubard 607:e98331f1d6b5 569 __STATIC_INLINE void nrf_gpio_pin_clear(uint32_t pin_number)
vcoubard 607:e98331f1d6b5 570 {
vcoubard 607:e98331f1d6b5 571 NRF_GPIO->OUTCLR = (1UL << pin_number);
vcoubard 607:e98331f1d6b5 572 }
vcoubard 607:e98331f1d6b5 573
vcoubard 607:e98331f1d6b5 574 __STATIC_INLINE void nrf_gpio_pins_clear(uint32_t pin_mask)
vcoubard 607:e98331f1d6b5 575 {
vcoubard 607:e98331f1d6b5 576 NRF_GPIO->OUTCLR = pin_mask;
vcoubard 607:e98331f1d6b5 577 }
vcoubard 607:e98331f1d6b5 578
vcoubard 607:e98331f1d6b5 579 __STATIC_INLINE void nrf_gpio_pin_toggle(uint32_t pin_number)
vcoubard 607:e98331f1d6b5 580 {
vcoubard 607:e98331f1d6b5 581 const uint32_t pin_bit = 1UL << pin_number;
vcoubard 607:e98331f1d6b5 582 const uint32_t pin_state = ((NRF_GPIO->OUT >> pin_number) & 1UL);
vcoubard 607:e98331f1d6b5 583
vcoubard 607:e98331f1d6b5 584 if (pin_state == 0)
vcoubard 607:e98331f1d6b5 585 {
vcoubard 607:e98331f1d6b5 586 // Current state low, set high.
vcoubard 607:e98331f1d6b5 587 NRF_GPIO->OUTSET = pin_bit;
vcoubard 607:e98331f1d6b5 588 }
vcoubard 607:e98331f1d6b5 589 else
vcoubard 607:e98331f1d6b5 590 {
vcoubard 607:e98331f1d6b5 591 // Current state high, set low.
vcoubard 607:e98331f1d6b5 592 NRF_GPIO->OUTCLR = pin_bit;
vcoubard 607:e98331f1d6b5 593 }
vcoubard 607:e98331f1d6b5 594 }
vcoubard 607:e98331f1d6b5 595
vcoubard 607:e98331f1d6b5 596 __STATIC_INLINE void nrf_gpio_pin_write(uint32_t pin_number, uint32_t value)
vcoubard 607:e98331f1d6b5 597 {
vcoubard 607:e98331f1d6b5 598 if (value == 0)
vcoubard 607:e98331f1d6b5 599 {
vcoubard 607:e98331f1d6b5 600 nrf_gpio_pin_clear(pin_number);
vcoubard 607:e98331f1d6b5 601 }
vcoubard 607:e98331f1d6b5 602 else
vcoubard 607:e98331f1d6b5 603 {
vcoubard 607:e98331f1d6b5 604 nrf_gpio_pin_set(pin_number);
vcoubard 607:e98331f1d6b5 605 }
vcoubard 607:e98331f1d6b5 606 }
vcoubard 607:e98331f1d6b5 607
vcoubard 607:e98331f1d6b5 608 __STATIC_INLINE uint32_t nrf_gpio_pin_read(uint32_t pin_number)
vcoubard 607:e98331f1d6b5 609 {
vcoubard 607:e98331f1d6b5 610 return ((NRF_GPIO->IN >> pin_number) & 1UL);
vcoubard 607:e98331f1d6b5 611 }
vcoubard 607:e98331f1d6b5 612
vcoubard 607:e98331f1d6b5 613 __STATIC_INLINE uint32_t nrf_gpio_pins_read(void)
vcoubard 607:e98331f1d6b5 614 {
vcoubard 607:e98331f1d6b5 615 return NRF_GPIO->IN;
vcoubard 607:e98331f1d6b5 616 }
vcoubard 607:e98331f1d6b5 617
vcoubard 607:e98331f1d6b5 618 __STATIC_INLINE nrf_gpio_pin_sense_t nrf_gpio_pin_sense_get(uint32_t pin_number)
vcoubard 607:e98331f1d6b5 619 {
vcoubard 607:e98331f1d6b5 620 return (nrf_gpio_pin_sense_t)((NRF_GPIO->PIN_CNF[pin_number] & GPIO_PIN_CNF_SENSE_Msk) >> GPIO_PIN_CNF_SENSE_Pos);
vcoubard 607:e98331f1d6b5 621 }
vcoubard 607:e98331f1d6b5 622
vcoubard 607:e98331f1d6b5 623 __STATIC_INLINE void nrf_gpio_word_byte_write(volatile uint32_t * word_address, uint8_t byte_no, uint8_t value)
vcoubard 607:e98331f1d6b5 624 {
vcoubard 607:e98331f1d6b5 625 *((volatile uint8_t*)(word_address) + byte_no) = value;
vcoubard 607:e98331f1d6b5 626 }
vcoubard 607:e98331f1d6b5 627
vcoubard 607:e98331f1d6b5 628 __STATIC_INLINE uint8_t nrf_gpio_word_byte_read(const volatile uint32_t* word_address, uint8_t byte_no)
vcoubard 607:e98331f1d6b5 629 {
vcoubard 607:e98331f1d6b5 630 return (*((const volatile uint8_t*)(word_address) + byte_no));
vcoubard 607:e98331f1d6b5 631 }
vcoubard 607:e98331f1d6b5 632
vcoubard 607:e98331f1d6b5 633 __STATIC_INLINE void nrf_gpio_port_dir_set(nrf_gpio_port_select_t port, nrf_gpio_port_dir_t dir)
vcoubard 607:e98331f1d6b5 634 {
vcoubard 607:e98331f1d6b5 635 if (dir == NRF_GPIO_PORT_DIR_OUTPUT)
vcoubard 607:e98331f1d6b5 636 {
vcoubard 607:e98331f1d6b5 637 nrf_gpio_word_byte_write(&NRF_GPIO->DIRSET, port, 0xFF);
vcoubard 607:e98331f1d6b5 638 }
vcoubard 607:e98331f1d6b5 639 else
vcoubard 607:e98331f1d6b5 640 {
vcoubard 607:e98331f1d6b5 641 nrf_gpio_range_cfg_input(port*8, (port+1)*8-1, NRF_GPIO_PIN_NOPULL);
vcoubard 607:e98331f1d6b5 642 }
vcoubard 607:e98331f1d6b5 643 }
vcoubard 607:e98331f1d6b5 644
vcoubard 607:e98331f1d6b5 645 __STATIC_INLINE uint8_t nrf_gpio_port_read(nrf_gpio_port_select_t port)
vcoubard 607:e98331f1d6b5 646 {
vcoubard 607:e98331f1d6b5 647 return nrf_gpio_word_byte_read(&NRF_GPIO->IN, port);
vcoubard 607:e98331f1d6b5 648 }
vcoubard 607:e98331f1d6b5 649
vcoubard 607:e98331f1d6b5 650 __STATIC_INLINE void nrf_gpio_port_write(nrf_gpio_port_select_t port, uint8_t value)
vcoubard 607:e98331f1d6b5 651 {
vcoubard 607:e98331f1d6b5 652 nrf_gpio_word_byte_write(&NRF_GPIO->OUT, port, value);
vcoubard 607:e98331f1d6b5 653 }
vcoubard 607:e98331f1d6b5 654
vcoubard 607:e98331f1d6b5 655 __STATIC_INLINE void nrf_gpio_port_set(nrf_gpio_port_select_t port, uint8_t set_mask)
vcoubard 607:e98331f1d6b5 656 {
vcoubard 607:e98331f1d6b5 657 nrf_gpio_word_byte_write(&NRF_GPIO->OUTSET, port, set_mask);
vcoubard 607:e98331f1d6b5 658 }
vcoubard 607:e98331f1d6b5 659
vcoubard 607:e98331f1d6b5 660 __STATIC_INLINE void nrf_gpio_port_clear(nrf_gpio_port_select_t port, uint8_t clr_mask)
vcoubard 607:e98331f1d6b5 661 {
vcoubard 607:e98331f1d6b5 662 nrf_gpio_word_byte_write(&NRF_GPIO->OUTCLR, port, clr_mask);
vcoubard 607:e98331f1d6b5 663 }
vcoubard 607:e98331f1d6b5 664 #endif //SUPPRESS_INLINE_IMPLEMENTATION
vcoubard 607:e98331f1d6b5 665 /** @} */
vcoubard 607:e98331f1d6b5 666
vcoubard 607:e98331f1d6b5 667 #endif