Adapt i2c slave callback interface for rp2040 and s32k11x
Signed-off-by: Shoukui Zhang <zhangshoukui@xiaomi.com>
This commit is contained in:
parent
4e6f3e9360
commit
f94160095e
@ -152,6 +152,7 @@ static int i2c_interrupt(int irq, void *context, void *arg)
|
||||
rp2040_i2c_slave_t *priv = (rp2040_i2c_slave_t *)arg;
|
||||
uint32_t data_cmd;
|
||||
uint32_t state;
|
||||
int length;
|
||||
|
||||
state = getreg32(RP2040_I2C_IC_INTR_STAT(priv->controller));
|
||||
|
||||
@ -159,7 +160,8 @@ static int i2c_interrupt(int irq, void *context, void *arg)
|
||||
|
||||
if (state & RP2040_I2C_IC_INTR_STAT_R_RD_REQ)
|
||||
{
|
||||
if (priv->tx_buf_ptr < priv->tx_buf_end)
|
||||
length = priv->tx_buf_end - priv->tx_buf_ptr;
|
||||
if (length > 0)
|
||||
{
|
||||
while (priv->tx_buf_ptr < priv->tx_buf_end
|
||||
&& getreg32(RP2040_I2C_IC_TXFLR(priv->controller))
|
||||
@ -168,6 +170,11 @@ static int i2c_interrupt(int irq, void *context, void *arg)
|
||||
putreg32(*priv->tx_buf_ptr++,
|
||||
RP2040_I2C_IC_DATA_CMD(priv->controller));
|
||||
}
|
||||
|
||||
if (priv->callback != NULL)
|
||||
{
|
||||
priv->callback(priv, I2CS_TX_COMPLETE, length);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -203,7 +210,8 @@ static int i2c_interrupt(int irq, void *context, void *arg)
|
||||
{
|
||||
if (priv->callback != NULL && priv->rx_buf_ptr > priv->rx_buffer)
|
||||
{
|
||||
priv->callback(priv, priv->rx_buf_ptr - priv->rx_buffer);
|
||||
priv->callback(priv, I2CS_RX_COMPLETE,
|
||||
priv->rx_buf_ptr - priv->rx_buffer);
|
||||
priv->rx_buf_ptr = priv->rx_buffer;
|
||||
}
|
||||
|
||||
@ -216,7 +224,8 @@ static int i2c_interrupt(int irq, void *context, void *arg)
|
||||
{
|
||||
if (priv->callback != NULL && priv->rx_buf_ptr > priv->rx_buffer)
|
||||
{
|
||||
priv->callback(priv, priv->rx_buf_ptr - priv->rx_buffer);
|
||||
priv->callback(priv, I2CS_RX_COMPLETE,
|
||||
priv->rx_buf_ptr - priv->rx_buffer);
|
||||
priv->rx_buf_ptr = priv->rx_buffer;
|
||||
}
|
||||
|
||||
|
@ -427,9 +427,19 @@ static int s32k1xx_lpi2c_slave_isr_process(
|
||||
|
||||
if ((priv->read_bufindex > 0) && (priv->callback != NULL))
|
||||
{
|
||||
priv->callback(priv->callback_arg, priv->read_bufindex);
|
||||
priv->callback(priv->callback_arg, I2CS_RX_COMPLETE,
|
||||
priv->read_bufindex);
|
||||
priv->read_bufindex = 0;
|
||||
}
|
||||
|
||||
/* Execute the registered callback function if data was send */
|
||||
|
||||
if ((priv->write_bufindex > 0) && (priv->callback != NULL))
|
||||
{
|
||||
priv->callback(priv->callback_arg, I2CS_TX_COMPLETE,
|
||||
priv->write_bufindex);
|
||||
priv->write_bufindex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Slave Bit Error (abort current transfer) */
|
||||
|
@ -384,10 +384,12 @@ static ssize_t smbus_sbd_write(struct file *filep, const char *buffer,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int smbus_sbd_callback(void *arg, size_t rx_len)
|
||||
static int smbus_sbd_callback(void *arg, i2c_slave_complete_t state,
|
||||
size_t rx_len)
|
||||
{
|
||||
struct smbus_sbd_dev_s *dev;
|
||||
int buffer_length;
|
||||
int ret = OK;
|
||||
int i;
|
||||
|
||||
/* Retrieve the pointer to the SMBus SBD slave device struct */
|
||||
@ -726,8 +728,15 @@ static int smbus_sbd_callback(void *arg, size_t rx_len)
|
||||
* request has been received.
|
||||
*/
|
||||
|
||||
return I2CS_WRITE(dev->i2c_slave_dev, (const uint8_t *)dev->write_buffer,
|
||||
buffer_length);
|
||||
ret = I2CS_WRITE(dev->i2c_slave_dev, (const uint8_t *)dev->write_buffer,
|
||||
buffer_length);
|
||||
if (ret >= 0)
|
||||
{
|
||||
dev->i2c_slave_dev->callback(dev->i2c_slave_dev->callback_arg,
|
||||
I2CS_TX_COMPLETE, buffer_length);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
Loading…
Reference in New Issue
Block a user