Linux provides an API for GPIO operations, with specific initialization and registration functions implemented in DRIVER/GPIO/LIB_GPIO.C. #include int gpio_request (unsigned gpio, const char *label), acquire and occupy the use of Gpio port, specify the specific por by the parameter Gpio T. A non-empty label pointer helps to diagnose. Mainly tells the kernel that this address is occupied. When other places call the same address, the Gpio_request will report an error and the address has been applied. The/PROC/MEM has an address Occupancy table description. The advantage of applying first in the visit is to avoid the competition of resources. void Gpio_free (unsigned gpio); Releases the use of the Gpio port, specifying the specific port by the parameter Gpio. int gpio_direction_input (unsigned gpio); set Gpio port (specified by the parameter gpio) as input. int gpio_direction_output (unsigned gpio, int value), sets the Gpio port (specified by the parameter gpio) to output, and specifies the output level value (value). int gpio_get_value (unsigned gpio), obtains the level value on the Gpio port and returns. void Gpio_set_value (unsigned gpio, int value), setting the level on the Gpio port. int Gpio_to_irq (unsigned gpio), by obtaining the IRQ number corresponding to the Gpio port. The main distinction between int gpio_cansleep (unsigned gpio) is the GPIO controller mounted on the external bus, or the internal GPIO controller. Because the GPIO controller on the external bus can hibernate, this is used to differentiate whether it is an extended gpio, and the gpio,0 that returns 1 is the internal gpio. int gpio_get_value_cansleep (unsigned gpio); void Gpio_set_value_cansleep (unsigned gpio, int value); These are the operations of GPIO that can hibernate extensions static inline int gpio_is_valid (int number) Determine if the Gpio is valid, return 0int gpio_export (unsigned gpio, booldirection_may_change) effectively; void Gpio_unexport ();//Create and cancel the corresponding gpio number int gpio_export_link (struct device *dev, const char *name below/sys/class/gpio/, unsigned gpio)//Create to export Gpio Sysfs link , first parameter is created under which Dev, the second is the parameter name, and the third one is the GPIO number
Linux standard GPIO operations