Skip to content

hid-service: bring #984 and #990 fixes to main - #991

Open
felipebalbi wants to merge 10 commits into
OpenDevicePartnership:mainfrom
felipebalbi:fix/hid-passthrough-main
Open

felipebalbi wants to merge 10 commits into
OpenDevicePartnership:mainfrom
felipebalbi:fix/hid-passthrough-main

Conversation

@felipebalbi

Copy link
Copy Markdown
Contributor

Bring the fixes from #984 and #990 to main, preserving original commits and authors.

  • Refresh HID metadata and fix passthrough failure, routing, and interrupt handling.
  • Make host/device buffer capacities configurable.
  • Require main-first integration checks for stable backports.

Validated: workspace tests, formatting, Clippy, and affected-crate host/ARM feature checks.

Closes #987
Closes #989

yourongtang and others added 8 commits November 19, 2026 09:50
Refresh HID metadata for both HID and report descriptor reads while
retaining cached metadata for input reports and commands. Invalidate the
cache before refreshing so a failed or cancelled metadata read cannot
leave stale metadata available for reuse.

Replace the descriptor's async mutex with SyncCell. Descriptor is Copy,
and cache accesses only copy, invalidate, or publish a complete value.
No cache reference or guard is held across an await, so cache access
does not need an async mutex. SyncCell uses critical sections on the
host and the existing single-core thread-mode model on bare-metal ARM.
Keep the async bus mutex because I2C transactions hold mutable access
across await.

SyncCell protects individual cache accesses, not the complete refresh
sequence. Operations on a Device must remain serialized, as in the
passthrough request loop; the old cache mutex did not serialize complete
refreshes either. Document this requirement and the cache lifetime.

While at that , also add inline behavioral tests for current
descriptor bytes, refreshed registers and lengths, warm cache reuse,
lazy initialization, and invalidation after errors, timeouts, and
cancellation.
Add a literal application HID descriptor from the ELAN HC4909-20H5V0
I2C Programming Guide v1.0, section 2.1. Test the 1129-byte report
length and the 1128/1129 storage boundary using sections 3.2 and 3.3.
Follow the numeric input length and layout in section 4.2,
not the conflicting prose annotation.

Exercise the real Host, comms routing, and Device with a scripted
version change and descriptor requests. Check actual upstream bytes
after each request, including cached input and command handling. Only
the physical I2C interfaces are doubled. Keep all tests inline and all
production code unchanged.

Cancel descriptor futures after partial metadata and report writes,
then verify fresh command metadata, released software resources, and a
complete report retry. Mutation checks confirm that truncating the
length, returning cached HID metadata, or omitting invalidation breaks
the new tests.

The host sequence, updated version, and opaque report payloads are
synthetic, not captured bootloader/application behavior. Paired mode
descriptors and actual OS/update-tool re-enumeration ordering still
need vendor or device/system evidence. Reset/interrupt timing from
section 3.5.2 is not established by these tests.

Cancellation exercises Rust futures and software state, not the
deployed HAL or controller. STOP generation, DMA cleanup, and touchpad
readiness for the next transfer still need HAL-specific and on-target
validation. No touchpad hardware was available. Existing passthrough
capacity and missing error-completion issues remain separate software
follow-ups, not hardware-only uncertainties.

Scoped tests pass: 83 unit tests and one doctest. Full workspace tests
remain blocked on Windows/MSVC by existing debug-service defmt and
espi-service ARM linker symbols.
Send explicit HID failure completions when a consumed request
returns an error. Distinguish failures from successful commands
with no response, preserve portable HID errors for the host, and
retain original HAL/buffer errors for device-side logging.

Validate completion destination and device ID before waking the
host. Keep request processing serialized; do not introduce host
timeouts that could confuse late, uncorrelated responses.

Add compile-time device-buffer overrides to passthrough macros.
Keep the legacy 512-byte allocation; integrations can select 1129
bytes for the ELAN HC4909-20H5V0 report descriptor documented in
I2C Programming Guide v1.0, sections 2.1 and 3.3. The separate
128-byte host buffer is unchanged.

Await interrupt-state requests in generated host tasks. Handle
coalesced completion, idle reset, and notifications posted between
consumption and state inspection without leaking them into the
next interrupt exchange.

Pin failure/retry behavior, routing, actual macro allocations,
and interrupt output transitions with inline behavioral tests.
Expand both composite macro forms in compile fixtures.

MessageData gains a public Failure variant; downstream exhaustive
matches may need updating. This is not a HID wire-format change.
Cancellation and physical controller abort/resynchronization
remain caller/HAL responsibilities.

Validation: 89 scoped unit tests and one doctest pass; formatting,
Clippy, workspace checking, and ARM Clippy pass. Full workspace
tests remain blocked on Windows/MSVC by existing debug-service
defmt and espi-service ARM linker failures.

Refs: OpenDevicePartnership#987
Add an optional buffer_size to the generated host task and forward
host_buffer_size independently through the composite macro. Keep
the 128-byte legacy allocation and existing device-size option.

The ELAN HC4909-20H5V0 I2C Programming Guide v1.0, sections 3.5 and
3.5.5 Figure 12, documents an IAP frame with length 0x0083. Let
integrations select sufficient storage for that 131-byte example
without treating it as the maximum for every possible command.
Leave parser bounds checks and device response storage unchanged.

Run the real composite-generated host task against a complete
scripted IAP packet. Verify the forwarded feature request and all
payload bytes, successful completion, and acceptance of the next
command. Check rejection with 128/130-byte buffers and compile all
four combinations of legacy, device, host, and combined options.

Payload contents and the host sequence are synthetic. These tests
establish software ingress capacity, not physical touchpad update
success, actual OS sequencing, or controller recovery. No hardware
corroboration is claimed and no OpenDevicePartnership#988 length adjustment is made.

Validation: 89 scoped unit tests and one doctest pass. Formatting,
Clippy, workspace checking, and ARM Clippy pass. Full workspace
tests retain the existing Windows/MSVC linker failures in
debug-service and espi-service.

Refs: OpenDevicePartnership#989
Call the helper macros through their defining crate instead of importing
them into the generated module. On main the imports are reported as
unused when the deprecated service's composite macro expands in tests.

Keep this main-specific integration adjustment separate from the
original commits ported from OpenDevicePartnership#984 and OpenDevicePartnership#990.

Assisted-by: OpenCode:gpt-6.1-sol
Make Copilot review verify that stable-* changes backport PRs already
merged into main and that their fixes remain present there. Report
missing main fixes as high-severity issues and require evidence when
integration cannot be verified.

Require original PR and commit references in stable review summaries.
Allow necessary stable API adaptations and different cherry-pick SHAs.

Validated behavior against an unmerged main PR, a valid adapted
backport, unavailable history, a main-targeting PR, and a reverted fix.

Assisted-by: OpenCode:gpt-6.1-sol
@felipebalbi

felipebalbi commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

This PR should only be merged after #984 and #990 are merged!

@felipebalbi
felipebalbi marked this pull request as ready for review November 19, 2026 18:48
@felipebalbi
felipebalbi requested review from a team as code owners November 19, 2026 18:48
@felipebalbi
felipebalbi requested review from RobertZ2011, kurtjd, tullom, williampMSFT and wmmc88 and a balanced review from Copilot November 19, 2026 18:48
@felipebalbi
felipebalbi enabled auto-merge (squash) November 19, 2026 18:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Critical error-recovery flaws can send input-report bytes during a pending descriptor read and lose a concurrent reset, leaving the interrupt asserted without notification.

2 open issues
What changed in this PR

Brings the HID passthrough fixes from #984 and #990 to main. The changes refresh descriptor metadata, improve request completion handling, and allow larger transfers without changing default buffer sizes.

Changes:

  • Refresh metadata on descriptor requests while retaining cached metadata for input reports and commands.
  • Add failure notifications, completion-routing checks, interrupt-race handling, and regression tests.
  • Make host/device buffer capacities independently configurable and document main-first requirements for stable backports.
File Description
hid-service/​src/​i2c/​passthrough/​mod.rs Adds configurable buffer capacities and awaits interrupt operations.
hid-service/​src/​i2c/​passthrough/​interrupt.rs Updates interrupt completion handling and adds race regressions.
hid-service/​src/​i2c/​host.rs Handles device failures and validates completion destinations and device IDs.
hid-service/​src/​i2c/​device.rs Refreshes metadata, reports failures, and adds device/bridge regression tests.
hid-service/​Cargo.toml Adds host-test dependencies.
embedded-service/​src/​hid/​mod.rs Adds explicit failure messages and a sending API.
Cargo.lock Records added HID test dependencies.
.github/​skills/​code-review/​SKILL.md Documents main-first verification for stable backports.

Review effort: Balanced

Comment on lines +104 to 105
int_signal.reset().await;
continue;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This may be valid. Trying to reproduce with a spike.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reproduced with the real Host on a single cooperative executor:

  1. Upstream: WRITE [01 00], followed by a pending READ.
  2. Downstream: descriptor request fails with Timeout.
  3. host.process() returns the error without consuming the READ.
  4. The host loop calls host.process() again.
  5. The pending READ becomes Request::InputReport.
  6. Input bytes [04 00 52 A5] are sent as the descriptor response.

@felipebalbi felipebalbi Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Alright, here's the thing. The bug is real, but the existing I²C slave trait doesn't give us a way to recover the failed exchange.

The MCXA HAL already has recover(), but our legacy I2cSlaveAsync trait doesn't expose it. This also affects #990, so we need an approach that doesn't break stable-v0.1.y consumers.

