i2c_smbus_ *功能不在centos7 i2c-dev.h上存在

时间:2015-11-25 16:07:08

标签: c++ linux i2c

我需要从Linux C ++程序管理SMBus设备。

我可以打开设备(/ dev / i2c-0),但我发现所有i2c_smbus *函数(i2c_smbus_write_word_data,i2c_smbus_read_word_data等等)都未在任何i2c标头中声明。

i2c文档说这些函数是在linux / i2c-dev.h标题中声明的,但在我的centos7中并不存在。

我在所有标题中都在寻找它们,但未在任何文件中定义。

关于为什么没有在那里定义的任何想法以及它们在哪里?

这是我的代码:

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <linux/i2c-dev.h>
#include <linux/i2c.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <memory.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/io.h>
#include <sys/ioctl.h>

int main() {
    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!

    int Address = 0x39; //Slave addr 

     char i2c_dev_node_path[] = "/dev/i2c-0";

     int ret_val = 0;
     /* Open the device node for the I2C adapter of bus 0 */
     i2c_dev_node = open(i2c_dev_node_path, O_RDWR);
     if (i2c_dev_node < 0)
     {       
         cout << "EROR Unable to open device node." << endl;
         return -1;
     }


     int i2c_dev_address = 0x39;

     ret_val = ioctl(i2c_dev_node,I2C_SLAVE,i2c_dev_address);
     if (ret_val < 0)
     {
         perror("Could not set I2C_SLAVE.");
         cout << "EROR Could not set I2C_SLAVE." << endl;
         return -1;
     }

     cout << "ALL OK!!!!!" << endl;


   int retVal = i2c_smbus_read_word_data ( i2c_dev_node , 0xac );

}

1 个答案:

答案 0 :(得分:0)

在/lib/modules/4.8.28-release/kernel/drivers/i2c/i2c-smbus.ko中复制i2c-smbus.ko

yum install libi2c-dev