9.1.2. CTP调试配置

9.1.2.1. 概述

相比RTP电阻触摸屏, CTP电容触摸屏的调试稍微繁琐一点,CTP驱动一般由触摸屏原厂提供,经过移植添加到SDK中编译和使用 本章节以GT911为例来说明一款新的CTP的调试和移植过程。

9.1.2.2. 内核配置

9.1.2.2.1. 驱动移植

驱动存放路径:linux-5.10/drivers/input/touchscreen/gt911

其中linux-5.10/drivers/input/touchscreen/Makefile修改添加如下:

diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index 75924acd8..4be057598 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -116,3 +116,6 @@ obj-$(CONFIG_TOUCHSCREEN_ROHM_BU21023)      += rohm_bu21023.o
 obj-$(CONFIG_TOUCHSCREEN_RASPBERRYPI_FW)       += raspberrypi-ts.o
 obj-$(CONFIG_TOUCHSCREEN_IQS5XX)       += iqs5xx.o
 obj-$(CONFIG_TOUCHSCREEN_ZINITIX)      += zinitix.o
+obj-$(CONFIG_INPUT_TOUCHSCREEN)   += gt911/

其中linux-5.10/drivers/input/touchscreen/Kconfig修改添加如下:

diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index a8d18a679..6acdc3b63 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -1344,5 +1344,7 @@ config TOUCHSCREEN_ZINITIX

          To compile this driver as a module, choose M here: the
          module will be called zinitix.
-
+source "drivers/input/touchscreen/gt911/Kconfig"

注意

请从触摸屏供应商处获取和内核版本匹配的驱动程序,如果版本不匹配则可能编译出错,需要自行适配。

9.1.2.2.2. 内核配置

参考快速入门 - 编译概述 - Kernel配置,进入kernel的功能配置,按如下选择:

Linux
    Device Drivers
        Input device support
            [*] Touchscreens
                <M> gt911 based touchscreens

驱动以ko的方式编译后,系统启动后在启动脚本S10mdev自动加载,如下:

start() {
     echo -n "Starting $DAEMON... "
     start-stop-daemon -S -b -m -p $PIDFILE -x /sbin/mdev -- -df
     [ $? -eq 0 ] && echo "OK" || echo "ERROR"

     # coldplug modules
     find /sys/ -name modalias -print0 | \
         xargs -0 sort -u | \
         tr '\n' '\0' | \
         xargs -0 modprobe -abq
}

小技巧

如果不需要自动加载,可注释掉所示代码,仿照其他启动服务自定义加载服务。

9.1.2.3. DTS参数配置

  • xxx-board.dts中要添加的参数选项需要查看驱动代码中所要解析的dts参数而添加,示例如下:

GT911驱动程序中所要解析的dts参数

