cleanup sound

This commit is contained in:
Stephen Crane 2018-09-06 13:25:24 +01:00
parent 6b0f1c387d
commit 96440c61f5
2 changed files with 12 additions and 4 deletions

View File

@ -3,17 +3,19 @@
#include "timed.h"
#include "sound.h"
static Sound *s;
#if defined(DAC_SOUND) && defined(ESP_PLATFORM)
#include <driver/dac.h>
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);
}

View File

@ -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