aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino/wiring_digital.c
diff options
context:
space:
mode:
authorDavid A. Mellis <d.mellis@arduino.cc>2011-02-11 17:53:24 -0500
committerDavid A. Mellis <d.mellis@arduino.cc>2011-02-11 17:53:24 -0500
commit3696fa044687542ee6b4a9bc488348e184ee3ae2 (patch)
treecef1d63cc3361f6ad0be727b8248d181edccded3 /cores/arduino/wiring_digital.c
parent11dd06436d6144420cc6f5b5d9a926e7f34818b1 (diff)
Optimized digitalWrite(), etc. from Alvaro Lopez.
Diffstat (limited to 'cores/arduino/wiring_digital.c')
-rwxr-xr-xcores/arduino/wiring_digital.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c
index 0949da4..95666b1 100755
--- a/cores/arduino/wiring_digital.c
+++ b/cores/arduino/wiring_digital.c
@@ -27,7 +27,7 @@
#include "wiring_private.h"
#include "pins_arduino.h"
-void pinMode(uint8_t pin, uint8_t mode)
+void pinMode_lookup(uint8_t pin, uint8_t mode)
{
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
@@ -121,7 +121,23 @@ static void turnOffPWM(uint8_t timer)
}
}
-void digitalWrite(uint8_t pin, uint8_t val)
+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);
@@ -136,20 +152,19 @@ void digitalWrite(uint8_t pin, uint8_t val)
out = portOutputRegister(port);
+ uint8_t oldSREG = SREG;
+ cli();
+
if (val == LOW) {
- uint8_t oldSREG = SREG;
- cli();
*out &= ~bit;
- SREG = oldSREG;
} else {
- uint8_t oldSREG = SREG;
- cli();
*out |= bit;
- SREG = oldSREG;
}
+
+ SREG = oldSREG;
}
-int digitalRead(uint8_t pin)
+int digitalRead_lookup(uint8_t pin)
{
uint8_t timer = digitalPinToTimer(pin);
uint8_t bit = digitalPinToBitMask(pin);