Skip to content

Add a USB mass storage disconnected callback #142

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 1 commit into from
Oct 2, 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
9 changes: 8 additions & 1 deletion libraries/UsbHostMsd/UsbHostMsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern "C" uint8_t usb_host_msd_get_lun_num();
extern "C" uint32_t usb_host_msd_get_num_of_blocks(uint8_t lun);
extern "C" uint32_t usb_host_msd_get_block_size(uint8_t lun);
extern "C" void usb_host_msd_attach_mnt_cbk(void (*fnc)(void));

extern "C" void usb_host_msd_attach_umnt_cbk(void (*fnc)(void));

/* -------------------------------------------------------------------------- */
/* CONSTRUCTOR */
Expand Down Expand Up @@ -224,4 +224,11 @@ const char *USBHostMSD::get_type() const {

bool USBHostMSD::attach_detected_callback(void (*cbk)()) {
usb_host_msd_attach_mnt_cbk(cbk);
return true;
}

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

1 change: 1 addition & 0 deletions libraries/UsbHostMsd/UsbHostMsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class USBHostMSD : public BlockDevice {
virtual bool select_lun(uint8_t lun);
virtual uint8_t get_lun_num();
bool attach_detected_callback(void (*cbk)());
bool attach_removed_callback(void (*cbk)());

private:
uint8_t get_lun();
Expand Down
9 changes: 9 additions & 0 deletions libraries/UsbHostMsd/tu_msc.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,16 @@ uint32_t usb_host_msd_get_block_size(uint8_t lun) {
}

static void (*mount_fnc)(void) = NULL;
static void (*unmount_fnc)(void) = NULL;

void usb_host_msd_attach_mnt_cbk(void (*fnc)(void)) {
mount_fnc = fnc;
}

void usb_host_msd_attach_umnt_cbk(void (*fnc)(void)) {
unmount_fnc = fnc;
}

//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
Expand Down Expand Up @@ -167,6 +172,10 @@ void tuh_msc_umount_cb(uint8_t dev_addr) {

device_address = -1;

if (unmount_fnc != NULL) {
unmount_fnc();
}

// uint8_t phy_disk = dev_addr-1;
//
// f_mount(phy_disk, NULL); // unmount disk
Expand Down