Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OUTPUT_OPENDRAIN, INPUT_PULLDOWN for pinMode() #114

Merged
merged 3 commits into from
Feb 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions teensy3/core_pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
16 changes: 14 additions & 2 deletions teensy3/pins_teensy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not to nitpick, but the indentation's off a bit! Nice addition, though :)

} 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
}
}

}


Expand Down