Ver código fonte

Merge pull request #114 from Xenoamor/master

Add OUTPUT_OPENDRAIN, INPUT_PULLDOWN for pinMode()
teensy4-core
Paul Stoffregen 9 anos atrás
pai
commit
fbd1b36d11
3 arquivos alterados com 21 adições e 2 exclusões
  1. +5
    -0
      keywords.txt
  2. +2
    -0
      teensy3/core_pins.h
  3. +14
    -2
      teensy3/pins_teensy.c

+ 5
- 0
keywords.txt Ver arquivo

@@ -66,6 +66,11 @@ digitalPinHasPWM KEYWORD2
NOT_AN_INTERRUPT LITERAL1
digitalPinToInterrupt KEYWORD2

# Teensy 3.x advanced pin states
OUTPUT_OPENDRAIN LITERAL1
INPUT_PULLUP LITERAL1
INPUT_PULLDOWN LITERAL1

# String functions
copy KEYWORD2
append KEYWORD2

+ 2
- 0
teensy3/core_pins.h Ver arquivo

@@ -40,6 +40,8 @@
#define INPUT 0
#define OUTPUT 1
#define INPUT_PULLUP 2
#define INPUT_PULLDOWN 3
#define OUTPUT_OPENDRAIN 4
#define LSBFIRST 0
#define MSBFIRST 1
#define _BV(n) (1<<(n))

+ 14
- 2
teensy3/pins_teensy.c Ver arquivo

@@ -983,25 +983,37 @@ void pinMode(uint8_t pin, uint8_t mode)
if (pin >= CORE_NUM_DIGITAL) return;
config = portConfigRegister(pin);

if (mode == OUTPUT) {
if (mode == OUTPUT || mode == OUTPUT_OPENDRAIN) {
#ifdef KINETISK
*portModeRegister(pin) = 1;
#else
*portModeRegister(pin) |= digitalPinToBitMask(pin); // TODO: atomic
#endif
*config = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
if (mode == OUTPUT_OPENDRAIN) {
*config |= PORT_PCR_ODE;
} else {
*config &= ~PORT_PCR_ODE;
}
} else {
#ifdef KINETISK
*portModeRegister(pin) = 0;
#else
*portModeRegister(pin) &= ~digitalPinToBitMask(pin);
#endif
if (mode == INPUT) {
if (mode == INPUT || mode == INPUT_PULLUP || mode == INPUT_PULLDOWN) {
*config = PORT_PCR_MUX(1);
if (mode == INPUT_PULLUP) {
*config |= (PORT_PCR_PE | PORT_PCR_PS); // pullup
} else if (mode == INPUT_PULLDOWN) {
*config |= (PORT_PCR_PE); // pulldown
*config &= ~(PORT_PCR_PS);
}
} else {
*config = PORT_PCR_MUX(1) | PORT_PCR_PE | PORT_PCR_PS; // pullup
}
}

}



Carregando…
Cancelar
Salvar