Subversion Repositories Kolibri OS

Rev

Rev 1605 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. struct hid_class_descriptor {
  3.     u8_t   bDescriptorType;
  4.     u16_t  wDescriptorLength;
  5. } __attribute__ ((packed));
  6.  
  7. struct hid_descriptor {
  8.     u8_t   bLength;
  9.     u8_t   bDescriptorType;
  10.     u16_t  bcdHID;
  11.     u8_t   bCountryCode;
  12.     u8_t   bNumDescriptors;
  13.  
  14.         struct hid_class_descriptor desc[1];
  15. } __attribute__ ((packed));
  16.  
  17. void create_hid_mouse(udev_t *dev, endpoint_descr_t *en_d);
  18.  
  19. bool init_hid(udev_t *dev)
  20. {
  21.     interface_descr_t              *interface;
  22.     struct hid_descriptor          *hds;
  23.     struct hid_class_descriptor    *hidclass;
  24.     u8_t *dptr = (u8_t*)dev->conf;
  25.  
  26.     int i=0, j=0;
  27.  
  28.     dbgprintf( "init hid device\n");
  29.  
  30.     dptr+= dev->conf->bLength;
  31.  
  32.   //  for(i = 0; i < dev->conf->bNumInterfaces; i++)
  33.   //  {
  34.         interface = (interface_descr_t*)dptr;
  35.         dptr+= interface->bLength;
  36.  
  37.         dbgprintf("interface           %d\n\n"
  38.                   "bLength             %d\n"
  39.                   "bDescriptorType     %d\n"
  40.                   "bInterfaceNumber    %d\n"
  41.                   "bAlternateSetting   %d\n"
  42.                   "bNumEndpoints       %d\n"
  43.                   "bInterfaceClass     %d\n"
  44.                   "bInterfaceSubClass  %d\n"
  45.                   "bInterfaceProtocol  %d\n"
  46.                   "iInterface          %d\n\n",
  47.                   i+1,
  48.                   interface->bLength,
  49.                   interface->bDescriptorType,
  50.                   interface->bInterfaceNumber,
  51.                   interface->bAlternateSetting,
  52.                   interface->bNumEndpoints,
  53.                   interface->bInterfaceClass,
  54.                   interface->bInterfaceSubClass,
  55.                   interface->bInterfaceProtocol,
  56.                   interface->iInterface);
  57.  
  58.         hds = (struct hid_descriptor*) dptr;
  59.  
  60.         dbgprintf("hid descriptor\n\n"
  61.                   "bLength             %d\n"
  62.                   "bDescriptorType     %d\n"
  63.                   "bcdHID              %x\n"
  64.                   "bCountryCode        %d\n"
  65.                   "bNumDescriptors     %d\n",
  66.                   hds->bLength,
  67.                   hds->bDescriptorType,
  68.                   hds->bcdHID,
  69.                   hds->bCountryCode,
  70.                   hds->bNumDescriptors);
  71.  
  72.         for(j=0; j < hds->bNumDescriptors; j++)
  73.         {
  74.             dbgprintf("bDescriptorType    %d\n"
  75.                       "wDescriptorLength  %d\n",
  76.                       hds->desc[j].bDescriptorType,
  77.                       hds->desc[j].wDescriptorLength);
  78.         };
  79.         dptr+= hds->bLength;
  80.  
  81.         endpoint_descr_t *ep;
  82.         ep = (endpoint_descr_t*)dptr;
  83.  
  84.         dbgprintf("\nendpoint\n\n"
  85.                   "bLength             %d\n"
  86.                   "bDescriptorType     %d\n"
  87.                   "bEndpointAddress    %d\n"
  88.                   "bmAttributes        %d\n"
  89.                   "wMaxPacketSize      %d\n"
  90.                   "bInterval           %d\n",
  91.                   ep->bLength, ep->bDescriptorType,
  92.                   ep->bEndpointAddress, ep->bmAttributes,
  93.                   ep->wMaxPacketSize, ep->bInterval);
  94.         dptr+= ep->bLength;
  95.  
  96.         if( interface->bInterfaceProtocol == 2)
  97.             create_hid_mouse(dev, ep);
  98.   //  }
  99.     return true;
  100. };
  101.  
  102.  
  103. bool mouse_handler(udev_t *dev, struct tag_request *rq)
  104. {
  105.     td_t   *td;
  106.     qh_t   *qh;
  107.  
  108.     td = rq->td_head;
  109.  
  110.     if( (td->status &0x7FF)==rq->size-1)
  111.     {
  112.         struct boot_packet *pkt;
  113.         pkt = (struct boot_packet *)rq->data;
  114.         SetMouseData(pkt->buttons, pkt->x, -pkt->y, -pkt->z, 0);
  115.     };
  116.     td->status = TD_CTRL_ACTIVE | TD_CTRL_IOC | dev->speed;
  117.     td->token ^= DATA1;
  118.  
  119.     u32_t efl = safe_cli();
  120.       list_add_tail(&rq->list, &dev->host->rq_list);
  121.       qh = dev->host->qh[6];
  122.       qh->qelem = rq->td_head->dma;
  123.       mb();
  124.     safe_sti(efl);
  125.  
  126.     return true;
  127. };
  128.  
  129. void create_hid_mouse(udev_t *dev, endpoint_descr_t *en_d)
  130. {
  131.     request_t *rq;
  132.     endp_t    enp;
  133.  
  134.     addr_t  address;
  135.     addr_t  size;
  136.     u32_t   toggle;
  137.  
  138.     void *packet;
  139.  
  140.     td_t   *td;
  141.     qh_t   *qh;
  142.  
  143.     static  u16_t __attribute__((aligned(16)))
  144.             req_set_conf[4]  = {0x0900,0x0001,0x0000,0x0000};
  145.  
  146.     if( !ctrl_request(dev, req_set_conf, DOUT, 0, 0))
  147.         return;
  148.  
  149.     enp.address = en_d->bEndpointAddress;
  150.     enp.size    = en_d->wMaxPacketSize;
  151.     enp.toggle  = DATA0;
  152.  
  153.     packet = kzalloc(enp.size, 0);
  154.  
  155.     rq = create_request(dev, &enp, DIN, packet, enp.size);
  156.     rq->qnum = 6;
  157.     rq->handler = &mouse_handler;
  158.  
  159.     u32_t efl = safe_cli();
  160.       list_add_tail(&rq->list, &dev->host->rq_list);
  161.       qh = dev->host->qh[6];
  162.       qh->qelem = rq->td_head->dma;
  163.       mb();
  164.     safe_sti(efl);
  165.  
  166.     dbgprintf("create_hid_mouse\n");
  167. }
  168.