Almost working DAC
This commit is contained in:
+46
-5
@@ -44,6 +44,25 @@ void AudioDac::Start(SampleRate sample_rate, BitDepth bit_depth) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Next, wait for the IC to boot up before we try configuring it.
|
||||||
|
bool is_booted = false;
|
||||||
|
for (int i=0; i<10; i++) {
|
||||||
|
uint8_t result = ReadPowerState();
|
||||||
|
is_booted = result >> 7;
|
||||||
|
if (is_booted) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(TAG, "Waiting for boot...");
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_booted) {
|
||||||
|
// TODO: properly handle
|
||||||
|
ESP_LOGE(TAG, "Timed out waiting for boot!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Now do all the math required to correctly set up the internal clocks.
|
// Now do all the math required to correctly set up the internal clocks.
|
||||||
int p, j, d, r;
|
int p, j, d, r;
|
||||||
int nmac, ndac, ncp, dosr, idac;
|
int nmac, ndac, ncp, dosr, idac;
|
||||||
@@ -153,15 +172,36 @@ void AudioDac::Start(SampleRate sample_rate, BitDepth bit_depth) {
|
|||||||
|
|
||||||
i2c_master_stop(handle);
|
i2c_master_stop(handle);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Configuring DAC");
|
||||||
// TODO: Handle this gracefully.
|
// TODO: Handle this gracefully.
|
||||||
ESP_ERROR_CHECK(i2c_master_cmd_begin(I2C_NUM_0, handle, 50));
|
ESP_ERROR_CHECK(i2c_master_cmd_begin(I2C_NUM_0, handle, kPCM5122Timeout));
|
||||||
|
|
||||||
i2c_cmd_link_delete(handle);
|
i2c_cmd_link_delete(handle);
|
||||||
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(10));
|
// The DAC takes a moment to reconfigure itself. Give it some time before we
|
||||||
|
// start asking for its state.
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(5));
|
||||||
|
|
||||||
// TODO: Handle this gracefully.
|
// TODO: investigate why it's stuck waiting for CP voltage.
|
||||||
assert(ReadPowerState() == 0x05);
|
/*
|
||||||
|
bool is_configured = false;
|
||||||
|
for (int i=0; i<10; i++) {
|
||||||
|
uint8_t result = ReadPowerState();
|
||||||
|
is_configured = (result & 0b1111) == 0b1001;
|
||||||
|
if (is_configured) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
ESP_LOGI(TAG, "Waiting for configure...");
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_configured) {
|
||||||
|
// TODO: properly handle
|
||||||
|
ESP_LOGE(TAG, "Timed out waiting for configure!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t AudioDac::ReadPowerState() {
|
uint8_t AudioDac::ReadPowerState() {
|
||||||
@@ -176,10 +216,11 @@ uint8_t AudioDac::ReadPowerState() {
|
|||||||
i2c_master_write_byte(handle, (kPCM5122Address << 1 | I2C_MASTER_WRITE), true);
|
i2c_master_write_byte(handle, (kPCM5122Address << 1 | I2C_MASTER_WRITE), true);
|
||||||
i2c_master_write_byte(handle, DSP_BOOT_POWER_STATE, true);
|
i2c_master_write_byte(handle, DSP_BOOT_POWER_STATE, true);
|
||||||
i2c_master_start(handle);
|
i2c_master_start(handle);
|
||||||
|
i2c_master_write_byte(handle, (kPCM5122Address << 1 | I2C_MASTER_READ), true);
|
||||||
i2c_master_read_byte(handle, &result, I2C_MASTER_NACK);
|
i2c_master_read_byte(handle, &result, I2C_MASTER_NACK);
|
||||||
i2c_master_stop(handle);
|
i2c_master_stop(handle);
|
||||||
|
|
||||||
ESP_ERROR_CHECK(i2c_master_cmd_begin(I2C_NUM_0, handle, 50));
|
ESP_ERROR_CHECK(i2c_master_cmd_begin(I2C_NUM_0, handle, kPCM5122Timeout));
|
||||||
|
|
||||||
i2c_cmd_link_delete(handle);
|
i2c_cmd_link_delete(handle);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
namespace gay_ipod {
|
namespace gay_ipod {
|
||||||
|
|
||||||
static const uint8_t kPCM5122Address = 0x4C;
|
static const uint8_t kPCM5122Address = 0x4C;
|
||||||
|
static const uint8_t kPCM5122Timeout = 100 / portTICK_RATE_MS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PCM5122PWR
|
* PCM5122PWR
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <cstdint>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
@@ -113,16 +114,13 @@ extern "C" void app_main(void)
|
|||||||
ESP_LOGI(TAG, "Everything looks good! Waiting a mo for debugger.");
|
ESP_LOGI(TAG, "Everything looks good! Waiting a mo for debugger.");
|
||||||
vTaskDelay(pdMS_TO_TICKS(1500));
|
vTaskDelay(pdMS_TO_TICKS(1500));
|
||||||
|
|
||||||
/*
|
|
||||||
* TODO: not working :(
|
|
||||||
ESP_LOGI(TAG, "Trying to init DAC");
|
ESP_LOGI(TAG, "Trying to init DAC");
|
||||||
gay_ipod::AudioDac dac(&expander);
|
gay_ipod::AudioDac dac(&expander);
|
||||||
dac.Start(
|
dac.Start(
|
||||||
gay_ipod::AudioDac::SAMPLE_RATE_44_1K,
|
gay_ipod::AudioDac::SAMPLE_RATE_48K,
|
||||||
gay_ipod::AudioDac::BIT_DEPTH_16);
|
gay_ipod::AudioDac::BIT_DEPTH_16);
|
||||||
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
*/
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Looks okay? Let's list some files!");
|
ESP_LOGI(TAG, "Looks okay? Let's list some files!");
|
||||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class GpioExpander {
|
|||||||
// 6 - sd chip select
|
// 6 - sd chip select
|
||||||
// 7 - display chip select
|
// 7 - display chip select
|
||||||
// All power switches low, chip selects high, active-low charge power high
|
// All power switches low, chip selects high, active-low charge power high
|
||||||
uint8_t port_a_ = 0b11010000;
|
uint8_t port_a_ = 0b11010001;
|
||||||
|
|
||||||
// Port B:
|
// Port B:
|
||||||
// 0 - 3.5mm jack detect (active low)
|
// 0 - 3.5mm jack detect (active low)
|
||||||
|
|||||||
Reference in New Issue
Block a user