libgpio-versal
GPIO support library for the VE2302 AI Edge board.
Runs on:
QNX OS
Description:
The libgpio-versal library is intended to facilitate the configuration and usage of GPIO pins on the Xilinx Versal SoC in custom applications. This library can be used with both the PMC and LPD GPIO controllers in the Versal SoC.
Including the library in the application
This library can be included in your application by adding LIBS += gpio-versal to your common.mk file, as well as including `hw/versal_gpio.h` to your application's source file(s). The library functions can then be called directly by your application code.
Library initialization and cleanup
The versal_gpio_init() function must be the first function called in the library. Calls to other library functions will be unpredictable unless the initialization has been completed first. The versal_gpio_fini() function should be called when your application is finished using the library.
GPIO configuration functions
versal_gpio_set_direction()
versal_gpio_get_direction()
versal_gpio_set_output_enable()
versal_gpio_get_output_enable()
versal_gpio_get_input()
versal_gpio_set_output()
versal_gpio_get_irq_type()
versal_gpio_set_irq_type()
Examples:
- The MIO pin must be muxed to the GPIO controller by the FSBL for this code to work as intended.
- This snippet omits error-code checking and handling for the purposes of brevity. Proper error-code checking and handling should be added as necessary in your application code.
/* Include the libgpio-versal header. */
#include <hw/versal_gpio.h>
int main(void)
{
gpio_dev_t dev;
gpio_pin_t pin;
/* Initialize the dev structure. */
versal_gpio_init(&dev);
/* Configure the GPIO pin structure to describe LPD MIO pin 12. */
pin.controller = VERSAL_GPIO_CONTROLLER_LPD;
pin.mio_type = VERSAL_MIO_TYPE_MIO;
pin.pin_number = 12;
/* Set the pin direction to output. */
versal_gpio_set_direction(&dev, pin, VERSAL_GPIO_DIR_OUT);
/* Configure the pin to output high. */
versal_gpio_set_output(&dev, pin, VERSAL_GPIO_LEVEL_HIGH);
/* Enable the pin output. */
versal_gpio_set_output_enable(&dev, pin, VERSAL_GPIO_OUT_EN);
/* Call fini() to cleanup. */
versal_gpio_fini(&dev);
}
