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 support for SMBus #1899
Add support for SMBus #1899
Conversation
6ddf640
to
1ae2585
Compare
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.
Overall seems good.
Do we need the default implementation? I think it would be simpler to remove that, and then we don't need the new error.
The idea with the default implementation is that we can do something like this: match self.smbus_dev.smbus_write_read(buf, 1, 1) {
Ok(_) => {}
Err(e) => {
if e.0 == Error::NotSupported {
// SMBus operations aren't supported. Try normal I2C
self.smbus_dev.write_read(e.1, 1, 1)
}
}
} |
I think it is misleading to mark an object as |
Yeah, I agree that is confusing. I originally had the functions as part of the I2C traits to not imply that we support SMBus. I'm expecting the In saying that most Tock I2C devices use 400kHz and SMBus is 100kHz, so it most likely won't work without the hardware having at least some implementation for these new functions. |
1ae2585
to
b8a81c1
Compare
I pushed an update that fleshes this out more. |
b8a81c1
to
ebb3780
Compare
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.
The MuxI2C changes look pretty good, but I still don't see where the NotSupported case would happen.
ebb3780
to
b190ce4
Compare
Personally, I think I am okay with the HIL changes, but may need to think about them a little more. However I don't really like adding a new SMBusDevice struct that is exactly identical to the I2CDevice struct, and implements the same traits with identical code...could we just modify the I2CDevice to have a SMBusMode boolean? Or a mode field that is an enum for either I2CMode or SMBusMode, and that defaults to I2CMode? That would also help resolve the issue of how the current implementation always prioritizes I2C transactions over SMBus transactions |
Would it be possible to separate the I2CMaster and SMBusMaster HILs, and then have the virtualI2C capsule look like this:
Then any board supporting smbus could just pass the same trait object for the i2c and smbus fields, while boards not supporting smbus would pass |
The problem with that is that we then can't mux the |
In this scenario virtual_i2c.rs is still responsible for muxing both i2c and smbus -- it just lets the SMBus HIL be completely seperate from the I2C HIL. But I can try to prototype this if that doesn't make sense |
https://github.com/hudson-ayers/tock/tree/smbus is what I have in mind. It seperates the SMBusMaster HIL from the I2CMaster, and removes the separate SMBusDevice struct in favor of adding a boolean to the I2CDevice struct. It requires a lot less changes to the virtual_i2c capsule and I think lets you do everything that the current implementation does, but I am not totally familiar with SMBus so I could be wrong. Let me know what you think @alistair23 |
b190ce4
to
0750d6e
Compare
I have pushed an update that follows what Hudson did and separates the SMBusMaster trait. I prefer the separate SMBusDevice so I have left that in. Let me know what people think. If we think we should squash the device and use a bool I can do that instead. |
Add some functions to support SMBus read/write operations. Although SMBus is similar to I2C it has a few differences, mostly in regards to frequency, ACK/NACK and timings. This doesn't support more complex SMBus operations such as the ARP features. Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
0750d6e
to
844d12e
Compare
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.
Tested the Imix app with this branch, which reads from multiple i2c sensors in quick succession, and it works.
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
844d12e
to
4391bd0
Compare
bors r+ |
1897: Apollo3: Add support for the I2C device r=bradjc a=alistair23 ### Pull Request Overview This PR adds I2C support to the RedBoard Artemis Nano and the Apollo3 chip. This PR applies on top of ~~#1896 and #1889 #1899 ### Testing Strategy Monitoring the I2C traffic on the boards Qwiic connector. ### TODO or Help Wanted ### Documentation Updated - [X] Updated the relevant files in `/docs`, or no updates are required. ### Formatting - [X] Ran `make format`. - [X] Fixed errors surfaced by `make clippy`. Co-authored-by: Alistair Francis <alistair@alistair23.me>
Pull Request Overview
Add some functions to support SMBus read/write operations. Although SMBus is similar to I2C it has a few differences, mostly in regards to frequency, ACK/NACK, timings and ARP.
Some I2C hardware exposes timing options that can be tweaked to better match the SMBus timing requirements. This is why we are adding two new functions. It tells the driver to tweak the timing to match the SMBus spec.
This PR adds new functions to the I2C HIL and also extends the
virtual_i2c.rs
to Mux SMBus devices with I2C devices.Testing Strategy
With some patches on top of this I can communicate with an SMBus IR temperature sensor. Once this is merged I'll send a PR to add the sensor.
TODO or Help Wanted
Documentation Updated
/docs
, or no updates are required.Formatting
make format
.make clippy
.