SD for ECE 4180
Fork of SDFileSystem by
Revision 4:9b2701146950, committed 2016-03-14
- Comitter:
- jtgt21
- Date:
- Mon Mar 14 17:17:08 2016 +0000
- Parent:
- 2:c8f66dc765d4
- Commit message:
- commited
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 Thu Nov 29 10:56:21 2012 +0000 +++ b/SDFileSystem.cpp Mon Mar 14 17:17:08 2016 +0000 @@ -113,15 +113,17 @@ * +------+---------+---------+- - - -+---------+-----------+----------+ */ #include "SDFileSystem.h" +#include "mbed.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) @@ -182,6 +184,14 @@ return SDCARD_FAIL; } +bool SDFileSystem::SD_inserted() +{ + if(_cd) { + return(true); + } + else + {return(false);} +} int SDFileSystem::initialise_card_v2() { for (int i = 0; i < SD_COMMAND_TIMEOUT; i++) { wait_ms(50);
--- a/SDFileSystem.h Thu Nov 29 10:56:21 2012 +0000 +++ b/SDFileSystem.h Mon Mar 14 17:17:08 2016 +0000 @@ -51,13 +51,15 @@ * @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(); + virtual bool SD_inserted(); + protected: @@ -68,13 +70,13 @@ int initialise_card(); int initialise_card_v1(); int initialise_card_v2(); - int _read(uint8_t * buffer, uint32_t length); int _write(const uint8_t *buffer, uint32_t length); uint64_t _sd_sectors(); uint64_t _sectors; SPI _spi; + DigitalIn _cd; DigitalOut _cs; int cdv; };