BAT_ADC (GPIO4) sits between two 100k resistors on the switched supply rail, so it reads the cell on battery and ~4.4 V on USB; above 4.25 V is reported as USB power. On battery the caption shows a glyph + percentage from a LiPo OCV table; the menu shows voltage and source. Menu lists now wrap at both ends.
14 lines
724 B
C
14 lines
724 B
C
#pragma once
|
|
#include <stdbool.h>
|
|
|
|
// Battery sense on the original T-Embed: BAT_ADC (GPIO4) sits between two 100k
|
|
// resistors on the switched supply rail (schematic net V_BAT), so V = 2 x V_pin.
|
|
// That rail is the cell when running on battery, but USB minus a Schottky drop
|
|
// (~4.4 V) when a cable is in — which is how we tell the two apart. There is no
|
|
// fuel gauge; the percentage is an open-circuit LiPo estimate. The CC1101 board
|
|
// is not handled (it has a BQ27220 instead).
|
|
void battery_init(void);
|
|
// Averages a burst of samples; returns false if the board has no ADC divider.
|
|
// *on_usb is set when the rail is above what a LiPo cell can reach.
|
|
bool battery_read(int *millivolts, int *percent, bool *on_usb);
|