Skip to content
Permalink
Browse files

drivers: i2c_nrfx_twi: Make use of NRFX_TWI_FLAG_SUSPEND

Make use of the new flag introduced in nrfx v1.7.2 that suspends
transfers, in order to properly handle scattered I2C transactions,
especially to perform i2c_burst_write() in the way expected by
display drivers, i.e. as a continuous transaction on the bus,
without the repeated START between its two parts.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
  • Loading branch information...
anangl authored and carlescufi committed Jul 26, 2019
1 parent 29782a0 commit e6fe54246509303e7081ce282f1d4eec2001b09a
Showing with 33 additions and 4 deletions.
  1. +33 −4 drivers/i2c/i2c_nrfx_twi.c
@@ -60,11 +60,40 @@ static int i2c_nrfx_twi_transfer(struct device *dev, struct i2c_msg *msgs,
.type = (msgs[i].flags & I2C_MSG_READ) ?
NRFX_TWI_XFER_RX : NRFX_TWI_XFER_TX
};
u32_t xfer_flags = 0;
nrfx_err_t res;

/* In case the STOP condition is not supposed to appear after
* the current message, check what is requested further:
*/
if (!(msgs[i].flags & I2C_MSG_STOP)) {
/* - if the transfer consists of more messages
* and the I2C repeated START is not requested
* to appear before the next message, suspend
* the transfer after the current message,
* so that it can be resumed with the next one,
* resulting in the two messages merged into
* a continuous transfer on the bus
*/
if ((i < (num_msgs - 1)) &&
!(msgs[i + 1].flags & I2C_MSG_RESTART)) {
xfer_flags |= NRFX_TWI_FLAG_SUSPEND;
/* - otherwise, just finish the transfer without
* generating the STOP condition, unless the current
* message is an RX request, for which such feature
* is not supported
*/
} else if (msgs[i].flags & I2C_MSG_READ) {
ret = -ENOTSUP;
break;
} else {
xfer_flags |= NRFX_TWI_FLAG_TX_NO_STOP;
}
}

nrfx_err_t res = nrfx_twi_xfer(&get_dev_config(dev)->twi,
&cur_xfer,
(msgs[i].flags & I2C_MSG_STOP) ?
0 : NRFX_TWI_FLAG_TX_NO_STOP);
res = nrfx_twi_xfer(&get_dev_config(dev)->twi,
&cur_xfer,
xfer_flags);
if (res != NRFX_SUCCESS) {
if (res == NRFX_ERROR_BUSY) {
ret = -EBUSY;

0 comments on commit e6fe542

Please sign in to comment.
You can’t perform that action at this time.