6
\$\begingroup\$

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

\$\endgroup\$
3
  • \$\begingroup\$ Is the unedited demo working properly? \$\endgroup\$
    – tyblu
    Commented Jan 20, 2011 at 4:38
  • \$\begingroup\$ yep, I got it to work. but two buttons is not enough for me :) \$\endgroup\$ Commented Jan 20, 2011 at 9:37
  • 1
    \$\begingroup\$ The LUFA keyboard sample shows how to detect buttons on IO pins and generate keyboard events. Using this, you have easy access to scancodes for the entire keyboard \$\endgroup\$ Commented Jan 20, 2011 at 16:26

3 Answers 3

5
\$\begingroup\$

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);
\$\endgroup\$
3
  • \$\begingroup\$ I've edited in your changes and deleted the second response \$\endgroup\$ Commented Jan 20, 2011 at 22:29
  • \$\begingroup\$ Is the second code block supposed to have "Report Size (5)" instead of .."(6)"? (The corresponding code is the same.) \$\endgroup\$
    – David X
    Commented Jan 21, 2011 at 8:25
  • \$\begingroup\$ yes it does, and works ! thanks, I missed that input part. I understand now that it simply comlete a byte. \$\endgroup\$ Commented Jan 21, 2011 at 15:38
3
\$\begingroup\$

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

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

\$\endgroup\$
2
\$\begingroup\$

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

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.