|
SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
|
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. | |
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.
| enum AXP517Tcpc::Alert : uint16_t |
PD_ALERTL/H bit definitions returned by readAlert().
Definition at line 56 of file AXP517Tcpc.hpp.
|
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.
|
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.
|
strong |
TCPCI TRANSMIT register packet type values.
Definition at line 76 of file AXP517Tcpc.hpp.
|
inlineexplicit |
Construct a TCPC helper using the shared AXP517 core transport.
| core | Initialized AXP517 core communication object. |
Definition at line 51 of file AXP517Tcpc.hpp.
| bool AXP517Tcpc::checkVendorId | ( | ) |
Verify the TCPC vendor ID.
| true | if the vendor ID matches a supported AXP517 TCPC ID. |
Definition at line 144 of file AXP517Tcpc.cpp.
Referenced by AXP517PdNegotiator::initSink().
| bool AXP517Tcpc::clearAlert | ( | uint16_t | maskRw1c | ) |
Clear PD_ALERTL/H bits using write-one-to-clear semantics.
| maskRw1c | Alert bits to clear. |
| true | on success, false on register access failure. |
Definition at line 163 of file AXP517Tcpc.cpp.
Referenced by clearAllAlerts(), AXP517Pd::handleFaultOnce(), and AXP517PdNegotiator::handleIrq().
|
inline |
Clear all PD alert bits.
| true | on success, false on register access failure. |
Definition at line 148 of file AXP517Tcpc.hpp.
References clearAlert().
Referenced by AXP517PdNegotiator::handleIrq(), init(), and AXP517PdNegotiator::requestFromCaps().
| bool AXP517Tcpc::clearFaultStatus | ( | uint8_t | maskRw1c | ) |
Clear TCPC FAULT_STATUS bits using write-one-to-clear semantics.
| maskRw1c | Fault bits to clear. |
| true | on success, false on register access failure. |
Definition at line 174 of file AXP517Tcpc.cpp.
Referenced by AXP517Pd::handleFaultOnce(), and AXP517PdNegotiator::handleIrq().
| bool AXP517Tcpc::clearPmicIrqStatus | ( | ) |
Clear the non-PD PMIC IRQ status registers.
| true | on 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().
| bool AXP517Tcpc::clearTx | ( | ) |
Reset the TX byte count and transmit command register.
| true | on success, false on register access failure. |
Definition at line 199 of file AXP517Tcpc.cpp.
Referenced by AXP517PdNegotiator::handleIrq(), init(), AXP517PdNegotiator::requestFromCaps(), and resetPdState().
|
inline |
Delay using the active platform HAL.
Definition at line 287 of file AXP517Tcpc.hpp.
References AXP517Core::delayMs().
Referenced by AXP517PdNegotiator::negotiate().
|
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().
Read and decode CC1/CC2 status.
| cc1 | Receives decoded CC1 status. |
| cc2 | Receives decoded CC2 status. |
| true | on 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().
| bool AXP517Tcpc::getPowerStatus | ( | uint8_t & | status | ) |
Read POWER_STATUS.
| status | Receives the raw POWER_STATUS register value. |
| true | on success, false on register access failure. |
Definition at line 249 of file AXP517Tcpc.cpp.
Referenced by isVbusPresent().
| bool AXP517Tcpc::init | ( | ) |
Initialize the TCPC as a USB-PD sink.
| true | on 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().
| bool AXP517Tcpc::isAttached | ( | ) |
Check whether either CC pin indicates attachment.
| true | if attached, false if detached or status read fails. |
Definition at line 241 of file AXP517Tcpc.cpp.
Referenced by AXP517PdNegotiator::handleIrq(), isTcpcDetachAlert(), and readStatusSnapshot().
| bool AXP517Tcpc::isVbusPresent | ( | ) |
Check whether TCPC VBUS present status is set.
| true | if VBUS is present, false otherwise. |
Definition at line 254 of file AXP517Tcpc.cpp.
References getPowerStatus().
Referenced by AXP517PdNegotiator::handleIrq(), and isVbusPresentNow().
|
inline |
Return the platform millisecond counter.
Definition at line 281 of file AXP517Tcpc.hpp.
References AXP517Core::millis().
Referenced by AXP517PdNegotiator::negotiate().
|
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().
| bool AXP517Tcpc::readAlert | ( | uint16_t & | out | ) |
Read PD_ALERTL/H.
| out | Receives the 16-bit alert bitmask. |
| true | on 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().
| bool AXP517Tcpc::readFaultStatus | ( | uint8_t & | out | ) |
Read the TCPC FAULT_STATUS register.
| out | Receives the raw fault status value. |
| true | on success, false on register access failure. |
Definition at line 169 of file AXP517Tcpc.cpp.
Referenced by AXP517Pd::handleFaultOnce(), and AXP517PdNegotiator::handleIrq().
|
inline |
Read one TCPC register.
| reg | Register address. |
| out | Receives the register value. |
| true | on success, false on register access failure. |
Definition at line 264 of file AXP517Tcpc.hpp.
| bool AXP517Tcpc::readVbusMv | ( | uint16_t & | mv | ) |
Read TCPC VBUS ADC value.
| mv | Receives VBUS voltage in millivolts. |
| true | on success, false on register access failure. |
Definition at line 261 of file AXP517Tcpc.cpp.
Referenced by isVbusPresentNow(), printVbus(), and readStatusSnapshot().
| bool AXP517Tcpc::rxReadMessage | ( | RxFifoMsg & | out | ) |
Read and decode one TCPC RX FIFO message.
| out | Destination for the decoded message. |
| true | when 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().
| bool AXP517Tcpc::setPolarityFromCc | ( | ) |
Set TCPC polarity from the current CC status.
| true | on success, false on register access failure. |
Definition at line 211 of file AXP517Tcpc.cpp.
Referenced by AXP517PdNegotiator::handleIrq(), and init().
| bool AXP517Tcpc::setSinkMessageHeaderAndRx | ( | ) |
Configure sink message-header defaults and enable SOP RX.
| true | on success, false on register access failure. |
Definition at line 205 of file AXP517Tcpc.cpp.
Referenced by AXP517PdNegotiator::handleIrq(), and init().
| 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.
| type | TCPCI transmit packet type. |
| retry | TCPCI retry count. |
| headerLE | USB-PD message header in little-endian order. |
| payload | Optional payload pointer. |
| payloadLen | Payload length in bytes. |
| true | on 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().
| bool AXP517Tcpc::writeMessageHeaderInfo | ( | uint8_t | v | ) |
Write the TCPCI MESSAGE_HEADER_INFO register.
| v | Raw register value. |
| true | on success, false on register access failure. |
Definition at line 189 of file AXP517Tcpc.cpp.
Referenced by AXP517Pd::configureHeaderInfo().
| bool AXP517Tcpc::writeReceiveDetect | ( | uint8_t | v | ) |
Write the TCPCI RECEIVE_DETECT register.
| v | Raw register value. |
| true | on success, false on register access failure. |
Definition at line 194 of file AXP517Tcpc.cpp.
Referenced by AXP517PdNegotiator::handleIrq(), and AXP517Pd::setReceiveDetectSop().
|
inline |
Write one TCPC register.
| reg | Register address. |
| v | Register value to write. |
| true | on success, false on register access failure. |
Definition at line 275 of file AXP517Tcpc.hpp.