|
SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
|
USB-PD message builder and FIFO helper for AXP517. More...
#include <AXP517Pd.hpp>
Classes | |
| struct | HeaderInfoCfg |
| Local USB-PD header defaults used for transmitted messages. More... | |
Public Types | |
| enum class | SpecRev : uint8_t { Rev10 = 0 , Rev20 = 1 , Rev30 = 2 } |
| USB-PD specification revision encoded in the message header. More... | |
| enum class | PowerRole : uint8_t { Sink = 0 , Source = 1 } |
| USB-PD power role encoded in the message header. More... | |
| enum class | DataRole : uint8_t { UFP = 0 , DFP = 1 } |
| USB Type-C data role encoded in the message header. More... | |
| enum class | ControlMsg : uint8_t { Accept = 0x03 , PS_RDY = 0x06 , GetSourceCap = 0x07 , SoftReset = 0x0D } |
| Supported USB-PD control message type values. More... | |
Public Member Functions | |
| AXP517Pd (AXP517Tcpc &tcpc) | |
| Construct a PD helper that uses an initialized TCPC instance. | |
| bool | configureHeaderInfo (const HeaderInfoCfg &cfg) |
| Configure local message-header defaults. | |
| bool | setReceiveDetectSop (bool enable) |
| Enable or disable SOP receive detection. | |
| bool | sendGetSourceCap () |
| Send a Get_Source_Cap control message. | |
| bool | sendControl (ControlMsg msgType) |
| Send a USB-PD control message. | |
| bool | sendHardReset () |
| Send a Hard Reset ordered set. | |
| bool | sendRaw (uint8_t msgType, const uint8_t *payload, uint8_t payloadLen) |
| Send a raw USB-PD data message. | |
| bool | tryReceive (AXP517Tcpc::RxFifoMsg &out) |
| Try to read one pending RX FIFO message. | |
| bool | handleFaultOnce (uint8_t &faultStatus) |
| Read and clear one TCPC fault status sample. | |
| void | resetMsgId () |
| Reset the local USB-PD message ID counter to zero. | |
USB-PD message builder and FIFO helper for AXP517.
This class owns only the protocol-level details such as message headers, message IDs, control messages, raw data messages, and TCPC RX/TX FIFO access. It does not run a complete USB-PD policy engine. Use AXP517PdNegotiator for sink voltage negotiation.
Definition at line 44 of file AXP517Pd.hpp.
|
strong |
Supported USB-PD control message type values.
| Enumerator | |
|---|---|
| Accept | Accept control message. |
| PS_RDY | Power Supply Ready control message. |
| GetSourceCap | Get Source Capabilities control message. |
| SoftReset | Soft Reset control message. |
Definition at line 81 of file AXP517Pd.hpp.
|
strong |
USB Type-C data role encoded in the message header.
| Enumerator | |
|---|---|
| UFP | Upstream Facing Port. |
| DFP | Downstream Facing Port. |
Definition at line 73 of file AXP517Pd.hpp.
|
strong |
USB-PD power role encoded in the message header.
| Enumerator | |
|---|---|
| Sink | Sink/UFP consumes VBUS. |
| Source | Source/DFP supplies VBUS. |
Definition at line 65 of file AXP517Pd.hpp.
|
strong |
USB-PD specification revision encoded in the message header.
| Enumerator | |
|---|---|
| Rev10 | USB-PD 1.0. |
| Rev20 | USB-PD 2.0. |
| Rev30 | USB-PD 3.0. |
Definition at line 56 of file AXP517Pd.hpp.
|
inlineexplicit |
Construct a PD helper that uses an initialized TCPC instance.
| tcpc | AXP517 TCPC register/FIFO access object. |
Definition at line 51 of file AXP517Pd.hpp.
| bool AXP517Pd::configureHeaderInfo | ( | const HeaderInfoCfg & | cfg | ) |
Configure local message-header defaults.
| cfg | Header configuration to use for subsequent transmissions. |
| true | on success, false on register access failure. |
Definition at line 36 of file AXP517Pd.cpp.
References DFP, AXP517Pd::HeaderInfoCfg::dr, AXP517Pd::HeaderInfoCfg::pr, Source, AXP517Pd::HeaderInfoCfg::spec, and AXP517Tcpc::writeMessageHeaderInfo().
| bool AXP517Pd::handleFaultOnce | ( | uint8_t & | faultStatus | ) |
Read and clear one TCPC fault status sample.
| faultStatus | Receives the raw FAULT_STATUS register value. |
| true | on success, false on register access failure. |
Definition at line 109 of file AXP517Pd.cpp.
References AXP517Tcpc::clearAlert(), AXP517Tcpc::clearFaultStatus(), AXP517Tcpc::readAlert(), and AXP517Tcpc::readFaultStatus().
|
inline |
Reset the local USB-PD message ID counter to zero.
Call this after Hard Reset because the TCPC hardware resets its GoodCRC counter and software message IDs must be synchronized with that state.
Definition at line 164 of file AXP517Pd.hpp.
Referenced by AXP517PdNegotiator::initSink(), and AXP517PdNegotiator::reset().
| bool AXP517Pd::sendControl | ( | ControlMsg | msgType | ) |
Send a USB-PD control message.
| msgType | Control message type to send. |
| true | on success, false on TX failure. |
Definition at line 68 of file AXP517Pd.cpp.
References AXP517Tcpc::R3, AXP517Tcpc::SOP, and AXP517Tcpc::txSend().
Referenced by sendGetSourceCap().
| bool AXP517Pd::sendGetSourceCap | ( | ) |
Send a Get_Source_Cap control message.
| true | on success, false on TX failure. |
Definition at line 78 of file AXP517Pd.cpp.
References GetSourceCap, and sendControl().
| bool AXP517Pd::sendHardReset | ( | ) |
Send a Hard Reset ordered set.
This uses TCPCI transmit type 5 with no TX buffer payload and retry count 0, matching the vendor Linux driver's TCPC_TX_HARD_RESET path.
| true | on success, false on TX failure. |
Definition at line 83 of file AXP517Pd.cpp.
References AXP517Tcpc::HARD_RESET, AXP517Tcpc::R0, and AXP517Tcpc::txSend().
| bool AXP517Pd::sendRaw | ( | uint8_t | msgType, |
| const uint8_t * | payload, | ||
| uint8_t | payloadLen | ||
| ) |
Send a raw USB-PD data message.
| msgType | USB-PD message type field. |
| payload | Pointer to payload bytes, or nullptr when payloadLen is 0. |
| payloadLen | Payload length in bytes. Data object payloads must be a multiple of 4 bytes. |
| true | on success, false on invalid arguments or TX failure. |
Definition at line 93 of file AXP517Pd.cpp.
References AXP517Tcpc::R3, AXP517Tcpc::SOP, and AXP517Tcpc::txSend().
| bool AXP517Pd::setReceiveDetectSop | ( | bool | enable | ) |
Enable or disable SOP receive detection.
| enable | true to receive SOP messages, false to disable RX detection. |
| true | on success, false on register access failure. |
Definition at line 48 of file AXP517Pd.cpp.
References AXP517Tcpc::writeReceiveDetect().
| bool AXP517Pd::tryReceive | ( | AXP517Tcpc::RxFifoMsg & | out | ) |
Try to read one pending RX FIFO message.
| out | Destination for the decoded TCPC RX FIFO message. |
| true | when a valid message was read, false otherwise. |
Definition at line 104 of file AXP517Pd.cpp.
References AXP517Tcpc::rxReadMessage().