diff --git a/Makefile b/Makefile index 282fca5..fd45a25 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,7 @@ MCU_TARGET = atmega644p # MCU_TARGET = atmega1280 # MCU_TARGET = atmega2560 # MCU_TARGET = at90usb1287 +# MCU_TARGET = atmega32u4 # CPU clock rate F_CPU = 16000000L @@ -109,7 +110,14 @@ LIBDEPS = SUBDIRS = ifneq (,$(findstring usb,$(MCU_TARGET))) +USE_LUFA = true +endif +ifneq (,$(findstring u4,$(MCU_TARGET))) +USE_LUFA = true +endif +ifdef USE_LUFA LDFLAGS += -Llufa_serial + LIBS += -llufa_serial SUBDIRS += lufa_serial LIBDEPS += lufa_serial/liblufa_serial.a diff --git a/arduino.h b/arduino.h index 3598e75..5c01ae1 100644 --- a/arduino.h +++ b/arduino.h @@ -86,6 +86,10 @@ #include "arduino_usb1287.h" #endif +#if defined (__AVR_ATmega32U4__) + #include "arduino_32U4.h" +#endif + #ifndef DIO0_PIN #error pins for this chip not defined in arduino.h! If you write an appropriate pin definition and have this firmware work on your chip, please tell us via the forum thread #endif diff --git a/heater.c b/heater.c index 10c5a65..62d5981 100644 --- a/heater.c +++ b/heater.c @@ -125,15 +125,25 @@ void heater_init() { #endif #endif #ifdef TCCR4A - case (uint16_t) &OCR4AL: - TCCR4A |= MASK(COM4A1); - break; - case (uint16_t) &OCR4BL: - TCCR4A |= MASK(COM4B1); - break; - case (uint16_t) &OCR4CL: - TCCR4A |= MASK(COM4C1); - break; + #if defined (OCR4AL) + case (uint16_t) &OCR4AL: + TCCR4A |= MASK(COM4A1); + break; + case (uint16_t) &OCR4BL: + TCCR4A |= MASK(COM4B1); + break; + case (uint16_t) &OCR4CL: + TCCR4A |= MASK(COM4C1); + break; + #else + // 10 bit timer + case (uint16_t) &OCR4A: + TCCR4A |= MASK(COM4A1); + break; + case (uint16_t) &OCR4B: + TCCR4A |= MASK(COM4B1); + break; + #endif #endif #ifdef TCCR5A case (uint16_t) &OCR5AL: diff --git a/mendel.c b/mendel.c index 5997b0b..3e66890 100644 --- a/mendel.c +++ b/mendel.c @@ -184,7 +184,8 @@ void io_init(void) { SET_OUTPUT(E_ENABLE_PIN); #endif - // setup PWM timers: fast PWM, no prescaler + // setup PWM timers: fast PWM + // Warning 2012-01-11: these are not consistent across all AVRs TCCR0A = MASK(WGM01) | MASK(WGM00); // PWM frequencies in TCCR0B, see page 108 of the ATmega644 reference. TCCR0B = MASK(CS00); // F_CPU / 256 (about 78(62.5) kHz on a 20(16) MHz chip) @@ -222,8 +223,14 @@ void io_init(void) { #endif #ifdef TCCR4A - TCCR4A = MASK(WGM40); - TCCR4B = MASK(WGM42) | MASK(CS40); + #ifdef TIMER4_IS_10_BIT + // ATmega16/32U4 fourth timer is a 10 special bit timer + TCCR4D = MASK(WGM40); + TCCR4B = MASK(CS40); + #else + TCCR4A = MASK(WGM40); + TCCR4B = MASK(WGM42) | MASK(CS40); + #endif TIMSK4 = 0; OCR4A = 0; OCR4B = 0;