美文网首页
Linux 驱动开发6: 触摸屏输入

Linux 驱动开发6: 触摸屏输入

作者: wjundong | 来源:发表于2022-08-09 01:07 被阅读0次

平台 f1c200s, 触摸屏芯片 FT6236

官方 mainline 没有加入 i2c, 但有兼容的驱动, 更改设备树文件 suniv.dtsi

// 在soc节点下添加
// 此处添加的属性与配置,来自于查找用户手册以及兼容设备
i2c0: i2c@1C27000 {
    compatible = "allwinner,sun6i-a31-i2c";
    reg = <0x01C27000 0x400>;
    interrupts = <7>;
    clocks = <&ccu CLK_BUS_I2C0>;
    resets = <&ccu RST_BUS_I2C0>;
    pinctrl-names = "default";
    pinctrl-0 = <&i2c0_pins>;
    status = "disabled";
    #address-cells = <1>;
    #size-cells = <0>;
};

// 在pio节点下,添加i2c引脚定义
i2c0_pins: i2c0 {
    pins = "PD0", "PD12";
    function = "i2c0";
};

i2c0 可复用到哪些引脚? 可以查看 pinctrl 子系统的 debug 信息, 比如
cat /sys/kernel/debug/pinctrl/1c20800.pinctrl/pinmux-functions

在设备树文件中引用 i2c

/* 首先要添加的头文件: */
#include <dt-bindings/input/input.h>
#include <dt-bindings/interrupt-controller/irq.h>

&i2c0 {
    pinctrl-0 = <&i2c0_pins>;
    pinctrl-names = "default";
    status = "okay";

    polytouch: edt-ft6236@38 {
        compatible = "focaltech,ft6236";
        reg = <0x38>;
        interrupt-parent = <&pio>;
        interrupts = <4 10 IRQ_TYPE_EDGE_FALLING>;      /* PE10*/
        pinctrl-names = "default";
        pinctrl-0 = <&ts_reset_pin>;
        irq-gpios = <&pio 4 10 GPIO_ACTIVE_HIGH>;       /* PE10*/
        reset-gpios = <&pio 0 2 GPIO_ACTIVE_LOW>;       /* PA2 */
    };
};

&pio {
    ts_reset_pin: ts_reset_pin@0 {
        pins = "PA2";
        function = "gpio_out";
    };
};
  • 在内核中使能 FT6236 驱动
    在 menuconfig 中搜索 FT5x 即可找到 (直接搜 FT6236 反而没有, 应该是同系列同一个驱动文件)

驱动加载成功会生成 /dev/input/event0, 下面是在应用层对其简单测试:

#include <stdio.h>
#include <linux/input.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

int get_xy(int fd, int *x, int *y)
{
    struct input_event ts;

    read(fd, &ts, sizeof(ts));
    
    if (ts.type == EV_ABS && ts.code == ABS_X)
    {
        *x = ts.value;
        return 0;
    }

    if (ts.type == EV_ABS && ts.code == ABS_Y)
    {
        *y = ts.value;
        return 0;
    }

    return -1;
}

int main()
{
    int x, y, tmp;
    int fd = open("/dev/input/event0", O_RDONLY);
    if (fd < 0)
    {
        perror("open device error");
        return -1;
    }

    while (1)
    {
        if (get_xy(fd, &x, &y) == 0)
            printf("pos x:%d, y:%d\n", x, y);
    }
}

相关文章

网友评论

      本文标题:Linux 驱动开发6: 触摸屏输入

      本文链接:https://www.haomeiwen.com/subject/dwsgwrtx.html