6

I'm trying to jump in the USB world with LUFA on a Teensy dev board, but I'm stuck in the understanding of the descriptors.

Currently I'm trying to add one button to the joystick demo without sucess. Does anyone know some resource that explains step by step how to set up a USB descriptor?

edti : After reading USB in a nutshel, I think I may not modified the Descriptor at all but the HIDReport instead...

Trygve Laugstøl
  • 1,410
  • 2
  • 19
  • 28
jojo l'abricot
  • 795
  • 1
  • 7
  • 13

3 Answers3

5

You need to edit the HID report descriptor, but also the main code. Change this portion of the HID descriptor:

    0x05, 0x09,          /*   Usage Page (Button)                              */
    0x09, 0x02,          /*   Usage (Button 2)                                 */
    0x09, 0x01,          /*   Usage (Button 1)                                 */
    0x15, 0x00,          /*   Logical Minimum (0)                              */
    0x25, 0x01,          /*   Logical Maximum (1)                              */
    0x75, 0x01,          /*   Report Size (1)                                  */
    0x95, 0x02,          /*   Report Count (2)                                 */
    0x81, 0x02,          /*   Input (Data, Variable, Absolute)                 */
    0x75, 0x06,          /*   Report Size (6)                                  */
    0x95, 0x01,          /*   Report Count (1)                                 */
    0x81, 0x01,          /*   Input (Constant)                                 */
    0xc0                 /* End Collection                                     */

To this:

    0x05, 0x09,          /*   Usage Page (Button)                              */
    0x09, 0x03,          /*   Usage (Button 3)                                 */
    0x09, 0x02,          /*   Usage (Button 2)                                 */
    0x09, 0x01,          /*   Usage (Button 1)                                 */
    0x15, 0x00,          /*   Logical Minimum (0)                              */
    0x25, 0x01,          /*   Logical Maximum (1)                              */
    0x75, 0x01,          /*   Report Size (1)                                  */
    0x95, 0x03,          /*   Report Count (3)                                 */
    0x81, 0x02,          /*   Input (Data, Variable, Absolute)                 */
    0x75, 0x06,          /*   Report Size (5)                                  */
    0x95, 0x01,          /*   Report Count (1)                                 */
    0x81, 0x01,          /*   Input (Constant)                                 */
    0xc0                 /* End Collection                                     */

And set the third bit of the Buttons element in the element in the CALLBACK_HID_Device_CreateHIDReport() function of the main source file, i.e. to "push" the new third button, use:

 if (ButtonStatus_LCL & BUTTONS_BUTTON1)
   JoystickReport->Button |= (1 << 2);
Toby Jaffey
  • 28,796
  • 19
  • 96
  • 150
3

Here's the USB in a Nutshell page on descriptors.

http://www.beyondlogic.org/usbnutshell/usb5.shtml

Toby Jaffey
  • 28,796
  • 19
  • 96
  • 150
2

The HID page at USB.org has a wealth of information about the HID spec. Of particular interest on that page is the HID Descriptor Tool, that can be used to create, edit and validate HID report descriptors.

If you are going to be doing a lot of work with USB, I highly recommend getting Jan Axelson's book USB COMPLETE. More information can be found here: http://www.lvr.com/usb.htm

samoz
  • 1,181
  • 3
  • 13
  • 26
Louis Davis
  • 616
  • 4
  • 5