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

Handles the power delivery capabilities (USB-PD). More...

Namespaces

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

Classes

struct  OTGParameters
 The requested OTG parameters. More...
 
struct  PDOTypes
 Define a USB PD PDO type. More...
 
struct  UsbPDData
 USB power delivery status storage. More...
 

Functions

void suspend_pd_state_machine ()
 Suspend the execution of the power delivery state machine.
 
void allow_source_resets (const bool allow)
 Allow the sink to reset the source, when the source capabilities were missed. A hard reset makes the source drop VBUS for up to ~2s. Forbid it when the battery cannot power the board (recovery mode), or this browns it out: the source is then used as a standard 5V port. Forbidden until allowed. Allowing it later starts the reset of a source waiting for its capabilities.
 
void resume_pd_state_machine ()
 resume the execution of the power delivery state machine
 
int get_vbus_voltage ()
 use the vbus measure from negociator (close to USBC, 0 to N volts)
 
bool is_usb_pd ()
 
policy::SourceStatus get_source_status ()
 
bool can_use_PD_full_power ()
 
bool is_standard_port ()
 return true if this voltage source is from a standard non pd port
 
void ic_interrupt ()
 
bool is_ic_interrupt_pending ()
 
bool is_vbus_powered ()
 
const char * cc_level_str (const int level)
 
void show_pd_contract ()
 
void show_pd_status ()
 Debug power delivery status.
 
void interrupt_handle ()
 
void pd_run ()
 
bool setup ()
 call once at program start, attach interrupts and init
 
void start_threads ()
 Start polling threads.
 
void loop ()
 call often (update status)
 
void shutdown ()
 call once at program end
 
uint16_t get_max_input_current ()
 return the max current available for this source
 
bool is_power_available ()
 Return true if some power is available on VBUS.
 
bool can_use_power ()
 Return true if we can use this source as power entry.
 
void force_set_to_source_mode (const bool force)
 force the system to source mode
 
OTGParameters get_otg_parameters ()
 Return the desired OTG parameters.
 
void allow_otg (const bool)
 Call to allow or forbid OTG mode.
 
void want_source_role_by_swap (const bool wanted)
 As a sink, ask the partner for the source role (power role swap), and do not use its power meanwhile.
 
bool is_attached_as_sink ()
 return true when the PD state machine is attached to a partner, as a sink
 
void retry_source_role_swap ()
 As a ready sink wanting the source role (want_source_role_by_swap), ask for the power role swap again.
 
bool is_source_contract_ready ()
 return true when we are a source, with a contract in place (PS_RDY sent): the sink can use the power
 
bool is_switching_to_otg ()
 return true is the system is prepaping to switch to OTG mode
 
bool is_source_hard_resetting ()
 return true when we are a source in a hard reset: VBUS must be cut until the end of the recovery time
 
std::array< PDOTypes, 5 > get_available_pd ()
 If the charger is PD compatible, return it's capabilities.
 

Variables

static bool isPowerSourceDetected_s = false
 
static uint32_t powerSourceDetectedTime_s = 0
 
static bool should_run_pd_state_machine = true
 
uint32_t lastPDdetected = 0
 
static bool isSetup = false
 
static uint32_t interruptStuckKicks_s = 0
 
static uint32_t interruptAlertReruns_s = 0
 
UsbPDData data
 

Detailed Description

Handles the power delivery capabilities (USB-PD).

Function Documentation

◆ interrupt_handle()

void lampda::bsp::powerDelivery::interrupt_handle ( )

HEADER FUNCTIONS BELOW

◆ is_ic_interrupt_pending()

bool lampda::bsp::powerDelivery::is_ic_interrupt_pending ( )

The FUSB302 interrupt line is level triggered (active low, until all interrupt registers are read), but we only get a callback on the falling edge. If an interrupt is raised before the callback is attached (VBUS and CC are already there at boot, the CC lines have a permanent Rd), or while another one is pending, there is no new falling edge: the line stays low forever, no message is received and no transmission completes (issue #633). So service the interrupt on the line level.

◆ want_source_role_by_swap()

void lampda::bsp::powerDelivery::want_source_role_by_swap ( const bool  wanted)

As a sink, ask the partner for the source role (power role swap), and do not use its power meanwhile.

Parameters
[in]wantedfalse to go back to the normal sink behavior