Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
charging_ic.h
Go to the documentation of this file.
1
5#ifndef CHARGING_IC_H
6#define CHARGING_IC_H
7
8#include <cstdint>
9#include <string>
10
11namespace lampda {
12namespace power {
14namespace charger {
15
17namespace drivers {
18
20enum class Status_t
21{
25 NOMINAL,
27 ERROR,
32};
33
36{
38 OFF,
45};
46
56bool enable(const uint16_t minSystemVoltage_mV,
57 const uint16_t maxBatteryVoltage_mV,
58 const uint16_t maxChargingCurrent_mA,
59 const uint16_t maxDichargingCurrent_mA,
60 const bool forceReset = false);
61
66void loop(const bool isChargeOk);
67
69void shutdown();
70
73void enable_charge(const bool enable);
74
81void set_input_current_limit(const uint16_t maxInputCurrent_mA, const bool shouldUseICO);
82
84uint16_t get_charge_current();
85
88
90void enable_OTG();
92void disable_OTG();
94void set_OTG_targets(const uint16_t voltage_mV, const uint16_t maxCurrent_mA);
96bool is_in_OTG();
97
100void try_clear_faults();
101
105std::string get_status_detail();
109std::string get_software_error_message();
110
115{
117 uint32_t time = 0;
119 bool is_measurment_valid() const;
120
123
125 uint16_t vbus_mV;
128 uint16_t psys_mV;
134 uint16_t vbus_mA;
136 uint16_t cmpin_mA;
138 uint16_t vsys_mV;
140 uint16_t battery_mV;
141};
142Measurments get_measurments();
143
149{
151 bool isPresent = false;
152
154 uint16_t voltage_mV;
158 int16_t current_mA;
159};
160Battery get_battery();
161
162} // namespace drivers
163} // namespace charger
164} // namespace power
165} // namespace lampda
166
167#endif
void set_OTG_targets(const uint16_t voltage_mV, const uint16_t maxCurrent_mA)
set the desired OTG capabilities
Definition: charging_ic.cpp:764
void disable_OTG()
Disable the OTG.
Definition: charging_ic.cpp:752
void shutdown()
call on program stop to gracefully shutdown the component.
Definition: charging_ic.cpp:688
uint16_t get_charge_current()
return the actual charge current, in milliamps.
Definition: charging_ic.cpp:720
void set_input_current_limit(const uint16_t maxInputCurrent_mA, const bool shouldUseICO)
Set the input current limit.
Definition: charging_ic.cpp:714
Status_t get_status()
return the status of the component
Definition: charging_ic.cpp:781
Status_t
Store the status of the charge component.
Definition: charging_ic.h:21
@ ERROR_HAS_FAULTS
the device is signaling faults
@ ERROR_COMPONENT
wrong manufacturer/device id
ChargeStatus_t get_charge_status()
return the charge status object of the battery
Definition: charging_ic.cpp:785
bool is_in_OTG()
Return true if the system is in OTG mode.
Definition: charging_ic.cpp:779
std::string get_status_detail()
return a string with details on the error status
Definition: charging_ic.cpp:783
ChargeStatus_t
Status of the charge process.
Definition: charging_ic.h:36
@ SLOW_CHARGE
activated when the charging current is too low
bool is_input_source_present()
return true if an input source is present for the charger on the USB port.
Definition: charging_ic.cpp:722
void try_clear_faults()
try to clear the faults that can be cleared. if this succeeds, the status will be to NOMINAL next loo...
Definition: charging_ic.cpp:728
std::string get_software_error_message()
contains details on software error if any
Definition: charging_ic.cpp:54
bool enable(const uint16_t minSystemVoltage_mV, const uint16_t maxBatteryVoltage_mV, const uint16_t maxChargingCurrent_mA, const uint16_t maxDichargingCurrent_mA, const bool forceReset)
Call once on program start.
Definition: charging_ic.cpp:483
void enable_OTG()
Enable the OTG and disable the charging process.
Definition: charging_ic.cpp:739
void enable_charge(const bool enable)
Enable the charge process. this will start the charge only if the conditions are right.
Definition: charging_ic.cpp:255
void loop()
call at every loop runs
Definition: charger.cpp:369
Program scope.
Definition: control_fixed_modes.hpp:12
Store the battery specific measurments ans status. It is a refined data version of the Measurments cl...
Definition: charging_ic.h:149
uint16_t voltage_mV
voltage of the battery, in millivolts.
Definition: charging_ic.h:154
bool isPresent
if false, the other infos are useless
Definition: charging_ic.h:151
int16_t current_mA
Actual current use, in milliamps. Positive is charging current. Negative is discharging current.
Definition: charging_ic.h:158
Store the DAC values mesured by some system sensors, relative to the battery and power.
Definition: charging_ic.h:115
bool is_measurment_valid() const
Return False if you should not use the values in this struct.
Definition: charging_ic.cpp:787
uint16_t vbus_mV
voltage on vbus, in millivolts
Definition: charging_ic.h:125
uint16_t psys_mV
power on vsys ?? The values here are always weird
Definition: charging_ic.h:128
bool isChargeOk
Indicates if the chargeOk signal from charger is high.
Definition: charging_ic.h:122
uint16_t battery_mV
battery voltage, in millivolts
Definition: charging_ic.h:140
uint16_t vbus_mA
vbus current, in milliamps
Definition: charging_ic.h:134
uint16_t vsys_mV
VSYS voltage, in millivolts.
Definition: charging_ic.h:138
uint16_t batDischargeCurrent_mA
battery discharge current, in milliamps
Definition: charging_ic.h:132
uint32_t time
The time those measurments were made.
Definition: charging_ic.h:117
uint16_t batChargeCurrent_mA
battery charging current, in milliamps
Definition: charging_ic.h:130