Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
power_delivery.h
Go to the documentation of this file.
1
5#ifndef PD_POWER_DELIVERY_H
6#define PD_POWER_DELIVERY_H
7
8#include <cstdint>
9#include <vector>
10
11namespace lampda {
12namespace power {
14namespace powerDelivery {
15
17bool setup();
19void start_threads();
20
22void loop();
23
25void shutdown();
26
31
34
36uint16_t get_max_input_current();
37
39bool is_standard_port();
40
43
46
48bool can_use_power();
49
51void force_set_to_source_mode(const bool force);
52
56void allow_otg(const bool);
57
62
67{
69 uint32_t voltage_mv;
71 uint32_t maxCurrent_mA;
72};
73
77std::vector<PDOTypes> get_available_pd();
78
80void show_pd_status();
81
84{
86 uint16_t requestedVoltage_mV = 0;
88 uint16_t requestedCurrent_mA = 0;
89
91 bool is_otg_requested() const { return requestedVoltage_mV != 0 && requestedCurrent_mA != 0; }
92
97 {
98 OTGParameters def;
99 def.requestedCurrent_mA = 3000;
100 def.requestedVoltage_mV = 5000;
101 return def;
102 }
103};
104
106OTGParameters get_otg_parameters();
107
108} // namespace powerDelivery
109} // namespace power
110} // namespace lampda
111
112#endif
bool is_switching_to_otg()
return true is the system is prepaping to switch to OTG mode
Definition: power_delivery.cpp:452
bool can_use_power()
Return true if we can use this source as power entry.
Definition: power_delivery.cpp:437
void loop()
call often (update status)
Definition: power_delivery.cpp:354
void show_pd_status()
Debug power delivery status.
Definition: power_delivery.cpp:221
OTGParameters get_otg_parameters()
Return the desired OTG parameters.
Definition: power_delivery.cpp:441
bool setup()
call once at program start, attach interrupts and init
Definition: power_delivery.cpp:320
void resume_pd_state_machine()
resume the execution of the power delivery state machine
Definition: power_delivery.cpp:47
void allow_otg(const bool allow)
Call to allow or forbid OTG mode.
Definition: power_delivery.cpp:450
bool is_standard_port()
return true if this voltage source is from a standard non pd port
Definition: power_delivery.cpp:93
int get_vbus_voltage()
use the vbus measure from negociator (close to USBC, 0 to N volts)
Definition: power_delivery.cpp:54
void force_set_to_source_mode(const bool force)
force the system to source mode
Definition: power_delivery.cpp:439
std::vector< PDOTypes > get_available_pd()
If the charger is PD compatible, return it's capabilities.
Definition: power_delivery.cpp:454
uint16_t get_max_input_current()
return the max current available for this source
Definition: power_delivery.cpp:410
void start_threads()
Start polling threads.
Definition: power_delivery.cpp:341
bool is_power_available()
Return true if some power is available on VBUS.
Definition: power_delivery.cpp:435
void shutdown()
call once at program end
Definition: power_delivery.cpp:408
bool is_cable_detected()
Return true is a power cable is connected.
Definition: power_delivery.cpp:84
void suspend_pd_state_machine()
Suspend the execution of the power delivery state machine.
Definition: power_delivery.cpp:41
Program scope.
Definition: control_fixed_modes.hpp:12
The requested OTG parameters.
Definition: power_delivery.h:84
uint16_t requestedVoltage_mV
Requested voltage for the OTG.
Definition: power_delivery.h:86
bool is_otg_requested() const
Return true if OTG is requested and should be turned on.
Definition: power_delivery.h:91
static OTGParameters get_default()
Return the default OTG targets.
Definition: power_delivery.h:96
uint16_t requestedCurrent_mA
Requested maximum current use for the OTG.
Definition: power_delivery.h:88
Define a USB PD PDO type.
Definition: power_delivery.h:67
uint32_t maxCurrent_mA
Maximum current of this PDO.
Definition: power_delivery.h:71
uint32_t voltage_mv
Voltage of this PDO.
Definition: power_delivery.h:69