mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
Remove the read and write methods from the I2C interface
This commit is contained in:
@@ -331,10 +331,6 @@ static uint32_t efm32_i2c_setfrequency(FAR struct i2c_master_s *dev,
|
||||
static int efm32_i2c_setaddress(FAR struct i2c_master_s *dev, int addr, int nbits);
|
||||
static int efm32_i2c_process(FAR struct i2c_master_s *dev,
|
||||
FAR struct i2c_msg_s *msgs, int count);
|
||||
static int efm32_i2c_write(FAR struct i2c_master_s *dev, const uint8_t * buffer,
|
||||
int buflen);
|
||||
static int efm32_i2c_read(FAR struct i2c_master_s *dev, uint8_t * buffer,
|
||||
int buflen);
|
||||
static int efm32_i2c_transfer(FAR struct i2c_master_s *dev,
|
||||
FAR struct i2c_msg_s *msgs, int count);
|
||||
|
||||
@@ -410,8 +406,6 @@ static const struct i2c_ops_s efm32_i2c_ops =
|
||||
{
|
||||
.setfrequency = efm32_i2c_setfrequency,
|
||||
.setaddress = efm32_i2c_setaddress,
|
||||
.write = efm32_i2c_write,
|
||||
.read = efm32_i2c_read,
|
||||
.transfer = efm32_i2c_transfer
|
||||
};
|
||||
|
||||
@@ -1642,49 +1636,6 @@ static int efm32_i2c_process(FAR struct i2c_master_s *dev,
|
||||
return -errval;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: efm32_i2c_write
|
||||
*
|
||||
* Description:
|
||||
* Write I2C data
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int efm32_i2c_write(FAR struct i2c_master_s *dev, const uint8_t * buffer,
|
||||
int buflen)
|
||||
{
|
||||
struct i2c_msg_s msgv =
|
||||
{
|
||||
.addr = ((struct efm32_i2c_inst_s *)dev)->address,
|
||||
.flags = ((struct efm32_i2c_inst_s *)dev)->flags,
|
||||
.buffer = (uint8_t *) buffer,
|
||||
.length = buflen
|
||||
};
|
||||
|
||||
return efm32_i2c_process(dev, &msgv, 1);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: efm32_i2c_read
|
||||
*
|
||||
* Description:
|
||||
* Read I2C data
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int efm32_i2c_read(FAR struct i2c_master_s *dev, uint8_t * buffer, int buflen)
|
||||
{
|
||||
struct i2c_msg_s msgv =
|
||||
{
|
||||
.addr = ((struct efm32_i2c_inst_s *)dev)->address,
|
||||
.flags = ((struct efm32_i2c_inst_s *)dev)->flags | I2C_M_READ,
|
||||
.buffer = buffer,
|
||||
.length = buflen
|
||||
};
|
||||
|
||||
return efm32_i2c_process(dev, &msgv, 1);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: efm32_i2c_transfer
|
||||
*
|
||||
|
||||
@@ -136,10 +136,6 @@ static uint32_t lpc11_i2c_setfrequency(FAR struct i2c_master_s *dev,
|
||||
uint32_t frequency);
|
||||
static int lpc11_i2c_setaddress(FAR struct i2c_master_s *dev, int addr,
|
||||
int nbits);
|
||||
static int lpc11_i2c_write(FAR struct i2c_master_s *dev,
|
||||
const uint8_t *buffer, int buflen);
|
||||
static int lpc11_i2c_read(FAR struct i2c_master_s *dev, uint8_t *buffer,
|
||||
int buflen);
|
||||
static int lpc11_i2c_transfer(FAR struct i2c_master_s *dev,
|
||||
FAR struct i2c_msg_s *msgs, int count);
|
||||
static void lpc11_stopnext(struct lpc11_i2cdev_s *priv);
|
||||
@@ -162,8 +158,6 @@ struct i2c_ops_s lpc11_i2c_ops =
|
||||
{
|
||||
.setfrequency = lpc11_i2c_setfrequency,
|
||||
.setaddress = lpc11_i2c_setaddress,
|
||||
.write = lpc11_i2c_write,
|
||||
.read = lpc11_i2c_read,
|
||||
.transfer = lpc11_i2c_transfer
|
||||
};
|
||||
|
||||
@@ -225,74 +219,6 @@ static int lpc11_i2c_setaddress(FAR struct i2c_master_s *dev, int addr,
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lpc11_i2c_write
|
||||
*
|
||||
* Description:
|
||||
* Send a block of data on I2C using the previously selected I2C
|
||||
* frequency and slave address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int lpc11_i2c_write(FAR struct i2c_master_s *dev, const uint8_t *buffer,
|
||||
int buflen)
|
||||
{
|
||||
struct lpc11_i2cdev_s *priv = (struct lpc11_i2cdev_s *)dev;
|
||||
int ret = 0;
|
||||
|
||||
DEBUGASSERT(dev != NULL);
|
||||
|
||||
priv->wrcnt = 0;
|
||||
priv->rdcnt = 0;
|
||||
priv->msg.flags = 0;
|
||||
priv->msg.buffer = (uint8_t *)buffer;
|
||||
priv->msg.length = buflen;
|
||||
|
||||
priv->nmsg = 1;
|
||||
priv->msgs = &(priv->msg);
|
||||
|
||||
if (buflen > 0)
|
||||
{
|
||||
ret = lpc11_i2c_start(priv);
|
||||
}
|
||||
|
||||
return (ret == 0 ? 0 : -ETIMEDOUT);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lpc11_i2c_read
|
||||
*
|
||||
* Description:
|
||||
* Receive a block of data on I2C using the previously selected I2C
|
||||
* frequency and slave address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int lpc11_i2c_read(FAR struct i2c_master_s *dev, uint8_t *buffer,
|
||||
int buflen)
|
||||
{
|
||||
struct lpc11_i2cdev_s *priv = (struct lpc11_i2cdev_s *)dev;
|
||||
int ret = 0;
|
||||
|
||||
DEBUGASSERT(dev != NULL);
|
||||
|
||||
priv->wrcnt = 0;
|
||||
priv->rdcnt = 0;
|
||||
priv->msg.flags = I2C_M_READ;
|
||||
priv->msg.buffer = buffer;
|
||||
priv->msg.length = buflen;
|
||||
|
||||
priv->nmsg = 1;
|
||||
priv->msgs = &(priv->msg);
|
||||
|
||||
if (buflen > 0)
|
||||
{
|
||||
ret = lpc11_i2c_start(priv);
|
||||
}
|
||||
|
||||
return (ret == 0 ? 0 : -ETIMEDOUT);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lpc11_i2c_start
|
||||
*
|
||||
|
||||
@@ -136,10 +136,6 @@ static uint32_t lpc17_i2c_setfrequency(FAR struct i2c_master_s *dev,
|
||||
uint32_t frequency);
|
||||
static int lpc17_i2c_setaddress(FAR struct i2c_master_s *dev, int addr,
|
||||
int nbits);
|
||||
static int lpc17_i2c_write(FAR struct i2c_master_s *dev,
|
||||
const uint8_t *buffer, int buflen);
|
||||
static int lpc17_i2c_read(FAR struct i2c_master_s *dev, uint8_t *buffer,
|
||||
int buflen);
|
||||
static int lpc17_i2c_transfer(FAR struct i2c_master_s *dev,
|
||||
FAR struct i2c_msg_s *msgs, int count);
|
||||
static void lpc17_stopnext(struct lpc17_i2cdev_s *priv);
|
||||
@@ -162,8 +158,6 @@ struct i2c_ops_s lpc17_i2c_ops =
|
||||
{
|
||||
.setfrequency = lpc17_i2c_setfrequency,
|
||||
.setaddress = lpc17_i2c_setaddress,
|
||||
.write = lpc17_i2c_write,
|
||||
.read = lpc17_i2c_read,
|
||||
.transfer = lpc17_i2c_transfer
|
||||
};
|
||||
|
||||
@@ -225,74 +219,6 @@ static int lpc17_i2c_setaddress(FAR struct i2c_master_s *dev, int addr,
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lpc17_i2c_write
|
||||
*
|
||||
* Description:
|
||||
* Send a block of data on I2C using the previously selected I2C
|
||||
* frequency and slave address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int lpc17_i2c_write(FAR struct i2c_master_s *dev, const uint8_t *buffer,
|
||||
int buflen)
|
||||
{
|
||||
struct lpc17_i2cdev_s *priv = (struct lpc17_i2cdev_s *)dev;
|
||||
int ret = 0;
|
||||
|
||||
DEBUGASSERT(dev != NULL);
|
||||
|
||||
priv->wrcnt = 0;
|
||||
priv->rdcnt = 0;
|
||||
priv->msg.flags = 0;
|
||||
priv->msg.buffer = (uint8_t *)buffer;
|
||||
priv->msg.length = buflen;
|
||||
|
||||
priv->nmsg = 1;
|
||||
priv->msgs = &(priv->msg);
|
||||
|
||||
if (buflen > 0)
|
||||
{
|
||||
ret = lpc17_i2c_start(priv);
|
||||
}
|
||||
|
||||
return (ret == 0 ? 0 : -ETIMEDOUT);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lpc17_i2c_read
|
||||
*
|
||||
* Description:
|
||||
* Receive a block of data on I2C using the previously selected I2C
|
||||
* frequency and slave address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int lpc17_i2c_read(FAR struct i2c_master_s *dev, uint8_t *buffer,
|
||||
int buflen)
|
||||
{
|
||||
struct lpc17_i2cdev_s *priv = (struct lpc17_i2cdev_s *)dev;
|
||||
int ret = 0;
|
||||
|
||||
DEBUGASSERT(dev != NULL);
|
||||
|
||||
priv->wrcnt = 0;
|
||||
priv->rdcnt = 0;
|
||||
priv->msg.flags = I2C_M_READ;
|
||||
priv->msg.buffer = buffer;
|
||||
priv->msg.length = buflen;
|
||||
|
||||
priv->nmsg = 1;
|
||||
priv->msgs = &(priv->msg);
|
||||
|
||||
if (buflen > 0)
|
||||
{
|
||||
ret = lpc17_i2c_start(priv);
|
||||
}
|
||||
|
||||
return (ret == 0 ? 0 : -ETIMEDOUT);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lpc17_i2c_start
|
||||
*
|
||||
|
||||
@@ -141,10 +141,6 @@ static uint32_t lpc2378_i2c_setfrequency(FAR struct i2c_master_s *dev,
|
||||
uint32_t frequency);
|
||||
static int lpc2378_i2c_setaddress(FAR struct i2c_master_s *dev, int addr,
|
||||
int nbits);
|
||||
static int lpc2378_i2c_write(FAR struct i2c_master_s *dev,
|
||||
const uint8_t *buffer, int buflen);
|
||||
static int lpc2378_i2c_read(FAR struct i2c_master_s *dev, uint8_t *buffer,
|
||||
int buflen);
|
||||
static int lpc2378_i2c_transfer(FAR struct i2c_master_s *dev,
|
||||
FAR struct i2c_msg_s *msgs, int count);
|
||||
static void lpc2378_stopnext(struct lpc2378_i2cdev_s *priv);
|
||||
@@ -167,8 +163,6 @@ struct i2c_ops_s lpc2378_i2c_ops =
|
||||
{
|
||||
.setfrequency = lpc2378_i2c_setfrequency,
|
||||
.setaddress = lpc2378_i2c_setaddress,
|
||||
.write = lpc2378_i2c_write,
|
||||
.read = lpc2378_i2c_read,
|
||||
.transfer = lpc2378_i2c_transfer
|
||||
};
|
||||
|
||||
@@ -230,74 +224,6 @@ static int lpc2378_i2c_setaddress(FAR struct i2c_master_s *dev, int addr,
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lpc2378_i2c_write
|
||||
*
|
||||
* Description:
|
||||
* Send a block of data on I2C using the previously selected I2C
|
||||
* frequency and slave address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int lpc2378_i2c_write(FAR struct i2c_master_s *dev, const uint8_t *buffer,
|
||||
int buflen)
|
||||
{
|
||||
struct lpc2378_i2cdev_s *priv = (struct lpc2378_i2cdev_s *)dev;
|
||||
int ret = 0;
|
||||
|
||||
DEBUGASSERT(dev != NULL);
|
||||
|
||||
priv->wrcnt = 0;
|
||||
priv->rdcnt = 0;
|
||||
priv->msg.flags = 0;
|
||||
priv->msg.buffer = (uint8_t *)buffer;
|
||||
priv->msg.length = buflen;
|
||||
|
||||
priv->nmsg = 1;
|
||||
priv->msgs = &(priv->msg);
|
||||
|
||||
if (buflen > 0)
|
||||
{
|
||||
ret = lpc2378_i2c_start(priv);
|
||||
}
|
||||
|
||||
return (ret == 0 ? 0 : -ETIMEDOUT);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lpc2378_i2c_read
|
||||
*
|
||||
* Description:
|
||||
* Receive a block of data on I2C using the previously selected I2C
|
||||
* frequency and slave address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int lpc2378_i2c_read(FAR struct i2c_master_s *dev, uint8_t *buffer,
|
||||
int buflen)
|
||||
{
|
||||
struct lpc2378_i2cdev_s *priv = (struct lpc2378_i2cdev_s *)dev;
|
||||
int ret = 0;
|
||||
|
||||
DEBUGASSERT(dev != NULL);
|
||||
|
||||
priv->wrcnt = 0;
|
||||
priv->rdcnt = 0;
|
||||
priv->msg.flags = I2C_M_READ;
|
||||
priv->msg.buffer = buffer;
|
||||
priv->msg.length = buflen;
|
||||
|
||||
priv->nmsg = 1;
|
||||
priv->msgs = &(priv->msg);
|
||||
|
||||
if (buflen > 0)
|
||||
{
|
||||
ret = lpc2378_i2c_start(priv);
|
||||
}
|
||||
|
||||
return (ret == 0 ? 0 : -ETIMEDOUT);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lpc2378_i2c_start
|
||||
*
|
||||
|
||||
@@ -125,18 +125,17 @@ static void i2c_reset(struct lpc31_i2cdev_s *priv);
|
||||
* I2C device operations
|
||||
****************************************************************************/
|
||||
|
||||
static uint32_t i2c_setfrequency(FAR struct i2c_master_s *dev, uint32_t frequency);
|
||||
static int i2c_setaddress(FAR struct i2c_master_s *dev, int addr, int nbits);
|
||||
static int i2c_write(FAR struct i2c_master_s *dev, const uint8_t *buffer, int buflen);
|
||||
static int i2c_read(FAR struct i2c_master_s *dev, uint8_t *buffer, int buflen);
|
||||
static int i2c_transfer(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs, int count);
|
||||
static uint32_t i2c_setfrequency(FAR struct i2c_master_s *dev,
|
||||
uint32_t frequency);
|
||||
static int i2c_setaddress(FAR struct i2c_master_s *dev, int addr,
|
||||
int nbits);
|
||||
static int i2c_transfer(FAR struct i2c_master_s *dev,
|
||||
FAR struct i2c_msg_s *msgs, int count);
|
||||
|
||||
struct i2c_ops_s lpc31_i2c_ops =
|
||||
{
|
||||
.setfrequency = i2c_setfrequency,
|
||||
.setaddress = i2c_setaddress,
|
||||
.write = i2c_write,
|
||||
.read = i2c_read,
|
||||
.transfer = i2c_transfer
|
||||
};
|
||||
|
||||
@@ -271,56 +270,6 @@ static int i2c_setaddress(FAR struct i2c_master_s *dev, int addr, int nbits)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lpc31_i2c_write
|
||||
*
|
||||
* Description:
|
||||
* Send a block of data on I2C using the previously selected I2C
|
||||
* frequency and slave address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int i2c_write(FAR struct i2c_master_s *dev, const uint8_t *buffer, int buflen)
|
||||
{
|
||||
struct lpc31_i2cdev_s *priv = (struct lpc31_i2cdev_s *) dev;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(dev != NULL);
|
||||
|
||||
priv->msg.flags &= ~I2C_M_READ;
|
||||
priv->msg.buffer = (uint8_t *)buffer;
|
||||
priv->msg.length = buflen;
|
||||
|
||||
ret = i2c_transfer(dev, &priv->msg, 1);
|
||||
|
||||
return ret == 1 ? OK : -ETIMEDOUT;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lpc31_i2c_read
|
||||
*
|
||||
* Description:
|
||||
* Receive a block of data on I2C using the previously selected I2C
|
||||
* frequency and slave address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int i2c_read(FAR struct i2c_master_s *dev, uint8_t *buffer, int buflen)
|
||||
{
|
||||
struct lpc31_i2cdev_s *priv = (struct lpc31_i2cdev_s *) dev;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(dev != NULL);
|
||||
|
||||
priv->msg.flags |= I2C_M_READ;
|
||||
priv->msg.buffer = buffer;
|
||||
priv->msg.length = buflen;
|
||||
|
||||
ret = i2c_transfer(dev, &priv->msg, 1);
|
||||
|
||||
return ret == 1 ? OK : -ETIMEDOUT;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: i2c_transfer
|
||||
*
|
||||
|
||||
@@ -140,10 +140,6 @@ static uint32_t lpc43_i2c_setfrequency(FAR struct i2c_master_s *dev,
|
||||
uint32_t frequency);
|
||||
static int lpc43_i2c_setaddress(FAR struct i2c_master_s *dev, int addr,
|
||||
int nbits);
|
||||
static int lpc43_i2c_write(FAR struct i2c_master_s *dev,
|
||||
const uint8_t *buffer, int buflen);
|
||||
static int lpc43_i2c_read(FAR struct i2c_master_s *dev, uint8_t *buffer,
|
||||
int buflen);
|
||||
static int lpc43_i2c_transfer(FAR struct i2c_master_s *dev,
|
||||
FAR struct i2c_msg_s *msgs, int count);
|
||||
|
||||
@@ -151,8 +147,6 @@ struct i2c_ops_s lpc43_i2c_ops =
|
||||
{
|
||||
.setfrequency = lpc43_i2c_setfrequency,
|
||||
.setaddress = lpc43_i2c_setaddress,
|
||||
.write = lpc43_i2c_write,
|
||||
.read = lpc43_i2c_read,
|
||||
.transfer = lpc43_i2c_transfer
|
||||
};
|
||||
|
||||
@@ -214,74 +208,6 @@ static int lpc43_i2c_setaddress(FAR struct i2c_master_s *dev, int addr,
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lpc43_i2c_write
|
||||
*
|
||||
* Description:
|
||||
* Send a block of data on I2C using the previously selected I2C
|
||||
* frequency and slave address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int lpc43_i2c_write(FAR struct i2c_master_s *dev, const uint8_t *buffer,
|
||||
int buflen)
|
||||
{
|
||||
struct lpc43_i2cdev_s *priv = (struct lpc43_i2cdev_s *)dev;
|
||||
int ret = 0;
|
||||
|
||||
DEBUGASSERT(dev != NULL);
|
||||
|
||||
priv->wrcnt = 0;
|
||||
priv->rdcnt = 0;
|
||||
priv->msg.flags = 0;
|
||||
priv->msg.buffer = (uint8_t *)buffer;
|
||||
priv->msg.length = buflen;
|
||||
|
||||
priv->nmsg = 1;
|
||||
priv->msgs = &(priv->msg);
|
||||
|
||||
if (buflen > 0)
|
||||
{
|
||||
ret = lpc43_i2c_start(priv);
|
||||
}
|
||||
|
||||
return (ret == 0 ? 0 : -ETIMEDOUT);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lpc43_i2c_read
|
||||
*
|
||||
* Description:
|
||||
* Receive a block of data on I2C using the previously selected I2C
|
||||
* frequency and slave address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int lpc43_i2c_read(FAR struct i2c_master_s *dev, uint8_t *buffer,
|
||||
int buflen)
|
||||
{
|
||||
struct lpc43_i2cdev_s *priv = (struct lpc43_i2cdev_s *)dev;
|
||||
int ret = 0;
|
||||
|
||||
DEBUGASSERT(dev != NULL);
|
||||
|
||||
priv->wrcnt = 0;
|
||||
priv->rdcnt = 0;
|
||||
priv->msg.flags = I2C_M_READ;
|
||||
priv->msg.buffer = buffer;
|
||||
priv->msg.length = buflen;
|
||||
|
||||
priv->nmsg = 1;
|
||||
priv->msgs = &(priv->msg);
|
||||
|
||||
if (buflen > 0)
|
||||
{
|
||||
ret = lpc43_i2c_start(priv);
|
||||
}
|
||||
|
||||
return (ret == 0 ? 0 : -ETIMEDOUT);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lpc43_i2c_start
|
||||
*
|
||||
|
||||
@@ -192,9 +192,6 @@ static void twi_startmessage(struct twi_dev_s *priv, struct i2c_msg_s *msg);
|
||||
static uint32_t twi_setfrequency(FAR struct i2c_master_s *dev,
|
||||
uint32_t frequency);
|
||||
static int twi_setaddress(FAR struct i2c_master_s *dev, int addr, int nbits);
|
||||
static int twi_write(FAR struct i2c_master_s *dev, const uint8_t *buffer,
|
||||
int buflen);
|
||||
static int twi_read(FAR struct i2c_master_s *dev, uint8_t *buffer, int buflen);
|
||||
static int twi_transfer(FAR struct i2c_master_s *dev,
|
||||
FAR struct i2c_msg_s *msgs, int count);
|
||||
|
||||
@@ -221,8 +218,6 @@ struct i2c_ops_s g_twiops =
|
||||
{
|
||||
.setfrequency = twi_setfrequency,
|
||||
.setaddress = twi_setaddress,
|
||||
.write = twi_write,
|
||||
.read = twi_read,
|
||||
.transfer = twi_transfer
|
||||
};
|
||||
|
||||
@@ -752,138 +747,6 @@ static int twi_setaddress(FAR struct i2c_master_s *dev, int addr, int nbits)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: twi_write
|
||||
*
|
||||
* Description:
|
||||
* Send a block of data on I2C using the previously selected I2C
|
||||
* frequency and slave address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int twi_write(FAR struct i2c_master_s *dev, const uint8_t *wbuffer, int wbuflen)
|
||||
{
|
||||
struct twi_dev_s *priv = (struct twi_dev_s *) dev;
|
||||
irqstate_t flags;
|
||||
int ret;
|
||||
|
||||
struct i2c_msg_s msg =
|
||||
{
|
||||
.addr = priv->address,
|
||||
.flags = priv->flags,
|
||||
.buffer = (uint8_t *)wbuffer, /* Override const */
|
||||
.length = wbuflen
|
||||
};
|
||||
|
||||
i2cvdbg("TWI%d buflen: %d\n", priv->twi, wbuflen);
|
||||
DEBUGASSERT(dev != NULL);
|
||||
|
||||
/* Get exclusive access to the device */
|
||||
|
||||
twi_takesem(&priv->exclsem);
|
||||
|
||||
/* Initiate the wrte */
|
||||
|
||||
priv->msg = &msg;
|
||||
priv->msgc = 1;
|
||||
|
||||
/* Initiate the write operation. The rest will be handled from interrupt
|
||||
* logic. Interrupts must be disabled to prevent re-entrance from the
|
||||
* interrupt level.
|
||||
*/
|
||||
|
||||
flags = irqsave();
|
||||
twi_startwrite(priv, &msg);
|
||||
|
||||
/* And wait for the write to complete. Interrupts will be re-enabled while
|
||||
* we are waiting.
|
||||
*/
|
||||
|
||||
ret = twi_wait(priv);
|
||||
if (ret < 0)
|
||||
{
|
||||
i2cdbg("ERROR: Transfer failed: %d\n", ret);
|
||||
}
|
||||
|
||||
if (ret == -ETIMEDOUT)
|
||||
{
|
||||
/* Reinitialize the TWI hardware */
|
||||
|
||||
i2clldbg("Reinitialize after write\n");
|
||||
twi_hw_initialize(priv, priv->pid, priv->deffreq);
|
||||
}
|
||||
|
||||
irqrestore(flags);
|
||||
twi_givesem(&priv->exclsem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: twi_read
|
||||
*
|
||||
* Description:
|
||||
* Receive a block of data on I2C using the previously selected I2C
|
||||
* frequency and slave address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int twi_read(FAR struct i2c_master_s *dev, uint8_t *rbuffer, int rbuflen)
|
||||
{
|
||||
struct twi_dev_s *priv = (struct twi_dev_s *)dev;
|
||||
irqstate_t flags;
|
||||
int ret;
|
||||
|
||||
struct i2c_msg_s msg =
|
||||
{
|
||||
.addr = priv->address,
|
||||
.flags = priv->flags | I2C_M_READ,
|
||||
.buffer = rbuffer,
|
||||
.length = rbuflen
|
||||
};
|
||||
|
||||
DEBUGASSERT(dev != NULL);
|
||||
i2cvdbg("TWI%d rbuflen: %d\n", priv->twi, rbuflen);
|
||||
|
||||
/* Get exclusive access to the device */
|
||||
|
||||
twi_takesem(&priv->exclsem);
|
||||
|
||||
/* Initiate the read */
|
||||
|
||||
priv->msg = &msg;
|
||||
priv->msgc = 1;
|
||||
|
||||
/* Initiate the read operation. The rest will be handled from interrupt
|
||||
* logic. Interrupts must be disabled to prevent re-entrance from the
|
||||
* interrupt level.
|
||||
*/
|
||||
|
||||
flags = irqsave();
|
||||
twi_startread(priv, &msg);
|
||||
|
||||
/* And wait for the read to complete. Interrupts will be re-enabled while
|
||||
* we are waiting.
|
||||
*/
|
||||
|
||||
ret = twi_wait(priv);
|
||||
if (ret < 0)
|
||||
{
|
||||
i2cdbg("ERROR: Transfer failed: %d\n", ret);
|
||||
}
|
||||
|
||||
if (ret == -ETIMEDOUT)
|
||||
{
|
||||
/* Reinitialize the TWI hardware */
|
||||
|
||||
i2clldbg("Reinitialize after read\n");
|
||||
twi_hw_initialize(priv, priv->pid, priv->deffreq);
|
||||
}
|
||||
|
||||
irqrestore(flags);
|
||||
twi_givesem(&priv->exclsem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: twi_transfer
|
||||
*
|
||||
|
||||
@@ -239,9 +239,6 @@ static void twi_startmessage(struct twi_dev_s *priv, struct i2c_msg_s *msg);
|
||||
static uint32_t twi_setfrequency(FAR struct i2c_master_s *dev,
|
||||
uint32_t frequency);
|
||||
static int twi_setaddress(FAR struct i2c_master_s *dev, int addr, int nbits);
|
||||
static int twi_write(FAR struct i2c_master_s *dev, const uint8_t *buffer,
|
||||
int buflen);
|
||||
static int twi_read(FAR struct i2c_master_s *dev, uint8_t *buffer, int buflen);
|
||||
static int twi_transfer(FAR struct i2c_master_s *dev,
|
||||
FAR struct i2c_msg_s *msgs, int count);
|
||||
|
||||
@@ -319,8 +316,6 @@ struct i2c_ops_s g_twiops =
|
||||
{
|
||||
.setfrequency = twi_setfrequency,
|
||||
.setaddress = twi_setaddress,
|
||||
.write = twi_write,
|
||||
.read = twi_read,
|
||||
.transfer = twi_transfer
|
||||
};
|
||||
|
||||
@@ -882,122 +877,6 @@ static int twi_setaddress(FAR struct i2c_master_s *dev, int addr, int nbits)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: twi_write
|
||||
*
|
||||
* Description:
|
||||
* Send a block of data on I2C using the previously selected I2C
|
||||
* frequency and slave address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int twi_write(FAR struct i2c_master_s *dev, const uint8_t *wbuffer, int wbuflen)
|
||||
{
|
||||
struct twi_dev_s *priv = (struct twi_dev_s *) dev;
|
||||
irqstate_t flags;
|
||||
int ret;
|
||||
|
||||
struct i2c_msg_s msg =
|
||||
{
|
||||
.addr = priv->address,
|
||||
.flags = priv->flags,
|
||||
.buffer = (uint8_t *)wbuffer, /* Override const */
|
||||
.length = wbuflen
|
||||
};
|
||||
|
||||
i2cvdbg("TWI%d buflen: %d\n", priv->attr->twi, wbuflen);
|
||||
DEBUGASSERT(dev != NULL);
|
||||
|
||||
/* Get exclusive access to the device */
|
||||
|
||||
twi_takesem(&priv->exclsem);
|
||||
|
||||
/* Initiate the write */
|
||||
|
||||
priv->msg = &msg;
|
||||
priv->msgc = 1;
|
||||
|
||||
/* Initiate the write operation. The rest will be handled from interrupt
|
||||
* logic. Interrupts must be disabled to prevent re-entrance from the
|
||||
* interrupt level.
|
||||
*/
|
||||
|
||||
flags = irqsave();
|
||||
twi_startwrite(priv, &msg);
|
||||
|
||||
/* And wait for the write to complete. Interrupts will be re-enabled while
|
||||
* we are waiting.
|
||||
*/
|
||||
|
||||
ret = twi_wait(priv, wbuflen);
|
||||
if (ret < 0)
|
||||
{
|
||||
i2cdbg("ERROR: Transfer failed: %d\n", ret);
|
||||
}
|
||||
|
||||
irqrestore(flags);
|
||||
twi_givesem(&priv->exclsem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: twi_read
|
||||
*
|
||||
* Description:
|
||||
* Receive a block of data on I2C using the previously selected I2C
|
||||
* frequency and slave address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int twi_read(FAR struct i2c_master_s *dev, uint8_t *rbuffer, int rbuflen)
|
||||
{
|
||||
struct twi_dev_s *priv = (struct twi_dev_s *)dev;
|
||||
irqstate_t flags;
|
||||
int ret;
|
||||
|
||||
struct i2c_msg_s msg =
|
||||
{
|
||||
.addr = priv->address,
|
||||
.flags = priv->flags | I2C_M_READ,
|
||||
.buffer = rbuffer,
|
||||
.length = rbuflen
|
||||
};
|
||||
|
||||
DEBUGASSERT(dev != NULL);
|
||||
i2cvdbg("TWI%d rbuflen: %d\n", priv->attr->twi, rbuflen);
|
||||
|
||||
/* Get exclusive access to the device */
|
||||
|
||||
twi_takesem(&priv->exclsem);
|
||||
|
||||
/* Initiate the read */
|
||||
|
||||
priv->msg = &msg;
|
||||
priv->msgc = 1;
|
||||
|
||||
/* Initiate the read operation. The rest will be handled from interrupt
|
||||
* logic. Interrupts must be disabled to prevent re-entrance from the
|
||||
* interrupt level.
|
||||
*/
|
||||
|
||||
flags = irqsave();
|
||||
twi_startread(priv, &msg);
|
||||
|
||||
/* And wait for the read to complete. Interrupts will be re-enabled while
|
||||
* we are waiting.
|
||||
*/
|
||||
|
||||
ret = twi_wait(priv, rbuflen);
|
||||
if (ret < 0)
|
||||
{
|
||||
i2cdbg("ERROR: Transfer failed: %d\n", ret);
|
||||
}
|
||||
|
||||
irqrestore(flags);
|
||||
twi_givesem(&priv->exclsem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: twi_transfer
|
||||
*
|
||||
|
||||
@@ -234,9 +234,6 @@ static void twi_startmessage(struct twi_dev_s *priv, struct i2c_msg_s *msg);
|
||||
static uint32_t twi_setfrequency(FAR struct i2c_master_s *dev,
|
||||
uint32_t frequency);
|
||||
static int twi_setaddress(FAR struct i2c_master_s *dev, int addr, int nbits);
|
||||
static int twi_write(FAR struct i2c_master_s *dev, const uint8_t *buffer,
|
||||
int buflen);
|
||||
static int twi_read(FAR struct i2c_master_s *dev, uint8_t *buffer, int buflen);
|
||||
static int twi_transfer(FAR struct i2c_master_s *dev,
|
||||
FAR struct i2c_msg_s *msgs, int count);
|
||||
|
||||
@@ -299,8 +296,6 @@ struct i2c_ops_s g_twiops =
|
||||
{
|
||||
.setfrequency = twi_setfrequency,
|
||||
.setaddress = twi_setaddress,
|
||||
.write = twi_write,
|
||||
.read = twi_read,
|
||||
.transfer = twi_transfer
|
||||
};
|
||||
|
||||
@@ -909,122 +904,6 @@ static int twi_setaddress(FAR struct i2c_master_s *dev, int addr, int nbits)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: twi_write
|
||||
*
|
||||
* Description:
|
||||
* Send a block of data on I2C using the previously selected I2C
|
||||
* frequency and slave address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int twi_write(FAR struct i2c_master_s *dev, const uint8_t *wbuffer, int wbuflen)
|
||||
{
|
||||
struct twi_dev_s *priv = (struct twi_dev_s *) dev;
|
||||
irqstate_t flags;
|
||||
int ret;
|
||||
|
||||
struct i2c_msg_s msg =
|
||||
{
|
||||
.addr = priv->address,
|
||||
.flags = priv->flags,
|
||||
.buffer = (uint8_t *)wbuffer, /* Override const */
|
||||
.length = wbuflen
|
||||
};
|
||||
|
||||
i2cvdbg("TWIHS%d buflen: %d\n", priv->attr->twi, wbuflen);
|
||||
DEBUGASSERT(dev != NULL);
|
||||
|
||||
/* Get exclusive access to the device */
|
||||
|
||||
twi_takesem(&priv->exclsem);
|
||||
|
||||
/* Initiate the write */
|
||||
|
||||
priv->msg = &msg;
|
||||
priv->msgc = 1;
|
||||
|
||||
/* Initiate the write operation. The rest will be handled from interrupt
|
||||
* logic. Interrupts must be disabled to prevent re-entrance from the
|
||||
* interrupt level.
|
||||
*/
|
||||
|
||||
flags = irqsave();
|
||||
twi_startwrite(priv, &msg);
|
||||
|
||||
/* And wait for the write to complete. Interrupts will be re-enabled while
|
||||
* we are waiting.
|
||||
*/
|
||||
|
||||
ret = twi_wait(priv, wbuflen);
|
||||
if (ret < 0)
|
||||
{
|
||||
i2cdbg("ERROR: Transfer failed: %d\n", ret);
|
||||
}
|
||||
|
||||
irqrestore(flags);
|
||||
twi_givesem(&priv->exclsem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: twi_read
|
||||
*
|
||||
* Description:
|
||||
* Receive a block of data on I2C using the previously selected I2C
|
||||
* frequency and slave address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int twi_read(FAR struct i2c_master_s *dev, uint8_t *rbuffer, int rbuflen)
|
||||
{
|
||||
struct twi_dev_s *priv = (struct twi_dev_s *)dev;
|
||||
irqstate_t flags;
|
||||
int ret;
|
||||
|
||||
struct i2c_msg_s msg =
|
||||
{
|
||||
.addr = priv->address,
|
||||
.flags = priv->flags | I2C_M_READ,
|
||||
.buffer = rbuffer,
|
||||
.length = rbuflen
|
||||
};
|
||||
|
||||
DEBUGASSERT(dev != NULL);
|
||||
i2cvdbg("TWIHS%d rbuflen: %d\n", priv->attr->twi, rbuflen);
|
||||
|
||||
/* Get exclusive access to the device */
|
||||
|
||||
twi_takesem(&priv->exclsem);
|
||||
|
||||
/* Initiate the read */
|
||||
|
||||
priv->msg = &msg;
|
||||
priv->msgc = 1;
|
||||
|
||||
/* Initiate the read operation. The rest will be handled from interrupt
|
||||
* logic. Interrupts must be disabled to prevent re-entrance from the
|
||||
* interrupt level.
|
||||
*/
|
||||
|
||||
flags = irqsave();
|
||||
twi_startread(priv, &msg);
|
||||
|
||||
/* And wait for the read to complete. Interrupts will be re-enabled while
|
||||
* we are waiting.
|
||||
*/
|
||||
|
||||
ret = twi_wait(priv, rbuflen);
|
||||
if (ret < 0)
|
||||
{
|
||||
i2cdbg("ERROR: Transfer failed: %d\n", ret);
|
||||
}
|
||||
|
||||
irqrestore(flags);
|
||||
twi_givesem(&priv->exclsem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: twi_transfer
|
||||
*
|
||||
|
||||
@@ -353,9 +353,6 @@ static uint32_t stm32_i2c_setfrequency(FAR struct i2c_master_s *dev,
|
||||
static int stm32_i2c_setaddress(FAR struct i2c_master_s *dev, int addr, int nbits);
|
||||
static int stm32_i2c_process(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs,
|
||||
int count);
|
||||
static int stm32_i2c_write(FAR struct i2c_master_s *dev, const uint8_t *buffer,
|
||||
int buflen);
|
||||
static int stm32_i2c_read(FAR struct i2c_master_s *dev, uint8_t *buffer, int buflen);
|
||||
static int stm32_i2c_transfer(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs,
|
||||
int count);
|
||||
|
||||
@@ -477,8 +474,6 @@ static const struct i2c_ops_s stm32_i2c_ops =
|
||||
{
|
||||
.setfrequency = stm32_i2c_setfrequency,
|
||||
.setaddress = stm32_i2c_setaddress,
|
||||
.write = stm32_i2c_write,
|
||||
.read = stm32_i2c_read,
|
||||
.transfer = stm32_i2c_transfer
|
||||
};
|
||||
|
||||
@@ -1849,52 +1844,6 @@ static int stm32_i2c_process(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s
|
||||
return -errval;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_i2c_write
|
||||
*
|
||||
* Description:
|
||||
* Write I2C data
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
static int stm32_i2c_write(FAR struct i2c_master_s *dev, const uint8_t *buffer, int buflen)
|
||||
{
|
||||
stm32_i2c_sem_wait(dev); /* ensure that address or flags don't change meanwhile */
|
||||
|
||||
struct i2c_msg_s msgv =
|
||||
{
|
||||
.addr = ((struct stm32_i2c_inst_s *)dev)->address,
|
||||
.flags = ((struct stm32_i2c_inst_s *)dev)->flags,
|
||||
.buffer = (uint8_t *)buffer,
|
||||
.length = buflen
|
||||
};
|
||||
|
||||
return stm32_i2c_process(dev, &msgv, 1);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_i2c_read
|
||||
*
|
||||
* Description:
|
||||
* Read I2C data
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
int stm32_i2c_read(FAR struct i2c_master_s *dev, uint8_t *buffer, int buflen)
|
||||
{
|
||||
stm32_i2c_sem_wait(dev); /* ensure that address or flags don't change meanwhile */
|
||||
|
||||
struct i2c_msg_s msgv =
|
||||
{
|
||||
.addr = ((struct stm32_i2c_inst_s *)dev)->address,
|
||||
.flags = ((struct stm32_i2c_inst_s *)dev)->flags | I2C_M_READ,
|
||||
.buffer = buffer,
|
||||
.length = buflen
|
||||
};
|
||||
|
||||
return stm32_i2c_process(dev, &msgv, 1);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_i2c_transfer
|
||||
*
|
||||
|
||||
@@ -382,9 +382,6 @@ static uint32_t stm32_i2c_setfrequency(FAR struct i2c_master_s *dev,
|
||||
static int stm32_i2c_setaddress(FAR struct i2c_master_s *dev, int addr, int nbits);
|
||||
static int stm32_i2c_process(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs,
|
||||
int count);
|
||||
static int stm32_i2c_write(FAR struct i2c_master_s *dev, const uint8_t *buffer,
|
||||
int buflen);
|
||||
static int stm32_i2c_read(FAR struct i2c_master_s *dev, uint8_t *buffer, int buflen);
|
||||
static int stm32_i2c_transfer(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs,
|
||||
int count);
|
||||
|
||||
@@ -485,8 +482,6 @@ static const struct i2c_ops_s stm32_i2c_ops =
|
||||
{
|
||||
.setfrequency = stm32_i2c_setfrequency,
|
||||
.setaddress = stm32_i2c_setaddress,
|
||||
.write = stm32_i2c_write,
|
||||
.read = stm32_i2c_read,
|
||||
.transfer = stm32_i2c_transfer
|
||||
};
|
||||
|
||||
@@ -2293,52 +2288,6 @@ static int stm32_i2c_process(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s
|
||||
return -errval;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_i2c_write
|
||||
*
|
||||
* Description:
|
||||
* Write I2C data
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
static int stm32_i2c_write(FAR struct i2c_master_s *dev, const uint8_t *buffer, int buflen)
|
||||
{
|
||||
stm32_i2c_sem_wait(dev); /* ensure that address or flags don't change meanwhile */
|
||||
|
||||
struct i2c_msg_s msgv =
|
||||
{
|
||||
.addr = ((struct stm32_i2c_inst_s *)dev)->address,
|
||||
.flags = ((struct stm32_i2c_inst_s *)dev)->flags,
|
||||
.buffer = (uint8_t *)buffer,
|
||||
.length = buflen
|
||||
};
|
||||
|
||||
return stm32_i2c_process(dev, &msgv, 1);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_i2c_read
|
||||
*
|
||||
* Description:
|
||||
* Read I2C data
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
int stm32_i2c_read(FAR struct i2c_master_s *dev, uint8_t *buffer, int buflen)
|
||||
{
|
||||
stm32_i2c_sem_wait(dev); /* ensure that address or flags don't change meanwhile */
|
||||
|
||||
struct i2c_msg_s msgv =
|
||||
{
|
||||
.addr = ((struct stm32_i2c_inst_s *)dev)->address,
|
||||
.flags = ((struct stm32_i2c_inst_s *)dev)->flags | I2C_M_READ,
|
||||
.buffer = buffer,
|
||||
.length = buflen
|
||||
};
|
||||
|
||||
return stm32_i2c_process(dev, &msgv, 1);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_i2c_transfer
|
||||
*
|
||||
|
||||
@@ -339,9 +339,6 @@ static uint32_t stm32_i2c_setfrequency(FAR struct i2c_master_s *dev,
|
||||
static int stm32_i2c_setaddress(FAR struct i2c_master_s *dev, int addr, int nbits);
|
||||
static int stm32_i2c_process(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs,
|
||||
int count);
|
||||
static int stm32_i2c_write(FAR struct i2c_master_s *dev, const uint8_t *buffer,
|
||||
int buflen);
|
||||
static int stm32_i2c_read(FAR struct i2c_master_s *dev, uint8_t *buffer, int buflen);
|
||||
static int stm32_i2c_transfer(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s *msgs,
|
||||
int count);
|
||||
|
||||
@@ -442,8 +439,6 @@ struct i2c_ops_s stm32_i2c_ops =
|
||||
{
|
||||
.setfrequency = stm32_i2c_setfrequency,
|
||||
.setaddress = stm32_i2c_setaddress,
|
||||
.write = stm32_i2c_write,
|
||||
.read = stm32_i2c_read,
|
||||
.transfer = stm32_i2c_transfer
|
||||
};
|
||||
|
||||
@@ -1850,52 +1845,6 @@ static int stm32_i2c_process(FAR struct i2c_master_s *dev, FAR struct i2c_msg_s
|
||||
return -errval;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_i2c_write
|
||||
*
|
||||
* Description:
|
||||
* Write I2C data
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
static int stm32_i2c_write(FAR struct i2c_master_s *dev, const uint8_t *buffer, int buflen)
|
||||
{
|
||||
stm32_i2c_sem_wait(dev); /* ensure that address or flags don't change meanwhile */
|
||||
|
||||
struct i2c_msg_s msgv =
|
||||
{
|
||||
.addr = ((struct stm32_i2c_inst_s *)dev)->address,
|
||||
.flags = ((struct stm32_i2c_inst_s *)dev)->flags,
|
||||
.buffer = (uint8_t *)buffer,
|
||||
.length = buflen
|
||||
};
|
||||
|
||||
return stm32_i2c_process(dev, &msgv, 1);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_i2c_read
|
||||
*
|
||||
* Description:
|
||||
* Read I2C data
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
int stm32_i2c_read(FAR struct i2c_master_s *dev, uint8_t *buffer, int buflen)
|
||||
{
|
||||
stm32_i2c_sem_wait(dev); /* ensure that address or flags don't change meanwhile */
|
||||
|
||||
struct i2c_msg_s msgv =
|
||||
{
|
||||
.addr = ((struct stm32_i2c_inst_s *)dev)->address,
|
||||
.flags = ((struct stm32_i2c_inst_s *)dev)->flags | I2C_M_READ,
|
||||
.buffer = buffer,
|
||||
.length = buflen
|
||||
};
|
||||
|
||||
return stm32_i2c_process(dev, &msgv, 1);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_i2c_transfer
|
||||
*
|
||||
|
||||
@@ -345,9 +345,6 @@ static uint32_t tiva_i2c_setfrequency(struct i2c_master_s *dev,
|
||||
static int tiva_i2c_setaddress(struct i2c_master_s *dev, int addr, int nbits);
|
||||
static int tiva_i2c_process(struct i2c_master_s *dev, struct i2c_msg_s *msgv,
|
||||
int msgc);
|
||||
static int tiva_i2c_write(struct i2c_master_s *dev, const uint8_t *buffer,
|
||||
int buflen);
|
||||
static int tiva_i2c_read(struct i2c_master_s *dev, uint8_t *buffer, int buflen);
|
||||
static int tiva_i2c_transfer(struct i2c_master_s *dev, struct i2c_msg_s *msgv,
|
||||
int msgc);
|
||||
|
||||
@@ -581,8 +578,6 @@ static const struct i2c_ops_s tiva_i2c_ops =
|
||||
{
|
||||
.setfrequency = tiva_i2c_setfrequency,
|
||||
.setaddress = tiva_i2c_setaddress,
|
||||
.write = tiva_i2c_write,
|
||||
.read = tiva_i2c_read,
|
||||
.transfer = tiva_i2c_transfer
|
||||
};
|
||||
|
||||
@@ -2071,58 +2066,6 @@ static int tiva_i2c_process(struct i2c_master_s *dev, struct i2c_msg_s *msgv, in
|
||||
return -errcode;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: tiva_i2c_write
|
||||
*
|
||||
* Description:
|
||||
* Write I2C data
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
static int tiva_i2c_write(struct i2c_master_s *dev, const uint8_t *buffer, int buflen)
|
||||
{
|
||||
struct tiva_i2c_inst_s *inst = (struct tiva_i2c_inst_s *)dev;
|
||||
struct i2c_msg_s msgv =
|
||||
{
|
||||
.addr = inst->address,
|
||||
.flags = inst->flags,
|
||||
.buffer = (uint8_t *)buffer,
|
||||
.length = buflen
|
||||
};
|
||||
|
||||
DEBUGASSERT(inst && inst->priv && inst->priv->config);
|
||||
i2cvdbg("I2C%d: buflen=%d\n", inst->priv->config->devno, buflen);
|
||||
|
||||
tiva_i2c_sem_wait(dev); /* ensure that address or flags don't change meanwhile */
|
||||
return tiva_i2c_process(dev, &msgv, 1);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: tiva_i2c_read
|
||||
*
|
||||
* Description:
|
||||
* Read I2C data
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
int tiva_i2c_read(struct i2c_master_s *dev, uint8_t *buffer, int buflen)
|
||||
{
|
||||
struct tiva_i2c_inst_s *inst = (struct tiva_i2c_inst_s *)dev;
|
||||
struct i2c_msg_s msgv =
|
||||
{
|
||||
.addr = inst->address,
|
||||
.flags = inst->flags | I2C_M_READ,
|
||||
.buffer = buffer,
|
||||
.length = buflen
|
||||
};
|
||||
|
||||
DEBUGASSERT(inst && inst->priv && inst->priv->config);
|
||||
i2cvdbg("I2C%d: buflen=%d\n", inst->priv->config->devno, buflen);
|
||||
|
||||
tiva_i2c_sem_wait(dev); /* ensure that address or flags don't change meanwhile */
|
||||
return tiva_i2c_process(dev, &msgv, 1);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: tiva_i2c_transfer
|
||||
*
|
||||
|
||||
@@ -100,10 +100,6 @@ static uint32_t ez80_i2c_setfrequency(FAR struct i2c_master_s *dev,
|
||||
uint32_t frequency);
|
||||
static int ez80_i2c_setaddress(FAR struct i2c_master_s *dev,
|
||||
int addr, int nbits);
|
||||
static int ez80_i2c_write(FAR struct i2c_master_s *dev,
|
||||
FAR const uint8_t *buffer, int buflen);
|
||||
static int ez80_i2c_read(FAR struct i2c_master_s *dev,
|
||||
FAR uint8_t *buffer, int buflen);
|
||||
static int ez80_i2c_transfer(FAR struct i2c_master_s *dev,
|
||||
FAR struct i2c_msg_s *msgs, int count);
|
||||
|
||||
@@ -127,8 +123,6 @@ const struct i2c_ops_s g_ops =
|
||||
{
|
||||
ez80_i2c_setfrequency,
|
||||
ez80_i2c_setaddress,
|
||||
ez80_i2c_write,
|
||||
ez80_i2c_read,
|
||||
ez80_i2c_transfer
|
||||
};
|
||||
|
||||
@@ -856,92 +850,6 @@ static int ez80_i2c_setaddress(FAR struct i2c_master_s *dev, int addr,
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ez80_i2c_write
|
||||
*
|
||||
* Description:
|
||||
* Send a block of data on I2C using the previously selected I2C
|
||||
* frequency and slave address. Each write operational will be an 'atomic'
|
||||
* operation in the sense that any other I2C actions will be serialized
|
||||
* and pend until this write completes. Required.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* buffer - A pointer to the read-only buffer of data to be written to device
|
||||
* buflen - The number of bytes to send from the buffer
|
||||
*
|
||||
* Returned Value:
|
||||
* 0: success, <0: A negated errno
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int ez80_i2c_write(FAR struct i2c_master_s *dev,
|
||||
FAR const uint8_t *buffer, int buflen)
|
||||
{
|
||||
FAR struct ez80_i2cdev_s *priv = (FAR struct ez80_i2cdev_s *)dev;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(dev != NULL && buffer != NULL && buflen > 0);
|
||||
|
||||
/* Get exclusive access to the I2C bus */
|
||||
|
||||
ez80_i2c_semtake();
|
||||
|
||||
/* Set the frequency */
|
||||
|
||||
ez80_i2c_setccr(priv->ccr);
|
||||
|
||||
/* Perform the transfer */
|
||||
|
||||
ret = ez80_i2c_write_transfer(priv, buffer, buflen, 0);
|
||||
|
||||
ez80_i2c_semgive();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ez80_i2c_read
|
||||
*
|
||||
* Description:
|
||||
* Receive a block of data from I2C using the previously selected I2C
|
||||
* frequency and slave address. Each read operational will be an 'atomic'
|
||||
* operation in the sense that any other I2C actions will be serialized
|
||||
* and pend until this read completes. Required.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* buffer - A pointer to a buffer of data to receive the data from the device
|
||||
* buflen - The requested number of bytes to be read
|
||||
*
|
||||
* Returned Value:
|
||||
* 0: success, <0: A negated errno
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int ez80_i2c_read(FAR struct i2c_master_s *dev, FAR uint8_t *buffer,
|
||||
int buflen)
|
||||
{
|
||||
FAR struct ez80_i2cdev_s *priv = (FAR struct ez80_i2cdev_s *)dev;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(dev != NULL && buffer != NULL && buflen > 0);
|
||||
|
||||
/* Get exclusive access to the I2C bus */
|
||||
|
||||
ez80_i2c_semtake();
|
||||
|
||||
/* Set the frequency */
|
||||
|
||||
ez80_i2c_setccr(priv->ccr);
|
||||
|
||||
/* Perform the transfer */
|
||||
|
||||
ret = ez80_i2c_read_transfer(priv, buffer, buflen, 0);
|
||||
|
||||
ez80_i2c_semgive();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ez80_i2c_transfer
|
||||
*
|
||||
|
||||
+1
-158
@@ -94,10 +94,6 @@ static uint32_t z8_i2c_setfrequency(FAR struct i2c_master_s *dev,
|
||||
uint32_t frequency);
|
||||
static int z8_i2c_setaddress(FAR struct i2c_master_s *dev, int addr,
|
||||
int nbits);
|
||||
static int z8_i2c_write(FAR struct i2c_master_s *dev,
|
||||
FAR const uint8_t *buffer, int buflen);
|
||||
static int z8_i2c_read(FAR struct i2c_master_s *dev,
|
||||
FAR uint8_t *buffer, int buflen);
|
||||
static int z8_i2c_transfer(FAR struct i2c_master_s *dev,
|
||||
FAR struct i2c_msg_s *msgs, int count);
|
||||
|
||||
@@ -121,8 +117,7 @@ const struct i2c_ops_s g_ops =
|
||||
{
|
||||
z8_i2c_setfrequency,
|
||||
z8_i2c_setaddress,
|
||||
z8_i2c_write,
|
||||
z8_i2c_read,
|
||||
z8_i2c_transfer,
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
@@ -542,158 +537,6 @@ static int z8_i2c_setaddress(FAR struct i2c_master_s *dev, int addr,
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: z8_i2c_write
|
||||
*
|
||||
* Description:
|
||||
* Send a block of data on I2C using the previously selected I2C
|
||||
* frequency and slave address. Each write operational will be an 'atomic'
|
||||
* operation in the sense that any other I2C actions will be serialized
|
||||
* and pend until this write completes. Required.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* buffer - A pointer to the read-only buffer of data to be written to device
|
||||
* buflen - The number of bytes to send from the buffer
|
||||
*
|
||||
* Returned Value:
|
||||
* 0: success, <0: A negated errno
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int z8_i2c_write(FAR struct i2c_master_s *dev,
|
||||
FAR const uint8_t *buffer, int buflen)
|
||||
{
|
||||
FAR struct z8_i2cdev_s *priv = (FAR struct z8_i2cdev_s *)dev;
|
||||
const uint8_t *ptr;
|
||||
int retry;
|
||||
int count;
|
||||
|
||||
DEBUGASSERT(dev != NULL && buffer != NULL && buflen > 0);
|
||||
|
||||
/* Get exclusive access */
|
||||
|
||||
z8_i2c_semtake();
|
||||
|
||||
/* Set the frequency */
|
||||
|
||||
z8_i2c_setbrg(priv->brg);
|
||||
|
||||
/* Retry as necessary to send this whole message */
|
||||
|
||||
for (retry = 0; retry < 100; retry++)
|
||||
{
|
||||
/* Load the address into the transmit register. It is not sent
|
||||
* until the START bit is set.
|
||||
*/
|
||||
|
||||
I2CD = I2C_WRITEADDR8(priv->addr);
|
||||
I2CCTL |= I2C_CTL_START;
|
||||
|
||||
/* Wait for the xmt buffer to become empty */
|
||||
|
||||
z8_i2c_waittxempty();
|
||||
|
||||
/* Then send all of the bytes in the buffer */
|
||||
|
||||
ptr = buffer;
|
||||
for (count = buflen; count; count--)
|
||||
{
|
||||
/* Send a byte of data and wait for it to be sent */
|
||||
|
||||
I2CD = *ptr++;
|
||||
z8_i2c_waittxempty();
|
||||
|
||||
/* If this was the last byte, then send STOP immediately. This
|
||||
* is because the ACK will not be valid until the STOP clocks out
|
||||
* the last bit.. Hmmm. If this true then we will never be
|
||||
* able to send more than one data byte???
|
||||
*/
|
||||
|
||||
if (count == 1)
|
||||
{
|
||||
I2CCTL |= I2C_CTL_STOP;
|
||||
|
||||
/* If this last byte was ACKed, then the whole buffer
|
||||
* was successfully sent and we can return success.
|
||||
*/
|
||||
|
||||
if ((I2CSTAT & I2C_STAT_ACK) != 0)
|
||||
{
|
||||
z8_i2c_semgive();
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* If was was not ACKed, then this inner loop will
|
||||
* terminated (because count will decrement to zero
|
||||
* and the whole message will be resent
|
||||
*/
|
||||
}
|
||||
|
||||
/* Not the last byte... was this byte ACKed? */
|
||||
|
||||
else if ((I2CSTAT & I2C_STAT_ACK) == 0)
|
||||
{
|
||||
/* No, flush the buffer and toggle the I2C on and off */
|
||||
|
||||
I2CCTL |= I2C_CTL_FLUSH;
|
||||
I2CCTL &= ~I2C_CTL_IEN;
|
||||
I2CCTL |= I2C_CTL_IEN;
|
||||
|
||||
/* Break out of the loop early and try again */
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
z8_i2c_semgive();
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: z8_i2c_read
|
||||
*
|
||||
* Description:
|
||||
* Receive a block of data from I2C using the previously selected I2C
|
||||
* frequency and slave address. Each read operational will be an 'atomic'
|
||||
* operation in the sense that any other I2C actions will be serialized
|
||||
* and pend until this read completes. Required.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* buffer - A pointer to a buffer of data to receive the data from the device
|
||||
* buflen - The requested number of bytes to be read
|
||||
*
|
||||
* Returned Value:
|
||||
* 0: success, <0: A negated errno
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int z8_i2c_read(FAR struct i2c_master_s *dev, FAR uint8_t *buffer,
|
||||
int buflen)
|
||||
{
|
||||
FAR struct z8_i2cdev_s *priv = (FAR struct z8_i2cdev_s *)dev;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(dev != NULL && buffer != NULL && buflen > 0);
|
||||
|
||||
/* Get exclusive access */
|
||||
|
||||
z8_i2c_semtake();
|
||||
|
||||
/* Set the frequency */
|
||||
|
||||
z8_i2c_setbrg(priv->brg);
|
||||
|
||||
/* Perform the transfer */
|
||||
|
||||
ret = z8_i2c_read_transfer(priv, buffer, buflen, 0);
|
||||
|
||||
z8_i2c_semgive();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: z8_i2c_transfer
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user