TS-4100 DIO: Difference between revisions

From embeddedTS Manuals
(Consistency of naming.)
(Formatting changes)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
The i.MX6UL and FPGA GPIO are exposed using the kernel's sysfs GPIO interface. See the kernel's documentation [https://www.kernel.org/doc/Documentation/gpio/sysfs.txt 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.
The i.MX6UL CPU and FPGA GPIO are exposed using a kernel character device. This interface provides a set of files and directories for interacting with GPIO which can be used from any language that interact with special files in linux using ioctl() or similar. For our platforms, we pre-install the "libgpiod" library and binaries. Documentation on these tools can be found [https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/README here]. This section only covers using these userspace tools and does not provide guidance on using the libgpiod library in end applications. Please see the libgpiod documentation for this purpose.


To interact with a pin, first export it to userspace:
A user with suitable permissions to read and write <source inline>/dev/gpiochip*</source> files can immediately interact with GPIO pins. For example, to read the push switch on the TS-8551-4100 which is connected to [[#FPGA_GPIO_Table|FPGA DIO_9]]:
<source lang=bash>
<source lang=bash>
echo "48" > /sys/class/gpio/export
gpioget 5 46
</source>
</source>
Multiple pins in the same chip can be read simultaneously by passing multiple pin numbers separated by spaces.


If you receive a permission denied on a pin that means it is claimed by another kernel driver. In this case, you can "cat /sys/kernel/debug/gpio" to see what driver has claimed it.  If it succeeds you will have a /sys/class/gpio/gpio48/ directory.  The relevant files in this directory are:
To write to a pin, the <source inline>gpioset</source> command is used. For example, to set [[#CPU_GPIO_Table|LCD_D02]]:
  direction - "in", "out" (out = low), "low", "high"
  value - write "1" or "0", or read "1" or "0" if direction is in
  edge - write with "rising", "falling", or "none"
 
With direction you can set it as an output and set the direction at the same time with high/low.  If you just specify out this is the same as low.
 
<source lang=bash>
<source lang=bash>
# Set as a low output
gpioset 2 7=0
echo "out" > /sys/class/gpio/gpio48/direction
</source>
# Set GPIO 48 high
Multiple pins in the same chip can be set simultaneously by passing multiple <source inline><pin>=<value></source> pairs separated by spaces.
echo "1" > /sys/class/gpio/gpio48/value
# Set GPIO 48 low
echo "0" > /sys/class/gpio/gpio48/value


# Read the value of GPIO 48
If a call to <source inline>gpioset</source> or <source inline>gpioget</source> fails with the message <source inline>Device or resource busy</source> that means that specific GPIO is claimed by another device. The command <source inline>cat /sys/kernel/debug/gpio</source> can be used to get a list of all of the system GPIO and what has claimed them.
echo "in" > /sys/class/gpio/gpio48/direction
cat /sys/class/gpio/gpio48/value
 
# You can set it as a high output by setting the direction:
echo "high" > /sys/class/gpio/gpio48/direction
</source>


As an output, the in can be written to 0 for low (GND), or 1 for high (3.3V). The GPIO pins directly off of the i.MX6ul processor support an absolute maximum of -0.5 to 3.6V.  It is also possible to use any processor GPIO as an interrupt by writing the edge value, and then using select() or poll() on the value file for changes.
The <source inline>gpiomon</source> tool can be used to monitor pins for changes.

Latest revision as of 16:09, 19 October 2021

The i.MX6UL CPU and FPGA GPIO are exposed using a kernel character device. This interface provides a set of files and directories for interacting with GPIO which can be used from any language that interact with special files in linux using ioctl() or similar. For our platforms, we pre-install the "libgpiod" library and binaries. Documentation on these tools can be found here. This section only covers using these userspace tools and does not provide guidance on using the libgpiod library in end applications. Please see the libgpiod documentation for this purpose.

A user with suitable permissions to read and write /dev/gpiochip* files can immediately interact with GPIO pins. For example, to read the push switch on the TS-8551-4100 which is connected to FPGA DIO_9:

gpioget 5 46

Multiple pins in the same chip can be read simultaneously by passing multiple pin numbers separated by spaces.

To write to a pin, the gpioset command is used. For example, to set LCD_D02:

gpioset 2 7=0

Multiple pins in the same chip can be set simultaneously by passing multiple <pin>=<value> pairs separated by spaces.

If a call to gpioset or gpioget fails with the message Device or resource busy 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.

The gpiomon tool can be used to monitor pins for changes.