summaryrefslogtreecommitdiff
path: root/src/drivers/i2s_dac.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/i2s_dac.cpp')
-rw-r--r--src/drivers/i2s_dac.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/drivers/i2s_dac.cpp b/src/drivers/i2s_dac.cpp
index 4d29f917..e206bd7a 100644
--- a/src/drivers/i2s_dac.cpp
+++ b/src/drivers/i2s_dac.cpp
@@ -88,13 +88,21 @@ I2SDac::I2SDac(IGpios& gpio, i2s_chan_handle_t i2s_handle)
I2S_SLOT_MODE_STEREO)) {
clock_config_.clk_src = I2S_CLK_SRC_APLL;
+ // The amplifier's power rails ramp unevenly, with the negative rail coming
+ // up ~5ms after the positive rail. Ensure that headphone output is muted
+ // during this to avoid a loud pop during power up.
+ gpio_.WriteSync(IGpios::Pin::kAmplifierMute, true);
+ vTaskDelay(pdMS_TO_TICKS(1));
+
gpio_.WriteSync(IGpios::Pin::kAmplifierEnable, true);
// Reset all registers back to their default values.
wm8523::WriteRegister(wm8523::Register::kReset, 1);
+
+ // Wait for DAC reset + analog rails ramp.
vTaskDelay(pdMS_TO_TICKS(10));
- wm8523::WriteRegister(wm8523::Register::kPsCtrl, 0b0);
+ wm8523::WriteRegister(wm8523::Register::kPsCtrl, 0b0);
// Use zero-cross detection for volume changes.
wm8523::WriteRegister(wm8523::Register::kDacCtrl, 0b10000);
}
@@ -103,6 +111,8 @@ I2SDac::~I2SDac() {
Stop();
i2s_del_channel(i2s_handle_);
+ gpio_.WriteSync(IGpios::Pin::kAmplifierMute, true);
+ vTaskDelay(pdMS_TO_TICKS(1));
gpio_.WriteSync(IGpios::Pin::kAmplifierEnable, false);
}
@@ -119,11 +129,13 @@ auto I2SDac::Stop() -> void {
auto I2SDac::SetPaused(bool paused) -> void {
if (paused) {
- gpio_.WriteSync(IGpios::Pin::kAmplifierUnmute, false);
+ gpio_.WriteSync(IGpios::Pin::kAmplifierUnmuteLegacy, false);
+ gpio_.WriteSync(IGpios::Pin::kAmplifierMute, true);
set_channel(false);
} else {
set_channel(true);
- gpio_.WriteSync(IGpios::Pin::kAmplifierUnmute, true);
+ gpio_.WriteSync(IGpios::Pin::kAmplifierUnmuteLegacy, true);
+ gpio_.WriteSync(IGpios::Pin::kAmplifierMute, false);
}
}