Seeed / 52Pi PiShow 2.8 device tree overlay

This post is about the PiShow 2.8″ Resistive Touch Display from Seeedstudio. I found this little 65K colors and 320×240 pixel touch display for $20 at one of there sales.

The documentation on there web page is not easy to understand and everything you need is already part of the standard operating system image.

I used some existing device tree overlay and merged them and changed the pins and adopted the settings from the seeed documentation.

The scree is showing the picture, the touch is working with my finger and the four buttons on the side are working too. I would call this a success.

Thanks to @notro for his guidance to make this example and his work in this area in general.

/*
 * Device Tree overlay for pishow 2.8
 *
 */

/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

    fragment@0 {
    target = <&spi0>;
    __overlay__ {
        status = "okay";

        spidev@0{
        status = "disabled";
        };

        spidev@1{
        status = "disabled";
        };
    };
    };

    fragment@1 {
    target = <&gpio>;
    __overlay__ {
        pishow_display_pins: pishow_display_pins {
        brcm,pins = <18 23 24 25>;
        brcm,function = <1 1 1 0>; /* out out out in */
        brcm,pull = <0>; /* none */
        };
            pishow_ts_pins: pishow_ts_pins {
        brcm,pins = <22>;
        brcm,function = <0>; /* in */
        };
        keypad_pins: keypad_pins {
        brcm,pins = <16 20 21 26>;
        brcm,function = <0>; /* in */
        brcm,pull = <1>; /* down */
        };
    };
    };

    fragment@2 {
    target = <&spi0>;
    __overlay__ {
        /* needed to avoid dtc warning */
        #address-cells = <1>;
        #size-cells = <0>;

        pishow28: pishow28@0{
        compatible = "ilitek,ili9341";
        reg = <0>;
        pinctrl-names = "default";
        pinctrl-0 = <&pishow_display_pins>,
                <&pishow_ts_pins>;

        spi-max-frequency = <32000000>;
        rotate = <270>;
        bgr;
        fps = <30>;
        buswidth = <8>;
        reset-gpios = <&gpio 23 0>;
        dc-gpios = <&gpio 24 0>;
        led-gpios = <&gpio 18 1>;
        debug = <0>;
        };

        pishow28_ts: pishow28_ts@1 {
        compatible = "ti,ads7846";
        reg = <1>;

        spi-max-frequency = <2000000>;
        interrupts = <22 2>; /* high-to-low edge triggered */
        interrupt-parent = <&gpio>;
        ti,keep-vref-on = <1>;
        pendown-gpio = <&gpio 22 0>;
        /* driver defaults */
        ti,x-min = /bits/ 16 <230>;
        ti,y-min = /bits/ 16 <200>;
        ti,x-max = /bits/ 16 <3900>;
        ti,y-max = /bits/ 16 <3700>;
        ti,pressure-min = /bits/ 16 <0>;
        ti,pressure-max = /bits/ 16 <0xFFFF>;
        ti,x-plate-ohms = /bits/ 16 <80>;
        ti,swap-xy = <1>;
        };
    };
    };
    fragment@3 {
    target-path = "/soc";
    __overlay__ {
        keypad: keypad {
        compatible = "gpio-keys";
        #address-cells = <1>;
        #size-cells = <0>;
        pinctrl-names = "default";
        pinctrl-0 = <&keypad_pins>;
        #status = "disabled";
        autorepeat;
        button@16 {
            label = "GPIO KEY_UP";
            linux,code = <103>;
            gpios = <&gpio 16 0>;
        };
        button@26 {
            label = "GPIO KEY_DOWN";
            linux,code = <108>;
            gpios = <&gpio 26 0>;
        };
        button@20 {
            label = "GPIO KEY_LEFT";
            linux,code = <105>;
            gpios = <&gpio 20 0>;
        };
        button@21 {
            label = "GPIO KEY_RIGHT";
            linux,code = <106>;
            gpios = <&gpio 21 0>;
        };
        };
    };
    };
    __overrides__ {
    speed =   <&pishow28>,"spi-max-frequency:0";
    rotate =  <&pishow28>,"rotate:0";
    fps =     <&pishow28>,"fps:0";
    debug =   <&pishow28>,"debug:0";
    swapxy =  <&pishow28_ts>,"ti,swap-xy;0";
    xmin =    <&pishow28_ts>,"ti,x-min;0";
    ymin =    <&pishow28_ts>,"ti,y-min;0";
    xmax =    <&pishow28_ts>,"ti,x-max;0";
    ymax =    <&pishow28_ts>,"ti,y-max;0";
    pmin =    <&pishow28_ts>,"ti,pressure-min;0";
    pmax =    <&pishow28_ts>,"ti,pressure-max;0";
    xohms =   <&pishow28_ts>,"ti,x-plate-ohms;0";
    #keypad =  <&keypad>,"status";
    };
};

I used this script to install the device tree compiler dtc. After the compiler was installed this command creates the dtbo file:

sudo dtc -@ -I dts -O dtb -o /boot/overlays/pishow28.dtbo pishow28.dts

The last step is to add “dtoverlay=pishow28” to the end of the “/boot/config.txt” file.

Plus the /etc/X11/xorg.conf.d/99-ads7846-cal.conf file that swaps the X and Y axis:

Section "InputClass"
    Identifier "Touchscreen"
    MatchProduct "ADS7846 Touchscreen"
    Option "InvertX" "1"
    Option "InvertY" "1"
    Option "SwapAxes" "0"
    Option "Calibration" "215 3800 129 3676"
EndSection

I also added one line in /etc/udev/rules.d/95-ads7846.rules file:

SUBSYSTEM=="input", KERNEL=="event[0-9]*", ATTRS{name}=="ADS7846*", SYMLINK+="input/touchscreen"

As an extra I did install the frame buffer copy tool to copy the main frame buffer to the new touch display frame buffer.