[MOD] Use custom tone() on Arduino mbed boards (#407)
This commit is contained in:
parent
97f3b94c4f
commit
1d42f1a0ff
2 changed files with 32 additions and 0 deletions
|
@ -512,6 +512,10 @@
|
|||
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
|
||||
#define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
|
||||
|
||||
// Arduino mbed OS boards have a really bad tone implementation which will crash after a couple seconds
|
||||
#define RADIOLIB_TONE_UNSUPPORTED
|
||||
#define RADIOLIB_MBED_TONE_OVERRIDE
|
||||
|
||||
// Arduino API callbacks
|
||||
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, pin_size_t pin, PinMode mode)
|
||||
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, pin_size_t pin, PinStatus val)
|
||||
|
@ -546,6 +550,10 @@
|
|||
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
|
||||
#define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
|
||||
|
||||
// Arduino mbed OS boards have a really bad tone implementation which will crash after a couple seconds
|
||||
#define RADIOLIB_TONE_UNSUPPORTED
|
||||
#define RADIOLIB_MBED_TONE_OVERRIDE
|
||||
|
||||
// Arduino API callbacks
|
||||
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, pin_size_t pin, PinMode mode)
|
||||
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, pin_size_t pin, PinStatus val)
|
||||
|
@ -648,6 +656,10 @@
|
|||
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
|
||||
#define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
|
||||
|
||||
// Arduino mbed OS boards have a really bad tone implementation which will crash after a couple seconds
|
||||
#define RADIOLIB_TONE_UNSUPPORTED
|
||||
#define RADIOLIB_MBED_TONE_OVERRIDE
|
||||
|
||||
// Arduino API callbacks
|
||||
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, pin_size_t pin, PinMode mode)
|
||||
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, pin_size_t pin, PinStatus val)
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
#include "Module.h"
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
|
||||
// we need this to emulate tone() on mbed Arduino boards
|
||||
#if defined(ARDUINO_ARDUINO_NANO33BLE)
|
||||
#include "mbed.h"
|
||||
mbed::PwmOut *pwmPin = NULL;
|
||||
#endif
|
||||
|
||||
Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio):
|
||||
_cs(cs),
|
||||
_irq(irq),
|
||||
|
@ -271,8 +278,17 @@ void Module::tone(RADIOLIB_PIN_TYPE pin, uint16_t value, uint32_t duration) {
|
|||
}
|
||||
#if defined(ESP32)
|
||||
// ESP32 tone() emulation
|
||||
(void)duration;
|
||||
ledcAttachPin(pin, RADIOLIB_TONE_ESP32_CHANNEL);
|
||||
ledcWriteTone(RADIOLIB_TONE_ESP32_CHANNEL, value);
|
||||
#elif defined(RADIOLIB_MBED_TONE_OVERRIDE)
|
||||
// better tone for mbed OS boards
|
||||
(void)duration;
|
||||
if(!pwmPin) {
|
||||
pwmPin = new mbed::PwmOut(digitalPinToPinName(pin));
|
||||
}
|
||||
pwmPin->period(1.0 / value);
|
||||
pwmPin->write(0.5);
|
||||
#else
|
||||
(void)value;
|
||||
(void)duration;
|
||||
|
@ -298,6 +314,10 @@ void Module::noTone(RADIOLIB_PIN_TYPE pin) {
|
|||
// ESP32 tone() emulation
|
||||
ledcDetachPin(pin);
|
||||
ledcWrite(RADIOLIB_TONE_ESP32_CHANNEL, 0);
|
||||
#elif defined(RADIOLIB_MBED_TONE_OVERRIDE)
|
||||
// better tone for mbed OS boards
|
||||
(void)pin;
|
||||
pwmPin->suspend();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue