From 6ab0533f310bcf262a230f36bf08fda27ec3a7c1 Mon Sep 17 00:00:00 2001 From: Bill Greiman Date: Tue, 4 Jul 2017 06:04:10 -0700 Subject: [PATCH] Support on-board SD with dedicated SPI --- examples/bench/bench.ino | 2 +- library.properties | 2 +- src/FatLib/FatFile.cpp | 4 ++-- src/SdFat.h | 2 +- src/SpiDriver/SdSpiDriver.h | 19 ++++++++++++------- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/examples/bench/bench.ino b/examples/bench/bench.ino index 74fc0831..3d0970ef 100644 --- a/examples/bench/bench.ino +++ b/examples/bench/bench.ino @@ -135,7 +135,7 @@ void loop() { } // fill buf with known data - for (uint16_t i = 0; i < (BUF_SIZE-2); i++) { + for (size_t i = 0; i < (BUF_SIZE-2); i++) { buf[i] = 'A' + (i % 26); } buf[BUF_SIZE-2] = '\r'; diff --git a/library.properties b/library.properties index 4c9c3f57..a6929b15 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SdFat -version=1.0.1 +version=1.0.2 author=Bill Greiman maintainer=Bill Greiman sentence=FAT16/FAT32 file system for SD cards. diff --git a/src/FatLib/FatFile.cpp b/src/FatLib/FatFile.cpp index 9e734d89..8f3a820c 100644 --- a/src/FatLib/FatFile.cpp +++ b/src/FatLib/FatFile.cpp @@ -766,7 +766,7 @@ int FatFile::read(void* buf, size_t nbyte) { memcpy(dst, src, n); #if USE_MULTI_BLOCK_IO } else if (toRead >= 1024) { - uint8_t nb = toRead >> 9; + size_t nb = toRead >> 9; if (!isRootFixed()) { uint8_t mb = m_vol->blocksPerCluster() - blockOfCluster; if (mb < nb) { @@ -1439,7 +1439,7 @@ int FatFile::write(const void* buf, size_t nbyte) { } else if (nToWrite >= 1024) { // use multiple block write command uint8_t maxBlocks = m_vol->blocksPerCluster() - blockOfCluster; - uint8_t nBlock = nToWrite >> 9; + size_t nBlock = nToWrite >> 9; if (nBlock > maxBlocks) { nBlock = maxBlocks; } diff --git a/src/SdFat.h b/src/SdFat.h index 5e8524f4..78f35afe 100644 --- a/src/SdFat.h +++ b/src/SdFat.h @@ -29,7 +29,7 @@ #include "SdCard/SdioCard.h" //------------------------------------------------------------------------------ /** SdFat version */ -#define SD_FAT_VERSION "1.0.1" +#define SD_FAT_VERSION "1.0.2" //============================================================================== /** * \class SdBaseFile diff --git a/src/SpiDriver/SdSpiDriver.h b/src/SpiDriver/SdSpiDriver.h index 254c7f91..2f2ccb7f 100644 --- a/src/SpiDriver/SdSpiDriver.h +++ b/src/SpiDriver/SdSpiDriver.h @@ -28,6 +28,11 @@ #include "SdSpiBaseDriver.h" #include "SdFatConfig.h" //----------------------------------------------------------------------------- +/** SDCARD_SPI is defined if board has built-in SD card socket */ +#ifndef SDCARD_SPI +#define SDCARD_SPI SPI +#endif // SDCARD_SPI +//----------------------------------------------------------------------------- /** * \class SdSpiLibDriver * \brief SdSpiLibDriver - use standard SPI library. @@ -40,11 +45,11 @@ class SdSpiLibDriver { public: /** Activate SPI hardware. */ void activate() { - SPI.beginTransaction(m_spiSettings); + SDCARD_SPI.beginTransaction(m_spiSettings); } /** Deactivate SPI hardware. */ void deactivate() { - SPI.endTransaction(); + SDCARD_SPI.endTransaction(); } /** Initialize the SPI bus. * @@ -54,14 +59,14 @@ class SdSpiLibDriver { m_csPin = csPin; digitalWrite(csPin, HIGH); pinMode(csPin, OUTPUT); - SPI.begin(); + SDCARD_SPI.begin(); } /** Receive a byte. * * \return The byte. */ uint8_t receive() { - return SPI.transfer( 0XFF); + return SDCARD_SPI.transfer( 0XFF); } /** Receive multiple bytes. * @@ -72,7 +77,7 @@ class SdSpiLibDriver { */ uint8_t receive(uint8_t* buf, size_t n) { for (size_t i = 0; i < n; i++) { - buf[i] = SPI.transfer(0XFF); + buf[i] = SDCARD_SPI.transfer(0XFF); } return 0; } @@ -81,7 +86,7 @@ class SdSpiLibDriver { * \param[in] data Byte to send */ void send(uint8_t data) { - SPI.transfer(data); + SDCARD_SPI.transfer(data); } /** Send multiple bytes. * @@ -90,7 +95,7 @@ class SdSpiLibDriver { */ void send(const uint8_t* buf, size_t n) { for (size_t i = 0; i < n; i++) { - SPI.transfer(buf[i]); + SDCARD_SPI.transfer(buf[i]); } } /** Set CS low. */