 RE: USB HID IN and OUT report when noting to send/receive Tsuneo Chinzei "When the PC has noting to send I do not get an SAM7-uC USB interrupt for the Interrupt In Endpoint. However for the HID Interrupt Out Endpoint I get interrupts all the time." Isn't IN and OUT reversed? USB is host centric. Then, IN and OUT is named after the host side. For vendor specific HID implementation, the HID host sends interrupt OUT transaction to the device just when the host app sends out report using WriteFile. For interrupt IN transaction, HID PC device driver issues IN transaction periodically by itself. - The device driver issues IN transaction just after the device is enumerated, even when the host app is not running. - The input reports from the device are stored to the IN buffer on the device driver. This buffer is a cyclic one. ( see HidD_GetNumInputBuffers() ) - HID host app reads out input reports from this buffer. ie. the host app doesn't access to the device directly. For USB, device cannot send any data until the host requests it by IN transaction. Then, the PC device driver issues IN transaction periodically, regardless of the status on the device. This kind of IN transaction is called as "polling-IN" transaction. To handle this IN transaction, you have two options. a) Respond to it just when any change occurs on the device b) Always send some data, even if it is the same as the last one. b) is often applied in many USB examples, because the host app is simpler than a). However, you have to extract change from the data stream. For a) strategy, On the firmware: Load data to the interrupt IN EP when the data is generated on your firmware. Usually, data loading is done in a timer ISR or one of main loop tasks, in which new data is generated. Not in the endpoint ISR. You may ignore the hardware interrupt from the interrupt IN EP, or may use the interrupt just to know the EP is empty. On the host app: You have to apply asynchronous (OVERLAPPED) ReadFile(), because synchronous ReadFile() blocks the thread, until the device returns input report.
"if I reply a few times with some data and then stop to reply and then read the data from the host input buffer of the PC using the visual C++ V6 HID USB api it reports some error." Just ignore the error. I suppose your host app handles it properly using OVERLAPPED. And WaitForSingleObject() returns timeout error, when no input report.
"I believe I must answer the requests of the host by sending NACKs - but the question is how to do it?" Just leave the EP alone. When you don't load any data to the interrupt IN EP, the EP is empty, and the EP returns NAK to the next IN transaction from the host. The hardware interrupt from the IN EP means that the data on the EP has been sent to the host, and the EP is empty now. It's same as UART TX. It NEVER means the arrival of host request to which your firmware has to respond immediately. Tsuneo |