Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
Classes | Namespaces | Functions | Variables
input_power_policy.h File Reference

Rules deciding when, and how much, current can be pulled from the USB input. More...

Go to the source code of this file.

Classes

class  lampda::bsp::powerDelivery::policy::VbusLossTracker
 
struct  lampda::bsp::powerDelivery::policy::SourceStatus
 Snapshot of the input source status. More...
 

Namespaces

namespace  lampda
 Program scope.
 
namespace  lampda::bsp
 Board Support Layer, handle the low level logic above the HAL.
 
namespace  lampda::bsp::powerDelivery
 Handles the power delivery capabilities (USB-PD).
 
namespace  lampda::bsp::powerDelivery::policy
 Input power rules, from a snapshot of the source status.
 

Functions

uint32_t lampda::bsp::powerDelivery::policy::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 lampda::bsp::powerDelivery::policy::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 lampda::bsp::powerDelivery::policy::is_unplugged (const uint32_t timeSinceVbusValid_ms, const bool isSinkHardResetting)
 VBUS was lost long enough to consider the source unplugged.
 
bool lampda::bsp::powerDelivery::policy::can_use_pd_full_power (const SourceStatus &s)
 The PD contract is established, and VBUS reached the negociated voltage.
 
bool lampda::bsp::powerDelivery::policy::is_standard_port (const SourceStatus &s)
 The source is a standard USB port (no PD), with a stabilize delay.
 
bool lampda::bsp::powerDelivery::policy::can_use_power (const SourceStatus &s)
 The source power can be used.
 
uint16_t lampda::bsp::powerDelivery::policy::max_input_current_mA (const SourceStatus &s)
 Maximum current that can be pulled from the source.
 

Variables

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

Detailed Description

Rules deciding when, and how much, current can be pulled from the USB input.

Pure functions of a status snapshot, so that the rules can be unit tested without the PD hardware.