![Image](http://www.matrixmultimedia.com/images/Article_NoStudentPic.png)
One of the most portable types of USB device is a Human Interface Device, as it does not require a driver file to connect and interface to your computer. The computer driver information for a HID device is actually stored inside the memory of the USB device. This means that your device will run without modification on pretty much any of today's computer systems: PC, MAC and even Linux. Though the PC side of the software will need porting to the various operating systems.
The HID descriptor is the piece of code that controls how the computer sees the embedded USB device so it is important to get this correct. Using the custom descriptor property of the HID component I pasted in the following section of code.
//HID Descriptor, 8 bytes Tx, 8 bytes Rx
0x06,0xA0,0xFF, //Usage Page - Vendor Defined
0x09,0x01, //Usage Vendor Defined
0xA1,0x01, //Collection - Application
0x09,0x02, //Usage Vendor Defined
0xA1,0x00, //Collection - Linked
0x06,0xA1,0xFF, //Usage Page - Buttons
0x09,0x03, //Usage Vendor Defined
0x09,0x04, //Usage Vendor Defined
0x15,0x00, //Logical Minimum - 0
0x26,0xFF,0x00, //Logical Maximum - 255
0x35,0x00, //Physical Minimum - 0
0x45,0xFF, //Physical Maximum - 255
0x75,0x08, //Report Size – 8bits
0x95,0x08, //Report Count – 8fields
0x81,0x02, //Input Data Variable Absolute
0x09,0x05, //Usage Vendor Defined
0x09,0x06, //Usage Vendor Defined
0x15,0x00, //Logical Minimum - 0
0x26,0xFF,0x00, //Logical Maximum - 255
0x35,0x00, //Physical Minimum - 0
0x45,0xFF, //Physical Maximum - 255
0x75,0x08, //Report Size 8bits
0x95,0x08, //Report Count 8fields
0x91,0x02, //Output Data Variable Absolute
0xC0, //End Collection
0xC0 //End Collection
The first highlighted line configures the amount of data going from the PC to the embedded USB device.
The second highlighted line configures the amount of data going back from the Embedded USB device to the PC.
The value 0x08 specifies that 8 bytes will be transferred. If you wish to change this then you will also need to change the HID Options property page to match.
Here is an example that will send and receive 8 bytes to match the above HID descriptor.
Also shown in the HID options property page is the rate of throughput of the data. At the moment the device is configured to throughput 8 bytes of data in and out of the system at a maximum rate of 100Hz. This can be changed by editing the interrupt periods inside the USB HID properties. Remember that this sets the maximum throughput for your application but your application can actually run with a much lower data throughput with no ill effects. If you try and go above the data throughput then the PC will terminate communications with the device and stop further communications from taking place. So if you are having problems getting your application to work once the device has appeared in your device manager then this could be the cause.
Now we have configured the device to run as a generic HID it is possible to use a purpose built application to talk to your device. There are a number of example applications provided at the following link in the Host Applications section.
http://www.lvr.com/hidpage.htm
The PC demo files supplied with this article were generated using the generic HID VB code and were compiled using the free trial version of VB 2008 Express edition. Other examples available from the link above include: VB.net, Visual C#, VB6, Visual C++ 6. All of the examples on the main HID page are using Microsoft compilers so if you have your own favourite compiler then there is bound to be HID examples available for that via a Google search.
The example Flowcode file simply takes the value from the first data byte and outputs to PortB. Once it has done this it copies its incoming buffer to its outgoing buffer and echos the data back to the PC.