diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 8273cd3f..5ea12a5e 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -18,6 +18,7 @@ * RADIOLIB_NC - alias for unused pin, usually the largest possible value of RADIOLIB_PIN_TYPE. * RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED - defined if the specific platform does not support SoftwareSerial. * RADIOLIB_HARDWARE_SERIAL_PORT - which hardware serial port should be used on platform that do not have SoftwareSerial support. + * RADIOLIB_TONE_UNSUPPORTED - some platforms do not have tone()/noTone(), which is required for AFSK. * * In addition, some platforms may require RadioLib to disable specific drivers (such as ESP8266). */ @@ -52,6 +53,7 @@ #define RADIOLIB_NC (0xFF) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + #define RADIOLIB_TONE_UNSUPPORTED #elif defined(ARDUINO_ARCH_STM32) // official STM32 Arduino core (https://github.com/stm32duino/Arduino_Core_STM32) @@ -85,6 +87,7 @@ #define RADIOLIB_NC (0xFFFFFFFF) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + #define RADIOLIB_TONE_UNSUPPORTED #elif (defined(NRF52832_XXAA) || defined(NRF52840_XXAA)) && !defined(ARDUINO_ARDUINO_NANO33BLE) // Adafruit nRF52 boards @@ -123,6 +126,7 @@ #define RADIOLIB_NC (0xFF) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + #define RADIOLIB_TONE_UNSUPPORTED #elif defined(ARDUINO_ARDUINO_NANO33BLE) // Arduino Nano 33 BLE @@ -148,6 +152,7 @@ #define RADIOLIB_NC (0xFF) #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED #define RADIOLIB_HARDWARE_SERIAL_PORT Serial1 + #define RADIOLIB_TONE_UNSUPPORTED #else // other platforms not covered by the above list - this may or may not work diff --git a/src/Module.cpp b/src/Module.cpp index 8482e32c..67ac9ac8 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -294,3 +294,19 @@ RADIOLIB_PIN_STATUS Module::digitalRead(RADIOLIB_PIN_TYPE pin) { } return(LOW); } + +void Module::tone(RADIOLIB_PIN_TYPE pin, uint16_t value) { + #ifndef RADIOLIB_TONE_UNSUPPORTED + if(pin != RADIOLIB_NC) { + ::tone(pin, value); + } + #endif +} + +void Module::noTone(RADIOLIB_PIN_TYPE pin) { + #ifndef RADIOLIB_TONE_UNSUPPORTED + if(pin != RADIOLIB_NC) { + ::noTone(pin); + } + #endif +} diff --git a/src/Module.h b/src/Module.h index ebc81986..f6855a05 100644 --- a/src/Module.h +++ b/src/Module.h @@ -368,6 +368,22 @@ class Module { */ static RADIOLIB_PIN_STATUS digitalRead(RADIOLIB_PIN_TYPE pin); + /*! + \brief Arduino core tone override that checks RADIOLIB_NC as alias for unused pin and RADIOLIB_TONE_UNSUPPORTED to make sure the platform does support tone. + + \param pin Pin to write to. + + \param value Frequency to output. + */ + static void tone(RADIOLIB_PIN_TYPE pin, uint16_t value); + + /*! + \brief Arduino core noTone override that checks RADIOLIB_NC as alias for unused pin and RADIOLIB_TONE_UNSUPPORTED to make sure the platform does support tone. + + \param pin Pin to write to. + */ + static void noTone(RADIOLIB_PIN_TYPE pin); + #ifndef RADIOLIB_GODMODE private: #endif