1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-17 12:02:15 +03:00

Compatibility and IRQ fixed for waveform/tone/pwm (#4872)

* Compatibility and IRQ fixed for waveform/tone/pwm

Fix a compiler ambiguity introduced with a floating point frequency option
for tone().  Thanks to @Rob58329 for discovering this and proposing the
fix.

Match original analogWrite behavior by going from 0...1023 (PWMRANGE) and
not 0...1024, and also explicitly set the analogWrite pin to an OUTPUT.
Thanks to @jandrassy for finding this.

Fixes #4380 discovered by @cranphin where interrupts were disabled on a
stopWaveform().  Remove that completely and bracket the update of non-atomic
fields in the structure with disable/enable IRQs for safety.

* Fix tone(int,int,int) infinite loop

Explicitly cast the frequency, when passed in as an int, to an
unsigned int.  Verified with snippet:
  tone(D1, (int)1000, 500);
  tone(D1, (unsigned int)1000, 500);
  tone(D1, 1000.0, 500);
  tone(D1, (int)1000);
  tone(D1, (unsigned int)1000);
  tone(D1, 1000.0);
This commit is contained in:
Earle F. Philhower, III
2018-07-02 11:02:49 -06:00
committed by Develo
parent 1eb0645dcb
commit be7a732b9d
4 changed files with 22 additions and 6 deletions

View File

@ -70,6 +70,13 @@ void tone(uint8_t _pin, double frequency, unsigned long duration) {
}
// Fix ambiguous tone() binding when adding in a duration
void tone(uint8_t _pin, int frequency, unsigned long duration) {
// Call the unsigned int version of the function explicitly
tone(_pin, (unsigned int)frequency, duration);
}
void noTone(uint8_t _pin) {
if (_pin > 16) {
return;