I own a stm32f4 discovery board, for which a demonstration project can be downloaded here:
http://www.st.com/web/en/catalog/tools/PF257904
This demo consists of software to use the board as a usb hid mouse, using the accelerometer to control the mouse movement. I want to change this into a gamepad, for now I'm leaving the other parts of the descriptor the same, so I only changed the usage from 0x09,0x02 (usage: mouse) to 0x09 , 0x09 (usage: gamepad). (these values can be found in the usb_hid_core file)
But after this change the computer still sees it as a mouse, but one that is not functioning correctly. What else should I change?
Any help would be greatly appreciated, I have been trying all kinds of things for weeks now, but nothing seems to work.
the usb_hid_core file can be found in this file at this location:
stsw-stm32068\STM32F4-Discovery_FW_V1.1.0\Libraries\STM32_USB_Device_Library\Class\hid\src
(i was under the impression that all that i would have to change would be this line in the descriptor to make it look as a gamepad, since the data that is send will still comply with the descriptor then, i also tried changing it to a very simply device that sends just one byte before changing it into a a gamepad, and i tried changing various other things like hid class). This is how it shows up after i change it to a gamepad (but is doens't work then): http://hmsprojects.com/USB-invoerapparaat.html
Best Answer
You need to change few others things to make it work as a gamepad. In usbd_hid_core.c you need to change :
to the 0x00 value.
Other thing, the report descriptor has to be changed, this is mine for a 3-buttons 2-axis gamepad, (you can change it to add button or anything else with the HIDtool) :
The size of the report descriptor has changed so modify it in usbd_hid_core.c :
Now the gamepad would be recognized. You only need to send a 3 bytes report (the first for the button, et the two others for the axis). For a test you could do it by using this code in stm32xx_it.c :
Anf finally change the line (in the same file) :
to :
This should work well on the STM32f4 discovery board. If not try change the PID by adding 1 (like 0x5711) in usbd_desc.c).