Repository navigation
i2c_target: Add attribute that exposes the number of bytes transferred. - #18485
alectric-tr wants to merge 3 commits into
Conversation
|
Code size report: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #18485 +/- ##
=======================================
Coverage 98.38% 98.38%
=======================================
Files 171 171
Lines 22301 22301
=======================================
Hits 21940 21940
Misses 361 361 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ba5fc7f to
a5994b4
Compare
Signed-off-by: Alex Tran <[email protected]>
Signed-off-by: Alex Tran <[email protected]>
Signed-off-by: Alex Tran <[email protected]>
a5994b4 to
075b090
Compare
|
Thanks for the contribution. And thanks for making a good PR with updates to both the docs and tests. The feature you've added is definitely useful. @projectgus and I discussed this PR and the main concerns we had were around atomicity: if another transaction comes in while the Python code is reading In most applications this probably won't matter, the I2C transactions will be slow/synchronous. But it would be good to try and improve the situation. One idea is to have an attribute (eg Instead, maybe it's enough to modify this PR to make it so that the new And then add another attribute Or, maybe something simpler that would still allow atomicity would be the following:
|
|
After recently playing around with I2CTarget, I stumbled across a possible need for this feature. Glad to see there's a PR in progress already! I wish to convert a Pimoroni RP2040 board into an I2CTarget and it seems configuring it as a memory device is the most performant option. For this I want some sections of memory to be read-only, where a write has no effect. If the host does a single byte write, then I can use the memaddr to check for a change and reload the stored value, but I cannot tell when multiple bytes are written in a row. I only have two read-only registers for now, so I am just using the hard irq to reset them both on every IRQ_END_WRITE. |
|
@alectric-tr are you still interested in working on this PR? |
Summary
As mentioned in the issue, the
I2CTargetclass exposes thememaddrattribute which is first memory address read/written by the controller, but there is no way of knowing how many attributes were read or written. This patch series adds the implementation, documentation, and tests for thenumbytesattribute to expose how many bytes were read/written in the last transaction.It is supported only when the I2C target device is configured as a memory device, otherwise the
numbytesattribute remains at 0.Fixes: #17996
Testing
Esp32 WROOMas the controller.RPI PICO 2W (RP2350)as the target.Tested for cases when the target was configured as a memory device and as an arbitrary I2C device.
Trade-offs and Alternatives
Alternatively,
numbytescan be split into 2 separate attributes, one for the number of bytes read and one for the number of bytes written after each transaction.Another alternative is to configure the I2C target device as an arbitrary I2C device and keep track of the count of a read/write request event until its end event has occurred. However, this method comes with more python code and some potential overhead of clock stretching.