Linux Standard GPIO operation

Source: Internet
Author: User

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&nbsp, 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.