LCOV - code coverage report
Current view: top level - home/jason/ncs-2.0.0/modules/hal/nordic/nrfx/hal - nrf_gpio.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 43 113 38.1 %
Date: 2022-08-18 11:36:24 Functions: 8 22 36.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 32 12.5 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (c) 2015 - 2022, Nordic Semiconductor ASA
       3                 :            :  * All rights reserved.
       4                 :            :  *
       5                 :            :  * SPDX-License-Identifier: BSD-3-Clause
       6                 :            :  *
       7                 :            :  * Redistribution and use in source and binary forms, with or without
       8                 :            :  * modification, are permitted provided that the following conditions are met:
       9                 :            :  *
      10                 :            :  * 1. Redistributions of source code must retain the above copyright notice, this
      11                 :            :  *    list of conditions and the following disclaimer.
      12                 :            :  *
      13                 :            :  * 2. Redistributions in binary form must reproduce the above copyright
      14                 :            :  *    notice, this list of conditions and the following disclaimer in the
      15                 :            :  *    documentation and/or other materials provided with the distribution.
      16                 :            :  *
      17                 :            :  * 3. Neither the name of the copyright holder nor the names of its
      18                 :            :  *    contributors may be used to endorse or promote products derived from this
      19                 :            :  *    software without specific prior written permission.
      20                 :            :  *
      21                 :            :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
      22                 :            :  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
      23                 :            :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
      24                 :            :  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
      25                 :            :  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
      26                 :            :  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
      27                 :            :  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
      28                 :            :  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
      29                 :            :  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
      30                 :            :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
      31                 :            :  * POSSIBILITY OF SUCH DAMAGE.
      32                 :            :  */
      33                 :            : 
      34                 :            : #ifndef NRF_GPIO_H__
      35                 :            : #define NRF_GPIO_H__
      36                 :            : 
      37                 :            : #include <nrfx.h>
      38                 :            : 
      39                 :            : #ifdef __cplusplus
      40                 :            : extern "C" {
      41                 :            : #endif
      42                 :            : 
      43                 :            : #ifndef NRF_P0
      44                 :            : #define NRF_P0 NRF_GPIO
      45                 :            : #endif
      46                 :            : 
      47                 :            : #if (GPIO_COUNT == 1)
      48                 :            : #define NUMBER_OF_PINS (P0_PIN_NUM)
      49                 :            : #define GPIO_REG_LIST  {NRF_P0}
      50                 :            : #elif (GPIO_COUNT == 2)
      51                 :            : #define NUMBER_OF_PINS (P0_PIN_NUM + P1_PIN_NUM)
      52                 :            : #define GPIO_REG_LIST  {NRF_P0, NRF_P1}
      53                 :            : #else
      54                 :            : #error "Not supported."
      55                 :            : #endif
      56                 :            : 
      57                 :            : #if defined(NRF52820_XXAA)
      58                 :            : #include <nrf_erratas.h>
      59                 :            : #endif
      60                 :            : 
      61                 :            : /**
      62                 :            :  * @defgroup nrf_gpio_hal GPIO HAL
      63                 :            :  * @{
      64                 :            :  * @ingroup nrf_gpio
      65                 :            :  * @brief   Hardware access layer for managing the GPIO peripheral.
      66                 :            :  */
      67                 :            : 
      68                 :            : #if defined(GPIO_LATCH_PIN0_Msk) || defined(__NRFX_DOXYGEN__)
      69                 :            : /** @brief Symbol indicating whether the functionality of latching GPIO state change is present. */
      70                 :            : #define NRF_GPIO_LATCH_PRESENT
      71                 :            : #endif
      72                 :            : 
      73                 :            : /** @brief Macro for mapping port and pin numbers to values understandable for nrf_gpio functions. */
      74                 :            : #define NRF_GPIO_PIN_MAP(port, pin) (((port) << 5) | ((pin) & 0x1F))
      75                 :            : 
      76                 :            : 
      77                 :            : /** @brief Pin direction definitions. */
      78                 :            : typedef enum
      79                 :            : {
      80                 :            :     NRF_GPIO_PIN_DIR_INPUT  = GPIO_PIN_CNF_DIR_Input, ///< Input.
      81                 :            :     NRF_GPIO_PIN_DIR_OUTPUT = GPIO_PIN_CNF_DIR_Output ///< Output.
      82                 :            : } nrf_gpio_pin_dir_t;
      83                 :            : 
      84                 :            : /** @brief Connection of input buffer. */
      85                 :            : typedef enum
      86                 :            : {
      87                 :            :     NRF_GPIO_PIN_INPUT_CONNECT    = GPIO_PIN_CNF_INPUT_Connect,   ///< Connect input buffer.
      88                 :            :     NRF_GPIO_PIN_INPUT_DISCONNECT = GPIO_PIN_CNF_INPUT_Disconnect ///< Disconnect input buffer.
      89                 :            : } nrf_gpio_pin_input_t;
      90                 :            : 
      91                 :            : /**
      92                 :            :  * @brief Enumerator used for selecting the pin to be pulled down or up at the time of pin
      93                 :            :  * configuration.
      94                 :            :  */
      95                 :            : typedef enum
      96                 :            : {
      97                 :            :     NRF_GPIO_PIN_NOPULL   = GPIO_PIN_CNF_PULL_Disabled, ///<  Pin pull-up resistor disabled.
      98                 :            :     NRF_GPIO_PIN_PULLDOWN = GPIO_PIN_CNF_PULL_Pulldown, ///<  Pin pull-down resistor enabled.
      99                 :            :     NRF_GPIO_PIN_PULLUP   = GPIO_PIN_CNF_PULL_Pullup,   ///<  Pin pull-up resistor enabled.
     100                 :            : } nrf_gpio_pin_pull_t;
     101                 :            : 
     102                 :            : /** @brief Enumerator used for selecting output drive mode. */
     103                 :            : typedef enum
     104                 :            : {
     105                 :            :     NRF_GPIO_PIN_S0S1 = GPIO_PIN_CNF_DRIVE_S0S1, ///< Standard '0', standard '1'.
     106                 :            :     NRF_GPIO_PIN_H0S1 = GPIO_PIN_CNF_DRIVE_H0S1, ///< High drive '0', standard '1'.
     107                 :            :     NRF_GPIO_PIN_S0H1 = GPIO_PIN_CNF_DRIVE_S0H1, ///< Standard '0', high drive '1'.
     108                 :            :     NRF_GPIO_PIN_H0H1 = GPIO_PIN_CNF_DRIVE_H0H1, ///< High drive '0', high drive '1'.
     109                 :            :     NRF_GPIO_PIN_D0S1 = GPIO_PIN_CNF_DRIVE_D0S1, ///< Disconnect '0' standard '1'.
     110                 :            :     NRF_GPIO_PIN_D0H1 = GPIO_PIN_CNF_DRIVE_D0H1, ///< Disconnect '0', high drive '1'.
     111                 :            :     NRF_GPIO_PIN_S0D1 = GPIO_PIN_CNF_DRIVE_S0D1, ///< Standard '0', disconnect '1'.
     112                 :            :     NRF_GPIO_PIN_H0D1 = GPIO_PIN_CNF_DRIVE_H0D1, ///< High drive '0', disconnect '1'.
     113                 :            : #if defined(GPIO_PIN_CNF_DRIVE_E0S1) || defined(__NRFX_DOXYGEN__)
     114                 :            :     NRF_GPIO_PIN_E0S1 = GPIO_PIN_CNF_DRIVE_E0S1, ///< Extra high drive '0', standard '1'.
     115                 :            : #endif
     116                 :            : #if defined(GPIO_PIN_CNF_DRIVE_S0E1) || defined(__NRFX_DOXYGEN__)
     117                 :            :     NRF_GPIO_PIN_S0E1 = GPIO_PIN_CNF_DRIVE_S0E1, ///< Standard '0', extra high drive '1'.
     118                 :            : #endif
     119                 :            : #if defined(GPIO_PIN_CNF_DRIVE_E0E1) || defined(__NRFX_DOXYGEN__)
     120                 :            :     NRF_GPIO_PIN_E0E1 = GPIO_PIN_CNF_DRIVE_E0E1, ///< Extra high drive '0', extra high drive '1'.
     121                 :            : #endif
     122                 :            : #if defined(GPIO_PIN_CNF_DRIVE_E0H1) || defined(__NRFX_DOXYGEN__)
     123                 :            :     NRF_GPIO_PIN_E0H1 = GPIO_PIN_CNF_DRIVE_E0H1, ///< Extra high drive '0', high drive '1'.
     124                 :            : #endif
     125                 :            : #if defined(GPIO_PIN_CNF_DRIVE_H0E1) || defined(__NRFX_DOXYGEN__)
     126                 :            :     NRF_GPIO_PIN_H0E1 = GPIO_PIN_CNF_DRIVE_H0E1, ///< High drive '0', extra high drive '1'.
     127                 :            : #endif
     128                 :            : #if defined(GPIO_PIN_CNF_DRIVE_D0E1) || defined(__NRFX_DOXYGEN__)
     129                 :            :     NRF_GPIO_PIN_D0E1 = GPIO_PIN_CNF_DRIVE_D0E1, ///< Disconnect '0', extra high drive '1'.
     130                 :            : #endif
     131                 :            : #if defined(GPIO_PIN_CNF_DRIVE_E0D1) || defined(__NRFX_DOXYGEN__)
     132                 :            :     NRF_GPIO_PIN_E0D1 = GPIO_PIN_CNF_DRIVE_E0D1, ///< Extra high drive '0', disconnect '1'.
     133                 :            : #endif
     134                 :            : } nrf_gpio_pin_drive_t;
     135                 :            : 
     136                 :            : /** @brief Enumerator used for selecting the pin to sense high or low level on the pin input. */
     137                 :            : typedef enum
     138                 :            : {
     139                 :            :     NRF_GPIO_PIN_NOSENSE    = GPIO_PIN_CNF_SENSE_Disabled, ///<  Pin sense level disabled.
     140                 :            :     NRF_GPIO_PIN_SENSE_LOW  = GPIO_PIN_CNF_SENSE_Low,      ///<  Pin sense low level.
     141                 :            :     NRF_GPIO_PIN_SENSE_HIGH = GPIO_PIN_CNF_SENSE_High,     ///<  Pin sense high level.
     142                 :            : } nrf_gpio_pin_sense_t;
     143                 :            : 
     144                 :            : #if defined(GPIO_PIN_CNF_MCUSEL_Msk) || defined(__NRFX_DOXYGEN__)
     145                 :            : /** @brief Enumerator used for selecting the MCU/Subsystem to control the specified pin. */
     146                 :            : typedef enum
     147                 :            : {
     148                 :            :     NRF_GPIO_PIN_MCUSEL_APP        = GPIO_PIN_CNF_MCUSEL_AppMCU,     ///< Pin controlled by Application MCU.
     149                 :            :     NRF_GPIO_PIN_MCUSEL_NETWORK    = GPIO_PIN_CNF_MCUSEL_NetworkMCU, ///< Pin controlled by Network MCU.
     150                 :            :     NRF_GPIO_PIN_MCUSEL_PERIPHERAL = GPIO_PIN_CNF_MCUSEL_Peripheral, ///< Pin controlled by dedicated peripheral.
     151                 :            :     NRF_GPIO_PIN_MCUSEL_TND        = GPIO_PIN_CNF_MCUSEL_TND,        ///< Pin controlled by Trace and Debug Subsystem.
     152                 :            : } nrf_gpio_pin_mcusel_t;
     153                 :            : #endif
     154                 :            : 
     155                 :            : /**
     156                 :            :  * @brief Function for configuring the GPIO pin range as output pins with normal drive strength.
     157                 :            :  *        This function can be used to configure pin range as simple output with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
     158                 :            :  *
     159                 :            :  * @note For configuring only one pin as output, use @ref nrf_gpio_cfg_output.
     160                 :            :  *       Sense capability on the pin is disabled and input is disconnected from the buffer as the pins are configured as output.
     161                 :            :  *
     162                 :            :  * @param pin_range_start  Specifies the start number (inclusive) in the range of pin numbers to be configured (allowed values 0-30).
     163                 :            :  * @param pin_range_end    Specifies the end number (inclusive) in the range of pin numbers to be configured (allowed values 0-30).
     164                 :            :  */
     165                 :            : NRF_STATIC_INLINE void nrf_gpio_range_cfg_output(uint32_t pin_range_start, uint32_t pin_range_end);
     166                 :            : 
     167                 :            : /**
     168                 :            :  * @brief Function for configuring the GPIO pin range as input pins with given initial value set, hiding inner details.
     169                 :            :  *        This function can be used to configure pin range as simple input.
     170                 :            :  *
     171                 :            :  * @note  For configuring only one pin as input, use @ref nrf_gpio_cfg_input.
     172                 :            :  *        Sense capability on the pin is disabled and input is connected to buffer so that the GPIO->IN register is readable.
     173                 :            :  *
     174                 :            :  * @param pin_range_start  Specifies the start number (inclusive) in the range of pin numbers to be configured (allowed values 0-30).
     175                 :            :  * @param pin_range_end    Specifies the end number (inclusive) in the range of pin numbers to be configured (allowed values 0-30).
     176                 :            :  * @param pull_config      State of the pin range pull resistor (no pull, pulled down, or pulled high).
     177                 :            :  */
     178                 :            : NRF_STATIC_INLINE void nrf_gpio_range_cfg_input(uint32_t            pin_range_start,
     179                 :            :                                                 uint32_t            pin_range_end,
     180                 :            :                                                 nrf_gpio_pin_pull_t pull_config);
     181                 :            : 
     182                 :            : /**
     183                 :            :  * @brief Pin configuration function.
     184                 :            :  *
     185                 :            :  * The main pin configuration function.
     186                 :            :  * This function allows to set any aspect in PIN_CNF register.
     187                 :            :  *
     188                 :            :  * @param pin_number Specifies the pin number.
     189                 :            :  * @param dir        Pin direction.
     190                 :            :  * @param input      Connect or disconnect the input buffer.
     191                 :            :  * @param pull       Pull configuration.
     192                 :            :  * @param drive      Drive configuration.
     193                 :            :  * @param sense      Pin sensing mechanism.
     194                 :            :  */
     195                 :            : NRF_STATIC_INLINE void nrf_gpio_cfg(
     196                 :            :     uint32_t             pin_number,
     197                 :            :     nrf_gpio_pin_dir_t   dir,
     198                 :            :     nrf_gpio_pin_input_t input,
     199                 :            :     nrf_gpio_pin_pull_t  pull,
     200                 :            :     nrf_gpio_pin_drive_t drive,
     201                 :            :     nrf_gpio_pin_sense_t sense);
     202                 :            : 
     203                 :            : /**
     204                 :            :  * @brief Function for reconfiguring pin.
     205                 :            :  *
     206                 :            :  * @note This function selectively updates fields in PIN_CNF register. Reconfiguration
     207                 :            :  *       is performed in single register write. Fields for which new configuration is
     208                 :            :  *       not provided remain unchanged.
     209                 :            :  *
     210                 :            :  * @param pin_number Specifies the pin number.
     211                 :            :  * @param p_dir      Pin direction. If NULL, previous setting remains.
     212                 :            :  * @param p_input    Connect or disconnect the input buffer. If NULL, previous setting remains.
     213                 :            :  * @param p_pull     Pull configuration. If NULL, previous setting remains.
     214                 :            :  * @param p_drive    Drive configuration. If NULL, previous setting remains.
     215                 :            :  * @param p_sense    Pin sensing mechanism. If NULL, previous setting remains.
     216                 :            :  */
     217                 :            : NRF_STATIC_INLINE void nrf_gpio_reconfigure(uint32_t                     pin_number,
     218                 :            :                                             const nrf_gpio_pin_dir_t *   p_dir,
     219                 :            :                                             const nrf_gpio_pin_input_t * p_input,
     220                 :            :                                             const nrf_gpio_pin_pull_t *  p_pull,
     221                 :            :                                             const nrf_gpio_pin_drive_t * p_drive,
     222                 :            :                                             const nrf_gpio_pin_sense_t * p_sense);
     223                 :            : 
     224                 :            : /**
     225                 :            :  * @brief Function for configuring the given GPIO pin number as output, hiding inner details.
     226                 :            :  *        This function can be used to configure a pin as simple output with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
     227                 :            :  *
     228                 :            :  * @note  Sense capability on the pin is disabled and input is disconnected from the buffer as the pins are configured as output.
     229                 :            :  *
     230                 :            :  * @param pin_number Specifies the pin number.
     231                 :            :  */
     232                 :            : NRF_STATIC_INLINE void nrf_gpio_cfg_output(uint32_t pin_number);
     233                 :            : 
     234                 :            : /**
     235                 :            :  * @brief Function for configuring the given GPIO pin number as input, hiding inner details.
     236                 :            :  *        This function can be used to configure a pin as simple input.
     237                 :            :  *
     238                 :            :  * @note  Sense capability on the pin is disabled and input is connected to buffer so that the GPIO->IN register is readable.
     239                 :            :  *
     240                 :            :  * @param pin_number  Specifies the pin number.
     241                 :            :  * @param pull_config State of the pin range pull resistor (no pull, pulled down, or pulled high).
     242                 :            :  */
     243                 :            : NRF_STATIC_INLINE void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config);
     244                 :            : 
     245                 :            : /**
     246                 :            :  * @brief Function for resetting pin configuration to its default state.
     247                 :            :  *
     248                 :            :  * @param pin_number Specifies the pin number.
     249                 :            :  */
     250                 :            : NRF_STATIC_INLINE void nrf_gpio_cfg_default(uint32_t pin_number);
     251                 :            : 
     252                 :            : /**
     253                 :            :  * @brief Function for configuring the given GPIO pin number as a watcher. Only input is connected.
     254                 :            :  *
     255                 :            :  * @param pin_number Specifies the pin number.
     256                 :            :  *
     257                 :            :  */
     258                 :            : NRF_STATIC_INLINE void nrf_gpio_cfg_watcher(uint32_t pin_number);
     259                 :            : 
     260                 :            : /**
     261                 :            :  * @brief Function for disconnecting input for the given GPIO.
     262                 :            :  *
     263                 :            :  * @param pin_number Specifies the pin number.
     264                 :            :  */
     265                 :            : NRF_STATIC_INLINE void nrf_gpio_input_disconnect(uint32_t pin_number);
     266                 :            : 
     267                 :            : /**
     268                 :            :  * @brief Function for configuring the given GPIO pin number as input, hiding inner details.
     269                 :            :  *        This function can be used to configure pin range as simple input.
     270                 :            :  *        Sense capability on the pin is configurable and input is connected to buffer so that the GPIO->IN register is readable.
     271                 :            :  *
     272                 :            :  * @param pin_number   Specifies the pin number.
     273                 :            :  * @param pull_config  State of the pin pull resistor (no pull, pulled down, or pulled high).
     274                 :            :  * @param sense_config Sense level of the pin (no sense, sense low, or sense high).
     275                 :            :  */
     276                 :            : NRF_STATIC_INLINE void nrf_gpio_cfg_sense_input(uint32_t             pin_number,
     277                 :            :                                                 nrf_gpio_pin_pull_t  pull_config,
     278                 :            :                                                 nrf_gpio_pin_sense_t sense_config);
     279                 :            : 
     280                 :            : /**
     281                 :            :  * @brief Function for configuring sense level for the given GPIO.
     282                 :            :  *
     283                 :            :  * @param pin_number   Specifies the pin number.
     284                 :            :  * @param sense_config Sense configuration.
     285                 :            :  */
     286                 :            : NRF_STATIC_INLINE void nrf_gpio_cfg_sense_set(uint32_t             pin_number,
     287                 :            :                                               nrf_gpio_pin_sense_t sense_config);
     288                 :            : 
     289                 :            : /**
     290                 :            :  * @brief Function for setting the direction for a GPIO pin.
     291                 :            :  *
     292                 :            :  * @param pin_number Specifies the pin number for which to set the direction.
     293                 :            :  * @param direction  Specifies the direction.
     294                 :            :  */
     295                 :            : NRF_STATIC_INLINE void nrf_gpio_pin_dir_set(uint32_t pin_number, nrf_gpio_pin_dir_t direction);
     296                 :            : 
     297                 :            : /**
     298                 :            :  * @brief Function for setting a GPIO pin.
     299                 :            :  *
     300                 :            :  * @param pin_number Specifies the pin number to be set.
     301                 :            :  */
     302                 :            : NRF_STATIC_INLINE void nrf_gpio_pin_set(uint32_t pin_number);
     303                 :            : 
     304                 :            : /**
     305                 :            :  * @brief Function for clearing a GPIO pin.
     306                 :            :  *
     307                 :            :  * @param pin_number Specifies the pin number to clear.
     308                 :            :  */
     309                 :            : NRF_STATIC_INLINE void nrf_gpio_pin_clear(uint32_t pin_number);
     310                 :            : 
     311                 :            : /**
     312                 :            :  * @brief Function for toggling a GPIO pin.
     313                 :            :  *
     314                 :            :  * @param pin_number Specifies the pin number to toggle.
     315                 :            :  */
     316                 :            : NRF_STATIC_INLINE void nrf_gpio_pin_toggle(uint32_t pin_number);
     317                 :            : 
     318                 :            : /**
     319                 :            :  * @brief Function for writing a value to a GPIO pin.
     320                 :            :  *
     321                 :            :  * @param pin_number Specifies the pin number to write.
     322                 :            :  * @param value      Specifies the value to be written to the pin.
     323                 :            :  * @arg 0 Clears the pin.
     324                 :            :  * @arg >=1 Sets the pin.
     325                 :            :  */
     326                 :            : NRF_STATIC_INLINE void nrf_gpio_pin_write(uint32_t pin_number, uint32_t value);
     327                 :            : 
     328                 :            : /**
     329                 :            :  * @brief Function for reading the input level of a GPIO pin.
     330                 :            :  *
     331                 :            :  * If the value returned by this function is to be valid, the pin's input buffer must be connected.
     332                 :            :  *
     333                 :            :  * @param pin_number Specifies the pin number to read.
     334                 :            :  *
     335                 :            :  * @return 0 if the pin input level is low. Positive value if the pin is high.
     336                 :            :  */
     337                 :            : NRF_STATIC_INLINE uint32_t nrf_gpio_pin_read(uint32_t pin_number);
     338                 :            : 
     339                 :            : /**
     340                 :            :  * @brief Function for reading the output level of a GPIO pin.
     341                 :            :  *
     342                 :            :  * @param pin_number Specifies the pin number to read.
     343                 :            :  *
     344                 :            :  * @return 0 if the pin output level is low. Positive value if pin output is high.
     345                 :            :  */
     346                 :            : NRF_STATIC_INLINE uint32_t nrf_gpio_pin_out_read(uint32_t pin_number);
     347                 :            : 
     348                 :            : /**
     349                 :            :  * @brief Function for reading the sense configuration of a GPIO pin.
     350                 :            :  *
     351                 :            :  * @param pin_number Specifies the pin number to read.
     352                 :            :  *
     353                 :            :  * @return Sense configuration.
     354                 :            :  */
     355                 :            : NRF_STATIC_INLINE nrf_gpio_pin_sense_t nrf_gpio_pin_sense_get(uint32_t pin_number);
     356                 :            : 
     357                 :            : /**
     358                 :            :  * @brief Function for reading the direction configuration of a GPIO pin.
     359                 :            :  *
     360                 :            :  * @param pin_number Specifies the pin number to read.
     361                 :            :  *
     362                 :            :  * @return Direction configuration.
     363                 :            :  */
     364                 :            : NRF_STATIC_INLINE nrf_gpio_pin_dir_t nrf_gpio_pin_dir_get(uint32_t pin_number);
     365                 :            : 
     366                 :            : /**
     367                 :            :  * @brief Function for reading the status of GPIO pin input buffer.
     368                 :            :  *
     369                 :            :  * @param pin_number Pin number to be read.
     370                 :            :  *
     371                 :            :  * @retval Input buffer configuration.
     372                 :            :  */
     373                 :            : NRF_STATIC_INLINE nrf_gpio_pin_input_t nrf_gpio_pin_input_get(uint32_t pin_number);
     374                 :            : 
     375                 :            : /**
     376                 :            :  * @brief Function for reading the pull configuration of a GPIO pin.
     377                 :            :  *
     378                 :            :  * @param pin_number Specifies the pin number to read.
     379                 :            :  *
     380                 :            :  * @retval Pull configuration.
     381                 :            :  */
     382                 :            : NRF_STATIC_INLINE nrf_gpio_pin_pull_t nrf_gpio_pin_pull_get(uint32_t pin_number);
     383                 :            : 
     384                 :            : /**
     385                 :            :  * @brief Function for setting output direction on the selected pins on the given port.
     386                 :            :  *
     387                 :            :  * @param p_reg    Pointer to the structure of registers of the peripheral.
     388                 :            :  * @param out_mask Mask specifying the pins to set as output.
     389                 :            :  */
     390                 :            : NRF_STATIC_INLINE void nrf_gpio_port_dir_output_set(NRF_GPIO_Type * p_reg, uint32_t out_mask);
     391                 :            : 
     392                 :            : /**
     393                 :            :  * @brief Function for setting input direction on selected pins on a given port.
     394                 :            :  *
     395                 :            :  * @param p_reg   Pointer to the structure of registers of the peripheral.
     396                 :            :  * @param in_mask Mask that specifies the pins to be set as input.
     397                 :            :  */
     398                 :            : NRF_STATIC_INLINE void nrf_gpio_port_dir_input_set(NRF_GPIO_Type * p_reg, uint32_t in_mask);
     399                 :            : 
     400                 :            : /**
     401                 :            :  * @brief Function for writing the direction configuration of the GPIO pins in the given port.
     402                 :            :  *
     403                 :            :  * @param p_reg    Pointer to the structure of registers of the peripheral.
     404                 :            :  * @param dir_mask Mask that specifies the direction of pins. Bit set means that the given pin is configured as output.
     405                 :            :  */
     406                 :            : NRF_STATIC_INLINE void nrf_gpio_port_dir_write(NRF_GPIO_Type * p_reg, uint32_t dir_mask);
     407                 :            : 
     408                 :            : /**
     409                 :            :  * @brief Function for reading the direction configuration of a GPIO port.
     410                 :            :  *
     411                 :            :  * @param p_reg Pointer to the structure of registers of the peripheral.
     412                 :            :  *
     413                 :            :  * @return Pin configuration of the current direction settings. Bit set means that the given pin is configured as output.
     414                 :            :  */
     415                 :            : NRF_STATIC_INLINE uint32_t nrf_gpio_port_dir_read(NRF_GPIO_Type const * p_reg);
     416                 :            : 
     417                 :            : /**
     418                 :            :  * @brief Function for reading the input signals of the GPIO pins on the given port.
     419                 :            :  *
     420                 :            :  * @param p_reg Pointer to the peripheral registers structure.
     421                 :            :  *
     422                 :            :  * @return Port input values.
     423                 :            :  */
     424                 :            : NRF_STATIC_INLINE uint32_t nrf_gpio_port_in_read(NRF_GPIO_Type const * p_reg);
     425                 :            : 
     426                 :            : /**
     427                 :            :  * @brief Function for reading the output signals of the GPIO pins on the given port.
     428                 :            :  *
     429                 :            :  * @param p_reg Pointer to the peripheral registers structure.
     430                 :            :  *
     431                 :            :  * @return Port output values.
     432                 :            :  */
     433                 :            : NRF_STATIC_INLINE uint32_t nrf_gpio_port_out_read(NRF_GPIO_Type const * p_reg);
     434                 :            : 
     435                 :            : /**
     436                 :            :  * @brief Function for writing the GPIO pins output on a given port.
     437                 :            :  *
     438                 :            :  * @param p_reg Pointer to the structure of registers of the peripheral.
     439                 :            :  * @param value Output port mask.
     440                 :            :  */
     441                 :            : NRF_STATIC_INLINE void nrf_gpio_port_out_write(NRF_GPIO_Type * p_reg, uint32_t value);
     442                 :            : 
     443                 :            : /**
     444                 :            :  * @brief Function for setting high level on selected the GPIO pins on the given port.
     445                 :            :  *
     446                 :            :  * @param p_reg    Pointer to the structure of registers of the peripheral.
     447                 :            :  * @param set_mask Mask with pins to be set as logical high level.
     448                 :            :  */
     449                 :            : NRF_STATIC_INLINE void nrf_gpio_port_out_set(NRF_GPIO_Type * p_reg, uint32_t set_mask);
     450                 :            : 
     451                 :            : /**
     452                 :            :  * @brief Function for setting low level on selected the GPIO pins on the given port.
     453                 :            :  *
     454                 :            :  * @param p_reg    Pointer to the structure of registers of the peripheral.
     455                 :            :  * @param clr_mask Mask with pins to be set as logical low level.
     456                 :            :  */
     457                 :            : NRF_STATIC_INLINE void nrf_gpio_port_out_clear(NRF_GPIO_Type * p_reg, uint32_t clr_mask);
     458                 :            : 
     459                 :            : /**
     460                 :            :  * @brief Function for reading pin state of multiple consecutive ports.
     461                 :            :  *
     462                 :            :  * @param start_port Index of the first port to read.
     463                 :            :  * @param length     Number of ports to read.
     464                 :            :  * @param p_masks    Pointer to output array where port states will be stored.
     465                 :            :  */
     466                 :            : NRF_STATIC_INLINE void nrf_gpio_ports_read(uint32_t   start_port,
     467                 :            :                                            uint32_t   length,
     468                 :            :                                            uint32_t * p_masks);
     469                 :            : 
     470                 :            : #if defined(NRF_GPIO_LATCH_PRESENT)
     471                 :            : /**
     472                 :            :  * @brief Function for reading latch state of multiple consecutive ports.
     473                 :            :  *
     474                 :            :  * @param start_port Index of the first port to read.
     475                 :            :  * @param length     Number of ports to read.
     476                 :            :  * @param p_masks    Pointer to output array where latch states will be stored.
     477                 :            :  */
     478                 :            : NRF_STATIC_INLINE void nrf_gpio_latches_read(uint32_t   start_port,
     479                 :            :                                              uint32_t   length,
     480                 :            :                                              uint32_t * p_masks);
     481                 :            : 
     482                 :            : /**
     483                 :            :  * @brief Function for reading and immediate clearing latch state of multiple consecutive ports.
     484                 :            :  *
     485                 :            :  * @param start_port Index of the first port to read and clear.
     486                 :            :  * @param length     Number of ports to read and clear.
     487                 :            :  * @param p_masks    Pointer to output array where latch states will be stored.
     488                 :            :  */
     489                 :            : NRF_STATIC_INLINE void nrf_gpio_latches_read_and_clear(uint32_t   start_port,
     490                 :            :                                                        uint32_t   length,
     491                 :            :                                                        uint32_t * p_masks);
     492                 :            : 
     493                 :            : /**
     494                 :            :  * @brief Function for reading latch state of single pin.
     495                 :            :  *
     496                 :            :  * @param pin_number Pin number.
     497                 :            :  *
     498                 :            :  * @return 0 if latch is not set. Positive value otherwise.
     499                 :            :  */
     500                 :            : NRF_STATIC_INLINE uint32_t nrf_gpio_pin_latch_get(uint32_t pin_number);
     501                 :            : 
     502                 :            : /**
     503                 :            :  * @brief Function for clearing latch state of a single pin.
     504                 :            :  *
     505                 :            :  * @param pin_number Pin number.
     506                 :            :  */
     507                 :            : NRF_STATIC_INLINE void nrf_gpio_pin_latch_clear(uint32_t pin_number);
     508                 :            : #endif // defined(NRF_GPIO_LATCH_PRESENT)
     509                 :            : 
     510                 :            : #if defined(GPIO_PIN_CNF_MCUSEL_Msk) || defined(__NRFX_DOXYGEN__)
     511                 :            : /**
     512                 :            :  * @brief Function for selecting the MCU to control a GPIO pin.
     513                 :            :  *
     514                 :            :  * @param pin_number Pin_number.
     515                 :            :  * @param mcu        MCU to control the pin.
     516                 :            :  */
     517                 :            : NRF_STATIC_INLINE void nrf_gpio_pin_mcu_select(uint32_t pin_number, nrf_gpio_pin_mcusel_t mcu);
     518                 :            : #endif
     519                 :            : 
     520                 :            : /**
     521                 :            :  * @brief Function for checking if provided pin is present on the MCU.
     522                 :            :  *
     523                 :            :  * @param[in] pin_number Number of the pin to be checked.
     524                 :            :  *
     525                 :            :  * @retval true  Pin is present.
     526                 :            :  * @retval false Pin is not present.
     527                 :            :  */
     528                 :            : NRF_STATIC_INLINE bool nrf_gpio_pin_present_check(uint32_t pin_number);
     529                 :            : 
     530                 :            : /**
     531                 :            :  * @brief Function for extracting port number and the relative pin number
     532                 :            :  *        from the absolute pin number.
     533                 :            :  *
     534                 :            :  * @param[in,out] p_pin Pointer to the absolute pin number overridden by the pin number
     535                 :            :  *                      that is relative to the port.
     536                 :            :  *
     537                 :            :  * @return Port number.
     538                 :            : */
     539                 :            : NRF_STATIC_INLINE uint32_t nrf_gpio_pin_port_number_extract(uint32_t * p_pin);
     540                 :            : 
     541                 :            : #ifndef NRF_DECLARE_ONLY
     542                 :            : 
     543                 :            : /**
     544                 :            :  * @brief Function for extracting port and the relative pin number from the absolute pin number.
     545                 :            :  *
     546                 :            :  * @param[in,out] p_pin Pointer to the absolute pin number overridden by the pin number
     547                 :            :  *                      that is relative to the port.
     548                 :            :  *
     549                 :            :  * @return Pointer to port register set.
     550                 :            :  */
     551                 :          8 : NRF_STATIC_INLINE NRF_GPIO_Type * nrf_gpio_pin_port_decode(uint32_t * p_pin)
     552                 :            : {
     553         [ -  + ]:          8 :     NRFX_ASSERT(nrf_gpio_pin_present_check(*p_pin));
     554                 :            : 
     555      [ -  +  - ]:          8 :     switch (nrf_gpio_pin_port_number_extract(p_pin))
     556                 :            :     {
     557                 :          0 :         default:
     558                 :          0 :             NRFX_ASSERT(0);
     559                 :            : #if defined(P0_FEATURE_PINS_PRESENT)
     560                 :            :         /* FALLTHROUGH */
     561                 :          8 :         case 0: return NRF_P0;
     562                 :            : #endif
     563                 :            : #if defined(P1_FEATURE_PINS_PRESENT)
     564                 :            :         /* FALLTHROUGH */
     565                 :          0 :         case 1: return NRF_P1;
     566                 :            : #endif
     567                 :            :     }
     568                 :            : }
     569                 :            : 
     570                 :            : 
     571                 :            : NRF_STATIC_INLINE void nrf_gpio_range_cfg_output(uint32_t pin_range_start, uint32_t pin_range_end)
     572                 :            : {
     573                 :            :     for (; pin_range_start <= pin_range_end; pin_range_start++)
     574                 :            :     {
     575                 :            :         nrf_gpio_cfg_output(pin_range_start);
     576                 :            :     }
     577                 :            : }
     578                 :            : 
     579                 :            : 
     580                 :            : NRF_STATIC_INLINE void nrf_gpio_range_cfg_input(uint32_t            pin_range_start,
     581                 :            :                                                 uint32_t            pin_range_end,
     582                 :            :                                                 nrf_gpio_pin_pull_t pull_config)
     583                 :            : {
     584                 :            :     for (; pin_range_start <= pin_range_end; pin_range_start++)
     585                 :            :     {
     586                 :            :         nrf_gpio_cfg_input(pin_range_start, pull_config);
     587                 :            :     }
     588                 :            : }
     589                 :            : 
     590                 :            : 
     591                 :          4 : NRF_STATIC_INLINE void nrf_gpio_cfg(
     592                 :            :     uint32_t             pin_number,
     593                 :            :     nrf_gpio_pin_dir_t   dir,
     594                 :            :     nrf_gpio_pin_input_t input,
     595                 :            :     nrf_gpio_pin_pull_t  pull,
     596                 :            :     nrf_gpio_pin_drive_t drive,
     597                 :            :     nrf_gpio_pin_sense_t sense)
     598                 :            : {
     599                 :          4 :     NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
     600                 :            : 
     601                 :            : #if defined(GPIO_PIN_CNF_MCUSEL_Msk)
     602                 :            :     /* Preserve MCUSEL setting. */
     603                 :          4 :     uint32_t cnf = reg->PIN_CNF[pin_number] & GPIO_PIN_CNF_MCUSEL_Msk;
     604                 :            : #else
     605                 :            :     uint32_t cnf = 0;
     606                 :            : #endif
     607                 :          4 :     cnf |= ((uint32_t)dir << GPIO_PIN_CNF_DIR_Pos)     |
     608                 :          4 :            ((uint32_t)input << GPIO_PIN_CNF_INPUT_Pos) |
     609                 :          4 :            ((uint32_t)pull << GPIO_PIN_CNF_PULL_Pos)   |
     610                 :          4 :            ((uint32_t)drive << GPIO_PIN_CNF_DRIVE_Pos) |
     611                 :          4 :            ((uint32_t)sense << GPIO_PIN_CNF_SENSE_Pos);
     612                 :            : 
     613                 :          4 :     reg->PIN_CNF[pin_number] = cnf;
     614                 :          4 : }
     615                 :            : 
     616                 :          0 : NRF_STATIC_INLINE void nrf_gpio_reconfigure(uint32_t                     pin_number,
     617                 :            :                                             const nrf_gpio_pin_dir_t *   p_dir,
     618                 :            :                                             const nrf_gpio_pin_input_t * p_input,
     619                 :            :                                             const nrf_gpio_pin_pull_t *  p_pull,
     620                 :            :                                             const nrf_gpio_pin_drive_t * p_drive,
     621                 :            :                                             const nrf_gpio_pin_sense_t * p_sense)
     622                 :            : {
     623                 :          0 :     NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
     624                 :          0 :     uint32_t cnf = reg->PIN_CNF[pin_number];
     625         [ #  # ]:          0 :     uint32_t to_update = (p_dir   ? GPIO_PIN_CNF_DIR_Msk   : 0) |
     626         [ #  # ]:          0 :                          (p_input ? GPIO_PIN_CNF_INPUT_Msk : 0) |
     627         [ #  # ]:          0 :                          (p_pull  ? GPIO_PIN_CNF_PULL_Msk  : 0) |
     628         [ #  # ]:          0 :                          (p_drive ? GPIO_PIN_CNF_DRIVE_Msk : 0) |
     629         [ #  # ]:          0 :                          (p_sense ? GPIO_PIN_CNF_SENSE_Msk : 0);
     630                 :            : 
     631                 :            :     /* Clear fields that will be updated. */
     632                 :          0 :     cnf &= ~to_update;
     633         [ #  # ]:          0 :     cnf |= ((uint32_t)(p_dir   ? *p_dir   : 0) << GPIO_PIN_CNF_DIR_Pos)   |
     634         [ #  # ]:          0 :            ((uint32_t)(p_input ? *p_input : 0) << GPIO_PIN_CNF_INPUT_Pos) |
     635         [ #  # ]:          0 :            ((uint32_t)(p_pull  ? *p_pull  : 0) << GPIO_PIN_CNF_PULL_Pos)  |
     636         [ #  # ]:          0 :            ((uint32_t)(p_drive ? *p_drive : 0) << GPIO_PIN_CNF_DRIVE_Pos) |
     637         [ #  # ]:          0 :            ((uint32_t)(p_sense ? *p_sense : 0)<< GPIO_PIN_CNF_SENSE_Pos);
     638                 :            : 
     639                 :          0 :     reg->PIN_CNF[pin_number] = cnf;
     640                 :          0 : }
     641                 :            : 
     642                 :            : NRF_STATIC_INLINE void nrf_gpio_cfg_output(uint32_t pin_number)
     643                 :            : {
     644                 :            :     nrf_gpio_cfg(
     645                 :            :         pin_number,
     646                 :            :         NRF_GPIO_PIN_DIR_OUTPUT,
     647                 :            :         NRF_GPIO_PIN_INPUT_DISCONNECT,
     648                 :            :         NRF_GPIO_PIN_NOPULL,
     649                 :            :         NRF_GPIO_PIN_S0S1,
     650                 :            :         NRF_GPIO_PIN_NOSENSE);
     651                 :            : }
     652                 :            : 
     653                 :            : 
     654                 :            : NRF_STATIC_INLINE void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config)
     655                 :            : {
     656                 :            :     nrf_gpio_cfg(
     657                 :            :         pin_number,
     658                 :            :         NRF_GPIO_PIN_DIR_INPUT,
     659                 :            :         NRF_GPIO_PIN_INPUT_CONNECT,
     660                 :            :         pull_config,
     661                 :            :         NRF_GPIO_PIN_S0S1,
     662                 :            :         NRF_GPIO_PIN_NOSENSE);
     663                 :            : }
     664                 :            : 
     665                 :            : 
     666                 :          0 : NRF_STATIC_INLINE void nrf_gpio_cfg_default(uint32_t pin_number)
     667                 :            : {
     668                 :          0 :     nrf_gpio_cfg(
     669                 :            :         pin_number,
     670                 :            :         NRF_GPIO_PIN_DIR_INPUT,
     671                 :            :         NRF_GPIO_PIN_INPUT_DISCONNECT,
     672                 :            :         NRF_GPIO_PIN_NOPULL,
     673                 :            :         NRF_GPIO_PIN_S0S1,
     674                 :            :         NRF_GPIO_PIN_NOSENSE);
     675                 :          0 : }
     676                 :            : 
     677                 :            : 
     678                 :            : NRF_STATIC_INLINE void nrf_gpio_cfg_watcher(uint32_t pin_number)
     679                 :            : {
     680                 :            :     nrf_gpio_pin_input_t input = NRF_GPIO_PIN_INPUT_CONNECT;
     681                 :            : 
     682                 :            :     nrf_gpio_reconfigure(pin_number, NULL, &input, NULL, NULL, NULL);
     683                 :            : }
     684                 :            : 
     685                 :            : 
     686                 :            : NRF_STATIC_INLINE void nrf_gpio_input_disconnect(uint32_t pin_number)
     687                 :            : {
     688                 :            :     nrf_gpio_pin_input_t input = NRF_GPIO_PIN_INPUT_DISCONNECT;
     689                 :            : 
     690                 :            :     nrf_gpio_reconfigure(pin_number, NULL, &input, NULL, NULL, NULL);
     691                 :            : }
     692                 :            : 
     693                 :            : 
     694                 :            : NRF_STATIC_INLINE void nrf_gpio_cfg_sense_input(uint32_t             pin_number,
     695                 :            :                                                 nrf_gpio_pin_pull_t  pull_config,
     696                 :            :                                                 nrf_gpio_pin_sense_t sense_config)
     697                 :            : {
     698                 :            :     nrf_gpio_cfg(
     699                 :            :         pin_number,
     700                 :            :         NRF_GPIO_PIN_DIR_INPUT,
     701                 :            :         NRF_GPIO_PIN_INPUT_CONNECT,
     702                 :            :         pull_config,
     703                 :            :         NRF_GPIO_PIN_S0S1,
     704                 :            :         sense_config);
     705                 :            : }
     706                 :            : 
     707                 :            : 
     708                 :          0 : NRF_STATIC_INLINE void nrf_gpio_cfg_sense_set(uint32_t             pin_number,
     709                 :            :                                               nrf_gpio_pin_sense_t sense_config)
     710                 :            : {
     711                 :          0 :     nrf_gpio_reconfigure(pin_number, NULL, NULL, NULL, NULL, &sense_config);
     712                 :          0 : }
     713                 :            : 
     714                 :            : NRF_STATIC_INLINE void nrf_gpio_pin_dir_set(uint32_t pin_number, nrf_gpio_pin_dir_t direction)
     715                 :            : {
     716                 :            :     if (direction == NRF_GPIO_PIN_DIR_INPUT)
     717                 :            :     {
     718                 :            :         nrf_gpio_cfg(
     719                 :            :             pin_number,
     720                 :            :             NRF_GPIO_PIN_DIR_INPUT,
     721                 :            :             NRF_GPIO_PIN_INPUT_CONNECT,
     722                 :            :             NRF_GPIO_PIN_NOPULL,
     723                 :            :             NRF_GPIO_PIN_S0S1,
     724                 :            :             NRF_GPIO_PIN_NOSENSE);
     725                 :            :     }
     726                 :            :     else
     727                 :            :     {
     728                 :            :         NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
     729                 :            :         reg->DIRSET = (1UL << pin_number);
     730                 :            :     }
     731                 :            : }
     732                 :            : 
     733                 :            : 
     734                 :          2 : NRF_STATIC_INLINE void nrf_gpio_pin_set(uint32_t pin_number)
     735                 :            : {
     736                 :          2 :     NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
     737                 :            : 
     738                 :          2 :     nrf_gpio_port_out_set(reg, 1UL << pin_number);
     739                 :          2 : }
     740                 :            : 
     741                 :            : 
     742                 :          0 : NRF_STATIC_INLINE void nrf_gpio_pin_clear(uint32_t pin_number)
     743                 :            : {
     744                 :          0 :     NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
     745                 :            : 
     746                 :          0 :     nrf_gpio_port_out_clear(reg, 1UL << pin_number);
     747                 :          0 : }
     748                 :            : 
     749                 :            : 
     750                 :          0 : NRF_STATIC_INLINE void nrf_gpio_pin_toggle(uint32_t pin_number)
     751                 :            : {
     752                 :          0 :     NRF_GPIO_Type * reg        = nrf_gpio_pin_port_decode(&pin_number);
     753                 :          0 :     uint32_t        pins_state = reg->OUT;
     754                 :            : 
     755                 :          0 :     reg->OUTSET = (~pins_state & (1UL << pin_number));
     756                 :          0 :     reg->OUTCLR = (pins_state & (1UL << pin_number));
     757                 :          0 : }
     758                 :            : 
     759                 :            : 
     760                 :          2 : NRF_STATIC_INLINE void nrf_gpio_pin_write(uint32_t pin_number, uint32_t value)
     761                 :            : {
     762         [ -  + ]:          2 :     if (value == 0)
     763                 :            :     {
     764                 :          0 :         nrf_gpio_pin_clear(pin_number);
     765                 :            :     }
     766                 :            :     else
     767                 :            :     {
     768                 :          2 :         nrf_gpio_pin_set(pin_number);
     769                 :            :     }
     770                 :          2 : }
     771                 :            : 
     772                 :            : 
     773                 :          0 : NRF_STATIC_INLINE uint32_t nrf_gpio_pin_read(uint32_t pin_number)
     774                 :            : {
     775                 :          0 :     NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
     776                 :            : 
     777                 :          0 :     return ((nrf_gpio_port_in_read(reg) >> pin_number) & 1UL);
     778                 :            : }
     779                 :            : 
     780                 :            : 
     781                 :            : NRF_STATIC_INLINE uint32_t nrf_gpio_pin_out_read(uint32_t pin_number)
     782                 :            : {
     783                 :            :     NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
     784                 :            : 
     785                 :            :     return ((nrf_gpio_port_out_read(reg) >> pin_number) & 1UL);
     786                 :            : }
     787                 :            : 
     788                 :            : 
     789                 :          0 : NRF_STATIC_INLINE nrf_gpio_pin_sense_t nrf_gpio_pin_sense_get(uint32_t pin_number)
     790                 :            : {
     791                 :          0 :     NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
     792                 :            : 
     793                 :          0 :     return (nrf_gpio_pin_sense_t)((reg->PIN_CNF[pin_number] &
     794                 :          0 :                                    GPIO_PIN_CNF_SENSE_Msk) >> GPIO_PIN_CNF_SENSE_Pos);
     795                 :            : }
     796                 :            : 
     797                 :            : 
     798                 :          0 : NRF_STATIC_INLINE nrf_gpio_pin_dir_t nrf_gpio_pin_dir_get(uint32_t pin_number)
     799                 :            : {
     800                 :          0 :     NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
     801                 :            : 
     802                 :          0 :     return (nrf_gpio_pin_dir_t)((reg->PIN_CNF[pin_number] &
     803                 :            :                                  GPIO_PIN_CNF_DIR_Msk) >> GPIO_PIN_CNF_DIR_Pos);
     804                 :            : }
     805                 :            : 
     806                 :            : NRF_STATIC_INLINE nrf_gpio_pin_input_t nrf_gpio_pin_input_get(uint32_t pin_number)
     807                 :            : {
     808                 :            :     NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
     809                 :            : 
     810                 :            :     return (nrf_gpio_pin_input_t)((reg->PIN_CNF[pin_number] &
     811                 :            :                                    GPIO_PIN_CNF_INPUT_Msk) >> GPIO_PIN_CNF_INPUT_Pos);
     812                 :            : }
     813                 :            : 
     814                 :            : NRF_STATIC_INLINE nrf_gpio_pin_pull_t nrf_gpio_pin_pull_get(uint32_t pin_number)
     815                 :            : {
     816                 :            :     NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
     817                 :            : 
     818                 :            :     return (nrf_gpio_pin_pull_t)((reg->PIN_CNF[pin_number] &
     819                 :            :                                   GPIO_PIN_CNF_PULL_Msk) >> GPIO_PIN_CNF_PULL_Pos);
     820                 :            : }
     821                 :            : 
     822                 :            : 
     823                 :            : NRF_STATIC_INLINE void nrf_gpio_port_dir_output_set(NRF_GPIO_Type * p_reg, uint32_t out_mask)
     824                 :            : {
     825                 :            :     p_reg->DIRSET = out_mask;
     826                 :            : }
     827                 :            : 
     828                 :            : 
     829                 :            : NRF_STATIC_INLINE void nrf_gpio_port_dir_input_set(NRF_GPIO_Type * p_reg, uint32_t in_mask)
     830                 :            : {
     831                 :            :     p_reg->DIRCLR = in_mask;
     832                 :            : }
     833                 :            : 
     834                 :            : 
     835                 :            : NRF_STATIC_INLINE void nrf_gpio_port_dir_write(NRF_GPIO_Type * p_reg, uint32_t value)
     836                 :            : {
     837                 :            :     p_reg->DIR = value;
     838                 :            : }
     839                 :            : 
     840                 :            : 
     841                 :            : NRF_STATIC_INLINE uint32_t nrf_gpio_port_dir_read(NRF_GPIO_Type const * p_reg)
     842                 :            : {
     843                 :            :     return p_reg->DIR;
     844                 :            : }
     845                 :            : 
     846                 :            : 
     847                 :          0 : NRF_STATIC_INLINE uint32_t nrf_gpio_port_in_read(NRF_GPIO_Type const * p_reg)
     848                 :            : {
     849                 :          0 :     return p_reg->IN;
     850                 :            : }
     851                 :            : 
     852                 :            : 
     853                 :          0 : NRF_STATIC_INLINE uint32_t nrf_gpio_port_out_read(NRF_GPIO_Type const * p_reg)
     854                 :            : {
     855                 :          0 :     return p_reg->OUT;
     856                 :            : }
     857                 :            : 
     858                 :            : 
     859                 :          0 : NRF_STATIC_INLINE void nrf_gpio_port_out_write(NRF_GPIO_Type * p_reg, uint32_t value)
     860                 :            : {
     861                 :          0 :     p_reg->OUT = value;
     862                 :          0 : }
     863                 :            : 
     864                 :            : 
     865                 :          2 : NRF_STATIC_INLINE void nrf_gpio_port_out_set(NRF_GPIO_Type * p_reg, uint32_t set_mask)
     866                 :            : {
     867                 :          2 :     p_reg->OUTSET = set_mask;
     868                 :          2 : }
     869                 :            : 
     870                 :            : 
     871                 :          0 : NRF_STATIC_INLINE void nrf_gpio_port_out_clear(NRF_GPIO_Type * p_reg, uint32_t clr_mask)
     872                 :            : {
     873                 :          0 :     p_reg->OUTCLR = clr_mask;
     874                 :          0 : }
     875                 :            : 
     876                 :            : 
     877                 :            : NRF_STATIC_INLINE void nrf_gpio_ports_read(uint32_t   start_port,
     878                 :            :                                            uint32_t   length,
     879                 :            :                                            uint32_t * p_masks)
     880                 :            : {
     881                 :            :     NRF_GPIO_Type * gpio_regs[GPIO_COUNT] = GPIO_REG_LIST;
     882                 :            : 
     883                 :            :     NRFX_ASSERT(start_port + length <= GPIO_COUNT);
     884                 :            :     uint32_t i;
     885                 :            : 
     886                 :            :     for (i = start_port; i < (start_port + length); i++)
     887                 :            :     {
     888                 :            :         *p_masks = nrf_gpio_port_in_read(gpio_regs[i]);
     889                 :            :         p_masks++;
     890                 :            :     }
     891                 :            : }
     892                 :            : 
     893                 :            : 
     894                 :            : #if defined(NRF_GPIO_LATCH_PRESENT)
     895                 :            : NRF_STATIC_INLINE void nrf_gpio_latches_read(uint32_t   start_port,
     896                 :            :                                              uint32_t   length,
     897                 :            :                                              uint32_t * p_masks)
     898                 :            : {
     899                 :            :     NRF_GPIO_Type * gpio_regs[GPIO_COUNT] = GPIO_REG_LIST;
     900                 :            :     uint32_t        i;
     901                 :            : 
     902                 :            :     for (i = start_port; i < (start_port + length); i++)
     903                 :            :     {
     904                 :            :         *p_masks = gpio_regs[i]->LATCH;
     905                 :            :         p_masks++;
     906                 :            :     }
     907                 :            : }
     908                 :            : 
     909                 :          0 : NRF_STATIC_INLINE void nrf_gpio_latches_read_and_clear(uint32_t   start_port,
     910                 :            :                                                        uint32_t   length,
     911                 :            :                                                        uint32_t * p_masks)
     912                 :            : {
     913                 :          0 :     NRF_GPIO_Type * gpio_regs[GPIO_COUNT] = GPIO_REG_LIST;
     914                 :            :     uint32_t        i;
     915                 :            : 
     916         [ #  # ]:          0 :     for (i = start_port; i < (start_port + length); i++)
     917                 :            :     {
     918                 :          0 :         *p_masks = gpio_regs[i]->LATCH;
     919                 :            : 
     920                 :            :         // The LATCH register is cleared by writing a '1' to the bit that shall be cleared.
     921                 :          0 :         gpio_regs[i]->LATCH = *p_masks;
     922                 :            : 
     923                 :          0 :         p_masks++;
     924                 :            :     }
     925                 :          0 : }
     926                 :            : 
     927                 :            : NRF_STATIC_INLINE uint32_t nrf_gpio_pin_latch_get(uint32_t pin_number)
     928                 :            : {
     929                 :            :     NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
     930                 :            : 
     931                 :            :     return (reg->LATCH & (1 << pin_number)) ? 1 : 0;
     932                 :            : }
     933                 :            : 
     934                 :            : 
     935                 :          0 : NRF_STATIC_INLINE void nrf_gpio_pin_latch_clear(uint32_t pin_number)
     936                 :            : {
     937                 :          0 :     NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
     938                 :            : 
     939                 :          0 :     reg->LATCH = (1 << pin_number);
     940                 :          0 : }
     941                 :            : #endif // defined(NRF_GPIO_LATCH_PRESENT)
     942                 :            : 
     943                 :            : #if defined(GPIO_PIN_CNF_MCUSEL_Msk)
     944                 :          2 : NRF_STATIC_INLINE void nrf_gpio_pin_mcu_select(uint32_t pin_number, nrf_gpio_pin_mcusel_t mcu)
     945                 :            : {
     946                 :          2 :     NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
     947                 :          2 :     uint32_t cnf = reg->PIN_CNF[pin_number] & ~GPIO_PIN_CNF_MCUSEL_Msk;
     948                 :          2 :     reg->PIN_CNF[pin_number] = cnf | (mcu << GPIO_PIN_CNF_MCUSEL_Pos);
     949                 :          2 : }
     950                 :            : #endif
     951                 :            : 
     952                 :          8 : NRF_STATIC_INLINE bool nrf_gpio_pin_present_check(uint32_t pin_number)
     953                 :            : {
     954                 :          8 :     uint32_t port = pin_number >> 5;
     955                 :          8 :     uint32_t mask = 0;
     956                 :            : 
     957      [ +  -  - ]:          8 :     switch (port)
     958                 :            :     {
     959                 :            : #ifdef P0_FEATURE_PINS_PRESENT
     960                 :          8 :         case 0:
     961                 :          8 :             mask = P0_FEATURE_PINS_PRESENT;
     962                 :            : #if defined(NRF52820_XXAA) && defined(DEVELOP_IN_NRF52833)
     963                 :            :             /* Allow use of the following additional GPIOs that are connected to LEDs and buttons
     964                 :            :              * on the nRF52833 DK:
     965                 :            :              * - P0.11 - Button 1
     966                 :            :              * - P0.12 - Button 2
     967                 :            :              * - P0.13 - LED 1
     968                 :            :              * - P0.24 - Button 3
     969                 :            :              * - P0.25 - Button 4
     970                 :            :              */
     971                 :            :             mask |= 0x03003800;
     972                 :            : #endif // defined(NRF52820_XXAA) && defined(DEVELOP_IN_NRF52833)
     973                 :          8 :             break;
     974                 :            : #endif
     975                 :            : #ifdef P1_FEATURE_PINS_PRESENT
     976                 :          0 :         case 1:
     977                 :          0 :             mask = P1_FEATURE_PINS_PRESENT;
     978                 :          0 :             break;
     979                 :            : #endif
     980                 :            :     }
     981                 :            : 
     982                 :          8 :     pin_number &= 0x1F;
     983                 :            : 
     984                 :          8 :     return (mask & (1UL << pin_number)) ? true : false;
     985                 :            : }
     986                 :            : 
     987                 :          8 : NRF_STATIC_INLINE uint32_t nrf_gpio_pin_port_number_extract(uint32_t * p_pin)
     988                 :            : {
     989                 :          8 :     uint32_t pin_number = *p_pin;
     990                 :          8 :     *p_pin = pin_number & 0x1F;
     991                 :            : 
     992                 :          8 :     return pin_number >> 5;
     993                 :            : }
     994                 :            : 
     995                 :            : #endif // NRF_DECLARE_ONLY
     996                 :            : 
     997                 :            : /** @} */
     998                 :            : 
     999                 :            : #ifdef __cplusplus
    1000                 :            : }
    1001                 :            : #endif
    1002                 :            : 
    1003                 :            : #endif // NRF_GPIO_H__

Generated by: LCOV version 1.14