Skip to content

Commit 3c8f1c0

Browse files
committed
Merge pull request #169 from oliviermartin/om/usb-device-connect-non-blocking
Allow USBDevice::connect() to be non-blocking
2 parents 4d6bf98 + f19f0b2 commit 3c8f1c0

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

libraries/USBDevice/USBDevice/USBDevice.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,12 +703,15 @@ bool USBDevice::configured(void)
703703
return (device.state == CONFIGURED);
704704
}
705705

706-
void USBDevice::connect(void)
706+
void USBDevice::connect(bool blocking)
707707
{
708708
/* Connect device */
709709
USBHAL::connect();
710-
/* Block if not configured */
711-
while (!configured());
710+
711+
if (blocking) {
712+
/* Block if not configured */
713+
while (!configured());
714+
}
712715
}
713716

714717
void USBDevice::disconnect(void)

libraries/USBDevice/USBDevice/USBDevice.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ class USBDevice: public USBHAL
3737

3838
/*
3939
* Connect a device
40+
*
41+
* @param blocking: block if not configured
4042
*/
41-
void connect(void);
43+
void connect(bool blocking = true);
4244

4345
/*
4446
* Disconnect a device

libraries/USBDevice/USBMSD/USBMSD.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ bool USBMSD::USBCallback_request(void) {
103103
}
104104

105105

106-
bool USBMSD::connect() {
107-
106+
bool USBMSD::connect(bool blocking) {
108107
//disk initialization
109108
if (disk_status() & NO_INIT) {
110109
if (disk_initialize()) {
@@ -131,7 +130,7 @@ bool USBMSD::connect() {
131130
}
132131

133132
//connect the device
134-
USBDevice::connect();
133+
USBDevice::connect(blocking);
135134
return true;
136135
}
137136

libraries/USBDevice/USBMSD/USBMSD.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ class USBMSD: public USBDevice {
7070
/**
7171
* Connect the USB MSD device. Establish disk initialization before really connect the device.
7272
*
73+
* @param blocking if not configured
7374
* @returns true if successful
7475
*/
75-
bool connect();
76+
bool connect(bool blocking = true);
7677

7778
/**
7879
* Disconnect the USB MSD device.

0 commit comments

Comments
 (0)