diff --git a/src/BuildOpt.h b/src/BuildOpt.h index f3f0d538..adafecf3 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -128,7 +128,10 @@ #define RADIOLIB_PROGMEM_READ_BYTE(addr) pgm_read_byte(addr) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + + // ESP32 doesn't support tone(), but it can be emulated via LED control peripheral #define RADIOLIB_TONE_UNSUPPORTED + #define RADIOLIB_TONE_ESP32_CHANNEL (1) #elif defined(ARDUINO_ARCH_STM32) // official STM32 Arduino core (https://github.com/stm32duino/Arduino_Core_STM32) diff --git a/src/Module.cpp b/src/Module.cpp index fe419e92..2205b326 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -344,12 +344,9 @@ void Module::tone(RADIOLIB_PIN_TYPE pin, uint16_t value) { ::tone(pin, value); #else #if defined(ESP32) - // ESP32 - emulate tone() via LED driver on channel 15 - if(ledcRead(15)) { - return; - } - ledcAttachPin(pin, 15); - ledcWriteTone(15, value); + // ESP32 tone() emulation + ledcAttachPin(pin, RADIOLIB_TONE_ESP32_CHANNEL); + ledcWriteTone(RADIOLIB_TONE_ESP32_CHANNEL, value); #endif #endif } @@ -364,7 +361,7 @@ void Module::noTone(RADIOLIB_PIN_TYPE pin) { #else #if defined(ESP32) ledcDetachPin(pin); - ledcWrite(15, 0); + ledcWrite(RADIOLIB_TONE_ESP32_CHANNEL, 0); #endif #endif }