#pragma once /** * Reads the battery level via the ADC voltage divider * (CONFIG_FRAME_BATTERY_ADC_GPIO -- see Kconfig for the expected XIAO * ESP32-C6 wiring). Returns 0-100, or -1 for any of: * - feature disabled (CONFIG_FRAME_BATTERY_ADC_GPIO < 0), * - running on mains (CONFIG_FRAME_VBUS_SENSE_GPIO reads high), * - reading outside the plausible LiPo range (catches "no battery * attached" and a button held on a shared pin, which reads ~0V), * - any ADC setup/read error. * * The battery pin is expected to be shared with a button (the settled * XIAO design shares the back button's GPIO0/A0): call this AFTER the * button checks at boot, since the ADC read temporarily reconfigures * the pin. On return the pin is always restored to button duty (input + * pull-up + deep-sleep wake armed). */ int battery_read_percent(void);