diff --git a/build/configs/rtl8730e/audio/defconfig b/build/configs/rtl8730e/audio/defconfig index 894586ad3e..fb0d2ce819 100644 --- a/build/configs/rtl8730e/audio/defconfig +++ b/build/configs/rtl8730e/audio/defconfig @@ -505,7 +505,7 @@ CONFIG_I2C_USERIO=y CONFIG_I2C_TRANSFER=y CONFIG_I2C_POLLED=y # CONFIG_I2C_TRACE is not set -# CONFIG_I2C_WRITEREAD is not set +CONFIG_I2C_WRITEREAD=y CONFIG_SPI=y CONFIG_SPI_USERIO=y # CONFIG_SPI_OWNBUS is not set diff --git a/os/arch/arm/src/amebasmart/amebasmart_i2c.c b/os/arch/arm/src/amebasmart/amebasmart_i2c.c index 83be4a7ca5..1f39674365 100644 --- a/os/arch/arm/src/amebasmart/amebasmart_i2c.c +++ b/os/arch/arm/src/amebasmart/amebasmart_i2c.c @@ -844,18 +844,22 @@ static int amebasmart_i2c_isr_process(struct amebasmart_i2c_priv_s *priv) i2c_slave_set_for_rd_req(priv->i2c_object, 1); ret = i2c_slave_write(priv->i2c_object, w_msgv->buffer, w_msgv->length); #else - ret = rtk_i2c_write(priv->i2c_object, w_msgv->addr, &write_restart, 1, 0); - ret = rtk_i2c_write(priv->i2c_object, w_msgv->addr, w_msgv->buffer, w_msgv->length, 1); + /* send stop only if there is no need to read after write */ + if ((r_msgv->flags & I2C_M_READ) != 0) + { + ret = rtk_i2c_write(priv->i2c_object, w_msgv->addr, w_msgv->buffer, w_msgv->length, 0); + } else { + ret = rtk_i2c_write(priv->i2c_object, w_msgv->addr, w_msgv->buffer, w_msgv->length, 1); + } #endif } - if ((r_msgv->flags & I2C_M_READ) != 0) { + if (ret == w_msgv->length && (r_msgv->flags & I2C_M_READ) != 0) { i2cinfo("i2c reading"); #ifdef CONFIG_I2C_SLAVE ret = i2c_slave_read(priv->i2c_object, r_msgv->buffer, r_msgv->length); #else - rtk_i2c_write(priv->i2c_object, r_msgv->addr, &write_restart, 1, 0); ret = rtk_i2c_read(priv->i2c_object, r_msgv->addr, r_msgv->buffer, r_msgv->length, 1); #endif } diff --git a/os/drivers/audio/syu645b.c b/os/drivers/audio/syu645b.c index 03c08402b0..9632479935 100644 --- a/os/drivers/audio/syu645b.c +++ b/os/drivers/audio/syu645b.c @@ -104,6 +104,20 @@ static struct pm_callback_s g_pm_syu645b_cb ={ }; #endif +static int syu645b_readreg_nbyte(FAR struct syu645b_dev_s *priv, uint8_t regaddr, uint8_t *regval, int nbytes) +{ + FAR struct i2c_dev_s *dev = priv->i2c; + FAR struct i2c_config_s *syu645b_i2c_config = &(priv->lower->i2c_config); + uint8_t reg_w[1]; + reg_w[0] = regaddr; + int ret = i2c_writeread(dev, syu645b_i2c_config, reg_w, 1, regval, nbytes); + if (ret != nbytes) { + auddbg("Error, cannot read reg %x\n", regaddr); + return ERROR; + } + return ret; +} + /************************************************************************************ * Name: syu645b_exec_i2c_script * @@ -137,25 +151,6 @@ static int syu645b_exec_i2c_script(FAR struct syu645b_dev_s *priv, t_codec_init_ return ret; } -static int syu645b_readreg_nbyte(FAR struct syu645b_dev_s *priv, uint8_t regaddr, uint8_t *regval, int nbytes) -{ - FAR struct i2c_dev_s *dev = priv->i2c; - FAR struct i2c_config_s *syu645b_i2c_config = &(priv->lower->i2c_config); - uint8_t reg_w[1]; - reg_w[0] = regaddr; - int ret = i2c_write(dev, syu645b_i2c_config, reg_w, 1); - if (ret != 1) { - auddbg("Error, cannot read reg %x\n", regaddr); - return ERROR; - } - ret = i2c_read(dev, syu645b_i2c_config, regval, nbytes); - if (ret != nbytes) { - auddbg("Error, cannot read reg %x\n", regaddr); - return ERROR; - } - return OK; -} - /************************************************************************************ * Name: syu645b_takesem *