Power Delivery

class brainstem.entity.PowerDelivery(module, index)[source]

Power Delivery or PD is a power specification which allows more charging options and device behaviors within the USB interface. This Entity will allow you to directly access the vast landscape of PD.

getCableCurrentMax()[source]

Gets the maximum current capability report by the e-mark of the attached cable

Returns:

value (int): An enumerated representation of current
  • Unknown/Unattached (0)

  • 3 Amps (1)

  • 5 Amps (2)

error: Non-zero BrainStem error code on failure.

Return type:

Result (object)

getCableOrientation()[source]

Gets the current orientation being used for PD communication

Returns:

value (int): An enumerated representation of the cables max speed
  • Unconnected = 0

  • CC1 (1)

  • CC2 (2)

error: Non-zero BrainStem error code on failure.

Return type:

Result (object)

getCableSpeedMax()[source]

Gets the maximum data rate capability reported by the e-mark of the attached cable.

Returns:

value (int): An enumerated representation of the cables max speed
  • Unknown/Unattached (0)

  • USB 2.0 (1)

  • USB 3.2 gen 1 (2)

  • USB 3.2 / USB 4 gen 2 (3)

  • USB 4 gen 3 (4)

error: Non-zero BrainStem error code on failure.

Return type:

Result (object)

getCableType()[source]

Gets the cable type reported by the e-mark of the attached cable.

Returns:

value (int): An enumerated representation of the cables max speed
  • Invalid, no e-mark and not Vconn powered (0)

  • Passive cable with e-mark (1)

  • Active cable (2)

error: Non-zero BrainStem error code on failure.

Return type:

Result (object)

getCableVoltageMax()[source]

Gets the maximum voltage capability reported by the e-mark of the attached cable.

Returns:

value (int): An enumerated representation of voltage
  • Unknown/Unattached (0)

  • 20 Volts DC (1)

  • 30 Volts DC (2)

  • 40 Volts DC (3)

  • 50 Volts DC (4)

error: Non-zero BrainStem error code on failure.

Return type:

Result (object)

getConnectionState()[source]

Gets the current state of the connection in the form of an enumeration.

Returns:

value (int): An enumerated representation of the current state. error: Non-zero BrainStem error code on failure.

Return type:

Result (object)

getFastRoleSwapCurrent()[source]

Gets the Fast Role Swap Current The fast role swap current refers to the amount of current required by the Local Sink in order to successfully preform the swap.

Returns:

value (int): An enumerated value referring to current swap value
  • 0A (0)

  • 900mA (1)

  • 1.5A (2)

  • 3A (3)

error: Non-zero BrainStem error code on failure.

Return type:

Result (object)

getFlagMode(flag)[source]

Gets the current mode of the local partner flag/advertisement. These flags are apart of the first Local Power Data Object and must be managed in order to accurately represent the system to other PD devices. This API allows overriding of that feature. Overriding may lead to unexpected behaviors.

Parameters:

flag (int) – Flag/Advertisement to be modified

Returns:

value (int): The current mode of the provided flag
  • Disabled (0)

  • Enable (1)

  • Auto (2) default

error: Non-zero BrainStem error code on failure.

Return type:

Result (object)

getNumberOfPowerDataObjects(partner, powerRole)[source]

Gets the number of Power Data Objects (PDOs) for a given partner and power role.

Parameters:
  • partner (int) –

    • Local = 0 = powerdeliveryPartnerLocal

    • Remote = 1 = powerdeliveryPartnerRemote

  • powerRole (int) –

    • Source = 1 = powerdeliveryPowerRoleSource

    • Sink = 2 = powerdeliveryPowerRoleSink

Returns:

value (int): The number of of Power Data Objects (PDO) error: Non-zero BrainStem error code on failure.

Return type:

Result (object)

getOverride()[source]

Gets the current enabled overrides

Returns:

value (int): Bit mapped representation of the current override configuration. error: Non-zero BrainStem error code on failure.

Return type:

Result (object)

getPeakCurrentConfiguration()[source]

Gets the Peak Current Configuration for the Local Source. The peak current configuration refers to the allowable tolerance/overload capabilities in regards to the devices max current. This tolerance includes a maximum value and a time unit.

Returns:

value (int): An enumerated value referring to the current configuration.
  • Allowable values are 0 - 4

error: Non-zero BrainStem error code on failure.

Return type:

Result (object)

getPowerDataObject(partner, powerRole, ruleIndex)[source]

Gets the number of Power Data Objects (PDOs) for a given partner and power role.

