一、硬件接口
I2C接口是用的I2C4,SCL和SDA外部没有加上拉,使用时需要将处理器IO配置为上拉,或触屏端的电路做上拉。
二、确定硬件连接正常
将触屏连接到主板,待系统启动后通过i2c tool工具查看是否存在I2C设备。
[root@RK356X:/]# i2cdetect -y 4
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- --
10: -- -- -- -- 14 -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
在DTS文件中I2C4节点下没配置设备的情况,可以看到设备节点为0x14,如果I2C节点下配置了设备,会显示UU,如下所示:
[root@RK356X:/]# i2cdetect -y 4
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- --
10: -- -- -- -- UU -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
如果执行i2cdetect -y 4指令后,结果输出时间较长,且存在很多器件,这个是由于i2c总线上没有上拉所致,情况如下所示:
[root@RK356X:/]# i2cdetect -y 4
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: 08 09 0a 0b 0c 0d 0e 0f
10: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
20: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f
30: -- -- -- -- -- -- -- -- 38 39 3a 3b 3c 3d 3e 3f
40: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f
70: 70 71 72 73 74 75 76 77
三、添加驱动
GT9xx触摸IC比较常用,一般SDK中都有驱动文件,位于SDK的\kernel\drivers\input\touchscreen\gt9xx路径下,如果有更新版本的驱动文件,也可替换此路径下的文件。SDK的自带的驱动版本为Version: 2.4,触屏厂家提供的驱动文件版本为Version: 2.8.0.1,我使用厂家提供的驱动文件。
DTS文件中添加设备:
&pinctrl {
...
gt9xx {
ts_int_default: ts-int-default {
rockchip,pins = <3 RK_PD7 RK_FUNC_GPIO &pcfg_pull_up>; //int
};
ts_int_output_low: ts-int-output-low {
rockchip,pins = <3 RK_PD7 RK_FUNC_GPIO &pcfg_output_low_pull_up>;
};
ts_int_output_high: ts-int-output-high {
rockchip,pins = <3 RK_PD7 RK_FUNC_GPIO &pcfg_output_high_pull_up>;
};
ts_int_input: ts-int-input {
rockchip,pins = <3 RK_PD7 RK_FUNC_GPIO &pcfg_pull_up>;
};
};
...
};
&i2c4 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&i2c4m0_up_xfer>;
clock-frequency = <400000>;
i2c-scl-rising-time-ns = <138>;
i2c-scl-falling-time-ns = <4>;
gt9xx@14 {
status = "okay";
compatible = "goodix,gt9xx";
reg = <0x14>;
interrupt-parent = <&gpio3>;
interrupts = <31 IRQ_TYPE_EDGE_FALLING>;
pinctrl-names = "default", "int-output-low","int-output-high", "int-input";
pinctrl-0 = <&ts_int_default>;
pinctrl-1 = <&ts_int_output_low>;
pinctrl-2 = <&ts_int_output_high>;
pinctrl-3 = <&ts_int_input>;
reset-gpios = <&gpio3 RK_PD6 GPIO_ACTIVE_LOW>;
irq-gpios = <&gpio3 RK_PD7 IRQ_TYPE_EDGE_FALLING>;
irq-flags = <2>; //falling edge.
touchscreen-max-id = <11>;
touchscreen-size-x = <1024>;
touchscreen-size-y = <600>;
touchscreen-max-w = <512>;
touchscreen-max-p = <512>;
touchscreen-key-map = <172>, <158>; /*KEY_HOMEPAGE=172, KEY_BACK=158,KEY_MENU=139*/
goodix,slide-wakeup = <0>;
goodix,type-a-report = <0>;
goodix,driver-send-cfg = <0>;
goodix,resume-in-workqueue = <0>;
goodix,int-sync = <1>;
goodix,swap-x2y = <0>;
goodix,esd-protect = <1>;
goodix,auto-update-cfg = <0>;
goodix,power-off-sleep = <0>;
goodix,pen-suppress-finger = <0>;
goodix,cfg-group0 = [
53 D0 02 00 05 05 F5 D5 21 48 2D 0F 5A 41 0E 05 00 00 32 32 20 00 05 14 14 1A 14 8B 2B 00
];
};
};
在pinctrl 节点下增加了int管脚的几种模式,i2c4节点下增加了器件及相关配置。设备地址0x14不是固定的,根据i2cdetect检测到的为准。
四、内核配置
cd 到SDK的kernel目录,执行make ARCH=arm64 menuconfig进入配置界面:
---Device Drivers
---Input device support
---Touchscreens
<*> Goodix gt9xx support for rockchip platform
然后按键盘上的方向右键选中Save,然后回车,然后退出配置。
再执行cp .config arch/arm64/configs/rockchip_linux_defconfig命令保存配置文件,或者执行make savedefconfig命令。
再重新编译kernel生产新的boot.img,将新生成的boot.img烧写进主板。
五、调试
主板启动之后,点击触屏,界面没有任何反应,执行dmesg | grep goodix-ts指令查看触屏相关日志:
[root@RK356X:/dev/input]# dmesg | grep goodix-ts
[ 0.729329] goodix-ts 4-0014: GTP Driver Version: V2.8.0.2<2017/12/14>
[ 0.729351] goodix-ts 4-0014: GTP I2C Address: 0x14
[ 0.729377] goodix-ts 4-0014: touch input parameters is [id x y w p]<11 1024 600 512 512>
[ 0.729393] goodix-ts 4-0014: int-sync enabled
[ 0.729413] goodix-ts 4-0014: esd-protect enabled
[ 0.729433] goodix-ts 4-0014: key-map is [ac 9e 0 0]
[ 0.729473] goodix-ts 4-0014: Looking up vdd_ana-supply from device tree
[ 0.729482] goodix-ts 4-0014: Looking up vdd_ana-supply property in node /i2c@fe5d0000/gt9xx@14 failed
[ 0.729512] goodix-ts 4-0014: 4-0014 supply vdd_ana not found, using dummy regulator
[ 0.729588] goodix-ts 4-0014: Linked as a consumer to regulator.0
[ 0.729606] goodix-ts 4-0014: Looking up vcc_i2c-supply from device tree
[ 0.729615] goodix-ts 4-0014: Looking up vcc_i2c-supply property in node /i2c@fe5d0000/gt9xx@14 failed
[ 0.729632] goodix-ts 4-0014: 4-0014 supply vcc_i2c not found, using dummy regulator
[ 0.729690] goodix-ts 4-0014: Success init pinctrl
[ 0.729717] goodix-ts 4-0014: Success request irq-gpio
[ 0.729738] goodix-ts 4-0014: Success request rst-gpio
[ 0.729752] goodix-ts 4-0014: Guitar reset
[ 0.814616] goodix-ts 4-0014: I2C Addr is 14
[ 0.815006] goodix-ts 4-0014: IC Version: 911_1060
[ 0.815428] goodix-ts 4-0014: Driver set not send config
[ 0.823513] goodix-ts 4-0014: Use slot report protocol
[ 0.823652] input: goodix-ts as /devices/virtual/input/input3
[ 0.823814] goodix-ts 4-0014: INT num 97, trigger type:2
[ 0.824038] goodix-ts 4-0014: create proc entry gt9xx_config success
[ 0.824074] goodix-ts 4-0014: ESD on
通过日志可以看出驱动加载正确,作为input3输入设备。
执行evtest /dev/input/event3命令检测触屏上报的事件及坐标:
[root@RK356X:/]# evtest /dev/input/event3
Input driver version is 1.0.1
Input device ID: bus 0x18 vendor 0xdead product 0xbeef version 0x28bb
Input device name: "goodix-ts"
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 158 (KEY_BACK)
Event code 172 (KEY_HOMEPAGE)
Event code 330 (BTN_TOUCH)
Event code 331 (BTN_STYLUS)
Event code 332 (BTN_STYLUS2)
Event type 3 (EV_ABS)
Event code 47 (ABS_MT_SLOT)
Value 0
Min 0
Max 15
Event code 48 (ABS_MT_TOUCH_MAJOR)
Value 0
Min 0
Max 512
Event code 53 (ABS_MT_POSITION_X)
Value 0
Min 0
Max 1024
Event code 54 (ABS_MT_POSITION_Y)
Value 0
Min 0
Max 600
Event code 55 (ABS_MT_TOOL_TYPE)
Value 0
Min 0
Max 15
Event code 57 (ABS_MT_TRACKING_ID)
Value 0
Min 0
Max 11
Event code 58 (ABS_MT_PRESSURE)
Value 0
Min 0
Max 512
Properties:
Property type 1 (INPUT_PROP_DIRECT)
Testing ... (interrupt to exit)
Event: time 946686360.775089, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 89
Event: time 946686360.775089, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 46
Event: time 946686360.775089, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 38
Event: time 946686360.775089, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 21
Event: time 946686360.775089, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 21
Event: time 946686360.775089, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 1
Event: time 946686360.775089, -------------- SYN_REPORT ------------
Event: time 946686360.835716, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value -1
Event: time 946686360.835716, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 0
Event: time 946686360.835716, -------------- SYN_REPORT ------------
Event: time 946686380.073918, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 90
Event: time 946686380.073918, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 945
Event: time 946686380.073918, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 599
Event: time 946686380.073918, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 17
Event: time 946686380.073918, type 3 (EV_ABS), code 58 (ABS_MT_PRESSURE), value 17
Event: time 946686380.073918, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 1
Event: time 946686380.073918, -------------- SYN_REPORT ------------
Event: time 946686380.159187, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value -1
Event: time 946686380.159187, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 0
Event: time 946686380.159187, -------------- SYN_REPORT ------------
点击了两个对角点,可以看到有触摸事件上报,并且坐标也是对的。原因是当前所用的linux系统不支持多点触控,只能用单点坐标(Linux version 4.19.193不支持多点功能,Linux version 4.19.232已支持多点功能)。如果是安卓系统,不需要以下修改。
回想之前调5寸屏(linux之调试触摸屏驱动)的时候也遇到了同样的问题,需要修改驱动文件gt9xx.c,按照之前的总结,修改static void gtp_mt_slot_report(struct goodix_ts_data *ts, u8 touch_num,struct goodix_point_t *points)和static s8 gtp_request_input_dev(struct goodix_ts_data *ts)两个函数后就可以正常触摸了。
六、将显示界面换为竖屏
执行vi /etc/xdg/weston/weston.ini打开weston.ini文件,添加以下内容:
[output]
name=DSI-1
transform=270
修改之后,断电重启即可。
竖屏的效果: