Skip to content

Commit

Permalink
Support on-board SD with dedicated SPI
Browse files Browse the repository at this point in the history
  • Loading branch information
greiman committed Jul 4, 2017
1 parent e89cfd3 commit 6ab0533
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/bench/bench.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SdFat
version=1.0.1
version=1.0.2
author=Bill Greiman <[email protected]>
maintainer=Bill Greiman <[email protected]>
sentence=FAT16/FAT32 file system for SD cards.
Expand Down
4 changes: 2 additions & 2 deletions src/FatLib/FatFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/SdFat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions src/SpiDriver/SdSpiDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
*
Expand All @@ -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.
*
Expand All @@ -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;
}
Expand All @@ -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.
*
Expand All @@ -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. */
Expand Down

0 comments on commit 6ab0533

Please sign in to comment.