Skip to content

Comments

feat: add HAS_AUTO_RETRY constant to Driver trait#42

Merged
elagil merged 2 commits intoelagil:mainfrom
okhsunrog:feature/driver-auto-retry-support
Feb 6, 2026
Merged

feat: add HAS_AUTO_RETRY constant to Driver trait#42
elagil merged 2 commits intoelagil:mainfrom
okhsunrog:feature/driver-auto-retry-support

Conversation

@okhsunrog
Copy link
Contributor

@okhsunrog okhsunrog commented Feb 5, 2026

Summary

  • Adds HAS_AUTO_RETRY: bool = false associated constant to the Driver trait (backward compatible default)
  • When true, the protocol layer skips software retry loops and calls driver.transmit() directly — Discarded means all hardware retries are exhausted, mapped to TransmitRetriesExceeded
  • TX message counter is maintained directly without wait_for_good_crc(), since hardware already verified GoodCRC reception
  • Updates transmit_chunk_request() with the same HAS_AUTO_RETRY handling
  • Changes wait_for_vbus(&self) to wait_for_vbus(&mut self) so PHY drivers can poll hardware registers (e.g. FUSB302B needs I2C access to check STATUS0.VBUSOK)
  • Updates HAS_AUTO_RETRY doc comment to reflect the actual implementation

Motivation

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's transmit() 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_vbus signature change from &self to &mut self is 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.rs

  • New const HAS_AUTO_RETRY: bool = false on the Driver trait
  • wait_for_vbus(&self)wait_for_vbus(&mut self)
  • Updated HAS_AUTO_RETRY doc comment

usbpd/src/protocol_layer/mod.rs

  • transmit(): when HAS_AUTO_RETRY, calls driver.transmit() directly (not transmit_inner() which retries indefinitely on Discarded), increments TX message counter on success
  • transmit_chunk_request(): same HAS_AUTO_RETRY branch added

Examples

  • Updated wait_for_vbus signature in all three example drivers (no behavioral change)

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).
@elagil elagil merged commit 32ae264 into elagil:main Feb 6, 2026
1 check passed
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.

2 participants