Electronic – What coordinates should an USB HID mouse return

hidusb

I am trying to implement an USB HID mouse for my custom board (to move the mouse pointer on my display). Right now, I am able to read the descriptors.

I found the logical min and max to be -127 and +127. After reading the documentation for HID, I got confused.

  • What is physical min and max of a device?
  • What is its role?

If I want to calibrate my mouse to a given display, where to give the coordinates? Also, when the mouse action takes place, I am getting coordinate values (X and Y and buttons) two or three times.

Is it because the values returned by the mouse are continuous and I have to implement some averaging? Or is it like the mouse coordinates returned are relative and I have to initialize my mouse coordinates as (0,0) and from the previous position I have to calculate the current position?


Thanks for the reply. But from which field of the descriptor I can find the unit, means whenever I move a mouse I will get the X and Y, how to find out what is the unit it has moved?(inch or meter). Because the HID descriptor I am getting consists of the following fields:

Usage Page-   05 01
Usage Mouse- 09 02
Collection(App)-a1 01
Usage(Pointer)-09 01
Collection(Physical)-a1 00
Usage Page(Button)-05 09
Usage Min- 19 01
Usage Max-29 05
Logical Min-15 00
Logical Max-25 01
Report Count-95 05
Report Size-75 01
Input(Data,Variable,Absolute)-81 02
Report Count- 95 00
Input-81 03
Usage Page-05 01
Usage X- 09 30
Usage Y- 09 31
Wheel   - 09 38
Logical Min-15 81
Logical Max-25 7f
Report Size -75 08
Report Count-95 03
Input-81 06

05 0c
0a 38
02 95
01 81
06 c0
c0

I dont know what are the values after the input field.

This is what I am getting as hid descriptor from my logitech mouse. I understand it is relatve(from 81 06).And in addition to it, I get coordinates(X and Y) and buttons whenever I move or click. But where to get the unit and unit exponent(for finding the resolution and how much the mouse has moved)?? Thanks again

Best Answer

If I recall correctly, the Physical Min and Max are just "window dressing" so to speak. From the HID spec:

While Logical Minimum and Logical Maximum (extents) bound the values returned by a device, Physical Minimum and Physical Maximum give meaning to those bounds by allowing the report value to be offset and scaled. For example, a thermometer might have logical extents of 0 and 999 but physical extents of 32 and 212 degrees.The resolution can be determined with the following algorithm:

So for this example, the HID thermometer would be returning a value between 0-999 in the report. That's the bytes that actually flow from device to PC through an IN endpoint. These values are determined by the Logical Min/Max.

The Physical Min/Max describes how the Logical units map onto a Physical "spectrum". In this case, from water's freezing (32 degrees F) to the boiling (212 F). In this case, when the device sends a 0, it means 32 F, and when it sends 999, it means 212 F. Software can then read the HID descriptor to determine the mapping.

In the grand scheme of things, physical min/max aren't that meaningful unless you intentionally use them. For consistency, I generally set my physical to match my logical.