Step 4: Device enumeration
To make things easy I have written some simple firmware to drive the device, you can use this to get going and also as a basis for understanding how the firmware operates.
Once you've got your first device running you will find it much easier to understand how you can adapt it for more complex applications.
The first is USB device enumeration - this complex sounding feat is in fact the initial communication with the USB host (your PC) when the device tells the host what it is and how it wishes to communicate.
USB communication is performed using 'endpoints' which send information either to the host or to the device. As well as setting up the communication channels the device must also pass its device name and two other important values: the VID and PID.
The VID is the Vendor ID and identifies the manufacturer of the device. To get your own VID you need to pay a thousand bucks or so to the USB standards body.
In this example we will use Microchip's VID to save the expense. If you are serious about producing and selling devices you will need to register one of your own.
The PID is the Product ID. Together with the VID they form a unique identifier for your device. When your device first enumerates Windows will store the VID and PID combination for the device; this is true even if you use a generic driver like the HID since it cuts down on the amount of time Windows needs to get your device ready.
This is important because, if you decide to change your device's enumeration information (add more endpoints, etc.), you will also need to at least change the PID before reconnecting otherwise you will get 'Device not started' errors even if you code is flawless (from experience I've noticed that Linux is not quite as fussy and tends not to complain if you keep the same VID/PID combination).