int input_sensor_startup(enum input_sensor_type *ctp_type)
{
        int ret = -1;
        struct ctp_config_info *data = container_of(ctp_type, struct ctp_config_info, input_type);
        struct device_node *np = NULL;
        np = of_find_node_by_name(NULL, "ctp");
        if (!np)
        {
                pr_err("ERROR! get ctp_para failed, func:%s, line:%d\n", __func__, __LINE__);
                goto devicetree_get_item_err;
        }
        if (!of_device_is_available(np))
        {
                pr_err("%s: ctp is not used\n", __func__);
                goto devicetree_get_item_err;
        }
        else
                data->ctp_used = 1;
        ret = of_property_read_u32(np, "ctp_twi_id", &data->twi_id);
        if (ret)
        {
                pr_err("get twi_id is fail, %d\n", ret);
                goto devicetree_get_item_err;
        }
        printk("ctp_twi_id is %d\r\n", data->twi_id);
        data->wakeup_gpio = of_get_named_gpio(np, "ctp_wakeup", 0);
        printk("wavkeup_gpio %d\r\n", data->wakeup_gpio);
        data->irq_gpio = of_get_named_gpio(np, "ctp_int_port", 0);
        printk("ctp_int_port %d\r\n", data->irq_gpio);
        ret = of_property_read_u32(np, "ctp_screen_max_x", &data->screen_max_x);
        if (ret)
                pr_err("get ctp_screen_max_x is fail, %d\n", ret);
        ret = of_property_read_u32(np, "ctp_screen_max_y", &data->screen_max_y);
        if (ret)
                pr_err("get screen_max_y is fail, %d\n", ret);
        ret = of_property_read_u32(np, "ctp_revert_x_flag", &data->revert_x_flag);
        if (ret)
                pr_err("get revert_x_flag is fail, %d\n", ret);
        ret = of_property_read_u32(np, "ctp_revert_y_flag", &data->revert_y_flag);
        if (ret)
                pr_err("get revert_y_flag is fail, %d\n", ret);
        ret = of_property_read_u32(np, "ctp_exchange_x_y_flag", &data->exchange_x_y_flag);
        if (ret)
                pr_err("get ctp_exchange_x_y_flag is fail, %d\n", ret);
        ret = of_property_read_u32(np, "ctp_abs_max_x", &data->abs_max_x);
        if (ret)
                pr_err("get ctp_abs_max_x is fail, %d\n", ret);
        ret = of_property_read_u32(np, "ctp_abs_max_y", &data->abs_max_y);
        if (ret)
                pr_err("get ctp_abs_max_y is fail, %d\n", ret);
        ret = of_property_read_u32(np, "ctp_convert_reslution", &data->convert_reslution);
        if (ret)
                pr_err("get convert_reslution is fail, %d\n", ret);
        printk("screen %d %d %d %d %d abs_x %d abs_y %d convert %d\r\n", data->screen_max_x, data->screen_max_y,
                                 data->revert_x_flag, data->revert_y_flag, data->exchange_x_y_flag,
                                 data->abs_max_x,data->abs_max_y,
                                 data->convert_reslution);
        return 0;
devicetree_get_item_err:
        pr_notice("=========script_get_item_err============\n");
        return ret;
}

xxx-board.dts中所添加的参数项

&twi2 {
    pinctrl-names = "default";
    pinctrl-0 = <&twi2_pins_a>;
    status = "okay";
    ctp {
        reg = <0x5d>;                                   //CTP设备地址,可以从规格书中获取
        device_type = "ctp";                            //默认
        status = "okay";                                //使能标志
        ctp_twi_id = <0x2>;                             //所挂在的twi总线id
        ctp_twi_addr = <0x5d>;                          //CTP设备地址,可以从规格书中获取
        ctp_screen_max_x = <0x500>;                     //CTP x轴的范围
        ctp_screen_max_y = <0x320>;                     //CTP y轴范围
        ctp_revert_x_flag = <0x0>;                      //CTP x轴是否翻转
        ctp_revert_y_flag = <0x0>;                      //CTP y轴是否翻转
        ctp_exchange_x_y_flag = <0x0>;                  //CTP x轴和y轴是否互换
        ctp_int_port = <&gpio_a 9 GPIO_ACTIVE_HIGH>;    //CTP中断引脚
        ctp_wakeup = <&gpio_a 8 GPIO_ACTIVE_HIGH>;      //CTP reset引脚
    };
};
  • CTP设备地址获取:

从规格书中可以看出GT911根据初始化时序的不同支持两种设备地址,默认时序的读写地址为0xBA/0xBB,读写地址去掉最后一位读写位就是设备地址,即:0x5d

../../../_images/slave_addr.png
  • 硬件接线示例图如下:

../../../_images/ctp1.png

注意

请务必确保dts所配置的参数和引脚与硬件原理图一致

9.1.2.4. 调试

  • 测量硬件通路

    测量硬件通路是否正常,测量电压信号是否正常

  • 查看打印信息

    在board.dts中修改bootargs,增加“loglevel=8” 调高打印级别,系统启动时或insmod驱动模块时看是否有异常打印

  • 获取坐标信息

    如果系统有编译getevent工具,触摸屏有触摸时进行坐标的打印

    # getevent
    
  • 获取设备信息

    # cat /proc/bus/input/devices
    
    例如:(以gt9xx为例)
    I: Bus=0018 Vendor=dead Product=beef Version=28bb
    N: Name="goodix-ts"
    P: Phys=input/ts
    S: Sysfs=/devices/virtual/input/input0
    U: Uniq=
    H: Handlers=event0
    B: PROP=2
    B: EV=b
    B: KEY=1c00 0 0 0 0 0
    B: ABS=6e1800000000000