GPIO

group GPIO

GPIO (General Peripheral Input/Output)

The GPIO driver provides support for controlling GPIOs. The available GPIOs are listed in pmsis/chips folder.

Defines

PI_GPIO_FLAG_PADCFG_MASK

Filter the content of pi_gpio_flags_e to get data dedicated to PADCFG register.

PI_GPIO_FLAG_PULL_MASK
PI_GPIO_FLAG_DRIVE_STRENGHT_MASK
PI_GPIO_FLAG_SCHMITT_TRIGGER_MASK
PI_GPIO_FLAG_DIR_MASK
PI_GPIO_ARE_BOTH_PULL_ENABLED(flag)

Typedefs

typedef struct pi_gpio_callback_s pi_gpio_callback_t

Enums

enum pi_gpio_flags_e

GPIO configuration flags.

Flags to configure gpio : input/output mode, drive strength, pull activation.

Values:

enumerator PI_GPIO_PULL_DISABLE = (0b00 << PI_GPIO_PULL_OFFSET)

Disable pull.

enumerator PI_GPIO_PULL_DOWN = (0b01 << PI_GPIO_PULL_OFFSET)

Enable pull down.

enumerator PI_GPIO_PULL_UP = (0b10 << PI_GPIO_PULL_OFFSET)

Enable pull up.

enumerator PI_GPIO_DRIVE_STRENGTH_LOW = (0b00 << PI_GPIO_DRIVE_OFFSET)

1mA drive strength.

enumerator PI_GPIO_DRIVE_STRENGTH_MODERATE = (0b01 << PI_GPIO_DRIVE_OFFSET)

4mA drive strength.

enumerator PI_GPIO_DRIVE_STRENGTH_MEDIUM = (0b10 << PI_GPIO_DRIVE_OFFSET)

8mA drive strength.

enumerator PI_GPIO_DRIVE_STRENGTH_HIGH = (0b11 << PI_GPIO_DRIVE_OFFSET)

12mA drive strength.

enumerator PI_GPIO_SCHMITT_TRIGGER_DISABLE = (0b0 << PI_GPIO_SCHMITT_TRIGGER_OFFSET)

Schmitt trigger disabled.

enumerator PI_GPIO_SCHMITT_TRIGGER_ENABLE = (0b1 << PI_GPIO_SCHMITT_TRIGGER_OFFSET)

Schmitt trigger enabled.

enumerator PI_GPIO_INPUT = (0b0 << PI_GPIO_DIR_OFFSET)

GPIO is an input.

enumerator PI_GPIO_OUTPUT = (0b1 << PI_GPIO_DIR_OFFSET)

GPIO is an output.

enum pi_gpio_notif_e

Sensitivity of a GPIO for notifications.

This is used to tell which GPIO value modification will trigger a notification(IRQ).

Values:

enumerator PI_GPIO_NOTIF_FALL = (0 << PI_GPIO_IRQ_TYPE_OFFSET)

IRQ are sent on a falling edge on the GPIO value.

enumerator PI_GPIO_NOTIF_RISE = (1 << PI_GPIO_IRQ_TYPE_OFFSET)

IRQ are sent on a rising edge on the GPIO value.

enumerator PI_GPIO_NOTIF_EDGE = (2 << PI_GPIO_IRQ_TYPE_OFFSET)

IRQ are sent on a rising or a falling edge on the GPIO value.

enumerator PI_GPIO_NOTIF_NONE = (3 << PI_GPIO_IRQ_TYPE_OFFSET)

No IRQ.

Functions

int32_t pi_gpio_pin_configure(pi_gpio_e gpio, pi_gpio_flags_e flags)

Configure a GPIO.

This function can be used to configure several aspects of a GPIO, like the direction.

Parameters:
  • gpio – GPIO enumerate type or GPIO number within the port (from 0 to 31).

  • flags – A bitfield of flags specifying how to configure the GPIO.

Return values:
  • 0 – If the operation is successfull.

  • ERRNO – An error code otherwise.

int32_t pi_gpio_pin_toggle(uint32_t pin)

GPIO toggle.

This function can be used to toggle a single GPIO.

Note

The pin parameter can be a GPIO enumerate type pi_gpio_e.

Note

This function is to be used on GPIO pins configured as PI_GPIO_OUTPUT.

Parameters:
  • pin – The GPIO number within the port (from 0 to 31).

