feat(m1): local time display and three-button monitoring (#6)

## Summary

Two M1 firmware enhancements on the Waveshare ESP32-S3-RLCD-4.2:

**Local-time display (UTC+8, fixed offset — China has no DST).**
Internal time stays strictly
UTC (RTC chip, JSONL `utc`, console `--json` keep the `Z`-suffixed
machine format). Only
human-facing surfaces convert via the new
`board::kLocalUtcOffsetSeconds`:

- display RTC line renders `unix + 8*3600` labeled `UTC+8` (split after
the date: measured
montserrat16 widths 157px + 119px fit the 179px status column; the old
one-line layout was
  already 223px and overflowed)
- text `status` and `rtc status` show the labeled UTC+8 line and keep
both the raw unix and a
  UTC line
- `rtc set` now takes UTC+8 local time (validates the local calendar
round-trip, converts
  -8h before `set_rtc_time`); help/usage/README updated

**Three buttons.**

- KEY (GPIO18) unchanged (short <1s / long 1-3s / >=3s portal).
- BOOT (GPIO0, strapping pin — input + pull-up, runtime read only):
mirrors the KEY 30ms
debounce and release bands (short <1s, long >=1s), new
`boot_short_presses` /
  `boot_long_presses`, no portal binding.
- RST is hardwired to chip reset, so it is tracked as a persistent boot
counter: NVS
namespace `frame`, key `rst_cnt`, incremented once per boot after
`nvs_flash_init`, exposed
  as `reset_count`.
- Surfaces: display `KEY:a/b BOOT:c/d` + `RST:e` lines, console text +
`--json`
(`boot_short`, `boot_long`, `reset_count`), JSONL
`boot_short`/`boot_long` only — measured
594B worst observed line vs the 640B buffer (46B headroom, gate was
>=40B); `reset_count`
  is static per boot so it is `--json`-only.

## On-device verification (34/34 deterministic asserts PASS + user
assist)

Evidence:
`.omo/evidence/m1wp/tz-buttons-finish-m1-wifi-provisioning.log`

- Build 0 warnings; clang-format 18.1.8 clean on whole `main/`.
- `rtc status`/text status UTC+8 lines match host `date` +8h (<=3s
skew); `rtc set` with a
  UTC+8 local time round-trips (`1788157541 = 14:25:41 local - 8h`).
- JSONL `utc` unchanged UTC-with-Z, crc32c intact, max line 594B < 640.
- KEY short press: +1 with BOOT unchanged (user-assisted). BOOT short:
+2 (user-assisted).
BOOT long: not physically exercised this session — code path is the
device-proven KEY band
logic (same constants); noted in `.omo/notepads` for the next bench
session.
- RST/reset_count: host RTS-pulse reboot 3->4 with boot banner; `--json`
agrees.
- Regressions: wifi auto-connect CONNECTED, tf_logging true, selftest
`wifi_config: ok` +
  `bad ignored`, `prov status` three-state.

Co-authored-by: ania-lain <[email protected]>
This commit is contained in:
Lain
2026-08-31 14:39:04 +08:00
committed by GitHub
co-authored by lain
parent e9f8b7386b
commit f5f944bef0
9 changed files with 168 additions and 58 deletions
+33 -6
View File
@@ -18,6 +18,7 @@ constexpr uint8_t kRtcSecondsRegister = 0x04;
constexpr uint8_t kRtcFirstRegister = 0x00;
constexpr std::size_t kRtcRegisterCount = 11;
// KEY release bands: <1s short press, 1s..<3s long press, >=3s provisioning portal command.
// BOOT release bands: <1s short press, >=1s long press (no portal binding).
constexpr int64_t kKeyLongPressUs = 1000000;
constexpr int64_t kKeyPortalHoldUs = 3000000;
@@ -54,12 +55,12 @@ board_service::~board_service() {
}
esp_err_t board_service::start() {
gpio_config_t key_config{};
key_config.pin_bit_mask = UINT64_C(1) << board::kKey;
key_config.mode = GPIO_MODE_INPUT;
key_config.pull_up_en = GPIO_PULLUP_ENABLE;
key_config.intr_type = GPIO_INTR_DISABLE;
esp_err_t result = gpio_config(&key_config);
gpio_config_t buttons_config{};
buttons_config.pin_bit_mask = (UINT64_C(1) << board::kKey) | (UINT64_C(1) << board::kBoot);
buttons_config.mode = GPIO_MODE_INPUT;
buttons_config.pull_up_en = GPIO_PULLUP_ENABLE;
buttons_config.intr_type = GPIO_INTR_DISABLE;
esp_err_t result = gpio_config(&buttons_config);
if (result != ESP_OK) {
return result;
}
@@ -296,6 +297,10 @@ void board_service::run() {
bool stable_pressed = last_pressed;
int64_t changed_at = esp_timer_get_time();
int64_t pressed_at = stable_pressed ? changed_at : 0;
bool boot_last_pressed = gpio_get_level(board::kBoot) == 0;
bool boot_stable_pressed = boot_last_pressed;
int64_t boot_changed_at = esp_timer_get_time();
int64_t boot_pressed_at = boot_stable_pressed ? boot_changed_at : 0;
int64_t next_sensor_at = 0;
while (true) {
@@ -328,6 +333,28 @@ void board_service::run() {
}
}
const bool boot_pressed = gpio_get_level(board::kBoot) == 0;
if (boot_pressed != boot_last_pressed) {
boot_last_pressed = boot_pressed;
boot_changed_at = now;
}
if (boot_pressed != boot_stable_pressed && now - boot_changed_at >= 30000) {
boot_stable_pressed = boot_pressed;
if (boot_pressed) {
boot_pressed_at = now;
} else if (boot_pressed_at != 0) {
const int64_t boot_held_us = now - boot_pressed_at;
status_.update([&](status_snapshot& value) {
if (boot_held_us >= kKeyLongPressUs) {
++value.boot_long_presses;
} else {
++value.boot_short_presses;
}
});
boot_pressed_at = 0;
}
}
if (now >= next_sensor_at) {
const esp_err_t sensor_result = sample_sensor();
if (sensor_result != ESP_OK) {