From 4b55ee14efcbd05d8c2162db1f347f465da73b87 Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Sat, 12 Mar 2016 17:42:30 +0200 Subject: [PATCH 1/2] Allow indefinite duration for `tone()` Bugfix: the `duration` parameter should be optional, per [`tone()`](https://www.arduino.cc/en/Reference/Tone) docs. --- cores/esp8266/Tone.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cores/esp8266/Tone.cpp b/cores/esp8266/Tone.cpp index 9d262e3bb0..19c8817c92 100644 --- a/cores/esp8266/Tone.cpp +++ b/cores/esp8266/Tone.cpp @@ -114,10 +114,14 @@ void noTone(uint8_t _pin) { } void t1IntHandler() { - if (toggle_counts[T1INDEX] > 0){ + if (toggle_counts[T1INDEX] != 0){ // toggle the pin digitalWrite(tone_pins[T1INDEX], toggle_counts[T1INDEX] % 2); toggle_counts[T1INDEX]--; + // handle the case of indefinite duration + if (toggle_counts[T1INDEX] < -2){ + toggle_counts[T1INDEX] = -1; + } }else{ disableTimer(T1INDEX); digitalWrite(tone_pins[T1INDEX], LOW); From 748f3f93fa18b9e057e91e542d3e432296df5205 Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Sat, 12 Mar 2016 19:21:32 +0200 Subject: [PATCH 2/2] Fix crashes when using `tone()` Mark `t1IntHandler()` with ICACHE_RAM_ATTR --- cores/esp8266/Tone.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp8266/Tone.cpp b/cores/esp8266/Tone.cpp index 19c8817c92..bcdd358a85 100644 --- a/cores/esp8266/Tone.cpp +++ b/cores/esp8266/Tone.cpp @@ -113,7 +113,7 @@ void noTone(uint8_t _pin) { digitalWrite(_pin, LOW); } -void t1IntHandler() { +ICACHE_RAM_ATTR void t1IntHandler() { if (toggle_counts[T1INDEX] != 0){ // toggle the pin digitalWrite(tone_pins[T1INDEX], toggle_counts[T1INDEX] % 2);