TA的每日心情 | 衰 2018-11-30 11:03 |
---|
签到天数: 53 天 连续签到: 1 天 [LV.5]常住居民I
|
视壮嵌入式板卡rk3399 kernel通用GPIO驱动控制
内核已经自带了通用GPIO驱动,可以直接在用户空间操作.
路径: /sys/class/gpio
rk3399_mid:/ $ ls /sys/class/gpio
export gpiochip1032 gpiochip1096 unexport
gpiochip1000 gpiochip1064 gpiochip1128
操作GPIO0_A6作为高电平输出有效, 操作步骤:
1. 计算对应的gpio number的值
通过/sys/kernel/debug/gpio查询信息:
rk3399_mid:/ $ cat /sys/kernel/debug/gpio
GPIOs 1000-1031, platform/pinctrl, gpio0:
gpio-1002 ( |3G_power ) out lo
gpio-1004 ( |bt_default_wake_host) in lo
gpio-1005 ( |power ) in hi
gpio-1009 ( |bt_default_reset ) out lo
gpio-1010 ( |reset ) out hi
gpio-1011 ( |pwd_en_3G ) out hi
GPIOs 1032-1063, platform/pinctrl, gpio1:
gpio-1033 ( |led_Test ) in lo
gpio-1034 ( |int-n ) in hi
gpio-1035 ( |vbus-5v ) out hi
gpio-1045 ( |enable ) out lo
gpio-1046 ( |vsel ) out hi
gpio-1049 ( |vsel ) out lo
GPIOs 1064-1095, platform/pinctrl, gpio2:
gpio-1076 ( |camsys_gpio ) out lo
gpio-1083 ( |bt_default_rts ) in hi
gpio-1090 ( |bt_default_wake ) in lo
gpio-1091 ( |camsys_gpio ) out lo
可以看到gpio0是以nubmer为1000开始, 那么GPIO0_A6就是 1000+ 6 = 1006
2. 设置该gpio为输出
rk3399_mid:/ $ cd /sys/class/gpio/
rk3399_mid:/sys/class/gpio $ echo 1006 > export
/system/bin/sh: can't create export: Permission denied
1|rk3399_mid:/sys/class/gpio $ su
rk3399_mid:/sys/class/gpio # echo 1006 > export
rk3399_mid:/sys/class/gpio # ls
export gpiochip1000 gpiochip1064 gpiochip1128
gpio1006 gpiochip1032 gpiochip1096 unexport
rk3399_mid:/sys/class/gpio # cd gpio1006/
rk3399_mid:/sys/class/gpio/gpio1006 # echo out > direction
3. 设置该gpio输出高电平
rk3399_mid:/sys/class/gpio/gpio1006 # echo 1 > value
rk3399_mid:/sys/class/gpio/gpio1006 # cat value
1
|
|