# USB descriptor (LUFA)

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

• Is the unedited demo working properly? – tyblu Jan 20 '11 at 4:38
• yep, I got it to work. but two buttons is not enough for me :) – jojo l'abricot Jan 20 '11 at 9:37
• 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 – Toby Jaffey Jan 20 '11 at 16:26

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);

• I've edited in your changes and deleted the second response – Toby Jaffey Jan 20 '11 at 22:29
• Is the second code block supposed to have "Report Size (5)" instead of .."(6)"? (The corresponding code is the same.) – David X Jan 21 '11 at 8:25
• yes it does, and works ! thanks, I missed that input part. I understand now that it simply comlete a byte. – jojo l'abricot Jan 21 '11 at 15:38

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

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

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