SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
AXP517Pd Class Reference

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.
 

Detailed Description

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.

Member Enumeration Documentation

◆ ControlMsg

enum class AXP517Pd::ControlMsg : uint8_t
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.

◆ DataRole

enum class AXP517Pd::DataRole : uint8_t
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.

◆ PowerRole

enum class AXP517Pd::PowerRole : uint8_t
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.

◆ SpecRev

enum class AXP517Pd::SpecRev : uint8_t
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.

Constructor & Destructor Documentation

◆ AXP517Pd()

AXP517Pd::AXP517Pd ( AXP517Tcpc tcpc)
inlineexplicit

Construct a PD helper that uses an initialized TCPC instance.

Parameters
tcpcAXP517 TCPC register/FIFO access object.

Definition at line 51 of file AXP517Pd.hpp.

Member Function Documentation

◆ configureHeaderInfo()

bool AXP517Pd::configureHeaderInfo ( const HeaderInfoCfg cfg)

Configure local message-header defaults.

Parameters
cfgHeader configuration to use for subsequent transmissions.
Return values
trueon 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().

◆ handleFaultOnce()

bool AXP517Pd::handleFaultOnce ( uint8_t &  faultStatus)

Read and clear one TCPC fault status sample.

Parameters
faultStatusReceives the raw FAULT_STATUS register value.
Return values
trueon success, false on register access failure.

Definition at line 109 of file AXP517Pd.cpp.

References AXP517Tcpc::clearAlert(), AXP517Tcpc::clearFaultStatus(), AXP517Tcpc::readAlert(), and AXP517Tcpc::readFaultStatus().

◆ resetMsgId()

void AXP517Pd::resetMsgId ( )
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().

◆ sendControl()

bool AXP517Pd::sendControl ( ControlMsg  msgType)

Send a USB-PD control message.

Parameters
msgTypeControl message type to send.
Return values
trueon success, false on TX failure.

Definition at line 68 of file AXP517Pd.cpp.

References AXP517Tcpc::R3, AXP517Tcpc::SOP, and AXP517Tcpc::txSend().

Referenced by sendGetSourceCap().

◆ sendGetSourceCap()

bool AXP517Pd::sendGetSourceCap ( )

Send a Get_Source_Cap control message.

Return values
trueon success, false on TX failure.

Definition at line 78 of file AXP517Pd.cpp.

References GetSourceCap, and sendControl().

◆ sendHardReset()

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.

Return values
trueon success, false on TX failure.

Definition at line 83 of file AXP517Pd.cpp.

References AXP517Tcpc::HARD_RESET, AXP517Tcpc::R0, and AXP517Tcpc::txSend().

◆ sendRaw()

bool AXP517Pd::sendRaw ( uint8_t  msgType,
const uint8_t *  payload,
uint8_t  payloadLen 
)

Send a raw USB-PD data message.

Parameters
msgTypeUSB-PD message type field.
payloadPointer to payload bytes, or nullptr when payloadLen is 0.
payloadLenPayload length in bytes. Data object payloads must be a multiple of 4 bytes.
Return values
trueon success, false on invalid arguments or TX failure.

Definition at line 93 of file AXP517Pd.cpp.

References AXP517Tcpc::R3, AXP517Tcpc::SOP, and AXP517Tcpc::txSend().

◆ setReceiveDetectSop()

bool AXP517Pd::setReceiveDetectSop ( bool  enable)

Enable or disable SOP receive detection.

Parameters
enabletrue to receive SOP messages, false to disable RX detection.
Return values
trueon success, false on register access failure.

Definition at line 48 of file AXP517Pd.cpp.

References AXP517Tcpc::writeReceiveDetect().

◆ tryReceive()

bool AXP517Pd::tryReceive ( AXP517Tcpc::RxFifoMsg out)

Try to read one pending RX FIFO message.

Parameters
outDestination for the decoded TCPC RX FIFO message.
Return values
truewhen a valid message was read, false otherwise.

Definition at line 104 of file AXP517Pd.cpp.

References AXP517Tcpc::rxReadMessage().


The documentation for this class was generated from the following files: