mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-15 12:29:26 +01:00
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:
parent
5088b09f2d
commit
76c964d32b
@ -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
|
||||
|
@ -20,6 +20,7 @@ extern "C"{
|
||||
|
||||
#define INPUT 0x0
|
||||
#define OUTPUT 0x1
|
||||
#define INPUT_PULLUP 0x2
|
||||
|
||||
#define true 0x1
|
||||
#define false 0x0
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user