Nordic nrf51 sdk sources. Mirrored from https://github.com/ARMmbed/nrf51-sdk.

Dependents:   nRF51822 nRF51822

Committer:
vcoubard
Date:
Thu Apr 07 17:37:40 2016 +0100
Revision:
19:47192cb9def7
Parent:
10:233fefd8162b
Child:
20:a90c48eb1d30
Synchronized with git rev 9251259f
Author: Liyou Zhou
Copy over coresponding files from nordic-sdk 9.0.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vcoubard 19:47192cb9def7 1 /* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
vcoubard 19:47192cb9def7 2 *
vcoubard 19:47192cb9def7 3 * The information contained herein is property of Nordic Semiconductor ASA.
vcoubard 19:47192cb9def7 4 * Terms and conditions of usage are described in detail in NORDIC
vcoubard 19:47192cb9def7 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
vcoubard 19:47192cb9def7 6 *
vcoubard 19:47192cb9def7 7 * Licensees are granted free, non-transferable use of the information. NO
vcoubard 19:47192cb9def7 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
vcoubard 19:47192cb9def7 9 * the file.
vcoubard 19:47192cb9def7 10 *
vcoubard 19:47192cb9def7 11 */
Vincent Coubard 0:f2542974c862 12 #ifndef NRF_GPIO_H__
Vincent Coubard 0:f2542974c862 13 #define NRF_GPIO_H__
Vincent Coubard 0:f2542974c862 14
Vincent Coubard 0:f2542974c862 15 #include "nrf51.h"
Vincent Coubard 0:f2542974c862 16 #include "nrf51_bitfields.h"
vcoubard 1:ebc0e0ef0a11 17 #include <stdbool.h>
Vincent Coubard 0:f2542974c862 18
Vincent Coubard 0:f2542974c862 19 /**
Vincent Coubard 0:f2542974c862 20 * @defgroup nrf_gpio GPIO abstraction
Vincent Coubard 0:f2542974c862 21 * @{
Vincent Coubard 0:f2542974c862 22 * @ingroup nrf_drivers
Vincent Coubard 0:f2542974c862 23 * @brief GPIO pin abstraction and port abstraction for reading and writing byte-wise to GPIO ports.
Vincent Coubard 0:f2542974c862 24 *
Vincent Coubard 0:f2542974c862 25 * Here, the GPIO ports are defined as follows:
Vincent Coubard 0:f2542974c862 26 * - Port 0 -> pin 0-7
Vincent Coubard 0:f2542974c862 27 * - Port 1 -> pin 8-15
Vincent Coubard 0:f2542974c862 28 * - Port 2 -> pin 16-23
Vincent Coubard 0:f2542974c862 29 * - Port 3 -> pin 24-31
Vincent Coubard 0:f2542974c862 30 */
Vincent Coubard 0:f2542974c862 31
vcoubard 1:ebc0e0ef0a11 32 #define NUMBER_OF_PINS 32
vcoubard 1:ebc0e0ef0a11 33
Vincent Coubard 0:f2542974c862 34 /**
Vincent Coubard 0:f2542974c862 35 * @enum nrf_gpio_port_dir_t
Vincent Coubard 0:f2542974c862 36 * @brief Enumerator used for setting the direction of a GPIO port.
Vincent Coubard 0:f2542974c862 37 */
Vincent Coubard 0:f2542974c862 38 typedef enum
Vincent Coubard 0:f2542974c862 39 {
Vincent Coubard 0:f2542974c862 40 NRF_GPIO_PORT_DIR_OUTPUT, ///< Output
Vincent Coubard 0:f2542974c862 41 NRF_GPIO_PORT_DIR_INPUT ///< Input
Vincent Coubard 0:f2542974c862 42 } nrf_gpio_port_dir_t;
Vincent Coubard 0:f2542974c862 43
Vincent Coubard 0:f2542974c862 44 /**
Vincent Coubard 0:f2542974c862 45 * @enum nrf_gpio_pin_dir_t
Vincent Coubard 0:f2542974c862 46 * Pin direction definitions.
Vincent Coubard 0:f2542974c862 47 */
Vincent Coubard 0:f2542974c862 48 typedef enum
Vincent Coubard 0:f2542974c862 49 {
Vincent Coubard 0:f2542974c862 50 NRF_GPIO_PIN_DIR_INPUT, ///< Input
Vincent Coubard 0:f2542974c862 51 NRF_GPIO_PIN_DIR_OUTPUT ///< Output
Vincent Coubard 0:f2542974c862 52 } nrf_gpio_pin_dir_t;
Vincent Coubard 0:f2542974c862 53
Vincent Coubard 0:f2542974c862 54 /**
Vincent Coubard 0:f2542974c862 55 * @enum nrf_gpio_port_select_t
Vincent Coubard 0:f2542974c862 56 * @brief Enumerator used for selecting between port 0 - 3.
Vincent Coubard 0:f2542974c862 57 */
Vincent Coubard 0:f2542974c862 58 typedef enum
Vincent Coubard 0:f2542974c862 59 {
Vincent Coubard 0:f2542974c862 60 NRF_GPIO_PORT_SELECT_PORT0 = 0, ///< Port 0 (GPIO pin 0-7)
Vincent Coubard 0:f2542974c862 61 NRF_GPIO_PORT_SELECT_PORT1, ///< Port 1 (GPIO pin 8-15)
Vincent Coubard 0:f2542974c862 62 NRF_GPIO_PORT_SELECT_PORT2, ///< Port 2 (GPIO pin 16-23)
Vincent Coubard 0:f2542974c862 63 NRF_GPIO_PORT_SELECT_PORT3, ///< Port 3 (GPIO pin 24-31)
Vincent Coubard 0:f2542974c862 64 } nrf_gpio_port_select_t;
Vincent Coubard 0:f2542974c862 65
Vincent Coubard 0:f2542974c862 66 /**
Vincent Coubard 0:f2542974c862 67 * @enum nrf_gpio_pin_pull_t
Vincent Coubard 0:f2542974c862 68 * @brief Enumerator used for selecting the pin to be pulled down or up at the time of pin configuration
Vincent Coubard 0:f2542974c862 69 */
Vincent Coubard 0:f2542974c862 70 typedef enum
Vincent Coubard 0:f2542974c862 71 {
Vincent Coubard 0:f2542974c862 72 NRF_GPIO_PIN_NOPULL = GPIO_PIN_CNF_PULL_Disabled, ///< Pin pullup resistor disabled
Vincent Coubard 0:f2542974c862 73 NRF_GPIO_PIN_PULLDOWN = GPIO_PIN_CNF_PULL_Pulldown, ///< Pin pulldown resistor enabled
Vincent Coubard 0:f2542974c862 74 NRF_GPIO_PIN_PULLUP = GPIO_PIN_CNF_PULL_Pullup, ///< Pin pullup resistor enabled
Vincent Coubard 0:f2542974c862 75 } nrf_gpio_pin_pull_t;
Vincent Coubard 0:f2542974c862 76
Vincent Coubard 0:f2542974c862 77 /**
Vincent Coubard 0:f2542974c862 78 * @enum nrf_gpio_pin_sense_t
Vincent Coubard 0:f2542974c862 79 * @brief Enumerator used for selecting the pin to sense high or low level on the pin input.
Vincent Coubard 0:f2542974c862 80 */
Vincent Coubard 0:f2542974c862 81 typedef enum
Vincent Coubard 0:f2542974c862 82 {
Vincent Coubard 0:f2542974c862 83 NRF_GPIO_PIN_NOSENSE = GPIO_PIN_CNF_SENSE_Disabled, ///< Pin sense level disabled.
Vincent Coubard 0:f2542974c862 84 NRF_GPIO_PIN_SENSE_LOW = GPIO_PIN_CNF_SENSE_Low, ///< Pin sense low level.
Vincent Coubard 0:f2542974c862 85 NRF_GPIO_PIN_SENSE_HIGH = GPIO_PIN_CNF_SENSE_High, ///< Pin sense high level.
Vincent Coubard 0:f2542974c862 86 } nrf_gpio_pin_sense_t;
Vincent Coubard 0:f2542974c862 87
Vincent Coubard 0:f2542974c862 88 /**
Vincent Coubard 0:f2542974c862 89 * @brief Function for configuring the GPIO pin range as outputs with normal drive strength.
Vincent Coubard 0:f2542974c862 90 * This function can be used to configure pin range as simple output with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
Vincent Coubard 0:f2542974c862 91 *
Vincent Coubard 0:f2542974c862 92 * @param pin_range_start specifies the start number (inclusive) in the range of pin numbers to be configured (allowed values 0-30)
Vincent Coubard 0:f2542974c862 93 *
Vincent Coubard 0:f2542974c862 94 * @param pin_range_end specifies the end number (inclusive) in the range of pin numbers to be configured (allowed values 0-30)
Vincent Coubard 0:f2542974c862 95 *
Vincent Coubard 0:f2542974c862 96 * @note For configuring only one pin as output use @ref nrf_gpio_cfg_output
Vincent Coubard 0:f2542974c862 97 * Sense capability on the pin is disabled, and input is disconnected from the buffer as the pins are configured as output.
Vincent Coubard 0:f2542974c862 98 */
vcoubard 1:ebc0e0ef0a11 99 __STATIC_INLINE void nrf_gpio_range_cfg_output(uint32_t pin_range_start, uint32_t pin_range_end);
Vincent Coubard 0:f2542974c862 100
Vincent Coubard 0:f2542974c862 101 /**
Vincent Coubard 0:f2542974c862 102 * @brief Function for configuring the GPIO pin range as inputs with given initial value set, hiding inner details.
Vincent Coubard 0:f2542974c862 103 * This function can be used to configure pin range as simple input.
Vincent Coubard 0:f2542974c862 104 *
Vincent Coubard 0:f2542974c862 105 * @param pin_range_start specifies the start number (inclusive) in the range of pin numbers to be configured (allowed values 0-30)
Vincent Coubard 0:f2542974c862 106 *
Vincent Coubard 0:f2542974c862 107 * @param pin_range_end specifies the end number (inclusive) in the range of pin numbers to be configured (allowed values 0-30)
Vincent Coubard 0:f2542974c862 108 *
Vincent Coubard 0:f2542974c862 109 * @param pull_config State of the pin range pull resistor (no pull, pulled down or pulled high)
Vincent Coubard 0:f2542974c862 110 *
Vincent Coubard 0:f2542974c862 111 * @note For configuring only one pin as input use @ref nrf_gpio_cfg_input
Vincent Coubard 0:f2542974c862 112 * Sense capability on the pin is disabled, and input is connected to buffer so that the GPIO->IN register is readable
Vincent Coubard 0:f2542974c862 113 */
vcoubard 1:ebc0e0ef0a11 114 __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 1:ebc0e0ef0a11 115
vcoubard 1:ebc0e0ef0a11 116 /**
vcoubard 1:ebc0e0ef0a11 117 * @brief Function for configuring the given GPIO pin number as output with given initial value set, hiding inner details.
vcoubard 1:ebc0e0ef0a11 118 * This function can be used to configure pin range as simple input with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
vcoubard 1:ebc0e0ef0a11 119 *
vcoubard 1:ebc0e0ef0a11 120 * @param pin_number specifies the pin number (allowed values 0-30)
vcoubard 1:ebc0e0ef0a11 121 *
vcoubard 1:ebc0e0ef0a11 122 * @note Sense capability on the pin is disabled, and input is disconnected from the buffer as the pins are configured as output.
vcoubard 1:ebc0e0ef0a11 123 */
vcoubard 1:ebc0e0ef0a11 124 __STATIC_INLINE void nrf_gpio_cfg_output(uint32_t pin_number);
vcoubard 1:ebc0e0ef0a11 125
vcoubard 1:ebc0e0ef0a11 126 /**
vcoubard 1:ebc0e0ef0a11 127 * @brief Function for configuring the given GPIO pin number as input with given initial value set, hiding inner details.
vcoubard 1:ebc0e0ef0a11 128 * This function can be used to configure pin range as simple input with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
vcoubard 1:ebc0e0ef0a11 129 *
vcoubard 1:ebc0e0ef0a11 130 * @param pin_number Specifies the pin number (allowed values 0-30).
vcoubard 1:ebc0e0ef0a11 131 * @param pull_config State of the pin range pull resistor (no pull, pulled down or pulled high).
vcoubard 1:ebc0e0ef0a11 132 *
vcoubard 1:ebc0e0ef0a11 133 * @note Sense capability on the pin is disabled, and input is connected to buffer so that the GPIO->IN register is readable
vcoubard 1:ebc0e0ef0a11 134 */
vcoubard 1:ebc0e0ef0a11 135 __STATIC_INLINE void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config);
vcoubard 1:ebc0e0ef0a11 136
vcoubard 1:ebc0e0ef0a11 137 /**
vcoubard 1:ebc0e0ef0a11 138 * @brief Function for reseting pin configuration to its default state.
vcoubard 1:ebc0e0ef0a11 139 *
vcoubard 1:ebc0e0ef0a11 140 * @param pin_number Specifies the pin number (allowed values 0-30).
vcoubard 1:ebc0e0ef0a11 141 */
vcoubard 1:ebc0e0ef0a11 142 __STATIC_INLINE void nrf_gpio_cfg_default(uint32_t pin_number);
vcoubard 1:ebc0e0ef0a11 143
vcoubard 1:ebc0e0ef0a11 144 /**
vcoubard 1:ebc0e0ef0a11 145 * @brief Function for configuring the given GPIO pin number as a watcher. Only input is connected.
vcoubard 1:ebc0e0ef0a11 146 *
vcoubard 1:ebc0e0ef0a11 147 * @param pin_number Specifies the pin number (allowed values 0-30).
vcoubard 1:ebc0e0ef0a11 148 *
vcoubard 1:ebc0e0ef0a11 149 */
vcoubard 1:ebc0e0ef0a11 150 __STATIC_INLINE void nrf_gpio_cfg_watcher(uint32_t pin_number);
vcoubard 1:ebc0e0ef0a11 151
vcoubard 1:ebc0e0ef0a11 152 /**
vcoubard 1:ebc0e0ef0a11 153 * @brief Function for disconnecting input for the given GPIO.
vcoubard 1:ebc0e0ef0a11 154 *
vcoubard 1:ebc0e0ef0a11 155 * @param pin_number Specifies the pin number (allowed values 0-30).
vcoubard 1:ebc0e0ef0a11 156 *
vcoubard 1:ebc0e0ef0a11 157 */
vcoubard 1:ebc0e0ef0a11 158 __STATIC_INLINE void nrf_gpio_input_disconnect(uint32_t pin_number);
vcoubard 1:ebc0e0ef0a11 159
vcoubard 1:ebc0e0ef0a11 160 /**
vcoubard 1:ebc0e0ef0a11 161 * @brief Function for configuring the given GPIO pin number as input with given initial value set, hiding inner details.
vcoubard 1:ebc0e0ef0a11 162 * This function can be used to configure pin range as simple input with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
vcoubard 1:ebc0e0ef0a11 163 * Sense capability on the pin is configurable, and input is connected to buffer so that the GPIO->IN register is readable.
vcoubard 1:ebc0e0ef0a11 164 *
vcoubard 1:ebc0e0ef0a11 165 * @param pin_number Specifies the pin number (allowed values 0-30).
vcoubard 1:ebc0e0ef0a11 166 * @param pull_config State of the pin pull resistor (no pull, pulled down or pulled high).
vcoubard 1:ebc0e0ef0a11 167 * @param sense_config Sense level of the pin (no sense, sense low or sense high).
vcoubard 1:ebc0e0ef0a11 168 */
vcoubard 1:ebc0e0ef0a11 169 __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 1:ebc0e0ef0a11 170
vcoubard 1:ebc0e0ef0a11 171 /**
vcoubard 1:ebc0e0ef0a11 172 * @brief Function for configuring sense level for the given GPIO.
vcoubard 1:ebc0e0ef0a11 173 *
vcoubard 1:ebc0e0ef0a11 174 * @param pin_number Specifies the pin number of gpio pin numbers to be configured (allowed values 0-30).
vcoubard 1:ebc0e0ef0a11 175 * @param sense_config Sense configuration.
vcoubard 1:ebc0e0ef0a11 176 *
vcoubard 1:ebc0e0ef0a11 177 */
vcoubard 1:ebc0e0ef0a11 178 __STATIC_INLINE void nrf_gpio_cfg_sense_set(uint32_t pin_number, nrf_gpio_pin_sense_t sense_config);
vcoubard 1:ebc0e0ef0a11 179
vcoubard 1:ebc0e0ef0a11 180 /**
vcoubard 1:ebc0e0ef0a11 181 * @brief Function for setting the direction for a GPIO pin.
vcoubard 1:ebc0e0ef0a11 182 *
vcoubard 1:ebc0e0ef0a11 183 * @param pin_number specifies the pin number [0:31] for which to
vcoubard 1:ebc0e0ef0a11 184 * set the direction.
vcoubard 1:ebc0e0ef0a11 185 *
vcoubard 1:ebc0e0ef0a11 186 * @param direction specifies the direction
vcoubard 1:ebc0e0ef0a11 187 */
vcoubard 1:ebc0e0ef0a11 188 __STATIC_INLINE void nrf_gpio_pin_dir_set(uint32_t pin_number, nrf_gpio_pin_dir_t direction);
vcoubard 1:ebc0e0ef0a11 189
vcoubard 1:ebc0e0ef0a11 190 /**
vcoubard 1:ebc0e0ef0a11 191 * @brief Function for setting a GPIO pin.
vcoubard 1:ebc0e0ef0a11 192 *
vcoubard 1:ebc0e0ef0a11 193 * Note that the pin must be configured as an output for this
vcoubard 1:ebc0e0ef0a11 194 * function to have any effect.
vcoubard 1:ebc0e0ef0a11 195 *
vcoubard 1:ebc0e0ef0a11 196 * @param pin_number specifies the pin number [0:31] to
vcoubard 1:ebc0e0ef0a11 197 * set.
vcoubard 1:ebc0e0ef0a11 198 */
vcoubard 1:ebc0e0ef0a11 199 __STATIC_INLINE void nrf_gpio_pin_set(uint32_t pin_number);
vcoubard 1:ebc0e0ef0a11 200
vcoubard 1:ebc0e0ef0a11 201 /**
vcoubard 1:ebc0e0ef0a11 202 * @brief Function for clearing a GPIO pin.
vcoubard 1:ebc0e0ef0a11 203 *
vcoubard 1:ebc0e0ef0a11 204 * Note that the pin must be configured as an output for this
vcoubard 1:ebc0e0ef0a11 205 * function to have any effect.
vcoubard 1:ebc0e0ef0a11 206 *
vcoubard 1:ebc0e0ef0a11 207 * @param pin_number specifies the pin number [0:31] to
vcoubard 1:ebc0e0ef0a11 208 * clear.
vcoubard 1:ebc0e0ef0a11 209 */
vcoubard 1:ebc0e0ef0a11 210 __STATIC_INLINE void nrf_gpio_pin_clear(uint32_t pin_number);
vcoubard 1:ebc0e0ef0a11 211
vcoubard 1:ebc0e0ef0a11 212 /**
vcoubard 1:ebc0e0ef0a11 213 * @brief Function for toggling a GPIO pin.
vcoubard 1:ebc0e0ef0a11 214 *
vcoubard 1:ebc0e0ef0a11 215 * Note that the pin must be configured as an output for this
vcoubard 1:ebc0e0ef0a11 216 * function to have any effect.
vcoubard 1:ebc0e0ef0a11 217 *
vcoubard 1:ebc0e0ef0a11 218 * @param pin_number specifies the pin number [0:31] to
vcoubard 1:ebc0e0ef0a11 219 * toggle.
vcoubard 1:ebc0e0ef0a11 220 */
vcoubard 1:ebc0e0ef0a11 221 __STATIC_INLINE void nrf_gpio_pin_toggle(uint32_t pin_number);
vcoubard 1:ebc0e0ef0a11 222
vcoubard 1:ebc0e0ef0a11 223 /**
vcoubard 1:ebc0e0ef0a11 224 * @brief Function for writing a value to a GPIO pin.
vcoubard 1:ebc0e0ef0a11 225 *
vcoubard 1:ebc0e0ef0a11 226 * Note that the pin must be configured as an output for this
vcoubard 1:ebc0e0ef0a11 227 * function to have any effect.
vcoubard 1:ebc0e0ef0a11 228 *
vcoubard 1:ebc0e0ef0a11 229 * @param pin_number specifies the pin number [0:31] to
vcoubard 1:ebc0e0ef0a11 230 * write.
vcoubard 1:ebc0e0ef0a11 231 *
vcoubard 1:ebc0e0ef0a11 232 * @param value specifies the value to be written to the pin.
vcoubard 1:ebc0e0ef0a11 233 * @arg 0 clears the pin
vcoubard 1:ebc0e0ef0a11 234 * @arg >=1 sets the pin.
vcoubard 1:ebc0e0ef0a11 235 */
vcoubard 1:ebc0e0ef0a11 236 __STATIC_INLINE void nrf_gpio_pin_write(uint32_t pin_number, uint32_t value);
vcoubard 1:ebc0e0ef0a11 237
vcoubard 1:ebc0e0ef0a11 238 /**
vcoubard 1:ebc0e0ef0a11 239 * @brief Function for reading the input level of a GPIO pin.
vcoubard 1:ebc0e0ef0a11 240 *
vcoubard 1:ebc0e0ef0a11 241 * Note that the pin must have input connected for the value
vcoubard 1:ebc0e0ef0a11 242 * returned from this function to be valid.
vcoubard 1:ebc0e0ef0a11 243 *
vcoubard 1:ebc0e0ef0a11 244 * @param pin_number specifies the pin number [0:31] to
vcoubard 1:ebc0e0ef0a11 245 * read.
vcoubard 1:ebc0e0ef0a11 246 *
vcoubard 1:ebc0e0ef0a11 247 * @return
vcoubard 1:ebc0e0ef0a11 248 * @retval 0 if the pin input level is low.
vcoubard 1:ebc0e0ef0a11 249 * @retval 1 if the pin input level is high.
vcoubard 1:ebc0e0ef0a11 250 * @retval > 1 should never occur.
vcoubard 1:ebc0e0ef0a11 251 */
vcoubard 1:ebc0e0ef0a11 252 __STATIC_INLINE uint32_t nrf_gpio_pin_read(uint32_t pin_number);
vcoubard 1:ebc0e0ef0a11 253
vcoubard 1:ebc0e0ef0a11 254 /**
vcoubard 1:ebc0e0ef0a11 255 * @brief Function for reading the input level of all GPIO pins.
vcoubard 1:ebc0e0ef0a11 256 *
vcoubard 1:ebc0e0ef0a11 257 * Note that the pin must have input connected for the value
vcoubard 1:ebc0e0ef0a11 258 * returned from this function to be valid.
vcoubard 1:ebc0e0ef0a11 259 *
vcoubard 1:ebc0e0ef0a11 260 * @retval Status of input of all pins
vcoubard 1:ebc0e0ef0a11 261 */
vcoubard 1:ebc0e0ef0a11 262 __STATIC_INLINE uint32_t nrf_gpio_pins_read(void);
vcoubard 1:ebc0e0ef0a11 263
vcoubard 1:ebc0e0ef0a11 264 /**
vcoubard 1:ebc0e0ef0a11 265 * @brief Function for reading the sense configuration of a GPIO pin.
vcoubard 1:ebc0e0ef0a11 266 *
vcoubard 1:ebc0e0ef0a11 267 * @param pin_number specifies the pin number [0:31] to
vcoubard 1:ebc0e0ef0a11 268 * read.
vcoubard 1:ebc0e0ef0a11 269 *
vcoubard 1:ebc0e0ef0a11 270 * @retval Sense configuration
vcoubard 1:ebc0e0ef0a11 271 */
vcoubard 1:ebc0e0ef0a11 272 __STATIC_INLINE nrf_gpio_pin_sense_t nrf_gpio_pin_sense_get(uint32_t pin_number);
vcoubard 1:ebc0e0ef0a11 273
vcoubard 1:ebc0e0ef0a11 274 /**
vcoubard 1:ebc0e0ef0a11 275 * @brief Generic function for writing a single byte of a 32 bit word at a given
vcoubard 1:ebc0e0ef0a11 276 * address.
vcoubard 1:ebc0e0ef0a11 277 *
vcoubard 1:ebc0e0ef0a11 278 * This function should not be called from outside the nrf_gpio
vcoubard 1:ebc0e0ef0a11 279 * abstraction layer.
vcoubard 1:ebc0e0ef0a11 280 *
vcoubard 1:ebc0e0ef0a11 281 * @param word_address is the address of the word to be written.
vcoubard 1:ebc0e0ef0a11 282 *
vcoubard 1:ebc0e0ef0a11 283 * @param byte_no is the word byte number (0-3) to be written.
vcoubard 1:ebc0e0ef0a11 284 *
vcoubard 1:ebc0e0ef0a11 285 * @param value is the value to be written to byte "byte_no" of word
vcoubard 1:ebc0e0ef0a11 286 * at address "word_address"
vcoubard 1:ebc0e0ef0a11 287 */
vcoubard 1:ebc0e0ef0a11 288 __STATIC_INLINE void nrf_gpio_word_byte_write(volatile uint32_t * word_address, uint8_t byte_no, uint8_t value);
vcoubard 1:ebc0e0ef0a11 289
vcoubard 1:ebc0e0ef0a11 290 /**
vcoubard 1:ebc0e0ef0a11 291 * @brief Generic function for reading a single byte of a 32 bit word at a given
vcoubard 1:ebc0e0ef0a11 292 * address.
vcoubard 1:ebc0e0ef0a11 293 *
vcoubard 1:ebc0e0ef0a11 294 * This function should not be called from outside the nrf_gpio
vcoubard 1:ebc0e0ef0a11 295 * abstraction layer.
vcoubard 1:ebc0e0ef0a11 296 *
vcoubard 1:ebc0e0ef0a11 297 * @param word_address is the address of the word to be read.
vcoubard 1:ebc0e0ef0a11 298 *
vcoubard 1:ebc0e0ef0a11 299 * @param byte_no is the byte number (0-3) of the word to be read.
vcoubard 1:ebc0e0ef0a11 300 *
vcoubard 1:ebc0e0ef0a11 301 * @return byte "byte_no" of word at address "word_address".
vcoubard 1:ebc0e0ef0a11 302 */
vcoubard 1:ebc0e0ef0a11 303 __STATIC_INLINE uint8_t nrf_gpio_word_byte_read(const volatile uint32_t* word_address, uint8_t byte_no);
vcoubard 1:ebc0e0ef0a11 304
vcoubard 1:ebc0e0ef0a11 305 /**
vcoubard 1:ebc0e0ef0a11 306 * @brief Function for setting the direction of a port.
vcoubard 1:ebc0e0ef0a11 307 *
vcoubard 1:ebc0e0ef0a11 308 * @param port is the port for which to set the direction.
vcoubard 1:ebc0e0ef0a11 309 *
vcoubard 1:ebc0e0ef0a11 310 * @param dir direction to be set for this port.
vcoubard 1:ebc0e0ef0a11 311 */
vcoubard 1:ebc0e0ef0a11 312 __STATIC_INLINE void nrf_gpio_port_dir_set(nrf_gpio_port_select_t port, nrf_gpio_port_dir_t dir);
vcoubard 1:ebc0e0ef0a11 313
vcoubard 1:ebc0e0ef0a11 314 /**
vcoubard 1:ebc0e0ef0a11 315 * @brief Function for reading a GPIO port.
vcoubard 1:ebc0e0ef0a11 316 *
vcoubard 1:ebc0e0ef0a11 317 * @param port is the port to read.
vcoubard 1:ebc0e0ef0a11 318 *
vcoubard 1:ebc0e0ef0a11 319 * @return the input value on this port.
vcoubard 1:ebc0e0ef0a11 320 */
vcoubard 1:ebc0e0ef0a11 321 __STATIC_INLINE uint8_t nrf_gpio_port_read(nrf_gpio_port_select_t port);
vcoubard 1:ebc0e0ef0a11 322
vcoubard 1:ebc0e0ef0a11 323 /**
vcoubard 1:ebc0e0ef0a11 324 * @brief Function for writing to a GPIO port.
vcoubard 1:ebc0e0ef0a11 325 *
vcoubard 1:ebc0e0ef0a11 326 * @param port is the port to write.
vcoubard 1:ebc0e0ef0a11 327 *
vcoubard 1:ebc0e0ef0a11 328 * @param value is the value to write to this port.
vcoubard 1:ebc0e0ef0a11 329 *
vcoubard 1:ebc0e0ef0a11 330 * @sa nrf_gpio_port_dir_set()
vcoubard 1:ebc0e0ef0a11 331 */
vcoubard 1:ebc0e0ef0a11 332 __STATIC_INLINE void nrf_gpio_port_write(nrf_gpio_port_select_t port, uint8_t value);
vcoubard 1:ebc0e0ef0a11 333
vcoubard 1:ebc0e0ef0a11 334 /**
vcoubard 1:ebc0e0ef0a11 335 * @brief Function for setting individual pins on GPIO port.
vcoubard 1:ebc0e0ef0a11 336 *
vcoubard 1:ebc0e0ef0a11 337 * @param port is the port for which to set the pins.
vcoubard 1:ebc0e0ef0a11 338 *
vcoubard 1:ebc0e0ef0a11 339 * @param set_mask is a mask specifying which pins to set. A bit
vcoubard 1:ebc0e0ef0a11 340 * set to 1 indicates that the corresponding port pin shall be
vcoubard 1:ebc0e0ef0a11 341 * set.
vcoubard 1:ebc0e0ef0a11 342 *
vcoubard 1:ebc0e0ef0a11 343 * @sa nrf_gpio_port_dir_set()
vcoubard 1:ebc0e0ef0a11 344 */
vcoubard 1:ebc0e0ef0a11 345 __STATIC_INLINE void nrf_gpio_port_set(nrf_gpio_port_select_t port, uint8_t set_mask);
vcoubard 1:ebc0e0ef0a11 346
vcoubard 1:ebc0e0ef0a11 347 /**
vcoubard 1:ebc0e0ef0a11 348 * @brief Function for clearing individual pins on GPIO port.
vcoubard 1:ebc0e0ef0a11 349 *
vcoubard 1:ebc0e0ef0a11 350 * @param port is the port for which to clear the pins.
vcoubard 1:ebc0e0ef0a11 351 *
vcoubard 1:ebc0e0ef0a11 352 * @param clr_mask is a mask specifying which pins to clear. A bit
vcoubard 1:ebc0e0ef0a11 353 * set to 1 indicates that the corresponding port pin shall be
vcoubard 1:ebc0e0ef0a11 354 * cleared.
vcoubard 1:ebc0e0ef0a11 355 *
vcoubard 1:ebc0e0ef0a11 356 * @sa nrf_gpio_port_dir_set()
vcoubard 1:ebc0e0ef0a11 357 */
vcoubard 1:ebc0e0ef0a11 358 __STATIC_INLINE void nrf_gpio_port_clear(nrf_gpio_port_select_t port, uint8_t clr_mask);
vcoubard 1:ebc0e0ef0a11 359
vcoubard 1:ebc0e0ef0a11 360 #ifndef SUPPRESS_INLINE_IMPLEMENTATION
vcoubard 1:ebc0e0ef0a11 361 __STATIC_INLINE void nrf_gpio_range_cfg_output(uint32_t pin_range_start, uint32_t pin_range_end)
vcoubard 1:ebc0e0ef0a11 362 {
vcoubard 1:ebc0e0ef0a11 363 /*lint -e{845} // A zero has been given as right argument to operator '|'" */
vcoubard 1:ebc0e0ef0a11 364 for (; pin_range_start <= pin_range_end; pin_range_start++)
vcoubard 1:ebc0e0ef0a11 365 {
vcoubard 1:ebc0e0ef0a11 366 NRF_GPIO->PIN_CNF[pin_range_start] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
vcoubard 1:ebc0e0ef0a11 367 | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
vcoubard 1:ebc0e0ef0a11 368 | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
vcoubard 1:ebc0e0ef0a11 369 | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
vcoubard 1:ebc0e0ef0a11 370 | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
vcoubard 1:ebc0e0ef0a11 371 }
vcoubard 1:ebc0e0ef0a11 372 }
vcoubard 1:ebc0e0ef0a11 373
vcoubard 1:ebc0e0ef0a11 374 __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)
Vincent Coubard 0:f2542974c862 375 {
Vincent Coubard 0:f2542974c862 376 /*lint -e{845} // A zero has been given as right argument to operator '|'" */
Vincent Coubard 0:f2542974c862 377 for (; pin_range_start <= pin_range_end; pin_range_start++)
Vincent Coubard 0:f2542974c862 378 {
Vincent Coubard 0:f2542974c862 379 NRF_GPIO->PIN_CNF[pin_range_start] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
Vincent Coubard 0:f2542974c862 380 | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
Vincent Coubard 0:f2542974c862 381 | (pull_config << GPIO_PIN_CNF_PULL_Pos)
Vincent Coubard 0:f2542974c862 382 | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
Vincent Coubard 0:f2542974c862 383 | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
Vincent Coubard 0:f2542974c862 384 }
Vincent Coubard 0:f2542974c862 385 }
Vincent Coubard 0:f2542974c862 386
vcoubard 1:ebc0e0ef0a11 387 __STATIC_INLINE void nrf_gpio_cfg_output(uint32_t pin_number)
Vincent Coubard 0:f2542974c862 388 {
Vincent Coubard 0:f2542974c862 389 /*lint -e{845} // A zero has been given as right argument to operator '|'" */
Vincent Coubard 0:f2542974c862 390 NRF_GPIO->PIN_CNF[pin_number] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
Vincent Coubard 0:f2542974c862 391 | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
Vincent Coubard 0:f2542974c862 392 | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
Vincent Coubard 0:f2542974c862 393 | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
Vincent Coubard 0:f2542974c862 394 | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
Vincent Coubard 0:f2542974c862 395 }
Vincent Coubard 0:f2542974c862 396
vcoubard 1:ebc0e0ef0a11 397 __STATIC_INLINE void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config)
Vincent Coubard 0:f2542974c862 398 {
Vincent Coubard 0:f2542974c862 399 /*lint -e{845} // A zero has been given as right argument to operator '|'" */
Vincent Coubard 0:f2542974c862 400 NRF_GPIO->PIN_CNF[pin_number] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
Vincent Coubard 0:f2542974c862 401 | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
Vincent Coubard 0:f2542974c862 402 | (pull_config << GPIO_PIN_CNF_PULL_Pos)
Vincent Coubard 0:f2542974c862 403 | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
Vincent Coubard 0:f2542974c862 404 | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
Vincent Coubard 0:f2542974c862 405 }
Vincent Coubard 0:f2542974c862 406
vcoubard 1:ebc0e0ef0a11 407 __STATIC_INLINE void nrf_gpio_cfg_default(uint32_t pin_number)
vcoubard 1:ebc0e0ef0a11 408 {
vcoubard 1:ebc0e0ef0a11 409 /*lint -e{845} // A zero has been given as right argument to operator '|'" */
vcoubard 1:ebc0e0ef0a11 410 NRF_GPIO->PIN_CNF[pin_number] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
vcoubard 1:ebc0e0ef0a11 411 | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
vcoubard 1:ebc0e0ef0a11 412 | (NRF_GPIO_PIN_NOPULL << GPIO_PIN_CNF_PULL_Pos)
vcoubard 1:ebc0e0ef0a11 413 | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
vcoubard 1:ebc0e0ef0a11 414 | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
vcoubard 1:ebc0e0ef0a11 415 }
vcoubard 1:ebc0e0ef0a11 416
vcoubard 1:ebc0e0ef0a11 417 __STATIC_INLINE void nrf_gpio_cfg_watcher(uint32_t pin_number)
vcoubard 1:ebc0e0ef0a11 418 {
vcoubard 1:ebc0e0ef0a11 419 /*lint -e{845} // A zero has been given as right argument to operator '|'" */
vcoubard 1:ebc0e0ef0a11 420 uint32_t cnf = NRF_GPIO->PIN_CNF[pin_number] & ~GPIO_PIN_CNF_INPUT_Msk;
vcoubard 1:ebc0e0ef0a11 421 NRF_GPIO->PIN_CNF[pin_number] = cnf | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos);
vcoubard 1:ebc0e0ef0a11 422 }
vcoubard 1:ebc0e0ef0a11 423
vcoubard 1:ebc0e0ef0a11 424 __STATIC_INLINE void nrf_gpio_input_disconnect(uint32_t pin_number)
vcoubard 1:ebc0e0ef0a11 425 {
vcoubard 1:ebc0e0ef0a11 426 /*lint -e{845} // A zero has been given as right argument to operator '|'" */
vcoubard 1:ebc0e0ef0a11 427 uint32_t cnf = NRF_GPIO->PIN_CNF[pin_number] & ~GPIO_PIN_CNF_INPUT_Msk;
vcoubard 1:ebc0e0ef0a11 428 NRF_GPIO->PIN_CNF[pin_number] = cnf | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos);
vcoubard 1:ebc0e0ef0a11 429 }
vcoubard 1:ebc0e0ef0a11 430
vcoubard 1:ebc0e0ef0a11 431 __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)
Vincent Coubard 0:f2542974c862 432 {
Vincent Coubard 0:f2542974c862 433 /*lint -e{845} // A zero has been given as right argument to operator '|'" */
Vincent Coubard 0:f2542974c862 434 NRF_GPIO->PIN_CNF[pin_number] = (sense_config << GPIO_PIN_CNF_SENSE_Pos)
Vincent Coubard 0:f2542974c862 435 | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
Vincent Coubard 0:f2542974c862 436 | (pull_config << GPIO_PIN_CNF_PULL_Pos)
Vincent Coubard 0:f2542974c862 437 | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
Vincent Coubard 0:f2542974c862 438 | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
Vincent Coubard 0:f2542974c862 439 }
Vincent Coubard 0:f2542974c862 440
vcoubard 1:ebc0e0ef0a11 441 __STATIC_INLINE void nrf_gpio_cfg_sense_set(uint32_t pin_number, nrf_gpio_pin_sense_t sense_config)
vcoubard 1:ebc0e0ef0a11 442 {
vcoubard 1:ebc0e0ef0a11 443 /*lint -e{845} // A zero has been given as right argument to operator '|'" */
vcoubard 1:ebc0e0ef0a11 444 //uint32_t cnf = NRF_GPIO->PIN_CNF[pin_number] & ~GPIO_PIN_CNF_SENSE_Msk;
vcoubard 1:ebc0e0ef0a11 445 NRF_GPIO->PIN_CNF[pin_number] &= ~GPIO_PIN_CNF_SENSE_Msk;
vcoubard 1:ebc0e0ef0a11 446 NRF_GPIO->PIN_CNF[pin_number] |= (sense_config << GPIO_PIN_CNF_SENSE_Pos);
vcoubard 1:ebc0e0ef0a11 447 }
vcoubard 1:ebc0e0ef0a11 448
vcoubard 1:ebc0e0ef0a11 449 __STATIC_INLINE void nrf_gpio_pin_dir_set(uint32_t pin_number, nrf_gpio_pin_dir_t direction)
Vincent Coubard 0:f2542974c862 450 {
Vincent Coubard 0:f2542974c862 451 if(direction == NRF_GPIO_PIN_DIR_INPUT)
Vincent Coubard 0:f2542974c862 452 {
Vincent Coubard 0:f2542974c862 453 NRF_GPIO->PIN_CNF[pin_number] =
Vincent Coubard 0:f2542974c862 454 (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
Vincent Coubard 0:f2542974c862 455 | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
Vincent Coubard 0:f2542974c862 456 | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
Vincent Coubard 0:f2542974c862 457 | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
Vincent Coubard 0:f2542974c862 458 | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);
Vincent Coubard 0:f2542974c862 459 }
Vincent Coubard 0:f2542974c862 460 else
Vincent Coubard 0:f2542974c862 461 {
Vincent Coubard 0:f2542974c862 462 NRF_GPIO->DIRSET = (1UL << pin_number);
Vincent Coubard 0:f2542974c862 463 }
Vincent Coubard 0:f2542974c862 464 }
Vincent Coubard 0:f2542974c862 465
vcoubard 1:ebc0e0ef0a11 466 __STATIC_INLINE void nrf_gpio_pin_set(uint32_t pin_number)
Vincent Coubard 0:f2542974c862 467 {
Vincent Coubard 0:f2542974c862 468 NRF_GPIO->OUTSET = (1UL << pin_number);
Vincent Coubard 0:f2542974c862 469 }
Vincent Coubard 0:f2542974c862 470
vcoubard 1:ebc0e0ef0a11 471 __STATIC_INLINE void nrf_gpio_pin_clear(uint32_t pin_number)
Vincent Coubard 0:f2542974c862 472 {
Vincent Coubard 0:f2542974c862 473 NRF_GPIO->OUTCLR = (1UL << pin_number);
Vincent Coubard 0:f2542974c862 474 }
Vincent Coubard 0:f2542974c862 475
vcoubard 1:ebc0e0ef0a11 476 __STATIC_INLINE void nrf_gpio_pin_toggle(uint32_t pin_number)
Vincent Coubard 0:f2542974c862 477 {
Vincent Coubard 0:f2542974c862 478 const uint32_t pin_bit = 1UL << pin_number;
Vincent Coubard 0:f2542974c862 479 const uint32_t pin_state = ((NRF_GPIO->OUT >> pin_number) & 1UL);
vcoubard 1:ebc0e0ef0a11 480
Vincent Coubard 0:f2542974c862 481 if (pin_state == 0)
Vincent Coubard 0:f2542974c862 482 {
Vincent Coubard 0:f2542974c862 483 // Current state low, set high.
vcoubard 1:ebc0e0ef0a11 484 NRF_GPIO->OUTSET = pin_bit;
Vincent Coubard 0:f2542974c862 485 }
Vincent Coubard 0:f2542974c862 486 else
Vincent Coubard 0:f2542974c862 487 {
vcoubard 1:ebc0e0ef0a11 488 // Current state high, set low.
vcoubard 1:ebc0e0ef0a11 489 NRF_GPIO->OUTCLR = pin_bit;
Vincent Coubard 0:f2542974c862 490 }
Vincent Coubard 0:f2542974c862 491 }
Vincent Coubard 0:f2542974c862 492
vcoubard 1:ebc0e0ef0a11 493 __STATIC_INLINE void nrf_gpio_pin_write(uint32_t pin_number, uint32_t value)
Vincent Coubard 0:f2542974c862 494 {
Vincent Coubard 0:f2542974c862 495 if (value == 0)
Vincent Coubard 0:f2542974c862 496 {
Vincent Coubard 0:f2542974c862 497 nrf_gpio_pin_clear(pin_number);
Vincent Coubard 0:f2542974c862 498 }
Vincent Coubard 0:f2542974c862 499 else
Vincent Coubard 0:f2542974c862 500 {
Vincent Coubard 0:f2542974c862 501 nrf_gpio_pin_set(pin_number);
Vincent Coubard 0:f2542974c862 502 }
Vincent Coubard 0:f2542974c862 503 }
Vincent Coubard 0:f2542974c862 504
vcoubard 1:ebc0e0ef0a11 505 __STATIC_INLINE uint32_t nrf_gpio_pin_read(uint32_t pin_number)
Vincent Coubard 0:f2542974c862 506 {
Vincent Coubard 0:f2542974c862 507 return ((NRF_GPIO->IN >> pin_number) & 1UL);
Vincent Coubard 0:f2542974c862 508 }
Vincent Coubard 0:f2542974c862 509
vcoubard 1:ebc0e0ef0a11 510 __STATIC_INLINE uint32_t nrf_gpio_pins_read(void)
vcoubard 1:ebc0e0ef0a11 511 {
vcoubard 1:ebc0e0ef0a11 512 return NRF_GPIO->IN;
vcoubard 1:ebc0e0ef0a11 513 }
vcoubard 1:ebc0e0ef0a11 514
vcoubard 1:ebc0e0ef0a11 515 __STATIC_INLINE nrf_gpio_pin_sense_t nrf_gpio_pin_sense_get(uint32_t pin_number)
vcoubard 1:ebc0e0ef0a11 516 {
vcoubard 1:ebc0e0ef0a11 517 return (nrf_gpio_pin_sense_t)((NRF_GPIO->PIN_CNF[pin_number] & GPIO_PIN_CNF_SENSE_Msk) >> GPIO_PIN_CNF_SENSE_Pos);
vcoubard 1:ebc0e0ef0a11 518 }
vcoubard 1:ebc0e0ef0a11 519
vcoubard 1:ebc0e0ef0a11 520 __STATIC_INLINE void nrf_gpio_word_byte_write(volatile uint32_t * word_address, uint8_t byte_no, uint8_t value)
Vincent Coubard 0:f2542974c862 521 {
Vincent Coubard 0:f2542974c862 522 *((volatile uint8_t*)(word_address) + byte_no) = value;
Vincent Coubard 0:f2542974c862 523 }
Vincent Coubard 0:f2542974c862 524
vcoubard 1:ebc0e0ef0a11 525 __STATIC_INLINE uint8_t nrf_gpio_word_byte_read(const volatile uint32_t* word_address, uint8_t byte_no)
Vincent Coubard 0:f2542974c862 526 {
Vincent Coubard 0:f2542974c862 527 return (*((const volatile uint8_t*)(word_address) + byte_no));
Vincent Coubard 0:f2542974c862 528 }
Vincent Coubard 0:f2542974c862 529
vcoubard 1:ebc0e0ef0a11 530 __STATIC_INLINE void nrf_gpio_port_dir_set(nrf_gpio_port_select_t port, nrf_gpio_port_dir_t dir)
Vincent Coubard 0:f2542974c862 531 {
Vincent Coubard 0:f2542974c862 532 if (dir == NRF_GPIO_PORT_DIR_OUTPUT)
Vincent Coubard 0:f2542974c862 533 {
Vincent Coubard 0:f2542974c862 534 nrf_gpio_word_byte_write(&NRF_GPIO->DIRSET, port, 0xFF);
Vincent Coubard 0:f2542974c862 535 }
Vincent Coubard 0:f2542974c862 536 else
Vincent Coubard 0:f2542974c862 537 {
Vincent Coubard 0:f2542974c862 538 nrf_gpio_range_cfg_input(port*8, (port+1)*8-1, NRF_GPIO_PIN_NOPULL);
Vincent Coubard 0:f2542974c862 539 }
Vincent Coubard 0:f2542974c862 540 }
Vincent Coubard 0:f2542974c862 541
vcoubard 1:ebc0e0ef0a11 542 __STATIC_INLINE uint8_t nrf_gpio_port_read(nrf_gpio_port_select_t port)
Vincent Coubard 0:f2542974c862 543 {
Vincent Coubard 0:f2542974c862 544 return nrf_gpio_word_byte_read(&NRF_GPIO->IN, port);
Vincent Coubard 0:f2542974c862 545 }
Vincent Coubard 0:f2542974c862 546
vcoubard 1:ebc0e0ef0a11 547 __STATIC_INLINE void nrf_gpio_port_write(nrf_gpio_port_select_t port, uint8_t value)
Vincent Coubard 0:f2542974c862 548 {
Vincent Coubard 0:f2542974c862 549 nrf_gpio_word_byte_write(&NRF_GPIO->OUT, port, value);
Vincent Coubard 0:f2542974c862 550 }
Vincent Coubard 0:f2542974c862 551
vcoubard 1:ebc0e0ef0a11 552 __STATIC_INLINE void nrf_gpio_port_set(nrf_gpio_port_select_t port, uint8_t set_mask)
Vincent Coubard 0:f2542974c862 553 {
Vincent Coubard 0:f2542974c862 554 nrf_gpio_word_byte_write(&NRF_GPIO->OUTSET, port, set_mask);
Vincent Coubard 0:f2542974c862 555 }
Vincent Coubard 0:f2542974c862 556
vcoubard 1:ebc0e0ef0a11 557 __STATIC_INLINE void nrf_gpio_port_clear(nrf_gpio_port_select_t port, uint8_t clr_mask)
Vincent Coubard 0:f2542974c862 558 {
Vincent Coubard 0:f2542974c862 559 nrf_gpio_word_byte_write(&NRF_GPIO->OUTCLR, port, clr_mask);
Vincent Coubard 0:f2542974c862 560 }
vcoubard 1:ebc0e0ef0a11 561 #endif //SUPPRESS_INLINE_IMPLEMENTATION
Vincent Coubard 0:f2542974c862 562 /** @} */
Vincent Coubard 0:f2542974c862 563
vcoubard 1:ebc0e0ef0a11 564 #endif