From 76c964d32b13f1fc01e3a5b07460d96f2dcaecd6 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Mon, 2 Jan 2012 14:20:28 -0500 Subject: [PATCH] Adding INPUT_PULLUP option pinMode(). (Paul Stoffregen). This also changes pinMode(pin, INPUT); to explicitly disable the pull-up resistor, even if it was previously set. http://code.google.com/p/arduino/issues/detail?id=246 --- build/shared/lib/keywords.txt | 1 + hardware/arduino/cores/arduino/Arduino.h | 1 + hardware/arduino/cores/arduino/wiring_digital.c | 10 +++++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/build/shared/lib/keywords.txt b/build/shared/lib/keywords.txt index 730de4e75..74fb064e5 100644 --- a/build/shared/lib/keywords.txt +++ b/build/shared/lib/keywords.txt @@ -3,6 +3,7 @@ HIGH LITERAL1 Constants LOW LITERAL1 Constants INPUT LITERAL1 Constants +INPUT_PULLUP LITERAL1 Constants OUTPUT LITERAL1 Constants DEC LITERAL1 Serial_Print BIN LITERAL1 Serial_Print diff --git a/hardware/arduino/cores/arduino/Arduino.h b/hardware/arduino/cores/arduino/Arduino.h index bfec9437e..830c9952f 100755 --- a/hardware/arduino/cores/arduino/Arduino.h +++ b/hardware/arduino/cores/arduino/Arduino.h @@ -20,6 +20,7 @@ extern "C"{ #define INPUT 0x0 #define OUTPUT 0x1 +#define INPUT_PULLUP 0x2 #define true 0x1 #define false 0x0 diff --git a/hardware/arduino/cores/arduino/wiring_digital.c b/hardware/arduino/cores/arduino/wiring_digital.c index 97ef1343d..584a28a23 100755 --- a/hardware/arduino/cores/arduino/wiring_digital.c +++ b/hardware/arduino/cores/arduino/wiring_digital.c @@ -32,17 +32,25 @@ void pinMode(uint8_t pin, uint8_t mode) { uint8_t bit = digitalPinToBitMask(pin); uint8_t port = digitalPinToPort(pin); - volatile uint8_t *reg; + volatile uint8_t *reg, *out; if (port == NOT_A_PIN) return; // JWS: can I let the optimizer do this? reg = portModeRegister(port); + out = portOutputRegister(port); if (mode == INPUT) { uint8_t oldSREG = SREG; cli(); *reg &= ~bit; + *out &= ~bit; + SREG = oldSREG; + } else if (mode == INPUT_PULLUP) { + uint8_t oldSREG = SREG; + cli(); + *reg &= ~bit; + *out |= bit; SREG = oldSREG; } else { uint8_t oldSREG = SREG;