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

USB Power Delivery protocol helper definitions. More...

Classes

struct  FixedSourcePdo
 Parsed fixed source PDO fields. More...
 
struct  Header
 USB-PD 16-bit message header wrapper. More...
 

Enumerations

enum class  SpecRev : uint8_t { Rev10 = 0 , Rev20 = 1 , Rev30 = 2 }
 USB-PD specification revision values used in message headers. More...
 
enum class  ControlMsg : uint8_t {
  GoodCRC = 0x01 , GotoMin = 0x02 , Accept = 0x03 , Reject = 0x04 ,
  Ping = 0x05 , PS_RDY = 0x06 , GetSourceCap = 0x07 , GetSinkCap = 0x08 ,
  DR_Swap = 0x09 , PR_Swap = 0x0A , VCONN_Swap = 0x0B , Wait = 0x0C ,
  SoftReset = 0x0D
}
 USB-PD control message type field values. More...
 
enum class  DataMsg : uint8_t {
  SourceCapabilities = 0x01 , Request = 0x02 , BIST = 0x03 , SinkCapabilities = 0x04 ,
  VendorDefined = 0x0F
}
 USB-PD data message type field values. More...
 
enum class  PdoType : uint8_t { Fixed = 0b00 , Battery = 0b01 , Variable = 0b10 , Augmented = 0b11 }
 USB-PD Power Data Object type. More...
 

Functions

uint16_t le16 (const uint8_t *p)
 Read a 16-bit little-endian integer from a byte buffer.
 
uint32_t le32 (const uint8_t *p)
 Read a 32-bit little-endian integer from a byte buffer.
 
void wr_le16 (uint8_t *p, uint16_t v)
 Write a 16-bit value to a byte buffer in little-endian order.
 
void wr_le32 (uint8_t *p, uint32_t v)
 Write a 32-bit value to a byte buffer in little-endian order.
 
uint16_t buildControlHeader (ControlMsg type, uint8_t msgId, bool powerRoleSource, bool dataRoleDfp, SpecRev specRev)
 Build a USB-PD control message header.
 
uint16_t buildDataHeader (DataMsg type, uint8_t objCount, uint8_t msgId, bool powerRoleSource, bool dataRoleDfp, SpecRev specRev)
 Build a USB-PD data message header.
 
PdoType pdoType (uint32_t pdo)
 Return the type field of a raw PDO.
 
bool parseFixedSourcePdo (uint32_t pdo, FixedSourcePdo &out)
 Parse a fixed source PDO.
 
uint32_t buildRdoFixedCurrent (uint8_t objectPos1based, uint16_t opMa, uint16_t maxMa, bool capMismatch=false, bool usbCommCapable=true, bool noUsbSuspend=true)
 Build a fixed-current Request Data Object.
 

Detailed Description

USB Power Delivery protocol helper definitions.

Enumeration Type Documentation

◆ ControlMsg

enum class usbpd::ControlMsg : uint8_t
strong

USB-PD control message type field values.

Enumerator
GoodCRC 

GoodCRC.

GotoMin 

GotoMin.

Accept 

Accept.

Reject 

Reject.

Ping 

Ping.

PS_RDY 

Power Supply Ready.

GetSourceCap 

Get Source Capabilities.

GetSinkCap 

Get Sink Capabilities.

DR_Swap 

Data Role Swap.

PR_Swap 

Power Role Swap.

VCONN_Swap 

VCONN Swap.

Wait 

Wait.

SoftReset 

Soft Reset.

Definition at line 201 of file UsbPdDefs.hpp.

◆ DataMsg

enum class usbpd::DataMsg : uint8_t
strong

USB-PD data message type field values.

Enumerator
SourceCapabilities 

Source_Capabilities.

Request 

Request.

BIST 

Built-In Self Test.

SinkCapabilities 

Sink_Capabilities.

VendorDefined 

Vendor Defined Message.

Definition at line 220 of file UsbPdDefs.hpp.

◆ PdoType

enum class usbpd::PdoType : uint8_t
strong

USB-PD Power Data Object type.

Enumerator
Fixed 

Fixed supply PDO.

Battery 

Battery supply PDO.

Variable 

Variable supply PDO.

Augmented 

Augmented PDO.

Definition at line 289 of file UsbPdDefs.hpp.

◆ SpecRev

enum class usbpd::SpecRev : uint8_t
strong

USB-PD specification revision values used in message headers.

Enumerator
Rev10 

USB-PD 1.0.

Rev20 

USB-PD 2.0.

Rev30 

USB-PD 3.0.

Definition at line 192 of file UsbPdDefs.hpp.

