Procházet zdrojové kódy

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 před 4 roky
rodič
revize
39867e87cd
1 změnil soubory, kde provedl 11 přidání a 6 odebrání
  1. +11
    -6
      utility/Sd2Card.cpp

+ 11
- 6
utility/Sd2Card.cpp Zobrazit soubor

@@ -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;

Načítá se…
Zrušit
Uložit