Adapting LPC1343 usbhid example to multi-byte transfers

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Adapting LPC1343 usbhid example to multi-byte transfers

704 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by davidsmoot on Mon May 21 16:22:16 MST 2012
I want to exchange HID reports between a USB host and my code running on a LPC1343 using the HID protocol.

I want to be able to define the size and structure of these messages to be an arbitrary number of bitfields and bytes.

I started with the example "USBHid" project.  I think I understand that code.  It exchanges a single byte in each direction.  It defines the output from the host as "LED" bitfields and the input to the host as "Button" bitfields.

So I want to hack together an example project that defines my own HID packet structure.  I copied the HID demo code base, modified it, and tested it.  It compiles but I get errors when I plug in the USB connection about the USB device failing to start even before I try to exchange data.  So here I am, asking for help.

This is my first attempt at coding a USB interface.  Any suggestions about debug tools / techniques?

If it worked, I expect my code to accept an "OutReport" of 4 bytes from the host, copy those four bytes to an "InReport", and append a counter byte to the end of the InReport.  But for now I get a USB error in the windows device manager of "Failed to start (10)"

I'm guessing I probably screwed up the syntax of the HID_ReportDescriptor byte array when I modified it.  The original byte array definition:
/* HID Report Descriptor */
const uint8_t HID_ReportDescriptor[] = {
  HID_UsagePageVendor(0x00),
  HID_Usage(0x01),
  HID_Collection(HID_Application),
    HID_UsagePage(HID_USAGE_PAGE_BUTTON),
    HID_UsageMin(1),
    HID_UsageMax(3),
    HID_LogicalMin(0),
    HID_LogicalMax(1),
    HID_ReportCount(3),
    HID_ReportSize(1),
    HID_Input(HID_Data | HID_Variable | HID_Absolute),
    HID_ReportCount(1),
    HID_ReportSize(5),
    HID_Input(HID_Constant),
    HID_UsagePage(HID_USAGE_PAGE_LED),
    HID_Usage(HID_USAGE_LED_GENERIC_INDICATOR),
    HID_LogicalMin(0),
    HID_LogicalMax(1),
    HID_ReportCount(8),
    HID_ReportSize(1),
    HID_Output(HID_Data | HID_Variable | HID_Absolute),
  HID_EndCollection,
};


My attempt at a custom version:
/* HID Report Descriptor */
const uint8_t HID_ReportDescriptor[] = {
HID_UsagePageVendor(0x00),
HID_Usage(0x01),
HID_Collection(HID_Application),
HID_UsagePageVendor(0xC5),
HID_UsageMin(1),
HID_UsageMax(4),
HID_LogicalMin(0),
HID_LogicalMax(1),
HID_ReportCount(4),
HID_ReportSize(1),
HID_Input(HID_Data | HID_Variable | HID_Absolute),
HID_ReportCount(1),
HID_ReportSize(4),
HID_Input(HID_Constant),
HID_UsageMin(1),
HID_UsageMax(4),
HID_LogicalMin(0),
HID_LogicalMax(255),
HID_ReportCount(4),
HID_ReportSize(4),
HID_Input(HID_Data | HID_Variable | HID_Absolute),
HID_UsageMin(1),
HID_UsageMax(5),
HID_LogicalMin(0),
HID_LogicalMax(1),
HID_ReportCount(5),
HID_ReportSize(1),
HID_Output(HID_Data | HID_Variable | HID_Absolute),
HID_ReportCount(1),
HID_ReportSize(3),
HID_Output(HID_Constant),
HID_UsageMin(1),
HID_UsageMax(3),
HID_LogicalMin(0),
HID_LogicalMax(255),
HID_ReportCount(3),
HID_ReportSize(3),
HID_Output(HID_Data | HID_Variable | HID_Absolute),
HID_EndCollection,
};


The code above is intended to define an input report to the host with 4 variable bitfields followed by 4 constant bitfields followed by 4 bytes of unsigned data for a total of 5 bytes from NXP to USB host.  Conversely, the output from host to NXP should have 5 variable bitfields followed by three constant bitfields followed by 3 unsigned bytes for a total of 4 bytes.

In addition to modifying the descriptor code above, I did the following changes to try to adapt the "usbhid" example to my goal:
1.  Added defines for the number of bytes in an InReport and OutReport.
2.  Modified definition of InReport and OutReport variables to be byte arrays instead of single bytes.
3.  Modified code that copies from InReport variable to output buffer to copy the additional bytes.
4.  Modified the code that copies data from the buffer from the host into the OutReport variable to copy the extra bytes.
5.  Modified the GetInReport Function to simply increment a static counter each time it is called.
6.  Modified the SetOutReport to copy its contents into the InReport structure.  The hope was to simply have all bytes from host echoed back to the host with the addition of the one extra byte of incrementing counter mentioned above.

I think maybe I am failing to correctly modify the "SetupPacket" but I can't figure out where I would do that.  My code is attached in a zip, it is just a minimally modified version of the "usbhid" example for LPC1343.

Any help or guidance appreciated.
David
0 Kudos
Reply
1 Reply

675 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by deBoogle on Tue May 21 04:48:01 MST 2013
Hi There,

I am currently attempting to do the same thing and seem to be hitting the same wall.

Did you get your problem solved and if so what advice can you offer a USB newbie?

Thanks in advance!
D
0 Kudos
Reply