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 BSP_PD_POWER_DELIVERY_H
6#define BSP_PD_POWER_DELIVERY_H
7
8#include <cstdint>
9#include <vector>
10
11namespace lampda {
12namespace bsp {
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
45bool can_use_power();
46
48void force_set_to_source_mode(const bool force);
49
53void allow_otg(const bool);
54
59
64{
66 uint32_t voltage_mv;
68 uint32_t maxCurrent_mA;
69};
70
74std::vector<PDOTypes> get_available_pd();
75
77void show_pd_status();
78
81{
83 uint16_t requestedVoltage_mV = 0;
85 uint16_t requestedCurrent_mA = 0;
86
88 bool is_otg_requested() const { return requestedVoltage_mV != 0 && requestedCurrent_mA != 0; }
89
94 {
95 OTGParameters def;
96 def.requestedCurrent_mA = 3000;
97 def.requestedVoltage_mV = 5000;
98 return def;
99 }
100};
101
103OTGParameters get_otg_parameters();
104
105} // namespace powerDelivery
106} // namespace bsp
107} // namespace lampda
108
109#endif
void allow_otg(const bool allow)
Call to allow or forbid OTG mode.
Definition: power_delivery.cpp:460
void shutdown()
call once at program end
Definition: power_delivery.cpp:418
void loop()
call often (update status)
Definition: power_delivery.cpp:364
void show_pd_status()
Debug power delivery status.
Definition: power_delivery.cpp:214
bool can_use_power()
Return true if we can use this source as power entry.
Definition: power_delivery.cpp:447
void suspend_pd_state_machine()
Suspend the execution of the power delivery state machine.
Definition: power_delivery.cpp:42
uint16_t get_max_input_current()
return the max current available for this source
Definition: power_delivery.cpp:420
bool setup()
call once at program start, attach interrupts and init
Definition: power_delivery.cpp:313
int get_vbus_voltage()
use the vbus measure from negociator (close to USBC, 0 to N volts)
Definition: power_delivery.cpp:55
std::vector< PDOTypes > get_available_pd()
If the charger is PD compatible, return it's capabilities.
Definition: power_delivery.cpp:464
OTGParameters get_otg_parameters()
Return the desired OTG parameters.
Definition: power_delivery.cpp:451
bool is_power_available()
Return true if some power is available on VBUS.
Definition: power_delivery.cpp:445
bool is_switching_to_otg()
return true is the system is prepaping to switch to OTG mode
Definition: power_delivery.cpp:462
void start_threads()
Start polling threads.
Definition: power_delivery.cpp:333
void resume_pd_state_machine()
resume the execution of the power delivery state machine
Definition: power_delivery.cpp:48
bool is_standard_port()
return true if this voltage source is from a standard non pd port
Definition: power_delivery.cpp:86
void force_set_to_source_mode(const bool force)
force the system to source mode
Definition: power_delivery.cpp:449
Program scope.
Definition: control_fixed_modes.hpp:15
The requested OTG parameters.
Definition: power_delivery.h:81
uint16_t requestedCurrent_mA
Requested maximum current use for the OTG.
Definition: power_delivery.h:85
bool is_otg_requested() const
Return true if OTG is requested and should be turned on.
Definition: power_delivery.h:88
static OTGParameters get_default()
Return the default OTG targets.
Definition: power_delivery.h:93
uint16_t requestedVoltage_mV
Requested voltage for the OTG.
Definition: power_delivery.h:83
Define a USB PD PDO type.
Definition: power_delivery.h:64
uint32_t voltage_mv
Voltage of this PDO.
Definition: power_delivery.h:66
uint32_t maxCurrent_mA
Maximum current of this PDO.
Definition: power_delivery.h:68