refactor(core): refactor panel selection for touch driver
What changed, and why it matters
This commit is a straightforward internal cleanup of how Trezor firmware chooses touch-screen hardware drivers and matching touch-panel correction data. It splits a single combined setting into separate 'driver' and 'panel' settings, similar to how display configuration already works. There is no user-visible change, no bug fix, and no security improvement or regression visible in the code.
No security action required. Treat as normal code-quality refactor during review; verify that each board TOML now selects the same driver+panel pair as before and that builds still succeed for all affected models.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors Cargo feature flags and board TOML files so that touch controller selection (e.g., FT6X36, FT3168) is independent from touch-panel coordinate-correction selection (e.g., T2T1 identity, LX154A2422CPT23, LX250A2410A). Previously, features like touch_ft6x36_t2t1 and touch_ft6x36_t3t1 bundled both driver and panel; now touch_ft6x36 is paired with a separate touch_panel_ feature. Board headers lose the TOUCH_PANEL_ macro definitions, which are now emitted by core/embed/io/touch/build.rs based on the selected panel feature. The build script also adds explicit bail_unsupported!() fallbacks if no panel is selected. This is a structural refactor with no functional logic changes to the touch drivers themselves.
Changed components
core/embed/io/Cargo.tomlcore/embed/io/touch/build.rscore/embed/models/T2T1/boards/hw.tomlcore/embed/models/T3T1/boards/revE.tomlcore/embed/models/T3T1/boards/trezor_t3t1_revE.hcore/embed/models/T3W1/boards/revA.tomlcore/embed/models/T3W1/boards/revB.tomlcore/embed/models/T3W1/boards/revC.tomlcore/embed/models/T3W1/boards/trezor_t3w1_revA.hcore/embed/models/T3W1/boards/trezor_t3w1_revB.hcore/embed/models/T3W1/boards/trezor_t3w1_revC.hInspect captured patch +71 / −18
diff --git a/core/embed/io/Cargo.toml b/core/embed/io/Cargo.toml
index 9badccca..1a308ee3 100644
--- a/core/embed/io/Cargo.toml
+++ b/core/embed/io/Cargo.toml
@@ -91,12 +91,18 @@ backlight_tps61043 = []
backlight_tps61062 = []
backlight_pin = []
-touch_ft6x36_t2t1 = []
-touch_ft6x36_t3t1 = []
+# touch drivers
+touch_ft6x36 = []
touch_ft3168 = []
touch_stmpe811 = []
touch_sitronix = []
+# touch panels (coordinate correction); selected alongside the driver by the
+# board TOML, mirroring the display driver/panel split below.
+touch_panel_t2t1 = []
+touch_panel_lx154a2422cpt23 = []
+touch_panel_lx250a2410a = []
+
framebuffer = []
# Drivers below that always need framebuffer pull it in implicitly,
diff --git a/core/embed/io/touch/build.rs b/core/embed/io/touch/build.rs
index 8bcc6ced..8478ba03 100644
--- a/core/embed/io/touch/build.rs
+++ b/core/embed/io/touch/build.rs
@@ -19,18 +19,14 @@ pub fn def_module(lib: &mut CLibrary) -> Result<()> {
}
if cfg!(feature = "emulator") {
- // The emulator always builds the unix touch driver instead of the HW one.
+ // The emulator reuses the emulated board's touch configuration but always
+ // builds the unix driver instead of the HW one. The unix driver does no
+ // panel correction, so the selected panel feature is ignored here.
lib.add_source("touch/unix/touch.c");
} else if cfg!(feature = "touch_ft3168") {
- lib.add_define("TOUCH_WAKEUP_ENABLED", Some("0"));
- lib.add_sources(["touch/ft3168/ft3168.c", "touch/ft3168/panels/lx250a2410a.c"]);
- } else if cfg!(feature = "touch_ft6x36_t3t1") {
- lib.add_sources([
- "touch/ft6x36/ft6x36.c",
- "touch/ft6x36/panels/lx154a2422cpt23.c",
- ]);
- } else if cfg!(feature = "touch_ft6x36_t2t1") {
- lib.add_source("touch/ft6x36/ft6x36.c");
+ add_driver_ft3168(lib)?;
+ } else if cfg!(feature = "touch_ft6x36") {
+ add_driver_ft6x36(lib)?;
} else if cfg!(feature = "touch_stmpe811") {
lib.add_sources(["touch/stmpe811/stmpe811.c", "touch/stmpe811/touch.c"]);
} else if cfg!(feature = "touch_sitronix") {
@@ -41,3 +37,53 @@ pub fn def_module(lib: &mut CLibrary) -> Result<()> {
Ok(())
}
+
+// ---------------------------------------------------------------------------
+// Panel functions: panel-selection define only, no driver knowledge.
+//
+// Only the panel-selection macro lives here; board-specific wiring and tuning
+// (TOUCH_SENSITIVITY, reset/interrupt pins, I2C instance) stay in the board
+// header.
+// -------------------------------------------------------------------------
+
+fn set_panel_t2t1(_lib: &mut CLibrary) {
+ // The T2T1 panel needs no touch coordinate correction; the driver falls back
+ // to identity mapping when no TOUCH_PANEL_* macro is defined.
+}
+
+fn set_panel_lx154a2422cpt23(lib: &mut CLibrary) {
+ lib.add_define("TOUCH_PANEL_LX154A2422CPT23", Some("1"));
+}
+
+fn set_panel_lx250a2410a(lib: &mut CLibrary) {
+ lib.add_define("TOUCH_PANEL_LX250A2410A", Some("1"));
+}
+
+// --------------------------------------------------------------------------
+// Driver functions: select panel (define + correction source), then add the
+// driver sources.
+// --------------------------------------------------------------------------
+
+fn add_driver_ft6x36(lib: &mut CLibrary) -> Result<()> {
+ lib.add_source("touch/ft6x36/ft6x36.c");
+ if cfg!(feature = "touch_panel_t2t1") {
+ set_panel_t2t1(lib);
+ } else if cfg!(feature = "touch_panel_lx154a2422cpt23") {
+ set_panel_lx154a2422cpt23(lib);
+ lib.add_source("touch/ft6x36/panels/lx154a2422cpt23.c");
+ } else {
+ bail_unsupported!();
+ }
+ Ok(())
+}
+
+fn add_driver_ft3168(lib: &mut CLibrary) -> Result<()> {
+ lib.add_source("touch/ft3168/ft3168.c");
+ if cfg!(feature = "touch_panel_lx250a2410a") {
+ set_panel_lx250a2410a(lib);
+ lib.add_source("touch/ft3168/panels/lx250a2410a.c");
+ } else {
+ bail_unsupported!();
+ }
+ Ok(())
+}
diff --git a/core/embed/models/T2T1/boards/hw.toml b/core/embed/models/T2T1/boards/hw.toml
index 30740d47..5fd256a8 100644
--- a/core/embed/models/T2T1/boards/hw.toml
+++ b/core/embed/models/T2T1/boards/hw.toml
@@ -9,7 +9,8 @@ panel = "io/display_panel_t2t1"
driver = "io/backlight_tps61043"
[touch]
-driver = "io/touch_ft6x36_t2t1"
+driver = "io/touch_ft6x36"
+panel = "io/touch_panel_t2t1"
[sd_card]
diff --git a/core/embed/models/T3T1/boards/revE.toml b/core/embed/models/T3T1/boards/revE.toml
index 6bef27b0..9a2e7dc8 100644
--- a/core/embed/models/T3T1/boards/revE.toml
+++ b/core/embed/models/T3T1/boards/revE.toml
@@ -9,7 +9,8 @@ panel = "io/display_panel_lx154a2482"
driver = "io/backlight_tps61043"
[touch]
-driver = "io/touch_ft6x36_t3t1"
+driver = "io/touch_ft6x36"
+panel = "io/touch_panel_lx154a2422cpt23"
[haptic]
diff --git a/core/embed/models/T3T1/boards/trezor_t3t1_revE.h b/core/embed/models/T3T1/boards/trezor_t3t1_revE.h
index fc1f9fb5..f5e586fe 100644
--- a/core/embed/models/T3T1/boards/trezor_t3t1_revE.h
+++ b/core/embed/models/T3T1/boards/trezor_t3t1_revE.h
@@ -82,7 +82,6 @@
#define I2C_INSTANCE_2_ER_IRQn I2C3_ER_IRQn
#define I2C_INSTANCE_2_GUARD_TIME 50 // Optiga requires 50us guard time
-#define TOUCH_PANEL_LX154A2422CPT23 1
#define TOUCH_SENSITIVITY 0x40
#define TOUCH_I2C_INSTANCE 0
#define TOUCH_RST_PORT GPIOC
diff --git a/core/embed/models/T3W1/boards/revA.toml b/core/embed/models/T3W1/boards/revA.toml
index cbfd99d3..dc74a5b4 100644
--- a/core/embed/models/T3W1/boards/revA.toml
+++ b/core/embed/models/T3W1/boards/revA.toml
@@ -10,6 +10,7 @@ driver = "io/backlight_tps61062"
[touch]
driver = "io/touch_ft3168"
+panel = "io/touch_panel_lx250a2410a"
[button]
diff --git a/core/embed/models/T3W1/boards/revB.toml b/core/embed/models/T3W1/boards/revB.toml
index 1035c76d..ceba657f 100644
--- a/core/embed/models/T3W1/boards/revB.toml
+++ b/core/embed/models/T3W1/boards/revB.toml
@@ -10,6 +10,7 @@ driver = "io/backlight_tps61062"
[touch]
driver = "io/touch_ft3168"
+panel = "io/touch_panel_lx250a2410a"
[button]
diff --git a/core/embed/models/T3W1/boards/revC.toml b/core/embed/models/T3W1/boards/revC.toml
index 01f6f20e..d5a1fa48 100644
--- a/core/embed/models/T3W1/boards/revC.toml
+++ b/core/embed/models/T3W1/boards/revC.toml
@@ -10,6 +10,7 @@ driver = "io/backlight_tps61062"
[touch]
driver = "io/touch_ft3168"
+panel = "io/touch_panel_lx250a2410a"
[button]
diff --git a/core/embed/models/T3W1/boards/trezor_t3w1_revA.h b/core/embed/models/T3W1/boards/trezor_t3w1_revA.h
index ab159c9d..db47b626 100644
--- a/core/embed/models/T3W1/boards/trezor_t3w1_revA.h
+++ b/core/embed/models/T3W1/boards/trezor_t3w1_revA.h
@@ -124,7 +124,6 @@
#define I2C_INSTANCE_3_GUARD_TIME 50
#define I2C_INSTANCE_3_GTZC_PERIPH GTZC_PERIPH_I2C4
-#define TOUCH_PANEL_LX250A2410A 1
#define TOUCH_SENSITIVITY 0x40
#define TOUCH_I2C_INSTANCE 2
#define TOUCH_INT_PORT GPIOC
diff --git a/core/embed/models/T3W1/boards/trezor_t3w1_revB.h b/core/embed/models/T3W1/boards/trezor_t3w1_revB.h
index 3606e608..4568b247 100644
--- a/core/embed/models/T3W1/boards/trezor_t3w1_revB.h
+++ b/core/embed/models/T3W1/boards/trezor_t3w1_revB.h
@@ -124,7 +124,6 @@
#define I2C_INSTANCE_3_GUARD_TIME 50
#define I2C_INSTANCE_3_GTZC_PERIPH GTZC_PERIPH_I2C4
-#define TOUCH_PANEL_LX250A2410A 1
#define TOUCH_SENSITIVITY 0x40
#define TOUCH_I2C_INSTANCE 2
#define TOUCH_INT_PORT GPIOC
diff --git a/core/embed/models/T3W1/boards/trezor_t3w1_revC.h b/core/embed/models/T3W1/boards/trezor_t3w1_revC.h
index 4987b386..b0c0d148 100644
--- a/core/embed/models/T3W1/boards/trezor_t3w1_revC.h
+++ b/core/embed/models/T3W1/boards/trezor_t3w1_revC.h
@@ -142,7 +142,6 @@
#define I2C_INSTANCE_4_ER_IRQn I2C5_ER_IRQn
#define I2C_INSTANCE_4_GUARD_TIME 0
-#define TOUCH_PANEL_LX250A2410A 1
#define TOUCH_SENSITIVITY 0x40
#define TOUCH_I2C_INSTANCE 4
#define TOUCH_INT_PORT GPIOC
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.