ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
esphome::fusb302b::PowerDelivery Class Referenceabstract

USB-PD sink protocol logic, independent of the PHY chip. More...

#include <pd.h>

Inheritance diagram for esphome::fusb302b::PowerDelivery:
esphome::fusb302b::FUSB302B

Public Member Functions

void set_request_voltage (uint8_t voltage)
 
uint8_t get_request_voltage () const
 
PdState get_state () const
 
bool is_connected () const
 

Protected Member Functions

virtual bool send_message (const PdMsg &msg)=0
 Returns false when the message could not be handed to the chip; the PHY logs the failure.
 
virtual void on_state_changed ()=0
 Called after state_ or contract_ changed, to let the main loop publish it.
 
virtual void on_soft_reset_received ()=0
 Called after the source soft reset the protocol; it sends new source capabilities next.
 
virtual void on_source_caps_received ()=0
 Called when source capabilities arrive, before the request for them is sent.
 
virtual void on_transition_timeout ()=0
 Called after an accepted request was not followed by PS_RDY in time and the state fell back to default power; the PHY sends a soft reset so the source offers its capabilities again.
 
virtual void on_request_failed ()=0
 Called when a request ended without a new contract: it was rejected, the source kept answering Wait or did not answer in time, or it could not be sent.
 
void handle_message_ (const PdMsg &msg)
 
void handle_transmit_failed_ ()
 Called by the PHY when the chip gave up on a message after its retries without receiving a GoodCRC.
 
void reset_protocol_ ()
 
void set_state_ (PdState state)
 
void set_contract_ (const PdContract &contract)
 
void clear_contract_ ()
 
void set_state_and_contract_ (PdState state, const PdContract &contract)
 Stores both before calling on_state_changed() once, so the main loop never sees the new state with the old contract.
 
void set_ams_ (bool active)
 
bool check_ams_ ()
 Returns true while an atomic message sequence is in progress.
 
void check_transition_timeout_ ()
 Falls back to default power when the source accepted a request but did not report the new supply ready in time.
 
void check_request_retry_ ()
 Sends the last request again once tSinkRequest has passed after the source answered Wait.
 
PdMsg make_control_msg_ (PdControlMsgType type) const
 
PdMsg make_data_msg_ (PdDataMsgType type, const uint32_t *objects, uint8_t len) const
 

Protected Attributes

std::atomic< PdState > state_ {PdState::PD_STATE_DISCONNECTED}
 
std::atomic< uint32_t > contract_ {0}
 
std::atomic< uint8_t > request_voltage_ {5}
 
uint32_t ams_start_ {0}
 
uint32_t wait_received_ms_ {0}
 
bool retry_request_pending_ {false}
 

Detailed Description

USB-PD sink protocol logic, independent of the PHY chip.

Everything except the getters and set_request_voltage() runs in the PHY task, which must also call check_transition_timeout_() and check_request_retry_() regularly; the protocol has no timers of its own.

Definition at line 106 of file pd.h.

Member Function Documentation

◆ check_ams_()

bool esphome::fusb302b::PowerDelivery::check_ams_ ( )
protected

Returns true while an atomic message sequence is in progress.

Ends it after a timeout, which fails the request unless the source already accepted a new contract.

Definition at line 116 of file pd.cpp.

◆ check_request_retry_()

void esphome::fusb302b::PowerDelivery::check_request_retry_ ( )
protected

Sends the last request again once tSinkRequest has passed after the source answered Wait.

Definition at line 128 of file pd.cpp.

◆ check_transition_timeout_()

void esphome::fusb302b::PowerDelivery::check_transition_timeout_ ( )
protected

Falls back to default power when the source accepted a request but did not report the new supply ready in time.

Definition at line 160 of file pd.cpp.

◆ clear_contract_()

void esphome::fusb302b::PowerDelivery::clear_contract_ ( )
protected

Definition at line 92 of file pd.cpp.

◆ get_request_voltage()

uint8_t esphome::fusb302b::PowerDelivery::get_request_voltage ( ) const
inline

Definition at line 111 of file pd.h.

◆ get_state()

PdState esphome::fusb302b::PowerDelivery::get_state ( ) const
inline

Definition at line 113 of file pd.h.

◆ handle_message_()

void esphome::fusb302b::PowerDelivery::handle_message_ ( const PdMsg & msg)
protected

Definition at line 176 of file pd.cpp.

◆ handle_transmit_failed_()

void esphome::fusb302b::PowerDelivery::handle_transmit_failed_ ( )
protected

