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:
+26
-9
@@ -59,14 +59,16 @@ Pins (`powerpod.h`):
|
||||
|
||||
> **TODO:** GPIO assignments above are provisional; confirm pinning against the real board before release.
|
||||
|
||||
Startup order:
|
||||
Startup order (normal path; UV energy-save skips I2C/BMA456/ESP-NOW/UART/button — see **Software UV protection**):
|
||||
|
||||
1. Read DIP + IO expander → `app_config`
|
||||
2. **I2C bus** — IO expander `0x20`; optional **BMA456H** (`init_bma456`, same bus)
|
||||
3. `esp_now_comm_init(&app_config)` — WiFi + ESP-NOW
|
||||
4. `led_ring_init()`
|
||||
5. `board_input_init()` — button press logs, LiPo ADC logs every **10 s**
|
||||
6. **Master only:** command queue, UART, registered commands (e.g. VERSION)
|
||||
1. `pod_settings_init()` — NVS
|
||||
2. LiPo ADC init + optional UV boot check (`battery_uv.c`)
|
||||
3. Read DIP + IO expander → `app_config`
|
||||
4. **I2C bus** — IO expander `0x20`; optional **BMA456H** (`init_bma456`, same bus)
|
||||
5. `esp_now_comm_init(&app_config)` — WiFi + ESP-NOW
|
||||
6. `led_ring_init()`
|
||||
7. LiPo monitor task + button (`board_input.c`)
|
||||
8. **Master only:** command queue, UART, registered commands (e.g. VERSION)
|
||||
|
||||
## BMA456 accelerometer (`bosch456.c`)
|
||||
|
||||
@@ -440,6 +442,19 @@ Read **cached** LiPo ADC values on the **master** (master local + one entry per
|
||||
# Host / goTool: all_clients returns master (id 0) + slaves from cache
|
||||
```
|
||||
|
||||
### Software UV protection (LiPo)
|
||||
|
||||
When `POWERPOD_BATTERY_UV_ENABLE` is `1` (default in `powerpod.h`, disable via CMake), the firmware monitors ADC pin voltages on GPIO 1 and 11:
|
||||
|
||||
| Condition | ADC threshold | Action |
|
||||
|-----------|---------------|--------|
|
||||
| Under-voltage | any valid channel < **2300 mV** (3.0 V pack) | NVS latch `uv_latch`, restart into energy-save mode |
|
||||
| Charged | all valid channels ≥ **3000 mV** (4.0 V pack) | Clear latch, restart into normal boot |
|
||||
|
||||
**Energy-save boot:** LED mode `6` (first 4 LEDs red ~10 % for 5 s), then no WiFi/ESP-NOW, UART, I2C, BMA456, or button — only LiPo ADC polling every 30 s until charged.
|
||||
|
||||
**Test LED pattern from host:** `led-ring -mode battery-low` (works even when UV feature is disabled).
|
||||
|
||||
### LED_RING command
|
||||
|
||||
Control the 95-LED ring from the host. The firmware **does not** animate digits locally; only UART updates the display.
|
||||
@@ -448,7 +463,7 @@ Control the 95-LED ring from the host. The firmware **does not** animate digits
|
||||
|
||||
| Field | Meaning |
|
||||
|-------|---------|
|
||||
| `mode` | `0` = clear, `1` = progress, `2` = digit (0–10), `3` = blink, `4` = find-me, `5` = solid color (all LEDs) |
|
||||
| `mode` | `0` = clear, `1` = progress, `2` = digit (0–10), `3` = blink, `4` = find-me, `5` = solid color (all LEDs), `6` = battery-low (first 4 LEDs red ~10 % for 5 s) |
|
||||
| `progress` | 0–100 (% of ring lit, mode `1`) |
|
||||
| `digit` | 0–10 (mode `2`, segment maps in `led_ring.c`) |
|
||||
| `r`, `g`, `b` | Color 0–255 |
|
||||
@@ -470,6 +485,7 @@ go run . -port /dev/ttyUSB0 led-ring -mode blink -g 255 -blink-count 2
|
||||
go run . -port /dev/ttyUSB0 find-me
|
||||
go run . -port /dev/ttyUSB0 find-me -client 16
|
||||
go run . -port /dev/ttyUSB0 led-ring -mode find-me
|
||||
go run . -port /dev/ttyUSB0 led-ring -mode battery-low -client 0
|
||||
go run . -port /dev/ttyUSB0 led-ring -mode color -r 255 -g 0 -b 0 -client 16
|
||||
go run . -port /dev/ttyUSB0 led-ring -mode digit -digit 5 -all
|
||||
```
|
||||
@@ -564,7 +580,8 @@ Target: ESP32-S3. Close serial monitor on the UART adapter port before running `
|
||||
| `cmd/cmd_tap_notify.c` | UART `TAP_NOTIFY` — ESP-NOW tap notify config |
|
||||
| `cmd/cmd_cache_status.c` | UART `CACHE_STATUS` — subscribed accel + tap cache poll |
|
||||
| `board_input.c/h` | Taster GPIO12, LiPo ADC on GPIO1 / GPIO11 |
|
||||
| `pod_settings.c/h` | NVS persistence (accel deadzone, …) |
|
||||
| `battery_uv.c/h` | Software LiPo UV latch, energy-save boot (`POWERPOD_BATTERY_UV_ENABLE`) |
|
||||
| `pod_settings.c/h` | NVS persistence (accel deadzone, UV latch, …) |
|
||||
| `led_ring.c/h` | LED ring (digit display, progress bar) |
|
||||
| `cmd/cmd_led_ring.c` | UART `LED_RING` progress command |
|
||||
| `cmd/cmd_set_log_level.c` | UART `SET_LOG_LEVEL` — runtime ESP-IDF log level |
|
||||
|
||||
Reference in New Issue
Block a user