首页 > 代码库 > penmount串口触摸屏加载

penmount串口触摸屏加载

static irqreturn_t pm_interrupt(struct serio *serio,
  unsigned char data, unsigned int flags)
{
 struct pm *pm = serio_get_drvdata(serio);
 struct input_dev *dev = pm->dev;

 pm->data[pm->idx] = data;

 if (pm->data[0] & 0x80) {
  if (PM_MAX_LENGTH == ++pm->idx) {
   //input_report_abs(dev, ABS_X, pm->data[2] * 128 + pm->data[1]);
   //input_report_abs(dev, ABS_Y, pm->data[4] * 128 + pm->data[3]);
   input_report_abs(dev, ABS_Y, pm->data[1] * 128 + pm->data[2]);
   input_report_abs(dev, ABS_X, pm->data[3] * 128 + pm->data[4]);
   input_report_key(dev, BTN_TOUCH, !!(pm->data[0] & 0x40));
   input_sync(dev);
   pm->idx = 0;
  }
 }

 return IRQ_HANDLED;
}

在驱动中如做上修改。

并在应用中加入如下文件:

/**************************************
Copyright: 2013, Tkai
File name: penmount_init.c
Description: 将串口属性由TTY改为M_MOUSE
Author: 陆晓来
Version: v1.0
Date: 2013.3.15
History: 无
**************************************/
#include "stdio.h"
#include "stdlib.h"
#include "sys/ioctl.h"
#include "sys/stat.h"
#include "unistd.h"
#include "fcntl.h"
#include "termios.h"
#include "errno.h"
#include "/opt/OMAP3530/linux-03.00.01.06/include/linux/tty.h"  //根据内核目录修改
#include "/opt/OMAP3530/linux-03.00.01.06/include/linux/serio.h"//根据内核目录修改
#define SERIO_ANY 0xff
#define device "/dev/ttyS0"    //根据实际使用串口资源修改

/*************************************************
Function: setLine()
Description: 设置串口参数
Calls: NULL
Called By: main()
Input: fd->串口文件操作符,flags->数据位数,speed->波特率
Output: NULL
Return: void
Others: NULL
*************************************************/
static void setLine(int fd, int flags, int speed)
{
 struct termios t;
 tcgetattr(fd, &t);
 t.c_cflag = flags | CREAD | HUPCL | CLOCAL;
 t.c_iflag = IGNBRK | IGNPAR;
 t.c_oflag = 0;
 t.c_lflag = 0;
 t.c_cc[VMIN ] = 1;
 t.c_cc[VTIME] = 0;
 cfsetispeed(&t, speed);
 cfsetospeed(&t, speed);
 tcsetattr(fd, TCSANOW, &t);
}

/*************************************************
Function: main()
Description: 主函数,打开串口设置参数并改变属性
Calls: setLine()
Called By: NULL
Input: void
Output: NULL
Return: 执行成功返回整数0,其它返回-1
Others: NULL
*************************************************/
int main(void)
{
 int fd;
 fd = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK);
 if (fd < 0)
 {
  fprintf(stderr, "inputattach: ‘%s‘ - %s\n",
   device, strerror(errno));
  return -1;
 }
 setLine(fd, CS8, B9600);
 int ldisc = N_MOUSE;
 if (ioctl(fd, TIOCSETD, &ldisc))
 {
  fprintf(stderr, "inputattach: can‘t set line discipline\n");
  return -1;
 }
 unsigned long devt = SERIO_PENMOUNT|(SERIO_ANY << 8)|(SERIO_ANY << 16);
 if (ioctl(fd, SPIOCSTYPE, &devt))
 {
  fprintf(stderr, "inputattach: can‘t set device type\n");
  return -1;
 }
 read(fd,NULL,0);
 return 0; 
}

penmount串口触摸屏加载