Page 1 of 1

handling physical disconnection and reconnection

Posted: Fri May 01, 2009 4:54 am
by thelorax
I've got a device on a battery, and I've finally managed to wrap my head around most of the custom class api.
Right now I'm trying to find any information on handling a physical disconnection from the usb port of a computer. Is there a way the device can know if it's plugged in? How can the device know when to call usb initialization functions? Is it possible to stop calling usbPoll when the device is not connected?
I was thinking I could trigger an interrupt on connection and disconnection and reinitialize and re-enumerate the device there, just like the samples for when the device is just turning on.
Is there a better way?

Thanks for any pointers,
Chris.

Re: handling physical disconnection and reconnection

Posted: Mon May 04, 2009 9:34 pm
by christian
You don't need to re-initialize or re-enumerate. The driver handles this automatically.

There are two ways to detect disconnect:
(1) Add hardware to check for USB power, or
(2) Check for USB frame pulses.

For (2), see e.g. Henrik's USB2LPT:
http://www-user.tu-chemnitz.de/~heha/ba ... -15.htm.en

Please note that the frame pulses will also go away when the host goes to sleep. It may be desired to go into battery mode in this case, or it may not be desired.