Abstract:
The present invention discloses a method for improving the communication of the Human Interface Device (HID), by simulating the bulk endpoint into the interrupt endpoint, to increase the communication speed of the Universal Serial Bus (USB) device, which is designed to work as an HID.

Description:
FIELD OF THE INVENTION  
       [0001]     The present invention relates to a method for improving the communication of the human interface device.  
       BACKGROUND OF THE INVENTION  
       [0002]     Generally, a USB device works with a driver, which provides a data transfer channel from the application to the device. However, to develop an error-free driver is very complicated. Any problem with the driver might lead to a system crash. For this reason, the operating system is designed to provide built-in drivers to some typical USB devices, such as the Human Interface Device (HID) like mouse and keyboard. Therefore, if the non-typical USB devices, such as the USB Key, are designed as a human interface device, they can directly utilize the built-in drivers of the operating system, eliminating the complexity of design of drivers and related risks.  
         [0003]     For the HID driver of the operating system, there are two approaches to access to the hardware device: Control Transfers and Interrupt Transfers, as defined by the USB Specification. Both Control Transfers and Interrupt Transfers are designed to best support trickle data transfers. The USB device as a human interface device cannot conduct bulk and high-speed data communication. When working on bulk data, the USB device as a human interface device cannot perform high-speed communication because the capacity of Interrupt Endpoint Buffers is not large enough.  
         [0004]     In the USB Specification, Bulk Transfers are defined for bulk and high-speed data communication. Generally, the capacity of the buffers for Bulk Transfers is relatively large in the chip used by the USB device. But the HID class device cannot use the communication means of Bulk Transfers.  
         [0005]     The chip with a USB interface has circuitries for various data transfer means inside. Each data transfer means corresponds to a circuitry, which is also referred to as “endpoint”. The endpoint that supports control transfers is named as the control endpoint. The endpoint that supports interrupt transfers is named as the interrupt endpoint. The endpoint that supports bulk transfers is named as the bulk endpoint.  
         [0006]     When connected to a host, the USB device sends a set of data to the host. The set of data declares the type of the device and the supported data transfer means. The host recognizes the USB device through the descriptor (i.e. the set of data). Each descriptor contains the information of a device or one of its components. All USB peripherals must respond to the request for standard USB descriptors. The host requests the descriptor to the device through control transfers during enumeration.  
         [0007]     The descriptors referenced by the present invention are: 
        The interface descriptor. It defines an interface between a USB device and a host, and indicates if the device is a human interface device and has any endpoint other than the control endpoint etc. The endpoint descriptor. It is required only if the device has any endpoint other than the control endpoint. It indicates the type of the endpoint, the address of the endpoint in the chip, the size of the endpoint&#39;s buffer, and the interval of the host&#39;s access to the endpoint.     The HID class descriptor. It is required only if the device is defined as a human interface device. It indicates the version number of the USB protocol supported by the device. It also indicates that if the device has private descriptors and the feature limitation to the private descriptors.     The report descriptor. It is required only if the device is defined as a human interface device. It indicates how the data is to be organized during the communication between the device and the host.        
 
       SUMMARY OF THE INVENTION  
       [0011]     When the USB device is designed to work as a human interface device, to exchange data in a higher speed between the device and the host, the present invention provides a method that uses the bulk endpoint to simulate the interrupt endpoint making use of the larger buffer of the bulk endpoint to improve the communication speed of bulk of data.  
         [0012]     The present invention provides a method for improving the communication of the human interface device, comprising the steps of: 
        1) setting Number of Endpoints to a value that is equal to or greater than 2 and setting Device Category to 3 in the interface descriptor;     2) reporting at least one interrupt input endpoint and at least one interrupt output endpoint to the host, the address of the interrupt input endpoint is set to the address of the bulk input endpoint in the USB device, and the address of the interrupt output endpoint is set to the address of the bulk output endpoint in the USB device;     3) specifying that the USB device has a report descriptor in the HID class descriptor;     4) specifying an input report and an output report in the report descriptor, the size of the input report and the output report is greater than or equal to the capacity of the buffer of the bulk endpoint;     5) receiving an instruction from the host through the bulk output endpoint by the USB device and returning the result from the USB device to the host through the bulk input endpoint, the size of the data transferred between the USB device and the host each time is equal to that of the corresponding report.        
 
         [0018]     In above method, the process of receiving and handling the instruction and data from the host comprises the steps of: 
        1) determining if the bulk endpoint is to transfer data;     2) reorganizing the data by the USB device when the bulk endpoint is to transfer the data;     3) executing the instruction by the USB device;     4) returning the result and status from the bulk endpoint.        
 
         [0023]     The present invention provides a method to simulate the bulk endpoint to the interrupt endpoint to significantly increase the communication speed of the USB device which is designed to work as a human interface device when transferring bulk of data. 
     
    
     BRIEF DESCRIPTION OF THE DRAWINGS  
       [0024]     The present invention may be further understood from the following description in conjunction with the appended drawings. In the drawings:  
         [0025]      FIG. 1  is a schematic of receiving the data and instruction from the host to the device;  
         [0026]      FIG. 2  is a schematic of handling the instruction and returning the result from the device to the host. 
     
    
     DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS  
       [0027]     The present invention is further described with the embodiments in conjunction with the appended drawings below.  
         [0028]     The method of the present invention involves changes to the setting of descriptors and data organizing.  
         [0029]     1. Setting of Descriptors  
         [0000]     1.1 The Interface Descriptor  
         [0030]     The present invention involves the setting of descriptors that set Number of Endpoints to a value that is equal to or greater than 2; and set Device Category to 3, which indicates that the device is an HID class device.  
         [0000]     1.2 The Endpoint Descriptor  
         [0031]     It is necessary to report two interrupt endpoints to the host for the present invention. To do so, two endpoint descriptors are added, which correspond to the two interrupt endpoints. The two interrupt endpoints are the interrupt input endpoint and the interrupt output endpoint separately. Set Endpoint Type to 3 to indicate the endpoint is an interrupt endpoint. Set Endpoint Numbers to the values that are identical to those of the bulk input and bulk output endpoints in the chip of the USB device. Set Buffer Sizes for the interrupt input endpoint and the interrupt output endpoint both to 64 bytes. Set the interval of the host&#39;s access to the interrupt input endpoint and the interrupt output endpoint to 1 ms.  
         [0032]     For various embodiments, the number of the interrupt endpoints may be more than 2. But there must be at least one interrupt input endpoint and at least one interrupt output endpoint.  
         [0000]     1.3 The HID Class Descriptor  
         [0033]     When setting the HID class descriptor, specify that the HID spec v1.10 or above is supported, and the device has a report descriptor, whose size is 58 bytes.  
         [0000]     1.4 The HID Report Descriptor  
         [0034]     Define an input report which is transmitted from the device to the host and an output report which is transmitted from the host to the device. The size of the input report and the output report is equal to or greater than the capacity of the buffer of the bulk endpoint.  
         [0035]     2. Data Organizing  
         [0036]     The data transferred between the USB device and the host each time is 64 bytes (equal to the size of the report). If the data size is more than 64 bytes, the data is divided into a series of data blocks, which have a size of 64 bytes, before its transmission. The receiver then combines the data blocks to generate complete data.  
         [0037]     In the 64 bytes of each report, the first 6 bytes are used to indicate the relationship between the report and the integral data block. The remaining 58 bytes are meaningful data. In the first 6 bytes, the first two indicate the size of all data. The 3 rd  ad 4 th  bytes indicate the size of applicable data of this report. The last two bytes indicate the offset location of the report data in all data.  
         [0038]     Referring to  FIG. 1 , the instruction and data are received as follows:  
         [0039]     Step  101 , the USB device is powered up;  
         [0040]     Step  102 , the USB device initializes;  
         [0041]     Step  103 , determine if the control endpoint has any request to send; if so, go to Step  104 ; else, go to Step  105 ;  
         [0042]     Step  104 , determine if the report is an HID report; if so, go to Step  106  to reorganize the instruction for executing in Step  107 , then go to Step  111  to return the result and status by the control endpoint in Step  111 , and finally go to Step  103  to wait for the control endpoint to send request again; else, go to Step  108 ;  
         [0043]     Step  105 , determine if the bulk endpoint has data to send; if so, go to Step  106  to reorganize the instruction for executing in Step  107 , then go to Step  111  to return the result and status by the bulk endpoint, and finally go to Step  103  to wait for the control endpoint to send request again; else, go to Step  111  to return the result and status, then go to Step  103  to wait for the control endpoint to send request again;  
         [0044]     Step  108 , determine if the request sent from the host is a standard USB request; if so, go to Step  109  to process the request; else, go to Step  110  to return request not supported message;  
         [0045]     After Step  109  and  110  executed, go to Step  111  to return the result and status, and finally go to Step  103  to wait for the control endpoint to send request.  
         [0046]     In above procedure, Step  103  and  104  are provided only for compatible considerations for the USB device. These steps are optional in practice.  
         [0047]     Also in practice, if the USB device communication does not refer to bulk data transfer, the Step  106  could be ignored, the next step is still applicable.  
         [0048]     Referring to  FIG. 2 , the instruction is executed and the result is returned as follows:  
         [0049]     Step  201 , the USB device goes into instruction reorganizing and executing status;  
         [0050]     Step  202 , the USB device obtains data offset and size;  
         [0051]     Step  203 , the USB device copies data to the buffer of the bulk endpoint in light of data offset and size;  
         [0052]     Step  204 , the USB device obtains the total size of the data;  
         [0053]     Step  205 , the USB device determines if the sum of the offset and the data size is equal to the total data size; if not, go to Step  206  to exit from instruction reorganizing and executing status, and process the next report; else, go to Step  207 ;  
         [0054]     Step  207 , the USB device determines if the data in the buffer of the bulk endpoint is valid; if not, go to Step  209  to set a command error status and to Step  210 ; else, go to Step  208 ;  
         [0055]     Step  208 , the USB device executes the instruction, such as Select a File;  
         [0056]     Step  210 , determine if the instruction is sent from the bulk endpoint; if so, return the result and status from the bulk endpoint in Step  212 ; else, return the result and status from the control endpoint in Step  211 ;  
         [0057]     Step  213 , exit and go into another command cycle.  
         [0058]     It will be appreciated by those of ordinary skill in the art that the invention can be embodied in other specific forms without departing from the spirit or essential character thereof. The presently disclosed embodiments are therefore considered in all respects to be illustrative and not restrictive. The scope of the invention is indicated by the appended claims rather than the foregoing description, and all changes which come within the meaning and range of equivalents thereof are intended to be embraced therein.