Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] RTTTL feature was not working with ESP32 IDF 5.x #5213

Open
wants to merge 9 commits into
base: mega
Choose a base branch
from
2 changes: 2 additions & 0 deletions lib/AnyRtttl/CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Changes for 2.3

* New feature: Official support for ESP8266 and ESP32.
* Fixed issue #2 - Support for PROGMEM / FLASH melodies in non-blocking mode.
* Fixed issue #6 - Error compiling for board ESP32 Wrover Kit (all versions).


Changes for 2.2.1:
Expand Down
7 changes: 5 additions & 2 deletions lib/AnyRtttl/examples/ESP32Rtttl/ESP32Rtttl.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const char arkanoid[] PROGMEM = "Arkanoid:d=4,o=5,b=140:8g6,16p,16g.6,2a#6,32p,8
const char mario[] PROGMEM = "mario:d=4,o=5,b=140:16e6,16e6,32p,8e6,16c6,8e6,8g6,8p,8g,8p,8c6,16p,8g,16p,8e,16p,8a,8b,16a#,8a,16g.,16e6,16g6,8a6,16f6,8g6,8e6,16c6,16d6,8b,16p,8c6,16p,8g,16p,8e,16p,8a,8b,16a#,8a,16g.,16e6,16g6,8a6,16f6,8g6,8e6,16c6,16d6,8b,8p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16c7,16p,16c7,16c7,p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16d#6,8p,16d6,8p,16c6";
// James Bond theme defined in inline code below (also stored in flash memory)

#ifdef ESP32
// tone() and noTone() are not implemented for Arduino core for the ESP32
// See https://github.com/espressif/arduino-esp32/issues/980
// and https://github.com/espressif/arduino-esp32/issues/1720
Expand All @@ -24,17 +25,19 @@ void esp32Tone(uint8_t pin, unsigned int frq, unsigned long duration) {
}

void esp32ToneSetup(uint8_t pin) {
ledcSetup(0, 1000, 10); // resolution always seems to be 10bit, no matter what is given
ledcAttachPin(pin, 0);
ledcAttach(pin, 1000, 10); // resolution always seems to be 10bit, no matter what is given
}
#endif

