File tree 4 files changed +50
-0
lines changed
4 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -350,6 +350,17 @@ boolean SDClass::begin(uint8_t csPin, uint32_t speed) {
350
350
root.openRoot (volume);
351
351
}
352
352
353
+ // Warning: see comment in SD.h about possible card corruption.
354
+ void SDClass::end (bool endSPI)
355
+ {
356
+ if (card.errorCode () == 0 && root.isOpen ()) {
357
+ root.close (); // Warning: this calls sync(), see above comment about corruption.
358
+ }
359
+
360
+ card.end (endSPI);
361
+ }
362
+
363
+
353
364
// this little helper is used to traverse paths
354
365
SdFile SDClass::getParentDir (const char *filepath, int *index) {
355
366
// get parent directory
Original file line number Diff line number Diff line change @@ -90,6 +90,24 @@ class SDClass {
90
90
// before other methods are used.
91
91
boolean begin (uint8_t csPin = SD_CHIP_SELECT_PIN, uint32_t speed = SPI_HALF_SPEED);
92
92
93
+ /*
94
+ In the following sequence:
95
+ //Insert SD Card A
96
+ SD.begin()
97
+ //do operations
98
+ //remove card A
99
+ //insert SD card B
100
+ SD.end()
101
+
102
+ It is possible that card A becomes corrupted due to removal before calling SD.end().
103
+ It is possible that card B becomes corrupted if there were ops pending for card A at the time SD.end() is called.
104
+
105
+ Call SD.end() or SD.end(true) to shut everything down.
106
+ Call SD.end(false) to shut everything but the SPI object down.
107
+ */
108
+ void end (bool endSPI = true );
109
+
110
+
93
111
// Open the specified file/directory with the supplied mode (e.g. read or
94
112
// write, etc). Returns a File object for interacting with the file.
95
113
// Note that currently only one file can be open at a time.
Original file line number Diff line number Diff line change @@ -349,6 +349,24 @@ uint8_t Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
349
349
chipSelectHigh ();
350
350
return false ;
351
351
}
352
+
353
+ // ------------------------------------------------------------------------------
354
+ /* *
355
+ * Shut down Sd2Card, which at this point means end SPI.
356
+ *
357
+ * \param[in] endSPI The value true (non-zero) or FALSE (zero).
358
+
359
+ Call card.end() or card.end(true) to shut everything down.
360
+ Call card.end(false) to shut everything but the SPI object down.
361
+ */
362
+ void Sd2Card::end (bool endSPI)
363
+ {
364
+ if (endSPI)
365
+ SPI.end ();
366
+ }
367
+
368
+
369
+
352
370
// ------------------------------------------------------------------------------
353
371
/* *
354
372
* Enable or disable partial block reads.
Original file line number Diff line number Diff line change @@ -200,6 +200,9 @@ class Sd2Card {
200
200
}
201
201
uint8_t init (uint8_t sckRateID, uint8_t chipSelectPin);
202
202
#endif
203
+
204
+ void end (bool endSPI = true );
205
+
203
206
void partialBlockRead (uint8_t value);
204
207
/* * Returns the current value, true or false, for partial block read. */
205
208
uint8_t partialBlockRead (void ) const {return partialBlockRead_;}
You can’t perform that action at this time.
0 commit comments