Skip to content

Allow USBDevice::connect() to be non-blocking #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions libraries/USBDevice/USBDevice/USBDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion libraries/USBDevice/USBDevice/USBDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions libraries/USBDevice/USBMSD/USBMSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -131,7 +130,7 @@ bool USBMSD::connect() {
}

//connect the device
USBDevice::connect();
USBDevice::connect(blocking);
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion libraries/USBDevice/USBMSD/USBMSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down