GPIOTE driver

group nrfx_gpiote

GPIO Task Event (GPIOTE) peripheral driver.

Defines

NRFX_GPIOTE_CONFIG_IN_SENSE_LOTOHI(hi_accu)

Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect low-to-high transition.

Set hi_accu to true to use IN_EVENT.

NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(hi_accu)

Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect high-to-low transition.

Set hi_accu to true to use IN_EVENT.

NRFX_GPIOTE_CONFIG_IN_SENSE_TOGGLE(hi_accu)

Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect any change on the pin.

Set hi_accu to true to use IN_EVENT.

NRFX_GPIOTE_RAW_CONFIG_IN_SENSE_LOTOHI(hi_accu)

Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect low-to-high transition.

Set hi_accu to true to use IN_EVENT.

Note

This macro prepares configuration that skips the GPIO setup.

NRFX_GPIOTE_RAW_CONFIG_IN_SENSE_HITOLO(hi_accu)

Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect high-to-low transition.

Set hi_accu to true to use IN_EVENT.

Note

This macro prepares configuration that skips the GPIO setup.

NRFX_GPIOTE_RAW_CONFIG_IN_SENSE_TOGGLE(hi_accu)

Macro for configuring a pin to use a GPIO IN or PORT EVENT to detect any change on the pin.

Set hi_accu to true to use IN_EVENT.

Note

This macro prepares configuration that skips the GPIO setup.

NRFX_GPIOTE_CONFIG_OUT_SIMPLE(init_high)

Macro for configuring a pin to use as output. GPIOTE is not used for the pin.

NRFX_GPIOTE_CONFIG_OUT_TASK_LOW

Macro for configuring a pin to use the GPIO OUT TASK to change the state from high to low.

The task will clear the pin. Therefore, the pin is set initially.

NRFX_GPIOTE_CONFIG_OUT_TASK_HIGH

Macro for configuring a pin to use the GPIO OUT TASK to change the state from low to high.

The task will set the pin. Therefore, the pin is cleared initially.

NRFX_GPIOTE_CONFIG_OUT_TASK_TOGGLE(init_high)

Macro for configuring a pin to use the GPIO OUT TASK to toggle the pin state.

The initial pin state must be provided.

NRFX_GPIOTE_APP_CHANNELS_MASK

Bitfield representing all GPIOTE channels available to the application.

Typedefs

typedef uint32_t nrfx_gpiote_pin_t

Pin.

typedef void (*nrfx_gpiote_evt_handler_t)(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action)

Pin event handler prototype.

Parameters
  • pin[in] Pin that triggered this event.

  • action[in] Action that led to triggering this event.

Functions

nrfx_err_t nrfx_gpiote_init(uint8_t interrupt_priority)

Function for initializing the GPIOTE module.

Parameters
  • interrupt_priority[in] Interrupt priority.

Returns NRFX_SUCCESS

Initialization was successful.

Returns NRFX_ERROR_INVALID_STATE

The driver was already initialized.

bool nrfx_gpiote_is_init(void)

Function for checking if the GPIOTE module is initialized.

The GPIOTE module is a shared module. Therefore, check if the module is already initialized and skip initialization if it is.

Returns true

The module is already initialized.

Returns false

The module is not initialized.

void nrfx_gpiote_uninit(void)

Function for uninitializing the GPIOTE module.

nrfx_err_t nrfx_gpiote_channel_alloc(uint8_t *p_channel)

Function for allocating a GPIOTE channel.

This function allocates the first unused GPIOTE channel from pool defined in NRFX_GPIOTE_APP_CHANNELS_MASK.

Note

To ensure the thread safety of the operation, this function uses the NRFX_CRITICAL_SECTION_ENTER and NRFX_CRITICAL_SECTION_EXIT macros. No further synchronization mechanism is needed, provided the macros are properly implemented (see nrfx_glue.h).

Note

Routines that allocate and free the GPIOTE channels are independent from the rest of the driver. In particular, the driver does not need to be initialized when this function is called.

Parameters
  • p_channel[out] Pointer to the GPIOTE channel that has been allocated.

Returns NRFX_SUCCESS

The channel was successfully allocated.

Returns NRFX_ERROR_NO_MEM

There is no available channel to be used.

nrfx_err_t nrfx_gpiote_channel_free(uint8_t channel)

Function for freeing a GPIOTE channel.

This function frees a GPIOTE channel that was allocated using nrfx_gpiote_channel_alloc.

Note

To ensure the thread safety of the operation, this function uses the NRFX_CRITICAL_SECTION_ENTER and NRFX_CRITICAL_SECTION_EXIT macros. No further synchronization mechanism is needed, provided the macros are properly implemented (see nrfx_glue.h).

Note

Routines that allocate and free the GPIOTE channels are independent from the rest of the driver. In particular, the driver does not need to be initialized when this function is called.

Parameters
  • channel[in] GPIOTE channel to be freed.

Returns NRFX_SUCCESS

The channel was successfully freed.

