Android系统 GPIO状态查询

GPIO口状态查询
定制的上位机(Android系统) 外接的传感器,需要使用距离感应器功能,定位问题原因,采用分段调试:

先查看上位机板子是否可以正常返回距离感应的状态
检查传输线
检查感应头是否正常
我这里是第一步的问题,线和感应头都正常,所以先说一下如何来返回正常的感应状态
距离传感器在检测到距离变化或者物体靠近时候会有高低电压的变化,并将信息通过数据线传输到上位机,adb shell 命令来进入到上位机,查看gpio口的状态变化

C:\Users\Administrator>adb shell
rk3399_mid:/ $ su
rk3399_mid:/ # cd sys/class/gpio
rk3399_mid:/sys/class/gpio # ls -al
total 0
drwxr-xr-x  2 root root    0 2013-01-18 16:54 .
drwxr-xr-x 73 root root    0 2013-01-18 16:54 ..
--w-------  1 root root 4096 2013-01-18 17:27 export
lrwxrwxrwx  1 root root    0 2013-01-18 17:28 gpio1058 -> ../../devices/platform/pinctrl/gpio/gpio1058
lrwxrwxrwx  1 root root    0 2013-01-18 17:14 gpio1069 -> ../../devices/platform/pinctrl/gpio/gpio1069
lrwxrwxrwx  1 root root    0 2013-01-18 16:55 gpio1154 -> ../../devices/platform/pinctrl/gpio/gpio1154
lrwxrwxrwx  1 root root    0 2013-01-18 17:14 gpiochip1000 -> ../../devices/platform/pinctrl/gpio/gpiochip1000
lrwxrwxrwx  1 root root    0 2013-01-18 17:14 gpiochip1032 -> ../../devices/platform/pinctrl/gpio/gpiochip1032
lrwxrwxrwx  1 root root    0 2013-01-18 17:14 gpiochip1064 -> ../../devices/platform/pinctrl/gpio/gpiochip1064
lrwxrwxrwx  1 root root    0 2013-01-18 17:14 gpiochip1096 -> ../../devices/platform/pinctrl/gpio/gpiochip1096
lrwxrwxrwx  1 root root    0 2013-01-18 17:14 gpiochip1128 -> ../../devices/platform/pinctrl/gpio/gpiochip1128
--w-------  1 root root 4096 2013-01-18 17:14 unexport

以上命令 查看所有gpio口的信息
格式化显示信息:

rk3399_mid:/sys/class/gpio # cat /d/gpio 
rk3399_mid:/sys/class/gpio # cat /d/gpio
GPIOs 1000-1031, platform/pinctrl, gpio0:
 gpio-1001 (                    |WK_iqr_int          ) in  hi
 gpio-1004 (                    |bt_default_wake_host) in  lo
 gpio-1005 (                    |power               ) in  hi
 gpio-1008 (                    |enable              ) out hi
 gpio-1009 (                    |bt_default_reset    ) out lo
 gpio-1010 (                    |reset               ) out hi
 gpio-1011 (                    |?                   ) out hi
 gpio-1012 (                    |?                   ) out lo

GPIOs 1032-1063, platform/pinctrl, gpio1:
 gpio-1034 (                    |reset               ) out hi
 gpio-1042 (                    |WK_cs_int           ) out hi
 gpio-1045 (                    |enable              ) out lo
 gpio-1046 (                    |vsel                ) out lo
 gpio-1049 (                    |vsel                ) out lo
 gpio-1058 (                    |sysfs               ) in  lo

GPIOs 1064-1095, platform/pinctrl, gpio2:
 *gpio-1068 (                    |gpio_radar          ) in  hi*
 gpio-1069 (                    |pic_int             ) in  hi
 gpio-1083 (                    |bt_default_rts      ) in  hi
 gpio-1090 (                    |bt_default_wake     ) in  hi

GPIOs 1096-1127, platform/pinctrl, gpio3:
 gpio-1112 (                    |mdio-reset          ) out hi

GPIOs 1128-1159, platform/pinctrl, gpio4:
 gpio-1153 (                    |vcc5v0_host         ) out hi
 gpio-1154 (                    |ex_enable           ) out lo
 gpio-1155 (                    |enable              ) out hi

其中 gpio-1068 ( |gpio_radar ) in hi
就是定制的上位机板子所用的距离传感器的命名 这里显示的hi 即为高电压状态,然后感应头的 地线与a4(我们用的是A4脚)短接 ,短接以后再次查询以上命令
gpio-1068 ( |gpio_radar ) in lo
此时 就显示的是低电量 说明板子本身没有问题,项目中用普通的传感器api调用即可

原文地址:https://blog.csdn.net/qq_15110579/article/details/82760991?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromBaidu-1.control&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromBaidu-1.control

在使用GPIO的时候,有时候不知道GPIO的状态,也不知道在内核中GPIO是否申请成功。

可以通过/sys/kernel/debug/gpio这个文件来查看。这个文件显示了申请成功的GPIO的输入输出状态和电平。

参考

http://elinux.org/GPIO

https://developer.ridgerun.com/wiki/index.php/How_to_use_GPIO_signals

配置
内核打开debugfs支持

Symbol: DEBUG_FS [=y]
   Prompt: Debug Filesystem
     Defined at lib/Kconfig.debug:77
     Depends on: SYSFS     
     Location:
       -> Kernel configuration
         -> Kernel hacking      

挂载debugfs
mount -t debugfs none /sys/kernel/debug

测试

root@android:/data # cat /sys/kernel/debug/gpio                                      
GPIOs 0-31, gpio-0:
 gpio-0   (ESDHC_CD            ) in  lo
 gpio-4   (btn volume-up       ) in  hi
 gpio-5   (btn volume-down     ) in  hi
 gpio-22  (AD7606_STBY         ) out lo
 gpio-31  (AD7606_CONVST       ) out lo
 
GPIOs 32-63, gpio-1:
 gpio-58  (spi_imx             ) out lo
 gpio-59  (spi_imx             ) in  lo
 gpio-60  (sysfs               ) out lo
 
GPIOs 64-95, gpio-2:
 gpio-83  (sensor pwr en       ) out lo
 gpio-86  (usb-pwr             ) out lo
 gpio-93  (btn power-key       ) in  hi
 
GPIOs 96-127, gpio-3:
 gpio-102 (matrix_kbd_col      ) out lo
 gpio-103 (matrix_kbd_row      ) in  hi
 gpio-104 (matrix_kbd_col      ) out lo
 gpio-105 (matrix_kbd_row      ) in  hi
 gpio-106 (matrix_kbd_col      ) out lo
 gpio-107 (matrix_kbd_row      ) in  hi
 gpio-108 (matrix_kbd_col      ) out lo
 gpio-109 (matrix_kbd_row      ) in  hi
 gpio-110 (scl                 ) in  hi
 gpio-111 (sda                 ) in  hi
 
GPIOs 128-159, gpio-4:
 
GPIOs 160-191, gpio-5:
 gpio-167 (AD7606_OS1          ) out lo
 gpio-168 (AD7606_OS0          ) out lo
 gpio-169 (AD7606_OS2          ) out lo
 gpio-170 (AD7606_RESET        ) out lo
 gpio-175 (cabc-en0            ) out lo
 gpio-176 (cabc-en1            ) out lo
 
GPIOs 192-223, gpio-6:
 gpio-192 (usb-h1-pwr          ) out lo
 gpio-205 (pFUZE-int           ) in  hi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值