瀏覽代碼

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

main
xxxajk 5 年之前
父節點
當前提交
49da4bd433
共有 2 個文件被更改,包括 53 次插入16 次删除
  1. +25
    -0
      SPI.cpp
  2. +28
    -16
      SPI.h

+ 25
- 0
SPI.cpp 查看文件

@@ -1323,6 +1323,31 @@ void SPIClass::transfer(const void * buf, void * retbuf, size_t count)



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 查看文件

@@ -71,7 +71,7 @@
/**********************************************************/

#if defined(__AVR__)
#define SPI_ATOMIC_VERSION 1
// define SPI_AVR_EIMSK for AVR boards with external interrupt pins
#if defined(EIMSK)
#define SPI_AVR_EIMSK EIMSK
@@ -321,6 +321,7 @@ private:
#elif defined(__arm__) && defined(TEENSYDUINO) && defined(KINETISK)

#define SPI_HAS_NOTUSINGINTERRUPT 1
#define SPI_ATOMIC_VERSION 1

class SPISettings {
public:
@@ -680,6 +681,7 @@ private:
/**********************************************************/

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

class SPISettings {
public:
@@ -1027,6 +1029,7 @@ private:
/**********************************************************/

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

//#include "debug/printf.h"

@@ -1093,20 +1096,28 @@ public:
// prevent conflicts. The input interruptNumber is the number used
// with attachInterrupt. If SPI is used from a different interrupt
// (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 notUsingInterrupt(IRQ_NUMBER_t interruptName);

@@ -1170,12 +1181,13 @@ public:
//return port().POPR;
}
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().PUSHR = data | SPI_PUSHR_CTAS(1);
//while (!(port().SR & SPI_SR_TCF)) ; // wait
//return port().POPR;
return rv;
}

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

Loading…
取消
儲存