-
Notifications
You must be signed in to change notification settings - Fork 235
I2c
API
#9
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
Comments
I2C is interesting. Since we very likely want to retain the async property of the interface, there needs to be a way to model master and slave operation and hence the ability to either initiate and keep a new "session" with a slave having a specific address (in the simple case, there're also variants where group addressing is possible) where the operation can be read, write or combined. Or in the slave case the device only has a specific address and needs to respond to the read or write operations initiated by the master. |
Meant to post this a while back, but just got reminded by 5415ee1 Anyway, just some feedback on how I ended up doing I2C. I had something like: pub trait I2CTrait {
fn read_from(&self, address: u8, register: Option<u8>, &mut [u8]) -> Result<usize>;
fn write_to(&self, address: u8, register: Option<u8>, &[u8]) -> Result<usize>;
} which was only a first pass -- had intended to make it more abstract and post it here, but that didn't end up happening I guess haha. However, it did support one operation that I think most people would need: Slave register addressingSelecting a target register on a slave device to read or write from is a very common operation, so it might be worthwhile including some API at the Reading or writing from a slave's register is done by first writing the slave's address followed by the register address on the bus, then writing the slave's address again and entering read or write as normal. The sequence of the Blocking APII'll use One option could be to compose a However(!), the controller should not send a That means the current So, for that option to work, additional traits that don't send the Alternatively, the device could choose to implement its own For example, the controller I was targeting, for example, provided a special mode that would generate a Being able to implement Target register word sizeWhat type do we make From a quick scan, the I2C spec doesn't describe the "target register" word size at all. Though, this makes good sense IMHO because you want a generic specification. Anyway, from "Fig 13. Combined Format" page 15, it looks like it is permitted to be n bytes. So, then, I guess the most generic Most simple slave ICs use 8-bit addressing, though I've seen some use 16-bits, and rarely, 32-bits (e.g. I2C-compatible audio codecs that have large register files). So, maybe a short-hand version taking a single u8 or something might be useful. Don't know. You'd probably still want to support the n-byte case anyway though, since I'm sure there are devices somewhere out there that use multiple bytes for something. A personal anecdote: this controller supports up to 24-bit addresses fine, but anything more than that I think I'd have to bit-bang the data bytes myself. Haven't looked at any others, but I would hope that other controllers permit the same. I only mention this so we don't accidentally end up with an API that not all devices can implement! Anyway, just my 2c. :) |
I'm an idiot and can't read, apparently. You've already got a Oops! |
I thought about doing something like that but I couldn't think of a way to enforce at compile time that the user won't perform a string of operations that don't contain a stop -- this would result in keeping the bus busy beyond the operations the user requested.
The I2C API in #27 doesn't have a separate |
The If you want to propose adding futures or generator based I2C traits you should open a new RFC issue. |
12: Release new Patch on crates.io with InputPin Support r=therealprof a=Caemor Since rust-embedded#9 still seems to be WIP a small update for crates.io would be nice, so I could move back to the crates.io version of this package. Co-authored-by: Chris <[email protected]> Co-authored-by: Chris <[email protected]>
9: Add serial::Read/Write implementation r=ryankurte a=rnestler So this is just a quick PoC to implement rust-embedded#8. @japaric Do you think it would be OK to implement it in that way? If yes I can finish it up. Co-authored-by: Raphael Nestler <[email protected]> Co-authored-by: Raphael Nestler <[email protected]> Co-authored-by: Danilo Bargen <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
This API has not been designed yet. What methods should it provide?
The text was updated successfully, but these errors were encountered: