From f568673e1b43af16098215ba398d13087f6f4f69 Mon Sep 17 00:00:00 2001 From: Alexander Polleti Date: Fri, 7 Sep 2018 07:50:37 +0200 Subject: [PATCH] c++: Fix compilation of C++ file that includes i2c.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Within a C++ file I include i2c.h and got 6 of the following errors: zephyr/include/i2c.h:199:42: error: invalid conversion from ‘const void*’ to ‘const i2c_driver_api*’ [-fpermissive] const struct i2c_driver_api *api = dev->driver_api; ~~~~~^~~~~~~~~~ I fixed it with a c style conversion for each instance, so const struct i2c_driver_api *api = dev->driver_api; becomes const struct i2c_driver_api *api = (const struct i2c_driver_api *)dev->driver_api; I handled the instances for i2c_slave_driver_api alike. I tested this with a one of my own boards and communication with a I2C sensor. Signed-off-by: Alexander Polleti --- include/i2c.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/include/i2c.h b/include/i2c.h index 45f84324068..838d9372d29 100644 --- a/include/i2c.h +++ b/include/i2c.h @@ -199,7 +199,8 @@ __syscall int i2c_configure(struct device *dev, u32_t dev_config); static inline int _impl_i2c_configure(struct device *dev, u32_t dev_config) { - const struct i2c_driver_api *api = dev->driver_api; + const struct i2c_driver_api *api = + (const struct i2c_driver_api *)dev->driver_api; return api->configure(dev, dev_config); } @@ -230,7 +231,8 @@ static inline int _impl_i2c_transfer(struct device *dev, struct i2c_msg *msgs, u8_t num_msgs, u16_t addr) { - const struct i2c_driver_api *api = dev->driver_api; + const struct i2c_driver_api *api = + (const struct i2c_driver_api *)dev->driver_api; return api->transfer(dev, msgs, num_msgs, addr); } @@ -264,7 +266,8 @@ __syscall int i2c_slave_register(struct device *dev, static inline int _impl_i2c_slave_register(struct device *dev, struct i2c_slave_config *cfg) { - const struct i2c_driver_api *api = dev->driver_api; + const struct i2c_driver_api *api = + (const struct i2c_driver_api *)dev->driver_api; if (!api->slave_register) { return -ENOTSUP; @@ -294,7 +297,8 @@ __syscall int i2c_slave_unregister(struct device *dev, static inline int _impl_i2c_slave_unregister(struct device *dev, struct i2c_slave_config *cfg) { - const struct i2c_driver_api *api = dev->driver_api; + const struct i2c_driver_api *api = + (const struct i2c_driver_api *)dev->driver_api; if (!api->slave_unregister) { return -ENOTSUP; @@ -319,7 +323,8 @@ __syscall int i2c_slave_driver_register(struct device *dev); static inline int _impl_i2c_slave_driver_register(struct device *dev) { - const struct i2c_slave_driver_api *api = dev->driver_api; + const struct i2c_slave_driver_api *api = + (const struct i2c_slave_driver_api *)dev->driver_api; return api->driver_register(dev); } @@ -340,7 +345,8 @@ __syscall int i2c_slave_driver_unregister(struct device *dev); static inline int _impl_i2c_slave_driver_unregister(struct device *dev) { - const struct i2c_slave_driver_api *api = dev->driver_api; + const struct i2c_slave_driver_api *api = + (const struct i2c_slave_driver_api *)dev->driver_api; return api->driver_unregister(dev); }