orangepi zero2 触摸屏幕SPI驱动

发布于:
分类: 嵌入式

orangepi zero2的5.x 内核的官方映像中没有内置 ili9488 的驱动程序,在4pda.to上面找到作者为vmb1983的文章,终于驱动成功。

ili9488.dts文件

/dts-v1/;
/plugin/;

/ {
    compatible = "xunlong,orangepi-zero2", "allwinner,sun50i-h616";

    fragment@0 {
        target = <&spi1>;
        __overlay__ {
            status = "okay";
            cs-gpios = <&pio 7 5 0>; /* PH5=CS0 */

            ili9488: ili9488@0 {
                compatible = "ilitek,ili9488";
                reg = <0>;
                pinctrl-names = "default";
                spi-max-frequency = <64000000>;
                rotate = <270>;
                bgr = <0>;
                fps = <30>;
                buswidth = <8>;
                reset-gpios = <&pio 2 8 1>; /* PC8 */
                dc-gpios = <&pio 2 5 0>; /* PC5 */
                led-gpios = <&pio 2 6 0>; /* PC6 */
                debug = <0>;
            };
        };
    };
};

如果是ili9486 需要修改初始化,可以用下面的dts(包含了ads7846触摸驱动)

/dts-v1/;
/plugin/;

/ {
    compatible = "allwinner,sun50i-h616";

    fragment@0 {
        target = <&spi1>;
        __overlay__ {
            status = "okay";
            cs-gpios = <&pio 2 10 0>,<&pio 7 5 0>; /*PC10=CS0 PH5=CS1*/

            ili9488: ili9488@1 {
                compatible = "ilitek,ili9488";
                reg = <1>;
                pinctrl-names = "default";
                spi-max-frequency = <32000000>;
                rotate = <90>;
                bgr = <0>;
                fps = <30>;
                buswidth = <8>;
                reset-gpios = <&pio 2 8 1>; /* PC8 */
                dc-gpios = <&pio 2 5 0>; /* PC5 */
                led-gpios = <&pio 2 6 0>; /* PC6 */
                debug = <0>;
                init = <
                    0x10000b0 0x0
                    0x1000011
                    0x20000FF
                    0x100003A 0x66
                    0x10000C2 0x44
                    0x10000C5 0x00 0x00 0x00 0x00
                    0x10000E0 0x0F 0x1F 0x1C 0x0C 0x0F 0x08 0x48 0x98 0x37 0x0A 0x13 0x04 0x11 0x0D 0x00
                    0x10000E1 0x0F 0x32 0x2E 0x0B 0x0D 0x05 0x47 0x75 0x37 0x06 0x10 0x03 0x24 0x20 0x00
                    0x10000E2 0x0F 0x32 0x2E 0x0B 0x0D 0x05 0x47 0x75 0x37 0x06 0x10 0x03 0x24 0x20 0x00
                    0x1000011
                    0x1000029>;
            };

            ads7846: ads7846@0 {
                compatible = "ti,ads7846";
                reg = <0>;
                pinctrl-names = "default";
                spi-max-frequency = <2000000>;
                interrupts = <2 9 2>; /* PC9 - IRQ */
                interrupt-parent = <&pio>;
                pendown-gpio = <&pio 2 9 0>; /* PC9 */
                
                /* OPTIONS */
                ti,keep-vref-on = <1>;
              			ti,pressure-min = /bits/ 16 <10>;
                ti,pressure-max = /bits/ 16 <1000>;
                ti,debounce-rep = /bits/ 16 <1>;
                ti,debounce-tol = /bits/ 16 <2>;
                ti,debounce-max = /bits/ 16 <100>;
                ti,settle-delay-usec = /bits/ 16 <20>;
                ti,penirq-recheck-delay-usecs = /bits/ 16 <20>;
                ti,x-plate-ohms = /bits/ 16 <400>;
                ti,y-plate-ohms = /bits/ 16 <400>;
            };
        };
    };
};

网上复制的gt911_i2c2.dts,需要可以添加

/dts-v1/;
/plugin/;

/ {
    compatible = "xunlong,orangepi-zero2", "allwinner,sun50i-h616";

    fragment@0 {
        target = <&i2c2>;
        __overlay__ {
            #address-cells = <1>;
            #size-cells = <0>;
            status = "okay";

            gt911@5d {
                    compatible = "goodix,gt911";
                    reg = <0x5d>;	// or 0x14
                    pinctrl-names = "default";
                    interrupt-parent = <&pio>;
                    interrupts = <2 9 2>; /* PC9-IRQ */
                    irq-gpios = <&pio 2 9 0>; /* PC9 */
                    reset-gpios = <&pio 7 4 0>; /* PH4 */

                    /* NOTE: Rotated 270 degree */
                    touchscreen-size-x = <320>;
                    touchscreen-size-y = <480>;
                    touchscreen-swapped-x-y = <0>;
                    touchscreen-inverted-x = <1>;
                    touchscreen-inverted-y = <0>;
            };
        };
    };
};

