When designing a USB device, first determine the category of the device, and then implement the Basic USB communication protocol and the category communication protocol of the device. For example, the USB flash disk belongs to the mass storage device. Therefore, in addition to the basic USB communication protocol, the UFI command specification in the large-capacity storage equipment specification must be implemented. Because Windows supports the mass storage protocol, the USB flash disk only needs to follow the mass storage protocol to organize data and process commands to exchange data with PCs.
The USB specification defines many device types, which are represented by different device category codes and interface category codes. The hid (Human Interface Device, Human Interface Device) device category code is 0x00, the interface category code is 0x03. The hid devices include keyboards, mice, and game poles. The mass storage device category code is also 0x00, the interface category code is 0x09. Mass Storage devices include floppy disks, hard disks, CDs, and flash disks. Others include displays, communication devices, and audio devices. In the USB specification, there is also a special Vendor Specific Class device, which is used by the vendor to customize the device type. Its Interface category code is 0xff. We can find a suitable device type.
The device mainly collects data and transmits the collected data to the PC end for processing. I will not detail the hardware implementation. This article focuses on the implementation of the lower computer software. Select the hid class for the device type, because this class does not require drivers. Windows comes with some common drivers. We only need to write firmware programs for communication, you can call the hid APIs to receive data. I will not use the upper computer here.