• AVR Freaks

Changing from Mouse to Generic HID

Author
brumbarchris
Super Member
  • Total Posts : 363
  • Reward points : 0
  • Joined: 2003/12/03 05:58:39
  • Location: Timisoara, Romania
  • Status: offline
2013/05/27 07:56:44 (permalink)
0

Changing from Mouse to Generic HID

Hi all,
After having successfully created a mouse in a PIC18F24J50 (just moves the cursor straight across the screen at a predetermined rate), I wanted to move on and change this to a HID, in order to communicate with a PC application (which I have yet to develop).
 
In order to change the mouse code to Generic HID I have made the following changes:
1. I changed the interface descriptor from:
 /* Interface Descriptor */
    INTERFACE_DESCRIPTOR_LENGTH,                    // size (in bytes) of this interface descriptor
    0x04,                                           // INTERFACE descriptor type
    0x00,                                           // Interface Number
    0x00,                                           // Alternate Setting Number
    0x01,                                           // Number of endpoints in this intf
    0x03,                                           // HID Interface Class code
    0x01,                                           // HID Interface Class SubClass Codes
    0x02,                                           // HID MOUSE Protocol code
    0x00,                                           // Interface string index

 
to
 
 /* Interface Descriptor */
    INTERFACE_DESCRIPTOR_LENGTH,                    // size (in bytes) of this interface descriptor
    0x04,                                           // INTERFACE descriptor type
    0x00,                                           // Interface Number
    0x00,                                           // Alternate Setting Number
    0x01,                                           // Number of endpoints in this intf
    0x03,                                           // HID Interface Class code
    0x00,                                          
    0x00,                                          
    0x00,                                          

 
2. I changed the Report descriptor from a mouse one to:
const unsigned char REPORT_DESCRIPTOR[]@REPORT_DESCRIPTOR_ADDRESS=
{
    0x06, 0x00, 0xFF,   /* Usage Page = 0xFF00 (Vendor Defined Page 1)                                                                                      */
    0x09, 0x01,         /* Usage (Vendor Usage 1)                                                                                                           */
    0xA1, 0x01,         /* Collection (Application)                                                                                                         */
    0x19, 0x01,         /*  Usage Minimum                                                                                                                   */
    0x29, 0x08,         /*  Usage Maximum     //eight input usages total (0x01 to 0x40)                                                                      */
    0x15, 0x01,         /*  Logical Minimum (data bytes in the report may have minimum value = 0x00)                                                        */
    0x25, 0x40,          /*  Logical Maximum (data bytes in the report may have maximum value = 0x00FF = unsigned 255)                                       */
    0x75, 0x08,         /*  Report Size: 8-bit field size                                                                                                   */
    0x95, 0x08,         /*  Report Count: Make eight 8-bit fields (the next time the parser hits an "Input", "Output", or "Feature" item)              */
    0x81, 0x00,         /*  Input (Data, Array, Abs): Instantiates input packet fields based on the above report size, count, logical min/max, and usage.   */
    0x19, 0x01,         /*  Usage Minimum                                                                                                                   */
    0x29, 0x08,         /*  Usage Maximum     //eight output usages total (0x01 to 0x40)                                                                     */
    0x91, 0x00,         /*  Output (Data, Array, Abs): Instantiates output packet fields.  Uses same report size and count as "Input" fields, since nothing new/different was specified to the parser since the "Input" item.*/
    0xC0                /* End Collection                                                                                                                   */
};

 
The new device successfully enumerates as a USB Human Interface Device, which is good. Sniffing USB traffic with USBlyzer, I still notice the OS (WinXP, that is) still polls the interrupt endpoint at the necessary rate, however, I am not sure it was supposed to happen that way. I was was under the impression that the OS would only do the polling for a Mouse device, whereas for a generic HID I expected the polling to be handled by the PC application that needs to be developed. Is my understanding wrong?
 
Regards,
Cristian
#1

3 Replies Related Threads

    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re:Changing from Mouse to Generic HID 2013/05/27 08:26:57 (permalink)
    0
    Hmm, I never considered much the underlying details Smile
    AFAIK, the PC will always poll for data since the USB device is somewhat a "slave" - so I'd say it's ok. Your application (I used HID many many times) will "grab" data from the USB hardware as it feels like, and the same for sensing (of course).

    GENOVA :D :D ! GODO
    #2
    brumbarchris
    Super Member
    • Total Posts : 363
    • Reward points : 0
    • Joined: 2003/12/03 05:58:39
    • Location: Timisoara, Romania
    • Status: offline
    Re:Changing from Mouse to Generic HID 2013/05/27 23:06:54 (permalink)
    0
    OK thanks.
     
    I find it much more difficult when trying to pick up on the host side application. When I started up with USB I selected HID based on the widely advertised theory that "you can use Windows HID drivers".
     
    So I have put a lot of effort in implementing the HID profile in the micro, and now, when I start looking into a C# PC application, I find out it is not very straightforward to even send a GET DESCRIPTOR request to the USB device, even if it is a HID...
     
    Regards,
    Cristian
    #3
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re:Changing from Mouse to Generic HID 2013/05/28 00:12:53 (permalink)
    0
    Yeah, true: but there are some special APIs for those - at least on Windows...
     
    In fact, when I wanted to fetch a string or alike from my HID devices, I did use a custom HID command (packet) for returning strings!
    post edited by DarioG - 2013/05/28 00:16:24

    GENOVA :D :D ! GODO
    #4
    Jump to:
    © 2019 APG vNext Commercial Version 4.5