1
\$\begingroup\$

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

\$\endgroup\$
  • 1
    \$\begingroup\$ I always understood that the fun of a HID interface is that you're not required to write drivers as you can use the standard HID driver. What's different in you application that you do need to write your own driver if I may ask? \$\endgroup\$ – jippie May 3 '12 at 6:41
  • \$\begingroup\$ It is a custom board, not a PC. There is no such thing as a "standard HID driver" on a custom hardware. \$\endgroup\$ – Axeman May 3 '12 at 7:27
  • 1
    \$\begingroup\$ @Axeman - that would depend on whether the MCU manufacturer provides a reference HID implementation. \$\endgroup\$ – Connor Wolf May 3 '12 at 7:31
  • \$\begingroup\$ @FakeName You're absolutely right. But I don't think that the problem is the HID implementation. The OP is talking about a driver for a mouse... and as far as I remember, the only "micro" I've used with a standard USB mouse driver are those that runs the .NETMF. \$\endgroup\$ – Axeman May 4 '12 at 11:01
1
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

It's my understanding that a mouse is fundamentally a relative device. The values returned by the mouse are the amount of movement since it last reported.

As such, if you want to make a system that performs like a typical computer mouse, you need to integrate the delta values reported by the HID driver.

With a computer screen, basically every display-update-cycle, the computer sums the total reported mouse movement in X and Y, and moves the pointer that much relative to it's current position.

You of course have to do some sanity-checking to ensure your pointer does not leave the screen, but that is the basics required for a implementation of a mouse-pointing-device.


There are (considerable) additional complexities involved in handling mouse-movement on a modern computer, as (almost all) current operating systems have an additional characteristic called pointer acceleration. However, provided your device's screen is not physically very large and/or high-resolution, it's very possible you can simply leave out pointer acceleration without making it much harder to use.

(See the wikipedia note about mouse speed for more information.)


From the sound of your post, it sounds a bit like you are thinking a mouse is an absolute pointing device. Mice in general are a relative pointing devices. They have no ability to tell where they are. All they can report is how much they have moved since they were last polled.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.