test
Fork of nrf51-sdk by
Embed:
(wiki syntax)
Show/hide line numbers
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 #ifndef NRF_GPIO_H__ 00033 #define NRF_GPIO_H__ 00034 00035 #include "nrf.h" 00036 #include <stdbool.h> 00037 00038 /** 00039 * @defgroup nrf_gpio GPIO abstraction 00040 * @{ 00041 * @ingroup nrf_drivers 00042 * @brief GPIO pin abstraction and port abstraction for reading and writing byte-wise to GPIO ports. 00043 * 00044 * Here, the GPIO ports are defined as follows: 00045 * - Port 0 -> pin 0-7 00046 * - Port 1 -> pin 8-15 00047 * - Port 2 -> pin 16-23 00048 * - Port 3 -> pin 24-31 00049 */ 00050 00051 #define NUMBER_OF_PINS 32 00052 00053 /** 00054 * @brief Enumerator used for selecting between port 0 - 3. 00055 */ 00056 typedef enum 00057 { 00058 NRF_GPIO_PORT_SELECT_PORT0 = 0, ///< Port 0 (GPIO pin 0-7) 00059 NRF_GPIO_PORT_SELECT_PORT1, ///< Port 1 (GPIO pin 8-15) 00060 NRF_GPIO_PORT_SELECT_PORT2, ///< Port 2 (GPIO pin 16-23) 00061 NRF_GPIO_PORT_SELECT_PORT3, ///< Port 3 (GPIO pin 24-31) 00062 } nrf_gpio_port_select_t; 00063 00064 /** 00065 * @brief Enumerator used for setting the direction of a GPIO port. 00066 */ 00067 typedef enum 00068 { 00069 NRF_GPIO_PORT_DIR_OUTPUT, ///< Output 00070 NRF_GPIO_PORT_DIR_INPUT ///< Input 00071 } nrf_gpio_port_dir_t; 00072 00073 /** 00074 * @brief Pin direction definitions. 00075 */ 00076 typedef enum 00077 { 00078 NRF_GPIO_PIN_DIR_INPUT = GPIO_PIN_CNF_DIR_Input, ///< Input 00079 NRF_GPIO_PIN_DIR_OUTPUT = GPIO_PIN_CNF_DIR_Output ///< Output 00080 } nrf_gpio_pin_dir_t; 00081 00082 /** 00083 * @brief Connection of input buffer 00084 */ 00085 typedef enum 00086 { 00087 NRF_GPIO_PIN_INPUT_CONNECT = GPIO_PIN_CNF_INPUT_Connect, ///< Connect input buffer 00088 NRF_GPIO_PIN_INPUT_DISCONNECT = GPIO_PIN_CNF_INPUT_Disconnect ///< Disconnect input buffer 00089 } nrf_gpio_pin_input_t; 00090 00091 /** 00092 * @brief Enumerator used for selecting the pin to be pulled down or up at the time of pin configuration 00093 */ 00094 typedef enum 00095 { 00096 NRF_GPIO_PIN_NOPULL = GPIO_PIN_CNF_PULL_Disabled, ///< Pin pullup resistor disabled 00097 NRF_GPIO_PIN_PULLDOWN = GPIO_PIN_CNF_PULL_Pulldown, ///< Pin pulldown resistor enabled 00098 NRF_GPIO_PIN_PULLUP = GPIO_PIN_CNF_PULL_Pullup, ///< Pin pullup resistor enabled 00099 } nrf_gpio_pin_pull_t; 00100 00101 /** 00102 * @brief Enumerator used for selecting output drive mode 00103 */ 00104 typedef enum 00105 { 00106 NRF_GPIO_PIN_S0S1 = GPIO_PIN_CNF_DRIVE_S0S1, ///< !< Standard '0', standard '1' 00107 NRF_GPIO_PIN_H0S1 = GPIO_PIN_CNF_DRIVE_H0S1, ///< !< High drive '0', standard '1' 00108 NRF_GPIO_PIN_S0H1 = GPIO_PIN_CNF_DRIVE_S0H1, ///< !< Standard '0', high drive '1' 00109 NRF_GPIO_PIN_H0H1 = GPIO_PIN_CNF_DRIVE_H0H1, ///< !< High drive '0', high 'drive '1'' 00110 NRF_GPIO_PIN_D0S1 = GPIO_PIN_CNF_DRIVE_D0S1, ///< !< Disconnect '0' standard '1' 00111 NRF_GPIO_PIN_D0H1 = GPIO_PIN_CNF_DRIVE_D0H1, ///< !< Disconnect '0', high drive '1' 00112 NRF_GPIO_PIN_S0D1 = GPIO_PIN_CNF_DRIVE_S0D1, ///< !< Standard '0'. disconnect '1' 00113 NRF_GPIO_PIN_H0D1 = GPIO_PIN_CNF_DRIVE_H0D1, ///< !< High drive '0', disconnect '1' 00114 } nrf_gpio_pin_drive_t; 00115 00116 /** 00117 * @brief Enumerator used for selecting the pin to sense high or low level on the pin input. 00118 */ 00119 typedef enum 00120 { 00121 NRF_GPIO_PIN_NOSENSE = GPIO_PIN_CNF_SENSE_Disabled, ///< Pin sense level disabled. 00122 NRF_GPIO_PIN_SENSE_LOW = GPIO_PIN_CNF_SENSE_Low, ///< Pin sense low level. 00123 NRF_GPIO_PIN_SENSE_HIGH = GPIO_PIN_CNF_SENSE_High, ///< Pin sense high level. 00124 } nrf_gpio_pin_sense_t; 00125 00126 00127 /** 00128 * @brief Function for configuring the GPIO pin range as outputs with normal drive strength. 00129 * This function can be used to configure pin range as simple output with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases). 00130 * 00131 * @param pin_range_start specifies the start number (inclusive) in the range of pin numbers to be configured (allowed values 0-30) 00132 * 00133 * @param pin_range_end specifies the end number (inclusive) in the range of pin numbers to be configured (allowed values 0-30) 00134 * 00135 * @note For configuring only one pin as output use @ref nrf_gpio_cfg_output 00136 * Sense capability on the pin is disabled, and input is disconnected from the buffer as the pins are configured as output. 00137 */ 00138 __STATIC_INLINE void nrf_gpio_range_cfg_output(uint32_t pin_range_start, uint32_t pin_range_end); 00139 00140 /** 00141 * @brief Function for configuring the GPIO pin range as inputs with given initial value set, hiding inner details. 00142 * This function can be used to configure pin range as simple input. 00143 * 00144 * @param pin_range_start specifies the start number (inclusive) in the range of pin numbers to be configured (allowed values 0-30) 00145 * 00146 * @param pin_range_end specifies the end number (inclusive) in the range of pin numbers to be configured (allowed values 0-30) 00147 * 00148 * @param pull_config State of the pin range pull resistor (no pull, pulled down or pulled high) 00149 * 00150 * @note For configuring only one pin as input use @ref nrf_gpio_cfg_input 00151 * Sense capability on the pin is disabled, and input is connected to buffer so that the GPIO->IN register is readable 00152 */ 00153 __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); 00154 00155 /** 00156 * @brief Pin configuration function 00157 * 00158 * The main pin configuration function. 00159 * This function allows to set any aspect in PIN_CNF register. 00160 * @param pin_number Specifies the pin number (allowed values 0-31). 00161 * @param dir Pin direction 00162 * @param input Connect or disconnect input buffer 00163 * @param pull Pull configuration 00164 * @param drive Drive configuration 00165 * @param sense Pin sensing mechanism 00166 */ 00167 __STATIC_INLINE void nrf_gpio_cfg( 00168 uint32_t pin_number, 00169 nrf_gpio_pin_dir_t dir, 00170 nrf_gpio_pin_input_t input, 00171 nrf_gpio_pin_pull_t pull, 00172 nrf_gpio_pin_drive_t drive, 00173 nrf_gpio_pin_sense_t sense); 00174 00175 /** 00176 * @brief Function for configuring the given GPIO pin number as output with given initial value set, hiding inner details. 00177 * This function can be used to configure pin range as simple input with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases). 00178 * 00179 * @param pin_number specifies the pin number (allowed values 0-31) 00180 * 00181 * @note Sense capability on the pin is disabled, and input is disconnected from the buffer as the pins are configured as output. 00182 */ 00183 __STATIC_INLINE void nrf_gpio_cfg_output(uint32_t pin_number); 00184 00185 /** 00186 * @brief Function for configuring the given GPIO pin number as input with given initial value set, hiding inner details. 00187 * This function can be used to configure pin range as simple input with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases). 00188 * 00189 * @param pin_number Specifies the pin number (allowed values 0-30). 00190 * @param pull_config State of the pin range pull resistor (no pull, pulled down or pulled high). 00191 * 00192 * @note Sense capability on the pin is disabled, and input is connected to buffer so that the GPIO->IN register is readable 00193 */ 00194 __STATIC_INLINE void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config); 00195 00196 /** 00197 * @brief Function for reseting pin configuration to its default state. 00198 * 00199 * @param pin_number Specifies the pin number (allowed values 0-31). 00200 */ 00201 __STATIC_INLINE void nrf_gpio_cfg_default(uint32_t pin_number); 00202 00203 /** 00204 * @brief Function for configuring the given GPIO pin number as a watcher. Only input is connected. 00205 * 00206 * @param pin_number Specifies the pin number (allowed values 0-31). 00207 * 00208 */ 00209 __STATIC_INLINE void nrf_gpio_cfg_watcher(uint32_t pin_number); 00210 00211 /** 00212 * @brief Function for disconnecting input for the given GPIO. 00213 * 00214 * @param pin_number Specifies the pin number (allowed values 0-31). 00215 * 00216 */ 00217 __STATIC_INLINE void nrf_gpio_input_disconnect(uint32_t pin_number); 00218 00219 /** 00220 * @brief Function for configuring the given GPIO pin number as input with given initial value set, hiding inner details. 00221 * This function can be used to configure pin range as simple input with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases). 00222 * Sense capability on the pin is configurable, and input is connected to buffer so that the GPIO->IN register is readable. 00223 * 00224 * @param pin_number Specifies the pin number (allowed values 0-30). 00225 * @param pull_config State of the pin pull resistor (no pull, pulled down or pulled high). 00226 * @param sense_config Sense level of the pin (no sense, sense low or sense high). 00227 */ 00228 __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); 00229 00230 /** 00231 * @brief Function for configuring sense level for the given GPIO. 00232 * 00233 * @param pin_number Specifies the pin number of gpio pin numbers to be configured (allowed values 0-30). 00234 * @param sense_config Sense configuration. 00235 * 00236 */ 00237 __STATIC_INLINE void nrf_gpio_cfg_sense_set(uint32_t pin_number, nrf_gpio_pin_sense_t sense_config); 00238 00239 /** 00240 * @brief Function for setting the direction for a GPIO pin. 00241 * 00242 * @param pin_number specifies the pin number [0:31] for which to 00243 * set the direction. 00244 * 00245 * @param direction specifies the direction 00246 */ 00247 __STATIC_INLINE void nrf_gpio_pin_dir_set(uint32_t pin_number, nrf_gpio_pin_dir_t direction); 00248 00249 /** 00250 * @brief Function for setting a GPIO pin. 00251 * 00252 * Note that the pin must be configured as an output for this 00253 * function to have any effect. 00254 * 00255 * @param pin_number specifies the pin number [0:31] to 00256 * set. 00257 */ 00258 __STATIC_INLINE void nrf_gpio_pin_set(uint32_t pin_number); 00259 00260 /** 00261 * @brief Function for setting GPIO pins. 00262 * 00263 * Note that pins must be configured as an output for this 00264 * function to have any effect. 00265 * 00266 * @param pin_mask Specifies the pins to set. 00267 * set. 00268 */ 00269 __STATIC_INLINE void nrf_gpio_pins_set(uint32_t pin_mask); 00270 00271 /** 00272 * @brief Function for clearing a GPIO pin. 00273 * 00274 * Note that the pin must be configured as an output for this 00275 * function to have any effect. 00276 * 00277 * @param pin_number specifies the pin number [0:31] to 00278 * clear. 00279 */ 00280 __STATIC_INLINE void nrf_gpio_pin_clear(uint32_t pin_number); 00281 00282 /** 00283 * @brief Function for clearing GPIO pins. 00284 * 00285 * Note that pins must be configured as an output for this 00286 * function to have any effect. 00287 * 00288 * @param pin_mask Specifies the pins to clear. 00289 * set. 00290 */ 00291 __STATIC_INLINE void nrf_gpio_pins_clear(uint32_t pin_mask); 00292 00293 /** 00294 * @brief Function for toggling a GPIO pin. 00295 * 00296 * Note that the pin must be configured as an output for this 00297 * function to have any effect. 00298 * 00299 * @param pin_number specifies the pin number [0:31] to 00300 * toggle. 00301 */ 00302 __STATIC_INLINE void nrf_gpio_pin_toggle(uint32_t pin_number); 00303 00304 /** 00305 * @brief Function for writing a value to a GPIO pin. 00306 * 00307 * Note that the pin must be configured as an output for this 00308 * function to have any effect. 00309 * 00310 * @param pin_number specifies the pin number [0:31] to 00311 * write. 00312 * 00313 * @param value specifies the value to be written to the pin. 00314 * @arg 0 clears the pin 00315 * @arg >=1 sets the pin. 00316 */ 00317 __STATIC_INLINE void nrf_gpio_pin_write(uint32_t pin_number, uint32_t value); 00318 00319 /** 00320 * @brief Function for reading the input level of a GPIO pin. 00321 * 00322 * Note that the pin must have input connected for the value 00323 * returned from this function to be valid. 00324 * 00325 * @param pin_number specifies the pin number [0:31] to 00326 * read. 00327 * 00328 * @return 00329 * @retval 0 if the pin input level is low. 00330 * @retval 1 if the pin input level is high. 00331 * @retval > 1 should never occur. 00332 */ 00333 __STATIC_INLINE uint32_t nrf_gpio_pin_read(uint32_t pin_number); 00334 00335 /** 00336 * @brief Function for reading the input level of all GPIO pins. 00337 * 00338 * Note that the pin must have input connected for the value 00339 * returned from this function to be valid. 00340 * 00341 * @retval Status of input of all pins 00342 */ 00343 __STATIC_INLINE uint32_t nrf_gpio_pins_read(void); 00344 00345 /** 00346 * @brief Function for reading the sense configuration of a GPIO pin. 00347 * 00348 * @param pin_number specifies the pin number [0:31] to 00349 * read. 00350 * 00351 * @retval Sense configuration 00352 */ 00353 __STATIC_INLINE nrf_gpio_pin_sense_t nrf_gpio_pin_sense_get(uint32_t pin_number); 00354 00355 /** 00356 * @brief Generic function for writing a single byte of a 32 bit word at a given 00357 * address. 00358 * 00359 * This function should not be called from outside the nrf_gpio 00360 * abstraction layer. 00361 * 00362 * @param word_address is the address of the word to be written. 00363 * 00364 * @param byte_no is the word byte number (0-3) to be written. 00365 * 00366 * @param value is the value to be written to byte "byte_no" of word 00367 * at address "word_address" 00368 */ 00369 __STATIC_INLINE void nrf_gpio_word_byte_write(volatile uint32_t * word_address, uint8_t byte_no, uint8_t value); 00370 00371 /** 00372 * @brief Generic function for reading a single byte of a 32 bit word at a given 00373 * address. 00374 * 00375 * This function should not be called from outside the nrf_gpio 00376 * abstraction layer. 00377 * 00378 * @param word_address is the address of the word to be read. 00379 * 00380 * @param byte_no is the byte number (0-3) of the word to be read. 00381 * 00382 * @return byte "byte_no" of word at address "word_address". 00383 */ 00384 __STATIC_INLINE uint8_t nrf_gpio_word_byte_read(const volatile uint32_t* word_address, uint8_t byte_no); 00385 00386 /** 00387 * @brief Function for setting the direction of a port. 00388 * 00389 * @param port is the port for which to set the direction. 00390 * 00391 * @param dir direction to be set for this port. 00392 */ 00393 __STATIC_INLINE void nrf_gpio_port_dir_set(nrf_gpio_port_select_t port, nrf_gpio_port_dir_t dir); 00394 00395 /** 00396 * @brief Function for reading a GPIO port. 00397 * 00398 * @param port is the port to read. 00399 * 00400 * @return the input value on this port. 00401 */ 00402 __STATIC_INLINE uint8_t nrf_gpio_port_read(nrf_gpio_port_select_t port); 00403 00404 /** 00405 * @brief Function for writing to a GPIO port. 00406 * 00407 * @param port is the port to write. 00408 * 00409 * @param value is the value to write to this port. 00410 * 00411 * @sa nrf_gpio_port_dir_set() 00412 */ 00413 __STATIC_INLINE void nrf_gpio_port_write(nrf_gpio_port_select_t port, uint8_t value); 00414 00415 /** 00416 * @brief Function for setting individual pins on GPIO port. 00417 * 00418 * @param port is the port for which to set the pins. 00419 * 00420 * @param set_mask is a mask specifying which pins to set. A bit 00421 * set to 1 indicates that the corresponding port pin shall be 00422 * set. 00423 * 00424 * @sa nrf_gpio_port_dir_set() 00425 */ 00426 __STATIC_INLINE void nrf_gpio_port_set(nrf_gpio_port_select_t port, uint8_t set_mask); 00427 00428 /** 00429 * @brief Function for clearing individual pins on GPIO port. 00430 * 00431 * @param port is the port for which to clear the pins. 00432 * 00433 * @param clr_mask is a mask specifying which pins to clear. A bit 00434 * set to 1 indicates that the corresponding port pin shall be 00435 * cleared. 00436 * 00437 * @sa nrf_gpio_port_dir_set() 00438 */ 00439 __STATIC_INLINE void nrf_gpio_port_clear(nrf_gpio_port_select_t port, uint8_t clr_mask); 00440 00441 #ifndef SUPPRESS_INLINE_IMPLEMENTATION 00442 __STATIC_INLINE void nrf_gpio_range_cfg_output(uint32_t pin_range_start, uint32_t pin_range_end) 00443 { 00444 /*lint -e{845} // A zero has been given as right argument to operator '|'" */ 00445 for (; pin_range_start <= pin_range_end; pin_range_start++) 00446 { 00447 nrf_gpio_cfg_output(pin_range_start); 00448 } 00449 } 00450 00451 __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) 00452 { 00453 /*lint -e{845} // A zero has been given as right argument to operator '|'" */ 00454 for (; pin_range_start <= pin_range_end; pin_range_start++) 00455 { 00456 nrf_gpio_cfg_input(pin_range_start, pull_config); 00457 } 00458 } 00459 00460 __STATIC_INLINE void nrf_gpio_cfg( 00461 uint32_t pin_number, 00462 nrf_gpio_pin_dir_t dir, 00463 nrf_gpio_pin_input_t input, 00464 nrf_gpio_pin_pull_t pull, 00465 nrf_gpio_pin_drive_t drive, 00466 nrf_gpio_pin_sense_t sense) 00467 { 00468 NRF_GPIO->PIN_CNF[pin_number] = ((uint32_t)dir << GPIO_PIN_CNF_DIR_Pos) 00469 | ((uint32_t)input << GPIO_PIN_CNF_INPUT_Pos) 00470 | ((uint32_t)pull << GPIO_PIN_CNF_PULL_Pos) 00471 | ((uint32_t)drive << GPIO_PIN_CNF_DRIVE_Pos) 00472 | ((uint32_t)sense << GPIO_PIN_CNF_SENSE_Pos); 00473 } 00474 00475 __STATIC_INLINE void nrf_gpio_cfg_output(uint32_t pin_number) 00476 { 00477 nrf_gpio_cfg( 00478 pin_number, 00479 NRF_GPIO_PIN_DIR_OUTPUT, 00480 NRF_GPIO_PIN_INPUT_DISCONNECT, 00481 NRF_GPIO_PIN_NOPULL, 00482 NRF_GPIO_PIN_S0S1, 00483 NRF_GPIO_PIN_NOSENSE); 00484 } 00485 00486 __STATIC_INLINE void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config) 00487 { 00488 nrf_gpio_cfg( 00489 pin_number, 00490 NRF_GPIO_PIN_DIR_INPUT, 00491 NRF_GPIO_PIN_INPUT_CONNECT, 00492 pull_config, 00493 NRF_GPIO_PIN_S0S1, 00494 NRF_GPIO_PIN_NOSENSE); 00495 } 00496 00497 __STATIC_INLINE void nrf_gpio_cfg_default(uint32_t pin_number) 00498 { 00499 nrf_gpio_cfg( 00500 pin_number, 00501 NRF_GPIO_PIN_DIR_INPUT, 00502 NRF_GPIO_PIN_INPUT_DISCONNECT, 00503 NRF_GPIO_PIN_NOPULL, 00504 NRF_GPIO_PIN_S0S1, 00505 NRF_GPIO_PIN_NOSENSE); 00506 } 00507 00508 __STATIC_INLINE void nrf_gpio_cfg_watcher(uint32_t pin_number) 00509 { 00510 /*lint -e{845} // A zero has been given as right argument to operator '|'" */ 00511 uint32_t cnf = NRF_GPIO->PIN_CNF[pin_number] & ~GPIO_PIN_CNF_INPUT_Msk; 00512 NRF_GPIO->PIN_CNF[pin_number] = cnf | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos); 00513 } 00514 00515 __STATIC_INLINE void nrf_gpio_input_disconnect(uint32_t pin_number) 00516 { 00517 /*lint -e{845} // A zero has been given as right argument to operator '|'" */ 00518 uint32_t cnf = NRF_GPIO->PIN_CNF[pin_number] & ~GPIO_PIN_CNF_INPUT_Msk; 00519 NRF_GPIO->PIN_CNF[pin_number] = cnf | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos); 00520 } 00521 00522 __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) 00523 { 00524 nrf_gpio_cfg( 00525 pin_number, 00526 NRF_GPIO_PIN_DIR_INPUT, 00527 NRF_GPIO_PIN_INPUT_CONNECT, 00528 pull_config, 00529 NRF_GPIO_PIN_S0S1, 00530 sense_config); 00531 } 00532 00533 __STATIC_INLINE void nrf_gpio_cfg_sense_set(uint32_t pin_number, nrf_gpio_pin_sense_t sense_config) 00534 { 00535 /*lint -e{845} // A zero has been given as right argument to operator '|'" */ 00536 //uint32_t cnf = NRF_GPIO->PIN_CNF[pin_number] & ~GPIO_PIN_CNF_SENSE_Msk; 00537 NRF_GPIO->PIN_CNF[pin_number] &= ~GPIO_PIN_CNF_SENSE_Msk; 00538 NRF_GPIO->PIN_CNF[pin_number] |= (sense_config << GPIO_PIN_CNF_SENSE_Pos); 00539 } 00540 00541 __STATIC_INLINE void nrf_gpio_pin_dir_set(uint32_t pin_number, nrf_gpio_pin_dir_t direction) 00542 { 00543 if(direction == NRF_GPIO_PIN_DIR_INPUT) 00544 { 00545 nrf_gpio_cfg( 00546 pin_number, 00547 NRF_GPIO_PIN_DIR_INPUT, 00548 NRF_GPIO_PIN_INPUT_CONNECT, 00549 NRF_GPIO_PIN_NOPULL, 00550 NRF_GPIO_PIN_S0S1, 00551 NRF_GPIO_PIN_NOSENSE); 00552 } 00553 else 00554 { 00555 NRF_GPIO->DIRSET = (1UL << pin_number); 00556 } 00557 } 00558 00559 __STATIC_INLINE void nrf_gpio_pin_set(uint32_t pin_number) 00560 { 00561 NRF_GPIO->OUTSET = (1UL << pin_number); 00562 } 00563 00564 __STATIC_INLINE void nrf_gpio_pins_set(uint32_t pin_mask) 00565 { 00566 NRF_GPIO->OUTSET = pin_mask; 00567 } 00568 00569 __STATIC_INLINE void nrf_gpio_pin_clear(uint32_t pin_number) 00570 { 00571 NRF_GPIO->OUTCLR = (1UL << pin_number); 00572 } 00573 00574 __STATIC_INLINE void nrf_gpio_pins_clear(uint32_t pin_mask) 00575 { 00576 NRF_GPIO->OUTCLR = pin_mask; 00577 } 00578 00579 __STATIC_INLINE void nrf_gpio_pin_toggle(uint32_t pin_number) 00580 { 00581 const uint32_t pin_bit = 1UL << pin_number; 00582 const uint32_t pin_state = ((NRF_GPIO->OUT >> pin_number) & 1UL); 00583 00584 if (pin_state == 0) 00585 { 00586 // Current state low, set high. 00587 NRF_GPIO->OUTSET = pin_bit; 00588 } 00589 else 00590 { 00591 // Current state high, set low. 00592 NRF_GPIO->OUTCLR = pin_bit; 00593 } 00594 } 00595 00596 __STATIC_INLINE void nrf_gpio_pin_write(uint32_t pin_number, uint32_t value) 00597 { 00598 if (value == 0) 00599 { 00600 nrf_gpio_pin_clear(pin_number); 00601 } 00602 else 00603 { 00604 nrf_gpio_pin_set(pin_number); 00605 } 00606 } 00607 00608 __STATIC_INLINE uint32_t nrf_gpio_pin_read(uint32_t pin_number) 00609 { 00610 return ((NRF_GPIO->IN >> pin_number) & 1UL); 00611 } 00612 00613 __STATIC_INLINE uint32_t nrf_gpio_pins_read(void) 00614 { 00615 return NRF_GPIO->IN; 00616 } 00617 00618 __STATIC_INLINE nrf_gpio_pin_sense_t nrf_gpio_pin_sense_get(uint32_t pin_number) 00619 { 00620 return (nrf_gpio_pin_sense_t)((NRF_GPIO->PIN_CNF[pin_number] & GPIO_PIN_CNF_SENSE_Msk) >> GPIO_PIN_CNF_SENSE_Pos); 00621 } 00622 00623 __STATIC_INLINE void nrf_gpio_word_byte_write(volatile uint32_t * word_address, uint8_t byte_no, uint8_t value) 00624 { 00625 *((volatile uint8_t*)(word_address) + byte_no) = value; 00626 } 00627 00628 __STATIC_INLINE uint8_t nrf_gpio_word_byte_read(const volatile uint32_t* word_address, uint8_t byte_no) 00629 { 00630 return (*((const volatile uint8_t*)(word_address) + byte_no)); 00631 } 00632 00633 __STATIC_INLINE void nrf_gpio_port_dir_set(nrf_gpio_port_select_t port, nrf_gpio_port_dir_t dir) 00634 { 00635 if (dir == NRF_GPIO_PORT_DIR_OUTPUT) 00636 { 00637 nrf_gpio_word_byte_write(&NRF_GPIO->DIRSET, port, 0xFF); 00638 } 00639 else 00640 { 00641 nrf_gpio_range_cfg_input(port*8, (port+1)*8-1, NRF_GPIO_PIN_NOPULL); 00642 } 00643 } 00644 00645 __STATIC_INLINE uint8_t nrf_gpio_port_read(nrf_gpio_port_select_t port) 00646 { 00647 return nrf_gpio_word_byte_read(&NRF_GPIO->IN, port); 00648 } 00649 00650 __STATIC_INLINE void nrf_gpio_port_write(nrf_gpio_port_select_t port, uint8_t value) 00651 { 00652 nrf_gpio_word_byte_write(&NRF_GPIO->OUT, port, value); 00653 } 00654 00655 __STATIC_INLINE void nrf_gpio_port_set(nrf_gpio_port_select_t port, uint8_t set_mask) 00656 { 00657 nrf_gpio_word_byte_write(&NRF_GPIO->OUTSET, port, set_mask); 00658 } 00659 00660 __STATIC_INLINE void nrf_gpio_port_clear(nrf_gpio_port_select_t port, uint8_t clr_mask) 00661 { 00662 nrf_gpio_word_byte_write(&NRF_GPIO->OUTCLR, port, clr_mask); 00663 } 00664 #endif //SUPPRESS_INLINE_IMPLEMENTATION 00665 /** @} */ 00666 00667 #endif
Generated on Tue Jul 12 2022 15:51:27 by 1.7.2