0

我正在为 i2c 通信生成几个包装文件。这些是用 C 编写的。

头文件如下所示:

#ifndef IMX6QI2C_WRAPPER_H_
#define IMX6QI2C_WRAPPER_H_

#include <linux/i2c-dev.h> //contains definitions for:
                                   struct i2c_msg
                                   struct i2c_rdwr_ioctl_data

//fn declarations

#endif /* IMX6QI2C_WRAPPER_H_ */

源文件包含:

#include "imx6qi2c_wrapper.h"
#include <stdio.h>    //printf()
#include <unistd.h>    //for close()
#include <string.h>    //for MANY implicit decl. & -Wformat errs
#include <sys/types.h> //open()
#include <sys/stat.h>  //open()
#include <fcntl.h>     //open(),O_RDWR
#include <sys/ioctl.h> //ioctl()
#include <errno.h>     //errno,strerror()

#define I2CMSGS_TOTAL_WR    1
#define I2CMSGS_TOTAL_RD    2
#define I2C_M_WR                0x00 //missing from i2c_msg flags


int imxSend_i2cMsg(const int i2c_fd, 
                   struct i2c_msg *i2cMsgArray, 
                   const unsigned int arraySize){ 

     //do stuff
}


int imxSend_i2cByte(const int i2c_fd,
                    const unsigned char i2cAddress,
                    const unsigned char devRegister,
                    const unsigned char value){

    struct i2c_msg i2cmsg[2];

    //do stuff

    ret=imxSend_i2cMsg(i2c_fd,&i2cmsg,I2CMSGS_TOTAL_WR);

    //do more stuff
}

现在,就“imxSend_i2cMsg()”的定义而言,编译器没有struct i2c_msg *i2cMsgArray问题。

但是struct i2c_msg i2cmsg[2]在函数“imxSend_i2cByte()”中声明局部变量有问题。

错误是:“数组类型的元素类型不完整”。

我很想知道。

它可能与#include 指令有关吗?在我的示例中,i2c-dev.h它包含“struct i2c_msg”的定义,是#included in i2c_wrapper.h,然后后者包含在i2c_wrapper.c文件中。据我了解,这意味着源文件确实可以“看到”“struct i2c_msg”。不?

我在stackoverflow中多次看到这个问题,但答案仍然不明显。有人可以指出我正确的方向吗?

谢谢您的帮助。

4

1 回答 1

0

好的,这是我的 makefile 中的错误“-I”标志。我没有正确指向“linux/i2c-dev.h”的位置

于 2013-07-25T12:15:09.027 回答