Просмотр исходного кода

Use CMD13 status directly for detection of SD card presence

The old readOCR() method is still used for ZuluSCSI v1.0 that
uses SPI access for the SD card.
Petteri Aimonen 7 месяцев назад
Родитель
Сommit
55560bb805
1 измененных файлов с 12 добавлено и 3 удалено
  1. 12 3
      src/ZuluSCSI.cpp

+ 12 - 3
src/ZuluSCSI.cpp

@@ -916,6 +916,16 @@ static void firmware_update()
   root.close();
 }
 
+// Checks if SD card is still present
+static bool poll_sd_card()
+{
+#ifdef SD_USE_SDIO
+  return SD.card()->status() != 0 && SD.card()->errorCode() == 0;
+#else
+  uint32_t ocr;
+  return SD.card()->readOCR(&ocr);
+#endif
+}
 
 // Place all the setup code that requires the SD card to be initialized here
 // Which is pretty much everything after platform_init and and platform_late_init
@@ -1123,10 +1133,9 @@ extern "C" void zuluscsi_main_loop(void)
         (uint32_t)(millis() - sd_card_check_time) > SDCARD_POLL_INTERVAL)
     {
       sd_card_check_time = millis();
-      uint32_t ocr;
-      if (!SD.card()->readOCR(&ocr))
+      if (!poll_sd_card())
       {
-        if (!SD.card()->readOCR(&ocr))
+        if (!poll_sd_card())
         {
           g_sdcard_present = false;
           logmsg("SD card removed, trying to reinit");