diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-10-16 13:52:43 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-10-16 13:52:43 +1100 |
| commit | 7523772886ca37cf05d0ad5b24f6d520e314242e (patch) | |
| tree | ab298342307c1023ef4e1a2a004407ca072dfc25 /src/drivers | |
| parent | 96ea6cef8881d005cb06be8a9132535a5564d5fd (diff) | |
| download | tangara-fw-7523772886ca37cf05d0ad5b24f6d520e314242e.tar.gz | |
Decouple play/pause from output on/off
I think this was the cause of toggling play/pause making audio go away.
Or at least I can't repro that bug anymore, anyway.
Diffstat (limited to 'src/drivers')
| -rw-r--r-- | src/drivers/i2s_dac.cpp | 47 | ||||
| -rw-r--r-- | src/drivers/include/i2s_dac.hpp | 3 |
2 files changed, 25 insertions, 25 deletions
diff --git a/src/drivers/i2s_dac.cpp b/src/drivers/i2s_dac.cpp index b28a8ee1..9ff6e380 100644 --- a/src/drivers/i2s_dac.cpp +++ b/src/drivers/i2s_dac.cpp @@ -111,38 +111,23 @@ I2SDac::~I2SDac() { auto I2SDac::Start() -> void { std::lock_guard<std::mutex> lock(configure_mutex_); - - gpio_.WriteSync(IGpios::Pin::kAmplifierUnmute, false); - - // Ensure the DAC powers up to a muted state. - wm8523::WriteRegister(wm8523::Register::kPsCtrl, 0b10); - - // Enable MCLK; this has the side effect of triggering the DAC's startup - // sequence. - i2s_channel_enable(i2s_handle_); - i2s_active_ = true; - wm8523::WriteRegister(wm8523::Register::kPsCtrl, 0b11); - gpio_.WriteSync(IGpios::Pin::kAmplifierUnmute, true); } auto I2SDac::Stop() -> void { std::lock_guard<std::mutex> lock(configure_mutex_); - - // Mute the DAC. - wm8523::WriteRegister(wm8523::Register::kPsCtrl, 0b10); - vTaskDelay(pdMS_TO_TICKS(5)); - // Silence the output. - gpio_.WriteSync(IGpios::Pin::kAmplifierUnmute, false); - - vTaskDelay(pdMS_TO_TICKS(5)); - - // Turn everything off. + set_channel(false); wm8523::WriteRegister(wm8523::Register::kPsCtrl, 0b0); - i2s_channel_disable(i2s_handle_); - i2s_active_ = false; +} - gpio_.WriteSync(IGpios::Pin::kAmplifierEnable, false); +auto I2SDac::SetPaused(bool paused) -> void { + if (paused) { + gpio_.WriteSync(IGpios::Pin::kAmplifierUnmute, false); + set_channel(false); + } else { + set_channel(true); + gpio_.WriteSync(IGpios::Pin::kAmplifierUnmute, true); + } } auto I2SDac::Reconfigure(Channels ch, BitsPerSample bps, SampleRate rate) @@ -261,4 +246,16 @@ auto I2SDac::SetSource(StreamBufferHandle_t buffer) -> void { } } +auto I2SDac::set_channel(bool enabled) -> void { + if (i2s_active_ == enabled) { + return; + } + i2s_active_ = enabled; + if (enabled) { + i2s_channel_enable(i2s_handle_); + } else { + i2s_channel_disable(i2s_handle_); + } +} + } // namespace drivers diff --git a/src/drivers/include/i2s_dac.hpp b/src/drivers/include/i2s_dac.hpp index b61f7989..d66d9762 100644 --- a/src/drivers/include/i2s_dac.hpp +++ b/src/drivers/include/i2s_dac.hpp @@ -46,6 +46,7 @@ class I2SDac { auto Start() -> void; auto Stop() -> void; + auto SetPaused(bool) -> void; enum Channels { CHANNELS_MONO, @@ -75,6 +76,8 @@ class I2SDac { I2SDac& operator=(const I2SDac&) = delete; private: + auto set_channel(bool) -> void; + IGpios& gpio_; i2s_chan_handle_t i2s_handle_; bool i2s_active_; |
