drivers: i2c_nrfx_twim: Use concatenation buffer by default
Issue an error logging message when the i2c_nrfx_twim driver lacks a concatenation buffer big enough to properly handle a call to i2c_burst_write() function, to give the user a hint what is wrong. Also use by default a 16-bytes long concatenation buffer for every instance of the i2c_nrfx_twim driver. Such value should cover most of the simple uses of the i2c_burst_write() function, like those in the stmemsc sensor drivers, and when a longer buffer is needed, the user will be provided with the above message pointing to the property that should be adjusted. Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
This commit is contained in:
parent
4801cbd921
commit
99ce264df7
2 changed files with 24 additions and 17 deletions
|
@ -65,17 +65,17 @@ static int i2c_nrfx_twim_transfer(const struct device *dev,
|
|||
break;
|
||||
}
|
||||
|
||||
/* Merge this fragment with the next if we have a buffer, this
|
||||
* isn't the last fragment, it doesn't end a bus transaction,
|
||||
* the next one doesn't start a bus transaction, and the
|
||||
* direction of the next fragment is the same as this one.
|
||||
/* This fragment needs to be merged with the next one if:
|
||||
* - it is not the last fragment
|
||||
* - it does not end a bus transaction
|
||||
* - the next fragment does not start a bus transaction
|
||||
* - the direction of the next fragment is the same as this one
|
||||
*/
|
||||
bool concat_next = (concat_buf_size > 0)
|
||||
&& ((i + 1) < num_msgs)
|
||||
&& !(msgs[i].flags & I2C_MSG_STOP)
|
||||
&& !(msgs[i + 1].flags & I2C_MSG_RESTART)
|
||||
&& ((msgs[i].flags & I2C_MSG_READ)
|
||||
== (msgs[i + 1].flags & I2C_MSG_READ));
|
||||
bool concat_next = ((i + 1) < num_msgs)
|
||||
&& !(msgs[i].flags & I2C_MSG_STOP)
|
||||
&& !(msgs[i + 1].flags & I2C_MSG_RESTART)
|
||||
&& ((msgs[i].flags & I2C_MSG_READ)
|
||||
== (msgs[i + 1].flags & I2C_MSG_READ));
|
||||
|
||||
/* If we need to concatenate the next message, or we've
|
||||
* already committed to concatenate this message, add it to
|
||||
|
@ -83,8 +83,13 @@ static int i2c_nrfx_twim_transfer(const struct device *dev,
|
|||
*/
|
||||
if (concat_next || (concat_len != 0)) {
|
||||
if ((concat_len + msgs[i].len) > concat_buf_size) {
|
||||
LOG_ERR("concat-buf overflow: %u + %u > %u",
|
||||
concat_len, msgs[i].len, concat_buf_size);
|
||||
LOG_ERR("Need to use concatenation buffer and "
|
||||
"provided size is insufficient "
|
||||
"(%u + %u > %u). "
|
||||
"Adjust the zephyr,concat-buf-size "
|
||||
"property in the \"%s\" node.",
|
||||
concat_len, msgs[i].len,
|
||||
concat_buf_size, dev->name);
|
||||
ret = -ENOSPC;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -29,12 +29,14 @@ properties:
|
|||
zephyr,concat-buf-size:
|
||||
type: int
|
||||
required: false
|
||||
description:
|
||||
If concatenation buffer size is set, then multiple messages in the
|
||||
same direction will be concatenated into single transfers as long
|
||||
as there is space in buffer and no restart or stop flag is set.
|
||||
default: 16
|
||||
description: |
|
||||
Size of a concatenation buffer that the driver is to use for merging
|
||||
multiple same direction I2C messages that have no RESTART or STOP
|
||||
flag between them (see e.g. the i2c_burst_write() function) into one
|
||||
transfer on the bus.
|
||||
|
||||
This property must be provided when interacting with devices like
|
||||
the SSD1306 display that cannot tolerate a repeated start and
|
||||
address appearing on the bus between message fragments. For many
|
||||
address appearing on the bus between message fragments. For many
|
||||
devices a concatenation buffer is not necessary.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue