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

AXP517 Type-C Port Controller helper. More...

#include <AXP517Tcpc.hpp>

Classes

struct  RxFifoMsg
 Decoded RX FIFO message. More...
 

Public Types

enum  Alert : uint16_t {
  AlertCcStatus = (1u << 0) , AlertPowerStatus = (1u << 1) , AlertRxStatus = (1u << 2) , AlertRxHardReset = (1u << 3) ,
  AlertTxFailed = (1u << 4) , AlertTxDiscarded = (1u << 5) , AlertTxSuccess = (1u << 6) , AlertVbusAlarmHi = (1u << 7) ,
  AlertVbusAlarmLo = (1u << 8) , AlertFault = (1u << 9) , AlertRxBufOverflow = (1u << 10) , AlertVbusDisconnect = (1u << 11) ,
  AlertExtendedStatus = (1u << 13) , AlertExtended = (1u << 14)
}
 PD_ALERTL/H bit definitions returned by readAlert(). More...
 
enum class  TransmitType : uint8_t {
  SOP = 0 , SOP_PRIME = 1 , SOP_DPRIME = 2 , SOP_DBG_PRIME = 3 ,
  SOP_DBG_DPRIME = 4 , HARD_RESET = 5 , CABLE_RESET = 6 , BIST_CARRIER_MODE2 = 7
}
 TCPCI TRANSMIT register packet type values. More...
 
enum class  RetryCount : uint8_t { R0 = 0 , R1 = 1 , R2 = 2 , R3 = 3 }
 TCPCI transmit retry count values. More...
 
enum class  CcStatus : uint8_t { OPEN = 0 , RP_DEF , RP_1_5 , RP_3_0 }
 Decoded sink-side CC status. More...
 

Public Member Functions

 AXP517Tcpc (AXP517Core &core)
 Construct a TCPC helper using the shared AXP517 core transport.
 
bool init ()
 Initialize the TCPC as a USB-PD sink.
 
bool checkVendorId ()
 Verify the TCPC vendor ID.
 
bool readAlert (uint16_t &out)
 Read PD_ALERTL/H.
 
bool clearAlert (uint16_t maskRw1c)
 Clear PD_ALERTL/H bits using write-one-to-clear semantics.
 
bool clearAllAlerts ()
 Clear all PD alert bits.
 
bool readFaultStatus (uint8_t &out)
 Read the TCPC FAULT_STATUS register.
 
bool clearFaultStatus (uint8_t maskRw1c)
 Clear TCPC FAULT_STATUS bits using write-one-to-clear semantics.
 
bool clearPmicIrqStatus ()
 Clear the non-PD PMIC IRQ status registers.
 
bool writeMessageHeaderInfo (uint8_t v)
 Write the TCPCI MESSAGE_HEADER_INFO register.
 
bool writeReceiveDetect (uint8_t v)
 Write the TCPCI RECEIVE_DETECT register.
 
bool clearTx ()
 Reset the TX byte count and transmit command register.
 
bool setSinkMessageHeaderAndRx ()
 Configure sink message-header defaults and enable SOP RX.
 
bool setPolarityFromCc ()
 Set TCPC polarity from the current CC status.
 
bool getCc (CcStatus &cc1, CcStatus &cc2)
 Read and decode CC1/CC2 status.
 
bool isAttached ()
 Check whether either CC pin indicates attachment.
 
bool getPowerStatus (uint8_t &status)
 Read POWER_STATUS.
 
bool isVbusPresent ()
 Check whether TCPC VBUS present status is set.
 
bool readVbusMv (uint16_t &mv)
 Read TCPC VBUS ADC value.
 
bool rxReadMessage (RxFifoMsg &out)
 Read and decode one TCPC RX FIFO message.
 
bool txSend (TransmitType type, RetryCount retry, uint16_t headerLE, const uint8_t *payload, uint8_t payloadLen)
 Send a USB-PD packet through the TCPC TX FIFO.
 
bool readReg (uint8_t reg, uint8_t &out)
 Read one TCPC register.
 
bool writeReg (uint8_t reg, uint8_t v)
 Write one TCPC register.
 
uint32_t millis ()
 Return the platform millisecond counter.
 
void delayMs (uint32_t ms)
 Delay using the active platform HAL.
 
void pinMode (uint8_t pin, uint8_t mode)
 Configure a platform GPIO pin through the active HAL.
 
uint8_t digitalRead (uint8_t pin)
 Read a platform GPIO pin through the active HAL.
 

Detailed Description

AXP517 Type-C Port Controller helper.

This class provides direct access to the AXP517 TCPC registers, alert handling, CC/VBUS status, and PD RX/TX FIFOs. It intentionally stays close to the TCPCI register model; policy decisions such as selecting a PDO are implemented in AXP517PdNegotiator.

Definition at line 44 of file AXP517Tcpc.hpp.

Member Enumeration Documentation

◆ Alert

enum AXP517Tcpc::Alert : uint16_t

PD_ALERTL/H bit definitions returned by readAlert().

Enumerator
AlertCcStatus 

CC_STATUS register changed.

AlertPowerStatus 

POWER_STATUS register changed.

AlertRxStatus 

RX buffer contains a SOP message.

AlertRxHardReset 

Hard Reset received.

AlertTxFailed 

Message transmission failed.

AlertTxDiscarded 

Transmission discarded due to RX activity.

AlertTxSuccess 

Message transmission completed.

AlertVbusAlarmHi 

VBUS high-voltage alarm.

AlertVbusAlarmLo 

VBUS low-voltage alarm.

AlertFault 

TCPC fault status changed.

AlertRxBufOverflow 

RX buffer overflow.

AlertVbusDisconnect 

VBUS sink disconnect threshold crossed.

AlertExtendedStatus 

EXTENDED_STATUS register changed.

AlertExtended 

ALERT_EXTENDED register changed.

Definition at line 56 of file AXP517Tcpc.hpp.

◆ CcStatus

enum class AXP517Tcpc::CcStatus : uint8_t
strong

Decoded sink-side CC status.

Enumerator
OPEN 

No source detected on this CC pin.

RP_DEF 

Default USB current advertisement.

RP_1_5 

1.5 A current advertisement.

RP_3_0 

3.0 A current advertisement.

Definition at line 100 of file AXP517Tcpc.hpp.

◆ RetryCount

enum class AXP517Tcpc::RetryCount : uint8_t
strong

TCPCI transmit retry count values.

Enumerator
R0 

No retry.

R1 

One retry.

R2 

Two retries.

R3 

Three retries.

Definition at line 90 of file AXP517Tcpc.hpp.

◆ TransmitType

enum class AXP517Tcpc::TransmitType : uint8_t
strong

TCPCI TRANSMIT register packet type values.

Enumerator
SOP 

SOP packet.

SOP_PRIME 

SOP' packet.

SOP_DPRIME 

SOP'' packet.

SOP_DBG_PRIME 

Debug SOP' packet.

SOP_DBG_DPRIME 

Debug SOP'' packet.

HARD_RESET 

Hard Reset ordered set.

CABLE_RESET 

Cable Reset ordered set.

BIST_CARRIER_MODE2 

BIST carrier mode 2.

Definition at line 76 of file AXP517Tcpc.hpp.

Constructor & Destructor Documentation

◆ AXP517Tcpc()

AXP517Tcpc::AXP517Tcpc ( AXP517Core core)
inlineexplicit

Construct a TCPC helper using the shared AXP517 core transport.

Parameters
coreInitialized AXP517 core communication object.

Definition at line 51 of file AXP517Tcpc.hpp.

Member Function Documentation

◆ checkVendorId()

bool AXP517Tcpc::checkVendorId ( )

Verify the TCPC vendor ID.

Return values
trueif the vendor ID matches a supported AXP517 TCPC ID.

Definition at line 144 of file AXP517Tcpc.cpp.

Referenced by AXP517PdNegotiator::initSink().

◆ clearAlert()

bool AXP517Tcpc::clearAlert ( uint16_t  maskRw1c)

Clear PD_ALERTL/H bits using write-one-to-clear semantics.

Parameters
maskRw1cAlert bits to clear.
Return values
trueon success, false on register access failure.

Definition at line 163 of file AXP517Tcpc.cpp.

Referenced by clearAllAlerts(), AXP517Pd::handleFaultOnce(), and AXP517PdNegotiator::handleIrq().

◆ clearAllAlerts()

bool AXP517Tcpc::clearAllAlerts ( )
inline

Clear all PD alert bits.

Return values
trueon success, false on register access failure.

Definition at line 148 of file AXP517Tcpc.hpp.

References clearAlert().

Referenced by AXP517PdNegotiator::handleIrq(), init(), and AXP517PdNegotiator::requestFromCaps().

◆ clearFaultStatus()

bool AXP517Tcpc::clearFaultStatus ( uint8_t  maskRw1c)

Clear TCPC FAULT_STATUS bits using write-one-to-clear semantics.

Parameters
maskRw1cFault bits to clear.
Return values
trueon success, false on register access failure.

Definition at line 174 of file AXP517Tcpc.cpp.

Referenced by AXP517Pd::handleFaultOnce(), and AXP517PdNegotiator::handleIrq().

◆ clearPmicIrqStatus()

bool AXP517Tcpc::clearPmicIrqStatus ( )

Clear the non-PD PMIC IRQ status registers.

Return values
trueon success, false on register access failure.

Definition at line 179 of file AXP517Tcpc.cpp.

References axp517_regs::irq::STATUS0, and axp517_regs::irq::STATUS3.

Referenced by AXP517PdNegotiator::handleIrq(), AXP517PdNegotiator::initSink(), and AXP517PdNegotiator::negotiate().

◆ clearTx()

bool AXP517Tcpc::clearTx ( )

Reset the TX byte count and transmit command register.

Return values
trueon success, false on register access failure.

Definition at line 199 of file AXP517Tcpc.cpp.

Referenced by AXP517PdNegotiator::handleIrq(), init(), AXP517PdNegotiator::requestFromCaps(), and resetPdState().

◆ delayMs()

void AXP517Tcpc::delayMs ( uint32_t  ms)
inline

Delay using the active platform HAL.

Definition at line 287 of file AXP517Tcpc.hpp.

References AXP517Core::delayMs().

Referenced by AXP517PdNegotiator::negotiate().

◆ digitalRead()

uint8_t AXP517Tcpc::digitalRead ( uint8_t  pin)
inline

Read a platform GPIO pin through the active HAL.

Definition at line 299 of file AXP517Tcpc.hpp.

References AXP517Core::digitalRead().

Referenced by AXP517PdNegotiator::negotiate(), and AXP517PdNegotiator::service().

◆ getCc()

bool AXP517Tcpc::getCc ( CcStatus cc1,
CcStatus cc2 
)

Read and decode CC1/CC2 status.

Parameters
cc1Receives decoded CC1 status.
cc2Receives decoded CC2 status.
Return values
trueon success, false on register access failure.

Definition at line 221 of file AXP517Tcpc.cpp.

References OPEN, RP_1_5, RP_3_0, and RP_DEF.

Referenced by isAttached().

◆ getPowerStatus()

bool AXP517Tcpc::getPowerStatus ( uint8_t &  status)

Read POWER_STATUS.

Parameters
statusReceives the raw POWER_STATUS register value.
Return values
trueon success, false on register access failure.

Definition at line 249 of file AXP517Tcpc.cpp.

Referenced by isVbusPresent().

◆ init()

bool AXP517Tcpc::init ( )

Initialize the TCPC as a USB-PD sink.

Return values
trueon success, false on register access or TCPC init failure.

Definition at line 84 of file AXP517Tcpc.cpp.

References clearAllAlerts(), clearTx(), AXP517Core::delayMs(), axp517_regs::adc::ENABLE, AXP517Core::enableModule(), i, setPolarityFromCc(), setSinkMessageHeaderAndRx(), and AXP517Core::TYPEC.

Referenced by AXP517PdNegotiator::initSink(), and AXP517PdNegotiator::negotiate().

◆ isAttached()

bool AXP517Tcpc::isAttached ( )

Check whether either CC pin indicates attachment.

Return values
trueif attached, false if detached or status read fails.

Definition at line 241 of file AXP517Tcpc.cpp.

References getCc(), and OPEN.

Referenced by AXP517PdNegotiator::handleIrq(), isTcpcDetachAlert(), and readStatusSnapshot().

◆ isVbusPresent()

bool AXP517Tcpc::isVbusPresent ( )

Check whether TCPC VBUS present status is set.

Return values
trueif VBUS is present, false otherwise.

Definition at line 254 of file AXP517Tcpc.cpp.

References getPowerStatus().

Referenced by AXP517PdNegotiator::handleIrq(), and isVbusPresentNow().

◆ millis()

uint32_t AXP517Tcpc::millis ( )
inline

Return the platform millisecond counter.

Definition at line 281 of file AXP517Tcpc.hpp.

References AXP517Core::millis().

Referenced by AXP517PdNegotiator::negotiate().

◆ pinMode()

void AXP517Tcpc::pinMode ( uint8_t  pin,
uint8_t  mode 
)
inline

Configure a platform GPIO pin through the active HAL.

Definition at line 293 of file AXP517Tcpc.hpp.

References AXP517Core::pinMode().

Referenced by AXP517PdNegotiator::setIrqPin().

◆ readAlert()

bool AXP517Tcpc::readAlert ( uint16_t &  out)

Read PD_ALERTL/H.

Parameters
outReceives the 16-bit alert bitmask.
Return values
trueon success, false on register access failure.