Parameters:
  • partner (int) –

    • Local = 0 = powerdeliveryPartnerLocal

    • Remote = 1 = powerdeliveryPartnerRemote

  • powerRole (int) –

    • Source = 1 = powerdeliveryPowerRoleSource

    • Sink = 2 = powerdeliveryPowerRoleSink

  • ruleIndex (int) –

Returns:

value (int): Power Data Object (PDO) for the given partner and power role. error: Non-zero BrainStem error code on failure.

Return type:

Result (object)

getPowerDataObjectEnabled(powerRole, ruleIndex)[source]

Gets the enabled state of the Local Power Data Object (PDO) for a given power role and index. Enabled refers to whether the PDO will be advertised when a PD connection is made. This does not indicate the currently active rule index. This information can be found in Request Data Object (RDO).

Parameters:
  • powerRole (int) –

    • Source = 1 = powerdeliveryPowerRoleSource

    • Sink = 2 = powerdeliveryPowerRoleSink

  • ruleIndex (int) – The index of the PDO in question. Valid index are 1-7.

Returns:

value (bool): Represents the enabled state. error: Non-zero BrainStem error code on failure.

Return type:

Result (object)

getPowerDataObjectEnabledList(powerRole)[source]

Gets all Power Data Object enables for a given power role. Equivalent of calling PowerDelivery.getPowerDataObjectEnabled() for all indexes.

Parameters:

powerRole (int) –

  • Source = 1 = powerdeliveryPowerRoleSource (1) Source

  • Sink = 2 = powerdeliveryPowerRoleSink (2) Sink

Returns:

value (bool): Bit mapped representation of the enabled PDOs for a given power role Values align with a given rule index (bits 1-7, bit 0 is invalid). error: Non-zero BrainStem error code on failure.

Return type:

Result (object)

getPowerDataObjectList()[source]

Gets all Power Data Objects (PDO) for a given partner and power role. Equivalent to calling PowerDelivery.getPowerDataObject() on all partners, power roles, and index’s.

Returns:

value (tuple(int)): All Power Data Objects (PDOs) On success the length should be 28 (7 rules * 2 partners * 2 power roles) The order of which is:

  • Rules 1-7 Local Source

  • Rules 1-7 Local Sink

  • Rules 1-7 Remote Source

  • Rules 1-7 Remote Sink

error: Non-zero BrainStem error code on failure.

Return type:

Result (object)

getPowerRole()[source]

Gets the power role that is currently being advertised by the local partner. (CC Strapping).

Returns:

value (int): The current power role
  • Disabled = 0 = powerdeliveryPowerRoleDisabled

  • Source = 1= powerdeliveryPowerRoleSource

  • Sink = 2 = powerdeliveryPowerRoleSink

  • Source/Sink = 3 = powerdeliveryPowerRoleSourceSink (Dual Role Port)

error: Non-zero BrainStem error code on failure.

Return type:

Result (object)

getPowerRolePreferred()[source]

Gets the preferred power role currently being advertised by the Local partner. (CC Strapping).

Returns:

value (int): The current power role
  • Disabled = 0 = powerdeliveryPowerRoleDisabled

  • Source = 1= powerdeliveryPowerRoleSource

  • Sink = 2 = powerdeliveryPowerRoleSink

error: Non-zero BrainStem error code on failure.

Return type:

Result (object)

getRequestDataObject(partner)[source]

Gets the current Request Data Object (RDO) for a given partner.

RDOs:
  • Are provided by the sinking device.

  • Exist only after a successful PD negotiation (Otherwise zero).

  • Only one RDO can exist at a time. i.e. Either the Local or Remote partner RDO

Parameters:

partner (int) –

  • Local = 0 = powerdeliveryPartnerLocal

  • Remote = 1 = powerdeliveryPartnerRemote

Returns:

value (int): Value of the request RDO. (Zero indicates the RDO is not active) error: Non-zero BrainStem error code on failure.

Return type:

Result (object)

request(request)[source]

Requests an action of the Remote partner. Actions are not guaranteed to occur.

Parameters:

request (int) –

  • pdRequestHardReset (0)

  • pdRequestSoftReset (1)

  • pdRequestDataReset (2)

  • pdRequestPowerRoleSwap (3)

  • pdRequestPowerFastRoleSwap (4)

  • pdRequestDataRoleSwap (5)

  • pdRequestVconnSwap (6)

  • pdRequestSinkGoToMinimum (7)

  • pdRequestRemoteSourcePowerDataObjects (8)

  • pdRequestRemoteSinkPowerDataObjects (9)

Returns (int):

Non-zero BrainStem error code on failure.

requestStatus()[source]

Gets the status of the last request command sent.

Returns:

value (int): the request status error: Non-zero BrainStem error code on failure.

Return type:

Result (object)