Return values:
  • 0 – If the operation is successfull.

  • ERRNO – An error code otherwise.

int32_t pi_gpio_pin_write(uint32_t pin, uint32_t value)

Set value of a single GPIO.

This function can be used to change the value of a single GPIO.

Note

The pin parameter can be a GPIO enumerate type pi_gpio_e.

Note

This function is to be used on GPIO pins configured as PI_GPIO_OUTPUT.

Parameters:
  • pin – The GPIO number within the port (from 0 to 31).

  • value – The value to be set. This can be either 0 or 1.

Return values:
  • 0 – If the operation is successfull.

  • ERRNO – An error code otherwise.

int32_t pi_gpio_pin_read(uint32_t pin, uint32_t *value)

Get value of a single GPIO.

This function can be used to get the value of a single GPIO. It will store the current input value of a GPIO pin into a given buffer.

Note

The pin parameter can be a GPIO enumerate type pi_gpio_e.

Note

This function should be used on GPIO pins configured as PI_GPIO_INPUT. Although this function can be used to retrieve current value set on a GPIO pin configured as PI_GPIO_OUTPUT.

Parameters:
  • pin – The GPIO number within the port (from 0 to 31).

  • value – A pointer to the variable where the GPIO value should be returned. The value will be either 0 or 1.

Return values:
  • 0 – If the operation is successfull.

  • ERRNO – An error code otherwise.

void pi_gpio_pin_notif_configure(uint32_t pin, pi_gpio_notif_e flags)

Configure notifications for a GPIO.

This function can be used to configure how to be notified by GPIO value modifications. By default, notifications will be buffered and can be read and cleared.

Note

The pin parameter can be a GPIO enumerate type pi_gpio_e.

Parameters:
  • pin – The GPIO number within the port (from 0 to 31).

  • flags – The flags to configure how the notification should be triggered.

void pi_gpio_pin_notif_clear(uint32_t pin)

Clear notification for a GPIO.

This function can be used to clear the notification of a GPIO. A GPIO notification is buffered and ths function must be called to clear it so that a new one can be seen.

Note

The pin parameter can be a GPIO enumerate type pi_gpio_e.

Parameters:
  • pin – The GPIO number within the port (from 0 to 31).

int32_t pi_gpio_pin_notif_get(uint32_t pin)

Get the value of a notification for a GPIO.

This function can be used to get the value of a notification of a GPIO. It returns 1 if at least one notification was received since the last time it was cleared. Reading the notification does not clear it.

Note

The pin parameter can be a GPIO enumerate type pi_gpio_e.

Parameters:
  • pin – The GPIO number within the port (from 0 to 31).

Return values:
  • 0 – If a notification was received.

  • 1 – Otherwise.

int32_t pi_gpio_pin_task_add(uint32_t pin, pi_evt_t *task, pi_gpio_notif_e flags)

Attach an event task callback to a GPIO pin.

This function is used to attach a callback that will be called when a GPIO triggers an IRQ.

This callback is executed by the event kernel.

Note

The pin parameter can be a GPIO enumerate type pi_gpio_e.

Parameters:
  • pin – The GPIO number within the port (from 0 to 31).

  • task – Event task executed when an IRQ is triggered.

  • flags – The flags to configure how the notification should be triggered.

Return values:
  • 0 – If the operation is successfull.

  • ERRNO – An error code otherwise.

int32_t pi_gpio_pin_task_remove(uint32_t pin)

Remove an event task callback attached to a GPIO pin.

This function is used to remove an attached callback to a GPIO pin. If a IRQ is triggered on the given pin, after removal of the event task, no handler will executed.

Note

The pin parameter can be a GPIO enumerate type pi_gpio_e.

Parameters:
  • pin – The GPIO number within the port (from 0 to 31).

Return values:
  • 0 – If the operation is successfull.

  • ERRNO – An error code otherwise.

struct pi_gpio_callback_s
#include <gpio.h>

GPIO callback struct.

This structure is used by IRQ handler to replace regular GPIO IRQ handler.

Public Members

uint32_t pin_mask

Mask of GPIO pins.

pi_callback_func_t handler

Callback handler.

void *args

Callback user args.

struct pi_gpio_callback_s *next

Next callback pointer.

struct pi_gpio_callback_s *prev

Previous callback pointer.