[gnoduino: 230/237] Adding INPUT_PULLUP option pinMode(). (Paul Stoffregen).
- From: Lucian Langa <lucilanga src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnoduino: 230/237] Adding INPUT_PULLUP option pinMode(). (Paul Stoffregen).
- Date: Sat, 31 Mar 2012 20:34:10 +0000 (UTC)
commit a16fe1f50cefc224b3d2d56ec9cde59950fd40c7
Author: David A. Mellis <d mellis arduino cc>
Date: Mon Jan 2 14:20:28 2012 -0500
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
arduino/cores/arduino/Arduino.h | 1 +
arduino/cores/arduino/wiring_digital.c | 10 +++++++++-
2 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/arduino/cores/arduino/Arduino.h b/arduino/cores/arduino/Arduino.h
index bfec943..830c995 100755
--- a/arduino/cores/arduino/Arduino.h
+++ b/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/arduino/cores/arduino/wiring_digital.c b/arduino/cores/arduino/wiring_digital.c
index 97ef134..584a28a 100755
--- a/arduino/cores/arduino/wiring_digital.c
+++ b/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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]