Sfoglia il codice sorgente

T4 - put inital calls for check pins and set pins...

Some libraries actually call this.  So define the Hardware data for the one pin for each of the MISO, MOSI, SCK and CS...

So far setting does nothing.

Enough to get Sparkfun Teensyview to build, other than example uses String class which is not included in link phase.
main
Kurt Eckhardt 5 anni fa
parent
commit
d80ed60712
2 ha cambiato i file con 93 aggiunte e 5 eliminazioni
  1. +78
    -1
      SPI.cpp
  2. +15
    -4
      SPI.h

+ 78
- 1
SPI.cpp Vedi File

@@ -1295,10 +1295,87 @@ void SPIClass::begin()
LPSPI4_CR = LPSPI_CR_RST;
}

uint8_t SPIClass::pinIsChipSelect(uint8_t pin)
{
return 0;
}

bool SPIClass::pinIsChipSelect(uint8_t pin1, uint8_t pin2)
{
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;
}

bool SPIClass::pinIsMOSI(uint8_t pin)
{
for (unsigned int i = 0; i < sizeof(hardware().mosi_pin); i++) {
if (pin == hardware().mosi_pin[i]) return true;
}
return false;
}

bool SPIClass::pinIsMISO(uint8_t pin)
{
for (unsigned int i = 0; i < sizeof(hardware().miso_pin); i++) {
if (pin == hardware().miso_pin[i]) return true;
}
return false;
}

bool SPIClass::pinIsSCK(uint8_t pin)
{
for (unsigned int i = 0; i < sizeof(hardware().sck_pin); i++) {
if (pin == hardware().sck_pin[i]) return true;
}
return false;
}

// setCS() is not intended for use from normal Arduino programs/sketches.
uint8_t SPIClass::setCS(uint8_t pin)
{
/*
for (unsigned int i = 0; i < sizeof(hardware().cs_pin); i++) {
if (pin == hardware().cs_pin[i]) {
volatile uint32_t *reg = portConfigRegister(pin);
*reg = hardware().cs_mux[i];
return hardware().cs_mask[i];
}
} */
return 0;
}

void SPIClass::setMOSI(uint8_t pin)
{
// Currently only one defined so just return...
}

void SPIClass::setMISO(uint8_t pin)
{
// Currently only one defined so just return...
}

void SPIClass::setSCK(uint8_t pin)
{
// Currently only one defined so just return...
}




const SPIClass::SPI_Hardware_t SPIClass::lpspi4_hardware = {
CCM_CCGR1,
CCM_CCGR1_LPSPI4(CCM_CCGR_ON)
12,
3 | 0x10,
11,
3 | 0x10,
13,
3 | 0x10,
10,
3 | 0x10,
};
SPIClass SPI(0, (uintptr_t)&SPIClass::lpspi4_hardware);


+ 15
- 4
SPI.h Vedi File

@@ -1071,13 +1071,23 @@ private:
friend class SPIClass;
};



class SPIClass { // Teensy 4
public:
static const uint8_t CNT_MISO_PINS = 1;
static const uint8_t CNT_MOSI_PINS = 1;
static const uint8_t CNT_SCK_PINS = 1;
static const uint8_t CNT_CS_PINS = 1;
typedef struct {
volatile uint32_t &clock_gate_register;
uint32_t clock_gate_mask;
uint8_t miso_pin[CNT_MISO_PINS];
uint32_t miso_mux[CNT_MISO_PINS];
uint8_t mosi_pin[CNT_MOSI_PINS];
uint32_t mosi_mux[CNT_MOSI_PINS];
uint8_t sck_pin[CNT_SCK_PINS];
uint32_t sck_mux[CNT_SCK_PINS];
uint8_t cs_pin[CNT_CS_PINS];
uint32_t cs_mux[CNT_CS_PINS];
} SPI_Hardware_t;
static const SPI_Hardware_t lpspi4_hardware;

@@ -1170,12 +1180,13 @@ public:
//return port().POPR;
}
uint16_t transfer16(uint16_t data) {
transfer(data >> 8);
transfer(data & 255);
uint16_t ret_val = transfer(data >> 8);
ret_val = (ret_val << 8) | transfer(data & 255);
//port().SR = SPI_SR_TCF;
//port().PUSHR = data | SPI_PUSHR_CTAS(1);
//while (!(port().SR & SPI_SR_TCF)) ; // wait
//return port().POPR;
return ret_val;
}

void inline transfer(void *buf, size_t count) {transfer(buf, buf, count);}

Loading…
Annulla
Salva