fix(m1): add rtc time sources, responsive status rendering, and key documentation (#5)
## Summary
Fixes three user-reported M1 defects (root causes pre-diagnosed):
1. **RTC permanently invalid** (`-` on screen, `"utc":""` in JSONL, 228x
`ESP_ERR_INVALID_CRC`):
nothing ever wrote the PCF85063, so after power loss its OS (oscillator
stopped) bit stays set.
- `board_service::set_rtc_time(int64_t)`: gmtime_r -> BCD -> multi-byte
I2C write of registers
0x04-0x0A with seconds bit7=0 (clears OS), then re-read confirms; I2C
access serialized
against `read_rtc` with a FreeRTOS mutex (console/SNTP context safe).
- `time_sync` service: on Wi-Fi CONNECTED starts `esp_netif_sntp`
(ntp.aliyun.com +
pool.ntp.org, `CONFIG_LWIP_SNTP_MAX_SERVERS=2`), and once `time()`
passes 2020-01-01 writes
the RTC once per sync (`rtc synced from sntp`).
- Console: `rtc status` (valid/unix/utc/OS bit), `rtc raw` (0x00-0x0A
hex + decode),
`rtc set YYYY-MM-DD HH:MM:SS` (strptime, UTC, range + calendar
round-trip validation).
2. **KEY feels slow**: display rendering was throttled to 10 s.
`display_service::run` now keeps
the 10 s full-render heartbeat (with memory refresh) but adds a 500 ms
fast path that
re-renders as soon as a signature over volatile fields (key counters,
key_pressed, wifi/storage
state, tf_logging_ok, ap_active, ssid_configured, rtc valid+minute)
changes. KEY counter now
appears within ~0.5-1 s.
3. **Which button?**: README now documents that only KEY (GPIO18) is
monitored; RST reboots and
BOOT (GPIO0) does nothing, plus the `rtc` commands, SNTP behavior, and
the CR1220 coin-cell
note (without a battery every power loss clears the clock again).
## On-device evidence
Single-session serial on /dev/ttyACM0 (see
`.omo/evidence/m1wp/rtc-render-fix-finish-m1-wifi-provisioning.log`):
- Post-flash boot auto-connected Wi-Fi and SNTP-synced the RTC before
the console attached
(pre-manual-set `rtc status` already showed real UTC 2026-08-31
05:17:55, OS bit clear).
- `rtc set 2026-08-31 12:00:00` -> `ESP_OK`; `rtc status` valid and
advancing across polls
(12:14:59 -> 12:15:49); JSONL `utc_valid:true` + non-empty `utc` with 10
s cadence and crc32c.
- Explicit RTS reset round captured live: `frame-time: sntp started
(ntp.aliyun.com,
pool.ntp.org)` and `frame-time: rtc synced from sntp (unix 1788154496)`
7.8 s after reset;
device-vs-host time delta 4 s.
- Pre-fix invalid state (OS bit set -> ESP_ERR_INVALID_CRC) is
documented in the prior soak
evidence (F3 log); the fix clears it on the first SNTP sync.
- KEY latency: no user press within the two assist windows;
console-observer polling at 500 ms
shows counters served immediately from the shared snapshot the display
fast path renders
(CITED: `volatile_signature` + 500 ms check in `display_service.cc`), 10
s heartbeat captured
via memory-metric refresh.
- Regression: `status --json` tf_logging=true, wifi=CONNECTED, selftest
`wifi_config: ok`.
Build 0 warnings; clang-format 18 clean;
pytest/ruff/frame-evidence/frame-doc-links green.
Co-authored-by: ania-lain <[email protected]>
This commit is contained in:
@@ -19,9 +19,30 @@ constexpr int kDrawRows = 40;
|
||||
constexpr std::size_t kDrawBytes =
|
||||
board::kDisplayWidth / 8U * static_cast<std::size_t>(kDrawRows) + 2U * sizeof(lv_color32_t);
|
||||
constexpr int64_t kRenderIntervalUs = 10LL * 1000LL * 1000LL;
|
||||
constexpr int64_t kFastCheckIntervalUs = 500LL * 1000LL;
|
||||
|
||||
uint32_t tick_milliseconds() { return static_cast<uint32_t>(esp_timer_get_time() / 1000); }
|
||||
|
||||
// Volatile-field digest; a change means the visible status text would change, so the
|
||||
// 500ms fast path re-renders without waiting for the 10s heartbeat.
|
||||
uint64_t volatile_signature(const status_snapshot& value) {
|
||||
uint64_t signature = UINT64_C(1469598103934665603);
|
||||
const auto fold = [&signature](uint64_t field) {
|
||||
signature = (signature ^ field) * UINT64_C(1099511628211);
|
||||
};
|
||||
fold(value.key_short_presses);
|
||||
fold(value.key_long_presses);
|
||||
fold(value.key_pressed ? 1U : 0U);
|
||||
fold(static_cast<uint64_t>(value.wifi));
|
||||
fold(static_cast<uint64_t>(value.storage));
|
||||
fold(value.tf_logging_ok ? 1U : 0U);
|
||||
fold(value.ap_active ? 1U : 0U);
|
||||
fold(value.ssid_configured ? 1U : 0U);
|
||||
fold(value.rtc.valid ? 1U : 0U);
|
||||
fold(value.rtc.valid ? static_cast<uint64_t>(value.rtc.unix_seconds / 60) : 0U);
|
||||
return signature;
|
||||
}
|
||||
|
||||
void format_rtc_time(const status_snapshot& value, char* output, std::size_t capacity) {
|
||||
output[0] = '\0';
|
||||
if (!value.rtc.valid) {
|
||||
@@ -198,12 +219,25 @@ void display_service::run() {
|
||||
}
|
||||
|
||||
int64_t next_render_at = 0;
|
||||
int64_t next_check_at = 0;
|
||||
uint64_t last_signature = 0;
|
||||
while (true) {
|
||||
const int64_t now = esp_timer_get_time();
|
||||
if (now >= next_render_at) {
|
||||
status_.refresh_memory_metrics();
|
||||
render_status(status_.snapshot());
|
||||
const status_snapshot value = status_.snapshot();
|
||||
render_status(value);
|
||||
last_signature = volatile_signature(value);
|
||||
next_render_at = now + kRenderIntervalUs;
|
||||
next_check_at = now + kFastCheckIntervalUs;
|
||||
} else if (now >= next_check_at) {
|
||||
const status_snapshot value = status_.snapshot();
|
||||
const uint64_t signature = volatile_signature(value);
|
||||
if (signature != last_signature) {
|
||||
render_status(value);
|
||||
last_signature = signature;
|
||||
}
|
||||
next_check_at = now + kFastCheckIntervalUs;
|
||||
}
|
||||
const uint32_t delay = std::clamp(lv_timer_handler(), UINT32_C(10), UINT32_C(1000));
|
||||
vTaskDelay(pdMS_TO_TICKS(delay));
|
||||
|
||||
Reference in New Issue
Block a user