Browse Source

SPCR1 used in setDataMode

main
Kurt Eckhardt 8 years ago
parent
commit
17ffb0096c
2 changed files with 24 additions and 12 deletions
  1. +23
    -11
      SPI.cpp
  2. +1
    -1
      SPI.h

+ 23
- 11
SPI.cpp View File

@@ -275,20 +275,33 @@ void SPIClass::setClockDivider_noInline(uint32_t clk)
updateCTAR(ctar);
}

bool SPIClass::pinIsChipSelect(uint8_t pin)
uint8_t SPIClass::pinIsChipSelect(uint8_t pin)
{
if (pin == 10 || pin == 9 || pin == 6 || pin == 2 || pin == 15) return true;
if (pin >= 20 && pin <= 23) return true;
return false;
switch (pin) {
case 10: return 0x01; // PTC4
case 2: return 0x01; // PTD0
case 9: return 0x02; // PTC3
case 6: return 0x02; // PTD4
case 20: return 0x04; // PTD5
case 23: return 0x04; // PTC2
case 21: return 0x08; // PTD6
case 22: return 0x08; // PTC1
case 15: return 0x10; // PTC0
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
case 26: return 0x01;
#endif
}

return 0;
}

bool SPIClass::pinIsChipSelect(uint8_t pin1, uint8_t pin2)
{
if (!pinIsChipSelect(pin1) || !pinIsChipSelect(pin2)) return false;
if ((pin1 == 2 && pin2 == 10) || (pin1 == 10 && pin2 == 2)) return false;
if ((pin1 == 6 && pin2 == 9) || (pin1 == 9 && pin2 == 6)) return false;
if ((pin1 == 20 && pin2 == 23) || (pin1 == 23 && pin2 == 20)) return false;
if ((pin1 == 21 && pin2 == 22) || (pin1 == 22 && pin2 == 21)) return false;
uint8_t pin1_mask, pin2_mask;
if ((pin1_mask = (uint8_t)pinIsChipSelect(pin1)) == 0) return false;
if ((pin2_mask = (uint8_t)pinIsChipSelect(pin2)) == 0) return false;
Serial.printf("pinIsChipSelect %d %d %x %x\n\r", pin1, pin2, pin1_mask, pin2_mask);
if ((pin1_mask & pin2_mask) != 0) return false;
return true;
}

@@ -398,8 +411,7 @@ void SPI1Class::setDataMode(uint8_t dataMode)
SIM_SCGC6 |= SIM_SCGC6_SPI1;

// TODO: implement with native code

SPCR = (SPCR & ~SPI_MODE_MASK) | dataMode;
SPCR1 = (SPCR1 & ~SPI_MODE_MASK) | dataMode;
}

void SPI1Class::setClockDivider_noInline(uint32_t clk)

+ 1
- 1
SPI.h View File

@@ -583,7 +583,7 @@ public:
SPCR.setSCK(pin);
}
// return true if "pin" has special chip select capability
static bool pinIsChipSelect(uint8_t pin);
static uint8_t pinIsChipSelect(uint8_t pin);
// return true if both pin1 and pin2 have independent chip select capability
static bool pinIsChipSelect(uint8_t pin1, uint8_t pin2);
// configure a pin for chip select and return its SPI_MCR_PCSIS bitmask

Loading…
Cancel
Save