diff options
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/hardware/ads7846.nix | 211 |
1 files changed, 121 insertions, 90 deletions
diff --git a/modules/hardware/ads7846.nix b/modules/hardware/ads7846.nix index cf1131e..bb1fe61 100644 --- a/modules/hardware/ads7846.nix +++ b/modules/hardware/ads7846.nix @@ -1,104 +1,135 @@ { ... }: { - hardware.deviceTree = { - overlays = [ - { - name = "ads7846-overlay"; - # taken from raspberry-pi kernel tree: - # https://github.com/raspberrypi/linux/blob/rpi-6.6.y/arch/arm/boot/dts/overlays/ads7846-overlay.dts - dtsText = '' - /* - * Generic Device Tree overlay for the ADS7846 touch controller - * - */ + # calibration for touchscreen + services = + let + calibrationPoints = "3900 200 200 3900"; + calibrationMatrix = "-1 0 1 0 1 0 0 0 1"; + in + { + libinput.enable = true; - /dts-v1/; - /plugin/; + # xorg configuration + xserver.inputClassSections = [ + '' + Identifier "ads7846 calibration" + MatchProduct "ADS7846 Touchscreen" + Option "Calibration" "${calibrationPoints}" + Option "SwapAxes" "0" + Driver "libinput" + '' + ]; - / { - compatible = "brcm,bcm2835"; + # wayland configuration + udev.extraRules = '' + ATTRS{name}=="ADS7846 Touchscreen", ENV{LIBINPUT_CALIBRATION_MATRIX}="${calibrationMatrix}" + ''; + }; - fragment@0 { - target = <&spi0>; - __overlay__ { - status = "okay"; - }; - }; + hardware.deviceTree = + let + # todo: parameter-ize this more. + penirq = 25; + in + { + overlays = [ + { + name = "ads7846-overlay"; + # taken from raspberry-pi kernel tree: + # https://github.com/raspberrypi/linux/blob/rpi-6.6.y/arch/arm/boot/dts/overlays/ads7846-overlay.dts + dtsText = '' + /* + * Generic Device Tree overlay for the ADS7846 touch controller + * + */ - fragment@1 { - target = <&spidev0>; - __overlay__ { - status = "disabled"; - }; - }; + /dts-v1/; + /plugin/; - fragment@2 { - target = <&spidev1>; - __overlay__ { - status = "disabled"; - }; - }; + / { + compatible = "brcm,bcm2711"; - fragment@3 { - target = <&gpio>; - __overlay__ { - ads7846_pins: ads7846_pins { - brcm,pins = <255>; /* illegal default value */ - brcm,function = <0>; /* in */ - brcm,pull = <0>; /* none */ - }; - }; - }; + fragment@0 { + target = <&spi0>; + __overlay__ { + status = "okay"; + }; + }; - fragment@4 { - target = <&spi0>; - __overlay__ { - /* needed to avoid dtc warning */ - #address-cells = <1>; - #size-cells = <0>; + fragment@1 { + target = <&spidev0>; + __overlay__ { + status = "disabled"; + }; + }; - ads7846: ads7846@1 { - compatible = "ti,ads7846"; - reg = <1>; - pinctrl-names = "default"; - pinctrl-0 = <&ads7846_pins>; + fragment@2 { + target = <&spidev1>; + __overlay__ { + status = "disabled"; + }; + }; - spi-max-frequency = <2000000>; - interrupts = <255 2>; /* high-to-low edge triggered */ - interrupt-parent = <&gpio>; - pendown-gpio = <&gpio 255 1>; + fragment@3 { + target = <&gpio>; + __overlay__ { + ads7846_pins: ads7846_pins { + brcm,pins = <${toString penirq}>; /* mel: previously illegal value of 255 */ + brcm,function = <0>; /* in */ + brcm,pull = <0>; /* none */ + }; + }; + }; - /* 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>; - }; - }; - }; - __overrides__ { - cs = <&ads7846>,"reg:0"; - speed = <&ads7846>,"spi-max-frequency:0"; - penirq = <&ads7846_pins>,"brcm,pins:0", /* REQUIRED */ - <&ads7846>,"interrupts:0", - <&ads7846>,"pendown-gpio:4"; - penirq_pull = <&ads7846_pins>,"brcm,pull:0"; - swapxy = <&ads7846>,"ti,swap-xy?"; - xmin = <&ads7846>,"ti,x-min;0"; - ymin = <&ads7846>,"ti,y-min;0"; - xmax = <&ads7846>,"ti,x-max;0"; - ymax = <&ads7846>,"ti,y-max;0"; - pmin = <&ads7846>,"ti,pressure-min;0"; - pmax = <&ads7846>,"ti,pressure-max;0"; - xohms = <&ads7846>,"ti,x-plate-ohms;0"; - }; - }; - ''; - } - ]; - }; + fragment@4 { + target = <&spi0>; + __overlay__ { + /* needed to avoid dtc warning */ + #address-cells = <1>; + #size-cells = <0>; + + ads7846: ads7846@1 { + compatible = "ti,ads7846"; + reg = <1>; + pinctrl-names = "default"; + pinctrl-0 = <&ads7846_pins>; + + spi-max-frequency = <2000000>; + 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>; + }; + }; + }; + __overrides__ { + cs = <&ads7846>,"reg:0"; + speed = <&ads7846>,"spi-max-frequency:0"; + penirq = <&ads7846_pins>,"brcm,pins:0", /* REQUIRED */ + <&ads7846>,"interrupts:0", + <&ads7846>,"pendown-gpio:4"; + penirq_pull = <&ads7846_pins>,"brcm,pull:0"; + swapxy = <&ads7846>,"ti,swap-xy?"; + xmin = <&ads7846>,"ti,x-min;0"; + ymin = <&ads7846>,"ti,y-min;0"; + xmax = <&ads7846>,"ti,x-max;0"; + ymax = <&ads7846>,"ti,y-max;0"; + pmin = <&ads7846>,"ti,pressure-min;0"; + pmax = <&ads7846>,"ti,pressure-max;0"; + xohms = <&ads7846>,"ti,x-plate-ohms;0"; + }; + }; + ''; + } + ]; + }; } |
