为什么i2c_smbus函数不可用? (I2C –嵌入式Linux) [英] Why are i2c_smbus function not available? (I2C – Embedded Linux)
问题描述
在开发嵌入式Linux软件以在I2C总线上进行通信时,有很多关于使用 i2c_smbus _ 函数的参考.在软件项目中针对ARM8处理器在软件项目中引用了 i2c_smbus 之类的功能 i2c_smbus_read_word_data 时,例如在以下范围内未生成" i2c_smbus_read_word_data"之类的错误:编译.
There are many references to using i2c_smbus_ functions when developing embedded Linux software to communicate on the I2C bus. When i2c_smbus functions such as i2c_smbus_read_word_data are referenced in software project for ARM8 processor errors such as ‘i2c_smbus_read_word_data’ was not declared in this scope are generated at compile.
对以下头文件的调查表明,大多数 i2c_smbus 函数定义都不存在.
Investigation of the following header files indicate the absence of most i2c_smbus function definition.
- /usr/arm-linux-gnueabi/include/linux/i2c.h
- /usr/arm-linux-gnueabi/include/linux/i2c-dev.h
在以下参考文献中, i2c.h 文件已定义了所有i2c_smbus.
Also in that following reference i2c.h file has all the i2c_smbus defined.
该问题如何解决?
研究参考
- Using I2C from userspace in Linux
- I2C Communication from Linux Userspace – Part II
- I2C dev interface
推荐答案
因为您的应用程序使用了错误的头文件.
Because you are using a wrong header file for your application.
如果您在标头中的函数i2c_smbus_read_word_data()
上看到extern
,则该标头是您的内核的标头文件,而不是您的 application 的标头文件. Linux内核具有i2c_smbus_read_word_data()
和其他i2c smbus函数供内部使用.但是它们是a)不是系统调用,或者b)无法从您的应用程序访问.
If you see an extern
on the function i2c_smbus_read_word_data()
in your header, it's a header file for your kernel, but not for your application. The Linux kernel has i2c_smbus_read_word_data()
and other i2c smbus functions for its internal use. But they are a) not system calls, or b) not accessible from your application.
相反,请从lm-sensors中获取 i2c-tools 并进行安装.如果您使用的是Debian,只需
Instead, get i2c-tools from lm-sensors and install it. If you are using Debian, just
sudo apt-get install libi2c-dev
,并使用i2c_smbus_read_word_data()
或它们提供的任何其他接口. i2c-dev是仅标头的程序包,这意味着没有库可链接.所有函数都是使用ioctl()
定义的内联函数.
and use i2c_smbus_read_word_data()
or any other interfaces they offer. i2c-dev is a header only package, meaning that there is no library to link to. All functions are inline functions defined using ioctl()
.
例如)
static inline __s32 i2c_smbus_access(int file, char read_write, __u8 command,
int size, union i2c_smbus_data *data)
{
struct i2c_smbus_ioctl_data args;
args.read_write = read_write;
args.command = command;
args.size = size;
args.data = data;
return ioctl(file,I2C_SMBUS,&args);
}
:
static inline __s32 i2c_smbus_read_word_data(int file, __u8 command)
{
union i2c_smbus_data data;
if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
I2C_SMBUS_WORD_DATA,&data))
return -1;
else
return 0x0FFFF & data.word;
}
这篇关于为什么i2c_smbus函数不可用? (I2C –嵌入式Linux)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!