Definition at line 154 of file AXP517Tcpc.cpp.

Referenced by AXP517Pd::handleFaultOnce(), AXP517PdNegotiator::handleIrq(), AXP517PdNegotiator::negotiate(), and AXP517PdNegotiator::service().

◆ readFaultStatus()

bool AXP517Tcpc::readFaultStatus ( uint8_t &  out)

Read the TCPC FAULT_STATUS register.

Parameters
outReceives the raw fault status value.
Return values
trueon success, false on register access failure.

Definition at line 169 of file AXP517Tcpc.cpp.

Referenced by AXP517Pd::handleFaultOnce(), and AXP517PdNegotiator::handleIrq().

◆ readReg()

bool AXP517Tcpc::readReg ( uint8_t  reg,
uint8_t &  out 
)
inline

Read one TCPC register.

Parameters
regRegister address.
outReceives the register value.
Return values
trueon success, false on register access failure.

Definition at line 264 of file AXP517Tcpc.hpp.

◆ readVbusMv()

bool AXP517Tcpc::readVbusMv ( uint16_t &  mv)

Read TCPC VBUS ADC value.

Parameters
mvReceives VBUS voltage in millivolts.
Return values
trueon success, false on register access failure.

Definition at line 261 of file AXP517Tcpc.cpp.

Referenced by isVbusPresentNow(), printVbus(), and readStatusSnapshot().

◆ rxReadMessage()

bool AXP517Tcpc::rxReadMessage ( RxFifoMsg out)

Read and decode one TCPC RX FIFO message.

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

Definition at line 272 of file AXP517Tcpc.cpp.

References buf, AXP517Tcpc::RxFifoMsg::byteCount, AXP517Tcpc::RxFifoMsg::frameType, AXP517Tcpc::RxFifoMsg::headerLE, i, AXP517Tcpc::RxFifoMsg::payload, and AXP517Tcpc::RxFifoMsg::payloadLen.

Referenced by AXP517PdNegotiator::handleIrq(), and AXP517Pd::tryReceive().

◆ setPolarityFromCc()

bool AXP517Tcpc::setPolarityFromCc ( )

Set TCPC polarity from the current CC status.

Return values
trueon success, false on register access failure.

Definition at line 211 of file AXP517Tcpc.cpp.

Referenced by AXP517PdNegotiator::handleIrq(), and init().

◆ setSinkMessageHeaderAndRx()

bool AXP517Tcpc::setSinkMessageHeaderAndRx ( )

Configure sink message-header defaults and enable SOP RX.

Return values
trueon success, false on register access failure.

Definition at line 205 of file AXP517Tcpc.cpp.

Referenced by AXP517PdNegotiator::handleIrq(), and init().

◆ txSend()

bool AXP517Tcpc::txSend ( TransmitType  type,
RetryCount  retry,
uint16_t  headerLE,
const uint8_t *  payload,
uint8_t  payloadLen 
)

Send a USB-PD packet through the TCPC TX FIFO.

Parameters
typeTCPCI transmit packet type.
retryTCPCI retry count.
headerLEUSB-PD message header in little-endian order.
payloadOptional payload pointer.
payloadLenPayload length in bytes.
Return values
trueon success, false on invalid arguments or register access failure.

Definition at line 298 of file AXP517Tcpc.cpp.

References buf, CABLE_RESET, HARD_RESET, and i.

Referenced by AXP517Pd::sendControl(), AXP517Pd::sendHardReset(), and AXP517Pd::sendRaw().

◆ writeMessageHeaderInfo()

bool AXP517Tcpc::writeMessageHeaderInfo ( uint8_t  v)

Write the TCPCI MESSAGE_HEADER_INFO register.

Parameters
vRaw register value.
Return values
trueon success, false on register access failure.

Definition at line 189 of file AXP517Tcpc.cpp.

Referenced by AXP517Pd::configureHeaderInfo().

◆ writeReceiveDetect()

bool AXP517Tcpc::writeReceiveDetect ( uint8_t  v)

Write the TCPCI RECEIVE_DETECT register.

Parameters
vRaw register value.
Return values
trueon success, false on register access failure.

Definition at line 194 of file AXP517Tcpc.cpp.

Referenced by AXP517PdNegotiator::handleIrq(), and AXP517Pd::setReceiveDetectSop().

◆ writeReg()

bool AXP517Tcpc::writeReg ( uint8_t  reg,
uint8_t  v 
)
inline

Write one TCPC register.

Parameters
regRegister address.
vRegister value to write.
Return values
trueon success, false on register access failure.

Definition at line 275 of file AXP517Tcpc.hpp.


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