An additive recovery hook is one option. Stopping after failure would prevent corruption but lose automatic recovery. I'll leave that decision to the maintainers/platform owners. Either way, we should pin the sequence above in a regression test.

Finally, the proper way to read this is: #990 fixes the hang but exposes an existing upstream transaction-recovery gap.

@RobertZ2011 @yourongtang @jerrysxie @OpenDevicePartnership/ec-hid-team

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It depends on how badly we want to avoid a breaking change. We could do something like adding a recover function to I2cSlaveAsync and provide a default implementation that logs an error. Or maybe the default could call a deprecated function. I'm wondering if that would work to essentially warn that you should implement that function while not breaking anything.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm gonna need a decision, though. I'm also glad to leave it out of this PR, file a ticket, and leave this to be sorted out on a dedicated PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's go with that for now. We should get feedback from existing users of this code before moving forward.

Drive the forwarded interrupt high before allowing the generated host
task to process or answer a request. A notification alone does not
establish that ordering on a cooperative executor.

Deprecate the notification-only deassert method without changing its
signature. Add deassert_and_wait with explicit GPIO error reporting,
and release the output mutex while the interrupt task waits. Retain
successful pin-level confirmation so interrupt cleanup cannot repeat a
fallible HIGH write and reassert LOW during a pending response.

Pin ordering through the real generated host task with its interrupt
task deliberately unpolled. Cover GPIO failure without forwarding or
responding, consecutive exchanges, idle notifications, failed-write
retry, and cleanup after an already-confirmed deassertion.

This does not address the separate upstream transaction-recovery gap.

Refs: OpenDevicePartnership#990, OpenDevicePartnership#991

Assisted-by: OpenCode:gpt-6.1-sol
felipebalbi added a commit to felipebalbi/embedded-services that referenced this pull request Nov 19, 2026
Drive the forwarded interrupt high before allowing the generated host
task to process or answer a request. A notification alone does not
establish that ordering on a cooperative executor.

Deprecate the notification-only deassert method without changing its
signature. Add deassert_and_wait with explicit GPIO error reporting,
and release the output mutex while the interrupt task waits. Retain
successful pin-level confirmation so interrupt cleanup cannot repeat a
fallible HIGH write and reassert LOW during a pending response.

Pin ordering through the real generated host task with its interrupt
task deliberately unpolled. Cover GPIO failure without forwarding or
responding, consecutive exchanges, idle notifications, failed-write
retry, and cleanup after an already-confirmed deassertion.

This does not address the separate upstream transaction-recovery gap.

Refs: OpenDevicePartnership#990, OpenDevicePartnership#991

Assisted-by: OpenCode:gpt-6.1-sol
@felipebalbi

Copy link
Copy Markdown
Contributor Author

Another thing to keep in mind: this PR retains the deassert() API deprecated in #990. Since this targets the next stable release, we have three options:

  1. Delete deassert() and keep deassert_and_wait().
  2. Keep deprecated deassert() alongside deassert_and_wait() for another release cycle.
  3. Give deassert() the confirmed-deassertion implementation and return type Result<(), Error>, then delete deassert_and_wait().

Which migration policy do we want?

@RobertZ2011 @OpenDevicePartnership/ec-hid-team

@RobertZ2011

Copy link
Copy Markdown
Contributor

Another thing to keep in mind: this PR retains the deassert() API deprecated in #990. Since this targets the next stable release, we have three options:

  1. Delete deassert() and keep deassert_and_wait().
  2. Keep deprecated deassert() alongside deassert_and_wait() for another release cycle.
  3. Give deassert() the confirmed-deassertion implementation and return type Result<(), Error>, then delete deassert_and_wait().

Which migration policy do we want?

@RobertZ2011 @OpenDevicePartnership/ec-hid-team

I'm fine with 2 if we really don't want to do a breaking change right now.

@felipebalbi

Copy link
Copy Markdown
Contributor Author

Another thing to keep in mind: this PR retains the deassert() API deprecated in #990. Since this targets the next stable release, we have three options:

  1. Delete deassert() and keep deassert_and_wait().
  2. Keep deprecated deassert() alongside deassert_and_wait() for another release cycle.
  3. Give deassert() the confirmed-deassertion implementation and return type Result<(), Error>, then delete deassert_and_wait().

Which migration policy do we want?
@RobertZ2011 @OpenDevicePartnership/ec-hid-team

I'm fine with 2 if we really don't want to do a breaking change right now.

done

felipebalbi added a commit to felipebalbi/embedded-services that referenced this pull request Nov 20, 2026
Pull in the comments from PR OpenDevicePartnership#991 explaining interrupt test
polling phases and the deprecated deassert API migration window.
@jerrysxie jerrysxie added this to EC Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

5 participants