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
This commit is contained in:
David A. Mellis 2012-01-02 14:20:28 -05:00
parent 3b962be273
commit 6c00397e22
2 changed files with 10 additions and 1 deletions

View File

@ -20,6 +20,7 @@ extern "C"{
#define INPUT 0x0
#define OUTPUT 0x1
#define INPUT_PULLUP 0x2
#define true 0x1
#define false 0x0

View File

@ -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;