Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
charger.h
Go to the documentation of this file.
1
8#ifndef COMPONENT_CHARGER_H
9#define COMPONENT_CHARGER_H
10
11#include <cstdint>
12
13#include <etl/string.h>
14
15namespace lampda {
16namespace component {
18namespace charger {
19
21bool setup();
23void loop();
25void shutdown();
26
28void set_enable_charge(const bool shouldCharge);
29
34{
36 bool areMeasuresOk = false;
40 bool isInOtg;
41
43 uint32_t lastUpdateTime_ms = 0;
44
46 uint16_t inputCurrent_mA = 0;
48 uint16_t chargeCurrent_mA = 0;
51 uint16_t powerRail_mV = 0;
52
54 uint16_t batteryVoltage_mV = 0;
56 int16_t batteryCurrent_mA = 0;
57
61 enum class ChargerStatus_t
62 {
65
76
83 };
86
88 bool is_charging() const;
90 bool is_effectivly_charging() const;
92 bool is_charge_finished() const;
94 etl::string<32> get_status_str() const;
95
97 etl::string<128> hardwareErrorMessage = "";
99 etl::string<128> softwareErrorMessage = "";
100};
101
103bool is_vbus_powered();
104
106bool can_use_vbus_power();
107
113void control_OTG(const uint16_t mv, const uint16_t ma);
114
117
120
121} // namespace charger
122} // namespace component
123} // namespace lampda
124
125#endif // CHARGER_H
bool is_vbus_signal_detected()
Return true if the USB VBUS presence signal is active.
Definition: charger.cpp:424
bool is_vbus_powered()
Return true if voltage is detected on VBUS.
Definition: charger.cpp:420
void shutdown()
Call when system goes to sleep.
Definition: charger.cpp:412
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:157
bool can_use_vbus_power()
Return true if we are allowed to use the VBUS power.
Definition: charger.cpp:422
void loop()
call at every loop runs
Definition: charger.cpp:357
void set_enable_charge(const bool shouldCharge)
debug feature: enable/disable the charging process
Definition: charger.cpp:418
bool setup()
call once at program startup
Definition: charger.cpp:316
Charger_t get_state()
Return the latest known state of the charger.
Definition: charger.cpp:426
Program scope.
Definition: control_fixed_modes.hpp:14
Store the charger characteristics.
Definition: charger.h:34
bool is_effectivly_charging() const
Return true when the battery is truly charging.
Definition: charger.cpp:442
uint16_t inputCurrent_mA
input current in VBUS side, in milliamps.
Definition: charger.h:46
uint16_t chargeCurrent_mA
charge current of the battery, in milliamps.
Definition: charger.h:48
uint16_t powerRail_mV
powerRail voltage (can be the same as VBUS in charge & OTG mode). Min value at 3200mV
Definition: charger.h:51
ChargerStatus_t status
global high level charger status
Definition: charger.h:85
ChargerStatus_t
Indicates a charger status soecific states.
Definition: charger.h:62
@ POWER_DETECTED
charger detects power on the input
@ ERROR_HARDWARE
critical: some hardware is faulty
int16_t batteryCurrent_mA
battery current (> 0 charging, < 0 discharging)
Definition: charger.h:56
etl::string< 128 > softwareErrorMessage
Contain a more detailed error of a software error.
Definition: charger.h:99
bool is_charging() const
Return true when the status is charging or powered.
Definition: charger.cpp:434
bool isChargeOkSignalHigh
True if we have a valid chargeOk signal from the component.
Definition: charger.h:38
bool areMeasuresOk
everything below makes no sense if this is false
Definition: charger.h:36
bool isInOtg
True if OTG is activated.
Definition: charger.h:40
uint32_t lastUpdateTime_ms
time of the last update of this struct.
Definition: charger.h:43
etl::string< 128 > hardwareErrorMessage
Contain a more detailed error of an hardware error.
Definition: charger.h:97
etl::string< 32 > get_status_str() const
Return the status as a string.
Definition: charger.cpp:447
bool is_charge_finished() const
Return true if the charge is finished.
Definition: charger.cpp:440
uint16_t batteryVoltage_mV
battery voltage
Definition: charger.h:54