linux gpio控制之sysfs接口

在3.14及之后的linux中对gpio提供了sysfs接口,说明文档:Documents/gpio/sysfs.txt。

Platforms which use the "gpiolib" implementors framework may choose to configure a sysfs user interface to GPIOs.This is different from the debugfs interface, since it provides control over GPIO direction and value instead of just showing a gpio state summary. Plus, it could be present on production systems without debugging support.

Note that standard kernel drivers exist for common "LEDs and Buttons" GPIO tasks:  "leds-gpio" and "gpio_keys", respectively. Use those instead of talking directly to the GPIOs; they integrate with kernel frameworks better than your userspace code could.

1. 目录

/sys/class/gpio

2. 操作

1) echo 29 > export
2) 此时会产生一个gpio29 的目录.
3) cd gpio29
4) 关注以下几个文件:
        direction 这个文件是控制你是输出还是输入模式
                如果想设置为输入:echo in > direction
                如果想设置为输出:echo out > direction
        value 这个文件是在输出模式时,控制高低电平
                高电平:echo 1 > value
                低电平:echo 0 > value
        edge 这个控制中断触发模式
                无: echo none > edge
                上升沿触发:echo rising > edge
                下降沿触发:echo falling > edge
                轮询:echo both > edge
        active_low: 这个按照官方的说法是这个翻转电平,输入非零的数即上升沿变为下降沿。
                o: echo 0 > active_low
                非零的数: echo 3 > active_low
5)关闭这个GPIO控制。
        cd /sys/class/gpio/
        echo 29 > unexport

 

参考:

1. http://blog.csdn.net/mirkerson/article/details/8464290

2. https://www.cnblogs.com/chenfulin5/p/6274076.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值