nrfcxx  0.1.0
C++-17 Framework for Nordic nRF5 Devices
Public Types | Public Member Functions | Static Public Attributes
nrfcxx::misc::lipo_monitor Class Reference

A state machine to monitor a LiPo battery and charger. More...

#include <nrfcxx/misc/lipomon.hpp>

Inheritance diagram for nrfcxx::misc::lipo_monitor:
nrfcxx::lpm::lpsm_capable nrfcxx::board::power_monitor nrfcxx::board::power_monitor

Public Types

enum  PowerSource_e : uint8_t { PS_Unknown = 0, PS_OnBattery = 1, PS_Charging = 2, PS_Charged = 3 }
 State of power source as inferred from VCHG_DETECT and BAT_CHG_STAT signals. More...
 

Public Member Functions

 lipo_monitor (notifier_type notify, const gpio::gpio_pin &vchg_detect, const gpio::gpio_pin &chgn_state, sensor::adc::voltage_divider &battmeas)
 Construct an instance. More...
 
bool vchg_detected_live ()
 Read the live USB detection signal.
 
bool charging_live ()
 Read the live charging signal.
 
int calibrate ()
 Initiate a calibration of the ADC used to measure voltage. More...
 
int batt_mV () const
 The most recently collected LiPo output voltage. More...
 
int power_source () const
 Get the latest processed power source. More...
 
- Public Member Functions inherited from nrfcxx::lpm::lpsm_capable
virtual int lpsm_start ()
 Validate and prepare to initiate an LPM collection. More...
 
virtual int lpsm_sample ()
 Ask the LPM infrastructure to initiate a new sample. More...
 
lpm::state_machine::process_flags_type lpsm_process ()
 Make progress on an LPM collection. More...
 
int lpsm_stop ()
 
int lpsm_reset ()
 
int lpsm_process_rc () const
 Get the internal result code from the last invocation of lpsm_process_(). More...
 
const lpm::state_machinemachine () const
 Gain read-only access to the LPM machine state.
 

Static Public Attributes

static constexpr auto PF_STARTED = lpm::state_machine::PF_STARTED
 
static constexpr auto PF_LIPO = lpm::state_machine::PF_APP_BASE
 Sensor-specific indication from lpm::lpsm_capable::lpsm_process() that a powered USB cable has been removed and the system is running from battery power.
 
static constexpr auto PF_MAINS = lpm::state_machine::PF_APP_BASE << 1
 Sensor-specific indication from lpm::lpsm_capable::lpsm_process() that a powered USB cable has been inserted and the system is running from mains power. More...
 
static constexpr auto PF_CHARGING = lpm::state_machine::PF_APP_BASE << 2
 Sensor-specific indication from lpm::lpsm_capable::lpsm_process() that the LiPo battery is being charged from a mains power source.
 
static constexpr auto PF_CHARGED = lpm::state_machine::PF_APP_BASE << 3
 Sensor-specific indication from lpm::lpsm_capable::lpsm_process() that the LiPo battery has completed charging.
 
static constexpr auto PF_CALIBRATED = lpm::state_machine::PF_APP_BASE << 5
 Sensor-specific indication from lpm::lpsm_capable::lpsm_process() that the battery voltage sensor has been calibrated.
 

Additional Inherited Members

- Protected Types inherited from nrfcxx::lpm::lpsm_capable
using state_type = state_machine::state_type
 
using process_flags_type = state_machine::process_flags_type
 
- Protected Member Functions inherited from nrfcxx::lpm::lpsm_capable
 lpsm_capable (notifier_type notify)
 Create a state machine that records state and supports delayed transitions. More...
 
virtual int lpsm_process_ (int &delay, process_flags_type &pf)
 Override to implement machine-specific operations of lpsm_process(). More...
 
virtual void lpsm_reset_ ()
 Override to reset state that is held outside the machine.
 
- Protected Attributes inherited from nrfcxx::lpm::lpsm_capable
state_machine machine_
 

Detailed Description

A state machine to monitor a LiPo battery and charger.

This class does several things:

lpm::lpsm_capable::lpsm_process() for this sensor returns the following flags:

calibrate() should be invoked by the application on startup and whenever the ambient temperature changes by more than 10 Cel from the last calibration.

Member Enumeration Documentation

◆ PowerSource_e

State of power source as inferred from VCHG_DETECT and BAT_CHG_STAT signals.

Enumerator
PS_Unknown 

No information available.

PS_OnBattery 

V_BUS is zero.

Values greater than this have V_BUS non-zero.

PS_Charging 

V_BUS is non-zero and TCK106 charging active.

PS_Charged 

V_BUS is non-zero and TCK106 charging not active.

Constructor & Destructor Documentation

◆ lipo_monitor()

nrfcxx::misc::lipo_monitor::lipo_monitor ( notifier_type  notify,
const gpio::gpio_pin vchg_detect,
const gpio::gpio_pin chgn_state,
sensor::adc::voltage_divider battmeas 
)

Construct an instance.

Parameters
notifythe setter used to indicate to the application that lpsm_process() should be invoked.
vchg_detecta GPIO reference that is high when a charging voltage is available, and low when it is not.
chgn_statea GPIO reference that is low when the battery is being charged, and high when it is not being charged. The signal is considered valid only when a charging voltage is available.
battmeasthe ADC client used to measure the voltage of the LiPo battery. A reference to this instance will be retained.

Member Function Documentation

◆ batt_mV()

int nrfcxx::misc::lipo_monitor::batt_mV ( ) const
inline

The most recently collected LiPo output voltage.

Note
A negative value indicates that the collection occurred when the system was externally powered, a condition in which the measured power may inaccurately represent the true state of the LiPo.

◆ calibrate()

int nrfcxx::misc::lipo_monitor::calibrate ( )

Initiate a calibration of the ADC used to measure voltage.

Returns
zero on success, negative if the state machine is busy.

◆ power_source()

int nrfcxx::misc::lipo_monitor::power_source ( ) const

Get the latest processed power source.

Note
The value returned here is not live, but the state as observed in the last invocation of lpsm_process().
Returns
An enumeration value from PowerSource_e or a negative error code.

Field Documentation

◆ PF_MAINS

constexpr auto nrfcxx::misc::lipo_monitor::PF_MAINS = lpm::state_machine::PF_APP_BASE << 1
staticconstexpr

Sensor-specific indication from lpm::lpsm_capable::lpsm_process() that a powered USB cable has been inserted and the system is running from mains power.

If this flag is returned either PF_CHARGING or PF_CHARGED will appear with it.


The documentation for this class was generated from the following file: