TS-4100 DIO: Difference between revisions
(Consistency of naming.) |
(Clean up.) |
||
Line 3: | Line 3: | ||
To interact with a pin, first export it to userspace: | To interact with a pin, first export it to userspace: | ||
<source lang=bash> | <source lang=bash> | ||
echo " | echo "71" > /sys/class/gpio/export | ||
# GPIO 71 is CPU LCD_D02 | |||
</source> | </source> | ||
If | If the command returns with "permission denied," that means that specific GPIO is claimed by another device. The command 'cat /sys/kernel/debug/gpio' can be used to get a list of all of the system GPIO and what has claimed them. | ||
direction - "in", "out" (out = low), "low", "high" | |||
If the command was successful, the directory "/sys/class/gpio/gpio71/" will have been created. The relevant files in this directory are: | |||
direction - write "in", "out" (out = low), "low", "high" | |||
value - write "1" or "0", or read "1" or "0" if direction is in | value - write "1" or "0", or read "1" or "0" if direction is in | ||
edge - write | edge - write "rising", "falling", or "none" | ||
With direction | With "direction", the GPIO can be set to an output and direction set at the same time using the "high" and "low" commands. Using "out" will act the same as "low". | ||
<source lang=bash> | <source lang=bash> | ||
# Set as a low output | # Set as a low output | ||
echo "out" > /sys/class/gpio/ | echo "out" > /sys/class/gpio/gpio71/direction | ||
# Set GPIO | # Set GPIO 71 high | ||
echo "1" > /sys/class/gpio/ | echo "1" > /sys/class/gpio/gpio71/value | ||
# Set GPIO | # Set GPIO 71 low | ||
echo "0" > /sys/class/gpio/ | echo "0" > /sys/class/gpio/gpio71/value | ||
# Read the value of GPIO | # Read the value of GPIO 71 | ||
echo "in" > /sys/class/gpio/ | echo "in" > /sys/class/gpio/gpio71/direction | ||
cat /sys/class/gpio/ | cat /sys/class/gpio/gpio71/value | ||
# | # Set as a high output | ||
echo "high" > /sys/class/gpio/ | echo "high" > /sys/class/gpio/gpio71/direction | ||
</source> | </source> | ||
As an output, the | As an output, the "value" file can be written with "0" for low output (GND), or "1" for high output (3.3V). The GPIO pins support an absolute maximum of -0.5 to 3.6 V input; any voltage outside of this range can damage the pin or the device. It is also possible to use any processor GPIO as an interrupt by writing the "edge" file with a value, and then using select() or poll() on the "value" file for changes. The [https://www.kernel.org/doc/Documentation/gpio/sysfs.txt kernel documentation] provides information on this and other use cases of the sysfs GPIO interface. |
Revision as of 17:22, 13 June 2019
The i.MX6UL and FPGA GPIO are exposed using the kernel's sysfs GPIO interface. See the kernel's documentation here for more detail. This interface provides a set of files and directories for interacting with GPIO which can be used from any language that can write files.
To interact with a pin, first export it to userspace:
echo "71" > /sys/class/gpio/export
# GPIO 71 is CPU LCD_D02
If the command returns with "permission denied," that means that specific GPIO is claimed by another device. The command 'cat /sys/kernel/debug/gpio' can be used to get a list of all of the system GPIO and what has claimed them.
If the command was successful, the directory "/sys/class/gpio/gpio71/" will have been created. The relevant files in this directory are:
direction - write "in", "out" (out = low), "low", "high" value - write "1" or "0", or read "1" or "0" if direction is in edge - write "rising", "falling", or "none"
With "direction", the GPIO can be set to an output and direction set at the same time using the "high" and "low" commands. Using "out" will act the same as "low".
# Set as a low output
echo "out" > /sys/class/gpio/gpio71/direction
# Set GPIO 71 high
echo "1" > /sys/class/gpio/gpio71/value
# Set GPIO 71 low
echo "0" > /sys/class/gpio/gpio71/value
# Read the value of GPIO 71
echo "in" > /sys/class/gpio/gpio71/direction
cat /sys/class/gpio/gpio71/value
# Set as a high output
echo "high" > /sys/class/gpio/gpio71/direction
As an output, the "value" file can be written with "0" for low output (GND), or "1" for high output (3.3V). The GPIO pins support an absolute maximum of -0.5 to 3.6 V input; any voltage outside of this range can damage the pin or the device. It is also possible to use any processor GPIO as an interrupt by writing the "edge" file with a value, and then using select() or poll() on the "value" file for changes. The kernel documentation provides information on this and other use cases of the sysfs GPIO interface.