Skip to content

Fix I2C HID command to use write_read for response commands#867

Open
jerrysxie wants to merge 2 commits into
OpenDevicePartnership:mainfrom
jerrysxie:fix-i2c-host-split-transaction
Open

Fix I2C HID command to use write_read for response commands#867
jerrysxie wants to merge 2 commits into
OpenDevicePartnership:mainfrom
jerrysxie:fix-i2c-host-split-transaction

Conversation

@jerrysxie
Copy link
Copy Markdown
Contributor

Per the HID over I2C Protocol Spec v1.0, commands that require a response (GetReport, GetIdle, GetProtocol) must be performed as a single I2C transaction with a repeated START condition (no STOP between the write and read phases).

The previous implementation used separate write and read operations, which inserted a STOP condition between them, violating the spec. Use write_read with a separate stack-allocated command buffer (max 7 bytes for these commands) so the command is sent and the response is read in a single I2C transaction.

Also simplify the data_reg conditional logic in both branches to remove dead-code conditions.

Assisted-by: GitHub Copilot:claude-opus-4.6

Per the HID over I2C Protocol Spec v1.0, commands that require a
response (GetReport, GetIdle, GetProtocol) must be performed as a
single I2C transaction with a repeated START condition (no STOP
between the write and read phases).

The previous implementation used separate write and read operations,
which inserted a STOP condition between them, violating the spec.
Use write_read with a separate stack-allocated command buffer (max
7 bytes for these commands) so the command is sent and the response
is read in a single I2C transaction.

Also simplify the data_reg conditional logic in both branches to
remove dead-code conditions.

Assisted-by: GitHub Copilot:claude-opus-4.6
@jerrysxie jerrysxie self-assigned this May 27, 2026
@jerrysxie jerrysxie marked this pull request as ready for review May 27, 2026 22:30
@jerrysxie jerrysxie requested a review from a team as a code owner May 27, 2026 22:30
Copilot AI review requested due to automatic review settings May 27, 2026 22:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the HID-over-I2C device-side command handling to comply with the HID over I2C v1.0 requirement that response-producing commands be executed as a single I2C transaction (write + repeated START + read), avoiding an intervening STOP.

Changes:

  • Switches response-required HID commands (e.g., GetReport/GetIdle/GetProtocol) to use I2c::write_read with a small stack command buffer.
  • Simplifies the command encoding path by separating response vs non-response command handling.
  • Adjusts conditional inclusion of data_reg to remove dead-code branches.

Comment thread hid-service/src/i2c/device.rs Outdated
Comment thread hid-service/src/i2c/device.rs Outdated
Comment thread hid-service/src/i2c/device.rs Outdated
williampMSFT
williampMSFT previously approved these changes May 27, 2026
- Use device_response_timeout instead of data_read_timeout for the
  write_read transaction to preserve the original write timeout
- Update error log messages to reflect the combined write_read
  operation instead of just 'read host data'
- Fix comment grammar: 'cmds ... has' -> 'Commands ... have'

Assisted-by: GitHub Copilot:claude-opus-4.6
@RobertZ2011 RobertZ2011 requested a review from williampMSFT May 27, 2026 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants