[ 驱动移植 ] [ 6 ] GPIO

头文件

#include <linux/gpio.h>

GPIO APIs in Linux Kernel

Validate the GPIO

bool gpio_is_valid(int gpio_number);

功能:判断 gpio 引脚是否合法。

Request the GPIO

int gpio_request(unsigned gpio, const char* label);

功能:请求指定的 gpio 引脚。

image.png

其他请求函数:

int gpio_request_one(unsigned gpio, unsigned long flags, const char *label); –  Request one GPIO.

int gpio_request_one(unsigned gpio, unsigned long flags, const char *label); –  Request one GPIO.

Export the GPIO

int gpio_export(unsigned int gpio, bool direction_may_change);


Unexport the GPIO

int gpio_unexport(unsigned int gpio);


Set the direction of the GPIO

int gpio_direction_input(unsigned gpio)
int gpio_direction_output(unsiged gpio, int value)


Change the GPIO value

gpio_set_value(unsigned int gpio, int value);

value: value to set to the GPIO. 0 - Low, 1 - High.


Read the GPIO value

int gpio_get_value(unsigned gpio);


Release the GPIO

void gpio_free(unsigned int gpio);
void gpio_free_array(struct gpio *array, size_t num); – Release multiple GPIOs.


GPIO Raspberry PI Tutorial




参考

1. https://embetronicx.com/tutorials/linux/device-drivers/gpio-driver-basic-using-raspberry-pi/