Paul's baseline branch
Fork of SDFileSystem by
Revision 16:c2c1f0b16380, committed 2015-01-05
- Comitter:
- neilt6
- Date:
- Mon Jan 05 18:43:29 2015 +0000
- Parent:
- 15:c9e938f6934f
- Child:
- 17:a47f74caa04e
- Commit message:
- Added support for no card detect switch
Changed in this revision
SDFileSystem.cpp | Show annotated file Show diff for this revision Revisions of this file |
SDFileSystem.h | Show annotated file Show diff for this revision Revisions of this file |
--- 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 {
--- a/SDFileSystem.h Mon Oct 27 17:02:05 2014 +0000 +++ b/SDFileSystem.h Mon Jan 05 18:43:29 2015 +0000 @@ -30,10 +30,13 @@ * #include "SDFileSystem.h" * * //Create an SDFileSystem object - * SDFileSystem sd(p5, p6, p7, p20, "sd", p22, SDFileSystem::SWITCH_NEG_NO); + * SDFileSystem sd(p5, p6, p7, p20, "sd"); * * int main() * { + * //Mount the filesystem + * sd.mount(); + * * //Perform a write test * printf("\nWriting to SD card..."); * FILE *fp = fopen("/sd/sdtest.txt", "w"); @@ -58,6 +61,9 @@ * } else { * printf("failed!\n"); * } + * + * //Unmount the filesystem + * sd.unmount(); * } * @endcode */ @@ -67,6 +73,7 @@ /** Represents the different card detect switch types */ enum SwitchType { + SWITCH_NONE, /**< No card detect switch (assumes socket is always occupied) */ SWITCH_POS_NO, /**< Switch shorts to VDD when the socket is occupied (positive logic, normally open) */ SWITCH_POS_NC, /**< Switch shorts to VDD when the socket is empty (positive logic, normally closed) */ SWITCH_NEG_NO, /**< Switch shorts to GND when the socket is occupied (negative logic, normally open) */ @@ -94,7 +101,7 @@ * @param cdtype The type of card detect switch. * @param hz The SPI bus frequency (defaults to 1MHz). */ - SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name, PinName cd, SwitchType cdtype, int hz = 1000000); + SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name, PinName cd = NC, SwitchType cdtype = SWITCH_NONE, int hz = 1000000); /** Get the detected SD/MMC card type *