resetEntityToFactoryDefaults()[source]

Resets the PowerDelivery Entity to it factory default configuration.

Returns (int):

Non-zero BrainStem error code on failure.

resetPowerDataObjectToDefault(powerRole, ruleIndex)[source]

Resets the Power Data Object (PDO) of the Local partner for a given power role and index.

Parameters:
  • powerRole (int) –

    • Source = 1 = powerdeliveryPowerRoleSource

    • Sink = 2 = powerdeliveryPowerRoleSink

  • ruleIndex (int) – The index of the PDO in question. Valid index are 1-7.

Returns (int):

Non-zero BrainStem error code on failure.

setFastRoleSwapCurrent(current)[source]

Sets the Fast Role Swap Current The fast role swap current refers to the amount of current required by the Local Sink in order to successfully preform the swap.

Parameters:

current (int) – An enumerated value referring to value to be set. - 0A (0) - 900mA (1) - 1.5A (2) - 3A (3)

Returns (int):

Non-zero BrainStem error code on failure.

setFlagMode(flag, mode)[source]

Sets how the local partner flag/advertisement is managed. These flags are apart of the first Local Power Data Object and must be managed in order to accurately represent the system to other PD devices. This API allows overriding of that feature. Overriding may lead to unexpected behaviors.

Parameters:
  • flag (int) – Flag/Advertisement to be modified

  • mode (int) –

    • Disabled (0)

    • Enable (1)

    • Auto (2) default

Returns (int):

Non-zero BrainStem error code on failure.

setOverride(overrides)[source]

Sets the current overrides.

Parameters:

overrides (int) – Overrides to be set in a bit mapped representation.

Returns (int):

Non-zero BrainStem error code on failure.

setPeakCurrentConfiguration(config)[source]

Sets the Peak Current Configuration for the Local Source. The peak current configuration refers to the allowable tolerance/overload capabilities in regards to the devices max current. This tolerance includes a maximum value and a time unit.

Parameters:

config (int) – An enumerated value referring to the configuration to be set - Allowable values are 0 - 4

Returns (int):

Non-zero BrainStem error code on failure.

setPowerDataObject(powerRole, ruleIndex, pdo)[source]

Sets the Power Data Object (PDO) of the local partner for a given power role and index.

Parameters:
  • powerRole (int) –

    • Source = 1 = powerdeliveryPowerRoleSource

    • Sink = 2 = powerdeliveryPowerRoleSink

  • ruleIndex (int) – The index of the PDO in question. Valid index are 1-7.

  • pdo (int) – Power Data Object to be set.

Returns (int):

Non-zero BrainStem error code on failure.

setPowerDataObjectEnabled(powerRole, ruleIndex, enable)[source]

Sets the enabled state of the Local Power Data Object (PDO) for a given powerRole and index. Enabled refers to whether the PDO will be advertised when a PD connection is made. This does not indicate the currently active rule index. This information can be found in Request Data Object (RDO).

Parameters:
  • powerRole (int) –

    • Source = 1 = powerdeliveryPowerRoleSource

    • Sink = 2 = powerdeliveryPowerRoleSink

  • ruleIndex (int) – The index of the PDO in question. Valid index are 1-7.

  • enable (bool) – The enabled state to be set.

Returns (int):

Non-zero BrainStem error code on failure.

setPowerRole(powerRole)[source]

Sets the power role to be advertised by the Local partner. (CC Strapping).

Parameters:

powerRole (int) –

  • Disabled = 0 = powerdeliveryPowerRoleDisabled

  • Source = 1= powerdeliveryPowerRoleSource

  • Sink = 2 = powerdeliveryPowerRoleSink

  • Source/Sink = 3 = powerdeliveryPowerRoleSourceSink (Dual Role Port)

Returns (int):

Non-zero BrainStem error code on failure.

setPowerRolePreferred(powerRole)[source]

Set the preferred power role to be advertised by the Local partner (CC Strapping).

Parameters:

powerRole (int) –

  • Disabled = 0 = powerdeliveryPowerRoleDisabled

  • Source = 1= powerdeliveryPowerRoleSource

  • Sink = 2 = powerdeliveryPowerRoleSink

Returns (int):

Non-zero BrainStem error code on failure.

setRequestDataObject(rdo)[source]

Sets the current Request Data Object (RDO) for a given partner. (Only the local partner can be changed.)

RDOs:
  • Are provided by the sinking device.

  • Exist only after a successful PD negotiation (Otherwise zero).

  • Only one RDO can exist at a time. i.e. Either the Local or Remote partner RDO

Parameters:

rdo (int) – RDO to be applied.

Returns (int):

Non-zero BrainStem error code on failure.