Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
Classes | Functions | Variables
lampda::bsp::powerDelivery::policy Namespace Reference

Input power rules, from a snapshot of the source status. More...

Classes

struct  SourceStatus
 Snapshot of the input source status. More...
 
class  VbusLossTracker
 

Functions

uint32_t pd_min_established_vbus_mV (const uint32_t negotiatedVoltage_mV)
 Lowest VBUS measure for which the negociated voltage is considered established A fixed 1V margin blocked a 9V contract from another lamp: VBUS read 7.98V (issue #357)
 
bool is_vbus_from_own_output (const bool isSwitchingToOtg, const bool isChargerInOtg, const bool isOutputGateEnabled)
 True when the VBUS measure can come from our own OTG output, and is not a power source The charger OTG also powers the output gate (output mode), and the two gates are never enabled together: the USB port is then isolated from our output, and VBUS can only come from an external source. It must be followed, or a cable unplugged in output mode is never seen (issue #646). While the gates are switching (both disabled), the port can still hold our own voltage: it is ignored too.
 
bool is_unplugged (const uint32_t timeSinceVbusValid_ms, const bool isSinkHardResetting)
 VBUS was lost long enough to consider the source unplugged.
 
bool can_use_pd_full_power (const SourceStatus &s)
 The PD contract is established, and VBUS reached the negociated voltage.
 
bool is_standard_port (const SourceStatus &s)
 The source is a standard USB port (no PD), with a stabilize delay.
 
bool can_use_power (const SourceStatus &s)
 The source power can be used.
 
uint16_t max_input_current_mA (const SourceStatus &s)
 Maximum current that can be pulled from the source.
 

Variables

static constexpr uint32_t standardPortDetectionDelay_ms = 1500
 Delay after a source detection (or a PD resume) before considering it a standard (non PD) port.
 
static constexpr uint32_t pdLostDelay_ms = 1000
 Delay after the last PD source detection before considering it a standard port.
 
static constexpr uint32_t maxPdNegociationWait_ms = 8000
 
static constexpr uint16_t standardPortCurrent_mA = 800
 Current pulled from a standard port (ICO finds the real maximum)
 
static constexpr uint32_t pdSourceTolerance_percent = 5
 PD source output tolerance (vSrcNew), in percents of the negociated voltage.
 
static constexpr uint32_t pdCableDrop_mV = 500
 Cable and connectors voltage drop allowed on VBUS (USB-C, at 3A)
 
static constexpr uint32_t vbusMeasureResolution_mV = 420
 VBUS measure resolution: the FUSB302 measure has 420mV steps, and rounds down.
 
static constexpr float pdCurrentRatio = 0.90f
 Do not use the whole PD current, or the source will cut us off.
 
static constexpr uint32_t unplugDeglitch_ms = 1000
 VBUS can be lost this long before the source is considered unplugged (flicker, ICO algorithm)
 
static constexpr uint32_t hardResetUnplugDeglitch_ms = 3000
 

Detailed Description

Input power rules, from a snapshot of the source status.

Variable Documentation

◆ hardResetUnplugDeglitch_ms

constexpr uint32_t lampda::bsp::powerDelivery::policy::hardResetUnplugDeglitch_ms = 3000
staticconstexpr

During a hard reset, the source drops VBUS: tSafe0V (650ms) + tSrcRecover (1000ms) + tSrcTurnOn (275ms) ~= 1.9s. VBUS can be lost this long before the source is considered unplugged. This limit does not depend on the PD state machine: if it stalls in a hard reset state, an unplug must still be detected (issue #642). Also used for a power role swap: old source turn off (tPSSourceOff, 920ms) + new source turn on (~400ms).

◆ maxPdNegociationWait_ms

constexpr uint32_t lampda::bsp::powerDelivery::policy::maxPdNegociationWait_ms = 8000
staticconstexpr

After this delay, the standard port fallback does not wait for the PD negociation anymore. It is only a guard against a stuck state machine: every negociation state has its own timeout. Worst case of a late negociation: CC debounce (200ms) + caps wait (600ms) + soft reset (30ms)

  • 2 * (hard reset recovery (650ms + 1275ms) + caps wait (600ms)) ~= 5.9s