feat(power): switch to physical power-key shutdown control

This commit is contained in:
admin
2026-03-02 15:16:23 +08:00
parent 673b257c4f
commit 67922d37b9
8 changed files with 396 additions and 23 deletions

View File

@@ -1,10 +1,10 @@
# ESP32-S3 GPIO Mapping
本文件记录当前板级 GPIO 分配,来源于硬件对接表(2026-02-26
本文件按当前固件实现校对(代码 + 当前 `sdkconfig`),审计日期:2026-03-02
## GPIO Table
## GPIO Table (Current Build)
| Board Pin | GPIO | Signal | Direction | Notes |
| Board Pin | GPIO | Signal | Direction (Current Build) | Notes |
| --- | --- | --- | --- | --- |
| 1 | GND | GND | - | Ground |
| 2 | 3V3 | 3V3 | - | 3.3V Power |
@@ -15,7 +15,7 @@
| 7 | IO7 | ES8311_I2C_SCL | Output | Voice codec I2C SCL |
| 8 | IO15 | BATTERY_ADC | Input | Battery voltage ADC detect |
| 9 | IO16 | PRINT_STB1_2 | Output | Printer strobe 1/2 |
| 10 | IO17 | PRINT_PAPER | Input | Paper detect |
| 10 | IO17 | PRINT_PAPER | Input | Paper-present level is controlled by `CONFIG_TQ_PRINTER_PAPER_PRESENT_LEVEL` (current: `0`, low means paper present) |
| 11 | IO18 | NTC_ADC | Input | NTC ADC |
| 12 | IO8 | PRINT_OUTA_P | Output | Printer OUTA+ |
| 13 | IO19 | PRINT_OUTA_N | Output | Printer OUTA- |
@@ -23,16 +23,16 @@
| 15 | IO3 | PRINT_OUTB_P | Output | Printer OUTB+ |
| 16 | IO46 | PRINT_OUTB_N | Output | Printer OUTB- |
| 17 | IO9 | SPI_SHARED_MOSI | Output | Printer/Screen shared MOSI |
| 18 | IO10 | PRINTER_MISO | Input | Printer MISO |
| 18 | IO10 | PRINTER_MISO | Input | Shared SPI MISO used by current screen driver config |
| 19 | IO11 | SPI_SHARED_CLK | Output | Printer/Screen shared CLK |
| 20 | IO12 | SCREEN_DC | Output | ST7789 DC |
| 21 | IO13 | SCREEN_CS1 | Output | ST7789 CS |
| 22 | IO14 | MIC_KEY | Input | Mic key (can ADC-mux 2 keys if needed) |
| 21 | IO13 | SCREEN_CS (SCREEN_CS1) | Output | ST7789 CS |
| 22 | IO14 | MIC_KEY | Input | Mic key (supports ADC-mux extension path) |
| 23 | IO21 | LED_G | Output | Green LED |
| 24 | IO47 | POWER_KEY | Input | Hold low for 2s to request power-off logic |
| 25 | IO48 | SCREEN_BACKLIGHT | Output | High level turns backlight on |
| 24 | IO47 | POWER_KEY | Input | Active-low power key, long press 2s triggers lifecycle stop and power-off hold release |
| 25 | IO48 | SCREEN_BACKLIGHT | Output | Backlight active level by `CONFIG_TQ_SCREEN_BACKLIGHT_ACTIVE_HIGH` (current: `y`, high = on) |
| 26 | IO45 | PRINT_LAT | Output | Printer LAT |
| 27 | IO0 | KEY_PRINT / BOOST_CTRL | Input/Output | Print confirm key or 7.2V boost control |
| 27 | IO0 | KEY_PRINT / BOOST_CTRL | Output (current) / Input (optional) | Current build uses boost mode at boot (`CONFIG_TQ_KEY_PRINT_BOOST_ENABLE_ON_BOOT=y`), so this pin is driven as boost control |
| 28 | IO35 | N/A | - | Not available |
| 29 | IO36 | N/A | - | Not available |
| 30 | IO37 | N/A | - | Not available |
@@ -48,18 +48,46 @@
| 40 | GND | GND | - | Ground |
| 41 | GND | GND | - | Ground |
## Firmware Mapping Notes
## Additional Runtime Pin Behavior
- `main/Kconfig.projbuild` contains board pin configs prefixed with `TQ_*`.
| Logical Signal | Config | Current Value | Behavior |
| --- | --- | --- | --- |
| SCREEN_RESET | `CONFIG_TQ_SCREEN_RESET_PIN` | `-1` | No dedicated reset pin. Runtime falls back to `CONFIG_TQ_SCREEN_BACKLIGHT_PIN` (`IO48`) as reset pin. |
## Firmware Mapping Notes (Current Implementation)
- Board pin mapping is configured through `main/Kconfig.projbuild` (`CONFIG_TQ_*`) and resolved from `sdkconfig` at build time.
- GPIO usage is config-driven. Current code path does not rely on `GPIO_NUM_xx` hardcoded pin numbers.
- `components/platform/src/platform_bootstrap.c` initializes critical GPIO on startup:
- `POWER_HOLD` asserted high early.
- `SCREEN_DC/SCREEN_CS/SCREEN_BACKLIGHT` default states.
- `KEY_PRINT` defaults to boost-enable output mode (`CONFIG_TQ_KEY_PRINT_BOOST_ENABLE_ON_BOOT=y`).
- key/sensor inputs (`POWER_KEY`, `MIC_KEY`, `PRINT_PAPER`, ADC inputs) default directions.
- `components/platform/src/display_st7789.c` provides ST7789 driver integration:
- SPI bus (`MOSI=IO9`, `CLK=IO11`) + `esp_lcd_new_panel_st7789`.
- Optional boot test pattern via `CONFIG_TQ_SCREEN_TEST_PATTERN_ON_BOOT`.
- Voice codec and I2S pin defaults are aligned to this table:
- I2C: `SDA=6`, `SCL=7`
- I2S: `MCLK=38`, `BCLK=39`, `WS=41`, `DIN=40`, `DOUT=42`
- PA: `IO20`
- `POWER_HOLD` is asserted high early.
- `LED_R` and `LED_G` default low.
- `SCREEN_CS/DC/BACKLIGHT` are initialized with configured defaults.
- `KEY_PRINT` is output boost control when `CONFIG_TQ_KEY_PRINT_BOOST_ENABLE_ON_BOOT=y`, otherwise input with pull-up.
- `POWER_KEY`, `MIC_KEY`, `PRINT_PAPER` default to input with pull-up.
- Physical power-key handling uses `managed_components/espressif__button`:
- Platform layer (`platform_power_key.c`) reports long-press events (`2s`, active-low).
- Control-plane consumes the shutdown request and performs graceful stop, then calls `platform_power_hold_set(false)` through `system_runtime_power_off()`.
- Thermal printer runtime behavior (`components/platform/src/thermal_printer.c`):
- `STB` lines are active-high.
- `LAT` idles high and is pulsed low-high.
- Shared `MOSI/CLK` are temporarily switched to GPIO bit-bang for printing.
- Paper detect compares GPIO level against `runtime_policy_printer_paper_present_level()`.
- Display stack is:
- `platform_display_*` (`display_st7789.c`) -> `lcd_module_*` (`display_lcd_module.c`) -> `st7789p3_*` (`display_st7789p3.c`).
- Current implementation no longer describes panel setup in `display_st7789.c` directly.
- LCD path includes shared-SPI recovery after printer takes over shared pins.
- Voice path (`components/platform/src/voice_audio.c`):
- I2C defaults to `SDA=6`, `SCL=7`, with internal pull-up enabled in both I2C code paths.
- I2S defaults to `MCLK=38`, `BCLK=39`, `WS=41`, `DOUT=42`, `DIN=40`.
- `PA` control defaults to `IO20` and polarity can be flipped by `CONFIG_TQ_VOICE_CODEC_PA_PIN_REVERSED`.
## Condition-Driven Behavior (Important)
| Config | Current | Impact |
| --- | --- | --- |
| `CONFIG_TQ_KEY_PRINT_BOOST_ENABLE_ON_BOOT` | `y` | `KEY_PRINT/BOOST_CTRL` works as output boost-control at boot/runtime instead of key input |
| `CONFIG_TQ_KEY_PRINT_BOOST_ACTIVE_HIGH` | `y` | Boost enable level is high |
| `CONFIG_TQ_SCREEN_BACKLIGHT_ACTIVE_HIGH` | `y` | Backlight ON level is high |
| `CONFIG_TQ_SCREEN_RESET_PIN` | `-1` | Screen reset falls back to backlight pin |
| `CONFIG_TQ_SCREEN_ENABLE` | `y` | Screen driver and its GPIO paths are compiled in |
| `CONFIG_TQ_PRINTER_PAPER_PRESENT_LEVEL` | `0` | Paper detect treats GPIO low as paper present |