Browse Source

Use SPI library for Teensy LC

With this commit no direct register access to SPI hardware should be done anymore for Teensy LC. This is done in the same way as for Teensy 4. Additionally the USE_TEENSY4_SPI define was renamed to USE_SPI_LIB as it is now used for not only Teensy 4.
main
Martin Rutschmann 4 years ago
parent
commit
39867e87cd
1 changed files with 11 additions and 6 deletions
  1. +11
    -6
      utility/Sd2Card.cpp

+ 11
- 6
utility/Sd2Card.cpp View File

} }
/** SPI send multiple bytes */ /** 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) { static void spiInit(uint8_t spiRate) {
switch (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 // the top 2 speeds are set to 24 MHz, for the SD library defaults
case 0: settings = SPISettings(25200000, MSBFIRST, SPI_MODE0); break; case 0: settings = SPISettings(25200000, MSBFIRST, SPI_MODE0); break;
#endif
case 1: settings = SPISettings(24000000, MSBFIRST, SPI_MODE0); break; case 1: settings = SPISettings(24000000, MSBFIRST, SPI_MODE0); break;
case 2: settings = SPISettings(8000000, MSBFIRST, SPI_MODE0); break; case 2: settings = SPISettings(8000000, MSBFIRST, SPI_MODE0); break;
case 3: settings = SPISettings(4000000, MSBFIRST, SPI_MODE0); break; case 3: settings = SPISettings(4000000, MSBFIRST, SPI_MODE0); break;
#if defined(USE_TEENSY3_SPI) #if defined(USE_TEENSY3_SPI)
spiBegin(); spiBegin();
spiInit(6); spiInit(6);
#elif defined(USE_TEENSY4_SPI)
#elif defined(USE_SPI_LIB)
spiInit(6); spiInit(6);
pinMode(SS_PIN, OUTPUT); pinMode(SS_PIN, OUTPUT);
digitalWrite(SS_PIN, HIGH); // disable any SPI device using hardware SS pin digitalWrite(SS_PIN, HIGH); // disable any SPI device using hardware SS pin
if (!waitStartBlock()) { if (!waitStartBlock()) {
goto fail; goto fail;
} }
#if defined(USE_TEENSY3_SPI) | defined(USE_TEENSY4_SPI)
#if defined(USE_TEENSY3_SPI) | defined(USE_SPI_LIB)
spiRec(dst, 512); spiRec(dst, 512);
spiRecIgnore(2); spiRecIgnore(2);
#else // OPTIMIZE_HARDWARE_SPI #else // OPTIMIZE_HARDWARE_SPI
* false, is returned for an invalid value of \a sckRateID. * false, is returned for an invalid value of \a sckRateID.
*/ */
uint8_t Sd2Card::setSckRate(uint8_t 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); spiInit(sckRateID);
return true; return true;
#else #else
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// send one block of data for write block or write multiple blocks // send one block of data for write block or write multiple blocks
uint8_t Sd2Card::writeData(uint8_t token, const uint8_t* src) { 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 // send data - optimized loop
SPDR = token; SPDR = token;

Loading…
Cancel
Save