Skip to content

Add patch for software SPI support #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ The SD library allows for reading from and writing to SD cards.

For more information about this library please visit us at
http://www.arduino.cc/en/Reference/{repository-name}

Added patch to adapt library for TFT shield on Arduino Mega. Description of the changes at
https://www.aranacorp.com/fr/utilisation-du-module-sd-du-shield-tft-avec-arduino-mega/
14 changes: 13 additions & 1 deletion src/SD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ namespace SDLib {
volume.init(card) &&
root.openRoot(volume);
}

#ifndef SOFTWARE_SPI //Added compiler directive so that MEGA works with this code
bool SDClass::begin(uint32_t clock, uint8_t csPin) {
if (root.isOpen()) {
root.close();
Expand All @@ -365,7 +365,19 @@ namespace SDLib {
volume.init(card) &&
root.openRoot(volume);
}
#else
bool SDClass::begin(uint32_t clock, uint8_t csPin) {
if (root.isOpen()) {
root.close();
}

return card.init(SPI_HALF_SPEED, csPin) &&
card.setSpiClock(clock) &&
volume.init(card) &&
root.openRoot(volume);
}
#endif  //SOFTWARE_SPI

//call this when a card is removed. It will allow you to insert and initialise a new card.
void SDClass::end() {
root.close();
Expand Down
3 changes: 2 additions & 1 deletion src/utility/Sd2Card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
along with the Arduino Sd2Card Library. If not, see
<http://www.gnu.org/licenses/>.
*/
#define USE_SPI_LIB
//#define USE_SPI_LIB //moved line 25
#include <Arduino.h>
#include "Sd2Card.h"
//------------------------------------------------------------------------------
#ifndef SOFTWARE_SPI
#define USE_SPI_LIB
#ifdef USE_SPI_LIB

#ifndef SDCARD_SPI
Expand Down
3 changes: 2 additions & 1 deletion src/utility/Sd2Card.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ uint8_t const SPI_QUARTER_SPEED = 2;
USE_SPI_LIB: if set, use the SPI library bundled with Arduino IDE, otherwise
run with a standalone driver for AVR.
*/
#define USE_SPI_LIB
//#define USE_SPI_LIB //moved line 56
/**
Define MEGA_SOFT_SPI non-zero to use software SPI on Mega Arduinos.
Pins used are SS 10, MOSI 11, MISO 12, and SCK 13.
Expand All @@ -53,6 +53,7 @@ uint8_t const SPI_QUARTER_SPEED = 2;
// SPI pin definitions
//
#ifndef SOFTWARE_SPI
#define USE_SPI_LIB
// hardware pin defs

// include pins_arduino.h or variant.h depending on architecture, via Arduino.h
Expand Down