usb鼠标驱动注解及测试

[11-20 15:53:39]   来源:http://www.88dzw.com  arm嵌入式   阅读:8872

文章摘要:struct usb_mouse *mouse = urb->context;//在usb_fill_int_urb中有对urb->context赋值signed char *data = mouse->data;struct input_dev *dev = &mouse->dev;int status;switch (urb->status) {case 0: /* success */break;case -ECONNRESET: /* unlink */case -ENOENT:case -ESHUTDOW

usb鼠标驱动注解及测试,标签:arm嵌入式系统,arm系统,http://www.88dzw.com

  struct usb_mouse *mouse = urb->context;

  //在usb_fill_int_urb中有对urb->context赋值

  signed char *data = mouse->data;

  struct input_dev *dev = &mouse->dev;

  int status;

  switch (urb->status) {

  case 0:                  /* success */

  break;

  case -ECONNRESET:         /* unlink */

  case -ENOENT:

  case -ESHUTDOWN:

  return;

  /* -EPIPE:? should clear the halt */

  default:         /* error */

  goto resubmit;

  }

  input_regs(dev, regs);

  input_report_key(dev, BTN_LEFT,         data[0] & 0x01);

  input_report_key(dev, BTN_RIGHT,         data[0] & 0x02);

  input_report_key(dev, BTN_MIDDLE,      data[0] & 0x04);

  input_report_key(dev, BTN_SIDE,         data[0] & 0x08);

  input_report_key(dev, BTN_EXTRA,         data[0] & 0x10);

  //向input系统报告key事件,分别是鼠标LEFT、RIGHT、MIDDLE、SIDE、EXTRA键,

  static inline void input_report_key(struct input_dev *dev, unsigned int code, int value)中的value非0时表示按下,0表示释放

  input_report_rel(dev, REL_X,         data[1]);

  input_report_rel(dev, REL_Y,         data[2]);

  input_report_rel(dev, REL_WHEEL, data[3]);

  //向input系统报告rel事件,分别是x方向位移、y方向位移、wheel值

  input_sync(dev);

  //最后需要向事件接受者发送一个完整的报告。这是input系统的要求。

  resubmit:

  status = usb_submit_urb (urb, SLAB_ATOMIC);

  //重新递交urb

  if (status)

  err ("can't resubmit intr, %s-%s/input0, status %d",

  mouse->usbdev->bus->bus_name,

  mouse->usbdev->devpath, status);

  }

  五、应用层测试代码编写

  在应用层编写测试鼠标的测试程序,在我的系统中,鼠标设备为/dev/input/event3. 测试代码如下:

  /*

  * usb_mouse_test.c

  *by lht

  */

  #include <stdio.h>

  #include <sys/types.h>

  #include <unistd.h>

  #include <fcntl.h>

  #include <linux/input.h>

  int main (void)

  {

  int fd,i,count;

  struct input_event ev_mouse[2];

  fd = open ("/dev/input/event3",O_RDWR);

  if (fd < 0) {

  printf ("fd open failed\n");

  exit(0);

  }

  printf ("\nmouse opened, fd=%d\n",fd);

  while(1)

  {

  printf("...............................................\n");

  count=read(fd, ev_mouse, sizeof(struct input_event));

  for(i=0;i<(int)count/sizeof(struct input_event);i++)

  {

  printf("type=%d\n",ev_mouse[i].type);

  if(EV_REL==ev_mouse[i].type)

  {

  printf("time:%ld.%d",ev_mouse[i].time.tv_sec,ev_mouse[i].time.tv_usec);

  printf(" type:%d code:%d value:%d\n",ev_mouse[i].type,ev_mouse[i].code,ev_mouse[i].value);

  }

上一页  [1] [2] [3] [4] [5] [6] [7]  下一页


Tag:arm嵌入式arm嵌入式系统,arm系统arm嵌入式

《usb鼠标驱动注解及测试》相关文章

分类导航
最新更新
热门排行