linux gpio learning

antecedent

Based on linux gpio, files will be generated in the /sys/class/gpiodirectory export, unexport, and of course there are gpiochipxfiles , which gpiochipxare the management of pins. For example, a certain chip may control a certain number of pins, and the number of pins ngpiois .
When executing echo 4 > /sys/class/gpio/export, a directory will /sys/class/gpiobe generated under the gpio4directory , in which there will be value, edge, directionrelated files such as , value is the current value, edge is the pin trigger mode, and direction is the pin input and output mode. But how did this come about echoafter that.

Process scan

  • In the initial initialization process there gpiolib_dev_initare exported as core_initcall(gpio/gpiolib.c)
  • This function calls bus_registerregister gpio , corresponding to the generated /sys/bus/gpiodirectory
  • call againalloc_chrdev_region
  • Then set the gpiochipgpiochip_setup_devs
  • This processes the total number of gpiochips, and for each call gpiochip_sysfs_register, the file goes gpiolib-sysfs.cto
  • call device_create_wtih_groupsto creategpiochip%d
  • The parameter corresponding to this function gpio_classis a classclass
  • The name of this classdefinition is, and attrgpio is also defined
  • attr includes export - export _store,unexport - unexport_store
  • The former is the property name, the latter is the function
  • That is, the echoaction is a trigger export_storefunction
  • This function call gpio_requestprepares pin
  • call again gpiod_exportin this function device_create_with_groupsto create gpio%d, among other things

Remark

  • Of course, there are still many details that are still unclear, just an overview, which will be added later

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325387168&siteId=291194637