简体   繁体   English

如何在Linux中访问IIO设备驱动程序

[英]How to access an IIO device driver in linux

I a noob to Linux device drivers. 我对Linux设备驱动程序不满意。

I have an IIO driver with me (for OPT3001 ambient light sensor) , operating over the I2C bus, which has been compiled successfully in the kernel (version 3.18). 我有一个IIO驱动程序(用于OPT3001环境光传感器),它通过I2C总线运行,该总线已在内核中成功编译(版本3.18)。 The device tree is modified to match the compatible field, present in the driver. 修改设备树以匹配驱动程序中存在的兼容字段。

The problem is how do I access this driver to get some data in the userspace ? 问题是如何访问此驱动程序以在用户空间中获取一些数据?

The driver has some callbacks for read and write registered in a structure. 驱动程序在结构中注册了一些用于读取和写入的回调。 Should I call them directly in my C file ? 我应该直接在C文件中调用它们吗?

You can use the userspace API provided by: 您可以使用以下提供的用户空间API:

#include <linux/i2c-dev.h>

Using it you can open de bus /dev/i2c-X (X=0,1,2,...), set device address using ioctl call, and use read and write operations to read and write to/from the bus. 使用它,您可以打开/ dev / i2c-X总线(X = 0,1,2,...),使用ioctl调用设置设备地址,并使用读写操作来读写总线。

Also, you can install "i2c-tools" package (apt-get install i2c-tools), to install userspace tools like i2cset, i2cget and i2cdetect, very useful for testing the I2C bus and the device connected to it. 另外,您可以安装“ i2c-tools”软件包(apt-get install i2c-tools),以安装诸如i2cset,i2cget和i2cdetect之类的用户空间工具,这对于测试I2C总线及其连接的设备非常有用。

you have differents possibilities : 您有不同的可能性:

  • your driver provide a /dev node you can open in you C file. 您的驱动程序提供了一个/ dev节点,您可以在C文件中打开该节点。
  • your driver provide informations through sysfs. 您的驱动程序通过sysfs提供信息。

in case of a /dev node, you can have access to file operations (open, read, write, ioctl). 如果是/ dev节点,则可以访问文件操作(打开,读取,写入,ioctl)。 you just have to open your file 1 time and each read() call will read the value from the sensor. 您只需要打开文件1次,每次read()调用都会从传感器读取值。

in case of sysfs, you should find the file to open/read in /sys/class/... 如果是sysfs,则应该在/ sys / class / ...中找到要打开/读取的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM