aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino/wiring_digital.c
diff options
context:
space:
mode:
authorDavid A. Mellis <d.mellis@arduino.cc>2010-10-17 17:55:53 -0400
committerDavid A. Mellis <d.mellis@arduino.cc>2010-10-17 17:55:53 -0400
commita4afb42b08555310142d01bbf346285e4fc9bff5 (patch)
tree9fe489e064ce72475a0f1dcc348f5cd66a7f54ed /cores/arduino/wiring_digital.c
parentb861fe903f5a91990667e0eb47d2f83586bd0408 (diff)
Modifying basic functions (digital and analog, read and write) to use register-based ifdefs, not cpu-based.
http://code.google.com/p/arduino/issues/detail?id=307 http://code.google.com/p/arduino/issues/detail?id=316 http://code.google.com/p/arduino/issues/detail?id=323 http://code.google.com/p/arduino/issues/detail?id=324
Diffstat (limited to 'cores/arduino/wiring_digital.c')
-rwxr-xr-xcores/arduino/wiring_digital.c87
1 files changed, 62 insertions, 25 deletions
diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c
index 1475f0c..0949da4 100755
--- a/cores/arduino/wiring_digital.c
+++ b/cores/arduino/wiring_digital.c
@@ -19,6 +19,8 @@
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
+ Modified 28 September 2010 by Mark Sproul
+
$Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
*/
@@ -56,32 +58,67 @@ void pinMode(uint8_t pin, uint8_t mode)
// But shouldn't this be moved into pinMode? Seems silly to check and do on
// each digitalread or write.
//
-static inline void turnOffPWM(uint8_t timer) __attribute__ ((always_inline));
-static inline void turnOffPWM(uint8_t timer)
+// Mark Sproul:
+// - Removed inline. Save 170 bytes on atmega1280
+// - changed to a switch statment; added 32 bytes but much easier to read and maintain.
+// - Added more #ifdefs, now compiles for atmega645
+//
+//static inline void turnOffPWM(uint8_t timer) __attribute__ ((always_inline));
+//static inline void turnOffPWM(uint8_t timer)
+static void turnOffPWM(uint8_t timer)
{
- if (timer == TIMER1A) cbi(TCCR1A, COM1A1);
- if (timer == TIMER1B) cbi(TCCR1A, COM1B1);
-
-#if defined(__AVR_ATmega8__)
- if (timer == TIMER2) cbi(TCCR2, COM21);
-#else
- if (timer == TIMER0A) cbi(TCCR0A, COM0A1);
- if (timer == TIMER0B) cbi(TCCR0A, COM0B1);
- if (timer == TIMER2A) cbi(TCCR2A, COM2A1);
- if (timer == TIMER2B) cbi(TCCR2A, COM2B1);
-#endif
-
-#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
- if (timer == TIMER3A) cbi(TCCR3A, COM3A1);
- if (timer == TIMER3B) cbi(TCCR3A, COM3B1);
- if (timer == TIMER3C) cbi(TCCR3A, COM3C1);
- if (timer == TIMER4A) cbi(TCCR4A, COM4A1);
- if (timer == TIMER4B) cbi(TCCR4A, COM4B1);
- if (timer == TIMER4C) cbi(TCCR4A, COM4C1);
- if (timer == TIMER5A) cbi(TCCR5A, COM5A1);
- if (timer == TIMER5B) cbi(TCCR5A, COM5B1);
- if (timer == TIMER5C) cbi(TCCR5A, COM5C1);
-#endif
+ switch (timer)
+ {
+ #if defined(TCCR1A) && defined(COM1A1)
+ case TIMER1A: cbi(TCCR1A, COM1A1); break;
+ #endif
+ #if defined(TCCR1A) && defined(COM1B1)
+ case TIMER1B: cbi(TCCR1A, COM1B1); break;
+ #endif
+
+ #if defined(TCCR2) && defined(COM21)
+ case TIMER2: cbi(TCCR2, COM21); break;
+ #endif
+
+ #if defined(TCCR0A) && defined(COM0A1)
+ case TIMER0A: cbi(TCCR0A, COM0A1); break;
+ #endif
+
+ #if defined(TIMER0B) && defined(COM0B1)
+ case TIMER0B: cbi(TCCR0A, COM0B1); break;
+ #endif
+ #if defined(TCCR2A) && defined(COM2A1)
+ case TIMER2A: cbi(TCCR2A, COM2A1); break;
+ #endif
+ #if defined(TCCR2A) && defined(COM2B1)
+ case TIMER2B: cbi(TCCR2A, COM2B1); break;
+ #endif
+
+ #if defined(TCCR3A) && defined(COM3A1)
+ case TIMER3A: cbi(TCCR3A, COM3A1); break;
+ #endif
+ #if defined(TCCR3A) && defined(COM3B1)
+ case TIMER3B: cbi(TCCR3A, COM3B1); break;
+ #endif
+ #if defined(TCCR3A) && defined(COM3C1)
+ case TIMER3C: cbi(TCCR3A, COM3C1); break;
+ #endif
+
+ #if defined(TCCR4A) && defined(COM4A1)
+ case TIMER4A: cbi(TCCR4A, COM4A1); break;
+ #endif
+ #if defined(TCCR4A) && defined(COM4B1)
+ case TIMER4B: cbi(TCCR4A, COM4B1); break;
+ #endif
+ #if defined(TCCR4A) && defined(COM4C1)
+ case TIMER4C: cbi(TCCR4A, COM4C1); break;
+ #endif
+ #if defined(TCCR5A)
+ case TIMER5A: cbi(TCCR5A, COM5A1); break;
+ case TIMER5B: cbi(TCCR5A, COM5B1); break;
+ case TIMER5C: cbi(TCCR5A, COM5C1); break;
+ #endif
+ }
}
void digitalWrite(uint8_t pin, uint8_t val)