Skip to content

Commit 99ce264

Browse files
ananglcarlescufi
authored andcommitted
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 <[email protected]>
1 parent 4801cbd commit 99ce264

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

drivers/i2c/i2c_nrfx_twim.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,31 @@ static int i2c_nrfx_twim_transfer(const struct device *dev,
6565
break;
6666
}
6767

68-
/* Merge this fragment with the next if we have a buffer, this
69-
* isn't the last fragment, it doesn't end a bus transaction,
70-
* the next one doesn't start a bus transaction, and the
71-
* direction of the next fragment is the same as this one.
68+
/* This fragment needs to be merged with the next one if:
69+
* - it is not the last fragment
70+
* - it does not end a bus transaction
71+
* - the next fragment does not start a bus transaction
72+
* - the direction of the next fragment is the same as this one
7273
*/
73-
bool concat_next = (concat_buf_size > 0)
74-
&& ((i + 1) < num_msgs)
75-
&& !(msgs[i].flags & I2C_MSG_STOP)
76-
&& !(msgs[i + 1].flags & I2C_MSG_RESTART)
77-
&& ((msgs[i].flags & I2C_MSG_READ)
78-
== (msgs[i + 1].flags & I2C_MSG_READ));
74+
bool concat_next = ((i + 1) < num_msgs)
75+
&& !(msgs[i].flags & I2C_MSG_STOP)
76+
&& !(msgs[i + 1].flags & I2C_MSG_RESTART)
77+
&& ((msgs[i].flags & I2C_MSG_READ)
78+
== (msgs[i + 1].flags & I2C_MSG_READ));
7979

8080
/* If we need to concatenate the next message, or we've
8181
* already committed to concatenate this message, add it to
8282
* the buffer after verifying there's room.
8383
*/
8484
if (concat_next || (concat_len != 0)) {
8585
if ((concat_len + msgs[i].len) > concat_buf_size) {
86-
LOG_ERR("concat-buf overflow: %u + %u > %u",
87-
concat_len, msgs[i].len, concat_buf_size);
86+
LOG_ERR("Need to use concatenation buffer and "
87+
"provided size is insufficient "
88+
"(%u + %u > %u). "
89+
"Adjust the zephyr,concat-buf-size "
90+
"property in the \"%s\" node.",
91+
concat_len, msgs[i].len,
92+
concat_buf_size, dev->name);
8893
ret = -ENOSPC;
8994
break;
9095
}

dts/bindings/i2c/nordic,nrf-twim.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ properties:
2929
zephyr,concat-buf-size:
3030
type: int
3131
required: false
32-
description:
33-
If concatenation buffer size is set, then multiple messages in the
34-
same direction will be concatenated into single transfers as long
35-
as there is space in buffer and no restart or stop flag is set.
32+
default: 16
33+
description: |
34+
Size of a concatenation buffer that the driver is to use for merging
35+
multiple same direction I2C messages that have no RESTART or STOP
36+
flag between them (see e.g. the i2c_burst_write() function) into one
37+
transfer on the bus.
3638
3739
This property must be provided when interacting with devices like
3840
the SSD1306 display that cannot tolerate a repeated start and
39-
address appearing on the bus between message fragments. For many
41+
address appearing on the bus between message fragments. For many
4042
devices a concatenation buffer is not necessary.

0 commit comments

Comments
 (0)