diff --git a/TimerOne.h b/TimerOne.h index e2b2bd7..1f8dcbc 100644 --- a/TimerOne.h +++ b/TimerOne.h @@ -7,6 +7,7 @@ * Modified again, June 2014 by Paul Stoffregen - support Teensy 3.x & even more AVR chips * Modified July 2017 by Stoyko Dimitrov - added support for ATTiny85 except for the PWM functionality * Modified March 2021 by Hagen Patzke - add ESP32 support for TZXDuino on ODROID-GO + * Modified August 2024 by Nathan Cheek - added support for ATmega128 * * * This is free software. You can redistribute it and/or modify it under @@ -180,7 +181,7 @@ class TimerOne #elif defined(__AVR__) -#if defined (__AVR_ATmega8__) +#if defined (__AVR_ATmega8__) || defined (__AVR_ATmega128__) //in some io definitions for older microcontrollers TIMSK is used instead of TIMSK1 #define TIMSK1 TIMSK #endif @@ -287,14 +288,23 @@ class TimerOne void attachInterrupt(void (*isr)()) __attribute__((always_inline)) { isrCallback = isr; + #if defined(__AVR_ATmega128__) + TIMSK1 |= _BV(TOIE1); + TIMSK1 &= ~(_BV(TICIE1) | _BV(OCIE1A) | _BV(OCIE1B)); + #else TIMSK1 = _BV(TOIE1); + #endif } void attachInterrupt(void (*isr)(), unsigned long microseconds) __attribute__((always_inline)) { if(microseconds > 0) setPeriod(microseconds); attachInterrupt(isr); } void detachInterrupt() __attribute__((always_inline)) { + #if defined(__AVR_ATmega128__) + TIMSK1 &= ~(_BV(TOIE1) | _BV(TICIE1) | _BV(OCIE1A) | _BV(OCIE1B)); + #else TIMSK1 = 0; + #endif } static void (*isrCallback)(); static void isrDefaultUnused(); diff --git a/config/known_16bit_timers.h b/config/known_16bit_timers.h index ec93a45..fa65878 100644 --- a/config/known_16bit_timers.h +++ b/config/known_16bit_timers.h @@ -142,7 +142,15 @@ #define TIMER1_B_PIN 11 //#define TIMER1_ICP_PIN 8 //#define TIMER1_CLK_PIN 5 - + +// ATmega128 +#elif defined (__AVR_ATmega128__) + #define TIMER1_A_PIN 13 // PB5 + #define TIMER1_B_PIN 14 // PB6 + #define TIMER1_C_PIN 15 // PB7 + #define TIMER1_ICP_PIN 22 // PD4 + #define TIMER1_CLK_PIN 24 // PD6 + // Sanguino // #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__) diff --git a/library.properties b/library.properties index 73f4f89..f26893a 100644 --- a/library.properties +++ b/library.properties @@ -1,6 +1,6 @@ name=TimerOne version=1.2 -author=Stoyko Dimitrov, Jesse Tane, Jérôme Despatis, Michael Polli, Dan Clemens, Paul Stoffregen, Hagen Patzke +author=Stoyko Dimitrov, Jesse Tane, Jérôme Despatis, Michael Polli, Dan Clemens, Paul Stoffregen, Hagen Patzke, Nathan Cheek maintainer=Paul Stoffregen sentence=Use hardware Timer1 for finer PWM control and/or running an periodic interrupt function paragraph=