Browse Source

T4: Add missing usingInterrupt methods, fix transfer16 method. ALL: Add missing macro defines.

main
xxxajk 5 years ago
parent
commit
49da4bd433
2 changed files with 53 additions and 16 deletions
  1. +25
    -0
      SPI.cpp
  2. +28
    -16
      SPI.h

+ 25
- 0
SPI.cpp View File







void SPIClass::usingInterrupt(IRQ_NUMBER_t interruptName)
{
uint32_t n = (uint32_t)interruptName;

if (n >= NVIC_NUM_INTERRUPTS) return;

//Serial.print("usingInterrupt ");
//Serial.println(n);
interruptMasksUsed |= (1 << (n >> 5));
interruptMask[n >> 5] |= (1 << (n & 0x1F));
//Serial.printf("interruptMasksUsed = %d\n", interruptMasksUsed);
//Serial.printf("interruptMask[0] = %08X\n", interruptMask[0]);
//Serial.printf("interruptMask[1] = %08X\n", interruptMask[1]);
//Serial.printf("interruptMask[2] = %08X\n", interruptMask[2]);
}

void SPIClass::notUsingInterrupt(IRQ_NUMBER_t interruptName)
{
uint32_t n = (uint32_t)interruptName;
if (n >= NVIC_NUM_INTERRUPTS) return;
interruptMask[n >> 5] &= ~(1 << (n & 0x1F));
if (interruptMask[n >> 5] == 0) {
interruptMasksUsed &= ~(1 << (n >> 5));
}
}







+ 28
- 16
SPI.h View File

/**********************************************************/ /**********************************************************/


#if defined(__AVR__) #if defined(__AVR__)
#define SPI_ATOMIC_VERSION 1
// define SPI_AVR_EIMSK for AVR boards with external interrupt pins // define SPI_AVR_EIMSK for AVR boards with external interrupt pins
#if defined(EIMSK) #if defined(EIMSK)
#define SPI_AVR_EIMSK EIMSK #define SPI_AVR_EIMSK EIMSK
#elif defined(__arm__) && defined(TEENSYDUINO) && defined(KINETISK) #elif defined(__arm__) && defined(TEENSYDUINO) && defined(KINETISK)


#define SPI_HAS_NOTUSINGINTERRUPT 1 #define SPI_HAS_NOTUSINGINTERRUPT 1
#define SPI_ATOMIC_VERSION 1


class SPISettings { class SPISettings {
public: public:
/**********************************************************/ /**********************************************************/


#elif defined(__arm__) && defined(TEENSYDUINO) && defined(KINETISL) #elif defined(__arm__) && defined(TEENSYDUINO) && defined(KINETISL)
#define SPI_ATOMIC_VERSION 1


class SPISettings { class SPISettings {
public: public:
/**********************************************************/ /**********************************************************/


#elif defined(__arm__) && defined(TEENSYDUINO) && (defined(__IMXRT1052__) || defined(__IMXRT1062__)) #elif defined(__arm__) && defined(TEENSYDUINO) && (defined(__IMXRT1052__) || defined(__IMXRT1062__))
#define SPI_ATOMIC_VERSION 1


//#include "debug/printf.h" //#include "debug/printf.h"


// prevent conflicts. The input interruptNumber is the number used // prevent conflicts. The input interruptNumber is the number used
// with attachInterrupt. If SPI is used from a different interrupt // with attachInterrupt. If SPI is used from a different interrupt
// (eg, a timer), interruptNumber should be 255. // (eg, a timer), interruptNumber should be 255.
/*void usingInterrupt(uint8_t n) {
if (n == 3 || n == 4 || n == 24 || n == 33) {
usingInterrupt(IRQ_PORTA);
} else if (n == 0 || n == 1 || (n >= 16 && n <= 19) || n == 25 || n == 32) {
usingInterrupt(IRQ_PORTB);
} else if ((n >= 9 && n <= 13) || n == 15 || n == 22 || n == 23
|| (n >= 27 && n <= 30)) {
usingInterrupt(IRQ_PORTC);
} else if (n == 2 || (n >= 5 && n <= 8) || n == 14 || n == 20 || n == 21) {
usingInterrupt(IRQ_PORTD);
} else if (n == 26 || n == 31) {
usingInterrupt(IRQ_PORTE);
void usingInterrupt(uint8_t n) {
if (n >= CORE_NUM_DIGITAL) return;
volatile uint32_t *gpio = portOutputRegister(n);
switch((uint32_t)gpio) {
case (uint32_t)&GPIO1_DR:
usingInterrupt(IRQ_GPIO1_0_15);
usingInterrupt(IRQ_GPIO1_16_31);
break;
case (uint32_t)&GPIO2_DR:
usingInterrupt(IRQ_GPIO2_0_15);
usingInterrupt(IRQ_GPIO2_16_31);
break;
case (uint32_t)&GPIO3_DR:
usingInterrupt(IRQ_GPIO3_0_15);
usingInterrupt(IRQ_GPIO3_16_31);
break;
case (uint32_t)&GPIO4_DR:
usingInterrupt(IRQ_GPIO4_0_15);
usingInterrupt(IRQ_GPIO4_16_31);
break;
} }
}*/
}
void usingInterrupt(IRQ_NUMBER_t interruptName); void usingInterrupt(IRQ_NUMBER_t interruptName);
void notUsingInterrupt(IRQ_NUMBER_t interruptName); void notUsingInterrupt(IRQ_NUMBER_t interruptName);


//return port().POPR; //return port().POPR;
} }
uint16_t transfer16(uint16_t data) { uint16_t transfer16(uint16_t data) {
transfer(data >> 8);
transfer(data & 255);
uint16_t rv=transfer(data >> 8);
rv |=transfer(data & 255) << 8;
//port().SR = SPI_SR_TCF; //port().SR = SPI_SR_TCF;
//port().PUSHR = data | SPI_PUSHR_CTAS(1); //port().PUSHR = data | SPI_PUSHR_CTAS(1);
//while (!(port().SR & SPI_SR_TCF)) ; // wait //while (!(port().SR & SPI_SR_TCF)) ; // wait
//return port().POPR; //return port().POPR;
return rv;
} }


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

Loading…
Cancel
Save