7#ifndef BSP_PD_INPUT_POWER_POLICY_H
8#define BSP_PD_INPUT_POWER_POLICY_H
14namespace powerDelivery {
44 const uint32_t margin_mV =
46 return negotiatedVoltage_mV > margin_mV ? negotiatedVoltage_mV - margin_mV : 0;
69 const bool isChargerInOtg,
70 const bool isOutputGateEnabled)
72 return isSwitchingToOtg or (isChargerInOtg and not isOutputGateEnabled);
76inline bool is_unplugged(
const uint32_t timeSinceVbusValid_ms,
const bool isSinkHardResetting)
93 lastVbusValid_ms_ = time_ms;
94 wasHardResetSeen_ =
false;
98 bool is_unplugged(
const uint32_t time_ms,
const bool isSinkHardResetting)
100 wasHardResetSeen_ = wasHardResetSeen_ or isSinkHardResetting;
105 uint32_t lastVbusValid_ms_ = 0;
106 bool wasHardResetSeen_ =
false;
126 uint32_t negotiatedCurrent_mA = 0;
169 return static_cast<uint16_t
>(s.negotiatedCurrent_mA *
pdCurrentRatio);
Definition: input_power_policy.h:88
bool is_unplugged(const uint32_t time_ms, const bool isSinkHardResetting)
VBUS is not valid: return true if this loss is an unplug.
Definition: input_power_policy.h:98
void on_vbus_valid(const uint32_t time_ms)
VBUS is valid: a new loss starts from this time.
Definition: input_power_policy.h:91
static constexpr uint32_t hardResetUnplugDeglitch_ms
Definition: input_power_policy.h:59
uint16_t max_input_current_mA(const SourceStatus &s)
Maximum current that can be pulled from the source.
Definition: input_power_policy.h:159
bool is_unplugged(const uint32_t timeSinceVbusValid_ms, const bool isSinkHardResetting)
VBUS was lost long enough to consider the source unplugged.
Definition: input_power_policy.h:76
static constexpr uint16_t standardPortCurrent_mA
Current pulled from a standard port (ICO finds the real maximum)
Definition: input_power_policy.h:30
static constexpr uint32_t pdLostDelay_ms
Delay after the last PD source detection before considering it a standard port.
Definition: input_power_policy.h:21
bool can_use_pd_full_power(const SourceStatus &s)
The PD contract is established, and VBUS reached the negociated voltage.
Definition: input_power_policy.h:132
static constexpr uint32_t pdCableDrop_mV
Cable and connectors voltage drop allowed on VBUS (USB-C, at 3A)
Definition: input_power_policy.h:34
static constexpr uint32_t unplugDeglitch_ms
VBUS can be lost this long before the source is considered unplugged (flicker, ICO algorithm)
Definition: input_power_policy.h:52
static constexpr uint32_t standardPortDetectionDelay_ms
Delay after a source detection (or a PD resume) before considering it a standard (non PD) port.
Definition: input_power_policy.h:19
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 bloc...
Definition: input_power_policy.h:42
static constexpr float pdCurrentRatio
Do not use the whole PD current, or the source will cut us off.
Definition: input_power_policy.h:49
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 OT...
Definition: input_power_policy.h:68
static constexpr uint32_t pdSourceTolerance_percent
PD source output tolerance (vSrcNew), in percents of the negociated voltage.
Definition: input_power_policy.h:32
static constexpr uint32_t maxPdNegociationWait_ms
Definition: input_power_policy.h:28
static constexpr uint32_t vbusMeasureResolution_mV
VBUS measure resolution: the FUSB302 measure has 420mV steps, and rounds down.
Definition: input_power_policy.h:36
bool can_use_power()
Return true if we can use this source as power entry.
Definition: power_delivery.cpp:619
bool is_standard_port()
return true if this voltage source is from a standard non pd port
Definition: power_delivery.cpp:130
Program scope.
Definition: control_fixed_modes.hpp:14
Snapshot of the input source status.
Definition: input_power_policy.h:111
uint32_t timeSinceSourceDetected_ms
Time since the source detection, or since the PD state machine resumed.
Definition: input_power_policy.h:115
bool isPowerSourceDetected
VBUS was detected (deglitched)
Definition: input_power_policy.h:113
bool isUsbPd
Source capabilities are known.
Definition: input_power_policy.h:119
bool isSinkNegotiating
The PD state machine is still negociating (waiting for capabilities, resetting, requesting)
Definition: input_power_policy.h:123
uint32_t vbusVoltage_mV
Measured VBUS voltage.
Definition: input_power_policy.h:128
uint32_t negotiatedVoltage_mV
Negociated contract (0 when no contract)
Definition: input_power_policy.h:125
bool isSinkReady
The PD state machine has an established contract.
Definition: input_power_policy.h:121
uint32_t timeSinceLastPdDetected_ms
Time since the source capabilities were last known.
Definition: input_power_policy.h:117