在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. 操作

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

参考:

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

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

linux gpio控制之sysfs接口的更多相关文章

  1. linux设备驱动程序--gpio控制

    gpio驱动程序 上一章节linux设备驱动程序--创建设备节点章节主要介绍了linux字符设备驱动程序的框架,从这一章节开始我们讲解各种外设的控制,包括gpio,i2c,dma等等,既然是外设,那就 ...

  2. Linux GPIO子系统

    一 概述 Linux内核中gpio是最简单,最常用的资源(和 interrupt ,dma,timer一样)驱动程序,应用程序都能够通过相应的接口使用gpio,gpio使用0-MAX_INT之间的整数 ...

  3. sysfs接口函数的建立_DEVICE_ATTR(转)

    sysfs接口函数到建立_DEVICE_ATTR 最近在弄Sensor驱动,看过一个某厂家的成品驱动,里面实现的全都是sysfs接口,hal层利用sysfs生成的接口,对Sensor进行操作. 说道s ...

  4. sysfs接口整理

    SYS节点 目录结构: 1:sysfs相关知识点介绍(介绍sysfs的体系结构) 2:sys节点核心知识(使用sys节点核心的知识) 3:代码实例(创建sys节点的代码实例) 1:sysfs相关知识点 ...

  5. sysfs接口函数到建立_DEVICE_ATTR

    sysfs接口函数到建立_DEVICE_ATTR 最近在弄Sensor驱动,看过一个某厂家的成品驱动,里面实现的全都是sysfs接口,hal层利用sysfs生成的接口,对Sensor进行操作. 说道s ...

  6. python环境下实现OrangePi Zero寄存器访问及GPIO控制

    最近入手OrangePi Zero一块,程序上需要使用板子上自带的LED灯,在网上一查,不得不说OPi的支持跟树莓派无法相比.自己摸索了一下,实现简单的GPIO控制方法,作者的Zero安装的是Armb ...

  7. sysfs_create_group创建sysfs接口

    在调试驱动,可能需要对驱动里的某些变量进行读写,或函数调用.可通过sysfs接口创建驱动对应的属性,使得可以在用户空间通过sysfs接口的show和store函数与硬件交互: Syss接口可通过sys ...

  8. 树莓派Zero W GPIO控制

    作者:陈拓 chentuo@ms.xab.ac.cn 2018.06.09/2018.07.05 0.  概述 本文介绍树莓派 Zero W的GPIO控制,并用LED看效果. 0.1 树莓派GPIO编 ...

  9. Linux GPIO控制方法

    Linux GPIO控制方法 kernel version 4.4.12 在文件系统层: 1. 进入 /sys/class/gpio/ 目录 2. 假设你想控制的GPIO0_29,步骤如下: 1. e ...

随机推荐

  1. [CXF REST标准实战系列] 二、Spring4.0 整合 CXF3.0,实现测试接口(转)

    转自:[CXF REST标准实战系列] 二.Spring4.0 整合 CXF3.0,实现测试接口 文章Points: 1.介绍RESTful架构风格 2.Spring配置CXF 3.三层初设计,实现W ...

  2. HDUOJ------------1051Wooden Sticks

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  3. js访问url和cookie

    function QueryString() { var data = []; this.Read = function() { var aPairs, aTmp; var queryString = ...

  4. Hibernate 、 Axis2发布

    1. you just compile your web-service into aar file (not include bean files), copy the aar into axis2 ...

  5. Block编程注意的问题

    一,前言   block 是在 iOS 4 中引入的新特性,它和 C++ 11 中的 lamba 表达式概念相似,有时候也被称为闭包.经过一段时间的使用,我发现要用对用好 block 还是有不少需要注 ...

  6. 【LeetCode】127. Word Ladder

    Word Ladder Given two words (start and end), and a dictionary, find the length of shortest transform ...

  7. GO语言学习 ---nil

    nil是什么 相信写过Golang的程序员对下面一段代码是非常非常熟悉的了: if err != nil { // do something.... }     当出现不等于nil的时候,说明出现某些 ...

  8. OGG_GoldenGate日常监控(案例)

    2014-03-11 Created By BaoXinjian  

  9. 判断当前用户有无Administrator的权限

    很方便的一个函数,有兴趣的看看! /************************************************************************/ /* 函数说明: ...

  10. -174dBm的含义

    常温下(290K)一个热电阻会产生少量的噪声能量P=kTB k = 玻尔兹曼常数(1.38 x 10–23 J/K)T = 温度(K)B = 噪声带宽(Hz) 由于总噪声功率是测量带宽的函数,数值通常 ...