Skip to content

Commit d8b4ea1

Browse files
author
Alrik Vidstrom
committed
Add callback functionality for thumb drive disconnects
Adds callback functionality for thumb drive disconnects that works similarly to the connect callback functionality.
1 parent 02fcda8 commit d8b4ea1

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/USBHost/USBHost.cpp

Lines changed: 5 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,10 @@ void USBHost::usb_process()
256257

257258
} while(0);
258259

260+
if (nullptr != unmount_fnc) {
261+
unmount_fnc();
262+
}
263+
259264
break;
260265

261266
// 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)