-
Notifications
You must be signed in to change notification settings - Fork 232
Add transactional I2C interface #223
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
Conversation
r? @ryankurte (rust_highfive has picked a reviewer for you, use r? to override) |
f8c1d08
to
b22c88c
Compare
Doesn't the trait need an entry in the prelude? |
Done. |
0de9610
to
bcaa268
Compare
Co-authored-by: Daniel Egger <daniel@eggers-club.de>
bcaa268
to
cfa13de
Compare
Is there anything left to do here? Since we have merged transactional SPI already, adding also transactional I2C to the same release would be nice. |
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.
Excellent, let's get this in then.
bors r+
👎 Rejected by code reviews |
... after @ryankurte removed his concern... |
bors r+ |
44: Implement transactional I2C interface and add example r=ryankurte a=eldruin I implemented the transactional I2C interface from rust-embedded/embedded-hal#223 and added an example with a driver which does a combined Write/Read transaction. This is based on previous work from #33 by @ryankurte, rust-embedded/rust-i2cdev#51 and is similar to #35. Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
44: Implement transactional I2C interface and add example r=ryankurte a=eldruin I implemented the transactional I2C interface from rust-embedded/embedded-hal#223 and added an example with a driver which does a combined Write/Read transaction. This is based on previous work from #33 by @ryankurte, rust-embedded/rust-i2cdev#51 and is similar to #35. Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
An example where a transactional I2C interface would be an improvement is when facing the problem of sending an array of data where the first item is the destination address.
At the moment this requires copying the data into a bigger array and assigning the first item to the address. With a transactional I2C two
write
operations could be chained into one transaction so that it is possible to send the address and data without an extra copy.This is specially problematic if the data length is unknown e.g. because it comes from the user.
You can see the problem here in the eeprom24x driver. In this case I am lucky enough to have the page upper limit so that the copy workaround is possible.
With this PR a bunch of code and macros could be replaced by doing something similar to this:
I added a PoC here in linux-embedded-hal including an example of a driver where a classical combined write/read is performed through the transactional interface.
Note: A default implementation of the
Transactional
trait like in #191 is not possible because STOPs would always be sent after each operation. What is possible is to do is the other way around. This includes an implementation of theWrite
,Read
andWriteRead
traits forTransactional
implementers.This is based on previous work from #178 by @ryankurte and it is similar to #191
TODO: