148 bool negotiate(
const RequestParams &req, SourceCaps *outCaps =
nullptr,
149 uint32_t timeoutMs = 6000);
159 SourceCaps *outCaps =
nullptr);
169 SourceCaps *outCaps =
nullptr);
177 bool requestFromCaps(
const SourceCaps &caps,
const RequestParams &req);
194 bool selectFixedOffer(
const SourceCaps &caps,
const RequestParams &req, FixedOffer &outOffer);
232 bool sendRequest(
const FixedOffer &offer,
const RequestParams &req);
239 bool _sinkReady =
false;
240 bool _txPending =
false;
241 uint8_t _txRetry = 0;
Minimal interrupt-driven USB-PD sink negotiation state machine.
bool handleIrq(const RequestParams &req, Event &outEvent, SourceCaps *outCaps=nullptr)
Process one TCPC IRQ status sample.
State state() const
Return the current negotiation state.
@ WaitAccept
Request sent; waiting for Accept.
@ Success
Requested contract is ready.
@ WaitPsRdy
Accept received; waiting for PS_RDY.
@ WaitSourceCap
Waiting for Source_Capabilities.
@ Failed
Negotiation failed.
@ Idle
Not initialized or inactive.
bool selectFixedOffer(const SourceCaps &caps, const RequestParams &req, FixedOffer &outOffer)
Select one fixed PDO offer matching the request.
bool hasIrqPin() const
Check whether a valid IRQ pin is configured.
void reset()
Reset message IDs and return to the initial wait state.
bool negotiate(const RequestParams &req, SourceCaps *outCaps=nullptr, uint32_t timeoutMs=6000)
Run a blocking fixed PDO negotiation.
bool setIrqPin(int irqPin)
Configure the PMIC/TCPC IRQ pin used for PD negotiation.
bool requestFromCaps(const SourceCaps &caps, const RequestParams &req)
Send a Request message selected from parsed source capabilities.
bool service(const RequestParams &req, Event &outEvent, SourceCaps *outCaps=nullptr)
Service pending IRQ-driven PD events.
bool parseSourceCaps(const AXP517Tcpc::RxFifoMsg &rx, SourceCaps &outCaps)
Parse fixed PDOs from a Source_Capabilities RX message.
bool initSink(int irqPin)
Initialize the TCPC sink and configure the PD receive path.
bool isDone() const
Check whether negotiation reached a terminal state.
bool isSuccess() const
Check whether negotiation completed successfully.
Event
Event reported by service() and handleIrq().
@ PsRdy
PS_RDY received; contract is active.
@ TxDiscarded
TCPC discarded TX due to RX activity.
@ TxFailed
TCPC reported TX failure.
@ None
No meaningful state change.
@ HardReset
Hard Reset received.
@ RequestSent
Request message transmitted.
@ Accept
Accept control message received.
@ SourceCapabilities
Source_Capabilities received.
@ Reject
Reject control message received.
@ CcDetached
CC or VBUS detach detected.
@ TxSuccess
TCPC reported TX success.
@ CcChanged
CC state changed while attached.
USB-PD message builder and FIFO helper for AXP517.
AXP517 Type-C Port Controller helper.
One fixed supply PDO offered by the source.
uint16_t mv
Fixed supply voltage in millivolts.
uint32_t rawPdo
Raw 32-bit PDO value.
uint8_t pdoIndex1Based
USB-PD object position, 1 through 7.
uint16_t maMax
Maximum current in milliamps.
Requested sink operating point.
bool noUsbSuspend
Set No USB Suspend in the RDO.
uint8_t pdoIndex1Based
Optional explicit source PDO index, 1 through 7.
uint16_t targetMv
Optional fixed PDO voltage to select.
bool usbCommCapable
Set USB Communications Capable in the RDO.
uint16_t maxMa
Optional maximum current; 0 uses opMa.
uint16_t opMa
Optional operating current; 0 uses source maximum.
bool capMismatch
Set Capability Mismatch in the RDO.
Parsed Source_Capabilities message.
uint16_t rawHeaderLE
Raw Source_Capabilities header.
uint8_t totalPdoCount
Total PDO count advertised in the message.
FixedOffer fixed[7]
Parsed fixed PDO offers.
uint8_t fixedCount
Number of valid entries in fixed[].