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.
Whilst working on I2C sensors for flight controllers I noticed that the Wire lib does not have a method to do a combined async I2C write+read operation. Most sensors I work with require first to write a register number, followed by a read.
I was also missing a callback on async operation completion.
This PR adds two new public methods to provide this functionality:
bool writeReadAsync(uint8_t address, const void *wbuf, size_t wlen, const void *rbuf, size_t rlen, bool sendStop)
void onFinishedAsync(void(*function)(void))
In addition the dma channel initialization/destruction was moved out of the main read/write method. Before, each async read/write call claims dma channels and allocates buffers, and freeing them upon completion. Now, the claim is done on the first async read/write call, and calling end() will free the buffers and dma channels.
Also the 16 bit receive buffer was replaced with a direct dma write to the 8 bit user provided read buffer.
NB: Earle, many thanks for your hard work on this project!
Test Program
Output Test Program