Allow USBDevice::connect() to be non-blocking.

It is required if USB is not the primary use of the device (eg: use
of USB mass storage to transfer pictures from the camera (the
device) to the host once in a while).
pull/169/head
Olivier Martin 2014-02-17 23:55:46 +00:00
parent b87dac9fce
commit f19f0b27c1
4 changed files with 13 additions and 8 deletions

View File

@ -703,12 +703,15 @@ bool USBDevice::configured(void)
return (device.state == CONFIGURED); return (device.state == CONFIGURED);
} }
void USBDevice::connect(void) void USBDevice::connect(bool blocking)
{ {
/* Connect device */ /* Connect device */
USBHAL::connect(); USBHAL::connect();
/* Block if not configured */
while (!configured()); if (blocking) {
/* Block if not configured */
while (!configured());
}
} }
void USBDevice::disconnect(void) void USBDevice::disconnect(void)

View File

@ -37,8 +37,10 @@ public:
/* /*
* Connect a device * Connect a device
*
* @param blocking: block if not configured
*/ */
void connect(void); void connect(bool blocking = true);
/* /*
* Disconnect a device * Disconnect a device

View File

@ -103,8 +103,7 @@ bool USBMSD::USBCallback_request(void) {
} }
bool USBMSD::connect() { bool USBMSD::connect(bool blocking) {
//disk initialization //disk initialization
if (disk_status() & NO_INIT) { if (disk_status() & NO_INIT) {
if (disk_initialize()) { if (disk_initialize()) {
@ -131,7 +130,7 @@ bool USBMSD::connect() {
} }
//connect the device //connect the device
USBDevice::connect(); USBDevice::connect(blocking);
return true; return true;
} }

View File

@ -70,9 +70,10 @@ public:
/** /**
* Connect the USB MSD device. Establish disk initialization before really connect the device. * Connect the USB MSD device. Establish disk initialization before really connect the device.
* *
* @param blocking if not configured
* @returns true if successful * @returns true if successful
*/ */
bool connect(); bool connect(bool blocking = true);
/** /**
* Disconnect the USB MSD device. * Disconnect the USB MSD device.