Login to device
To get state of GPIO run the following command
root@imx8mq-trux-q01:~# cat /sys/kernel/debug/gpio
Output :
gpiochip0: GPIOs 0-31, parent: platform/30200000.gpio, 30200000.gpio: gpio-5 ( |hdmi_on ) out lo gpio-8 ( |eth_phy ) out hi gpio-10 ( |int ) in hi IRQ gpio-12 ( |spi_imx ) out hi gpiochip1: GPIOs 32-63, parent: platform/30210000.gpio, 30210000.gpio: gpio-44 ( |cd ) in lo IRQ ACTIVE LOW gpio-51 ( |regulator-vsd-3v3 ) out hi gpio-52 ( |spi_imx ) out hi gpiochip2: GPIOs 64-95, parent: platform/30220000.gpio, 30220000.gpio: gpiochip3: GPIOs 96-127, parent: platform/30230000.gpio, 30230000.gpio: gpio-102 ( |Back ) in lo IRQ ACTIVE LOW gpio-109 ( |Home ) in lo IRQ ACTIVE LOW gpio-111 ( |Down ) in lo IRQ ACTIVE LOW gpio-113 ( |eMMC ) out lo gpio-114 ( |Up ) in lo IRQ ACTIVE LOW gpiochip4: GPIOs 128-159, parent: platform/30240000.gpio, 30240000.gpio: gpio-137 ( |spi_imx ) in lo gpio-142 ( |scl ) out hi gpio-143 ( |sda ) in hi gpio-144 ( |scl ) out hi gpio-145 ( |sda ) in hi gpio-146 ( |scl ) out hi gpio-147 ( |sda ) in hi gpio-148 ( |scl ) out hi gpio-149 ( |sda ) in hi
Each GPIO is defined as “in” or “out” and the state is shown as “lo” or “hi”. This can be changed via ‘sys/class/gpio’
1. Export GPIO
root@imx8mq-trux-q01:~# echo <GPIO_NUMBER> > /sys/class/gpio/export
2. Configure GPIO
root@imx8mq-trux-q01:~# echo <in or out> > /sys/class/gpio<gpionumber>/direction
3. Changing value of GPIO
root@imx8mq-trux-q01:~# echo <1 or 0> > /sys/class/gpio<gpionumber>/value
4. Read Gpio
- direction
root@imx8mq-trux-q01:~# cat /sys/class/gpio<gpionumber>/direction
- value
root@imx8mq-trux-q01:~# cat /sys/class/gpio<gpionumber>/value
5. Unexport gpio after use
root@imx8mq-trux-q01:~# echo <GPIO_NUMBER> > /sys/class/gpio/unexport