Improve DAC startup for r6

custom
jacqueline 2 years ago
parent 394e3e9466
commit 079b2b53d4
  1. 30
      src/drivers/i2s_dac.cpp
  2. 3
      src/drivers/include/gpios.hpp
  3. 1
      src/drivers/include/i2s_dac.hpp
  4. 4
      src/system_fsm/booting.cpp

@ -12,6 +12,7 @@
#include <cmath> #include <cmath>
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
#include <mutex>
#include "assert.h" #include "assert.h"
#include "driver/i2c.h" #include "driver/i2c.h"
@ -100,11 +101,14 @@ I2SDac::~I2SDac() {
} }
auto I2SDac::Start() -> void { auto I2SDac::Start() -> void {
std::lock_guard<std::mutex> lock(configure_mutex_);
gpio_->WriteSync(IGpios::Pin::kAmplifierUnmute, false);
// Ramp up the amplifier power supply. // Ramp up the amplifier power supply.
gpio_->WriteSync(IGpios::Pin::kAmplifierEnable, true); gpio_->WriteSync(IGpios::Pin::kAmplifierEnable, true);
// Wait for voltage to stabilise // Wait for voltage to stabilise
vTaskDelay(pdMS_TO_TICKS(1)); vTaskDelay(pdMS_TO_TICKS(5));
// Ensure the DAC powers up to a muted state. // Ensure the DAC powers up to a muted state.
wm8523::WriteRegister(wm8523::Register::kPsCtrl, 0b10); wm8523::WriteRegister(wm8523::Register::kPsCtrl, 0b10);
@ -112,26 +116,40 @@ auto I2SDac::Start() -> void {
// Enable MCLK; this has the side effect of triggering the DAC's startup // Enable MCLK; this has the side effect of triggering the DAC's startup
// sequence. // sequence.
i2s_channel_enable(i2s_handle_); i2s_channel_enable(i2s_handle_);
i2s_active_ = true;
// Wait for DAC output lines to stabilise // Wait for DAC output lines to stabilise
vTaskDelay(pdMS_TO_TICKS(1)); vTaskDelay(pdMS_TO_TICKS(5));
// FIXME: Pull the amp's EN pin here.
wm8523::WriteRegister(wm8523::Register::kPsCtrl, 0b11); wm8523::WriteRegister(wm8523::Register::kPsCtrl, 0b11);
i2s_active_ = true;
vTaskDelay(pdMS_TO_TICKS(5));
gpio_->WriteSync(IGpios::Pin::kAmplifierUnmute, true);
} }
auto I2SDac::Stop() -> void { 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.
wm8523::WriteRegister(wm8523::Register::kPsCtrl, 0b0); wm8523::WriteRegister(wm8523::Register::kPsCtrl, 0b0);
i2s_channel_disable(i2s_handle_); i2s_channel_disable(i2s_handle_);
i2s_active_ = false;
gpio_->WriteSync(IGpios::Pin::kAmplifierEnable, false); gpio_->WriteSync(IGpios::Pin::kAmplifierEnable, false);
i2s_active_ = false;
} }
auto I2SDac::Reconfigure(Channels ch, BitsPerSample bps, SampleRate rate) auto I2SDac::Reconfigure(Channels ch, BitsPerSample bps, SampleRate rate)
-> void { -> void {
std::lock_guard<std::mutex> lock(configure_mutex_);
if (i2s_active_) { if (i2s_active_) {
// Ramp down into mute instead of just outright stopping to minimise any // Ramp down into mute instead of just outright stopping to minimise any
// clicks and pops. // clicks and pops.

@ -54,7 +54,8 @@ class IGpios {
kPhoneDetect = 8, kPhoneDetect = 8,
kAmplifierEnable = 9, kAmplifierEnable = 9,
kSdCardDetect = 10, kSdCardDetect = 10,
// 11 through 15 are unused kAmplifierUnmute = 11,
// 12 through 15 are unused
}; };
/* Nicer value names for use with kSdMuxSwitch. */ /* Nicer value names for use with kSdMuxSwitch. */

@ -73,6 +73,7 @@ class I2SDac {
i2s_chan_handle_t i2s_handle_; i2s_chan_handle_t i2s_handle_;
bool i2s_active_; bool i2s_active_;
StreamBufferHandle_t buffer_; StreamBufferHandle_t buffer_;
std::mutex configure_mutex_;
i2s_std_clk_config_t clock_config_; i2s_std_clk_config_t clock_config_;
i2s_std_slot_config_t slot_config_; i2s_std_slot_config_t slot_config_;

@ -80,8 +80,8 @@ auto Booting::entry() -> void {
true, NULL, battery_timer_cb); true, NULL, battery_timer_cb);
xTimerStart(battery_timer, portMAX_DELAY); xTimerStart(battery_timer, portMAX_DELAY);
ESP_LOGI(kTag, "starting bluetooth"); // ESP_LOGI(kTag, "starting bluetooth");
sBluetooth.reset(new drivers::Bluetooth(sNvs.get())); // sBluetooth.reset(new drivers::Bluetooth(sNvs.get()));
// sBluetooth->Enable(); // sBluetooth->Enable();
// At this point we've done all of the essential boot tasks. Start remaining // At this point we've done all of the essential boot tasks. Start remaining

Loading…
Cancel
Save