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.0There 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