PMSIS API
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages

GPIO (General Peripheral Input/Output) More...

Data Structures

struct  pi_gpio_conf
 GPIO configuration structure. More...
 
struct  pi_gpio_callback_t
 GPIO callback struct. More...
 

Enumerations

enum  pi_gpio_flags_e
 GPIO configuration flags. More...
 
enum  pi_gpio_notif_e
 Sensitivity of a GPIO for notifications. More...
 

Functions

void pi_gpio_conf_init (struct pi_gpio_conf *conf)
 Initialize a GPIO configuration with default values. More...
 
int pi_gpio_open (struct pi_device *device)
 Open a GPIO device. More...
 
void pi_gpio_close (struct pi_device *device)
 Close an opened GPIO device. More...
 
int pi_gpio_pin_configure (struct pi_device *device, pi_gpio_e gpio, pi_gpio_flags_e flags)
 Configure a GPIO. More...
 
int pi_gpio_pin_write (struct pi_device *device, uint32_t pin, uint32_t value)
 Set value of a single GPIO. More...
 
int pi_gpio_pin_read (struct pi_device *device, uint32_t pin, uint32_t *value)
 Get value of a single GPIO. More...
 
void pi_gpio_pin_notif_configure (struct pi_device *device, uint32_t pin, pi_gpio_notif_e flags)
 Configure notifications for a GPIO. More...
 
void pi_gpio_pin_notif_clear (struct pi_device *device, uint32_t pin)
 Clear notification for a GPIO. More...
 
int pi_gpio_pin_notif_get (struct pi_device *device, uint32_t pin)
 Get the value of a notification for a GPIO. More...
 
int pi_gpio_pin_task_add (struct pi_device *device, uint32_t pin, pi_task_t *task, pi_gpio_notif_e flags)
 Attach an event task callback to a GPIO pin. More...
 
int pi_gpio_pin_task_remove (struct pi_device *device, uint32_t pin)
 Remove an event task callback attached to a GPIO pin. More...
 
static void pi_gpio_callback_init (pi_gpio_callback_t *cb, uint32_t pin_mask, pi_callback_func_t handler, void *arg)
 Init GPIO callback. More...
 
int pi_gpio_callback_add (struct pi_device *device, pi_gpio_callback_t *cb)
 Attach a callback. More...
 
int pi_gpio_callback_remove (struct pi_device *device, pi_gpio_callback_t *cb)
 Remove a callback. More...
 

Description

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

Enumeration Type Documentation

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

Enumerator
PI_GPIO_PULL_DISABLE 

Disable pull.

PI_GPIO_PULL_ENABLE 

Enable pull.

PI_GPIO_DRIVE_STRENGTH_LOW 

Low drive strength.

PI_GPIO_DRIVE_STRENGTH_HIGH 

High drive strength.

PI_GPIO_INPUT 

GPIO is an input.

PI_GPIO_OUTPUT 

GPIO is an output.

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

Enumerator
PI_GPIO_NOTIF_FALL 

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

PI_GPIO_NOTIF_RISE 

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

PI_GPIO_NOTIF_EDGE 

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

PI_GPIO_NOTIF_NONE 

No IRQ.

Function Documentation

int pi_gpio_callback_add ( struct pi_device *  device,
pi_gpio_callback_t cb 
)

Add an application callback to a GPIO device. Multiple callbacks can be attached to a device, and to a GPIO pin.

Parameters
devicePointer to device struct.
cbCallback to add to the list.
Return values
0If operation is successfull.
ERRNOAn error code otherwise.
Note
The callback can initialized with pi_gpio_callback_init().
Using callbacks is incompatible with event handling model(using event tasks cf. pi_gpio_pin_task_add()).
A callback is executed when a GPIO's corresponding bit is set in the callbask mask.
static void pi_gpio_callback_init ( pi_gpio_callback_t cb,
uint32_t  pin_mask,
pi_callback_func_t  handler,
void *  arg 
)
inlinestatic

Intialize a GPIO callback with the handler to call and the user args.

Parameters
cbPointer to callback to initialize.
pin_maskMask of GPIO pins.
handlerCallback function.
argCallback function arg.
int pi_gpio_callback_remove ( struct pi_device *  device,
pi_gpio_callback_t cb 
)

Remove an application callback from a GPIO device.

Parameters
devicePointer to device struct.
cbCallback to remove from the list.
Return values
0If operation is successfull.
ERRNOAn error code otherwise.
void pi_gpio_close ( struct pi_device *  device)

