From ff936a5f9292c01141937a04130a699592eb92af Mon Sep 17 00:00:00 2001 From: Marcio Teixeira Date: Wed, 28 Mar 2018 14:40:03 -0600 Subject: [PATCH] Added code to release USB id on CLCD. --- Marlin/usb-flashdrive/Fake_Sd2Card_impl.h | 9 ++++++++- Marlin/usb-flashdrive/lib/UsbCore.h | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Marlin/usb-flashdrive/Fake_Sd2Card_impl.h b/Marlin/usb-flashdrive/Fake_Sd2Card_impl.h index 81ea28bfd..ab9bce697 100644 --- a/Marlin/usb-flashdrive/Fake_Sd2Card_impl.h +++ b/Marlin/usb-flashdrive/Fake_Sd2Card_impl.h @@ -93,8 +93,15 @@ bool Sd2Card::usbHostReady() { // Marlin will call this to learn whether an SD card is inserted. bool Sd2Card::isInserted() { if(usbHostReady()) { + const uint8_t lastUsbTaskState = usb.getUsbTaskState(); usb.Task(); - return usb.getUsbTaskState() == USB_STATE_RUNNING; + const uint8_t newUsbTaskState = usb.getUsbTaskState(); + if(lastUsbTaskState == USB_STATE_RUNNING && newUsbTaskState != USB_STATE_RUNNING) { + // the user pulled the flash drive. Make sure the bulk storage driver releases the address + SERIAL_ECHOLNPGM("Drive removed\n"); + bulk.Release(); + } + return newUsbTaskState == USB_STATE_RUNNING; } } diff --git a/Marlin/usb-flashdrive/lib/UsbCore.h b/Marlin/usb-flashdrive/lib/UsbCore.h index c3f8e6c34..88569fc22 100644 --- a/Marlin/usb-flashdrive/lib/UsbCore.h +++ b/Marlin/usb-flashdrive/lib/UsbCore.h @@ -94,7 +94,7 @@ typedef MAX3421e MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega #define USB_RETRY_LIMIT 3 // 3 retry limit for a transfer #define USB_SETTLE_DELAY 200 //settle delay in milliseconds -#define USB_NUMDEVICES 16 //number of USB devices +#define USB_NUMDEVICES 2 //number of USB devices (changed by marcio@alephobjects.com) //#define HUB_MAX_HUBS 7 // maximum number of hubs that can be attached to the host controller #define HUB_PORT_RESET_DELAY 20 // hub port reset delay 10 ms recomended, can be up to 20 ms