imx6ull(imx6ull芯片介绍)

imx6ull(imx6ull芯片介绍)需要注意的是 SNVS TAMPER9 引脚被复用为 GPIO5 IO09 需要追加到 iomuxc snvs 节点 my gt911 pinctrl tsc reset tscresetgrp fsl pins lt used for tsc reset MX6UL PAD LCD RESETGPIO3 IO04 0x10b0 gt

大家好,我是讯享网,很高兴认识大家。



需要注意的是,SNVS_TAMPER9 引脚被复用为 GPIO5_IO09,需要追加到 iomuxc_snvs 节点。

/my gt911/
pinctrl_tsc_reset: tscresetgrp {
   fsl,pins = <
       /* used for tsc reset */
       MX6UL_PAD_LCD_RESETGPIO3_IO04 0x10b0
       >;
};

/my gt911/
pinctrl_tsc_irq: tsc_irq {
   fsl,pins = <
       /* used for tsc irq */
       MX6ULL_PAD_SNVS_TAMPER9
GPIO5_IO09   0x4001b8b0
       >;
}

gt911_tsc@5d {
   compatible = “goodix,gt911”;
reg = <0x5d>;
   pinctrl-0 = <&pinctrl_tsc_reset>;
   pinctrl-1 = <&pinctrl_tsc_irq>;
   reset-gpios = <&gpio3 4 GPIO_ACTIVE_LOW>;
   irq-gpios = <&gpio5 9 GPIO_ACTIVE_HIGH>;
   interrupt-parent = <&gpio5>;
   interrupts = <9 IRQ_TYPE_EDGE_FALLING>;
};

/* 匹配列表 /
static const struct of_device_id gt911_of_match[] = {
   {.compatible = “goodix,gt911”},
   {/
Sentinel /}
};

/
i2c驱动结构体 /
struct i2c_driver gt911_i2c_driver = {
   .driver = {
       .owner = THIS_MODULE,
       .name = “gt911”,   /
驱动名字 用于和设备匹配  适用于没有设备树的情况/
       .of_match_table =gt911_of_match,  /
设备树匹配列表 /
   },
   .probe =gt911_probe,
   .remove =gt911_remove,
   .id_table = gt911_id, /
id配置列表 */
};

