Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API Buffer mbed
Fork of BLE_LEDBlinker by
nrf_gpio.h
00001 /* 00002 * Copyright (c) Nordic Semiconductor ASA 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without modification, 00006 * are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, this 00009 * list of conditions and the following disclaimer. 00010 * 00011 * 2. Redistributions in binary form must reproduce the above copyright notice, this 00012 * list of conditions and the following disclaimer in the documentation and/or 00013 * other materials provided with the distribution. 00014 * 00015 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other 00016 * contributors to this software may be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00021 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00022 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00023 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00024 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00025 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00026 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00027 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 * 00031 */ 00032 00033 #ifndef NRF_GPIO_H__ 00034 #define NRF_GPIO_H__ 00035 00036 #include "nrf51.h" 00037 #include "nrf51_bitfields.h" 00038 #include <stdbool.h> 00039 00040 /** 00041 * @defgroup nrf_gpio GPIO abstraction 00042 * @{ 00043 * @ingroup nrf_drivers 00044 * @brief GPIO pin abstraction and port abstraction for reading and writing byte-wise to GPIO ports. 00045 * 00046 * Here, the GPIO ports are defined as follows: 00047 * - Port 0 -> pin 0-7 00048 * - Port 1 -> pin 8-15 00049 * - Port 2 -> pin 16-23 00050 * - Port 3 -> pin 24-31 00051 */ 00052 00053 #define NUMBER_OF_PINS 32 00054 00055 /** 00056 * @enum nrf_gpio_port_dir_t 00057 * @brief Enumerator used for setting the direction of a GPIO port. 00058 */ 00059 typedef enum 00060 { 00061 NRF_GPIO_PORT_DIR_OUTPUT, ///< Output 00062 NRF_GPIO_PORT_DIR_INPUT ///< Input 00063 } nrf_gpio_port_dir_t; 00064 00065 /** 00066 * @enum nrf_gpio_pin_dir_t 00067 * Pin direction definitions. 00068 */ 00069 typedef enum 00070 { 00071 NRF_GPIO_PIN_DIR_INPUT, ///< Input 00072 NRF_GPIO_PIN_DIR_OUTPUT ///< Output 00073 } nrf_gpio_pin_dir_t; 00074 00075 /** 00076 * @enum nrf_gpio_port_select_t 00077 * @brief Enumerator used for selecting between port 0 - 3. 00078 */ 00079 typedef enum 00080 { 00081 NRF_GPIO_PORT_SELECT_PORT0 = 0, ///< Port 0 (GPIO pin 0-7) 00082 NRF_GPIO_PORT_SELECT_PORT1, ///< Port 1 (GPIO pin 8-15) 00083 NRF_GPIO_PORT_SELECT_PORT2, ///< Port 2 (GPIO pin 16-23) 00084 NRF_GPIO_PORT_SELECT_PORT3, ///< Port 3 (GPIO pin 24-31) 00085 } nrf_gpio_port_select_t; 00086 00087 /** 00088 * @enum nrf_gpio_pin_pull_t 00089 * @brief Enumerator used for selecting the pin to be pulled down or up at the time of pin configuration 00090 */ 00091 typedef enum 00092 { 00093 NRF_GPIO_PIN_NOPULL = GPIO_PIN_CNF_PULL_Disabled, ///< Pin pullup resistor disabled 00094 NRF_GPIO_PIN_PULLDOWN = GPIO_PIN_CNF_PULL_Pulldown, ///< Pin pulldown resistor enabled 00095 NRF_GPIO_PIN_PULLUP = GPIO_PIN_CNF_PULL_Pullup, ///< Pin pullup resistor enabled 00096 } nrf_gpio_pin_pull_t; 00097 00098 /** 00099 * @enum nrf_gpio_pin_sense_t 00100 * @brief Enumerator used for selecting the pin to sense high or low level on the pin input. 00101 */ 00102 typedef enum 00103 { 00104 NRF_GPIO_PIN_NOSENSE = GPIO_PIN_CNF_SENSE_Disabled, ///< Pin sense level disabled. 00105 NRF_GPIO_PIN_SENSE_LOW = GPIO_PIN_CNF_SENSE_Low, ///< Pin sense low level. 00106 NRF_GPIO_PIN_SENSE_HIGH = GPIO_PIN_CNF_SENSE_High, ///< Pin sense high level. 00107 } nrf_gpio_pin_sense_t; 00108 00109 /** 00110 * @brief Function for configuring the GPIO pin range as outputs with normal drive strength. 00111 * This function can be used to configure pin range as simple output with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases). 00112 * 00113 * @param pin_range_start specifies the start number (inclusive) in the range of pin numbers to be configured (allowed values 0-30) 00114 * 00115 * @param pin_range_end specifies the end number (inclusive) in the range of pin numbers to be configured (allowed values 0-30) 00116 * 00117 * @note For configuring only one pin as output use @ref nrf_gpio_cfg_output 00118 * Sense capability on the pin is disabled, and input is disconnected from the buffer as the pins are configured as output. 00119 */ 00120 __STATIC_INLINE void nrf_gpio_range_cfg_output(uint32_t pin_range_start, uint32_t pin_range_end); 00121 00122 /** 00123 * @brief Function for configuring the GPIO pin range as inputs with given initial value set, hiding inner details. 00124 * This function can be used to configure pin range as simple input. 00125 * 00126 * @param pin_range_start specifies the start number (inclusive) in the range of pin numbers to be configured (allowed values 0-30) 00127 * 00128 * @param pin_range_end specifies the end number (inclusive) in the range of pin numbers to be configured (allowed values 0-30) 00129 * 00130 * @param pull_config State of the pin range pull resistor (no pull, pulled down or pulled high) 00131 * 00132 * @note For configuring only one pin as input use @ref nrf_gpio_cfg_input 00133 * Sense capability on the pin is disabled, and input is connected to buffer so that the GPIO->IN register is readable 00134 */ 00135 __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); 00136 00137 /** 00138 * @brief Function for configuring the given GPIO pin number as output with given initial value set, hiding inner details. 00139 * This function can be used to configure pin range as simple input with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases). 00140 * 00141 * @param pin_number specifies the pin number (allowed values 0-30) 00142 * 00143 * @note Sense capability on the pin is disabled, and input is disconnected from the buffer as the pins are configured as output. 00144 */ 00145 __STATIC_INLINE void nrf_gpio_cfg_output(uint32_t pin_number); 00146 00147 /** 00148 * @brief Function for configuring the given GPIO pin number as input with given initial value set, hiding inner details. 00149 * This function can be used to configure pin range as simple input with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases). 00150 * 00151 * @param pin_number Specifies the pin number (allowed values 0-30). 00152 * @param pull_config State of the pin range pull resistor (no pull, pulled down or pulled high). 00153 * 00154 * @note Sense capability on the pin is disabled, and input is connected to buffer so that the GPIO->IN register is readable 00155 */ 00156 __STATIC_INLINE void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config); 00157 00158 /** 00159 * @brief Function for reseting pin configuration to its default state. 00160 * 00161 * @param pin_number Specifies the pin number (allowed values 0-30). 00162 */ 00163 __STATIC_INLINE void nrf_gpio_cfg_default(uint32_t pin_number); 00164 00165 /** 00166 * @brief Function for configuring the given GPIO pin number as a watcher. Only input is connected. 00167 * 00168 * @param pin_number Specifies the pin number (allowed values 0-30). 00169 * 00170 */ 00171 __STATIC_INLINE void nrf_gpio_cfg_watcher(uint32_t pin_number); 00172 00173 /** 00174 * @brief Function for disconnecting input for the given GPIO. 00175 * 00176 * @param pin_number Specifies the pin number (allowed values 0-30). 00177 * 00178 */ 00179 __STATIC_INLINE void nrf_gpio_input_disconnect(uint32_t pin_number); 00180 00181 /** 00182 * @brief Function for configuring the given GPIO pin number as input with given initial value set, hiding inner details. 00183 * This function can be used to configure pin range as simple input with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases). 00184 * Sense capability on the pin is configurable, and input is connected to buffer so that the GPIO->IN register is readable. 00185 * 00186 * @param pin_number Specifies the pin number (allowed values 0-30). 00187 * @param pull_config State of the pin pull resistor (no pull, pulled down or pulled high). 00188 * @param sense_config Sense level of the pin (no sense, sense low or sense high). 00189 */ 00190 __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); 00191 00192 /** 00193 * @brief Function for configuring sense level for the given GPIO. 00194 * 00195 * @param pin_number Specifies the pin number of gpio pin numbers to be configured (allowed values 0-30). 00196 * @param sense_config Sense configuration. 00197 * 00198 */ 00199 __STATIC_INLINE void nrf_gpio_cfg_sense_set(uint32_t pin_number, nrf_gpio_pin_sense_t sense_config); 00200 00201 /** 00202 * @brief Function for setting the direction for a GPIO pin. 00203 * 00204 * @param pin_number specifies the pin number [0:31] for which to 00205 * set the direction. 00206 * 00207 * @param direction specifies the direction 00208 */ 00209 __STATIC_INLINE void nrf_gpio_pin_dir_set(uint32_t pin_number, nrf_gpio_pin_dir_t direction); 00210 00211 /** 00212 * @brief Function for setting a GPIO pin. 00213 * 00214 * Note that the pin must be configured as an output for this 00215 * function to have any effect. 00216 * 00217 * @param pin_number specifies the pin number [0:31] to 00218 * set. 00219 */ 00220 __STATIC_INLINE void nrf_gpio_pin_set(uint32_t pin_number); 00221 00222 /** 00223 * @brief Function for clearing a GPIO pin. 00224 * 00225 * Note that the pin must be configured as an output for this 00226 * function to have any effect. 00227 * 00228 * @param pin_number specifies the pin number [0:31] to 00229 * clear. 00230 */ 00231 __STATIC_INLINE void nrf_gpio_pin_clear(uint32_t pin_number); 00232 00233 /** 00234 * @brief Function for toggling a GPIO pin. 00235 * 00236 * Note that the pin must be configured as an output for this 00237 * function to have any effect. 00238 * 00239 * @param pin_number specifies the pin number [0:31] to 00240 * toggle. 00241 */ 00242 __STATIC_INLINE void nrf_gpio_pin_toggle(uint32_t pin_number); 00243 00244 /** 00245 * @brief Function for writing a value to a GPIO pin. 00246 * 00247 * Note that the pin must be configured as an output for this 00248 * function to have any effect. 00249 * 00250 * @param pin_number specifies the pin number [0:31] to 00251 * write. 00252 * 00253 * @param value specifies the value to be written to the pin. 00254 * @arg 0 clears the pin 00255 * @arg >=1 sets the pin. 00256 */ 00257 __STATIC_INLINE void nrf_gpio_pin_write(uint32_t pin_number, uint32_t value); 00258 00259 /** 00260 * @brief Function for reading the input level of a GPIO pin. 00261 * 00262 * Note that the pin must have input connected for the value 00263 * returned from this function to be valid. 00264 * 00265 * @param pin_number specifies the pin number [0:31] to 00266 * read. 00267 * 00268 * @return 00269 * @retval 0 if the pin input level is low. 00270 * @retval 1 if the pin input level is high. 00271 * @retval > 1 should never occur. 00272 */ 00273 __STATIC_INLINE uint32_t nrf_gpio_pin_read(uint32_t pin_number); 00274 00275 /** 00276 * @brief Function for reading the input level of all GPIO pins. 00277 * 00278 * Note that the pin must have input connected for the value 00279 * returned from this function to be valid. 00280 * 00281 * @retval Status of input of all pins 00282 */ 00283 __STATIC_INLINE uint32_t nrf_gpio_pins_read(void); 00284 00285 /** 00286 * @brief Function for reading the sense configuration of a GPIO pin. 00287 * 00288 * @param pin_number specifies the pin number [0:31] to 00289 * read. 00290 * 00291 * @retval Sense configuration 00292 */ 00293 __STATIC_INLINE nrf_gpio_pin_sense_t nrf_gpio_pin_sense_get(uint32_t pin_number); 00294 00295 /** 00296 * @brief Generic function for writing a single byte of a 32 bit word at a given 00297 * address. 00298 * 00299 * This function should not be called from outside the nrf_gpio 00300 * abstraction layer. 00301 * 00302 * @param word_address is the address of the word to be written. 00303 * 00304 * @param byte_no is the word byte number (0-3) to be written. 00305 * 00306 * @param value is the value to be written to byte "byte_no" of word 00307 * at address "word_address" 00308 */ 00309 __STATIC_INLINE void nrf_gpio_word_byte_write(volatile uint32_t * word_address, uint8_t byte_no, uint8_t value); 00310 00311 /** 00312 * @brief Generic function for reading a single byte of a 32 bit word at a given 00313 * address. 00314 * 00315 * This function should not be called from outside the nrf_gpio 00316 * abstraction layer. 00317 * 00318 * @param word_address is the address of the word to be read. 00319 * 00320 * @param byte_no is the byte number (0-3) of the word to be read. 00321 * 00322 * @return byte "byte_no" of word at address "word_address". 00323 */ 00324 __STATIC_INLINE uint8_t nrf_gpio_word_byte_read(const volatile uint32_t* word_address, uint8_t byte_no); 00325 00326 /** 00327 * @brief Function for setting the direction of a port. 00328 * 00329 * @param port is the port for which to set the direction. 00330 * 00331 * @param dir direction to be set for this port. 00332 */ 00333 __STATIC_INLINE void nrf_gpio_port_dir_set(nrf_gpio_port_select_t port, nrf_gpio_port_dir_t dir); 00334 00335 /** 00336 * @brief Function for reading a GPIO port. 00337 * 00338 * @param port is the port to read. 00339 * 00340 * @return the input value on this port. 00341 */ 00342 __STATIC_INLINE uint8_t nrf_gpio_port_read(nrf_gpio_port_select_t port); 00343 00344 /** 00345 * @brief Function for writing to a GPIO port. 00346 * 00347 * @param port is the port to write. 00348 * 00349 * @param value is the value to write to this port. 00350 * 00351 * @sa nrf_gpio_port_dir_set() 00352 */ 00353 __STATIC_INLINE void nrf_gpio_port_write(nrf_gpio_port_select_t port, uint8_t value); 00354 00355 /** 00356 * @brief Function for setting individual pins on GPIO port. 00357 * 00358 * @param port is the port for which to set the pins. 00359 * 00360 * @param set_mask is a mask specifying which pins to set. A bit 00361 * set to 1 indicates that the corresponding port pin shall be 00362 * set. 00363 * 00364 * @sa nrf_gpio_port_dir_set() 00365 */ 00366 __STATIC_INLINE void nrf_gpio_port_set(nrf_gpio_port_select_t port, uint8_t set_mask); 00367 00368 /** 00369 * @brief Function for clearing individual pins on GPIO port. 00370 * 00371 * @param port is the port for which to clear the pins. 00372 * 00373 * @param clr_mask is a mask specifying which pins to clear. A bit 00374 * set to 1 indicates that the corresponding port pin shall be 00375 * cleared. 00376 * 00377 * @sa nrf_gpio_port_dir_set() 00378 */ 00379 __STATIC_INLINE void nrf_gpio_port_clear(nrf_gpio_port_select_t port, uint8_t clr_mask); 00380 00381 #ifndef SUPPRESS_INLINE_IMPLEMENTATION 00382 __STATIC_INLINE void nrf_gpio_range_cfg_output(uint32_t pin_range_start, uint32_t pin_range_end) 00383 { 00384 /*lint -e{845} // A zero has been given as right argument to operator '|'" */ 00385 for (; pin_range_start <= pin_range_end; pin_range_start++) 00386 { 00387 NRF_GPIO->PIN_CNF[pin_range_start] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) 00388 | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) 00389 | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) 00390 | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos) 00391 | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); 00392 } 00393 } 00394 00395 __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) 00396 { 00397 /*lint -e{845} // A zero has been given as right argument to operator '|'" */ 00398 for (; pin_range_start <= pin_range_end; pin_range_start++) 00399 { 00400 NRF_GPIO->PIN_CNF[pin_range_start] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) 00401 | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) 00402 | (pull_config << GPIO_PIN_CNF_PULL_Pos) 00403 | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) 00404 | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos); 00405 } 00406 } 00407 00408 __STATIC_INLINE void nrf_gpio_cfg_output(uint32_t pin_number) 00409 { 00410 /*lint -e{845} // A zero has been given as right argument to operator '|'" */ 00411 NRF_GPIO->PIN_CNF[pin_number] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) 00412 | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) 00413 | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) 00414 | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos) 00415 | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); 00416 } 00417 00418 __STATIC_INLINE void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config) 00419 { 00420 /*lint -e{845} // A zero has been given as right argument to operator '|'" */ 00421 NRF_GPIO->PIN_CNF[pin_number] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) 00422 | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) 00423 | (pull_config << GPIO_PIN_CNF_PULL_Pos) 00424 | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) 00425 | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos); 00426 } 00427 00428 __STATIC_INLINE void nrf_gpio_cfg_default(uint32_t pin_number) 00429 { 00430 /*lint -e{845} // A zero has been given as right argument to operator '|'" */ 00431 NRF_GPIO->PIN_CNF[pin_number] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) 00432 | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) 00433 | (NRF_GPIO_PIN_NOPULL << GPIO_PIN_CNF_PULL_Pos) 00434 | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos) 00435 | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos); 00436 } 00437 00438 __STATIC_INLINE void nrf_gpio_cfg_watcher(uint32_t pin_number) 00439 { 00440 /*lint -e{845} // A zero has been given as right argument to operator '|'" */ 00441 uint32_t cnf = NRF_GPIO->PIN_CNF[pin_number] & ~GPIO_PIN_CNF_INPUT_Msk; 00442 NRF_GPIO->PIN_CNF[pin_number] = cnf | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos); 00443 } 00444 00445 __STATIC_INLINE void nrf_gpio_input_disconnect(uint32_t pin_number) 00446 { 00447 /*lint -e{845} // A zero has been given as right argument to operator '|'" */ 00448 uint32_t cnf = NRF_GPIO->PIN_CNF[pin_number] & ~GPIO_PIN_CNF_INPUT_Msk; 00449 NRF_GPIO->PIN_CNF[pin_number] = cnf | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos); 00450 } 00451 00452 __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) 00453 { 00454 /*lint -e{845} // A zero has been given as right argument to operator '|'" */ 00455 NRF_GPIO->PIN_CNF[pin_number] = (sense_config << GPIO_PIN_CNF_SENSE_Pos) 00456 | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) 00457 | (pull_config << GPIO_PIN_CNF_PULL_Pos) 00458 | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) 00459 | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos); 00460 } 00461 00462 __STATIC_INLINE void nrf_gpio_cfg_sense_set(uint32_t pin_number, nrf_gpio_pin_sense_t sense_config) 00463 { 00464 /*lint -e{845} // A zero has been given as right argument to operator '|'" */ 00465 //uint32_t cnf = NRF_GPIO->PIN_CNF[pin_number] & ~GPIO_PIN_CNF_SENSE_Msk; 00466 NRF_GPIO->PIN_CNF[pin_number] &= ~GPIO_PIN_CNF_SENSE_Msk; 00467 NRF_GPIO->PIN_CNF[pin_number] |= (sense_config << GPIO_PIN_CNF_SENSE_Pos); 00468 } 00469 00470 __STATIC_INLINE void nrf_gpio_pin_dir_set(uint32_t pin_number, nrf_gpio_pin_dir_t direction) 00471 { 00472 if(direction == NRF_GPIO_PIN_DIR_INPUT) 00473 { 00474 NRF_GPIO->PIN_CNF[pin_number] = 00475 (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) 00476 | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) 00477 | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) 00478 | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) 00479 | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos); 00480 } 00481 else 00482 { 00483 NRF_GPIO->DIRSET = (1UL << pin_number); 00484 } 00485 } 00486 00487 __STATIC_INLINE void nrf_gpio_pin_set(uint32_t pin_number) 00488 { 00489 NRF_GPIO->OUTSET = (1UL << pin_number); 00490 } 00491 00492 __STATIC_INLINE void nrf_gpio_pin_clear(uint32_t pin_number) 00493 { 00494 NRF_GPIO->OUTCLR = (1UL << pin_number); 00495 } 00496 00497 __STATIC_INLINE void nrf_gpio_pin_toggle(uint32_t pin_number) 00498 { 00499 const uint32_t pin_bit = 1UL << pin_number; 00500 const uint32_t pin_state = ((NRF_GPIO->OUT >> pin_number) & 1UL); 00501 00502 if (pin_state == 0) 00503 { 00504 // Current state low, set high. 00505 NRF_GPIO->OUTSET = pin_bit; 00506 } 00507 else 00508 { 00509 // Current state high, set low. 00510 NRF_GPIO->OUTCLR = pin_bit; 00511 } 00512 } 00513 00514 __STATIC_INLINE void nrf_gpio_pin_write(uint32_t pin_number, uint32_t value) 00515 { 00516 if (value == 0) 00517 { 00518 nrf_gpio_pin_clear(pin_number); 00519 } 00520 else 00521 { 00522 nrf_gpio_pin_set(pin_number); 00523 } 00524 } 00525 00526 __STATIC_INLINE uint32_t nrf_gpio_pin_read(uint32_t pin_number) 00527 { 00528 return ((NRF_GPIO->IN >> pin_number) & 1UL); 00529 } 00530 00531 __STATIC_INLINE uint32_t nrf_gpio_pins_read(void) 00532 { 00533 return NRF_GPIO->IN; 00534 } 00535 00536 __STATIC_INLINE nrf_gpio_pin_sense_t nrf_gpio_pin_sense_get(uint32_t pin_number) 00537 { 00538 return (nrf_gpio_pin_sense_t)((NRF_GPIO->PIN_CNF[pin_number] & GPIO_PIN_CNF_SENSE_Msk) >> GPIO_PIN_CNF_SENSE_Pos); 00539 } 00540 00541 __STATIC_INLINE void nrf_gpio_word_byte_write(volatile uint32_t * word_address, uint8_t byte_no, uint8_t value) 00542 { 00543 *((volatile uint8_t*)(word_address) + byte_no) = value; 00544 } 00545 00546 __STATIC_INLINE uint8_t nrf_gpio_word_byte_read(const volatile uint32_t* word_address, uint8_t byte_no) 00547 { 00548 return (*((const volatile uint8_t*)(word_address) + byte_no)); 00549 } 00550 00551 __STATIC_INLINE void nrf_gpio_port_dir_set(nrf_gpio_port_select_t port, nrf_gpio_port_dir_t dir) 00552 { 00553 if (dir == NRF_GPIO_PORT_DIR_OUTPUT) 00554 { 00555 nrf_gpio_word_byte_write(&NRF_GPIO->DIRSET, port, 0xFF); 00556 } 00557 else 00558 { 00559 nrf_gpio_range_cfg_input(port*8, (port+1)*8-1, NRF_GPIO_PIN_NOPULL); 00560 } 00561 } 00562 00563 __STATIC_INLINE uint8_t nrf_gpio_port_read(nrf_gpio_port_select_t port) 00564 { 00565 return nrf_gpio_word_byte_read(&NRF_GPIO->IN, port); 00566 } 00567 00568 __STATIC_INLINE void nrf_gpio_port_write(nrf_gpio_port_select_t port, uint8_t value) 00569 { 00570 nrf_gpio_word_byte_write(&NRF_GPIO->OUT, port, value); 00571 } 00572 00573 __STATIC_INLINE void nrf_gpio_port_set(nrf_gpio_port_select_t port, uint8_t set_mask) 00574 { 00575 nrf_gpio_word_byte_write(&NRF_GPIO->OUTSET, port, set_mask); 00576 } 00577 00578 __STATIC_INLINE void nrf_gpio_port_clear(nrf_gpio_port_select_t port, uint8_t clr_mask) 00579 { 00580 nrf_gpio_word_byte_write(&NRF_GPIO->OUTCLR, port, clr_mask); 00581 } 00582 #endif //SUPPRESS_INLINE_IMPLEMENTATION 00583 /** @} */ 00584 00585 #endif
Generated on Tue Jul 12 2022 19:00:01 by
1.7.2
