Bläddra i källkod

Support on-board SD with dedicated SPI

Bill Greiman 7 år sedan
förälder
incheckning
6ab0533f31
5 ändrade filer med 17 tillägg och 12 borttagningar
  1. 1 1
      examples/bench/bench.ino
  2. 1 1
      library.properties
  3. 2 2
      src/FatLib/FatFile.cpp
  4. 1 1
      src/SdFat.h
  5. 12 7
      src/SpiDriver/SdSpiDriver.h

+ 1 - 1
examples/bench/bench.ino

@@ -135,7 +135,7 @@ void loop() {
   }
   }
 
 
   // fill buf with known data
   // 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[i] = 'A' + (i % 26);
   }
   }
   buf[BUF_SIZE-2] = '\r';
   buf[BUF_SIZE-2] = '\r';

+ 1 - 1
library.properties

@@ -1,5 +1,5 @@
 name=SdFat
 name=SdFat
-version=1.0.1
+version=1.0.2
 author=Bill Greiman <fat16lib@sbcglobal.net>
 author=Bill Greiman <fat16lib@sbcglobal.net>
 maintainer=Bill Greiman <fat16lib@sbcglobal.net>
 maintainer=Bill Greiman <fat16lib@sbcglobal.net>
 sentence=FAT16/FAT32 file system for SD cards.
 sentence=FAT16/FAT32 file system for SD cards.

+ 2 - 2
src/FatLib/FatFile.cpp

@@ -766,7 +766,7 @@ int FatFile::read(void* buf, size_t nbyte) {
       memcpy(dst, src, n);
       memcpy(dst, src, n);
 #if USE_MULTI_BLOCK_IO
 #if USE_MULTI_BLOCK_IO
     } else if (toRead >= 1024) {
     } else if (toRead >= 1024) {
-      uint8_t nb = toRead >> 9;
+      size_t nb = toRead >> 9;
       if (!isRootFixed()) {
       if (!isRootFixed()) {
         uint8_t mb = m_vol->blocksPerCluster() - blockOfCluster;
         uint8_t mb = m_vol->blocksPerCluster() - blockOfCluster;
         if (mb < nb) {
         if (mb < nb) {
@@ -1439,7 +1439,7 @@ int FatFile::write(const void* buf, size_t nbyte) {
     } else if (nToWrite >= 1024) {
     } else if (nToWrite >= 1024) {
       // use multiple block write command
       // use multiple block write command
       uint8_t maxBlocks = m_vol->blocksPerCluster() - blockOfCluster;
       uint8_t maxBlocks = m_vol->blocksPerCluster() - blockOfCluster;
-      uint8_t nBlock = nToWrite >> 9;
+      size_t nBlock = nToWrite >> 9;
       if (nBlock > maxBlocks) {
       if (nBlock > maxBlocks) {
         nBlock = maxBlocks;
         nBlock = maxBlocks;
       }
       }

+ 1 - 1
src/SdFat.h

@@ -29,7 +29,7 @@
 #include "SdCard/SdioCard.h"
 #include "SdCard/SdioCard.h"
 //------------------------------------------------------------------------------
 //------------------------------------------------------------------------------
 /** SdFat version */
 /** SdFat version */
-#define SD_FAT_VERSION "1.0.1"
+#define SD_FAT_VERSION "1.0.2"
 //==============================================================================
 //==============================================================================
 /**
 /**
  * \class SdBaseFile
  * \class SdBaseFile

+ 12 - 7
src/SpiDriver/SdSpiDriver.h

@@ -28,6 +28,11 @@
 #include "SdSpiBaseDriver.h"
 #include "SdSpiBaseDriver.h"
 #include "SdFatConfig.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
  * \class SdSpiLibDriver
  * \brief SdSpiLibDriver - use standard SPI library.
  * \brief SdSpiLibDriver - use standard SPI library.
@@ -40,11 +45,11 @@ class SdSpiLibDriver {
  public:
  public:
   /** Activate SPI hardware. */
   /** Activate SPI hardware. */
   void activate() {
   void activate() {
-    SPI.beginTransaction(m_spiSettings);
+    SDCARD_SPI.beginTransaction(m_spiSettings);
   }
   }
   /** Deactivate SPI hardware. */
   /** Deactivate SPI hardware. */
   void deactivate() {
   void deactivate() {
-    SPI.endTransaction();
+    SDCARD_SPI.endTransaction();
   }
   }
   /** Initialize the SPI bus.
   /** Initialize the SPI bus.
    *
    *
@@ -54,14 +59,14 @@ class SdSpiLibDriver {
     m_csPin = csPin;
     m_csPin = csPin;
     digitalWrite(csPin, HIGH);
     digitalWrite(csPin, HIGH);
     pinMode(csPin, OUTPUT);
     pinMode(csPin, OUTPUT);
-    SPI.begin();
+    SDCARD_SPI.begin();
   }
   }
   /** Receive a byte.
   /** Receive a byte.
    *
    *
    * \return The byte.
    * \return The byte.
    */
    */
   uint8_t receive() {
   uint8_t receive() {
-    return SPI.transfer( 0XFF);
+    return SDCARD_SPI.transfer( 0XFF);
   }
   }
   /** Receive multiple bytes.
   /** Receive multiple bytes.
   *
   *
@@ -72,7 +77,7 @@ class SdSpiLibDriver {
   */
   */
   uint8_t receive(uint8_t* buf, size_t n) {
   uint8_t receive(uint8_t* buf, size_t n) {
     for (size_t i = 0; i < n; i++) {
     for (size_t i = 0; i < n; i++) {
-      buf[i] = SPI.transfer(0XFF);
+      buf[i] = SDCARD_SPI.transfer(0XFF);
     }
     }
     return 0;
     return 0;
   }
   }
@@ -81,7 +86,7 @@ class SdSpiLibDriver {
    * \param[in] data Byte to send
    * \param[in] data Byte to send
    */
    */
   void send(uint8_t data) {
   void send(uint8_t data) {
-    SPI.transfer(data);
+    SDCARD_SPI.transfer(data);
   }
   }
   /** Send multiple bytes.
   /** Send multiple bytes.
    *
    *
@@ -90,7 +95,7 @@ class SdSpiLibDriver {
    */
    */
   void send(const uint8_t* buf, size_t n) {
   void send(const uint8_t* buf, size_t n) {
     for (size_t i = 0; i < n; i++) {
     for (size_t i = 0; i < n; i++) {
-      SPI.transfer(buf[i]);
+      SDCARD_SPI.transfer(buf[i]);
     }
     }
   }
   }
   /** Set CS low. */
   /** Set CS low. */