t113-c-触摸篇
学一下如何添加触摸
先在menuconfig里面寻找是否有GT911
但是结果并没有找得到
那么在kernel_menuconfig中是否有呢
也没见有,但是我找到了gt9xx这个选项
估计就是这个了,那就不用添加驱动了把它选上
board.dts
设备树中也应该看一看,这中驱动硬是在iic也就是twi总线下的,果然在twi2找到了
打包
打包的时候需要注意的boot空间区域增大了,需要修改一下分区表文件
另外如何添加一个新的驱动到menuconfig可以参考一下的文章:
https://blog.csdn.net/qq_39721016/article/details/127629996#2focaltech_touch_13
/dev下的event:
每一个event对应着一个输入的设备,至于详情需要到proc中找:
cat /proc/bus/input/devices 使用这条指令可以查看设备详情
https://www.cnblogs.com/sky-heaven/p/9214064.html
这篇文章很好地概况了event的知识和一些查看系统情况的知识,有很参考价值
查看代码
转自:https://blog.csdn.net/qq_21792169/article/details/51458855
当我们在Linux操作系统下使用input子系统时,当我们先插鼠标,在插上摄像头与先插摄像头,在插鼠标,操作系统为两个设备分配的event号不是固定的,先插上的是event0,后插上的是event1 。那么问题来了,我们写应用程序,我们怎么知道那个设备对应那个event接口,我们不可能认为指定使用那个接口,因为有时候插播顺序并不一致,下面我用代码来获取event接口。
使用cat /proc/bus/input/devices
I: Bus=0011 Vendor=0001 Product=0001 Version=ab41
N: Name="AT Translated Set 2 keyboard"
P: Phys=isa0060/serio0/input0
S: Sysfs=/devices/platform/i8042/serio0/input/input2
U: Uniq=
H: Handlers=kbd event2
B: EV=120013
B: KEY=4 2000000 3803078 f800d001 feffffdf ffefffff ffffffff fffffffe
B: MSC=10
B: LED=7
I: Bus=0011 Vendor=0002 Product=0005 Version=0000
N: Name="ImPS/2 Generic Wheel Mouse"
P: Phys=isa0060/serio1/input0
S: Sysfs=/devices/platform/i8042/serio1/input/input3
U: Uniq=
H: Handlers=mouse1 event3
B: EV=7
B: KEY=70000 0 0 0 0 0 0 0 0
B: REL=103
主要观察打印信息,Name项是不一样的,我们就可以从这里下手,读取到这个名字,然后在这一类中读取event的值。
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <sys/mman.h>
//#define DBG_PRINTF(...)
#define DBG_PRINTF printf
char *command="cat /proc/bus/input/devices > log.txt" ;
char *file_path="./log.txt";
char *file_buff;
int number;
int find_event()
{
int iFd;
FILE *tFp;
struct stat tStat;
char *sub_buff="Handlers=mouse1";
/* according to mouse name find event number*/
char *buff;
tFp=fopen(file_path,"r+"); /* check if have log.txt file */
if(NULL!=tFp)
{
fclose(tFp);
system("rm log.txt");
}
system(command);
/* 打开文件 */
tFp = fopen(file_path, "r+");
if (tFp == NULL)
{
DBG_PRINTF("can't open %s\n", file_path);
return -1;
}
iFd = fileno(tFp);
fstat(iFd, &tStat);
/* mmap the file to mem */
file_buff = (unsigned char *)mmap(NULL , tStat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, iFd, 0);
if (file_buff== (unsigned char *)-1)
{
DBG_PRINTF("mmap error!\n");
return -1;
}
buff=strstr(file_buff,sub_buff);/* in the mem file_buff find sub_buff name */
if(NULL==buff)
{
DBG_PRINTF("can't find %s\n",sub_buff);
munmap(file_buff, tStat.st_size);
return -1;
}
number=*(buff+strlen(sub_buff)+6);/* 6== event */
munmap(file_buff, tStat.st_size);
fclose(tFp);
return 0;
}
int main(int argc, char **argv)
{
find_event();
DBG_PRINTF("event%d\n",number-'0');
return 0;
}
遇到同样的问题我们可以采取同样的措施,先映射到内存上,再来查找。也可以直接使用fopen打开文件,然后使用fgets函数来读取到buf中,在使用strstr来查找。
查看CPU信息:cat /proc/cpuinfo
查看内存信息:cat /proc/meminfo
查看USB设备:cat /proc/bus/usb/devices
查看键盘和鼠标:cat /proc/bus/input/devices
查看各分区使用情况:df
查看体系结构:busybox uname -a
查看中断信息:cat /proc/interrupts
软件触摸
那么就写一软件来测试一下触摸是否正常:
以下面这个代码为例子修改一下就能驱动
https://blog.csdn.net/chenxun_2010/article/details/41722119
intput库的详细解释:
https://www.cnblogs.com/yikoulinux/p/15208238.html
c语言中有关于time的操作:
https://blog.csdn.net/QLeelq/article/details/115756474
/*
* Copyright 2002 Red Hat Inc., Durham, North Carolina.
*
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation on the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* This is a simple test program that reads from /dev/input/event*,
* decoding events into a human readable form.
*/
/*
* Authors:
* Rickard E. (Rik) Faith <faith@redhat.com>
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include <linux/input.h>
struct input_event event;
int main(int argc, char **argv)
{
char name[64]; /* RATS: Use ok, but could be better */
char buf[256] = { 0, }; /* RATS: Use ok */
unsigned char mask[EV_MAX / 8 + 1]; /* RATS: Use ok */
int version;
int fd = 0;
int rc;
int i, j;
char *tmp;
#define test_bit(bit) (mask[(bit)/8] & (1 << ((bit)%8)))
for (i = 0; i < 32; i++) {
sprintf(name, "/dev/input/event%d", i);
if ((fd = open(name, O_RDONLY, 0)) >= 0) {
ioctl(fd, EVIOCGVERSION, &version);
ioctl(fd, EVIOCGNAME(sizeof(buf)), buf);
ioctl(fd, EVIOCGBIT(0, sizeof(mask)), mask);
printf("%s\n", name);
printf(" evdev version: %d.%d.%d\n",
version >> 16, (version >> 8) & 0xff, version & 0xff);
printf(" name: %s\n", buf);
printf(" features:");
for (j = 0; j < EV_MAX; j++) {
if (test_bit(j)) {
const char *type = "unknown";
switch (j) {
case EV_KEY: type = "keys/buttons"; break;
case EV_REL: type = "relative"; break;
case EV_ABS: type = "absolute"; break;
case EV_MSC: type = "reserved"; break;
case EV_LED: type = "leds"; break;
case EV_SND: type = "sound"; break;
case EV_REP: type = "repeat"; break;
case EV_FF: type = "feedback"; break;
}
printf(" %s", type);
}
}
printf("\n");
close(fd);
}
}
if (argc > 1) {
sprintf(name, "/dev/input/event%d", atoi(argv[1]));
if ((fd = open(name, O_RDWR, 0)) >= 0) {
printf("%s: open, fd = %d\n", name, fd);
for (i = 0; i < LED_MAX; i++) {
event.time.tv_sec = time(0);
event.time.tv_usec = 0;
event.type = EV_LED;
event.code = i;
event.value = 0;
write(fd, &event, sizeof(event));
}
while ((rc = read(fd, &event, sizeof(event))) > 0) {
printf("%-24.24s.%06lu type 0x%04x; code 0x%04x;"
" value 0x%08x; ",
ctime(&event.time.tv_sec),
event.time.tv_usec,
event.type, event.code, event.value);
switch (event.type) {
case EV_KEY:
if (event.code > BTN_MISC) {
printf("Button %d %s",
event.code & 0xff,
event.value ? "press" : "release");
}
else {
printf("Key %d (0x%x) %s",
event.code & 0xff,
event.code & 0xff,
event.value ? "press" : "release");
}
break;
case EV_REL:
switch (event.code) {
case REL_X: tmp = "X"; break;
case REL_Y: tmp = "Y"; break;
case REL_HWHEEL: tmp = "HWHEEL"; break;
case REL_DIAL: tmp = "DIAL"; break;
case REL_WHEEL: tmp = "WHEEL"; break;
case REL_MISC: tmp = "MISC"; break;
default: tmp = "UNKNOWN"; break;
}
printf("Relative %s %d", tmp, event.value);
break;
case EV_ABS:
switch (event.code) {
case ABS_X: tmp = "X"; break;
case ABS_Y: tmp = "Y"; break;
case ABS_Z: tmp = "Z"; break;
case ABS_RX: tmp = "RX"; break;
case ABS_RY: tmp = "RY"; break;
case ABS_RZ: tmp = "RZ"; break;
case ABS_THROTTLE: tmp = "THROTTLE"; break;
case ABS_RUDDER: tmp = "RUDDER"; break;
case ABS_WHEEL: tmp = "WHEEL"; break;
case ABS_GAS: tmp = "GAS"; break;
case ABS_BRAKE: tmp = "BRAKE"; break;
case ABS_HAT0X: tmp = "HAT0X"; break;
case ABS_HAT0Y: tmp = "HAT0Y"; break;
case ABS_HAT1X: tmp = "HAT1X"; break;
case ABS_HAT1Y: tmp = "HAT1Y"; break;
case ABS_HAT2X: tmp = "HAT2X"; break;
case ABS_HAT2Y: tmp = "HAT2Y"; break;
case ABS_HAT3X: tmp = "HAT3X"; break;
case ABS_HAT3Y: tmp = "HAT3Y"; break;
case ABS_PRESSURE: tmp = "PRESSURE"; break;
case ABS_DISTANCE: tmp = "DISTANCE"; break;
case ABS_TILT_X: tmp = "TILT_X"; break;
case ABS_TILT_Y: tmp = "TILT_Y"; break;
case ABS_MISC: tmp = "MISC"; break;
default: tmp = "UNKNOWN"; break;
}
printf("Absolute %s %d", tmp, event.value);
break;
case EV_MSC: printf("Misc"); break;
case EV_LED: printf("Led"); break;
case EV_SND: printf("Snd"); break;
case EV_REP: printf("Rep"); break;
case EV_FF: printf("FF"); break;
break;
}
printf("\n");
}
printf("rc = %d, (%s)\n", rc, strerror(errno));
close(fd);
}
}
return 0;
}