Skip to content

Commit 80dfa09

Browse files
committed
Fix tone after rework of HardwareTimer
When timerTonePinDeinit() is called, it will deinitialize timer. It is then necessary to recreate HardwareTimer object to initialize timer. So, when NoTone() is called, without destruct, only pause the timer. Also when frequency is null just pause the timer.
1 parent 7e682d2 commit 80dfa09

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Diff for: cores/arduino/Tone.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ static void timerTonePinInit(PinName p, uint32_t frequency, uint32_t duration)
8181

8282
if (frequency <= MAX_FREQ) {
8383
if (frequency == 0) {
84-
timerTonePinDeinit();
84+
if (TimerTone != NULL) {
85+
TimerTone->pause();
86+
}
8587
} else {
8688
TimerTone_pinInfo.pin = p;
8789

@@ -121,12 +123,13 @@ void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
121123
void noTone(uint8_t _pin, bool destruct)
122124
{
123125
PinName p = digitalPinToPinName(_pin);
124-
if ((p != NC) && (TimerTone_pinInfo.pin == p)) {
125-
timerTonePinDeinit();
126-
127-
if ((destruct) && (TimerTone != NULL)) {
126+
if ((p != NC) && (TimerTone_pinInfo.pin == p) && (TimerTone != NULL)) {
127+
if (destruct) {
128+
timerTonePinDeinit();
128129
delete (TimerTone);
129130
TimerTone = NULL;
131+
} else {
132+
TimerTone->pause();
130133
}
131134
}
132135
}

0 commit comments

Comments
 (0)