I2C: Remove setaddress method

This commit is contained in:
Gregory Nutt
2016-02-01 12:14:31 -06:00
parent ecdc428086
commit f9053182d3
23 changed files with 207 additions and 522 deletions
+15 -53
View File
@@ -147,50 +147,6 @@ static const struct battery_charger_operations_s g_bq2425xops =
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: bq2425x_i2c_write
*
* Description:
* Write to the I2C device.
*
****************************************************************************/
static int bq2425x_i2c_write(FAR struct bq2425x_dev_s *priv,
FAR const uint8_t *buffer, int buflen)
{
struct i2c_config_s config;
/* Set up the configuration and perform the write-read operation */
config.frequency = priv->frequency;
config.address = priv->addr;
config.addrlen = 7;
return i2c_write(priv->i2c, &config, buffer, buflen);
}
/****************************************************************************
* Name: bq2425x_i2c_read
*
* Description:
* Read from the I2C device.
*
****************************************************************************/
static int bq2425x_i2c_read(FAR struct bq2425x_dev_s *priv,
FAR uint8_t *buffer, int buflen)
{
struct i2c_config_s config;
/* Set up the configuration and perform the write-read operation */
config.frequency = priv->frequency;
config.address = priv->addr;
config.addrlen = 7;
return i2c_read(priv->i2c, &config, buffer, buflen);
}
/****************************************************************************
* Name: bq2425x_getreg8
*
@@ -205,16 +161,19 @@ static int bq2425x_i2c_read(FAR struct bq2425x_dev_s *priv,
static int bq2425x_getreg8(FAR struct bq2425x_dev_s *priv, uint8_t regaddr,
FAR uint8_t *regval)
{
struct i2c_config_s config;
uint8_t val;
int ret;
/* Set the I2C address and address size */
/* Set up the I2C configuration */
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
config.frequency = priv->frequency;
config.address = priv->addr;
config.addrlen = 7;
/* Write the register address */
ret = bq2425x_i2c_write(priv, &regaddr, 1);
ret = i2c_write(priv->i2c, &config, &regaddr, 1);
if (ret < 0)
{
batdbg("i2c_write failed: %d\n", ret);
@@ -223,7 +182,7 @@ static int bq2425x_getreg8(FAR struct bq2425x_dev_s *priv, uint8_t regaddr,
/* Restart and read 8-bits from the register */
ret = bq2425x_i2c_read(priv, &val, 1);
ret = i2c_read(priv->i2c, &config, &val, 1);
if (ret < 0)
{
batdbg("i2c_read failed: %d\n", ret);
@@ -249,8 +208,15 @@ static int bq2425x_getreg8(FAR struct bq2425x_dev_s *priv, uint8_t regaddr,
static int bq2425x_putreg8(FAR struct bq2425x_dev_s *priv, uint8_t regaddr,
uint8_t regval)
{
struct i2c_config_s config;
uint8_t buffer[2];
/* Set up the I2C configuration */
config.frequency = priv->frequency;
config.address = priv->addr;
config.addrlen = 7;
batdbg("addr: %02x regval: %08x\n", regaddr, regval);
/* Set up a 3 byte message to send */
@@ -258,13 +224,9 @@ static int bq2425x_putreg8(FAR struct bq2425x_dev_s *priv, uint8_t regaddr,
buffer[0] = regaddr;
buffer[1] = regval;
/* Set the I2C address and address size */
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
/* Write the register address followed by the data (no RESTART) */
return bq2425x_i2c_write(priv, buffer, 2);
return i2c_write(priv->i2c, &config, buffer, 2);
}
/****************************************************************************
+13 -51
View File
@@ -229,50 +229,6 @@ static const struct battery_gauge_operations_s g_max1704xops =
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: max1704x_i2c_write
*
* Description:
* Write to the I2C device.
*
****************************************************************************/
static int max1704x_i2c_write(FAR struct max1704x_dev_s *priv,
FAR const uint8_t *buffer, int buflen)
{
struct i2c_config_s config;
/* Set up the configuration and perform the write-read operation */
config.frequency = priv->frequency;
config.address = priv->addr;
config.addrlen = 7;
return i2c_write(priv->i2c, &config, buffer, buflen);
}
/****************************************************************************
* Name: max1704x_i2c_read
*
* Description:
* Read from the I2C device.
*
****************************************************************************/
static int max1704x_i2c_read(FAR struct max1704x_dev_s *priv,
FAR uint8_t *buffer, int buflen)
{
struct i2c_config_s config;
/* Set up the configuration and perform the write-read operation */
config.frequency = priv->frequency;
config.address = priv->addr;
config.addrlen = 7;
return i2c_read(priv->i2c, &config, buffer, buflen);
}
/****************************************************************************
* Name: max1704x_getreg16
*
@@ -287,16 +243,19 @@ static int max1704x_i2c_read(FAR struct max1704x_dev_s *priv,
static int max1704x_getreg16(FAR struct max1704x_dev_s *priv, uint8_t regaddr,
FAR uint16_t *regval)
{
struct i2c_config_s config;
uint8_t buffer[2];
int ret;
/* Set the I2C address and address size */
/* Set up the configuration and perform the write-read operation */
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
config.frequency = priv->frequency;
config.address = priv->addr;
config.addrlen = 7;
/* Write the register address */
ret = max1704x_i2c_write(priv, &regaddr, 1);
ret = i2c_write(priv->i2c, &config, &regaddr, 1);
if (ret < 0)
{
batdbg("i2c_write failed: %d\n", ret);
@@ -305,7 +264,7 @@ static int max1704x_getreg16(FAR struct max1704x_dev_s *priv, uint8_t regaddr,
/* Restart and read 16-bits from the register */
ret = max1704x_i2c_read(priv, buffer, 2);
ret = i2c_read(priv->i2c, &config, buffer, 2);
if (ret < 0)
{
batdbg("i2c_read failed: %d\n", ret);
@@ -330,6 +289,7 @@ static int max1704x_getreg16(FAR struct max1704x_dev_s *priv, uint8_t regaddr,
static int max1704x_putreg16(FAR struct max1704x_dev_s *priv, uint8_t regaddr,
uint16_t regval)
{
struct i2c_config_s config;
uint8_t buffer[3];
batdbg("addr: %02x regval: %08x\n", regaddr, regval);
@@ -340,13 +300,15 @@ static int max1704x_putreg16(FAR struct max1704x_dev_s *priv, uint8_t regaddr,
buffer[1] = (uint8_t)(regval >> 8);
buffer[2] = (uint8_t)(regval & 0xff);
/* Set the I2C address and address size */
/* Set up the configuration and perform the write-read operation */
I2C_SETADDRESS(priv->i2c, priv->addr, 7);
config.frequency = priv->frequency;
config.address = priv->addr;
config.addrlen = 7;
/* Write the register address followed by the data (no RESTART) */
return max1704x_i2c_write(priv, buffer, 3);
return i2c_write(priv->i2c, &config, buffer, 3);
}
/****************************************************************************