Add software LiPo UV protection with energy-save boot.

Detect under-voltage on GPIO1/11, persist UV state in NVS, enter a minimal
power mode without ESP-NOW, and recover after charge; expose LED mode 6
battery-low for host testing via goTool.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-23 18:22:52 +02:00
co-authored by Cursor
parent be18b758ed
commit f006f8b912
26 changed files with 418 additions and 37 deletions
+51
View File
@@ -0,0 +1,51 @@
#ifndef BATTERY_UV_H
#define BATTERY_UV_H
#include "board_input.h"
#include "powerpod.h"
#include <stdbool.h>
#if POWERPOD_BATTERY_UV_ENABLE
/** ADC pin voltage (mV) below which UV is triggered (3.0 V pack via 33k/10k divider). */
#define BATTERY_UV_ADC_MV 2300u
/** ADC pin voltage (mV) at which charging is detected (4.0 V pack, rounded). */
#define BATTERY_CHARGE_ADC_MV 3000u
bool battery_uv_is_latched(void);
bool battery_uv_reading_is_under(const board_lipo_reading_t *reading);
bool battery_uv_reading_is_charged(const board_lipo_reading_t *reading);
/** true → enter UV energy-save path (does not return). */
bool battery_uv_evaluate_boot(void);
void battery_uv_poll(const board_lipo_reading_t *reading);
/** Blocks: LED indicator, then minimal ADC polling until charged. */
void battery_uv_run_mode(void);
#else
static inline bool battery_uv_is_latched(void) { return false; }
static inline bool battery_uv_reading_is_under(const board_lipo_reading_t *reading) {
(void)reading;
return false;
}
static inline bool battery_uv_reading_is_charged(const board_lipo_reading_t *reading) {
(void)reading;
return false;
}
static inline bool battery_uv_evaluate_boot(void) { return false; }
static inline void battery_uv_poll(const board_lipo_reading_t *reading) {
(void)reading;
}
static inline void battery_uv_run_mode(void) {}
#endif
#endif