Bläddra i källkod

Merge pull request #569 from ZuluSCSI/dev_fix_usb_msc_multilun

RP2040: Fix regression in USBMassStoragePresentImages
Alex Perez 6 månader sedan
förälder
incheckning
9b423cc7c5
1 ändrade filer med 24 tillägg och 4 borttagningar
  1. 24 4
      lib/ZuluSCSI_platform_RP2MCU/ZuluSCSI_platform_msc.cpp

+ 24 - 4
lib/ZuluSCSI_platform_RP2MCU/ZuluSCSI_platform_msc.cpp

@@ -60,6 +60,7 @@ static struct {
   uint8_t lun_count = 0;
   uint8_t unitReady = 0;
   uint8_t SDMode = 1;
+  uint8_t lun_count_prev_response = 0;
 } g_MSC;
 
 void platform_msc_lock_set(bool block)
@@ -209,6 +210,18 @@ void platform_enter_msc() {
 
   // MSC is ready for read/write
   g_MSC.unitReady = g_MSC.lun_count;
+
+  if (g_MSC.lun_count_prev_response != 0 &&
+      g_MSC.lun_count != g_MSC.lun_count_prev_response)
+  {
+    // Host has already queried us for the number of LUNs, but
+    // our response has now changed. We need to re-enumerate to
+    // update it.
+    g_MSC.lun_count_prev_response = 0;
+    tud_disconnect();
+    delay(250);
+    tud_connect();
+  }
 }
 
 /* perform any cleanup tasks for the MSC-specific functionality */
@@ -243,18 +256,25 @@ extern "C" void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8],
 extern "C" uint8_t tud_msc_get_maxlun_cb(void)
 {
   MSCScopedLock lock;
-  if (g_msc_initiator) return init_msc_get_maxlun_cb();
+  uint8_t result;
 
-  if (g_MSC.lun_count != 0)
+  if (g_msc_initiator)
   {
-    return g_MSC.lun_count; // number of LUNs supported
+    result = init_msc_get_maxlun_cb();
+  }
+  else if (g_MSC.lun_count != 0)
+  {
+    result = g_MSC.lun_count; // number of LUNs supported
   }
   else
   {
     // Returning 0 makes TU_VERIFY(maxlun); fail in tinyusb/src/class/msc/msc_device.c:378
     // This stalls the endpoint and causes an unnecessary enumeration delay on Windows.
-    return 1;
+    result = 1;
   }
+
+  g_MSC.lun_count_prev_response = result;
+  return result;
 }
 
 // return writable status