Skip to content

Commit b2c1548

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 b2c1548

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Diff for: cores/arduino/Tone.cpp

+6-3
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

@@ -122,11 +124,12 @@ void noTone(uint8_t _pin, bool destruct)
122124
{
123125
PinName p = digitalPinToPinName(_pin);
124126
if ((p != NC) && (TimerTone_pinInfo.pin == p)) {
125-
timerTonePinDeinit();
126-
127127
if ((destruct) && (TimerTone != NULL)) {
128+
timerTonePinDeinit();
128129
delete (TimerTone);
129130
TimerTone = NULL;
131+
} else {
132+
TimerTone->pause();
130133
}
131134
}
132135
}

0 commit comments

Comments
 (0)