This function closes a GPIO device. If memory was allocated, it is freed.

Parameters
deviceA pointer to the device structure of the device to open.
Note
Closing a GPIO device will disable all GPIOs.
void pi_gpio_conf_init ( struct pi_gpio_conf conf)

The structure containing the configuration must be kept alive until the device is opened.

Parameters
confA pointer to the GPIO configuration.
int pi_gpio_open ( struct pi_device *  device)

This function must be called before the GPIO device can be used. It will do all the needed configuration to make it usable and initialize the handle used to refer to this opened device when calling other functions. This operation must be done once for each GPIO port, i.e. for every group of 32 GPIOs. The opened device can then be used to drive the 32 GPIOs.

Parameters
deviceA pointer to the device structure of the device to open.
Return values
0If the operation is successfull,
ERRNOAn error code otherwise.
Note
The device structure is allocated by the caller and must be kept alive until the device is closed.
int pi_gpio_pin_configure ( struct pi_device *  device,
pi_gpio_e  gpio,
pi_gpio_flags_e  flags 
)

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

Parameters
deviceA pointer to the device structure this GPIO belongs to.
gpioGPIO enumerate type or GPIO number within the port (from 0 to 31).
flagsA bitfield of flags specifying how to configure the GPIO.
Return values
0If the operation is successfull.
ERRNOAn error code otherwise.
void pi_gpio_pin_notif_clear ( struct pi_device *  device,
uint32_t  pin 
)

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.

Parameters
deviceA pointer to the device structure this GPIO belongs to.
pinThe GPIO number within the port (from 0 to 31).
Note
The pin parameter can be a GPIO enumerate type pi_gpio_e.
void pi_gpio_pin_notif_configure ( struct pi_device *  device,
uint32_t  pin,
pi_gpio_notif_e  flags 
)

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.

Parameters
deviceA pointer to the device structure this GPIO belongs to.
pinThe GPIO number within the port (from 0 to 31).
flagsThe flags to configure how the notification should be triggered.
Note
The pin parameter can be a GPIO enumerate type pi_gpio_e.
int pi_gpio_pin_notif_get ( struct pi_device *  device,
uint32_t  pin 
)

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.

Parameters
deviceA pointer to the device structure this GPIO belongs to.
pinThe GPIO number within the port (from 0 to 31).
Return values
0If a notification was received.
1Otherwise.
Note
The pin parameter can be a GPIO enumerate type pi_gpio_e.
int pi_gpio_pin_read ( struct pi_device *  device,
uint32_t  pin,
uint32_t *  value 
)

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.

Parameters
deviceA pointer to the device structure this GPIO belongs to.
pinThe GPIO number within the port (from 0 to 31).
valueA pointer to the variable where the GPIO value should be returned. The value will be either 0 or 1.
Return values
0If the operation is successfull.
ERRNOAn error code otherwise.
Note
The pin parameter can be a GPIO enumerate type pi_gpio_e.
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.
int pi_gpio_pin_task_add ( struct pi_device *  device,
uint32_t  pin,
pi_task_t *  task,
pi_gpio_notif_e  flags 
)

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.

Parameters
deviceA pointer to the device structure this GPIO belongs to.
pinThe GPIO number within the port (from 0 to 31).
taskEvent task executed when an IRQ is triggered.
flagsThe flags to configure how the notification should be triggered.
Return values
0If the operation is successfull.
ERRNOAn error code otherwise.
Note
The pin parameter can be a GPIO enumerate type pi_gpio_e.
int pi_gpio_pin_task_remove ( struct pi_device *  device,
uint32_t  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.

Parameters
deviceA pointer to the device structure this GPIO belongs to.
pinThe GPIO number within the port (from 0 to 31).
Return values
0If the operation is successfull.
ERRNOAn error code otherwise.
Note
The pin parameter can be a GPIO enumerate type pi_gpio_e.
int pi_gpio_pin_write ( struct pi_device *  device,
uint32_t  pin,
uint32_t  value 
)

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

Parameters
deviceA pointer to the device structure this GPIO belongs to.
pinThe GPIO number within the port (from 0 to 31).
valueThe value to be set. This can be either 0 or 1.
Return values
0If the operation is successfull.
ERRNOAn error code otherwise.
Note
The pin parameter can be a GPIO enumerate type pi_gpio_e.
This function is to be used on GPIO pins configured as PI_GPIO_OUTPUT.