added I2C TwoWire::busIdle to be checked by writeReadAsync #2798
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.
Problem
When using
writeReadAsync
in a multi-threaded environment (e.g. with FreeRTOS), the DMA interrupt fires immediately after the TX FIFO is loaded—not when the I2C peripheral has actually finished clocking out those bytes. As a result, a newwriteReadAsync
call might start too early and interrupt the ongoing hardware transfer. This issue only affects write-only transactions (rbytes == 0
), because read transactions already use a different interrupt that waits for RX completion.Solution
This PR adds a
bool busIdle()
function that checks if the I2C hardware is truly idle (i.e., no master activity and the transmit FIFO is empty). InsidewriteReadAsync
, if the bus is still busy, we returnfalse
—just as we already do if a DMA transfer is in progress. This allows the caller to detect the “bus still busy” case and retry the operation once the bus becomes free.Benefits
writeReadAsync
by giving callers a straightforward way to avoid interrupting a still-active write.