Author Topic: HID Touchscreen - Width/Height usages  (Read 10142 times)

usa303

  • Member
  • ***
  • Posts: 2
HID Touchscreen - Width/Height usages
« on: October 10, 2014, 03:27:38 am »
I'm designing HID touchscreen and wonder about features "Width" and "Height". All HID reports that I checked have them defined like:
Code: [Select]
    0x75, 0x10,                         //       REPORT_SIZE (16)         
    0x95, 0x02,                         //       REPORT_COUNT (2)                     
    0x05, 0x0d,                         //       USAGE_PAGE (Digitizers)
    0x09, 0x48,                         //       USAGE (Width)               
    0x09, 0x49,                         //       USAGE (Height)               
    0x81, 0x02,                         //       INPUT (Data,Var,Abs)

Can please someone explain why USAGE (Height) comes immediately after USAGE (Width) without any INPUT field?
How should I write real width and height values - just two 16-bit values one after one?

Or probably I should better define descriptor like:
Code: [Select]
    0x75, 0x10,                         //      REPORT_SIZE (16)
    0x95, 0x01,                         //      REPORT_COUNT (1)
    0x05, 0x0d,                         //      USAGE_PAGE (Digitizers)
    0x09, 0x48,                         //      USAGE (Width)       
    0x81, 0x02,                         //      INPUT (Data,Var,Abs)         
    0x09, 0x49,                         //      USAGE (Height)               
    0x81, 0x02,                         //      INPUT (Data,Var,Abs)

android

  • Member
  • ***
  • Posts: 5
Re: HID Touchscreen - Width/Height usages
« Reply #1 on: October 10, 2014, 08:47:42 am »
Both of your examples are equivalent. They describe the same report to be sent to the host. A C declaration for both of them would look something like:

Code: [Select]
//--------------------------------------------------------------------------------
// Digitizer Device Page inputReport (Device --> Host)
//--------------------------------------------------------------------------------

typedef struct
{
                                                     // No REPORT ID byte
                                                     // Collection: TouchScreen Stylus
  uint16_t DIG_TouchScreenStylusWidth;               // Usage 0x000D0048: Width, Value = 0 to 32767
  uint16_t DIG_TouchScreenStylusHeight;              // Usage 0x000D0049: Height, Value = 0 to 32767
} inputReport_t;

Your first example is just a slightly shorter way of defining the same report, which consists of 2 x 16-bit fields. The first field is to hold the Width value (USAGE 0x000D0048 = PAGE 0x000D (digitizer) and USAGE 0x0048 (width) within that page) and the second field is to hold the Height value (USAGE 0x0049). The order is unimportant because the report descriptor defines the order of the fields and the host driver uses that to determine how to parse the report.

Other ways of reducing the size of a report descriptor include:
  • not re-specifying GLOBAL items (for example LOGICAL_MINIMUM and LOGICAL_MAXIMUM) unless they need to be changed for the next field
  • specifying a range of usages (via USAGE_MINIMUM and USAGE_MAXIMUM) instead of a long list of individual USAGE items

I'm still amazed at the amount of effort the relevant committee went to to define a way of compressing a report descriptor - when you consider that it is only one message in the thousands of USB messages that are exchanged after you plug a USB device in. But they must have had their reasons - probably to allow descriptors to fit within embedded devices with limited memory I guess.

usa303

  • Member
  • ***
  • Posts: 2
Re: HID Touchscreen - Width/Height usages
« Reply #2 on: October 10, 2014, 11:27:42 am »
Thank you for your detailed reply, now it is clear.
Indeed, the length of report descriptor is very important, especially for small microcontrollers like PIC16, when every byte counts.