Boards of fast -iMX6 - -sys controlled device tree kernel GPIO

This document explains fast as -iMX6 development board, controlled by GPIO mode sys file.
Through sys GPIO control, you need to do a few steps:
1 Turn on kernel "GPIO_SYSFS" drive configuration;
2 ensure IO is configured as GPIO, and no driver calls;
3 GPIO number calculated by command or script action GPIO.
1 GPIO_SYSFS the configuration
as shown, can be seen that the kernel GPIO_SYSFS default configuration, the driver all original basic BSP
will include, in general, is the default configuration.

2 is configured to ensure IO GPIO, and no driver calls
here to the GPIO LED as an example, the LED driver is pulled to ensure that no driver calls.
--- the Drivers Device>
Character Devices --->
the Enable config --- LEDS removed, and programmed to rebuild the kernel development board.
Configuration as shown menuconfig.

Development board programmed to ensure that the device node is not led, the default kernel is led device node, as shown
in FIG.

3 计算 GPIO 编号并测试
LED 的网络标号为:KEY_ROW6
LED 对应 GPIO 的 PIN 脚名称为:GPIO_2
GPIO_2 对应的宏定义为:#define MX6QDL_PAD_GPIO_2__GPIO1_IO02
那么 GPIO_2 对应的 GPIO 的 bank[n]为 GPIO1_IO02,也就是 bank 1 的 02 号 GPIO。
GPIO 的编号计算方法为:nr=(P -1)* 32 + N;
nr 为编号,P 为 bank 号,N 为具体 bank 中的编号。
那么 P=1,N=2,通过计算得出 nr=2。
测试命令为:

echo nr > /sys/class/gpio/export
echo out > /sys/class/gpio/gpionr/direction
echo 1 > /sys/class/gpio/gpionr/value ---> 写高电平,小灯亮
echo 0 > /sys/class/gpio/gpionr/value ---> 写低电平,小灯灭
以上 nr 替换成 GPIO 的编号,则命令为:
echo 2 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio2/direction
echo 1 > /sys/class/gpio/gpio2/value --->写高电平,小灯亮
echo 0 > /sys/class/gpio/gpio2/value ---> 写低电平,小灯灭
如下图所示,执行三条命令之后小灯亮。

接着执行 echo 0 > /sys/class/gpio/gpio2/value 小灯灭。
至此,sys 测试 gpio 完成。
另外需要注意的是,本文档没有介绍 LED 对应的管脚是如何配置的,因为 LED 驱动能够
运行,那么肯定在设备树文件中配置了。
如果想要掌握如何配置管脚,可以参考“iTOP-iMX6-设备树内核-IO 配置分析文档
_V1.X”和“iTOP-iMX6-设备树内核-IO 扩展例程_V1.X”文档。

 

Guess you like

Origin www.cnblogs.com/mingyue77/p/11268091.html