-
Notifications
You must be signed in to change notification settings - Fork 412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TwoWire::writeReadAsync #2388
Conversation
Thanks for the contribution! Other than minor formatting issues w/CI this looks good after a quick glance. Let me read it more closely tomorrow, but we'll get this in soon! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a quick check and this breaks TalkingToMyselfAsync
which is my go-to test since I don't have any simple SPI peripherals. It runs a single cycle and then fails to make any progress sending the 2nd message. Can you take a look at it?
Hmmm, not good. I'll have a look... |
I've got Apparently I was too aggressive moving the dma configuration from writeReadAsync() to beginAsync(), moving it back and adding dma_channel_cleanup solved it. Also did some other minor cleanups. |
Great, thanks for the follow up! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just walked through this and wanted to say, very neat way of using the weird control-bits-per-byte in the I2C peripheral! This code itself looks good, but would you be able to put in a paragraph or two in docs/wire.rst
with this new call and callback function? I could probably add it after the fact, but I think you have a better grasp of where this makes sense to use...
Thanks! I've made an attempt to update the docs. Also, I renamed the function arguments to be more in line with the current naming and added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks for going the extra mile and adding some kind of docs! That's always the least fun but probably most important bit.
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