Linux应用程序——用户层操作GPIO

stm32mp157  盘古开发板  Linux内核版本4.19

目录

1、拜兔核i2SOM的wiki上关于gpio应用的说明

2、gpio操作相关的数据结构

3、测试代码:

4、参考链接


1、拜兔核i2SOM的wiki上关于gpio应用的说明

链接:http://wiki.i2som.com/pages/viewpage.action?pageId=22479311

以下是链接中的复制内容:

 

GPIO操作在Linux系统上是常用功能,STM32MP1芯片平台也同样支持。从Linux 4.8版本开始,Linux引入了新的gpio操作方式,GPIO字符设备。不再使用以前SYSFS方式在"/sys/class/gpio"目录下来操作GPIO,而是,基于"文件描述符"的字符设备,每个GPIO组在"/dev"下有一个对应的gpiochip文件,例如"/dev/gpiochip0, /dev/gpiochip1"。使用常规的LInux文件操作方式即可操作这些gpiochip文件,基本可以概括为open() + ioctl() + poll() + read() + close()。

STM32MP1平台的gpiochip文件描述

字符设备

描述

/dev/gpiochip0 GPIOA
/dev/gpiochip1 GPIOB
/dev/gpiochip2 GPIOC
/dev/gpiochip3 GPIOD
/dev/gpiochip4 GPIOE
/dev/gpiochip5 GPIOF
/dev/gpiochip6 GPIOG
/dev/gpiochip7 GPIOH
/dev/gpiochip8 GPIOI
/dev/gpiochip9 GPIOJ
/dev/gpiochip10 GPIOK
/dev/gpiochip11 GPIOZ

gpiochip 操作

gpio申请

flags: desired flags for the desired GPIO lines, such as GPIOHANDLE_REQUEST_OUTPUT, GPIOHANDLE_REQUEST_ACTIVE_LOW etc, OR:ed * together. Note that even if multiple lines are requested, the same flags * must be applicable to all of them, if you want lines with individual * flags set, request them one by one. It is possible to select * a batch of input or output lines, but they must all have the same * characteristics, i.e. all inputs or all outputs, all active low etc

lines: number of lines requested in this request, i.e. the number of valid fields in the above arrays, set to 1 to request a single line

struct gpiohandle_request {

    __u32 lineoffsets[GPIOHANDLES_MAX];

    __u32 flags;

    __u8 default_values[GPIOHANDLES_MAX];

    char consumer_label[32];

    __u32 lines;

    int fd;

};

 

#define GPIOHANDLES_MAX 64

#define GPIOHANDLE_REQUEST_INPUT (1UL << 0)

#define GPIOHANDLE_REQUEST_OUTPUT (1UL << 1)

#define GPIOHANDLE_REQUEST_ACTIVE_LOW (1UL << 2)

#define GPIOHANDLE_REQUEST_OPEN_DRAIN (1UL << 3)

#define GPIOHANDLE_REQUEST_OPEN_SOURCE (1UL << 4)

gpio 操作数据

stru

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值