1
1
/*
2
2
Tone.cpp
3
-
3
+
4
4
A Tone Generator Library for the ESP8266
5
-
5
+
6
6
Original Copyright (c) 2016 Ben Pirt. All rights reserved.
7
7
This file is part of the esp8266 core for Arduino environment.
8
-
8
+
9
9
This library is free software; you can redistribute it and/or
10
10
modify it under the terms of the GNU Lesser General Public
11
11
License as published by the Free Software Foundation; either
12
12
version 2.1 of the License, or (at your option) any later version.
13
-
13
+
14
14
This library is distributed in the hope that it will be useful,
15
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
17
Lesser General Public License for more details.
18
-
18
+
19
19
You should have received a copy of the GNU Lesser General Public
20
20
License along with this library; if not, write to the Free Software
21
21
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
@@ -34,7 +34,9 @@ static void _startTone(uint8_t _pin, uint32_t high, uint32_t low, uint32_t durat
34
34
return ;
35
35
}
36
36
37
- pinMode (_pin, OUTPUT);
37
+ if (!(_toneMap & 1UL << _pin)) {
38
+ pinMode (_pin, OUTPUT);
39
+ }
38
40
39
41
high = std::max (high, (uint32_t )microsecondsToClockCycles (25 )); // new 20KHz maximum tone frequency,
40
42
low = std::max (low, (uint32_t )microsecondsToClockCycles (25 )); // (25us high + 25us low period = 20KHz)
@@ -43,7 +45,7 @@ static void _startTone(uint8_t _pin, uint32_t high, uint32_t low, uint32_t durat
43
45
duration += high + low - 1 ;
44
46
duration -= duration % (high + low);
45
47
if (startWaveformClockCycles (_pin, high, low, duration)) {
46
- _toneMap |= 1 << _pin;
48
+ _toneMap |= 1UL << _pin;
47
49
}
48
50
}
49
51
@@ -86,6 +88,6 @@ void noTone(uint8_t _pin) {
86
88
return ;
87
89
}
88
90
stopWaveform (_pin);
89
- _toneMap &= ~(1 << _pin);
91
+ _toneMap &= ~(1UL << _pin);
90
92
digitalWrite (_pin, 0 );
91
93
}
0 commit comments