|
SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
|
Minimal interrupt-driven USB-PD sink negotiation state machine. More...
#include <AXP517PdNegotiator.hpp>
Classes | |
| struct | FixedOffer |
| One fixed supply PDO offered by the source. More... | |
| struct | RequestParams |
| Requested sink operating point. More... | |
| struct | SourceCaps |
| Parsed Source_Capabilities message. More... | |
Public Types | |
| enum class | State : uint8_t { Idle , WaitSourceCap , WaitAccept , WaitPsRdy , Success , Failed } |
| Negotiation state. More... | |
| enum class | Event : uint8_t { None , SourceCapabilities , RequestSent , TxSuccess , TxFailed , TxDiscarded , Accept , Reject , PsRdy , HardReset , CcDetached , CcChanged } |
| Event reported by service() and handleIrq(). More... | |
Public Member Functions | |
| AXP517PdNegotiator (AXP517Tcpc &tcpc, AXP517Pd &pd) | |
| Construct a negotiator from the low-level TCPC and PD helpers. | |
| bool | setIrqPin (int irqPin) |
| Configure the PMIC/TCPC IRQ pin used for PD negotiation. | |
| bool | hasIrqPin () const |
| Check whether a valid IRQ pin is configured. | |
| bool | initSink (int irqPin) |
| Initialize the TCPC sink and configure the PD receive path. | |
| bool | negotiate (const RequestParams &req, SourceCaps *outCaps=nullptr, uint32_t timeoutMs=6000) |
| Run a blocking fixed PDO negotiation. | |
| bool | service (const RequestParams &req, Event &outEvent, SourceCaps *outCaps=nullptr) |
| Service pending IRQ-driven PD events. | |
| bool | handleIrq (const RequestParams &req, Event &outEvent, SourceCaps *outCaps=nullptr) |
| Process one TCPC IRQ status sample. | |
| bool | requestFromCaps (const SourceCaps &caps, const RequestParams &req) |
| Send a Request message selected from parsed source capabilities. | |
| bool | parseSourceCaps (const AXP517Tcpc::RxFifoMsg &rx, SourceCaps &outCaps) |
| Parse fixed PDOs from a Source_Capabilities RX message. | |
| bool | selectFixedOffer (const SourceCaps &caps, const RequestParams &req, FixedOffer &outOffer) |
| Select one fixed PDO offer matching the request. | |
| State | state () const |
| Return the current negotiation state. | |
| bool | isSuccess () const |
| Check whether negotiation completed successfully. | |
| bool | isDone () const |
| Check whether negotiation reached a terminal state. | |
| void | reset () |
| Reset message IDs and return to the initial wait state. | |
Minimal interrupt-driven USB-PD sink negotiation state machine.
The AXP517 TCPC delivers USB-PD messages through an IRQ-driven RX FIFO. A valid interrupt pin is therefore required before requesting a PD voltage. This class requests a fixed PDO by voltage or PDO index, waits for Accept and PS_RDY, and exposes parsed source capabilities for diagnostics.
Definition at line 45 of file AXP517PdNegotiator.hpp.
|
strong |
Event reported by service() and handleIrq().
Definition at line 103 of file AXP517PdNegotiator.hpp.
|
strong |
Negotiation state.
Definition at line 91 of file AXP517PdNegotiator.hpp.
|
explicit |
Construct a negotiator from the low-level TCPC and PD helpers.
| tcpc | TCPC register/FIFO access object. |
| pd | USB-PD message helper. |
Definition at line 73 of file AXP517PdNegotiator.cpp.
| bool AXP517PdNegotiator::handleIrq | ( | const RequestParams & | req, |
| Event & | outEvent, | ||
| SourceCaps * | outCaps = nullptr |
||
| ) |
Process one TCPC IRQ status sample.
| req | Requested operating point. |
| outEvent | Receives the event produced by this IRQ sample. |
| outCaps | Optional destination for parsed source capabilities. |
| true | on success, false on register/FIFO access failure. |
Definition at line 201 of file AXP517PdNegotiator.cpp.
References Accept, AXP517Tcpc::AlertCcStatus, AXP517Tcpc::AlertFault, AXP517Tcpc::AlertPowerStatus, AXP517Tcpc::AlertRxHardReset, AXP517Tcpc::AlertRxStatus, AXP517Tcpc::AlertTxDiscarded, AXP517Tcpc::AlertTxFailed, AXP517Tcpc::AlertTxSuccess, AXP517Tcpc::AlertVbusDisconnect, CcChanged, CcDetached, AXP517Tcpc::clearAlert(), AXP517Tcpc::clearAllAlerts(), AXP517Tcpc::clearFaultStatus(), AXP517Tcpc::clearPmicIrqStatus(), AXP517Tcpc::clearTx(), Failed, HardReset, hasIrqPin(), AXP517Tcpc::isAttached(), AXP517Tcpc::isVbusPresent(), usbpd::Header::msgType(), None, usbpd::Header::objCount(), parseSourceCaps(), PsRdy, AXP517Tcpc::readAlert(), AXP517Tcpc::readFaultStatus(), Reject, requestFromCaps(), RequestSent, reset(), AXP517Tcpc::rxReadMessage(), SENSORLIB_LOG_E, AXP517Tcpc::setPolarityFromCc(), AXP517Tcpc::setSinkMessageHeaderAndRx(), SourceCapabilities, Success, TxDiscarded, TxFailed, TxSuccess, WaitAccept, WaitPsRdy, WaitSourceCap, and AXP517Tcpc::writeReceiveDetect().
Referenced by negotiate(), and service().
|
inline |
Check whether a valid IRQ pin is configured.
| true | if an IRQ pin has been configured. |
Definition at line 129 of file AXP517PdNegotiator.hpp.
Referenced by handleIrq(), negotiate(), and service().
| bool AXP517PdNegotiator::initSink | ( | int | irqPin | ) |
Initialize the TCPC sink and configure the PD receive path.
| irqPin | Platform GPIO number connected to PMIC_IRQ. |
| true | on success, false on invalid IRQ pin or TCPC setup failure. |
Definition at line 90 of file AXP517PdNegotiator.cpp.
References AXP517Tcpc::checkVendorId(), AXP517Tcpc::clearPmicIrqStatus(), AXP517Tcpc::init(), AXP517Pd::resetMsgId(), SENSORLIB_LOG_E, setIrqPin(), and WaitSourceCap.
Referenced by PmicAXP517::initPdSink(), and negotiate().
|
inline |
Check whether negotiation reached a terminal state.
Definition at line 215 of file AXP517PdNegotiator.hpp.
References Failed, and Success.
Referenced by negotiate(), and service().
|
inline |
Check whether negotiation completed successfully.
Definition at line 207 of file AXP517PdNegotiator.hpp.
References Success.
Referenced by negotiate().
| bool AXP517PdNegotiator::negotiate | ( | const RequestParams & | req, |
| SourceCaps * | outCaps = nullptr, |
||
| uint32_t | timeoutMs = 6000 |
||
| ) |
Run a blocking fixed PDO negotiation.
| req | Requested operating point. |
| outCaps | Optional destination for parsed source capabilities. |
| timeoutMs | Timeout in milliseconds. |
| true | when a PD contract reaches PS_RDY, false otherwise. |
Definition at line 129 of file AXP517PdNegotiator.cpp.
References AXP517Tcpc::clearPmicIrqStatus(), AXP517Tcpc::delayMs(), AXP517Tcpc::digitalRead(), handleIrq(), hasIrqPin(), AXP517Tcpc::init(), initSink(), isDone(), isSuccess(), AXP517Tcpc::millis(), None, AXP517Tcpc::readAlert(), reset(), SENSORLIB_LOG_E, SENSORLIB_LOG_W, and service().
Referenced by PmicAXP517::requestPd().
| bool AXP517PdNegotiator::parseSourceCaps | ( | const AXP517Tcpc::RxFifoMsg & | rx, |
| SourceCaps & | outCaps | ||
| ) |
Parse fixed PDOs from a Source_Capabilities RX message.
| rx | Raw TCPC RX FIFO message. |
| outCaps | Destination for parsed capabilities. |
| true | when at least one fixed PDO was parsed. |
Definition at line 326 of file AXP517PdNegotiator.cpp.
References AXP517PdNegotiator::SourceCaps::fixed, AXP517PdNegotiator::SourceCaps::fixedCount, AXP517Tcpc::RxFifoMsg::headerLE, i, usbpd::le32(), AXP517PdNegotiator::FixedOffer::maMax, usbpd::Header::msgType(), AXP517PdNegotiator::FixedOffer::mv, usbpd::Header::objCount(), usbpd::parseFixedSourcePdo(), AXP517Tcpc::RxFifoMsg::payload, AXP517Tcpc::RxFifoMsg::payloadLen, AXP517PdNegotiator::FixedOffer::pdoIndex1Based, AXP517PdNegotiator::SourceCaps::rawHeaderLE, AXP517PdNegotiator::FixedOffer::rawPdo, and AXP517PdNegotiator::SourceCaps::totalPdoCount.
Referenced by handleIrq().
| bool AXP517PdNegotiator::requestFromCaps | ( | const SourceCaps & | caps, |
| const RequestParams & | req | ||
| ) |
Send a Request message selected from parsed source capabilities.
| caps | Parsed source capabilities. |
| req | Requested operating point. |
| true | on success, false when no matching offer exists or TX fails. |
Definition at line 385 of file AXP517PdNegotiator.cpp.
References AXP517Tcpc::clearAllAlerts(), AXP517Tcpc::clearTx(), and selectFixedOffer().
Referenced by handleIrq().
| void AXP517PdNegotiator::reset | ( | ) |
Reset message IDs and return to the initial wait state.
Definition at line 121 of file AXP517PdNegotiator.cpp.
References Idle, AXP517Pd::resetMsgId(), and WaitSourceCap.
Referenced by handleIrq(), negotiate(), and resetPdState().
| bool AXP517PdNegotiator::selectFixedOffer | ( | const SourceCaps & | caps, |
| const RequestParams & | req, | ||
| FixedOffer & | outOffer | ||
| ) |
Select one fixed PDO offer matching the request.
| caps | Parsed source capabilities. |
| req | Requested operating point. |
| outOffer | Receives the selected offer. |
| true | when a matching fixed offer was found. |
Definition at line 356 of file AXP517PdNegotiator.cpp.
References AXP517PdNegotiator::SourceCaps::fixed, AXP517PdNegotiator::SourceCaps::fixedCount, i, AXP517PdNegotiator::FixedOffer::mv, AXP517PdNegotiator::FixedOffer::pdoIndex1Based, AXP517PdNegotiator::RequestParams::pdoIndex1Based, and AXP517PdNegotiator::RequestParams::targetMv.
Referenced by requestFromCaps().
| bool AXP517PdNegotiator::service | ( | const RequestParams & | req, |
| Event & | outEvent, | ||
| SourceCaps * | outCaps = nullptr |
||
| ) |
Service pending IRQ-driven PD events.
| req | Requested operating point. |
| outEvent | Receives the most recent negotiator event. |
| outCaps | Optional destination for parsed source capabilities. |
| true | on success, false on register/FIFO access failure. |
Definition at line 174 of file AXP517PdNegotiator.cpp.
References AXP517Tcpc::digitalRead(), handleIrq(), hasIrqPin(), isDone(), None, AXP517Tcpc::readAlert(), and SENSORLIB_LOG_E.
Referenced by negotiate().
| bool AXP517PdNegotiator::setIrqPin | ( | int | irqPin | ) |
Configure the PMIC/TCPC IRQ pin used for PD negotiation.
| irqPin | Platform GPIO number connected to PMIC_IRQ. |
| true | on success, false when irqPin is invalid. |
Definition at line 78 of file AXP517PdNegotiator.cpp.
References AXP517Tcpc::pinMode().
Referenced by initSink(), and PmicAXP517::setPdIrqPin().
|
inline |
Return the current negotiation state.
Definition at line 199 of file AXP517PdNegotiator.hpp.