Skip to content

Commit a0e2532

Browse files
authored
Merge pull request #27 from alrvid/master
Add callback functionality for thumb drive disconnects
2 parents 02fcda8 + f8b3422 commit a0e2532

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/USBHost/USBHost.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ USBHost * USBHost::instHost = NULL;
3131
#define MIN(a, b) ((a > b) ? b : a)
3232

3333
extern void (*mount_fnc)(void);
34+
extern void (*unmount_fnc)(void);
3435

3536
/**
3637
* How interrupts are processed:
@@ -256,6 +257,11 @@ void USBHost::usb_process()
256257

257258
} while(0);
258259

260+
// Call the device disconnected callback if registered
261+
if (nullptr != unmount_fnc) {
262+
unmount_fnc();
263+
}
264+
259265
break;
260266

261267
// a td has been processed

src/USBHostMSD/USBHostMSD.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#define BO_MASS_STORAGE_RESET (0xFF)
3030

3131
void (*mount_fnc)(void) = nullptr;
32+
void (*unmount_fnc)(void) = nullptr;
3233

3334
USBHostMSD::USBHostMSD()
3435
{
@@ -442,4 +443,9 @@ bool USBHostMSD::attach_detected_callback(void (*cbk)()) {
442443
return true;
443444
}
444445

446+
bool USBHostMSD::attach_removed_callback(void (*cbk)()) {
447+
unmount_fnc = cbk;
448+
return true;
449+
}
450+
445451
#endif

src/USBHostMSD/USBHostMSD.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class USBHostMSD : public IUSBEnumerator, public mbed::BlockDevice
6565
virtual mbed::bd_size_t size() const;
6666
virtual const char *get_type() const;
6767
bool attach_detected_callback(void (*cbk)());
68-
68+
bool attach_removed_callback(void (*cbk)());
6969

7070
protected:
7171
//From IUSBEnumerator

0 commit comments

Comments
 (0)