feat: add HAS_AUTO_RETRY constant to Driver trait#42
Merged
elagil merged 2 commits intoelagil:mainfrom Feb 6, 2026
Merged
Conversation
Add support for hardware automatic retries in USB PD drivers. When HAS_AUTO_RETRY is true, the protocol layer skips its software retry loop and calls driver.transmit() directly — Discarded means all hardware retries are exhausted, so no software retry is needed. The TX message counter is maintained directly without calling wait_for_good_crc(), since hardware already verified GoodCRC reception (e.g. via I_TXSENT on FUSB302B). Also updates transmit_chunk_request() with the same HAS_AUTO_RETRY handling for chunked extended message flows.
Some PHYs (e.g. FUSB302B) need I2C access to poll VBUS status, which requires &mut self. Existing implementations that don't need mutability are unaffected — they just change the signature. Also update HAS_AUTO_RETRY doc comment to reflect the current implementation (no longer calls wait_for_good_crc).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
HAS_AUTO_RETRY: bool = falseassociated constant to theDrivertrait (backward compatible default)true, the protocol layer skips software retry loops and callsdriver.transmit()directly —Discardedmeans all hardware retries are exhausted, mapped toTransmitRetriesExceededwait_for_good_crc(), since hardware already verified GoodCRC receptiontransmit_chunk_request()with the sameHAS_AUTO_RETRYhandlingwait_for_vbus(&self)towait_for_vbus(&mut self)so PHY drivers can poll hardware registers (e.g. FUSB302B needs I2C access to check STATUS0.VBUSOK)HAS_AUTO_RETRYdoc comment to reflect the actual implementationMotivation
Some USB PD PHY chips (e.g. FUSB302B) handle packet retries and GoodCRC verification entirely in hardware. For these drivers, the protocol layer's software retry loop and
wait_for_good_crc()are redundant — the driver'stransmit()already returns success only after hardware confirmed GoodCRC reception. This constant lets the protocol layer skip that overhead and rely on the hardware.The
wait_for_vbussignature change from&selfto&mut selfis needed because some PHYs require mutable bus access to poll VBUS status registers. Existing implementations just update the signature with no behavioral change.Changes
usbpd-traits/src/lib.rsconst HAS_AUTO_RETRY: bool = falseon theDrivertraitwait_for_vbus(&self)→wait_for_vbus(&mut self)HAS_AUTO_RETRYdoc commentusbpd/src/protocol_layer/mod.rstransmit(): whenHAS_AUTO_RETRY, callsdriver.transmit()directly (nottransmit_inner()which retries indefinitely onDiscarded), increments TX message counter on successtransmit_chunk_request(): sameHAS_AUTO_RETRYbranch addedExamples
wait_for_vbussignature in all three example drivers (no behavioral change)