mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-14 11:29:26 +01:00
Fix for tone() on Leonardo.
This commit is contained in:
parent
409da1d9c7
commit
44556206a8
@ -11,6 +11,71 @@
|
|||||||
|
|
||||||
#include "binary.h"
|
#include "binary.h"
|
||||||
|
|
||||||
|
// Workaround for wrong definitions in "iom32u4.h".
|
||||||
|
// This should be fixed in the AVR toolchain.
|
||||||
|
#ifdef __AVR_ATmega32U4__
|
||||||
|
#undef UHCON
|
||||||
|
#undef UHINT
|
||||||
|
#undef UHIEN
|
||||||
|
#undef UHADDR
|
||||||
|
#undef UHFNUM
|
||||||
|
#undef UHFNUML
|
||||||
|
#undef UHFNUMH
|
||||||
|
#undef UHFLEN
|
||||||
|
#undef UPINRQX
|
||||||
|
#undef UPINTX
|
||||||
|
#undef UPNUM
|
||||||
|
#undef UPRST
|
||||||
|
#undef UPCONX
|
||||||
|
#undef UPCFG0X
|
||||||
|
#undef UPCFG1X
|
||||||
|
#undef UPSTAX
|
||||||
|
#undef UPCFG2X
|
||||||
|
#undef UPIENX
|
||||||
|
#undef UPDATX
|
||||||
|
#undef TCCR2A
|
||||||
|
#undef WGM20
|
||||||
|
#undef WGM21
|
||||||
|
#undef COM2B0
|
||||||
|
#undef COM2B1
|
||||||
|
#undef COM2A0
|
||||||
|
#undef COM2A1
|
||||||
|
#undef TCCR2B
|
||||||
|
#undef CS20
|
||||||
|
#undef CS21
|
||||||
|
#undef CS22
|
||||||
|
#undef WGM22
|
||||||
|
#undef FOC2B
|
||||||
|
#undef FOC2A
|
||||||
|
#undef TCNT2
|
||||||
|
#undef TCNT2_0
|
||||||
|
#undef TCNT2_1
|
||||||
|
#undef TCNT2_2
|
||||||
|
#undef TCNT2_3
|
||||||
|
#undef TCNT2_4
|
||||||
|
#undef TCNT2_5
|
||||||
|
#undef TCNT2_6
|
||||||
|
#undef TCNT2_7
|
||||||
|
#undef OCR2A
|
||||||
|
#undef OCR2_0
|
||||||
|
#undef OCR2_1
|
||||||
|
#undef OCR2_2
|
||||||
|
#undef OCR2_3
|
||||||
|
#undef OCR2_4
|
||||||
|
#undef OCR2_5
|
||||||
|
#undef OCR2_6
|
||||||
|
#undef OCR2_7
|
||||||
|
#undef OCR2B
|
||||||
|
#undef OCR2_0
|
||||||
|
#undef OCR2_1
|
||||||
|
#undef OCR2_2
|
||||||
|
#undef OCR2_3
|
||||||
|
#undef OCR2_4
|
||||||
|
#undef OCR2_5
|
||||||
|
#undef OCR2_6
|
||||||
|
#undef OCR2_7
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"{
|
extern "C"{
|
||||||
#endif
|
#endif
|
||||||
|
@ -29,6 +29,7 @@ Version Modified By Date Comments
|
|||||||
09/11/25 Fixed timer0 from being excluded
|
09/11/25 Fixed timer0 from being excluded
|
||||||
0006 D Mellis 09/12/29 Replaced objects with functions
|
0006 D Mellis 09/12/29 Replaced objects with functions
|
||||||
0007 M Sproul 10/08/29 Changed #ifdefs from cpu to register
|
0007 M Sproul 10/08/29 Changed #ifdefs from cpu to register
|
||||||
|
0008 S Kanemoto 12/06/22 Fixed for Leonardo by @maris_HY
|
||||||
*************************************************/
|
*************************************************/
|
||||||
|
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
@ -85,10 +86,10 @@ volatile uint8_t timer5_pin_mask;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// MLS: This does not make sense, the 3 options are the same
|
|
||||||
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
||||||
|
|
||||||
#define AVAILABLE_TONE_PINS 1
|
#define AVAILABLE_TONE_PINS 1
|
||||||
|
#define USE_TIMER2
|
||||||
|
|
||||||
const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 3, 4, 5, 1, 0 */ };
|
const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 3, 4, 5, 1, 0 */ };
|
||||||
static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255, 255, 255, 255, 255 */ };
|
static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255, 255, 255, 255, 255 */ };
|
||||||
@ -96,13 +97,23 @@ static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255, 255, 255, 255, 25
|
|||||||
#elif defined(__AVR_ATmega8__)
|
#elif defined(__AVR_ATmega8__)
|
||||||
|
|
||||||
#define AVAILABLE_TONE_PINS 1
|
#define AVAILABLE_TONE_PINS 1
|
||||||
|
#define USE_TIMER2
|
||||||
|
|
||||||
const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 1 */ };
|
const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 1 */ };
|
||||||
static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255 */ };
|
static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255 */ };
|
||||||
|
|
||||||
|
#elif defined(__AVR_ATmega32U4__)
|
||||||
|
|
||||||
|
#define AVAILABLE_TONE_PINS 1
|
||||||
|
#define USE_TIMER3
|
||||||
|
|
||||||
|
const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 3 /*, 1 */ };
|
||||||
|
static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255 */ };
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define AVAILABLE_TONE_PINS 1
|
#define AVAILABLE_TONE_PINS 1
|
||||||
|
#define USE_TIMER2
|
||||||
|
|
||||||
// Leave timer 0 to last.
|
// Leave timer 0 to last.
|
||||||
const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 1, 0 */ };
|
const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 1, 0 */ };
|
||||||
@ -480,8 +491,7 @@ void noTone(uint8_t _pin)
|
|||||||
digitalWrite(_pin, 0);
|
digitalWrite(_pin, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#ifdef USE_TIMER0
|
||||||
#if !defined(__AVR_ATmega8__)
|
|
||||||
ISR(TIMER0_COMPA_vect)
|
ISR(TIMER0_COMPA_vect)
|
||||||
{
|
{
|
||||||
if (timer0_toggle_count != 0)
|
if (timer0_toggle_count != 0)
|
||||||
@ -501,6 +511,7 @@ ISR(TIMER0_COMPA_vect)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef USE_TIMER1
|
||||||
ISR(TIMER1_COMPA_vect)
|
ISR(TIMER1_COMPA_vect)
|
||||||
{
|
{
|
||||||
if (timer1_toggle_count != 0)
|
if (timer1_toggle_count != 0)
|
||||||
@ -520,6 +531,7 @@ ISR(TIMER1_COMPA_vect)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef USE_TIMER2
|
||||||
ISR(TIMER2_COMPA_vect)
|
ISR(TIMER2_COMPA_vect)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -541,12 +553,10 @@ ISR(TIMER2_COMPA_vect)
|
|||||||
// *timer2_pin_port &= ~(timer2_pin_mask); // keep pin low after stop
|
// *timer2_pin_port &= ~(timer2_pin_mask); // keep pin low after stop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef USE_TIMER3
|
||||||
//#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
ISR(TIMER3_COMPA_vect)
|
ISR(TIMER3_COMPA_vect)
|
||||||
{
|
{
|
||||||
if (timer3_toggle_count != 0)
|
if (timer3_toggle_count != 0)
|
||||||
@ -563,7 +573,10 @@ ISR(TIMER3_COMPA_vect)
|
|||||||
*timer3_pin_port &= ~(timer3_pin_mask); // keep pin low after stop
|
*timer3_pin_port &= ~(timer3_pin_mask); // keep pin low after stop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef USE_TIMER4
|
||||||
ISR(TIMER4_COMPA_vect)
|
ISR(TIMER4_COMPA_vect)
|
||||||
{
|
{
|
||||||
if (timer4_toggle_count != 0)
|
if (timer4_toggle_count != 0)
|
||||||
@ -580,7 +593,10 @@ ISR(TIMER4_COMPA_vect)
|
|||||||
*timer4_pin_port &= ~(timer4_pin_mask); // keep pin low after stop
|
*timer4_pin_port &= ~(timer4_pin_mask); // keep pin low after stop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef USE_TIMER5
|
||||||
ISR(TIMER5_COMPA_vect)
|
ISR(TIMER5_COMPA_vect)
|
||||||
{
|
{
|
||||||
if (timer5_toggle_count != 0)
|
if (timer5_toggle_count != 0)
|
||||||
@ -597,5 +613,4 @@ ISR(TIMER5_COMPA_vect)
|
|||||||
*timer5_pin_port &= ~(timer5_pin_mask); // keep pin low after stop
|
*timer5_pin_port &= ~(timer5_pin_mask); // keep pin low after stop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user