diff --git a/libraries/USBDevice/USBDevice/USBDevice.cpp b/libraries/USBDevice/USBDevice/USBDevice.cpp index 7bdaf102647..ffe0b448b16 100644 --- a/libraries/USBDevice/USBDevice/USBDevice.cpp +++ b/libraries/USBDevice/USBDevice/USBDevice.cpp @@ -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) diff --git a/libraries/USBDevice/USBDevice/USBDevice.h b/libraries/USBDevice/USBDevice/USBDevice.h index 8457389df45..2035aaec38d 100644 --- a/libraries/USBDevice/USBDevice/USBDevice.h +++ b/libraries/USBDevice/USBDevice/USBDevice.h @@ -37,8 +37,10 @@ class USBDevice: public USBHAL /* * Connect a device + * + * @param blocking: block if not configured */ - void connect(void); + void connect(bool blocking = true); /* * Disconnect a device diff --git a/libraries/USBDevice/USBMSD/USBMSD.cpp b/libraries/USBDevice/USBMSD/USBMSD.cpp index 3bda241bdbb..74c17c1843c 100644 --- a/libraries/USBDevice/USBMSD/USBMSD.cpp +++ b/libraries/USBDevice/USBMSD/USBMSD.cpp @@ -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; } diff --git a/libraries/USBDevice/USBMSD/USBMSD.h b/libraries/USBDevice/USBMSD/USBMSD.h index ba852fa96e6..359ca7052fa 100644 --- a/libraries/USBDevice/USBMSD/USBMSD.h +++ b/libraries/USBDevice/USBMSD/USBMSD.h @@ -70,9 +70,10 @@ class USBMSD: public USBDevice { /** * 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.