Selaa lähdekoodia

Adds support for digital pin toggling (digitalToggle) (Based directly off of the existing digitalWrite functions)

main
Robert Givens 7 vuotta sitten
vanhempi
commit
bbdf5bd600
2 muutettua tiedostoa jossa 282 lisäystä ja 0 poistoa
  1. +272
    -0
      teensy3/core_pins.h
  2. +10
    -0
      teensy3/pins_teensy.c

+ 272
- 0
teensy3/core_pins.h Näytä tiedosto

@@ -1021,6 +1021,71 @@
#define CORE_PIN62_PORTSET GPIOE_PSOR
#define CORE_PIN63_PORTSET GPIOE_PSOR

#define CORE_PIN0_PORTTOGGLE GPIOB_PTOR
#define CORE_PIN1_PORTTOGGLE GPIOB_PTOR
#define CORE_PIN2_PORTTOGGLE GPIOD_PTOR
#define CORE_PIN3_PORTTOGGLE GPIOA_PTOR
#define CORE_PIN4_PORTTOGGLE GPIOA_PTOR
#define CORE_PIN5_PORTTOGGLE GPIOD_PTOR
#define CORE_PIN6_PORTTOGGLE GPIOD_PTOR
#define CORE_PIN7_PORTTOGGLE GPIOD_PTOR
#define CORE_PIN8_PORTTOGGLE GPIOD_PTOR
#define CORE_PIN9_PORTTOGGLE GPIOC_PTOR
#define CORE_PIN10_PORTTOGGLE GPIOC_PTOR
#define CORE_PIN11_PORTTOGGLE GPIOC_PTOR
#define CORE_PIN12_PORTTOGGLE GPIOC_PTOR
#define CORE_PIN13_PORTTOGGLE GPIOC_PTOR
#define CORE_PIN14_PORTTOGGLE GPIOD_PTOR
#define CORE_PIN15_PORTTOGGLE GPIOC_PTOR
#define CORE_PIN16_PORTTOGGLE GPIOB_PTOR
#define CORE_PIN17_PORTTOGGLE GPIOB_PTOR
#define CORE_PIN18_PORTTOGGLE GPIOB_PTOR
#define CORE_PIN19_PORTTOGGLE GPIOB_PTOR
#define CORE_PIN20_PORTTOGGLE GPIOD_PTOR
#define CORE_PIN21_PORTTOGGLE GPIOD_PTOR
#define CORE_PIN22_PORTTOGGLE GPIOC_PTOR
#define CORE_PIN23_PORTTOGGLE GPIOC_PTOR
#define CORE_PIN24_PORTTOGGLE GPIOE_PTOR
#define CORE_PIN25_PORTTOGGLE GPIOA_PTOR
#define CORE_PIN26_PORTTOGGLE GPIOA_PTOR
#define CORE_PIN27_PORTTOGGLE GPIOA_PTOR
#define CORE_PIN28_PORTTOGGLE GPIOA_PTOR
#define CORE_PIN29_PORTTOGGLE GPIOB_PTOR
#define CORE_PIN30_PORTTOGGLE GPIOB_PTOR
#define CORE_PIN31_PORTTOGGLE GPIOB_PTOR
#define CORE_PIN32_PORTTOGGLE GPIOB_PTOR
#define CORE_PIN33_PORTTOGGLE GPIOE_PTOR
#define CORE_PIN34_PORTTOGGLE GPIOE_PTOR
#define CORE_PIN35_PORTTOGGLE GPIOC_PTOR
#define CORE_PIN36_PORTTOGGLE GPIOC_PTOR
#define CORE_PIN37_PORTTOGGLE GPIOC_PTOR
#define CORE_PIN38_PORTTOGGLE GPIOC_PTOR
#define CORE_PIN39_PORTTOGGLE GPIOA_PTOR
#define CORE_PIN40_PORTTOGGLE GPIOA_PTOR
#define CORE_PIN41_PORTTOGGLE GPIOA_PTOR
#define CORE_PIN42_PORTTOGGLE GPIOA_PTOR
#define CORE_PIN43_PORTTOGGLE GPIOB_PTOR
#define CORE_PIN44_PORTTOGGLE GPIOB_PTOR
#define CORE_PIN45_PORTTOGGLE GPIOB_PTOR
#define CORE_PIN46_PORTTOGGLE GPIOB_PTOR
#define CORE_PIN47_PORTTOGGLE GPIOD_PTOR
#define CORE_PIN48_PORTTOGGLE GPIOD_PTOR
#define CORE_PIN49_PORTTOGGLE GPIOB_PTOR
#define CORE_PIN50_PORTTOGGLE GPIOB_PTOR
#define CORE_PIN51_PORTTOGGLE GPIOD_PTOR
#define CORE_PIN52_PORTTOGGLE GPIOD_PTOR
#define CORE_PIN53_PORTTOGGLE GPIOD_PTOR
#define CORE_PIN54_PORTTOGGLE GPIOD_PTOR
#define CORE_PIN55_PORTTOGGLE GPIOD_PTOR
#define CORE_PIN56_PORTTOGGLE GPIOE_PTOR
#define CORE_PIN57_PORTTOGGLE GPIOE_PTOR
#define CORE_PIN58_PORTTOGGLE GPIOE_PTOR
#define CORE_PIN59_PORTTOGGLE GPIOE_PTOR
#define CORE_PIN60_PORTTOGGLE GPIOE_PTOR
#define CORE_PIN61_PORTTOGGLE GPIOE_PTOR
#define CORE_PIN62_PORTTOGGLE GPIOE_PTOR
#define CORE_PIN63_PORTTOGGLE GPIOE_PTOR

