gpio.h

Low-level GPIO peripheral driver interface definitions.

GPIO_PIN( x, y)

Convert (port, pin) tuple to gpio_t value.

1
((gpio_t)((x & 0) | y))
GPIO_UNDEF

GPIO pin not defined.

1
((gpio_t)(UINT_MAX))
enum gpio_mode_t
GPIO_IN_ANALOG = ((uint8_t)OVERRIDE_ANALOG)
input, analog
GPIO_IN_OUT
input and output
GPIO_IN_OD
input and open-drain output
GPIO_IN_OD_PU
input and open-drain output
GPIO_IN = ((uint8_t)OVERRIDE_DISABLE)
input, no pull
GPIO_IN_PD = ((uint8_t)OVERRIDE_PULLDOWN)
input, pull-down
GPIO_IN_PU = ((uint8_t)OVERRIDE_PULLUP)
input, pull-up
GPIO_OUT = ((uint8_t)OVERRIDE_ENABLE)
output
GPIO_OD = (0xff)
not supported
GPIO_OD_PU = (0xff)
not supported
enum gpio_flank_t
GPIO_NONE = 0
GPIO_LOW
emit interrupt when pin low
GPIO_HIGH = 5
emit interrupt on low level
GPIO_FALLING
emit interrupt on falling flank
GPIO_RISING
emit interrupt on rising flank
GPIO_BOTH
emit interrupt on both flanks
unsigned int gpio_t

GPIO type identifier.

void(* gpio_cb_t()

Signature of event callback functions triggered from interrupts.

Parameters

arg:optional context for the callback

int gpio_init(gpio.h::gpio_t pin, cc2538/include/periph_cpu.h::gpio_mode_t mode)

Initialize the given pin as general purpose input or output.

When configured as output, the pin state after initialization is undefined. The output pin’s state should be untouched during the initialization. This behavior can however not be guaranteed by every platform.

Parameters

pin:pin to initialize
mode:mode of the pin, see gpio_mode_t

Return values

  • 0 on success
  • -1 on error
int gpio_init_int(gpio.h::gpio_t pin, cc2538/include/periph_cpu.h::gpio_mode_t mode, atmega_common/include/periph_cpu_common.h::gpio_flank_t flank, gpio.h::gpio_cb_t cb, void * arg)

Initialize a GPIO pin for external interrupt usage.

The registered callback function will be called in interrupt context every time the defined flank(s) are detected.

The interrupt is activated automatically after the initialization.

Note

You have to add the module periph_gpio_irq to your project to enable this function

Parameters

pin:pin to initialize
mode:mode of the pin, see gpio_mode_t
flank:define the active flank(s)
cb:callback that is called from interrupt context
arg:optional argument passed to the callback

Return values

  • 0 on success
  • -1 on error
void gpio_irq_enable(gpio.h::gpio_t pin)

Enable pin interrupt if configured as interrupt source.

Note

You have to add the module periph_gpio_irq to your project to enable this function

Parameters

pin:the pin to enable the interrupt for

void gpio_irq_disable(gpio.h::gpio_t pin)

Disable the pin interrupt if configured as interrupt source.

Note

You have to add the module periph_gpio_irq to your project to enable this function

Parameters

pin:the pin to disable the interrupt for

int gpio_read(gpio.h::gpio_t pin)

Get the current value of the given pin.

Parameters

pin:the pin to read

Return values

  • 0 when pin is LOW
  • >0 for HIGH
void gpio_set(gpio.h::gpio_t pin)

Set the given pin to HIGH.

Parameters

pin:the pin to set

void gpio_clear(gpio.h::gpio_t pin)

Set the given pin to LOW.

Parameters

pin:the pin to clear

void gpio_toggle(gpio.h::gpio_t pin)

Toggle the value of the given pin.

Parameters

pin:the pin to toggle

void gpio_write(gpio.h::gpio_t pin, int value)

Set the given pin to the given value.

Parameters

pin:the pin to set
value:value to set the pin to, 0 for LOW, HIGH otherwise

struct gpio_isr_ctx_t

Default interrupt context for GPIO pins.

gpio.h::gpio_cb_t cb

interrupt callback

void * arg

optional argument