From 009e9f76cbf72d747e51fe12bb72d3c26c97c1cd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 2 Feb 2016 07:13:03 -0600 Subject: [PATCH] I2C: Fixes/improvements from last massive I2C commits --- arch | 2 +- drivers/i2c/i2c_read.c | 1 - drivers/i2c/i2c_write.c | 1 - drivers/ioexpander/pca9555.c | 18 +++++++++++------- drivers/mtd/at24xx.c | 32 ++++++++++++++++++++------------ drivers/sensors/Kconfig | 14 +++++++------- drivers/sensors/lm75.c | 32 ++++++++++++++++++++------------ drivers/sensors/lm92.c | 32 ++++++++++++++++++++------------ drivers/sensors/ms58xx.c | 32 ++++++++++++++++++++------------ 9 files changed, 99 insertions(+), 65 deletions(-) diff --git a/arch b/arch index cb55e30476..f80912e0ce 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit cb55e3047693dca56aaf2aaa2e932f6b83d148c5 +Subproject commit f80912e0ceb3ff4c83eb86a3d128df81b2bc9a85 diff --git a/drivers/i2c/i2c_read.c b/drivers/i2c/i2c_read.c index 83b0e681b2..b72523b4ee 100644 --- a/drivers/i2c/i2c_read.c +++ b/drivers/i2c/i2c_read.c @@ -88,4 +88,3 @@ int i2c_read(FAR struct i2c_master_s *dev, return I2C_TRANSFER(dev, &msg, 1); } - diff --git a/drivers/i2c/i2c_write.c b/drivers/i2c/i2c_write.c index 0638486d65..30939806c3 100644 --- a/drivers/i2c/i2c_write.c +++ b/drivers/i2c/i2c_write.c @@ -84,4 +84,3 @@ int i2c_write(FAR struct i2c_master_s *dev, return I2C_TRANSFER(dev, &msg, 1); } - diff --git a/drivers/ioexpander/pca9555.c b/drivers/ioexpander/pca9555.c index 2d9f213304..bdfb9c6c79 100644 --- a/drivers/ioexpander/pca9555.c +++ b/drivers/ioexpander/pca9555.c @@ -136,17 +136,21 @@ static const struct ioexpander_ops_s g_pca9555_ops = ****************************************************************************/ static inline int pca9555_write(FAR struct pca9555_dev_s *pca, - FAR const uint8_t *wbuffer, int wbuflen) + FAR const uint8_t *, int wbuflen) { - struct i2c_config_s config; + struct i2c_msg_s msg; - /* Set up the configuration and perform the write-read operation */ + /* Setup for the transfer */ - config.frequency = pca->config->frequency; - config.address = pca->config->address; - config.addrlen = 7; + msg.frequency = pca->config->frequency; + msg.addr = pca->config->address; + msg.flags = 0; + msg.buffer = (FAR uint8_t *)wbuffer; /* Override const */ + msg.length = wbuflen; - return i2c_write(pca->i2c, &config, wbuffer, wbuflen); + /* Then perform the transfer. */ + + return I2C_TRANSFER((pca->i2c, &msg, 1); } /**************************************************************************** diff --git a/drivers/mtd/at24xx.c b/drivers/mtd/at24xx.c index 85299baada..fdecf95b80 100644 --- a/drivers/mtd/at24xx.c +++ b/drivers/mtd/at24xx.c @@ -203,15 +203,19 @@ static struct at24c_dev_s g_at24c; static int at24c_i2c_write(FAR struct at24c_dev_s *priv, uint16_t at24addr, FAR const uint8_t *buffer, int buflen) { - struct i2c_config_s config; + struct i2c_msg_s msg; - /* Set up the I2C configuration */ + /* Setup for the transfer */ - config.frequency = CONFIG_AT24XX_FREQUENCY; - config.address = at24addr; - config.addrlen = 7; + msg.frequency = CONFIG_AT24XX_FREQUENCY, + msg.addr = at24addr; + msg.flags = 0; + msg.buffer = (FAR uint8_t *)buffer; /* Override const */ + msg.length = buflen; - return i2c_write(priv->dev, &config, buffer, buflen); + /* Then perform the transfer. */ + + return I2C_TRANSFER(priv->dev, &msg, 1); } /**************************************************************************** @@ -225,15 +229,19 @@ static int at24c_i2c_write(FAR struct at24c_dev_s *priv, uint16_t at24addr, static int at24c_i2c_read(FAR struct at24c_dev_s *priv, uint16_t at24addr, FAR uint8_t *buffer, int buflen) { - struct i2c_config_s config; + struct i2c_msg_s msg; - /* Set up the I2C configuration */ + /* Setup for the transfer */ - config.frequency = CONFIG_AT24XX_FREQUENCY; - config.address = at24addr; - config.addrlen = 7; + msg.frequency = CONFIG_AT24XX_FREQUENCY, + msg.addr = at24addr, + msg.flags = I2C_M_READ; + msg.buffer = buffer; + msg.length = buflen; - return i2c_read(priv->dev, &config, buffer, buflen); + /* Then perform the transfer. */ + + return I2C_TRANSFER(priv->dev, &msg, 1); } /************************************************************************************ diff --git a/drivers/sensors/Kconfig b/drivers/sensors/Kconfig index abbe171699..c73e1abae0 100644 --- a/drivers/sensors/Kconfig +++ b/drivers/sensors/Kconfig @@ -24,7 +24,7 @@ config LIS331DL select I2C config LIS331DL_I2C_FREQUENCY - bool "LIS331DL I2C frequency" + int "LIS331DL I2C frequency" default 100000 range 1 100000 depends on LIS331DL @@ -37,7 +37,7 @@ config SN_LSM9DS1 Enable driver support for the STMicro LSM9DS1. config LSM9DS1_I2C_FREQUENCY - bool "LSM9DS1 I2C frequency" + int "LSM9DS1 I2C frequency" default 400000 range 1 400000 depends on SN_LSM9DS1 @@ -50,7 +50,7 @@ config MB7040 Enable driver support for the MaxBotix MB7040 sonar. config MB7040_I2C_FREQUENCY - bool "MB7040 I2C frequency" + int "MB7040 I2C frequency" default 400000 range 1 400000 depends on MB7040 @@ -63,7 +63,7 @@ config MCP9844 Enable driver support for the MCP9844 I2C Temperature sensor. config MCP9844_I2C_FREQUENCY - bool "MCP9844 I2C frequency" + int "MCP9844 I2C frequency" default 400000 range 1 400000 depends on MCP9844 @@ -76,7 +76,7 @@ config MS58XX Enable driver support for MEAS MS58XX altimeters. config MS58XX_I2C_FREQUENCY - bool "MS58XX I2C frequency" + int "MS58XX I2C frequency" default 400000 range 1 400000 depends on MS58XX @@ -164,7 +164,7 @@ config LM75 the TI TMP100/101. config LM75_I2C_FREQUENCY - bool "LM75 I2C frequency" + int "LM75 I2C frequency" default 100000 range 1 100000 depends on I2C_LM75 @@ -177,7 +177,7 @@ config LM92 Enable driver support for the TI LM92 Temperature Sensor. config LM92_I2C_FREQUENCY - bool "LM92 I2C frequency" + int "LM92 I2C frequency" default 400000 range 1 400000 depends on LM92 diff --git a/drivers/sensors/lm75.c b/drivers/sensors/lm75.c index 4affac4554..f3fad73972 100644 --- a/drivers/sensors/lm75.c +++ b/drivers/sensors/lm75.c @@ -135,15 +135,19 @@ static const struct file_operations g_lm75fops = static int lm75_i2c_write(FAR struct lm75_dev_s *priv, FAR const uint8_t *buffer, int buflen) { - struct i2c_config_s config; + struct i2c_msg_s msg; - /* Set up the I2C configuration */ + /* Setup for the transfer */ - config.frequency = CONFIG_LM75_I2C_FREQUENCY; - config.address = priv->addr; - config.addrlen = 7; + msg.frequency = CONFIG_LM75_I2C_FREQUENCY, + msg.addr = priv->addr; + msg.flags = 0; + msg.buffer = (FAR uint8_t *)buffer; /* Override const */ + msg.length = buflen; - return i2c_write(priv->i2c, &config, buffer, buflen); + /* Then perform the transfer. */ + + return I2C_TRANSFER(priv->i2c, &msg, 1); } /**************************************************************************** @@ -157,15 +161,19 @@ static int lm75_i2c_write(FAR struct lm75_dev_s *priv, static int lm75_i2c_read(FAR struct lm75_dev_s *priv, FAR uint8_t *buffer, int buflen) { - struct i2c_config_s config; + struct i2c_msg_s msg; - /* Set up the I2C configuration */ + /* Setup for the transfer */ - config.frequency = CONFIG_LM75_I2C_FREQUENCY; - config.address = priv->addr; - config.addrlen = 7; + msg.frequency = CONFIG_LM75_I2C_FREQUENCY, + msg.addr = priv->addr, + msg.flags = I2C_M_READ; + msg.buffer = buffer; + msg.length = buflen; - return i2c_read(priv->i2c, &config, buffer, buflen); + /* Then perform the transfer. */ + + return I2C_TRANSFER(priv->i2c, &msg, 1); } /**************************************************************************** diff --git a/drivers/sensors/lm92.c b/drivers/sensors/lm92.c index 6d8bf190c0..73f4d54634 100644 --- a/drivers/sensors/lm92.c +++ b/drivers/sensors/lm92.c @@ -137,15 +137,19 @@ static const struct file_operations g_lm92fops = static int lm92_i2c_write(FAR struct lm92_dev_s *priv, FAR const uint8_t *buffer, int buflen) { - struct i2c_config_s config; + struct i2c_msg_s msg; - /* Set up the I2C configuration */ + /* Setup for the transfer */ - config.frequency = CONFIG_LM92_I2C_FREQUENCY; - config.address = priv->addr; - config.addrlen = 7; + msg.frequency = CONFIG_LM92_I2C_FREQUENCY, + msg.addr = priv->addr; + msg.flags = 0; + msg.buffer = (FAR uint8_t *)buffer; /* Override const */ + msg.length = buflen; - return i2c_write(priv->i2c, &config, buffer, buflen); + /* Then perform the transfer. */ + + return I2C_TRANSFER(priv->i2c, &msg, 1); } /**************************************************************************** @@ -159,15 +163,19 @@ static int lm92_i2c_write(FAR struct lm92_dev_s *priv, static int lm92_i2c_read(FAR struct lm92_dev_s *priv, FAR uint8_t *buffer, int buflen) { - struct i2c_config_s config; + struct i2c_msg_s msg; - /* Set up the I2C configuration */ + /* Setup for the transfer */ - config.frequency = CONFIG_LM92_I2C_FREQUENCY; - config.address = priv->addr; - config.addrlen = 7; + msg.frequency = CONFIG_LM92_I2C_FREQUENCY, + msg.addr = priv->addr, + msg.flags = I2C_M_READ; + msg.buffer = buffer; + msg.length = buflen; - return i2c_read(priv->i2c, &config, buffer, buflen); + /* Then perform the transfer. */ + + return I2C_TRANSFER(priv->i2c, &msg, 1); } /**************************************************************************** diff --git a/drivers/sensors/ms58xx.c b/drivers/sensors/ms58xx.c index 1d4bfdd68c..410a391a72 100644 --- a/drivers/sensors/ms58xx.c +++ b/drivers/sensors/ms58xx.c @@ -251,15 +251,19 @@ static uint8_t ms58xx_crc(FAR uint16_t *src, uint8_t crcIndex) static int ms58xx_i2c_write(FAR struct ms58xx_dev_s *priv, FAR const uint8_t *buffer, int buflen) { - struct i2c_config_s config; + struct i2c_msg_s msg; - /* Set up the configuration and perform the write-read operation */ + /* Setup for the transfer */ - config.frequency = CONFIG_MS58XX_I2C_FREQUENCY; - config.address = priv->addr; - config.addrlen = 7; + msg.frequency = CONFIG_MS58XX_I2C_FREQUENCY, + msg.addr = priv->addr; + msg.flags = 0; + msg.buffer = (FAR uint8_t *)buffer; /* Override const */ + msg.length = buflen; - return i2c_write(priv->i2c, &config, buffer, buflen); + /* Then perform the transfer. */ + + return I2C_TRANSFER(priv->i2c, &msg, 1); } /**************************************************************************** @@ -273,15 +277,19 @@ static int ms58xx_i2c_write(FAR struct ms58xx_dev_s *priv, static int ms58xx_i2c_read(FAR struct ms58xx_dev_s *priv, FAR uint8_t *buffer, int buflen) { - struct i2c_config_s config; + struct i2c_msg_s msg; - /* Set up the configuration and perform the write-read operation */ + /* Setup for the transfer */ - config.frequency = CONFIG_MS58XX_I2C_FREQUENCY; - config.address = priv->addr; - config.addrlen = 7; + msg.frequency = CONFIG_MS58XX_I2C_FREQUENCY, + msg.addr = priv->addr, + msg.flags = I2C_M_READ; + msg.buffer = buffer; + msg.length = buflen; - return i2c_read(priv->i2c, &config, buffer, buflen); + /* Then perform the transfer. */ + + return I2C_TRANSFER(priv->i2c, &msg, 1); } /****************************************************************************