Returns NRFX_ERROR_INVALID_PARAM

The channel is not user-configurable.

nrfx_err_t nrfx_gpiote_out_init(nrfx_gpiote_pin_t pin, nrfx_gpiote_out_config_t const *p_config)

Function for initializing a GPIOTE output pin.

The output pin can be controlled by the CPU or by PPI. The initial configuration specifies which mode is used. If PPI mode is used, the driver attempts to allocate one of the available GPIOTE channels. If no channel is available, an error is returned.

Parameters
  • pin[in] Pin.

  • p_config[in] Initial configuration.

Returns NRFX_SUCCESS

Initialization was successful.

Returns NRFX_ERROR_BUSY

The pin is already used.

Returns NRFX_ERROR_NO_MEM

No GPIOTE channel is available.

nrfx_err_t nrfx_gpiote_out_prealloc_init(nrfx_gpiote_pin_t pin, nrfx_gpiote_out_config_t const *p_config, uint8_t channel)

Function for initializing a GPIOTE output pin with preallocated channel.

The output pin can be controlled by PPI.

Parameters
  • pin[in] Pin.

  • p_config[in] Initial configuration.

  • channel[in] GPIOTE channel allocated with nrfx_gpiote_channel_alloc.

Returns NRFX_SUCCESS

Initialization was successful.

Returns NRFX_ERROR_BUSY

The pin is already used.

Returns NRFX_ERROR_INVALID_PARAM

Pin is configured to not be controlled by the GPIOTE task and cannot be used with preallocated channel. Use nrfx_gpiote_out_init instead.

void nrfx_gpiote_out_uninit(nrfx_gpiote_pin_t pin)

Function for uninitializing a GPIOTE output pin.

The driver frees the GPIOTE channel if the output pin was using one.

Parameters
  • pin[in] Pin.

void nrfx_gpiote_out_set(nrfx_gpiote_pin_t pin)

Function for setting a GPIOTE output pin.

Parameters
  • pin[in] Pin.

void nrfx_gpiote_out_clear(nrfx_gpiote_pin_t pin)

Function for clearing a GPIOTE output pin.

Parameters
  • pin[in] Pin.

void nrfx_gpiote_out_toggle(nrfx_gpiote_pin_t pin)

Function for toggling a GPIOTE output pin.

Parameters
  • pin[in] Pin.

void nrfx_gpiote_out_task_enable(nrfx_gpiote_pin_t pin)

Function for enabling a GPIOTE output pin task.

Parameters
  • pin[in] Pin.

void nrfx_gpiote_out_task_disable(nrfx_gpiote_pin_t pin)

Function for disabling a GPIOTE output pin task.

Parameters
  • pin[in] Pin.

nrf_gpiote_task_t nrfx_gpiote_out_task_get(nrfx_gpiote_pin_t pin)

Function for getting the OUT task for the specified output pin.

The returned task identifier can be used within GPIOTE HAL, for example, to configure a DPPI channel.

Parameters
  • pin[in] Pin.

Returns

OUT task associated with the specified output pin.

uint32_t nrfx_gpiote_out_task_addr_get(nrfx_gpiote_pin_t pin)

Function for getting the address of the OUT task for the specified output pin.

Parameters
  • pin[in] Pin.

Returns

Address of OUT task.

nrf_gpiote_task_t nrfx_gpiote_set_task_get(nrfx_gpiote_pin_t pin)

Function for getting the SET task for the specified output pin.

The returned task identifier can be used within GPIOTE HAL, for example, to configure a DPPI channel.

Parameters
  • pin[in] Pin.

Returns

SET task associated with the specified output pin.

uint32_t nrfx_gpiote_set_task_addr_get(nrfx_gpiote_pin_t pin)

Function for getting the address of the SET task for the specified output pin.

Parameters
  • pin[in] Pin.

Returns

Address of SET task.

nrf_gpiote_task_t nrfx_gpiote_clr_task_get(nrfx_gpiote_pin_t pin)

Function for getting the CLR task for the specified output pin.

The returned task identifier can be used within GPIOTE HAL, for example, to configure a DPPI channel.

Parameters
  • pin[in] Pin.

Returns

CLR task associated with the specified output pin.

uint32_t nrfx_gpiote_clr_task_addr_get(nrfx_gpiote_pin_t pin)

Function for getting the address of the SET task for the specified output pin.

Parameters
  • pin[in] Pin.

Returns

Address of CLR task.

nrfx_err_t nrfx_gpiote_in_init(nrfx_gpiote_pin_t pin, nrfx_gpiote_in_config_t const *p_config, nrfx_gpiote_evt_handler_t evt_handler)

Function for initializing a GPIOTE input pin.

The input pin can act in two ways:

  • lower accuracy but low power (high frequency clock not needed)

  • higher accuracy (high frequency clock required)