Called by the PHY when the chip gave up on a message after its retries without receiving a GoodCRC.

Definition at line 169 of file pd.cpp.

◆ is_connected()

bool esphome::fusb302b::PowerDelivery::is_connected ( ) const
inline

Definition at line 114 of file pd.h.

◆ make_control_msg_()

PdMsg esphome::fusb302b::PowerDelivery::make_control_msg_ ( PdControlMsgType type) const
protected

Definition at line 55 of file pd.cpp.

◆ make_data_msg_()

PdMsg esphome::fusb302b::PowerDelivery::make_data_msg_ ( PdDataMsgType type,
const uint32_t * objects,
uint8_t len ) const
protected

Definition at line 62 of file pd.cpp.

◆ on_request_failed()

virtual void esphome::fusb302b::PowerDelivery::on_request_failed ( )
protectedpure virtual

Called when a request ended without a new contract: it was rejected, the source kept answering Wait or did not answer in time, or it could not be sent.

A contract already in place stays valid.

Implemented in esphome::fusb302b::FUSB302B.

◆ on_soft_reset_received()

virtual void esphome::fusb302b::PowerDelivery::on_soft_reset_received ( )
protectedpure virtual

Called after the source soft reset the protocol; it sends new source capabilities next.

Implemented in esphome::fusb302b::FUSB302B.

◆ on_source_caps_received()

virtual void esphome::fusb302b::PowerDelivery::on_source_caps_received ( )
protectedpure virtual

Called when source capabilities arrive, before the request for them is sent.

Implemented in esphome::fusb302b::FUSB302B.

◆ on_state_changed()

virtual void esphome::fusb302b::PowerDelivery::on_state_changed ( )
protectedpure virtual

Called after state_ or contract_ changed, to let the main loop publish it.

Implemented in esphome::fusb302b::FUSB302B.

◆ on_transition_timeout()

virtual void esphome::fusb302b::PowerDelivery::on_transition_timeout ( )
protectedpure virtual

Called after an accepted request was not followed by PS_RDY in time and the state fell back to default power; the PHY sends a soft reset so the source offers its capabilities again.

Implemented in esphome::fusb302b::FUSB302B.

◆ reset_protocol_()

void esphome::fusb302b::PowerDelivery::reset_protocol_ ( )
protected

Definition at line 71 of file pd.cpp.

◆ send_message()

virtual bool esphome::fusb302b::PowerDelivery::send_message ( const PdMsg & msg)
protectedpure virtual

Returns false when the message could not be handed to the chip; the PHY logs the failure.

Implemented in esphome::fusb302b::FUSB302B.

◆ set_ams_()

void esphome::fusb302b::PowerDelivery::set_ams_ ( bool active)
protected

Definition at line 108 of file pd.cpp.

◆ set_contract_()

void esphome::fusb302b::PowerDelivery::set_contract_ ( const PdContract & contract)
protected

Definition at line 85 of file pd.cpp.

◆ set_request_voltage()

void esphome::fusb302b::PowerDelivery::set_request_voltage ( uint8_t voltage)
inline

Definition at line 108 of file pd.h.

◆ set_state_()

void esphome::fusb302b::PowerDelivery::set_state_ ( PdState state)
protected

Definition at line 80 of file pd.cpp.

◆ set_state_and_contract_()

void esphome::fusb302b::PowerDelivery::set_state_and_contract_ ( PdState state,
const PdContract & contract )
protected

Stores both before calling on_state_changed() once, so the main loop never sees the new state with the old contract.

Definition at line 98 of file pd.cpp.

Field Documentation

◆ ams_start_

uint32_t esphome::fusb302b::PowerDelivery::ams_start_ {0}
protected

Definition at line 160 of file pd.h.

◆ contract_

std::atomic<uint32_t> esphome::fusb302b::PowerDelivery::contract_ {0}
protected

Definition at line 156 of file pd.h.

◆ request_voltage_

std::atomic<uint8_t> esphome::fusb302b::PowerDelivery::request_voltage_ {5}
protected

Definition at line 157 of file pd.h.

◆ retry_request_pending_

bool esphome::fusb302b::PowerDelivery::retry_request_pending_ {false}
protected

Definition at line 162 of file pd.h.

◆ state_

std::atomic<PdState> esphome::fusb302b::PowerDelivery::state_ {PdState::PD_STATE_DISCONNECTED}
protected

Definition at line 155 of file pd.h.

◆ wait_received_ms_

uint32_t esphome::fusb302b::PowerDelivery::wait_received_ms_ {0}
protected

Definition at line 161 of file pd.h.


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