previously
Based on Linux Gpio will be in the/sys/class/gpio directory will generate export, Unexport file, of course, there are gpiochipx files, GPIOCHIPX is the management of the pin, such as a certain chip may control a number of pins, in the corresponding The Ngpio in the directory is the number of controls.
When the Echo 4 >/sys/class/gpio/export is executed, the Gpio4 directory will be generated in the/sys/class/gpio directory, which will be like value, edge, direction and other related files.valueis the current value,Edgeis the PIN trigger,directionis the pin input, output mode. But how does echo produce this?Process Scanningfunction Gpiolib_dev_init is exported as Core_initcall (GPIO/GPIOLIB.C) in the initial initialization process This function calls Bus_register registration GPIO, corresponding to the build/sys/bus/gpio directory to call Alloc_chrdev_region gpiochip Settings Gpiochip_setup_devs This will process the total number of gpiochip, for each call Gpiochip_sysfs_register, file to the GPIOLIB-SYSFS.C call Device_create_wtih_groups to create gpiochip%d the corresponding parameter for this function is gpio_class that is, a class class the name of this class definition is Gpio, and defines theattr attrincluding Export-export _store, Unexport-unexport_store the former is the property name, the latter is the function is the echo action to trigger the Export_store function call Gpio_request prepare PIN Then call Gpiod_export to call device_create_with_groups in this function to create gpio%d, and other thingsNotesOf course, there are a lot of details are not clear, but an overview, later to supplement