From 6cbb866123927ea67380154eb4cd3fc6457427a6 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sun, 14 Nov 2010 11:48:21 -0500 Subject: [PATCH] Adding CS pin parameter to SD.begin(). Defaults to 4 (for Arduino Ethernet Shield). http://code.google.com/p/arduino/issues/detail?id=400 --- libraries/SD/SD.cpp | 10 ++++------ libraries/SD/SD.h | 7 +++++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/libraries/SD/SD.cpp b/libraries/SD/SD.cpp index e76ad7d7970..86bd5919a35 100644 --- a/libraries/SD/SD.cpp +++ b/libraries/SD/SD.cpp @@ -52,10 +52,6 @@ #include "SD.h" -// Use this to configure the chip select pin of the SD card. -#define SD_CARD_CHIP_SELECT_PIN 4 // For use with Arduino Ethernet Shield - - // Used by `getNextPathComponent` #define MAX_COMPONENT_LEN 12 // What is max length? #define PATH_COMPONENT_BUFFER_LEN MAX_COMPONENT_LEN+1 @@ -311,7 +307,9 @@ boolean callback_openPath(SdFile& parentDir, char *filePathComponent, /* Implementation of class used to create `SDCard` object. */ -void SDClass::begin() { + + +void SDClass::begin(uint8_t csPin) { /* Performs the initialisation required by the sdfatlib library. @@ -320,7 +318,7 @@ void SDClass::begin() { */ // TODO: Allow chip select pin to be supplied? - if (!(card.init(SPI_HALF_SPEED, SD_CARD_CHIP_SELECT_PIN) + if (!(card.init(SPI_HALF_SPEED, csPin) && volume.init(card) && root.openRoot(volume))) { while (true) { // Bail diff --git a/libraries/SD/SD.h b/libraries/SD/SD.h index bfce4239315..1c0479798ce 100644 --- a/libraries/SD/SD.h +++ b/libraries/SD/SD.h @@ -1,6 +1,6 @@ /* - MemoryCard - a slightly more friendly wrapper for sdfatlib + SD - a slightly more friendly wrapper for sdfatlib This library aims to expose a subset of SD card functionality in the form of a higher level "wrapper" object. @@ -20,6 +20,9 @@ #include #include +// Use this to configure the chip select pin of the SD card. +#define SD_CARD_CHIP_SELECT_PIN 4 // For use with Arduino Ethernet Shield + class SDClass { private: @@ -32,7 +35,7 @@ class SDClass { public: // This needs to be called to set up the connection to the memory card // before other methods are used. - void begin(); + void begin(uint8_t csPin = SD_CARD_CHIP_SELECT_PIN); // Open the specified file/directory with the supplied mode (e.g. read or // write, etc). Once opened the file can be accessed via the