Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SDFileSystem by
Revision 1:25f4ba436b81, committed 2014-07-30
- Comitter:
- neilt6
- Date:
- Wed Jul 30 15:36:56 2014 +0000
- Parent:
- 0:2a6d8a096edc
- Child:
- 2:eec1db773e7d
- Commit message:
- Added support for normally open card detect switches
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 Tue Jul 29 20:12:23 2014 +0000
+++ b/SDFileSystem.cpp Wed Jul 30 15:36:56 2014 +0000
@@ -19,7 +19,7 @@
#include "CRC7.h"
#include "CRC16.h"
-SDFileSystem::SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName cd, const char* name, int hz) : FATFileSystem(name), m_SPI(mosi, miso, sclk), m_CS(cs, 1), m_CD(cd)
+SDFileSystem::SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName cd, const char* name, SwitchType cdtype, int hz) : FATFileSystem(name), m_SPI(mosi, miso, sclk), m_CS(cs, 1), m_CD(cd), m_CD_ASSERT((int)cdtype)
{
//Initialize the member variables
m_SpiFreq = hz;
@@ -31,7 +31,10 @@
//Configure the card detect pin
m_CD.mode(PullUp);
- m_CD.fall(this, &SDFileSystem::checkSocket);
+ if (cdtype == SWITCH_NO)
+ m_CD.rise(this, &SDFileSystem::checkSocket);
+ else
+ m_CD.fall(this, &SDFileSystem::checkSocket);
}
SDFileSystem::CardType SDFileSystem::card_type()
@@ -347,7 +350,7 @@
void SDFileSystem::checkSocket()
{
//Check if a card is in the socket
- if (m_CD) {
+ if (m_CD == m_CD_ASSERT) {
//The socket is occupied, clear the STA_NODISK flag
m_Status &= ~STA_NODISK;
} else {
--- a/SDFileSystem.h Tue Jul 29 20:12:23 2014 +0000
+++ b/SDFileSystem.h Wed Jul 30 15:36:56 2014 +0000
@@ -64,6 +64,13 @@
class SDFileSystem : public FATFileSystem
{
public:
+ /** Represents the different card detect switch types
+ */
+ enum SwitchType {
+ SWITCH_NO = 0, /**< Switch shorts to GND when the socket is occupied (normally open) */
+ SWITCH_NC = 1 /**< Switch shorts to GND when the socket is empty (normally closed) */
+ };
+
/** Represents the different SD/MMC card types
*/
enum CardType {
@@ -80,11 +87,12 @@
* @param miso The SPI data in pin.
* @param sclk The SPI clock pin.
* @param cs The SPI chip select pin.
- * @param cd The active-high card detect pin.
+ * @param cd The card detect pin.
* @param name The name used to access the virtual filesystem.
+ * @param cdtype The type of card detect switch (defaults to SWITCH_NO).
* @param hz The SPI bus frequency (defaults to 1MHz).
*/
- SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName cd, const char* name, int hz = 1000000);
+ SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName cd, const char* name, SwitchType cdtype = SWITCH_NO, int hz = 1000000);
/** Get the detected SD/MMC card type
*
@@ -119,6 +127,7 @@
SPI m_SPI;
DigitalOut m_CS;
InterruptIn m_CD;
+ const int m_CD_ASSERT;
int m_SpiFreq;
int m_Status;
SDFileSystem::CardType m_CardType;
