Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
Classes | Typedefs | Enumerations | Functions | Variables
lampda::power::charger::drivers Namespace Reference

Hardware driver interactions for the charger component. More...

Classes

struct  Battery
 Store the battery specific measurments ans status. It is a refined data version of the Measurments class. More...
 
struct  Measurments
 Store the DAC values mesured by some system sensors, relative to the battery and power. More...
 
struct  PowerLimits
 Store the power limits for the battery charge protocol. More...
 

Typedefs

using charger_ic = bq25713::BQ25713
 

Enumerations

enum class  Status_t {
  UNINITIALIZED , NOMINAL , ERROR , ERROR_COMPONENT ,
  ERROR_HAS_FAULTS
}
 Store the status of the charge component. More...
 
enum class  ChargeStatus_t { OFF , PRECHARGE , FASTCHARGE , SLOW_CHARGE }
 Status of the charge process. More...
 

Functions

std::string get_software_error_message ()
 contains details on software error if any
 
void set_software_error_message (const std::string &msg)
 
void run_fault_detection ()
 
void run_status_update ()
 
void control_charge ()
 
void control_OTG ()
 
void enable_charge (const bool enable)
 Enable the charge process. this will start the charge only if the conditions are right.
 
void enable_input_current_optimization (const bool enable)
 enable/disable the Input Current Optimizer algorithm
 
void update_battery ()
 
void run_ADC ()
 
void program_input_current_limit ()
 
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=false)
 Call once on program start.
 
void loop (const bool isChargeOk)
 Call often during execution.
 
void shutdown ()
 call on program stop to gracefully shutdown the component.
 
void set_input_current_limit (const uint16_t maxInputCurrent_mA, const bool shouldUseICO)
 Set the input current limit.
 
uint16_t get_charge_current ()
 return the actual charge current, in milliamps.
 
bool is_input_source_present ()
 return true if an input source is present for the charger on the USB port.
 
void try_clear_faults ()
 try to clear the faults that can be cleared. if this succeeds, the status will be to NOMINAL next loop call.
 
void enable_OTG ()
 Enable the OTG and disable the charging process.
 
void disable_OTG ()
 Disable the OTG.
 
void set_OTG_targets (const uint16_t voltage_mV, const uint16_t maxCurrent_mA)
 set the desired OTG capabilities
 
bool is_in_OTG ()
 Return true if the system is in OTG mode.
 
Status_t get_status ()
 return the status of the component
 
std::string get_status_detail ()
 return a string with details on the error status
 
ChargeStatus_t get_charge_status ()
 return the charge status object of the battery
 
Measurments get_measurments ()
 
Battery get_battery ()
 

Variables

charger_ic chargerIc
 
charger_ic::Regt chargerIcRegisters
 
static Measurments measurments_s
 
static Battery battery_s
 
static Status_t status_s = Status_t::UNINITIALIZED
 
static std::string status_error = ""
 
static ChargeStatus_t chargeStatus_s = ChargeStatus_t::OFF
 
static bool isChargeOk_s = false
 
static bool isChargeEnabled_s = false
 
static bool isInOtg_s = false
 
std::string softwareError_detail = ""
 
static PowerLimits powerLimits_s
 define the power limits for input power
 
bool isInit = false
 

Detailed Description

Hardware driver interactions for the charger component.

Enumeration Type Documentation

◆ ChargeStatus_t

Status of the charge process.

Enumerator
OFF 

no charging

PRECHARGE 

battery undervoltage charge

FASTCHARGE 

nominal charge

SLOW_CHARGE 

activated when the charging current is too low

◆ Status_t

Store the status of the charge component.

Enumerator
UNINITIALIZED 

not initialized

NOMINAL 

works fine

ERROR 

generic error

ERROR_COMPONENT 

wrong manufacturer/device id

ERROR_HAS_FAULTS 

the device is signaling faults

Function Documentation

◆ enable()

bool lampda::power::charger::drivers::enable ( const uint16_t  minSystemVoltage_mV,
const uint16_t  maxBatteryVoltage_mV,
const uint16_t  maxChargingCurrent_mA,
const uint16_t  maxDichargingCurrent_mA,
const bool  forceReset = false 
)

Call once on program start.

Parameters
[in]minSystemVoltage_mVMinimal allowed battery voltage.
[in]maxBatteryVoltage_mVMaximal allowed battery voltage
[in]maxChargingCurrent_mAMaximum allowed charge current for the battery.
[in]maxDichargingCurrent_mAMaximum allowed discharging current of the battery.
[in]forceResetIf true, will reset the internal registers of the component.
Returns
True if the initialization suceeded.

◆ enable_input_current_optimization()

void lampda::power::charger::drivers::enable_input_current_optimization ( const bool  enable)

enable/disable the Input Current Optimizer algorithm

Parameters
[in]enableIf true, the InputCurrentOptimization algorithm will be activated and the VBUS charge current will be optimized to reach a target droop voltage

◆ loop()

void lampda::power::charger::drivers::loop ( const bool  isChargeOk)

Call often during execution.

Parameters
[in]isChargeOkShould match what is read on the CHRG_OK IC pin of the charger.

◆ set_input_current_limit()

void lampda::power::charger::drivers::set_input_current_limit ( const uint16_t  maxInputCurrent_mA,
const bool  shouldUseICO 
)

Set the input current limit.

Parameters
[in]maxInputCurrent_mAMaximum allowed current use on VBUS, in milliamps.
[in]shouldUseICOIf True, the InputCurrentInitialization will be used. It automatically finds the most allowed current.

Variable Documentation

◆ isInit

bool lampda::power::charger::drivers::isInit = false

HEADER FUNCTIONS