Skip to content

Add callback functionality for thumb drive disconnects #27

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 2 commits into from
Sep 27, 2023
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
6 changes: 6 additions & 0 deletions src/USBHost/USBHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ USBHost * USBHost::instHost = NULL;
#define MIN(a, b) ((a > b) ? b : a)

extern void (*mount_fnc)(void);
extern void (*unmount_fnc)(void);

/**
* How interrupts are processed:
Expand Down Expand Up @@ -256,6 +257,11 @@ void USBHost::usb_process()

} while(0);

// Call the device disconnected callback if registered
if (nullptr != unmount_fnc) {
unmount_fnc();
}

break;

// a td has been processed
Expand Down
6 changes: 6 additions & 0 deletions src/USBHostMSD/USBHostMSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define BO_MASS_STORAGE_RESET (0xFF)

void (*mount_fnc)(void) = nullptr;
void (*unmount_fnc)(void) = nullptr;

USBHostMSD::USBHostMSD()
{
Expand Down Expand Up @@ -442,4 +443,9 @@ bool USBHostMSD::attach_detected_callback(void (*cbk)()) {
return true;
}

bool USBHostMSD::attach_removed_callback(void (*cbk)()) {
unmount_fnc = cbk;
return true;
}

#endif
2 changes: 1 addition & 1 deletion src/USBHostMSD/USBHostMSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class USBHostMSD : public IUSBEnumerator, public mbed::BlockDevice
virtual mbed::bd_size_t size() const;
virtual const char *get_type() const;
bool attach_detected_callback(void (*cbk)());

bool attach_removed_callback(void (*cbk)());

protected:
//From IUSBEnumerator
Expand Down