A re-written SDFileSystem library with improved compatibility, CRC support, and card removal/replacement support.

Dependencies:   FATFileSystem

Dependents:   xadow_m0_SD_Hello roam_v1 roam_v2 Polytech_tours ... more

Revision:
16:c2c1f0b16380
Parent:
15:c9e938f6934f
Child:
17:a47f74caa04e
--- a/SDFileSystem.cpp	Mon Oct 27 17:02:05 2014 +0000
+++ b/SDFileSystem.cpp	Mon Jan 05 18:43:29 2015 +0000
@@ -48,16 +48,18 @@
         m_Cd.mode(PullUp);
         m_CdAssert = 0;
         m_Cd.rise(this, &SDFileSystem::onCardRemoval);
-    } else {
+    } else if (cdtype == SWITCH_NEG_NC) {
         m_Cd.mode(PullUp);
         m_CdAssert = 1;
         m_Cd.fall(this, &SDFileSystem::onCardRemoval);
+    } else {
+        m_CdAssert = -1;
     }
 }
 
 SDFileSystem::CardType SDFileSystem::card_type()
 {
-    //Check the card socket
+    //Check if there's a card in the socket
     checkSocket();
 
     //If a card is present but not initialized, initialize it
@@ -76,7 +78,7 @@
 
 void SDFileSystem::crc(bool enabled)
 {
-    //Check the card socket
+    //Check if there's a card in the socket
     checkSocket();
 
     //Just update the member variable if the card isn't initialized
@@ -397,14 +399,14 @@
 
 void SDFileSystem::onCardRemoval()
 {
-    //Check the card socket
+    //Check if there's a card in the socket
     checkSocket();
 }
 
 inline void SDFileSystem::checkSocket()
 {
-    //Check if a card is in the socket
-    if (m_Cd == m_CdAssert) {
+    //Use the card detect switch (if available) to determine if the socket is occupied
+    if (m_CdAssert == -1 || m_Cd == m_CdAssert) {
         //The socket is occupied, clear the STA_NODISK flag
         m_Status &= ~STA_NODISK;
     } else {