aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino/wiring_digital.c
diff options
context:
space:
mode:
authorDavid A. Mellis <d.mellis@arduino.cc>2011-02-11 19:29:46 -0500
committerDavid A. Mellis <d.mellis@arduino.cc>2011-02-11 19:29:46 -0500
commiteed15e48d68d10426e015515ec4143849739f2de (patch)
tree4fc54101c58590a6c1c7225a60d223797f4e198b /cores/arduino/wiring_digital.c
parent3696fa044687542ee6b4a9bc488348e184ee3ae2 (diff)
Changes to optimized digitalWrte(), etc.
Factoring out the implementation of digitalWrite(), digitalRead(), and pinMode() into macros that can either be inlined (for constant pin numbers) or executed within a function (non-constant pins). Removing testing for timers on pins in digitalWrite(), digitalRead(), and pinMode(). Moving pin to port macros from pins_arduino.h to wiring.h.
Diffstat (limited to 'cores/arduino/wiring_digital.c')
-rwxr-xr-xcores/arduino/wiring_digital.c76
1 files changed, 4 insertions, 72 deletions
diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c
index 95666b1..9671045 100755
--- a/cores/arduino/wiring_digital.c
+++ b/cores/arduino/wiring_digital.c
@@ -27,28 +27,9 @@
#include "wiring_private.h"
#include "pins_arduino.h"
-void pinMode_lookup(uint8_t pin, uint8_t mode)
+void pinMode_lookup(uint8_t pin, uint8_t val)
{
- uint8_t bit = digitalPinToBitMask(pin);
- uint8_t port = digitalPinToPort(pin);
- volatile uint8_t *reg;
-
- if (port == NOT_A_PIN) return;
-
- // JWS: can I let the optimizer do this?
- reg = portModeRegister(port);
-
- if (mode == INPUT) {
- uint8_t oldSREG = SREG;
- cli();
- *reg &= ~bit;
- SREG = oldSREG;
- } else {
- uint8_t oldSREG = SREG;
- cli();
- *reg |= bit;
- SREG = oldSREG;
- }
+ pinMode_implementation(pin, val);
}
// Forcing this inline keeps the callers from having to push their own stuff
@@ -121,61 +102,12 @@ static void turnOffPWM(uint8_t timer)
}
}
-void __digitalWriteOR_locked(volatile uint8_t*out, uint8_t bit)
-{
- uint8_t oldSREG = SREG;
- cli();
- *out |= bit;
- SREG=oldSREG;
-}
-
-void __digitalWriteAND_locked(volatile uint8_t*out, uint8_t bit)
-{
- uint8_t oldSREG = SREG;
- cli();
- *out &= bit; // NOTE - no inversion here, invert before calling!!!
- SREG=oldSREG;
-}
-
void digitalWrite_lookup(uint8_t pin, uint8_t val)
{
- uint8_t timer = digitalPinToTimer(pin);
- uint8_t bit = digitalPinToBitMask(pin);
- uint8_t port = digitalPinToPort(pin);
- volatile uint8_t *out;
-
- if (port == NOT_A_PIN) return;
-
- // If the pin that support PWM output, we need to turn it off
- // before doing a digital write.
- if (timer != NOT_ON_TIMER) turnOffPWM(timer);
-
- out = portOutputRegister(port);
-
- uint8_t oldSREG = SREG;
- cli();
-
- if (val == LOW) {
- *out &= ~bit;
- } else {
- *out |= bit;
- }
-
- SREG = oldSREG;
+ digitalWrite_implementation(pin, val);
}
int digitalRead_lookup(uint8_t pin)
{
- uint8_t timer = digitalPinToTimer(pin);
- uint8_t bit = digitalPinToBitMask(pin);
- uint8_t port = digitalPinToPort(pin);
-
- if (port == NOT_A_PIN) return LOW;
-
- // If the pin that support PWM output, we need to turn it off
- // before getting a digital reading.
- if (timer != NOT_ON_TIMER) turnOffPWM(timer);
-
- if (*portInputRegister(port) & bit) return HIGH;
- return LOW;
+ digitalRead_implementation(pin);
}