From 1b85b12738b985d554021a5fdafa1da121dda9f0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 15 Jul 2014 03:50:47 +0000 Subject: [PATCH] HAL_Linux: made I2C driver more portable this uses a typeof() to cope with different kernel data types for I2C messages --- libraries/AP_HAL_Linux/I2CDriver.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/libraries/AP_HAL_Linux/I2CDriver.cpp b/libraries/AP_HAL_Linux/I2CDriver.cpp index beee6a4f22..aee6cb1977 100644 --- a/libraries/AP_HAL_Linux/I2CDriver.cpp +++ b/libraries/AP_HAL_Linux/I2CDriver.cpp @@ -15,12 +15,6 @@ #include #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 *)® + buf : (typeof(msgs->buf))® }, { 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; ibuf))® 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) {