Electronic – USB descriptor (LUFA)

avrlufasoftwareteensyusb

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…

Best Answer

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