@@ -29,6 +29,7 @@ Version Modified By Date Comments
29
29
09/11/25 Fixed timer0 from being excluded
30
30
0006 D Mellis 09/12/29 Replaced objects with functions
31
31
0007 M Sproul 10/08/29 Changed #ifdefs from cpu to register
32
+ 0008 S Kanemoto 12/06/22 Fixed for Leonardo by @maris_HY
32
33
*************************************************/
33
34
34
35
#include < avr/interrupt.h>
@@ -85,24 +86,34 @@ volatile uint8_t timer5_pin_mask;
85
86
#endif
86
87
87
88
88
- // MLS: This does not make sense, the 3 options are the same
89
89
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
90
90
91
91
#define AVAILABLE_TONE_PINS 1
92
+ #define USE_TIMER2
92
93
93
94
const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /* , 3, 4, 5, 1, 0 */ };
94
95
static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /* , 255, 255, 255, 255, 255 */ };
95
96
96
97
#elif defined(__AVR_ATmega8__)
97
98
98
99
#define AVAILABLE_TONE_PINS 1
100
+ #define USE_TIMER2
99
101
100
102
const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /* , 1 */ };
101
103
static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /* , 255 */ };
102
104
105
+ #elif defined(__AVR_ATmega32U4__)
106
+
107
+ #define AVAILABLE_TONE_PINS 1
108
+ #define USE_TIMER3
109
+
110
+ const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 3 /* , 1 */ };
111
+ static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /* , 255 */ };
112
+
103
113
#else
104
114
105
115
#define AVAILABLE_TONE_PINS 1
116
+ #define USE_TIMER2
106
117
107
118
// Leave timer 0 to last.
108
119
const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /* , 1, 0 */ };
@@ -480,8 +491,7 @@ void noTone(uint8_t _pin)
480
491
digitalWrite (_pin, 0 );
481
492
}
482
493
483
- #if 0
484
- #if !defined(__AVR_ATmega8__)
494
+ #ifdef USE_TIMER0
485
495
ISR (TIMER0_COMPA_vect)
486
496
{
487
497
if (timer0_toggle_count != 0 )
@@ -501,6 +511,7 @@ ISR(TIMER0_COMPA_vect)
501
511
#endif
502
512
503
513
514
+ #ifdef USE_TIMER1
504
515
ISR (TIMER1_COMPA_vect)
505
516
{
506
517
if (timer1_toggle_count != 0 )
@@ -520,6 +531,7 @@ ISR(TIMER1_COMPA_vect)
520
531
#endif
521
532
522
533
534
+ #ifdef USE_TIMER2
523
535
ISR (TIMER2_COMPA_vect)
524
536
{
525
537
@@ -541,12 +553,10 @@ ISR(TIMER2_COMPA_vect)
541
553
// *timer2_pin_port &= ~(timer2_pin_mask); // keep pin low after stop
542
554
}
543
555
}
556
+ #endif
544
557
545
558
546
-
547
- // #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
548
- #if 0
549
-
559
+ #ifdef USE_TIMER3
550
560
ISR (TIMER3_COMPA_vect)
551
561
{
552
562
if (timer3_toggle_count != 0 )
@@ -563,7 +573,10 @@ ISR(TIMER3_COMPA_vect)
563
573
*timer3_pin_port &= ~(timer3_pin_mask); // keep pin low after stop
564
574
}
565
575
}
576
+ #endif
577
+
566
578
579
+ #ifdef USE_TIMER4
567
580
ISR (TIMER4_COMPA_vect)
568
581
{
569
582
if (timer4_toggle_count != 0 )
@@ -580,7 +593,10 @@ ISR(TIMER4_COMPA_vect)
580
593
*timer4_pin_port &= ~(timer4_pin_mask); // keep pin low after stop
581
594
}
582
595
}
596
+ #endif
583
597
598
+
599
+ #ifdef USE_TIMER5
584
600
ISR (TIMER5_COMPA_vect)
585
601
{
586
602
if (timer5_toggle_count != 0 )
@@ -597,5 +613,4 @@ ISR(TIMER5_COMPA_vect)
597
613
*timer5_pin_port &= ~(timer5_pin_mask); // keep pin low after stop
598
614
}
599
615
}
600
-
601
616
#endif
0 commit comments