SD card Reader with SD card detect
Fork of SDFileSystem by
Revision 3:2cf87e7f54e7, committed 2015-04-27
- Comitter:
- anevil14
- Date:
- Mon Apr 27 04:08:38 2015 +0000
- Parent:
- 2:c8f66dc765d4
- Commit message:
- sd card reader with sd card detect;
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 |
diff -r c8f66dc765d4 -r 2cf87e7f54e7 SDFileSystem.cpp --- a/SDFileSystem.cpp Thu Nov 29 10:56:21 2012 +0000 +++ b/SDFileSystem.cpp Mon Apr 27 04:08:38 2015 +0000 @@ -115,13 +115,15 @@ #include "SDFileSystem.h" #include "mbed_debug.h" + #define SD_COMMAND_TIMEOUT 5000 #define SD_DBG 0 -SDFileSystem::SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name) : - FATFileSystem(name), _spi(mosi, miso, sclk), _cs(cs) { +SDFileSystem::SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName cd, const char* name) : + FATFileSystem(name), _spi(mosi, miso, sclk), _cs(cs), _cd(cd){ _cs = 1; + _cd.mode(PullUp); } #define R1_IDLE_STATE (1 << 0) @@ -198,7 +200,7 @@ debug("Timeout waiting for v2.x card\n"); return SDCARD_FAIL; } - + int SDFileSystem::disk_initialize() { int i = initialise_card(); debug_if(SD_DBG, "init card = %d\n", i); @@ -348,7 +350,17 @@ _spi.write(0xFF); return -1; // timeout } - +bool SDFileSystem::SDInserted() +{ + if (_cd) + { + return true; + } + else + { + return false; + } +} int SDFileSystem::_read(uint8_t *buffer, uint32_t length) { _cs = 0;
diff -r c8f66dc765d4 -r 2cf87e7f54e7 SDFileSystem.h --- a/SDFileSystem.h Thu Nov 29 10:56:21 2012 +0000 +++ b/SDFileSystem.h Mon Apr 27 04:08:38 2015 +0000 @@ -51,14 +51,14 @@ * @param cs DigitalOut pin used as SD Card chip select * @param name The name used to access the virtual filesystem */ - SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name); + SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName cd, const char* name); virtual int disk_initialize(); virtual int disk_status(); virtual int disk_read(uint8_t * buffer, uint64_t block_number); virtual int disk_write(const uint8_t * buffer, uint64_t block_number); virtual int disk_sync(); virtual uint64_t disk_sectors(); - + bool SDInserted(); protected: int _cmd(int cmd, int arg); @@ -73,9 +73,9 @@ int _write(const uint8_t *buffer, uint32_t length); uint64_t _sd_sectors(); uint64_t _sectors; - SPI _spi; DigitalOut _cs; + DigitalIn _cd; int cdv; };