This repository has been archived by the owner on Nov 17, 2021. It is now read-only.
Ensured non-blocking update() loop + changed onRequest calling policy #9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
I am using this library for a project, which has this kind of behavior:
During testing, I have found these unexpected behaviors (from my humble point of view as user of this library).
1. Blocking behavior
When this library, inside the
update()
method, callsi2c_slave_read_buffer(..., 0)
, it sometimes blocks. I have not understood when this exactly happens, but I am sure that blocking is not fine: we are inside the Arduinoloop()
method, so we want to be asynchronous to improve performances.Therefore I have changed the call into
i2c_slave_read_buffer(..., 1)
to ensure the call never blocks.The official ESP IDF API documentation is not clear what happens in case of zero (no wait? wait until there is at least something?), so this change seems safer and actually my code stopped to have a blocking behavior (so this change works).
2 Callback behavior
The
user_onRequest
method is always called, which is somehow unexpected. Actually, the official Wire lib documentation is not completely clear on the behavior, but it seems to me reasonable to have a strict separation between the two callbacks:user_onReceive
called only for master writes,user_onRequest
only for master reads. So I have slightly changed theif
condition, and successfully obtained the desired behavior.All these changes are provided into the pull request, along with the addition of a small sanity check.
I provide this pull request in the hope you will find these changes useful (if not, feel free to discard this pr).
Regards.