It's a whole new topic for me.
Also, it's a quite important part of phone or even some other hand held device.
Battery capacity by hardware or Software gas gauge, battery state (Charging by AC or USB), battery or process temperature, and low power state detect and shut down device.
There might be more relative issue that I don't mention.
Let's talk about Software Gas Gauge because I focus on this recently.
The purpose of SW Gas Gauge is measure the capacity of battery.
The main idea is that calculate the voltage of battery by software.
The items that we could get from device are Vbat (detected by ADC from chip or PMU) & Vout (also from ADC results).
Vtarget = Vbat + Vsense.
The problem is how to measure Vsence by Vout.
Vsense = Isense *Rsense (we know Rsense)
Isense = Vout / Rout (we know Vout & Rout)
After this we get target V for battery capacity measurement.
We need OCV(Open Circuit Voltage) table to look up corresponding Capacity from Voltage.
However, the capacity are not really accurate.
We have fix the error of charging and non-charging separately.
For Charging, we have to measure the jump up voltage of AC & USB individually.
Then, measure the Vtarget:
Vtarget = = Vbat + Vsense - Verror (Verror are related to AC or USB connected)