本帖最后由 wateras1 于 2018-4-19 10:54 编辑
MTK7688之openwrt下的GPIO操作
在上一篇我使用了reg工具来操作gpio(
https://bbs.eeworld.com.cn/thread-641719-1-1.html),其实也可以通过openwrt固件自带的GPIO文件来操作。
widora默认支持9个GPIO,分别是GPIO0(实为GPIO11),14,15,16,17,39,40,41,42。如需再多的GPIO需要改动引脚复用关系。
控制台操作IO终端进入/sys/class/gpio/目录,导出想要控制的GPIO,比如导出GPIO11,则输入以下命令:
root@Widora:/# cd /sys/class/gpio
root@Widora:/sys/class/gpio# ls
export gpiochip0 gpiochip32 gpiochip64 unexport
root@Widora:/sys/class/gpio# echo 11 > export
root@Widora:/sys/class/gpio# ls
export gpio11 gpiochip0 gpiochip32 gpiochip64 unexport gpiochipX 表示的就是一个gpio_chip,用来管理和控制一组gpio端口的控制器 目录保存系统中GPIO寄存器的信息,包括每个寄存器控制引脚的起始编号base,寄存器名称或标志label,引脚总数ngpio
giopchi0表示管理gpio0~gpio31
gpiochip32表示管理gpio32~gpio63
gpiochip64表示管理gpio64
root@Widora:/sys/class/gpio# cd /
root@Widora:/# cd /sys/devices
root@Widora:/sys/devices# ls
10000000.palmbus 10130000.sdhci gpio-keys-polled system
10100000.ethernet 101c0000.ehci pinctrl virtual
10110000.esw 101c1000.ohci platform
10120000.usbphy cpuintc@0 rstctrl
root@Widora:/sys/devices# cd 10000000.palmbus/
root@Widora:/sys/devices/10000000.palmbus# ls
10000000.sysc 10000600.gpio 10000d00.uart1 modalias
10000120.watchdog 10000900.i2c 10000e00.uart2 subsystem
10000200.intc 10000b00.spi 10005000.pwm uevent
10000300.memc 10000c00.uartlite driver_override
root@Widora:/sys/devices/10000000.palmbus# cd 10000600.gpio/
root@Widora:/sys/devices/10000000.palmbus/10000600.gpio# cd gpio
root@Widora:/sys/devices/10000000.palmbus/10000600.gpio/gpio# ls
gpio11 gpiochip0 gpiochip32 gpiochip64
root@Widora:/sys/devices/10000000.palmbus/10000600.gpio/gpio# cd gpio11
root@Widora:/sys/devices/10000000.palmbus/10000600.gpio/gpio/gpio11# ls
active_low device direction edge subsystem uevent value
root@Widora:/sys/devices/10000000.palmbus/10000600.gpio/gpio/gpio11# echo out >
direction
root@Widora:/sys/devices/10000000.palmbus/10000600.gpio/gpio/gpio11# echo 1 >val
ue
root@Widora:/sys/devices/10000000.palmbus/10000600.gpio/gpio/gpio11# echo 0 >val
ue
就可以操作GPIO输出高低电平。
我们也可以将GPIO11配置入输入模式
root@Widora:/sys/devices/10000000.palmbus/10000600.gpio/gpio/gpio11# echo in >di
rection
root@Widora:/sys/devices/10000000.palmbus/10000600.gpio/gpio/gpio11# cat value
1
此内容由EEWORLD论坛网友wateras1原创,如需转载或用于商业用途需征得作者同意并注明出处