From 09eacb71f0740dba94345ce452d7c4a2c9cdd47f Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 9 Jan 2024 14:17:58 +1100 Subject: [PATCH] bringup r8 muting --- src/drivers/gpios.cpp | 6 +++--- src/drivers/i2s_dac.cpp | 18 +++++++++++++++--- src/drivers/include/gpios.hpp | 5 +++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/drivers/gpios.cpp b/src/drivers/gpios.cpp index e5560665..5c255204 100644 --- a/src/drivers/gpios.cpp +++ b/src/drivers/gpios.cpp @@ -37,13 +37,13 @@ static const uint8_t kPortADefault = 0b00111110; // 0 - 3.5mm jack detect (active low) // 1 - headphone amp power enable // 2 - sd card detect -// 3 - NC -// 4 - NC +// 3 - amplifier unmute (revisions < r8) +// 4 - amplifier mute (revisions >= r8) // 5 - NC // 6 - NC // 7 - NC // Default inputs high, amp off. -static const uint8_t kPortBDefault = 0b00000101; +static const uint8_t kPortBDefault = 0b00001101; /* * Convenience mehod for packing the port a and b bytes into a single 16 bit 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); } } diff --git a/src/drivers/include/gpios.hpp b/src/drivers/include/gpios.hpp index fe4b1c4c..55486be7 100644 --- a/src/drivers/include/gpios.hpp +++ b/src/drivers/include/gpios.hpp @@ -55,8 +55,9 @@ class IGpios { kPhoneDetect = 8, kAmplifierEnable = 9, kSdCardDetect = 10, - kAmplifierUnmute = 11, - // 12 through 15 are unused + kAmplifierUnmuteLegacy = 11, + kAmplifierMute = 12, + // 13 through 15 are unused }; /* Nicer value names for use with kSdMuxSwitch. */