October 2017
Intermediate to advanced
586 pages
14h 8m
English
You can allocate and take ownership of a GPIO using the gpio_request() function:
static int gpio_request(unsigned gpio, const char *label)
gpio represents the GPIO number we are interested in, and label is the label used by the kernel for the GPIO in sysfs, as we can see in /sys/kernel/debug/gpio. You have to check the value returned, where 0 mean success and a negative error code is produced on an error. Once you've done this with the GPIO, it should be set free with the gpio_free() function:
void gpio_free(unsigned int gpio)
If in doubt, you can use the gpio_is_valid() function to check whether this GPIO number is valid on the system prior to allocating it:
static bool gpio_is_valid(int number)
Once ...