Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
charger.h
Go to the documentation of this file.
1
8#ifndef CHARGER_H
9#define CHARGER_H
10
11#include <cstdint>
12#include <string>
13
14namespace lampda {
15namespace power {
17namespace charger {
18
20bool setup();
22void loop();
24void shutdown();
25
27void set_enable_charge(const bool shouldCharge);
28
33{
35 bool areMeasuresOk = false;
39 bool isInOtg;
40
42 uint32_t lastUpdateTime_ms = 0;
43
45 uint16_t inputCurrent_mA = 0;
47 uint16_t chargeCurrent_mA = 0;
50 uint16_t powerRail_mV = 0;
51
53 uint16_t batteryVoltage_mV = 0;
55 int16_t batteryCurrent_mA = 0;
56
60 enum class ChargerStatus_t
61 {
64
75
82 };
85
87 bool is_charging() const;
89 bool is_effectivly_charging() const;
91 bool is_charge_finished() const;
93 std::string get_status_str() const;
94
96 std::string hardwareErrorMessage = "";
98 std::string softwareErrorMessage = "";
99};
100
102bool is_vbus_powered();
103
105bool can_use_vbus_power();
106
112void control_OTG(const uint16_t mv, const uint16_t ma);
113
116
119
120} // namespace charger
121} // namespace power
122} // namespace lampda
123
124#endif // CHARGER_H
bool is_vbus_signal_detected()
Return true if the USB VBUS presence signal is active.
Definition: charger.cpp:436
bool is_vbus_powered()
Return true if voltage is detected on VBUS.
Definition: charger.cpp:432
void control_OTG(const uint16_t mv, const uint16_t ma)
Set the OTG control parameters. Set the parameters to zero to disable OTG mode.
Definition: charger.cpp:170
bool setup()
call once at program startup
Definition: charger.cpp:330
void shutdown()
Call when system goes to sleep.
Definition: charger.cpp:424
Charger_t get_state()
Return the latest known state of the charger.
Definition: charger.cpp:438
void set_enable_charge(const bool shouldCharge)
debug feature: enable/disable the charging process
Definition: charger.cpp:430
void loop()
call at every loop runs
Definition: charger.cpp:369
bool can_use_vbus_power()
Return true if we are allowed to use the VBUS power.
Definition: charger.cpp:434
Program scope.
Definition: control_fixed_modes.hpp:12
Store the charger characteristics.
Definition: charger.h:33
std::string softwareErrorMessage
Contain a more detailed error of a software error.
Definition: charger.h:98
ChargerStatus_t status
global high level charger status
Definition: charger.h:84
int16_t batteryCurrent_mA
battery current (> 0 charging, < 0 discharging)
Definition: charger.h:55
uint16_t batteryVoltage_mV
battery voltage
Definition: charger.h:53
std::string hardwareErrorMessage
Contain a more detailed error of an hardware error.
Definition: charger.h:96
uint16_t powerRail_mV
powerRail voltage (can be the same as VBUS in charge & OTG mode). Min value at 3200mV
Definition: charger.h:50
bool isChargeOkSignalHigh
True if we have a valid chargeOk signal from the component.
Definition: charger.h:37
bool is_effectivly_charging() const
Return true when the battery is truly charging.
Definition: charger.cpp:448
bool is_charge_finished() const
Return true if the charge is finished.
Definition: charger.cpp:446
bool is_charging() const
Return true when the status is charging or powered.
Definition: charger.cpp:440
uint16_t inputCurrent_mA
input current in VBUS side, in milliamps.
Definition: charger.h:45
std::string get_status_str() const
Return the status as a string.
Definition: charger.cpp:453
bool areMeasuresOk
everything below makes no sense if this is false
Definition: charger.h:35
ChargerStatus_t
Indicates a charger status soecific states.
Definition: charger.h:61
@ CHARGING
currently charging the batteries
@ POWER_DETECTED
charger detects power on the input
@ INACTIVE
no input power, charger is down
@ ERROR_SOFTWARE
a software error was detected
@ ERROR_HARDWARE
critical: some hardware is faulty
bool isInOtg
True if OTG is activated.
Definition: charger.h:39
uint16_t chargeCurrent_mA
charge current of the battery, in milliamps.
Definition: charger.h:47
uint32_t lastUpdateTime_ms
time of the last update of this struct.
Definition: charger.h:42