The user space gpio calls

From WRTnode Wiki Site
Jump to: navigation, search
This page contains changes which are not marked for translation.

Other languages:
English 100% • ‎中文(中国大陆)‎ 100%

User space access gpio, namely through sysfs access gpio interface

control the gpio directory in: / sys/class/gpio

  • /sys/class/gpio/export

export is used to notify system need to export control GPIO pin number

  • /sys/class/gpio/unexport

unexport is used to cancel the export notification to system

  • /sys/class/gpio/gpiochipX

gpiochipX said is a gpio_chip, used to manage and control a group of gpio port controller Directory information stored system GPIO registers,

Base: starting each register control pin number,

label: register a name or logo

ngpio: the total number of pins

  • /sys/class/gpioN

gpioN: specific gpio pin

direction: the direction of the gpio port, read the result is in or out.  

value: level of gpio pin, 0 (low level) 1 (high level), if the gpio is configured as output, the value is writable, remember any nonzero value will output a high level

edge: the interrupt is triggered




Export the gpio pins

1 Calculate the pin number

pin number = base of control pin register + offset of control pin register

2 /sys/class/gpio/export write the number

for example gpio0 ,after the success of the command to generate/sys/class/gpio/gpio0 directory, if there are no corresponding directory, illustrate the pin cannot be derived

echo 0 > /sys/class/gpio/export

3 The direction file in /sys/class/gpio/gpio0

direction: define input and output

defined as the output:

echo out > direction

defined as the input:

echo in > direction

4 The value file in /sys/class/gpio/gpio0

Value: level of gpio pin, 0 (low level) 1 (high level), if the gpio is configured as output, the value is writable, remember any nonzero value will output a high level

echo 1 > value

export gpio0 pin:

Usergpio.png


Usergpio2.png

But when we execute unexport will prompt error

echo 0 > /sys/class/gpio/unexport
echo 0 > /sys/class/gpio/export
ash: write error: Invalid argument

The solution:
The ticket for gpio unexport
The patch for gpio-ralink.c