aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino/wiring_digital.c
diff options
context:
space:
mode:
authorDavid A. Mellis <d.mellis@arduino.cc>2012-01-02 14:20:28 -0500
committerDavid A. Mellis <d.mellis@arduino.cc>2012-01-02 14:20:28 -0500
commit6c00397e22021762851511a0a9b6f914db81deca (patch)
tree1171a9e870c2d87a82b0c1df2928a2a5c641dbe0 /cores/arduino/wiring_digital.c
parent3b962be2730265dd27220b801fc9bceb92220977 (diff)
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
Diffstat (limited to 'cores/arduino/wiring_digital.c')
-rwxr-xr-xcores/arduino/wiring_digital.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c
index 97ef134..584a28a 100755
--- a/cores/arduino/wiring_digital.c
+++ b/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;