8#ifndef COMPONENT_CHARGER_H
9#define COMPONENT_CHARGER_H
13#include <etl/string.h>
113void control_OTG(
const uint16_t mv,
const uint16_t ma);
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
@ CHARGING
currently charging the batteries
@ POWER_DETECTED
charger detects power on the input
@ SLOW_CHARGING
charging but very slowly
@ INACTIVE
no input power, charger is down
@ ERROR_SOFTWARE
a software error was detected
@ CHARGE_FINISHED
charging process is done
@ ERROR_HARDWARE
critical: some hardware is faulty
@ ERROR_BATTERY_MISSING
battery not detected
@ UNINITIALIZED
not initialized yet
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