static int gt911_probe(struct i2c_client *client, const struct i2c_device_id id)
{
   u8 ret = 0;
   gt911.client = client;
   printk(“[BSP] gt911 driver and device has match! ”);

   /
获取设备树中的中断和复位引脚 /
   printk(“[BSP] get gpios ”);
   gt911.irq_pin   = of_get_named_gpio(client->dev.of_node, “irq-gpios”, 0);
   gt911.reset_pin = of_get_named_gpio(client->dev.of_node, “reset-gpios”, 0);

   /
初始化复位引脚 /
   ret = gt911_ts_reset(client, &gt911);

   /
初始化gt911 /
   printk(“[BSP] init gt911 ”);
   gt911_write_reg(&gt911, GT_CTRL_REG, 2);  /
软复位 /
   mdelay(100);
   gt911_write_reg(&gt911, GT_CTRL_REG, 0);  /
停止软复位 /
   mdelay(100);

   /
input 注册设备/
   printk(“[BSP] init input device ”);
   gt911.input  = devm_input_allocate_device(&client->dev);
   
   /
初始化input /
   gt911.input->name = client->name;
   gt911.input->id.bustype = BUS_I2C;
   gt911.input->dev.parent = &client->dev;
   
   /
设置input设备需要上报哪些事件/
   set_bit(EV_SYN, gt911.input->evbit);
   
set_bit(EV_KEY, gt911.input->evbit);      /
按键事件 /
   __set_bit(EV_ABS, gt911.input->evbit);      /
重复事件 /
   /
设置input设备需要上报哪些按键/
   __set_bit(BTN_TOUCH, gt911.input->keybit);  /
触摸值 /
   
   /
多点触摸 */
   input_mt_init_slots(gt911.input, MAX_SUPPORT_POINTS, 0);  /*触摸点的数量 /
   input_set_abs_params(gt911.input, ABS_MT_POSITION_X,0, 800, 0, 0);
   input_set_abs_params(gt911.input, ABS_MT_POSITION_Y,0, 480, 0, 0);

   /
注册input /
   ret = input_register_device(gt911.input);
   
   /
最后初始化中断 /
   ret = gt911_ts_irq(client, &gt911);
   
   printk(“[BSP] %s done ”,FUNCTION);
   return 0;
}

/ 申请复位IO 并且默认输出高电平 /
devm_gpio_request_one(&client->dev,
                     dev->reset_pin,
                     GPIOF_OUT_INIT_HIGH,
                     “gt911 reset”);

gpio_set_value(dev->reset_pin, 0);  /
复位 /
msleep(10);
gpio_set_value(dev->reset_pin, 1);  /
停止复位 /
msleep(300);

/ 申请复位 IO /
devm_gpio_request_one(&client->dev,
                     dev->irq_pin,
                     GPIOF_IN,
                     “gt911 irq”);

/
申请中断  /
devm_request_threaded_irq(&client->dev,
                         client->irq,
                         NULL,
                         gt911_irq_handler, /
中断处理函数 /
                         IRQF_TRIGGER_FALLING | IRQF_ONESHOT, /
触发方式 /
                         client->name,
                         &gt911);

/ —–读取触摸信息寄存器—– /
ret = gt911_read_regs(dev, GT_GSTID_REG, &data, 1);
if(data == 0x00) /
没有触摸数据/
{  
   goto fail;
}
else
{  /
统计触摸信息 /
   status       = data >> 7;          // bit7:1表示坐标(或按键)已经准备好,主控可以读取  0 表示未就绪,数据无效
   large_detect = (data >> 6) & 0x01; // bit6:
   touch_num    = data & 0x0f;        // bit3~0:屏上的坐标点个数
}

if(touch_num) /
有触摸按下 /
{
   /
—–读取具体的触摸点数据寄存器—– /
   gt911_read_regs(dev, GT_TP1_REG, buf, BUFFER_SIZE);
   id = buf[0]; // 数据中的第一个触摸点的id
   touch_index |= (0x01<<id);

   /
上报每一个触摸点坐标 /
   for (i = 0; i < 5; i++)
   {
       if ((touch_index & (0x01<<i)))
       {
           input_x = (buf[pos + 1] | (buf[pos + 2] << 8)) & 0x0fff;  // x坐标
           input_y = (buf[pos + 3] | (buf[pos + 4] << 8)) & 0x0fff;  // y坐标

           input_mt_slot (dev->input, id); // 产生ABS_MT_SLOT 事件 报告是哪个触摸点的坐标
           input_mt_report_slot_state(dev->input, MT_TOOL_FINGER, true);   // 指定手指触摸  连续触摸
           input_report_abs(dev->input, ABS_MT_POSITION_X, input_x);   // 上报触摸点坐标信息
           input_report_abs(dev->input, ABS_MT_POSITION_Y, input_y);   // 上报触摸点坐标信息
           printk(“%d ”, id, input_x, input_y);

           report_num++;
           if (report_num < touch_num)
           {
               pos += 8;
               id = buf[pos];
               touch_index |= (0x01<<id);
           }
       }
       else
       {
           input_mt_slot(dev->input, i);
           input_mt_report_slot_state(dev->input, MT_TOOL_FINGER, false);   // 关闭手指触摸
       }
   }
   printk(“ ”);
}
else if(last_index)/
触摸释放 /
{
   for (i = 0; i < 5; i++)
   {
       if ((last_index & (0x01<<i)))
       {
           input_mt_slot(dev->input, i); /
上报触摸点 /
           input_mt_report_slot_state(dev->input, MT_TOOL_FINGER, false); // 关闭手指触摸
       }
   }
}
last_index = touch_index;

input_mt_report_pointer_emulation(dev->input, true);
input_sync(dev->input);   /
同步数据 数据上报完成 /

data = 0x00;  /
向0x814E寄存器写0  不然就会一直进入中断 /
gt911_write_regs(dev, GT_GSTID_REG, &data, 1);   //写入


讯享网

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig

-> Device Drivers
-> Input device support        
 -> Touchscreens (INPUT_TOUCHSCREEN [=y])
  <
>   Goodix I2C touchscreen  

https://www.bilibili.com/read/build_myboard.sh

hexdump /dev/input/event2

小讯
上一篇 2025-04-21 17:51
下一篇 2025-04-18 10:04

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/147601.html