#define CORE_PIN0_PORTCLEAR GPIOB_PCOR
#define CORE_PIN1_PORTCLEAR GPIOB_PCOR
#define CORE_PIN2_PORTCLEAR GPIOD_PCOR
@@ -1762,6 +1827,213 @@ static inline void digitalWriteFast(uint8_t pin, uint8_t val)
}
}

void digitalToggle(uint8_t pin);
static inline void digitalToggleFast(uint8_t pin) __attribute__((always_inline, unused));
static inline void digitalToggleFast(uint8_t pin)
{
if (__builtin_constant_p(pin)) {
if (pin == 0) {
CORE_PIN0_PORTTOGGLE = CORE_PIN0_BITMASK;
}
else if (pin == 1) {
CORE_PIN1_PORTTOGGLE = CORE_PIN1_BITMASK;
}
else if (pin == 2) {
CORE_PIN2_PORTTOGGLE = CORE_PIN2_BITMASK;
}
else if (pin == 3) {
CORE_PIN3_PORTTOGGLE = CORE_PIN3_BITMASK;
}
else if (pin == 4) {
CORE_PIN4_PORTTOGGLE = CORE_PIN4_BITMASK;
}
else if (pin == 5) {
CORE_PIN5_PORTTOGGLE = CORE_PIN5_BITMASK;
}
else if (pin == 6) {
CORE_PIN6_PORTTOGGLE = CORE_PIN6_BITMASK;
}
else if (pin == 7) {
CORE_PIN7_PORTTOGGLE = CORE_PIN7_BITMASK;
}
else if (pin == 8) {
CORE_PIN8_PORTTOGGLE = CORE_PIN8_BITMASK;
}
else if (pin == 9) {
CORE_PIN9_PORTTOGGLE = CORE_PIN9_BITMASK;
}
else if (pin == 10) {
CORE_PIN10_PORTTOGGLE = CORE_PIN10_BITMASK;
}
else if (pin == 11) {
CORE_PIN11_PORTTOGGLE = CORE_PIN11_BITMASK;
}
else if (pin == 12) {
CORE_PIN12_PORTTOGGLE = CORE_PIN12_BITMASK;
}
else if (pin == 13) {
CORE_PIN13_PORTTOGGLE = CORE_PIN13_BITMASK;
}
else if (pin == 14) {
CORE_PIN14_PORTTOGGLE = CORE_PIN14_BITMASK;
}
else if (pin == 15) {
CORE_PIN15_PORTTOGGLE = CORE_PIN15_BITMASK;
}
else if (pin == 16) {
CORE_PIN16_PORTTOGGLE = CORE_PIN16_BITMASK;
}
else if (pin == 17) {
CORE_PIN17_PORTTOGGLE = CORE_PIN17_BITMASK;
}
else if (pin == 18) {
CORE_PIN18_PORTTOGGLE = CORE_PIN18_BITMASK;
}
else if (pin == 19) {
CORE_PIN19_PORTTOGGLE = CORE_PIN19_BITMASK;
}
else if (pin == 20) {
CORE_PIN20_PORTTOGGLE = CORE_PIN20_BITMASK;
}
else if (pin == 21) {
CORE_PIN21_PORTTOGGLE = CORE_PIN21_BITMASK;
}
else if (pin == 22) {
CORE_PIN22_PORTTOGGLE = CORE_PIN22_BITMASK;
}
else if (pin == 23) {
CORE_PIN23_PORTTOGGLE = CORE_PIN23_BITMASK;
}
else if (pin == 24) {
CORE_PIN24_PORTTOGGLE = CORE_PIN24_BITMASK;
}
else if (pin == 25) {
CORE_PIN25_PORTTOGGLE = CORE_PIN25_BITMASK;
}
else if (pin == 26) {
CORE_PIN26_PORTTOGGLE = CORE_PIN26_BITMASK;
}
#if defined(CORE_PIN27_PORTTOGGLE)
else if (pin == 27) {
CORE_PIN27_PORTTOGGLE = CORE_PIN27_BITMASK;
}
else if (pin == 28) {
CORE_PIN28_PORTTOGGLE = CORE_PIN28_BITMASK;
}
else if (pin == 29) {
CORE_PIN29_PORTTOGGLE = CORE_PIN29_BITMASK;
}
else if (pin == 30) {
CORE_PIN30_PORTTOGGLE = CORE_PIN30_BITMASK;
}
else if (pin == 31) {
CORE_PIN31_PORTTOGGLE = CORE_PIN31_BITMASK;
}
else if (pin == 32) {
CORE_PIN32_PORTTOGGLE = CORE_PIN32_BITMASK;
}
else if (pin == 33) {
CORE_PIN33_PORTTOGGLE = CORE_PIN33_BITMASK;
}
#endif
#if defined(CORE_PIN34_PORTSET)
else if (pin == 34) {
CORE_PIN34_PORTTOGGLE = CORE_PIN34_BITMASK;
}
else if (pin == 35) {
CORE_PIN35_PORTTOGGLE = CORE_PIN35_BITMASK;
}
else if (pin == 36) {
CORE_PIN36_PORTTOGGLE = CORE_PIN36_BITMASK;
}
else if (pin == 37) {
CORE_PIN37_PORTTOGGLE = CORE_PIN37_BITMASK;
}
else if (pin == 38) {
CORE_PIN38_PORTTOGGLE = CORE_PIN38_BITMASK;
}
else if (pin == 39) {
CORE_PIN39_PORTTOGGLE = CORE_PIN39_BITMASK;
}
else if (pin == 40) {
CORE_PIN40_PORTTOGGLE = CORE_PIN40_BITMASK;
}
else if (pin == 41) {
CORE_PIN41_PORTTOGGLE = CORE_PIN41_BITMASK;
}
else if (pin == 42) {
CORE_PIN42_PORTTOGGLE = CORE_PIN42_BITMASK;
}
else if (pin == 43) {
CORE_PIN43_PORTTOGGLE = CORE_PIN43_BITMASK;
}
else if (pin == 44) {
CORE_PIN44_PORTTOGGLE = CORE_PIN44_BITMASK;
}
else if (pin == 45) {
CORE_PIN45_PORTTOGGLE = CORE_PIN45_BITMASK;
}
else if (pin == 46) {
CORE_PIN46_PORTTOGGLE = CORE_PIN46_BITMASK;
}
else if (pin == 47) {
CORE_PIN47_PORTTOGGLE = CORE_PIN47_BITMASK;
}
else if (pin == 48) {
CORE_PIN48_PORTTOGGLE = CORE_PIN48_BITMASK;
}
else if (pin == 49) {
CORE_PIN49_PORTTOGGLE = CORE_PIN49_BITMASK;
}
else if (pin == 50) {
CORE_PIN50_PORTTOGGLE = CORE_PIN50_BITMASK;
}
else if (pin == 51) {
CORE_PIN51_PORTTOGGLE = CORE_PIN51_BITMASK;
}
else if (pin == 52) {
CORE_PIN52_PORTTOGGLE = CORE_PIN52_BITMASK;
}
else if (pin == 53) {
CORE_PIN53_PORTTOGGLE = CORE_PIN53_BITMASK;
}
else if (pin == 54) {
CORE_PIN54_PORTTOGGLE = CORE_PIN54_BITMASK;
}
else if (pin == 55) {
CORE_PIN55_PORTTOGGLE = CORE_PIN55_BITMASK;
}
else if (pin == 56) {
CORE_PIN56_PORTTOGGLE = CORE_PIN56_BITMASK;
}
else if (pin == 57) {
CORE_PIN57_PORTTOGGLE = CORE_PIN57_BITMASK;
}
else if (pin == 58) {
CORE_PIN58_PORTTOGGLE = CORE_PIN58_BITMASK;
}
else if (pin == 59) {
CORE_PIN59_PORTTOGGLE = CORE_PIN59_BITMASK;
}
else if (pin == 60) {
CORE_PIN60_PORTTOGGLE = CORE_PIN60_BITMASK;
}
else if (pin == 61) {
CORE_PIN61_PORTTOGGLE = CORE_PIN61_BITMASK;
}
else if (pin == 62) {
CORE_PIN62_PORTTOGGLE = CORE_PIN62_BITMASK;
}
else if (pin == 63) {
CORE_PIN63_PORTTOGGLE = CORE_PIN63_BITMASK;
}
#endif
}
else {
*portToggleRegister(pin) = digitalPinToBitMask(pin);
}
}

uint8_t digitalRead(uint8_t pin);
static inline uint8_t digitalReadFast(uint8_t pin) __attribute__((always_inline, unused));
static inline uint8_t digitalReadFast(uint8_t pin)

+ 10
- 0
teensy3/pins_teensy.c Näytä tiedosto

@@ -1035,6 +1035,16 @@ void digitalWrite(uint8_t pin, uint8_t val)

}

void digitalToggle(uint8_t pin)
{
if (pin >= CORE_NUM_DIGITAL) return;
#ifdef KINETISK
*portToggleRegister(pin) = 1;
#else
*portToggleRegister(pin) = digitalPinToBitMask(pin);
#endif
}

uint8_t digitalRead(uint8_t pin)
{
if (pin >= CORE_NUM_DIGITAL) return 0;

Loading…
Peruuta
Tallenna