本测试程序通过 ioctl(fd, I2C_SMBUS, &ioctl_data)访问smbus。
#include #include #include #include #include #include #include
#define I2C_DEV "/dev/i2c-0"
#define I2C_24CXX_ADDR 0x50 /* 0x58 for 0x24c64 or 0x50 for 24c128*/
#define REG_OFFSET 0x20
#define WRITE_VALUE 0x5a
#if 0
#define I2C_SMBUS_READ 1
#define I2C_SMBUS_WRITE 0
union i2c_smbus_data {
__u8 byte;
__u16 word;
__u8 block[I2C_SMBUS_BLOCK_MAX + 2]; /* block[0] is used for length */
/* and one more for user-space compatibility */
};
struct i2c_smbus_ioctl_data {
__u8 read_write;
__u8 command;
__u32 size;
union i2c_smbus_data __user *data;
};
#endif
int
main()
{
union i2c_smbus_data data;
struct i2c_smbus_ioctl_data ioctl