Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix i2c_writeread for RTL8730E and SYU645B register read #6567

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/configs/rtl8730e/audio/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions os/arch/arm/src/amebasmart/amebasmart_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
33 changes: 14 additions & 19 deletions os/drivers/audio/syu645b.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
*
Expand Down