mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-08 14:12:05 +00:00
m5stack runs with native tone support now.
This commit is contained in:
parent
b2284b2097
commit
025d2264a2
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
@ -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
|
@ -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
|
||||
|
@ -11,7 +11,6 @@
|
||||
#define BUTTON_PIN 38
|
||||
|
||||
#define PIN_BUZZER 25
|
||||
#define TONE_PIN_CHANNEL 0
|
||||
|
||||
#undef RF95_SCK
|
||||
#undef RF95_MISO
|
||||
|
@ -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);
|
||||
}
|
@ -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
|
@ -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
|
||||
|
@ -21,7 +21,6 @@
|
||||
|
||||
//BUZZER
|
||||
#define PIN_BUZZER 2
|
||||
#define TONE_PIN_CHANNEL 0
|
||||
|
||||
#undef RF95_SCK
|
||||
#undef RF95_MISO
|
||||
|
Loading…
Reference in New Issue
Block a user