The initial configuration specifies which mode is used. If high-accuracy mode is used, the driver attempts to allocate one of the available GPIOTE channels. If no channel is available, an error is returned. In low accuracy mode SENSE feature is used. In this case, only one active pin can be detected at a time. It can be worked around by setting all of the used low accuracy pins to toggle mode. For more information about SENSE functionality, refer to Product Specification.

Parameters
  • pin[in] Pin.

  • p_config[in] Initial configuration.

  • evt_handler[in] User function to be called when the configured transition occurs.

Returns NRFX_SUCCESS

Initialization was successful.

Returns NRFX_ERROR_BUSY

The pin is already used.

Returns NRFX_ERROR_NO_MEM

No GPIOTE channel is available.

nrfx_err_t nrfx_gpiote_in_prealloc_init(nrfx_gpiote_pin_t pin, nrfx_gpiote_in_config_t const *p_config, uint8_t channel, nrfx_gpiote_evt_handler_t evt_handler)

Function for initializing a GPIOTE input pin with preallocated channel.

The input pin can act in higher accuracy (high frequency clock required) mode.

Parameters
  • pin[in] Pin.

  • p_config[in] Initial configuration.

  • channel[in] GPIOTE channel allocated with nrfx_gpiote_channel_alloc.

  • evt_handler[in] User function to be called when the configured transition occurs.

Returns NRFX_SUCCESS

Initialization was successful.

Returns NRFX_ERROR_BUSY

The pin is already used.

Returns NRFX_ERROR_INVALID_PARAM

Pin is configured to not be controlled by the GPIOTE task and cannot be used with preallocated channel. Use nrfx_gpiote_in_init instead.

void nrfx_gpiote_in_uninit(nrfx_gpiote_pin_t pin)

Function for uninitializing a GPIOTE input pin.

The driver frees the GPIOTE channel if the input pin was using one.

Parameters
  • pin[in] Pin.

void nrfx_gpiote_in_event_enable(nrfx_gpiote_pin_t pin, bool int_enable)

Function for enabling sensing of a GPIOTE input pin.

If the input pin is configured as high-accuracy pin, the function enables an IN_EVENT. Otherwise, the function enables the GPIO sense mechanism. The PORT event is shared between multiple pins, therefore the interrupt is always enabled.

Parameters
  • pin[in] Pin.

  • int_enable[in] True to enable the interrupt. Always valid for a high-accuracy pin.

void nrfx_gpiote_in_event_disable(nrfx_gpiote_pin_t pin)

Function for disabling a GPIOTE input pin.

Parameters
  • pin[in] Pin.

bool nrfx_gpiote_in_is_set(nrfx_gpiote_pin_t pin)

Function for checking if a GPIOTE input pin is set.

Parameters
  • pin[in] Pin.

Returns true

The input pin is set.

Returns false

The input pin is not set.

nrf_gpiote_event_t nrfx_gpiote_in_event_get(nrfx_gpiote_pin_t pin)

Function for getting the GPIOTE event for the specified input pin.

The returned event identifier can be used within GPIOTE HAL, for example, to configure a DPPI channel. If the pin is configured to use low-accuracy mode, the PORT event is returned.

Parameters
  • pin[in] Pin.

Returns

Event associated with the specified input pin.

uint32_t nrfx_gpiote_in_event_addr_get(nrfx_gpiote_pin_t pin)

Function for getting the address of a GPIOTE input pin event.

If the pin is configured to use low-accuracy mode, the address of the PORT event is returned.

Parameters
  • pin[in] Pin.

Returns

Address of the specified input pin event.

void nrfx_gpiote_out_task_force(nrfx_gpiote_pin_t pin, uint8_t state)

Function for forcing a specific state on the pin configured as task.

Parameters
  • pin[in] Pin.

  • state[in] Pin state.

void nrfx_gpiote_out_task_trigger(nrfx_gpiote_pin_t pin)

Function for triggering the task OUT manually.

Parameters
  • pin[in] Pin.

void nrfx_gpiote_set_task_trigger(nrfx_gpiote_pin_t pin)

Function for triggering the task SET manually.

Parameters
  • pin[in] Pin.

void nrfx_gpiote_clr_task_trigger(nrfx_gpiote_pin_t pin)

Function for triggering the task CLR manually.

Parameters
  • pin[in] Pin.

struct nrfx_gpiote_in_config_t
#include <nrfx_gpiote.h>

Input pin configuration.

Public Members

nrf_gpiote_polarity_t sense

Transition that triggers the interrupt.

nrf_gpio_pin_pull_t pull

Pulling mode.

bool is_watcher

True when the input pin is tracking an output pin.

bool hi_accuracy

True when high accuracy (IN_EVENT) is used.

bool skip_gpio_setup

Do not change GPIO configuration

struct nrfx_gpiote_out_config_t
#include <nrfx_gpiote.h>

Output pin configuration.

Public Members

nrf_gpiote_polarity_t action

Configuration of the pin task.

nrf_gpiote_outinit_t init_state

Initial state of the output pin.

bool task_pin

True if the pin is controlled by a GPIOTE task.