From 025d2264a2c411961bd9a04becfa8b493cdd5eb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 24 Nov 2022 10:44:43 +0100 Subject: [PATCH] m5stack runs with native tone support now. --- src/buzz/buzz.cpp | 11 +-------- variants/m5stack_core/Speaker.cpp | 33 ------------------------- variants/m5stack_core/Speaker.h | 30 ---------------------- variants/m5stack_core/platformio.ini | 1 - variants/m5stack_core/variant.h | 1 - variants/m5stack_coreink/Speaker.cpp | 33 ------------------------- variants/m5stack_coreink/Speaker.h | 30 ---------------------- variants/m5stack_coreink/platformio.ini | 1 - variants/m5stack_coreink/variant.h | 1 - 9 files changed, 1 insertion(+), 140 deletions(-) delete mode 100644 variants/m5stack_core/Speaker.cpp delete mode 100644 variants/m5stack_core/Speaker.h delete mode 100644 variants/m5stack_coreink/Speaker.cpp delete mode 100644 variants/m5stack_coreink/Speaker.h diff --git a/src/buzz/buzz.cpp b/src/buzz/buzz.cpp index 9bd85f3a5..a7074b0e1 100644 --- a/src/buzz/buzz.cpp +++ b/src/buzz/buzz.cpp @@ -2,10 +2,7 @@ #include "configuration.h" #include "NodeDB.h" -#ifdef M5STACK -#include "Speaker.h" -TONE Tone; -#elif !defined(ARCH_ESP32) +#ifndef ARCH_ESP32 #include "Tone.h" #endif @@ -42,13 +39,7 @@ void playTones(const ToneDuration *tone_durations, int size) { if (config.device.buzzer_gpio) { for (int i = 0; i < size; i++) { const auto &tone_duration = tone_durations[i]; -#ifdef M5STACK - Tone.tone(tone_duration.frequency_khz); - delay(tone_duration.duration_ms); - Tone.mute(); -#else tone(config.device.buzzer_gpio, tone_duration.frequency_khz, tone_duration.duration_ms); -#endif // to distinguish the notes, set a minimum time between them. delay(1.3 * tone_duration.duration_ms); } diff --git a/variants/m5stack_core/Speaker.cpp b/variants/m5stack_core/Speaker.cpp deleted file mode 100644 index 0aaff1238..000000000 --- a/variants/m5stack_core/Speaker.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "Speaker.h" - -TONE::TONE(void) { - _volume = 5; - _begun = false; -} - -void TONE::begin() { - _begun = true; - ledcSetup(TONE_PIN_CHANNEL, 0, 13); - ledcAttachPin(PIN_BUZZER, TONE_PIN_CHANNEL); -} - -void TONE::end() { - mute(); - ledcDetachPin(PIN_BUZZER); - _begun = false; -} - -void TONE::tone(uint16_t frequency) { - if(!_begun) begin(); - ledcWriteTone(TONE_PIN_CHANNEL, frequency); - ledcWrite(TONE_PIN_CHANNEL, 0x400 >> _volume); -} - -void TONE::setVolume(uint8_t volume) { - _volume = 11 - volume; -} - -void TONE::mute() { - ledcWriteTone(TONE_PIN_CHANNEL, 0); - digitalWrite(PIN_BUZZER, 0); -} \ No newline at end of file diff --git a/variants/m5stack_core/Speaker.h b/variants/m5stack_core/Speaker.h deleted file mode 100644 index 2ab877d9b..000000000 --- a/variants/m5stack_core/Speaker.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef _SPEAKER_H_ - #define _SPEAKER_H_ - - #include "configuration.h" - - #ifdef __cplusplus - extern "C" - { - #endif /* __cplusplus */ - #include "esp32-hal-dac.h" - #ifdef __cplusplus - } - #endif /* __cplusplus */ - - class TONE { - public: - TONE(void); - - void begin(); - void end(); - void mute(); - void tone(uint16_t frequency); - void setVolume(uint8_t volume); - - private: - uint8_t _volume; - bool _begun; - bool speaker_on; - }; -#endif diff --git a/variants/m5stack_core/platformio.ini b/variants/m5stack_core/platformio.ini index d1cda8fd8..f84e04785 100644 --- a/variants/m5stack_core/platformio.ini +++ b/variants/m5stack_core/platformio.ini @@ -6,7 +6,6 @@ monitor_port = COM8 monitor_filters = esp32_exception_decoder build_src_filter = ${esp32_base.build_src_filter} - +<../variants/m5stack_core> build_flags = ${esp32_base.build_flags} -I variants/m5stack_core -DILI9341_DRIVER diff --git a/variants/m5stack_core/variant.h b/variants/m5stack_core/variant.h index f33ab08a8..186788f06 100644 --- a/variants/m5stack_core/variant.h +++ b/variants/m5stack_core/variant.h @@ -11,7 +11,6 @@ #define BUTTON_PIN 38 #define PIN_BUZZER 25 -#define TONE_PIN_CHANNEL 0 #undef RF95_SCK #undef RF95_MISO diff --git a/variants/m5stack_coreink/Speaker.cpp b/variants/m5stack_coreink/Speaker.cpp deleted file mode 100644 index 0aaff1238..000000000 --- a/variants/m5stack_coreink/Speaker.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "Speaker.h" - -TONE::TONE(void) { - _volume = 5; - _begun = false; -} - -void TONE::begin() { - _begun = true; - ledcSetup(TONE_PIN_CHANNEL, 0, 13); - ledcAttachPin(PIN_BUZZER, TONE_PIN_CHANNEL); -} - -void TONE::end() { - mute(); - ledcDetachPin(PIN_BUZZER); - _begun = false; -} - -void TONE::tone(uint16_t frequency) { - if(!_begun) begin(); - ledcWriteTone(TONE_PIN_CHANNEL, frequency); - ledcWrite(TONE_PIN_CHANNEL, 0x400 >> _volume); -} - -void TONE::setVolume(uint8_t volume) { - _volume = 11 - volume; -} - -void TONE::mute() { - ledcWriteTone(TONE_PIN_CHANNEL, 0); - digitalWrite(PIN_BUZZER, 0); -} \ No newline at end of file diff --git a/variants/m5stack_coreink/Speaker.h b/variants/m5stack_coreink/Speaker.h deleted file mode 100644 index 2ab877d9b..000000000 --- a/variants/m5stack_coreink/Speaker.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef _SPEAKER_H_ - #define _SPEAKER_H_ - - #include "configuration.h" - - #ifdef __cplusplus - extern "C" - { - #endif /* __cplusplus */ - #include "esp32-hal-dac.h" - #ifdef __cplusplus - } - #endif /* __cplusplus */ - - class TONE { - public: - TONE(void); - - void begin(); - void end(); - void mute(); - void tone(uint16_t frequency); - void setVolume(uint8_t volume); - - private: - uint8_t _volume; - bool _begun; - bool speaker_on; - }; -#endif diff --git a/variants/m5stack_coreink/platformio.ini b/variants/m5stack_coreink/platformio.ini index 796b58e67..06f970dba 100644 --- a/variants/m5stack_coreink/platformio.ini +++ b/variants/m5stack_coreink/platformio.ini @@ -3,7 +3,6 @@ extends = esp32_base board = m5stack-coreink build_src_filter = ${esp32_base.build_src_filter} - +<../variants/m5stack_coreink> build_flags = ${esp32_base.build_flags} -I variants/m5stack_coreink ;-D RADIOLIB_VERBOSE diff --git a/variants/m5stack_coreink/variant.h b/variants/m5stack_coreink/variant.h index 0676fda1c..e5f49c7a8 100644 --- a/variants/m5stack_coreink/variant.h +++ b/variants/m5stack_coreink/variant.h @@ -21,7 +21,6 @@ //BUZZER #define PIN_BUZZER 2 -#define TONE_PIN_CHANNEL 0 #undef RF95_SCK #undef RF95_MISO