Skip to content

Commit a9b2d4b

Browse files
committed
release pins/deref SPI when done
1 parent 16acc15 commit a9b2d4b

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/SD.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ namespace SDLib {
367367
//call this when a card is removed. It will allow you to insert and initialise a new card.
368368
void SDClass::end() {
369369
root.close();
370+
card.done();
370371
}
371372

372373
// this little helper is used to traverse paths

src/utility/Sd2Card.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,32 @@ uint8_t Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
358358
return false;
359359
}
360360
//------------------------------------------------------------------------------
361+
/**
362+
Return initialized pins to floating and dereference SPI lib.
363+
*/
364+
void Sd2Card::done() {
365+
pinMode(chipSelectPin_, INPUT);
366+
digitalWrite(chipSelectPin_, LOW);
367+
368+
#ifndef USE_SPI_LIB
369+
pinMode(SPI_MISO_PIN, INPUT);
370+
digitalWrite(SPI_MISO_PIN, LOW);
371+
pinMode(SPI_MOSI_PIN, INPUT);
372+
digitalWrite(SPI_MOSI_PIN, LOW);
373+
pinMode(SPI_SCK_PIN, INPUT);
374+
digitalWrite(SPI_SCK_PIN, LOW);
375+
#endif
376+
377+
#ifndef SOFTWARE_SPI
378+
#ifndef USE_SPI_LIB
379+
pinMode(SS_PIN, INPUT);
380+
digitalWrite(SS_PIN, LOW);
381+
#else // USE_SPI_LIB
382+
SDCARD_SPI.end();
383+
#endif // USE_SPI_LIB
384+
#endif // SOFTWARE_SPI
385+
}
386+
//------------------------------------------------------------------------------
361387
/**
362388
Enable or disable partial block reads.
363389

src/utility/Sd2Card.h

+1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ class Sd2Card {
206206
return init(sckRateID, SD_CHIP_SELECT_PIN);
207207
}
208208
uint8_t init(uint8_t sckRateID, uint8_t chipSelectPin);
209+
void done();
209210
void partialBlockRead(uint8_t value);
210211
/** Returns the current value, true or false, for partial block read. */
211212
uint8_t partialBlockRead(void) const {

0 commit comments

Comments
 (0)