I32 | vc_gpio_init_label (VCGpioCfg *gpio, char *label) |
Gets a GPIO chipset number by its label. More... | |
I32 | vc_gpio_deinit (VCGpioCfg *gpio, I32 unexportGpiosIff1) |
Unexports Gpios of a Chipset by Request. More... | |
I32 | vc_gpio_val_set (VCGpio gpioNr, I32 value, VCGpioCfg *gpio, I32 unexportIff1) |
Set Gpio Value of a VC's GPIO (non-performant). More... | |
I32 | vc_gpio_val_get (VCGpio gpioNr, I32 *value, VCGpioCfg *gpio, I32 unexportIff1) |
Get Gpio Value of a VC's GPIO (non-performant). More... | |
I32 | vc_gpio_dir_set (VCGpio gpioNr, VCGpioDir dir, VCGpioCfg *gpio, I32 unexportIff1) |
Set Gpio Direction for VC's GPIO (non-performant). More... | |
I32 | vc_gpio_edge_set (VCGpio gpioNr, VCGpioEdge edge, VCGpioCfg *gpio, I32 unexportIff1) |
Enable/Set Interrupt Moment for VC's GPIO (non-performant). More... | |
I32 | vc_gpio_edge_wait (I32 fd, VCGpioCfg *gpio, I32 timeoutMS) |
Wait for Interrupt at VC's GPIO (non-performant). More... | |
I32 | vc_gpio_open (I32 *fd, VCGpio gpioNr, char *file, I32 writeIff1, VCGpioCfg *gpio, I32 *prvUnexpIff1OrNULL) |
Opens Gpio File Descriptor of a VC's GPIO. More... | |
I32 | vc_gpio_close (I32 *fd, VCGpio gpioNr, VCGpioCfg *gpio, I32 unexportIff1) |
Closes Gpio File Descriptor of a VC's GPIO. More... | |
I32 | vc_gpio_export (VCGpio gpioNr, I32 unexportIff1, VCGpioCfg *gpio, I32 *prvUnexpIff1OrNULL) |
Exports a Gpio of a VC's GPIO. More... | |
I32 | vc_gpio_chippath_find (char *label, char *path, U32 pathMaxBytes) |
Gets the sys-Path of the GPIO Chip based on its Label. More... | |
#define | VCGPIO_GPIOS "/amba@0/axi-gpio0@41200000" |
label of gpio chipset to access I/O pins. | |
#define | VCGPIOS (32) |
Maximum Cross-Camera Hardware Gpio Count. | |
#define | vc_gpio_init(gpio) vc_gpio_init_label(gpio, VCGPIO_GPIOS) |
Initializes the GPIO Config for communication via vc's i/os. More... | |
These are convenience functions only, since they access the gpios over the sys file system of linux. A good reference will be at the following reference: https://www.kernel.org/doc/Documentation/gpio/sysfs.txt
Accessing and handling GPIOs is similar to commands done at the shell, so this will be described first.
To access a gpio pin it has to be exported first. To do that, one has to get the offset number of the chipset providing the gpio pins. Each available gpio providing chipset is listed at the folder '/sys/class/gpio' by a link to another folder, where it's link name starts with 'gpiochip' followed by its offset number, for example, '/sys/class/gpio/gpiochip224'. To identify the right gpio pin chipset, the folder behind the gpiochip contains a file called label
. Its content must fit the string behind the C definition VCGPIO_GPIOS. After identifying the correct gpiochip, one has to export the pin using the gpiochip's offset number plus the pin number to be accessed, starting with 0, and write it into the file named '/sys/class/gpio/export'. For example, if you identified the gpiochip224 as the correct chipset, and you want to access pin nr. 10, the following shell command will do the task (224+10=234):
A new link will be generated afterwards where you can access several properties and the value of the pin. The name of the link begins with 'gpio' followed by the number used at the export instruction, for example, '/sys/class/gpio/gpio234'. To configure the pin direction write 'in' or 'out' to its file 'direction', e.g.:
To set the pin's value write '1' or '0' to its file 'value', e.g.:
To retrieve the pin's value read its file 'value', and so on. You can unexport the pin by doing the same as at exporting, but to the file named 'unexport'.
Those tasks must be done the same way at C code. Here we provide some functions which do it. A pitfall by writing or reading the value without re-opening the file is not to jump to the beginning of the file, e.g. via:
#define vc_gpio_init | ( | gpio | ) | vc_gpio_init_label(gpio, VCGPIO_GPIOS) |
Initializes the GPIO Config for communication via vc's i/os.
I32 vc_gpio_init_label | ( | VCGpioCfg * | gpioNew, |
char * | label | ||
) |
This function searches for the correctly labelled chipset and stores its number at the gpio
struct.
This function unexports any gpios of a chipset by request.
unexportGpiosIff1 | will unexport all pins if and only if set to 1. |
This function sets the gpio value of VC's GPIO pin. The gpio should be configured as output by calling the routine vc_gpio_dir_set(). If you have to do this task fast, it is recommended to hold the corresponding gpio file opened and write to it by yourself.
unexportIff1 | will unexport the pin afterwards if and only if set to 1. |
This function gets the gpio value of VC's GPIO pin. The gpio should be configured as input by calling the routine vc_gpio_dir_set(). If you have to do this task fast, it is recommended to hold the corresponding gpio file opened and read from it by yourself.
unexportIff1 | will unexport the pin afterwards if and only if set to 1. |
This function sets the gpio direction for VC's GPIO. If you have to change this state fast, it is recommended to hold the corresponding gpio file opened and write to it by yourself.
unexportIff1 | will unexport the pin afterwards if and only if set to 1. |
This function en- or disables and sets the interrupt moment for VC's GPIO. If you have to change this state fast, it is recommended to hold the corresponding gpio file opened and write to it by yourself.
unexportIff1 | will unexport the pin afterwards if and only if set to 1. |
This function waits for an interrupt at the gpio opened with fd
.
I32 vc_gpio_open | ( | I32 * | fd, |
VCGpio | gpioNr, | ||
char * | file, | ||
I32 | writeIff1, | ||
VCGpioCfg * | gpio, | ||
I32 * | prvUnexpIff1OrNULL | ||
) |
This function opens the gpio file descriptor of a VC's GPIO pin. Functions, like vc_gpio_val_set(), use this routine, like vc_gpio_open(), then write(), then vc_gpio_close().
This function closes the gpio file descriptor of a VC's GPIO pin. Functions, like vc_gpio_val_set(), use this routine, like vc_gpio_open(), then write(), then vc_gpio_close().
unexportIff1 | will unexport the pin afterwards if and only if set to 1. |
This function exports the pin of a VC's GPIO. Before one can access a pin, it must be exported.
prvUnexpIff1OrNULL | provides the information to the gpio export status before exporting. |
unexportIff1 | will unexport instead of export the pin if and only if set to 1. |