接线方式

触摸屏引脚 GPIO Orangepi引脚
CS PH5 03
RST PC8 15
D/C PC5 13
SDI(TDI)/MOS PH7 19
SCK(TCK) PH6 23
BL/LED PC6 11
SDO Empty
TCS PC10 26
TDO/MIS PH8 21
PEN/TIRQ PC9 07

ili9488驱动安装

cp *.ko /lib/modules/5.16.17-sun50iw9/kernel/drivers/staging/fbtft/
depmod

orangepi-add-overlay ili9488.dts
orangepi-add-overlay ads7846.dts

模块的软件连接

我从根目录下完成了所有操作。如果您在普通用户下执行此操作,那么最好在所有命令之前添加sudo以使用 root 权限执行它们。

cp *.dts /boot/overlay-user/
orangepi-add-overlay ili9488_ads7846.dts

其中XXX是 DTS 文件所在文件夹的完整路径,YYY是该文件的名称。
指定的命令会将*.dts文件转换为.dtbo文件(同名),放入/boot/overlay-user文件夹,并将覆盖文件的名称(不带扩展名)添加到/boot/orangepiEnv.txt文件中的“user_overlays= ”。

小心 SPI 频率:如果太高,它将无法工作。对于显示器,我建议从 16 MHz 开始,然后根据需要增加。对于触摸屏您可以保持在 2 MHz(4 时它不再适用于我)。

重新启动后,控制台应显示在屏幕上。要检查触屏,您可以运行命令 evtest 测试
它将为您提供可用输入设备的列表,包括 ADS7846 触摸屏(或类似设备)。选择后,程序会切换到输入事件等待模式,当触摸独轮车时,会在屏幕上显示相应的信息。退出此程序 Ctrl+C。

如果有些东西不起作用,你可以运行命令dmesg|grep spi然后查看日志,看是否有任何错误。
如果一切正常,则连接正确且模块正常工作。接下来,您需要继续设置以在图形模式下使用。

关于设置模块,创建 /usr/share/X11/xorg.conf.d/99-fbdev.conf 文件, 让屏幕自动显示图形:

Section "Device"
Identifier "fbtft"
Driver "fbdev"
Option "fbdev" "/dev/fb0"
EndSection

如果有额外的 HDMI 屏幕,您可能需要指定 fb1 而不是 fb0。
理论上,此后启动/重启该服务后,屏幕上应该会出现KlipperScreen界面。

首先,您需要检查是否对按下屏幕至少有一些反应。如果有,您可以继续校准(见下文)。如果没有反应(但在 evtest 中一切正常),请执行以下操作:
使用命令sudo apt install xinput安装xinput实用程序

使用命令DISPLAY=:0 xinput检查可用的输入设备

如果列表中有ADS7846 Touchscreen,则应查看/var/log/Xorg.0.log日志并尝试查找原因。如果没有,我们尝试使用命令安装libinput 组件(驱动程序)

apt install xserver-xorg-input-libinput

我们检查结果。如果一切正常,请继续进行校准。如果不是,我们研究上面的日志并尝试了解原因。

触摸屏的校准:
在开始校准之前,使用以下命令安装xinput_calibrator实用程序

sudo apt-get install xinput-calibrator

我们使用命令开始校准

DISPLAY=:0 xinput_calibrator

屏幕上将显示一个图像,需要用手写笔准确地点击并按下屏幕角落显示的十字。一旦所有 4 个都准确命中,校准就会结束(如果出现错误,一切都会重新开始)。

校准完成后,内容将显示在控制台上,必须将其插入位于/etc/X11/xorg.conf.d/99-calibration.conf文件中(在某些发行版中,所有内容都必须写入在/usr/share/X11/文件中,而不是)。
此外,您可能需要使用 Option “TransformationMatrix” ” <matrix>” 行指定转换矩阵的参数(此处有更多详细信息)。因此,该文件应如下所示:

Section "InputClass"
        Identifier      "calibration"
        MatchProduct    "ADS7846 Touchscreen"
    Option "TransformationMatrix" "0 1 0 -1 0 1 0 0 1"
    Option  "MinX"  "2788"
        Option  "MaxX"  "61860"
        Option  "MinY"  "4198"
        Option  "MaxY"  "61541"
        Option  "SwapXY"        "0" # unless it was already set to 1
        Option  "InvertX"       "0"  # unless it was already set
        Option  "InvertY"       "0"  # unless it was already set
EndSection

这样做并重新启动 KlipperScreen 后,一切都应该正常。
要测试本节中列出的不同选项,您只需重新启动 KlipperScreen 服务,而不是整个设备。这是通过以下命令完成的:

sudo service KlipperScreen restart //重启服务
sudo service KlipperScreen start //启动服务
sudo service KlipperScreen stop //停止服务

 

留下评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注