Hot!HID Packet length

Author
AlexT
New Member
  • Total Posts : 9
  • Reward points : 0
  • Joined: 2008/07/05 22:11:02
  • Location: 0
  • Status: offline
2009/12/23 00:54:14 (permalink)
0

HID Packet length

Hi All,

When using a Vendor Defined HID Report, is it possible to send packet smaller than the maximum size specified in the report? I have set my HID Input report for 64 Bytes Counts, as long as I send 64 bytes packets to the PC everything is fine, but if I send a packet with less bytes, the PC never receive it... Is it a limitation of HID? it feel like a waste of bandwith to fill the unused bytes of a packet with 0's to be able to send it...

I will aprreciate any explainations/solutions/Ideas

Thank you,
Alex
#1

13 Replies Related Threads

    DarioG
    Allmächtig.
    • Total Posts : 54079
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: HID Packet length 2009/12/23 04:15:10 (permalink)
    0
    AFAIK you must send that precise amount. Anyway, it won't bea waste even if you're not using all of them, since a transaction takes 1mSec anyway.

    GENOVA :D :D ! GODO
    #2
    AlexT
    New Member
    • Total Posts : 9
    • Reward points : 0
    • Joined: 2008/07/05 22:11:02
    • Location: 0
    • Status: offline
    RE: HID Packet length 2009/12/23 07:27:21 (permalink)
    0
    Thanks Dario for the explaination,

    I know from reading thru the pile of docs I got about USB that it is possible to configure more than 1 input reports and assing different Report_ID to then, I try to add another one to my device but then it failed ennumeration... I could not find example on the net on how to write the ennumeration for more than 1 input report, also I have no idea hot to tell the PIC how to send to another report ID, as now all data sent get the report ID 00 automaticly (the first byte I receive in windows), is this possible to do with PIC and how would I need to do this?

    Here is my ennumeration setup:
    Descriptor_begin
    Device
    db 0x12, DEVICE ; bLength, bDescriptorType
    db 0x00, 0x02 ; bcdUSB (low byte), bcdUSB (high byte)
    db 0x00, 0x00 ; bDeviceClass, bDeviceSubClass
    db 0x00, 0x08 ; bDeviceProtocl, bMaxPacketSize
    db 0x25, 0x09 ; idVendor (low byte), idVendor (high byte)
    db 0x99, 0x12 ; idProduct (low byte), idProduct (high byte)
    db 0x01, 0x00 ; bcdDevice (low byte), bcdDevice (high byte)
    db 0x01, 0x02 ; iManufacturer, iProduct
    db 0x00, NUM_CONFIGURATIONS ; iSerialNumber (none), bNumConfigurations

    Configuration1
    db 0x09, CONFIGURATION ; bLength, bDescriptorType
    db 0x29, 0x00 ; wTotalLength (low byte), wTotalLength (high byte)
    db NUM_INTERFACES, 0x01 ; bNumInterfaces, bConfigurationValue
    db 0x00, 0xA0 ; iConfiguration (none), bmAttributes
    db 0x32, 0x09 ; bMaxPower (100 mA), bLength (Interface1 descriptor starts here)
    db INTERFACE, 0x00 ; bDescriptorType, bInterfaceNumber
    db 0x00, 0x02 ; bAlternateSetting, bNumEndpoints (excluding EP0)
    db 0x03, 0x00 ; bInterfaceClass (HID code), bInterfaceSubClass
    db 0x00, 0x00 ; bInterfaceProtocol, iInterface (none)
    HID1
    db 0x09, HID ; bLength, bDescriptorType
    db 0x01, 0x01 ; bcdHID (low byte), bcdHID (high byte)
    db 0x00, 0x01 ; bCountryCode (none), bNumDescriptors
    db REPORT, 0x2F ; bDescriptorType, wDescriptorLength (low byte)
    db 0x00, 0x07 ; wDescriptorLength (high byte), bLength (Endpoint1 descritor starts here)
    db ENDPOINT, 0x81 ; bDescriptorType, bEndpointAddress (EP1 IN)
    db 0x03, 0x40 ; bmAttributes (Interrupt), wMaxPacketSize (low byte)
    db 0x00, 0x09 ; wMaxPacketSize (high byte), bInterval (1 ms)
    Endpoint2
    db 0x07, ENDPOINT ; bLength, bDescriptorType
    db 0x01, 0x03 ; bEndpointAddress (EP1 OUT), bmAttributes (Interrupt)
    db 0x40, 0x00 ; wMaxPacketSize (low byte), wMaxPacketSize (high byte)
    db 0x09 ; bInterval
    Report1
    db 0x06, 0xA0 ; Usage Page (Vendor Defined),
    db 0xFF, 0x09 ; ..., Usage ID (Vendor Defined)
    db 0x01, 0xA1 ; ..., Collection (Application)
    db 0x01, 0x09 ; ..., Usage ID (Vendor Defined) ; The Input Report
    db 0x03, 0x15 ; ..., Logical Minimum (0)
    db 0x00, 0x26 ; ..., Logical Maximum (255)
    db 0x00, 0xFF ; ...,
    db 0x75, 0x08 ; Report Size (8 bits),
    db 0x95, 0x40 ; Report Count (64 fields),
    db 0x81, 0x02 ; Input (Data, Variable, Absolute),
    db 0x09, 0x04 ; Usage ID (Vendor Defined), ; The Output Report
    db 0x15, 0x00 ; Logical Minimum (0),
    db 0x26, 0x00 ; Logical Maximum (255)
    db 0xFF, 0x75 ; ..., Report Size (8 bits)
    db 0x08, 0x95 ; ..., Report Count (64 fields)
    db 0x40, 0x91 ; ..., Output (Data, Variable, Absolute)
    db 0x02, 0x09 ; ..., Usage ID (Vendor Defined) ; The Feature Report
    db 0x05, 0x15 ; ..., Logical Minimum (0)
    db 0x00, 0x26 ; ..., Logical Maximum (255)
    db 0x00, 0xFF ; ...,
    db 0x75, 0x08 ; Report Size (8 bits),
    db 0x95, 0x02 ; Report Count (2 fields),
    db 0xB1, 0x02 ; Feature (Data, Variable, Absolute),
    db 0xC0 ; End Collection
    post edited by AlexT - 2009/12/23 07:31:09
    #3
    DarioG
    Allmächtig.
    • Total Posts : 54079
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: HID Packet length 2009/12/23 09:34:38 (permalink)
    0
    I did succeed in making up a HID device with more than one endpoint, but actually they were a keyboard with a data channel 8for reconfiguration) and a combo keyboard-mouse 8before Microchip published it as well9.
    I always get crazy with descriptors and such, but in the end they more or less do work Smile

    Basically you clone the data for the 1st endpoint, add another Report Descriptor, and you're done...

    GENOVA :D :D ! GODO
    #4
    BrunoF
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2011/03/27 18:35:36
    • Location: Far south away
    • Status: offline
    RE: HID Packet length 2011/03/27 18:48:35 (permalink)
    0
    DarioG

    AFAIK you must send that precise amount. Anyway, it won't bea waste even if you're not using all of them, since a transaction takes 1mSec anyway.



    Sorry to resuscitate this old post, but i have the same problem...When i try to send a packet size that is smaller than what i declared in descriptor endpoint, it just fail.

    Now, after reading this i was a little disappointed...but i went to the Universal Serial Bus Specification 2.0, and readed this:

    5.7.3 Interrupt Transfer Packet Size Constraints
    An endpoint for an interrupt pipe specifies the maximum size data payload that it will transmit or receive.
    The maximum allowable interrupt data payload size is 64 bytes or less for full-speed. High-speed endpoints
    are allowed maximum data payload sizes up to 1024 bytes. A high speed, high bandwidth endpoint
    specifies whether it requires two or three transactions per microframe. Low-speed devices are limited to
    eight bytes or less maximum data payload size. This maximum applies to the data payloads of the data
    packets; i.e., the size specified is for the data field of the packet as defined in Chapter 8, not including other
    protocol-required information. The USB does not require that data packets be exactly the maximum size;
    i.e., if a data packet is less than the maximum, it does not need to be padded to the maximum size.


    So...now i feel a little more of hope, but im having problems when trying to implement it.

    Keep it fighting! Seems that USB specification allows it!

    Good luck!
    #5
    chinzei
    Super Member
    • Total Posts : 2250
    • Reward points : 0
    • Joined: 2003/11/07 12:39:02
    • Location: Tokyo, Japan
    • Status: offline
    RE: HID Packet length 2011/03/27 20:25:44 (permalink)
    +2 (1)
    Seems that USB specification allows it!

    If the interface of your device would a vendor specific class, above rule could be directly applied to the interrupt endpoint on the interface. For HID interrupt endpoint(s), however, HID rule is applied.

    HID spec tells, "a HID class device identifies its data protocol and the type of data provided within its Report descriptor." (4.2 Subclass) That is, any length of report, which isn't defined in the report descriptor, is not accepted by PC HID class driver. Unfortunately, there is no way to define variable length report on a report descriptor, just fixed length.

    In other word, define as many report length as required on the report descriptor, using report ID.
    For example, this report descriptor defines 1, 2, 16 and 32 bytes input and output reports.
        
    char ReportDescriptor[63] = {
        0x06, 0x00, 0xff,              // USAGE_PAGE (Vendor Defined Page 1)
        0x09, 0x01,                    // USAGE (Vendor Usage  1)
        0xa1, 0x01,                    // COLLECTION (Application)
                                       // ------- common globals --------
        0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
        0x26, 0xff, 0x00,              //   LOGICAL_MAXIMUM (255)
        0x75, 0x08,                    //   REPORT_SIZE (8)
                                       // ------- 1 byte report --------
        0x85, 0x01,                    //   REPORT_ID (1)
        0x95, 0x01,                    //   REPORT_COUNT (1)
        0x09, 0x01,                    //   USAGE (Vendor Usage  1)
        0x81, 0x02,                    //   INPUT (Data,Var,Abs)
        0x09, 0x01,                    //   USAGE (Vendor Usage  1)
        0x91, 0x02,                    //   OUTPUT (Data,Var,Abs)
                                       // ------- 2 bytes report --------
        0x85, 0x02,                    //   REPORT_ID (2)
        0x95, 0x02,                    //   REPORT_COUNT (2)
        0x09, 0x01,                    //   USAGE (Vendor Usage  1)
        0x81, 0x02,                    //   INPUT (Data,Var,Abs)
        0x09, 0x01,                    //   USAGE (Vendor Usage  1)
        0x91, 0x02,                    //   OUTPUT (Data,Var,Abs)
                                       // ------- 16 bytes report --------
        0x85, 0x10,                    //   REPORT_ID (16)
        0x95, 0x10,                    //   REPORT_COUNT (16)
        0x09, 0x01,                    //   USAGE (Vendor Usage  1)
        0x81, 0x02,                    //   INPUT (Data,Var,Abs)
        0x09, 0x01,                    //   USAGE (Vendor Usage  1)
        0x91, 0x02,                    //   OUTPUT (Data,Var,Abs)
                                       // ------- 32 bytes report --------
        0x85, 0x20,                    //   REPORT_ID (32)
        0x95, 0x20,                    //   REPORT_COUNT (32)
        0x09, 0x01,                    //   USAGE (Vendor Usage  1)
        0x81, 0x02,                    //   INPUT (Data,Var,Abs)
        0x09, 0x01,                    //   USAGE (Vendor Usage  1)
        0x91, 0x02,                    //   OUTPUT (Data,Var,Abs)
        0xc0                           // END_COLLECTION
    };

    In above example, the value of each report ID is intentionally chosen, so that it represents the size of body data

    Each report is preceded by the report ID, when it is exchanged over interrupt endpoint.
        
                    the first byte    body data     total
                     (report ID)
     1 byte report:      0x01          1 byte        2 bytes
     2 byte report:      0x02          2 bytes       3 bytes
    16 byte report:      0x10         16 bytes      17 bytes
    32 byte report:      0x20         32 bytes      33 bytes


    Tsuneo
    post edited by chinzei - 2011/03/28 05:43:45
    #6
    DarioG
    Allmächtig.
    • Total Posts : 54079
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: HID Packet length 2011/03/28 02:16:35 (permalink)
    0
    thanks Tsuneo Smile yeah, that's it.

    GENOVA :D :D ! GODO
    #7
    BrunoF
    New Member
    • Total Posts : 12
    • Reward points : 0
    • Joined: 2011/03/27 18:35:36
    • Location: Far south away
    • Status: offline
    RE: HID Packet length 2011/03/30 21:19:17 (permalink)
    0
    Yes. You're right.

    Now, will mpusbapi.dll support HID Reports ID? Hmmm... I will have to try it or find other dll that supports it.

    Cheers.
    #8
    Snake
    Super Member
    • Total Posts : 183
    • Reward points : 0
    • Joined: 2008/06/08 13:25:18
    • Location: Germany
    • Status: offline
    RE: HID Packet length 2014/06/14 15:49:34 (permalink)
    0
    Hi,
     
    I am having the same problem. I want to send messages with different lenghts. I adjusted the report descriptor like Tsuneo suggested and now I can send Messages with a different length and the different report IDs to my device.
     
    But how do I use this on my pic. I am sending messages like this:
    USBInHandle = HIDTxPacket(CUSTOM_DEVICE_HID_EP, (uint8_t*)&ToSendDataBufferHID, 32);

    The report ID is the first byte that is sent but of 33 bytes and not of the 32? How do I tell it which ID to use?
    And how do I know which ID an incoming message has?
    #9
    DarioG
    Allmächtig.
    • Total Posts : 54079
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: HID Packet length 2014/06/15 06:04:37 (permalink)
    0
    This thread is kind of old :)

    I know that, depending upon descriptors (Tsuneo knows better!) you can either receive/send the Report ID in first position of your "packet" or not.

    GENOVA :D :D ! GODO
    #10
    Snake
    Super Member
    • Total Posts : 183
    • Reward points : 0
    • Joined: 2008/06/08 13:25:18
    • Location: Germany
    • Status: offline
    RE: HID Packet length 2014/06/15 13:51:15 (permalink)
    +1 (1)
    Thanks. It seems to be enough to just define different reports instead of not. Now I can send one byte more and it is recognized by my computer correctly. The first bit has to be the ID otherwise it won't work.
     
    For example:
                
    ToSendDataBufferHID[0] = 0x20;
    USBInHandle = HIDTxPacket(CUSTOM_DEVICE_HID_EP, (uint8_t*)&ToSendDataBufferHID, 33);

     
    The receiving part:
    USBOutHandle = HIDRxPacket(CUSTOM_DEVICE_HID_EP, (uint8_t*)&ReceivedDataBufferHID, 65);

     
    But now I am having a problem with 64byte messages. If I sent 64+1bytes from my computer I only receive the first 64 on my pic. So the last byte is missing. If I try to send 65bytes to the computer I get a bunch of strange usb errors in USBTrace but no data.
     
    I had a look at the other descriptor and saw this:
        /* Endpoint Descriptor */
        0x07,
        USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor
        CUSTOM_DEVICE_HID_EP | _EP_IN, //EndpointAddress
        _INTERRUPT, //Attributes
        0x40,0x00, //size
        0x01, //Interval

     
    I though there might be the limit of 64 and changed it to 65/0x41 but after that my device isn't recognized by Windows anymore.
     
    I hope someone knows what I need to change?
    #11
    DarioG
    Allmächtig.
    • Total Posts : 54079
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    RE: HID Packet length 2014/06/15 13:54:38 (permalink)
    0
    All right :)
    and it seems to me that I always faced the same issue - i.e. only 63 bytes of "actual payload" ...

    GENOVA :D :D ! GODO
    #12
    jesu
    New Member
    • Total Posts : 1
    • Reward points : 0
    • Joined: 2018/04/24 21:38:41
    • Location: 0
    • Status: offline
    Re: HID Packet length 2018/04/26 04:50:26 (permalink)
    -1 (1)
    How to enable the USB HID additional feature nTouch-pad ...?
    #13
    qɥb
    Monolothic Member
    • Total Posts : 3264
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: HID Packet length 2018/04/26 13:42:15 (permalink)
    0
    Apart from the tenuous link to "HID", your question has nothing to do with the topic you have hijacked.
    Please do NOT drag ancient topics back from the dead, start your own.
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #14
    Jump to:
    © 2018 APG vNext Commercial Version 4.5