Skip to content

Commit ea82143

Browse files
cinimlclaude
andcommitted
tune(touch): RTC を 2→5 に拡大 + サーボ電源 ON 後に recalibrate()
m5stack/StackChan-BSP#6 で提案された残り 2 つの対策を導入。 1. CTRL1 の RTC[2:0] を 2 → 5 に拡大。応答サイクルが 4 → 7 になり、 software 側の firmly_touched() フィルタに加えて HW debounce が 1 段乗る。radio coex バースト 1 発で抜けてくる単発スパイクを 弾く目的。なで検出のレイテンシは ~30 ms 程度しか増えない。 2. Si12tTouch::recalibrate() を追加し、サーボ VM 電源 ON + 1.5 s settle 後に呼び出して baseline を再取得。サーボ電源が立ち上がる と内部電源環境が変わって以前の baseline が外れたまま FTC=10 s の slow auto-cal を待つことになり、その間 ghost touch が出る原因。 実機で「感度を Type_Low/L3 に下げても誤爆がまだ起きる」状態だったので 合わせ技で対策。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent a9f63f5 commit ea82143

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

components/board/include/board/si12t_touch.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ class Si12tTouch {
6565
// intensities. Returns an all-zero Reading on bus error.
6666
Reading read();
6767

68+
// Force the chip to update its idle baseline for all channels. Call
69+
// after a disturbance that's likely to skew the running baseline (e.g.
70+
// servo VM rail switched on, Wi-Fi associated). Without this the chip
71+
// can park its baseline mid-burst and report ghost touches until its
72+
// own slow auto-calibration catches up (FTC = 10 s).
73+
void recalibrate();
74+
6875
std::uint8_t address() const noexcept { return address_; }
6976

7077
private:

components/board/si12t_touch.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,15 @@ constexpr std::uint8_t kRegOutput1 = 0x10;
4545
// firmware (hal_head_touch.cpp). m5stack/StackChan-BSP#6 trial.
4646
constexpr std::uint8_t kSensitivityValue = 0x33;
4747

48-
// CTRL1 = Auto Mode, FTC=01, response interrupt on Middle/High.
49-
constexpr std::uint8_t kCtrl1Value = 0x22;
48+
// CTRL1 = MS | FTC[1:0] | ILC[1:0] | RTC[2:0].
49+
// 0x25 = auto mode, FTC=01 (10 s first-touch recal), ILC=00 (interrupt on
50+
// middle/high), RTC=5 → response cycle (RTC + 2) = 7 scan cycles.
51+
// Was 0x22 (RTC=2 → 4 cycles); bumping to 5 stacks an extra HW debounce
52+
// on top of our software firmly_touched() filter to reject single-spike
53+
// noise from radio coex bursts. Trade-off: nadenade latency rises by
54+
// roughly (5-2) scan cycles ≈ 30 ms at the chip's default scan rate,
55+
// which is unnoticeable for head-petting. m5stack/StackChan-BSP#6 trial.
56+
constexpr std::uint8_t kCtrl1Value = 0x25;
5057

5158
} // namespace
5259

@@ -91,6 +98,19 @@ tl::expected<Si12tTouch, Error> Si12tTouch::probe(std::uint8_t address)
9198
return chip;
9299
}
93100

101+
void Si12tTouch::recalibrate()
102+
{
103+
// Pulse all-channel bits in Ref_rst1 (ch 1-8) / Ref_rst2 (ch 9-12) to
104+
// force the chip to update its idle baseline (datasheet 12.2.4). Call
105+
// after known disturbances — power-rail switching, radio coex bursts —
106+
// that would otherwise leave the baseline biased and the chip stuck
107+
// reporting low-level intensities with nothing touching it.
108+
write_register(kRegRefRst1, 0xFF);
109+
write_register(kRegRefRst2, 0x0F);
110+
write_register(kRegRefRst1, 0x00);
111+
write_register(kRegRefRst2, 0x00);
112+
}
113+
94114
Si12tTouch::Reading Si12tTouch::read()
95115
{
96116
Reading r{};

main/app_main.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,15 @@ extern "C" void app_main()
11211121
// driving UART. SCS0009 needs ~1 s after Vmotor comes up before it
11221122
// answers PING.
11231123
vTaskDelay(pdMS_TO_TICKS(1500));
1124+
// Servo VM coming up is a known Si12T baseline disturbance: the
1125+
// chip's running baseline acquired with Vmotor off no longer
1126+
// matches the post-power-on environment, which we've seen as
1127+
// ghost head-touch firings in the first few seconds. Force a
1128+
// baseline update now (cheap: 4 I2C writes) so the chip starts
1129+
// clean instead of waiting for FTC=10 s to drift back.
1130+
if (auto* t = board.touch_sensor(); t != nullptr) {
1131+
t->recalibrate();
1132+
}
11241133
} else if (!cfg.servo_enabled) {
11251134
ESP_LOGW(kTag, "servo VM rail OFF: cfg.servo_enabled=false (set via settings UI)");
11261135
}

0 commit comments

Comments
 (0)