void setup() {
pinMode(BUZZER_PIN, OUTPUT);

#ifdef ESP32
// setup AnyRtttl for ESP32
esp32ToneSetup(BUZZER_PIN);
anyrtttl::setToneFunction(&esp32Tone);
anyrtttl::setNoToneFunction(&esp32NoTone);
#endif

Serial.begin(115200);

Expand Down
4 changes: 2 additions & 2 deletions lib/AnyRtttl/src/anyrtttl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ namespace anyrtttl
* Description:
* Defines a function pointer to a tone() function
****************************************************************************/
typedef void (*ToneFuncPtr)(uint8_t _pin, unsigned int, unsigned long);
typedef void (*ToneFuncPtr)(uint8_t pin, unsigned int frequency, unsigned long duration);

/****************************************************************************
* Description:
* Defines a function pointer to a noTone() function
****************************************************************************/
typedef void (*NoToneFuncPtr)(uint8_t);
typedef void (*NoToneFuncPtr)(uint8_t pin);

/****************************************************************************
* Description:
Expand Down
22 changes: 11 additions & 11 deletions lib/AnyRtttl/src/binrtttl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,16 @@ uint16_t getBpmsCount()
return gNoteBpmsCount;
}

BPM_INDEX findBpmIndex(RTTTL_BPM n)
{
for(BPM_INDEX i=0; i<gNoteBpmsCount; i++)
{
if (getBpmFromIndex(i) == n)
{
return i;
}
}
return INVALID_BPM_INDEX;
}
// BPM_INDEX findBpmIndex(RTTTL_BPM n)
// {
// for(BPM_INDEX i=0; i<gNoteBpmsCount; i++)
// {
// if (getBpmFromIndex(i) == n)
// {
// return i;
// }
// }
// return INVALID_BPM_INDEX;
// }

}; //anyrtttl namespace
4 changes: 2 additions & 2 deletions lib/AnyRtttl/src/binrtttl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ typedef unsigned char BPM_INDEX;
// static DURATION_INDEX INVALID_DURATION_INDEX = (DURATION_INDEX)-1;
// static NOTE_LETTER_INDEX INVALID_NOTE_LETTER_INDEX = (NOTE_LETTER_INDEX)-1;
// static OCTAVE_INDEX INVALID_OCTAVE_INDEX = (OCTAVE_INDEX)-1;
static BPM_INDEX INVALID_BPM_INDEX = (BPM_INDEX)-1;
// static BPM_INDEX INVALID_BPM_INDEX = (BPM_INDEX)-1;

typedef unsigned short RTTTL_DURATION;
typedef char RTTTL_NOTE_LETTER;
Expand Down Expand Up @@ -100,7 +100,7 @@ OCTAVE_INDEX findNoteOctaveIndex(RTTTL_OCTAVE_VALUE n);
//allowed values: 25, 28, 31, 35, 40, 45, 50, 56, 63, 70, 80, 90, 100, 112, 125, 140, 160, 180, 200, 225, 250, 285, 320, 355, 400, 450, 500, 565, 635, 715, 800 and 900.
RTTTL_BPM getBpmFromIndex(BPM_INDEX iIndex);
uint16_t getBpmsCount();
BPM_INDEX findBpmIndex(RTTTL_BPM n);
// BPM_INDEX findBpmIndex(RTTTL_BPM n); // tonhuisman: Disabled as we don't use this, and we can avoid a compilation warning

}; //anyrtttl namespace

Expand Down
30 changes: 15 additions & 15 deletions platformio_esp32_envs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ lib_ignore = ${esp32_always.lib_ignore}
build_flags = ${esp32_common.build_flags}
-DFEATURE_ARDUINO_OTA=1
-DPLUGIN_BUILD_NORMAL_IRext
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1
extra_scripts = ${esp32_common.extra_scripts}
pre:tools/pio/ir_build_check.py

Expand Down Expand Up @@ -199,55 +199,55 @@ board = esp32_4M
build_flags = ${esp32_common.build_flags}
-DFEATURE_ARDUINO_OTA=1
-DPLUGIN_SET_COLLECTION_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_B_ESP32_4M316k]
extends = esp32_common
board = esp32_4M
build_flags = ${esp32_common.build_flags}
-DFEATURE_ARDUINO_OTA=1
-DPLUGIN_SET_COLLECTION_B_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_C_ESP32_4M316k]
extends = esp32_common
board = esp32_4M
build_flags = ${esp32_common.build_flags}
-DFEATURE_ARDUINO_OTA=1
-DPLUGIN_SET_COLLECTION_C_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_D_ESP32_4M316k]
extends = esp32_common
board = esp32_4M
build_flags = ${esp32_common.build_flags}
-DFEATURE_ARDUINO_OTA=1
-DPLUGIN_SET_COLLECTION_D_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_E_ESP32_4M316k]
extends = esp32_common
board = esp32_4M
build_flags = ${esp32_common.build_flags}
-DFEATURE_ARDUINO_OTA=1
-DPLUGIN_SET_COLLECTION_E_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_F_ESP32_4M316k]
extends = esp32_common
board = esp32_4M
build_flags = ${esp32_common.build_flags}
-DFEATURE_ARDUINO_OTA=1
-DPLUGIN_SET_COLLECTION_F_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_G_ESP32_4M316k]
extends = esp32_common
board = esp32_4M
build_flags = ${esp32_common.build_flags}
-DFEATURE_ARDUINO_OTA=1
-DPLUGIN_SET_COLLECTION_G_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1


[env:collection_A_ESP32_IRExt_4M316k]
Expand Down Expand Up @@ -382,43 +382,43 @@ build_flags = ${esp32_IRExt.build_flags}
extends = env:collection_A_ESP32_4M316k
build_flags = ${env:collection_A_ESP32_4M316k.build_flags}
-DFEATURE_ETHERNET=1
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_B_ESP32_4M316k_ETH]
extends = env:collection_B_ESP32_4M316k
build_flags = ${env:collection_B_ESP32_4M316k.build_flags}
-DFEATURE_ETHERNET=1
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_C_ESP32_4M316k_ETH]
extends = env:collection_C_ESP32_4M316k
build_flags = ${env:collection_C_ESP32_4M316k.build_flags}
-DFEATURE_ETHERNET=1
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_D_ESP32_4M316k_ETH]
extends = env:collection_D_ESP32_4M316k
build_flags = ${env:collection_D_ESP32_4M316k.build_flags}
-DFEATURE_ETHERNET=1
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_E_ESP32_4M316k_ETH]
extends = env:collection_E_ESP32_4M316k
build_flags = ${env:collection_E_ESP32_4M316k.build_flags}
-DFEATURE_ETHERNET=1
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_F_ESP32_4M316k_ETH]
extends = env:collection_F_ESP32_4M316k
build_flags = ${env:collection_F_ESP32_4M316k.build_flags}
-DFEATURE_ETHERNET=1
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_G_ESP32_4M316k_ETH]
extends = env:collection_G_ESP32_4M316k
build_flags = ${env:collection_G_ESP32_4M316k.build_flags}
-DFEATURE_ETHERNET=1
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:energy_ESP32_4M316k_ETH]
extends = env:energy_ESP32_4M316k
Expand Down
14 changes: 7 additions & 7 deletions platformio_esp32c3_envs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -86,49 +86,49 @@ extends = esp32c3_common
board = esp32c3cdc
build_flags = ${esp32c3_common.build_flags}
-DPLUGIN_SET_COLLECTION_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_B_ESP32c3_4M316k_CDC]
extends = esp32c3_common
board = esp32c3cdc
build_flags = ${esp32c3_common.build_flags}
-DPLUGIN_SET_COLLECTION_B_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_C_ESP32c3_4M316k_CDC]
extends = esp32c3_common
board = esp32c3cdc
build_flags = ${esp32c3_common.build_flags}
-DPLUGIN_SET_COLLECTION_C_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_D_ESP32c3_4M316k_CDC]
extends = esp32c3_common
board = esp32c3cdc
build_flags = ${esp32c3_common.build_flags}
-DPLUGIN_SET_COLLECTION_D_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_E_ESP32c3_4M316k_CDC]
extends = esp32c3_common
board = esp32c3cdc
build_flags = ${esp32c3_common.build_flags}
-DPLUGIN_SET_COLLECTION_E_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_F_ESP32c3_4M316k_CDC]
extends = esp32c3_common
board = esp32c3cdc
build_flags = ${esp32c3_common.build_flags}
-DPLUGIN_SET_COLLECTION_F_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_G_ESP32c3_4M316k_CDC]
extends = esp32c3_common
board = esp32c3cdc
build_flags = ${esp32c3_common.build_flags}
-DPLUGIN_SET_COLLECTION_G_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1


[env:energy_ESP32c3_4M316k_CDC]
Expand Down
14 changes: 7 additions & 7 deletions platformio_esp32s2_envs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -102,49 +102,49 @@ extends = esp32s2_common
board = esp32s2cdc
build_flags = ${esp32s2_common.build_flags}
-DPLUGIN_SET_COLLECTION_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_B_ESP32s2_4M316k_CDC]
extends = esp32s2_common
board = esp32s2cdc
build_flags = ${esp32s2_common.build_flags}
-DPLUGIN_SET_COLLECTION_B_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_C_ESP32s2_4M316k_CDC]
extends = esp32s2_common
board = esp32s2cdc
build_flags = ${esp32s2_common.build_flags}
-DPLUGIN_SET_COLLECTION_C_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_D_ESP32s2_4M316k_CDC]
extends = esp32s2_common
board = esp32s2cdc
build_flags = ${esp32s2_common.build_flags}
-DPLUGIN_SET_COLLECTION_D_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_E_ESP32s2_4M316k_CDC]
extends = esp32s2_common
board = esp32s2cdc
build_flags = ${esp32s2_common.build_flags}
-DPLUGIN_SET_COLLECTION_E_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_F_ESP32s2_4M316k_CDC]
extends = esp32s2_common
board = esp32s2cdc
build_flags = ${esp32s2_common.build_flags}
-DPLUGIN_SET_COLLECTION_F_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_G_ESP32s2_4M316k_CDC]
extends = esp32s2_common
board = esp32s2cdc
build_flags = ${esp32s2_common.build_flags}
-DPLUGIN_SET_COLLECTION_G_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1


[env:energy_ESP32s2_4M316k_CDC]
Expand Down
14 changes: 7 additions & 7 deletions platformio_esp32s3_envs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -66,49 +66,49 @@ extends = esp32s3_common
board = esp32s3cdc-qio_qspi
build_flags = ${esp32s3_common.build_flags}
-DPLUGIN_SET_COLLECTION_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_B_ESP32s3_4M316k_CDC]
extends = esp32s3_common
board = esp32s3cdc-qio_qspi
build_flags = ${esp32s3_common.build_flags}
-DPLUGIN_SET_COLLECTION_B_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_C_ESP32s3_4M316k_CDC]
extends = esp32s3_common
board = esp32s3cdc-qio_qspi
build_flags = ${esp32s3_common.build_flags}
-DPLUGIN_SET_COLLECTION_C_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_D_ESP32s3_4M316k_CDC]
extends = esp32s3_common
board = esp32s3cdc-qio_qspi
build_flags = ${esp32s3_common.build_flags}
-DPLUGIN_SET_COLLECTION_D_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_E_ESP32s3_4M316k_CDC]
extends = esp32s3_common
board = esp32s3cdc-qio_qspi
build_flags = ${esp32s3_common.build_flags}
-DPLUGIN_SET_COLLECTION_E_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_F_ESP32s3_4M316k_CDC]
extends = esp32s3_common
board = esp32s3cdc-qio_qspi
build_flags = ${esp32s3_common.build_flags}
-DPLUGIN_SET_COLLECTION_F_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1

[env:collection_G_ESP32s3_4M316k_CDC]
extends = esp32s3_common
board = esp32s3cdc-qio_qspi
build_flags = ${esp32s3_common.build_flags}
-DPLUGIN_SET_COLLECTION_G_ESP32
-DCOLLECTION_USE_RTTTL
-DCOLLECTION_FEATURE_RTTTL=1


[env:energy_ESP32s3_4M316k_CDC]
Expand Down
Loading