Strange HID report for mouse

Discuss with MikroElektronika software developers about current library development.
Post Reply
Author
Message
VCC
Posts: 463
Joined: 08 Jun 2009 18:31
Location: Romania

Strange HID report for mouse

#1 Post by VCC » 21 Jun 2014 15:18

Hi,
I was checking a bit of code from the HID example which comes with USB Host Library, on mikroPascal for PIC32. Since I don't have the EasyPIC_Fusion_v7_for_PIC32 board, for which the example was written for, I couldn't test the HID mouse example as is.
To test if the mouse works, I copied pieces of this example into a new project and it turned out that X and Y movements were swapped and mixed with mouse buttons. The piece of code which handles this is

Code: Select all

procedure MouseReportReceived(reportData : ^byte);
var
  arrCh : array[6] of byte;
  i : byte;
begin
  for i := 0 to 5 do
  begin
    arrCh[i] := reportData^;
    reportData := reportData + 1
  end;

  mouseData.button := arrCh[0] + (word(arrCh[1]) shl 8);
  mouseData.x := arrCh[2] + (word(arrCh[3]) shl 8);
  mouseData.y := arrCh[4] + (word(arrCh[5]) shl 8);
  HID_MOUSE_UpdatePosition(mouseData.x, mouseData.y);
end;
It was a bit confusing until I've found what others say about the mouse HID report:http://www.instructables.com/id/USB-Wii ... and-Mouse/ This one works as it states.
My questions is, are the multiple possible standards to implement different HID reports or the code from the example is supposed to do something else? As I said, I don't have EasyPIC_Fusion_v7_for_PIC32 board so I don't know how the example works.
Thank you :D

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Strange HID report for mouse

#2 Post by Dany » 21 Jun 2014 16:36

Hi Vcc,

Perhaps these articles can help: http://www.eetasia.com/ARTICLES/2001MAR ... S=DOWNLOAD, http://www.instructables.com/id/USB-Wii ... and-Mouse/ and http://www.usb.org/developers/devclass_docs/HID1_11.pdf.

As you can see in them the USB mouse report is only 3 bytes long:

Code: Select all

Table 6. USB Mouse Data Report Format
Byte  bits
0     bit7..3 = Padding; bit2= Button3;  Bit1= Button2;  Bit0 = Button1.
1     bit7..0 = Horizontal (X) Displacement
2     bit7..0 = Vertical (Y) Displacement
My questions is, are the multiple possible standards to implement different HID reports or the code from the example is supposed to do something else?
I do not really know. All that I know of is the 3 bytes report, but the code you show suggests a 6 byte (3 word) report.

To be sure: what do you actually want to do
- read an USB mouse data with a PIC (I assume this one), or
- let a PIC behave as an USB mouse to e.g. the PC
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

VCC
Posts: 463
Joined: 08 Jun 2009 18:31
Location: Romania

Re: Strange HID report for mouse

#3 Post by VCC » 21 Jun 2014 17:03

Hi Dany,
thank you for info. The report from http://www.instructables.com/id/USB-Wii ... and-Mouse/ works as they say, with 5 bytes. I can't test the last byte since I don't have a mouse with horizontal scroll. However, the vertical scroll, from the 4th byte is working, despite the 3 bytes report you mentioned in http://www.eetasia.com/ARTICLES/2001MAR ... S=DOWNLOAD. Anyway, they have the same structure, one byte for every piece of data (x, y, buttons, scrolls). The code from mikroe's example mixes the bytes.
In http://www.usb.org/developers/devclass_docs/HID1_11.pdf, at page 19, 5.8 Format of Multibyte Numeric Values, there is something that explains it. :D

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: Strange HID report for mouse

#4 Post by Dany » 21 Jun 2014 20:29

VCC wrote:Hi Dany,
thank you for info. The report from http://www.instructables.com/id/USB-Wii ... and-Mouse/ works as they say, with 5 bytes. I can't test the last byte since I don't have a mouse with horizontal scroll. However, the vertical scroll, from the 4th byte is working, despite the 3 bytes report you mentioned in http://www.eetasia.com/ARTICLES/2001MAR ... S=DOWNLOAD. Anyway, they have the same structure, one byte for every piece of data (x, y, buttons, scrolls). The code from mikroe's example mixes the bytes.
In http://www.usb.org/developers/devclass_docs/HID1_11.pdf, at page 19, 5.8 Format of Multibyte Numeric Values, there is something that explains it. :D
Thanks!!! :D I never made something as an USB mouse. :oops: :oops:
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

VCC
Posts: 463
Joined: 08 Jun 2009 18:31
Location: Romania

Re: Strange HID report for mouse

#5 Post by VCC » 22 Jun 2014 05:17

I never made something as an USB mouse.
Neither do I. I use an existing mouse :lol: . So I have to read carefully all these articles, because I might encounter a mouse of the other type and my application should accept both.

Post Reply

Return to “Library Development Discussion”