GPIO (General Peripheral Input/Output)
More...
|
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...
|
|
The GPIO driver provides support for controlling GPIOs. The available GPIOs are listed in pmsis/chips folder.
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.
|
Add an application callback to a GPIO device. Multiple callbacks can be attached to a device, and to a GPIO pin.
- Parameters
-
device | Pointer to device struct. |
cb | Callback to add to the list. |
- Return values
-
0 | If operation is successfull. |
ERRNO | An 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
-
cb | Pointer to callback to initialize. |
pin_mask | Mask of GPIO pins. |
handler | Callback function. |
arg | Callback function arg. |
Remove an application callback from a GPIO device.
- Parameters
-
device | Pointer to device struct. |
cb | Callback to remove from the list. |
- Return values
-
0 | If operation is successfull. |
ERRNO | An 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
-
device | A pointer to the device structure of the device to open. |
- Note
- Closing a GPIO device will disable all GPIOs.
The structure containing the configuration must be kept alive until the device is opened.
- Parameters
-
conf | A 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
-
device | A pointer to the device structure of the device to open. |
- Return values
-
0 | If the operation is successfull, |
ERRNO | An error code otherwise. |
- Note
- The device structure is allocated by the caller and must be kept alive until the device is closed.
This function can be used to configure several aspects of a GPIO, like the direction.
- Parameters
-
device | A pointer to the device structure this GPIO belongs to. |
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. |
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
-
device | A pointer to the device structure this GPIO belongs to. |
pin | The 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
-
device | A pointer to the device structure this GPIO belongs to. |
pin | The GPIO number within the port (from 0 to 31). |
flags | The 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
-
device | A pointer to the device structure this GPIO belongs to. |
pin | The GPIO number within the port (from 0 to 31). |
- Return values
-
0 | If a notification was received. |
1 | Otherwise. |
- 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
-
device | A pointer to the device structure this GPIO belongs to. |
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. |
- 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
-
device | A pointer to the device structure this GPIO belongs to. |
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. |
- 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
-
device | A pointer to the device structure this GPIO belongs to. |
pin | The GPIO number within the port (from 0 to 31). |
- Return values
-
0 | If the operation is successfull. |
ERRNO | An 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
-
device | A pointer to the device structure this GPIO belongs to. |
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. |
- 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.