Function Documentation

◆ buildControlHeader()

uint16_t usbpd::buildControlHeader ( ControlMsg  type,
uint8_t  msgId,
bool  powerRoleSource,
bool  dataRoleDfp,
SpecRev  specRev 
)
inline

Build a USB-PD control message header.

Parameters
typeControl message type.
msgIdThree-bit USB-PD message ID.
powerRoleSourcetrue for Source, false for Sink.
dataRoleDfptrue for DFP, false for UFP.
specRevUSB-PD specification revision.
Returns
Encoded 16-bit USB-PD header.

Definition at line 237 of file UsbPdDefs.hpp.

References usbpd::Header::setExtended().

◆ buildDataHeader()

uint16_t usbpd::buildDataHeader ( DataMsg  type,
uint8_t  objCount,
uint8_t  msgId,
bool  powerRoleSource,
bool  dataRoleDfp,
SpecRev  specRev 
)
inline

Build a USB-PD data message header.

Parameters
typeData message type.
objCountNumber of 32-bit data objects.
msgIdThree-bit USB-PD message ID.
powerRoleSourcetrue for Source, false for Sink.
dataRoleDfptrue for DFP, false for UFP.
specRevUSB-PD specification revision.
Returns
Encoded 16-bit USB-PD header.

Definition at line 266 of file UsbPdDefs.hpp.

References usbpd::Header::setExtended().

◆ buildRdoFixedCurrent()

uint32_t usbpd::buildRdoFixedCurrent ( uint8_t  objectPos1based,
uint16_t  opMa,
uint16_t  maxMa,
bool  capMismatch = false,
bool  usbCommCapable = true,
bool  noUsbSuspend = true 
)
inline

Build a fixed-current Request Data Object.

The generated RDO uses the common PD2.0 fixed/variable current layout: object position, capability mismatch, USB communications capable, no USB suspend, operating current, and maximum operating current.

Parameters
objectPos1basedSource PDO object position, 1 through 7.
opMaOperating current in milliamps.
maxMaMaximum operating current in milliamps.
capMismatchSet the Capability Mismatch bit.
usbCommCapableSet the USB Communications Capable bit.
noUsbSuspendSet the No USB Suspend bit.
Returns
Encoded 32-bit RDO value.

Definition at line 352 of file UsbPdDefs.hpp.

◆ le16()

uint16_t usbpd::le16 ( const uint8_t *  p)
inline

Read a 16-bit little-endian integer from a byte buffer.

Parameters
pPointer to at least two bytes.
Returns
Decoded 16-bit value.

Definition at line 46 of file UsbPdDefs.hpp.

◆ le32()

uint32_t usbpd::le32 ( const uint8_t *  p)
inline

Read a 32-bit little-endian integer from a byte buffer.

Parameters
pPointer to at least four bytes.
Returns
Decoded 32-bit value.

Definition at line 56 of file UsbPdDefs.hpp.

Referenced by AXP517PdNegotiator::parseSourceCaps().

◆ parseFixedSourcePdo()

bool usbpd::parseFixedSourcePdo ( uint32_t  pdo,
FixedSourcePdo out 
)
inline

Parse a fixed source PDO.

Parameters
pdoRaw 32-bit PDO value.
outDestination for decoded fixed-source fields.
Return values
trueif the PDO is fixed-source, false for other PDO types.

Definition at line 322 of file UsbPdDefs.hpp.

References usbpd::FixedSourcePdo::dualRolePower, Fixed, usbpd::FixedSourcePdo::ma, usbpd::FixedSourcePdo::mv, pdoType(), and usbpd::FixedSourcePdo::usbCommCapable.

Referenced by AXP517PdNegotiator::parseSourceCaps().

◆ pdoType()

PdoType usbpd::pdoType ( uint32_t  pdo)
inline

Return the type field of a raw PDO.

Parameters
pdoRaw 32-bit PDO value.
Returns
PDO type.

Definition at line 311 of file UsbPdDefs.hpp.

Referenced by parseFixedSourcePdo().

◆ wr_le16()

void usbpd::wr_le16 ( uint8_t *  p,
uint16_t  v 
)
inline

Write a 16-bit value to a byte buffer in little-endian order.

Parameters
pPointer to at least two destination bytes.
vValue to write.

Definition at line 69 of file UsbPdDefs.hpp.

◆ wr_le32()

void usbpd::wr_le32 ( uint8_t *  p,
uint32_t  v 
)
inline

Write a 32-bit value to a byte buffer in little-endian order.

Parameters
pPointer to at least four destination bytes.
vValue to write.

Definition at line 80 of file UsbPdDefs.hpp.