Merge pull request #169 from oliviermartin/om/usb-device-connect-non-blocking

Allow USBDevice::connect() to be non-blocking
pull/173/head
Emilio Monti 2014-02-18 10:51:54 +00:00
commit 3c8f1c0c59
4 changed files with 13 additions and 8 deletions

View File

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

View File

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

View File

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

View File

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