Skip to content

Commit fbb0c56

Browse files
authored
Merge pull request #142 from alrvid/main
Add a USB mass storage disconnected callback
2 parents d3536cc + 80b93bf commit fbb0c56

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

Diff for: libraries/UsbHostMsd/UsbHostMsd.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extern "C" uint8_t usb_host_msd_get_lun_num();
2626
extern "C" uint32_t usb_host_msd_get_num_of_blocks(uint8_t lun);
2727
extern "C" uint32_t usb_host_msd_get_block_size(uint8_t lun);
2828
extern "C" void usb_host_msd_attach_mnt_cbk(void (*fnc)(void));
29-
29+
extern "C" void usb_host_msd_attach_umnt_cbk(void (*fnc)(void));
3030

3131
/* -------------------------------------------------------------------------- */
3232
/* CONSTRUCTOR */
@@ -224,4 +224,11 @@ const char *USBHostMSD::get_type() const {
224224

225225
bool USBHostMSD::attach_detected_callback(void (*cbk)()) {
226226
usb_host_msd_attach_mnt_cbk(cbk);
227+
return true;
228+
}
229+
230+
bool USBHostMSD::attach_removed_callback(void (*cbk)()) {
231+
usb_host_msd_attach_umnt_cbk(cbk);
232+
return true;
227233
}
234+

Diff for: libraries/UsbHostMsd/UsbHostMsd.h

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class USBHostMSD : public BlockDevice {
4747
virtual bool select_lun(uint8_t lun);
4848
virtual uint8_t get_lun_num();
4949
bool attach_detected_callback(void (*cbk)());
50+
bool attach_removed_callback(void (*cbk)());
5051

5152
private:
5253
uint8_t get_lun();

Diff for: libraries/UsbHostMsd/tu_msc.c

+9
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,16 @@ uint32_t usb_host_msd_get_block_size(uint8_t lun) {
6868
}
6969

7070
static void (*mount_fnc)(void) = NULL;
71+
static void (*unmount_fnc)(void) = NULL;
7172

7273
void usb_host_msd_attach_mnt_cbk(void (*fnc)(void)) {
7374
mount_fnc = fnc;
7475
}
7576

77+
void usb_host_msd_attach_umnt_cbk(void (*fnc)(void)) {
78+
unmount_fnc = fnc;
79+
}
80+
7681
//--------------------------------------------------------------------+
7782
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
7883
//--------------------------------------------------------------------+
@@ -167,6 +172,10 @@ void tuh_msc_umount_cb(uint8_t dev_addr) {
167172

168173
device_address = -1;
169174

175+
if (unmount_fnc != NULL) {
176+
unmount_fnc();
177+
}
178+
170179
// uint8_t phy_disk = dev_addr-1;
171180
//
172181
// f_mount(phy_disk, NULL); // unmount disk

0 commit comments

Comments
 (0)