From 79b7600448b8713b4aefcdfb1229dfe2caad0d26 Mon Sep 17 00:00:00 2001 From: Mel Date: Wed, 30 Apr 2025 17:47:52 +0200 Subject: Parameterize ADS7846 touchscreen device tree Signed-off-by: Mel --- modules/hardware/ads7846.nix | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'modules') diff --git a/modules/hardware/ads7846.nix b/modules/hardware/ads7846.nix index bb1fe61..4d7582a 100644 --- a/modules/hardware/ads7846.nix +++ b/modules/hardware/ads7846.nix @@ -5,7 +5,7 @@ services = let calibrationPoints = "3900 200 200 3900"; - calibrationMatrix = "-1 0 1 0 1 0 0 0 1"; + calibrationMatrix = "-1 0 1 0 1 0"; in { libinput.enable = true; @@ -29,8 +29,17 @@ hardware.deviceTree = let - # todo: parameter-ize this more. + cs = 1; penirq = 25; + penirq_pull = 2; + speed = 50000; + pmin = 0; + pmax = 255; + xohms = 150; + xmin = 200; + xmax = 3900; + ymin = 200; + ymax = 3900; in { overlays = [ @@ -77,7 +86,7 @@ ads7846_pins: ads7846_pins { brcm,pins = <${toString penirq}>; /* mel: previously illegal value of 255 */ brcm,function = <0>; /* in */ - brcm,pull = <0>; /* none */ + brcm,pull = <${toString penirq_pull}>; /* none */ }; }; }; @@ -91,23 +100,23 @@ ads7846: ads7846@1 { compatible = "ti,ads7846"; - reg = <1>; + reg = <${toString cs}>; pinctrl-names = "default"; pinctrl-0 = <&ads7846_pins>; - spi-max-frequency = <2000000>; + spi-max-frequency = <${toString speed}>; interrupts = <${toString penirq} 2>; /* high-to-low edge triggered */ interrupt-parent = <&gpio>; pendown-gpio = <&gpio ${toString penirq} 1>; /* driver defaults */ - ti,x-min = /bits/ 16 <0>; - ti,y-min = /bits/ 16 <0>; - ti,x-max = /bits/ 16 <0x0FFF>; - ti,y-max = /bits/ 16 <0x0FFF>; - ti,pressure-min = /bits/ 16 <0>; - ti,pressure-max = /bits/ 16 <0xFFFF>; - ti,x-plate-ohms = /bits/ 16 <400>; + ti,x-min = /bits/ 16 <${toString xmin}>; + ti,y-min = /bits/ 16 <${toString ymin}>; + ti,x-max = /bits/ 16 <${toString xmax}>; + ti,y-max = /bits/ 16 <${toString ymax}>; + ti,pressure-min = /bits/ 16 <${toString pmin}>; + ti,pressure-max = /bits/ 16 <${toString pmax}>; + ti,x-plate-ohms = /bits/ 16 <${toString xohms}>; }; }; }; -- cgit 1.4.1