瀏覽代碼

Merge pull request #22 from rutmarti/master

Use SPI library for Teensy LC
main
Paul Stoffregen 4 年之前
父節點
當前提交
f7c6002632
沒有連結到貢獻者的電子郵件帳戶。
共有 1 個檔案被更改,包括 11 行新增6 行删除
  1. +11
    -6
      utility/Sd2Card.cpp

+ 11
- 6
utility/Sd2Card.cpp 查看文件

@@ -143,13 +143,18 @@ static void spiSend(uint8_t b) {
}
/** SPI send multiple bytes */
#elif defined(__IMXRT1052__) || defined(__IMXRT1062__)
#define USE_TEENSY4_SPI
#elif defined(__IMXRT1052__) || defined(__IMXRT1062__) || defined(__MKL26Z64__)
#define USE_SPI_LIB
static void spiInit(uint8_t spiRate) {
switch (spiRate) {
#ifdef __MKL26Z64__
// the top 2 speeds are set to 24 MHz, for the SD library defaults
case 0: settings = SPISettings(24000000, MSBFIRST, SPI_MODE0); break;
#else
// the top 2 speeds are set to 24 MHz, for the SD library defaults
case 0: settings = SPISettings(25200000, MSBFIRST, SPI_MODE0); break;
#endif
case 1: settings = SPISettings(24000000, MSBFIRST, SPI_MODE0); break;
case 2: settings = SPISettings(8000000, MSBFIRST, SPI_MODE0); break;
case 3: settings = SPISettings(4000000, MSBFIRST, SPI_MODE0); break;
@@ -267,7 +272,7 @@ uint8_t Sd2Card::SD_init(uint8_t sckRateID, uint8_t chipSelectPin) {
#if defined(USE_TEENSY3_SPI)
spiBegin();
spiInit(6);
#elif defined(USE_TEENSY4_SPI)
#elif defined(USE_SPI_LIB)
spiInit(6);
pinMode(SS_PIN, OUTPUT);
digitalWrite(SS_PIN, HIGH); // disable any SPI device using hardware SS pin
@@ -360,7 +365,7 @@ uint8_t Sd2Card::SD_readBlock(uint32_t block, uint8_t* dst)
if (!waitStartBlock()) {
goto fail;
}
#if defined(USE_TEENSY3_SPI) | defined(USE_TEENSY4_SPI)
#if defined(USE_TEENSY3_SPI) | defined(USE_SPI_LIB)
spiRec(dst, 512);
spiRecIgnore(2);
#else // OPTIMIZE_HARDWARE_SPI
@@ -408,7 +413,7 @@ uint8_t Sd2Card::SD_readBlock(uint32_t block, uint8_t* dst)
* false, is returned for an invalid value of \a sckRateID.
*/
uint8_t Sd2Card::setSckRate(uint8_t sckRateID) {
#if defined(USE_TEENSY3_SPI) || defined(USE_TEENSY4_SPI)
#if defined(USE_TEENSY3_SPI) || defined(USE_SPI_LIB)
spiInit(sckRateID);
return true;
#else
@@ -506,7 +511,7 @@ uint8_t Sd2Card::SD_writeBlock(uint32_t blockNumber, const uint8_t* src) {
//------------------------------------------------------------------------------
// send one block of data for write block or write multiple blocks
uint8_t Sd2Card::writeData(uint8_t token, const uint8_t* src) {
#if defined(OPTIMIZE_HARDWARE_SPI) && !defined(USE_TEENSY4_SPI)
#if defined(OPTIMIZE_HARDWARE_SPI) && !defined(USE_SPI_LIB)
// send data - optimized loop
SPDR = token;

Loading…
取消
儲存