HAL_Linux: made I2C driver more portable

this uses a typeof() to cope with different kernel data types for I2C
messages
This commit is contained in:
Andrew Tridgell 2014-07-15 03:50:47 +00:00
parent 485726258b
commit 1b85b12738

View File

@ -15,12 +15,6 @@
#include <linux/i2c.h>
#endif
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NONE
#define I2C_DATA_TYPE char
#else
#define I2C_DATA_TYPE __u8
#endif
using namespace Linux;
/*
@ -151,13 +145,13 @@ uint8_t LinuxI2CDriver::readRegisters(uint8_t addr, uint8_t reg,
addr : addr,
flags : 0,
len : 1,
buf : (I2C_DATA_TYPE *)&reg
buf : (typeof(msgs->buf))&reg
},
{
addr : addr,
flags : I2C_M_RD,
len : len,
buf : (I2C_DATA_TYPE *)data,
buf : (typeof(msgs->buf))data,
}
};
struct i2c_rdwr_ioctl_data i2c_data = {
@ -188,17 +182,17 @@ uint8_t LinuxI2CDriver::readRegistersMultiple(uint8_t addr, uint8_t reg,
struct i2c_msg msgs[2*n];
struct i2c_rdwr_ioctl_data i2c_data = {
msgs : msgs,
nmsgs : 2*n
nmsgs : (typeof(i2c_data.nmsgs))(2*n)
};
for (uint8_t i=0; i<n; i++) {
msgs[i*2].addr = addr;
msgs[i*2].flags = 0;
msgs[i*2].len = 1;
msgs[i*2].buf = (I2C_DATA_TYPE *)&reg;
msgs[i*2].buf = (typeof(msgs->buf))&reg;
msgs[i*2+1].addr = addr;
msgs[i*2+1].flags = I2C_M_RD;
msgs[i*2+1].len = len;
msgs[i*2+1].buf = (I2C_DATA_TYPE *)data;
msgs[i*2+1].buf = (typeof(msgs->buf))data;
data += len;
};
if (ioctl(_fd, I2C_RDWR, &i2c_data) == -1) {