summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-08-21 15:43:23 +1000
committerjacqueline <me@jacqueline.id.au>2023-08-21 15:43:23 +1000
commit764b01e913d0123747757e5efd3545d46e921848 (patch)
tree76f0a1d2afb4b60818cc46fd5649938713f2f261 /src/drivers
parent27f329a9dbf18a046ade534c9330b03e586cdb98 (diff)
downloadtangara-fw-764b01e913d0123747757e5efd3545d46e921848.tar.gz
Add idle->standby support when locked and no music
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/i2s_dac.cpp26
-rw-r--r--src/drivers/include/touchwheel.hpp2
-rw-r--r--src/drivers/touchwheel.cpp6
3 files changed, 22 insertions, 12 deletions
diff --git a/src/drivers/i2s_dac.cpp b/src/drivers/i2s_dac.cpp
index 885321d1..679c40b2 100644
--- a/src/drivers/i2s_dac.cpp
+++ b/src/drivers/i2s_dac.cpp
@@ -91,9 +91,7 @@ I2SDac::I2SDac(IGpios* gpio, i2s_chan_handle_t i2s_handle)
// Reset all registers back to their default values.
wm8523::WriteRegister(wm8523::Register::kReset, 1);
vTaskDelay(pdMS_TO_TICKS(10));
-
- // Power up the charge pump.
- wm8523::WriteRegister(wm8523::Register::kPsCtrl, 0b01);
+ wm8523::WriteRegister(wm8523::Register::kPsCtrl, 0b0);
}
I2SDac::~I2SDac() {
@@ -102,24 +100,28 @@ I2SDac::~I2SDac() {
}
auto I2SDac::Start() -> void {
+ // Ramp up the amplifier power supply.
gpio_->WriteSync(IGpios::Pin::kAmplifierEnable, true);
+
+ // Wait for voltage to stabilise
vTaskDelay(pdMS_TO_TICKS(1));
- wm8523::WriteRegister(wm8523::Register::kPsCtrl, 0b10);
- uint8_t zeroes[256]{0};
- size_t bytes_loaded = 0;
- esp_err_t res = ESP_OK;
- do {
- res = i2s_channel_preload_data(i2s_handle_, zeroes, 256, &bytes_loaded);
- } while (bytes_loaded > 0 && res == ESP_OK);
+ // Ensure the DAC powers up to a muted state.
+ wm8523::WriteRegister(wm8523::Register::kPsCtrl, 0b10);
- wm8523::WriteRegister(wm8523::Register::kPsCtrl, 0b11);
+ // Enable MCLK; this has the side effect of triggering the DAC's startup
+ // sequence.
i2s_channel_enable(i2s_handle_);
+
+ // Wait for DAC output lines to stabilise
+ vTaskDelay(pdMS_TO_TICKS(1));
+
+ // FIXME: Pull the amp's EN pin here.
i2s_active_ = true;
}
auto I2SDac::Stop() -> void {
- wm8523::WriteRegister(wm8523::Register::kPsCtrl, 0b01);
+ wm8523::WriteRegister(wm8523::Register::kPsCtrl, 0b0);
i2s_channel_disable(i2s_handle_);
gpio_->WriteSync(IGpios::Pin::kAmplifierEnable, false);
diff --git a/src/drivers/include/touchwheel.hpp b/src/drivers/include/touchwheel.hpp
index f42b575b..38e8a9f1 100644
--- a/src/drivers/include/touchwheel.hpp
+++ b/src/drivers/include/touchwheel.hpp
@@ -35,6 +35,8 @@ class TouchWheel {
auto Update() -> void;
auto GetTouchWheelData() const -> TouchWheelData;
+ auto PowerDown() -> void;
+
private:
TouchWheelData data_;
diff --git a/src/drivers/touchwheel.cpp b/src/drivers/touchwheel.cpp
index 59c2911e..6b925055 100644
--- a/src/drivers/touchwheel.cpp
+++ b/src/drivers/touchwheel.cpp
@@ -22,6 +22,8 @@
namespace drivers {
+// Touch wheel implementation using a Microchip AT42QT2120
+
static const char* kTag = "TOUCHWHEEL";
static const uint8_t kTouchWheelAddress = 0x1C;
static const gpio_num_t kIntPin = GPIO_NUM_25;
@@ -121,4 +123,8 @@ TouchWheelData TouchWheel::GetTouchWheelData() const {
return data_;
}
+auto TouchWheel::PowerDown() -> void {
+ WriteRegister(LOW_POWER, 0);
+}
+
} // namespace drivers