rust-embedded / rust-embedded/linux-embedded-hal
I2C transaction breaks I2c trait contract
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 319
- Forks
- 60
- Avg merge
- 12h 31m
- Merged PRs (30d)
- 1
Description
According to I2c trait transaction contract is as follows:
Transaction contract:
- Before executing the first operation an ST is sent automatically. This is followed by SAD+R/W as appropriate.
- Data from adjacent operations of the same type are sent after each other without an SP or SR.
- Between adjacent operations of a different type an SR and SAD+R/W is sent.
- After executing the last operation an SP is sent automatically.
- If the last operation is a `Read` the master does not send an acknowledge for the last byte.
- `ST` = start condition
- `SAD+R/W` = slave address followed by bit 1 to indicate reading or 0 to indicate writing
- `SR` = repeated start condition
- `SP` = stop condition
Using following simple test code:
use embedded_hal::i2c::blocking::{I2c, Operation as I2cOperation};
use linux_embedded_hal::I2cdev;
fn main() {
let mut i2c_dev = I2cdev::new("/dev/i2c-1").unwrap();
let data = [0xaa; 1];
let mut ops = [I2cOperation::Write(&[0x40]), I2cOperation::Write(&data)];
i2c_dev.transaction(0x3d, &mut ops).unwrap();
}
I'm expecting no SR "repeated start condition" to appear as both operations are of the same type (Write). Unfortunately I can see SR "repeated start condition" on the bus as well as SAD+R/W "slave address followed by bit 1 to indicate reading or 0 to indicate writing" (positions 6 and 8). This was captured using logic analyzer on embedded Linux board for the sample code attached above:

Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the I2cdev::transaction implementation and trace the Linux I2C operation path used by the supplied example. Compare the generated bus sequence with the transaction contract, especially adjacent Write operations. Done means the example no longer produces an unnecessary repeated start and address between consecutive writes, with the relevant behavior covered by tests if the implementation exposes a testable path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- linux, rust
- Domain
- embedded-iot, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100