|
From: Alan S. <st...@ro...> - 2009-07-26 14:27:02
|
On Sat, 25 Jul 2009, Frank Tkalcevic wrote: > I am having a problem with missing interrupt reports in my application. > > I am using libusb-1.0.2 to access a HID device (I'm testing with a Logitech > Dual Action gamepad). I can tell I am missing reports, because quite > regularly it appears a button is stuck down. If I look in my application > debug, I can see that the last report included the key down bit, but no > following report to say the key has been released. > > My original application used libusb-0.1.12 because I wanted it to work on > WIN32 too. The application created a background thread for the USB > processing. In this thread, I'd loop around forever calling > usb_interrupt_read with a 50msec timeout. If I received a message I'd process > it, then continue waiting for the next message. > > Because this wasn't working, I suspected I was receiving interrupts while I > wasn't waiting in a usb_interrupt_read. That can't happen. If you don't ask for a transfer (interrupt or other) then it won't occur. However what _could_ happen is that the device could drop or otherwise lose a report if your program doesn't transfer it in time. > I changed my code so that the USB > read thread only did the interrupt read, then put the message in a local > queue, minimising the time away from the interrupt read. This didn't help. > > Next change was to create multiple read threads on the same device. Still no > change. > > Then I upgraded to libusb-1.0.2. The initial port just used sync transfers. > Same problem. > > Next I changed my code to use async requests. It is written such that I can > submit multiple transfer requests, and I can run with multiple read threads. > Still no change. > > Help! I am doing something fundementally wrong, or is there something special > that needs to be done to read interrupt reports? Nothing special needs to be done. Maybe the device isn't sending the data in the first place. > I'm not sure how libusb works with interrupt reports. I've read some USB > documentation that says USB interrupt reports are only returned to the host > when polled for. That's true of all USB transfers, not just interrupt reports. > Is this handled by the host hardware, or is this in the > device driver? Is this initiated by libusb? It is handled partially in software and partially in hardware. The software submits requests for data transfers. The driver informs the hardware about these requests, and the hardware is responsible for polling the device until a reply is received or the transfer is cancelled. At least, that's how the USB controllers work on standard PCs. Other systems (embedded or system-on-a-chip) use simpler controllers where the polling and transfers have to be handled in more detail by the driver. Alan Stern |