Browse Source

Update pins_teensy.c

Add INPUT_PULLDOWN and OUTPUT_OPENDRAIN options for pinMode()
main
Xenoamor 8 years ago
parent
commit
1d197b5b7f
1 changed files with 14 additions and 2 deletions
  1. +14
    -2
      teensy3/pins_teensy.c

+ 14
- 2
teensy3/pins_teensy.c View File

if (pin >= CORE_NUM_DIGITAL) return; if (pin >= CORE_NUM_DIGITAL) return;
config = portConfigRegister(pin); config = portConfigRegister(pin);


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

} }





Loading…
Cancel
Save