USB device stack (USBDevice::connect non-blocking)
Fork of USBDevice by
Revision 18:a0db8d2001f6, committed 2014-02-15
- Comitter:
- Olivier
- Date:
- Sat Feb 15 12:34:43 2014 +0000
- Parent:
- 17:bbd6dac92961
- Commit message:
- 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).
Changed in this revision
diff -r bbd6dac92961 -r a0db8d2001f6 USBDevice/USBDevice.cpp --- a/USBDevice/USBDevice.cpp Thu Jan 23 17:30:20 2014 +0000 +++ b/USBDevice/USBDevice.cpp Sat Feb 15 12:34:43 2014 +0000 @@ -703,12 +703,15 @@ 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 -r bbd6dac92961 -r a0db8d2001f6 USBDevice/USBDevice.h --- a/USBDevice/USBDevice.h Thu Jan 23 17:30:20 2014 +0000 +++ b/USBDevice/USBDevice.h Sat Feb 15 12:34:43 2014 +0000 @@ -37,8 +37,10 @@ /* * Connect a device + * + * @param blocking: block if not configured */ - void connect(void); + void connect(bool blocking = true); /* * Disconnect a device
diff -r bbd6dac92961 -r a0db8d2001f6 USBMSD/USBMSD.cpp --- a/USBMSD/USBMSD.cpp Thu Jan 23 17:30:20 2014 +0000 +++ b/USBMSD/USBMSD.cpp Sat Feb 15 12:34:43 2014 +0000 @@ -103,8 +103,7 @@ } -bool USBMSD::connect() { - +bool USBMSD::connect(bool blocking) { //disk initialization if (disk_status() & NO_INIT) { if (disk_initialize()) { @@ -131,7 +130,7 @@ } //connect the device - USBDevice::connect(); + USBDevice::connect(blocking); return true; }
diff -r bbd6dac92961 -r a0db8d2001f6 USBMSD/USBMSD.h --- a/USBMSD/USBMSD.h Thu Jan 23 17:30:20 2014 +0000 +++ b/USBMSD/USBMSD.h Sat Feb 15 12:34:43 2014 +0000 @@ -70,9 +70,10 @@ /** * 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.