Author Topic: HID class on USB  (Read 8636 times)

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
HID class on USB
« on: August 07, 2011, 05:53:46 PM »
Hi Mark,
  Just wondering if there are any plans to include the HID class on the USB (on the M5225x chip)?

Thanks
Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: HID class on USB
« Reply #1 on: August 08, 2011, 10:23:32 PM »
Hi Neil

I have been waiting for someone to ask for the HID class. Until now it hasn't happened though...

Although I haven't actually done anything with it before I don't expect that it is that complicated. The class itself is realised purely at the usb_application.c layer since the lower level parts should have all of the interfaces needed.

Something that I have also not used is isochronous mode and this may need some modifications at the driver layer too.

Essentially, up to now, the CDC class seems to have allowed all projects using USB device to be realised. It is possibly also suitable for realising things that could/should use HID. I have also hear that in some cases (in other projects) HID has been used to realsie things that are more suited to CDC to, so there is obviously a bit of flexibilty.

If you are interested in a concrete HID device project contact me directly - I don't think that it would be difficult to adapt for.

Regards

Mark


« Last Edit: February 13, 2012, 01:57:55 PM by mark »

Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: HID class on USB
« Reply #2 on: February 12, 2012, 10:51:40 PM »
Hi Mark,
  Did you ever get the HID to work on the USB, any signs this being added to utasker?

Thanks
Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: HID class on USB
« Reply #3 on: February 13, 2012, 08:17:19 PM »
Hi Neil

In fact HID has recently been added and I have just made a M522xx release with it here: http://www.utasker.com/forum/index.php?topic=1310.0

There are new defines to better control the USB device mode in config.h, whereby USE_USB_HID_MOUSE causes it to enumerate as a mouse. Depending on the board available, switches or similar are used to control the mouse position and mouse buttons.

The changes are essentiall as follows:
-   usb.h – this contains a few new defines which are needed for HID mouse operation
-   usb_application.c – this contains the HID mouse application layer control
-   app_hw_m5223x.h – this contains the setup macros for the switches on the boards so that they can be used as mouse direction/key inputs.

When the USB is attached it will enumerate and install the standard Windows HID driver (this doesn’t need any special INF files). After installation Windows will poll the board via USB Interrupt IN every 8ms. When buttons are pressed (depends on board used and how many buttons they have - or the user can define different inputs) USB IN tokens are sent containing the details of changes.
When no keys are pressed the USB controller returns NAK to the Interrupt IN requests since there is no information to be sent.

In fact HID turned out to be fairly simple yet quite powerful (although OUT direction is not used in the mouse case).
The most difficult thing to understand is the content of ucMouseReport[]. This is the report that tells the PC host what is connected and what the data means. In the simple mouse case there are 4 bytes sent when there is a movement/click:
[Button state][x movement][y movement][wheel movement]

Practical is the fact that there is a default HID driver on all PCs and a standard PC API. It seems quite simple to write a PC program that can work together with the HID driver and so it looks like quite a useful general purpose interface for various applications due to this reason - it is quite simple to write applications on both the PC and the embedded target which can interract to perform useful task without needing to get involved with developing specal purpose PC USB drivers.

I found that it was best to learn by reading the HID specification and comparing the report field that is sent by reference devices (like an old Logitec mouse) – I use TOTAL PHASE BEAGLE USB 480 analyser with their DATA CENTER 6 (this can be downloaded from their web site) to view the recordings and this decodes the HID class information and so shows what is being reported quite nicely. Attached is a quick example.

Regards

Mark




Offline neil

  • Sr. Member
  • ****
  • Posts: 438
    • View Profile
Re: HID class on USB
« Reply #4 on: February 14, 2012, 08:07:11 AM »
Thats excellent Mark.

At the moment I am not running the latest utasker (just updated the SD card module, and works well) , and would like to use the HID.

Can you tell me what I can copy from the app_hw_m5223x.h to my current version ?

Are there different VID & PID codes?

Thanks
Neil

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: HID class on USB
« Reply #5 on: February 14, 2012, 12:44:17 PM »
Hi Neil

There are some defines for the mouse inputs:

    #define CONFIGURE_MOUSE_INPUTS()
    #define MOUSE_LEFT_CLICK()         0
    #define MOUSE_UP()                 0
    #define MOUSE_DOWN()               0
    #define MOUSE_LEFT()               0
    #define MOUSE_RIGHT()              0


When left at 0 it will build but, of course, nothing would actually react. To allow a switch to control the mouse direction to the left, for example, the switch can be defined - eg.
#define MOUSE_LEFT()               (!_READ_PORT_MASK(DD, USER_SWITCH_SW1)) // press this button to move mouse left
etc.

There is a different VID/PID for the HID mouse but it is just a 'dummy' one. There is no official one for the project as is the case for CDC (and also MSD in case of the freescale project).

Regards

Mark