查看: 597|回复: 0

【HiKey】开发板GPIO使用基础

[复制链接]

该用户从未签到

发表于 2016-9-7 09:00:50 | 显示全部楼层 |阅读模式
分享到:
HiKey(LeMaker version):
如何控制开发板GPIO
HiKey开发板有20各GPIO bank(GPIO0-GPIO19)
每个bank都有几个基础值如下表所示
如何计算GPIO PIN值
GPIO PIN脚可以通过用户空间操作sysfs来访问
默认的内核配置已经将物理GPIO和sysfs的映射关系打开
在导入和导出前,只需要获得相应的GPIO的PIN脚编号即可
HiKey开发板的计算方法如下所示:
对于某个具体的PIN脚值 = 该PIN脚所在bank上的基础值 + PIN脚的index(offset)
GPIO0:  GPIO0*NUMBER* =  504 + *NUMBER*, for example, GPIO0_7  = 504 + 7 = 511
GPIO1:  GPIO1*NUMBER* =  496 + *NUMBER*, for example, GPIO1_5  = 496 + 5 = 501
GPIO2:  GPIO2*NUMBER* =  488 + *NUMBER*, for example, GPIO2_4  = 488 + 4 = 492
GPIO3:  GPIO3*NUMBER* =  480 + *NUMBER*, for example, GPIO3_6  = 480 + 6 = 486
GPIO4:  GPIO4*NUMBER* =  472 + *NUMBER*, for example, GPIO4_6  = 472 + 6 = 478
GPIO5:  GPIO5*NUMBER* =  464 + *NUMBER*, for example, GPIO5_3  = 464 + 3 = 467
GPIO6:  GPIO6*NUMBER* =  456 + *NUMBER*, for example, GPIO6_2  = 456 + 2 = 458
GPIO7:  GPIO7*NUMBER* =  448 + *NUMBER*, for example, GPIO7_1  = 448 + 1 = 449
GPIO8:  GPIO8*NUMBER* =  440 + *NUMBER*, for example, GPIO8_5  = 440 + 5 = 445
GPIO9:  GPIO9*NUMBER* =  432 + *NUMBER*, for example, GPIO9_6  = 432 + 6 = 438
GPIO10: GPIO10*NUMBER* = 424 + *NUMBER*, for example, GPIO10_5  = 424 + 5 = 429
GPIO11: GPIO11*NUMBER* = 416 + *NUMBER*, for example, GPIO11_3  = 416 + 3 = 419
GPIO12: GPIO12*NUMBER* = 408 + *NUMBER*, for example, GPIO12_1  = 408 + 1 = 409
GPIO13: GPIO13*NUMBER* = 400 + *NUMBER*, for example, GPIO13_1  = 400 + 1 = 401
GPIO14: GPIO14*NUMBER* = 392 + *NUMBER*, for example, GPIO14_4  = 392 + 4 = 396
GPIO15: GPIO15*NUMBER* = 384 + *NUMBER*, for example, GPIO15_5  = 384 + 5 = 389
GPIO16: GPIO16*NUMBER* = 376 + *NUMBER*, for example, GPIO16_2  = 376 + 2 = 378
GPIO17: GPIO17*NUMBER* = 368 + *NUMBER*, for example, GPIO17_1  = 368 + 1 = 369
GPIO18: GPIO18*NUMBER* = 360 + *NUMBER*, for example, GPIO18_7  = 360 + 7 = 367
GPIO19: GPIO19*NUMBER* = 352 + *NUMBER*, for example, GPIO19_6  = 352 + 6 = 358
使用sysfs来控制GPIO
首先需要导出需要操作的GPIO(以GPIO13_6为例)
GPIO13_6 的PIN脚值位 400 + 6 = 406
echo 406 > /sys/class/gpio/export
会产生/sys/class/gpio/gpio406这个目录
To set a GPIO pin as output you have to change the input/output direction with
设置该管脚为输出
echo out > /sys/class/gpio/gpio406/direction
设置该管脚为输入
echo in > /sys/class/gpio/gpio406/direction
查看该管脚高低电平值
cat /sys/class/gpio/gpio406/value
设置该管脚高低电平值
echo 1 > /sys/class/gpio/gpio406/value
回复

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /4 下一条

手机版|小黑屋|与非网

GMT+8, 2024-11-19 12:26 , Processed in 0.123025 second(s), 17 queries , MemCache On.

ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

苏公网安备 32059002001037号

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.