From 96440c61f56430ca7b2eceea6af87b37048f6a05 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Thu, 6 Sep 2018 13:25:24 +0100 Subject: [PATCH] cleanup sound --- sound.cpp | 11 +++++++---- sound.h | 5 +++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/sound.cpp b/sound.cpp index 87840c2..d803d98 100644 --- a/sound.cpp +++ b/sound.cpp @@ -3,17 +3,19 @@ #include "timed.h" #include "sound.h" +static Sound *s; + #if defined(DAC_SOUND) && defined(ESP_PLATFORM) #include static portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED; - static dac_channel_t channel; -static volatile const uint8_t *_bytes; -static volatile unsigned _size, _off; - void IRAM_ATTR timer_callback() { + s->on_tick(); +} + +void IRAM_ATTR Sound::on_tick() { portENTER_CRITICAL_ISR(&mux); if (_off < _size) @@ -32,6 +34,7 @@ void Sound::begin(unsigned pin, unsigned freq) { else if (pin == 26) channel = DAC_CHANNEL_2; + s = this; timer_create(freq, &timer_callback); } diff --git a/sound.h b/sound.h index a3a6ed5..b4af0cd 100644 --- a/sound.h +++ b/sound.h @@ -5,6 +5,11 @@ class Sound { public: void begin(unsigned pin, unsigned freq); const uint8_t *play(const uint8_t *bytes, unsigned size); + void on_tick(); + +private: + volatile const uint8_t *_bytes; + volatile unsigned _size, _off; }; #endif