mar*_*des 5 c linux driver i2c raspberry-pi
我正在尝试使用Raspberry Pi作为开发套件,通过I2C总线配置SAA6752HS芯片(MPEG-2编码器).在我必须在芯片的地址0xC2处写入之前,这是一块蛋糕.对于此任务,我必须使用期望有效负载大小为189字节的I2C命令.然后我在/usr/include/linux/i2c.h中偶然发现I2C驱动程序内部的32字节限制,由I2C_SMBUS_BLOCK_MAX定义.不可能强制使用不同的最大限制值.I2C lib周围的所有内容最终都会进入函数i2c_smbus_access,任何超过32个字节的请求都会使ioctl返回-1.到目前为止我不知道如何调试它.
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);
}
Run Code Online (Sandbox Code Playgroud)
考虑到有些设备需要超过32个字节的有效载荷数据才能工作,我无法理解为什么存在这样的限制(SAA6752HS就是这样一个例子).
有没有办法克服这种限制而不重写新的驱动程序?
先感谢您.
这是Linux i2c接口的文档:https://www.kernel.org/doc/Documentation/i2c/dev-interface
在最简单的级别,您可以使用ioctl(I2C_SLAVE)设置从站地址和write系统调用来编写命令.就像是:
i2c_write(int file, int address, int subaddress, int size, char *data) {
char buf[size + 1]; // note: variable length array
ioctl(file, I2C_SLAVE, address); // real code would need to check for an error
buf[0] = subaddress; // need to send everything in one call to write
memcpy(buf + 1, data, size); // so copy subaddress and data to a buffer
write(file, buf, size + 1);
}
Run Code Online (Sandbox Code Playgroud)