15 ESP_LOGE(TAG,
"Write failed");
22 this->
reg(PCM5122_REG_RESET) = PCM5122_RESET_MODULES;
24 this->
reg(PCM5122_REG_RESET) = 0x00;
27 optional<uint8_t> err_detect = this->
read_byte(PCM5122_REG_ERROR_DETECT);
28 if (!err_detect.has_value()) {
29 ESP_LOGE(TAG,
"Failed to read ERROR_DETECT");
33 uint8_t err_detect_val = err_detect.value();
34 err_detect_val |= PCM5122_ERROR_DETECT_IGNORE_CLKHALT;
35 err_detect_val &= ~PCM5122_ERROR_DETECT_DISABLE_DIV_AUTOSET;
36 this->
reg(PCM5122_REG_ERROR_DETECT) = err_detect_val;
42 alen = PCM5122_AUDIO_FORMAT_ALEN_16BIT;
45 alen = PCM5122_AUDIO_FORMAT_ALEN_24BIT;
49 alen = PCM5122_AUDIO_FORMAT_ALEN_32BIT;
52 this->
reg(PCM5122_REG_AUDIO_FORMAT) = PCM5122_AUDIO_FORMAT_I2S | alen;
55 optional<uint8_t> pll_ref = this->
read_byte(PCM5122_REG_PLL_REF);
56 if (!pll_ref.has_value()) {
57 ESP_LOGE(TAG,
"Failed to read PLL_REF");
61 uint8_t pll_ref_val = pll_ref.value();
62 pll_ref_val &= ~PCM5122_PLL_REF_MASK;
63 pll_ref_val |= PCM5122_PLL_REF_SOURCE_BCK;
64 this->
reg(PCM5122_REG_PLL_REF) = pll_ref_val;
124 const uint8_t dvol_max_volume = 0x30;
125 const uint8_t dvol_min_volume = 0x99;
127 const uint8_t volume_byte =
128 dvol_max_volume +
static_cast<uint8_t
>(lroundf((1.0f - this->
volume_) * (dvol_min_volume - dvol_max_volume)));
130 ESP_LOGV(TAG,
"Setting volume to 0x%.2x", volume_byte);
133 !this->
write_byte(PCM5122_REG_DVOL_RIGHT, volume_byte)) {
134 ESP_LOGE(TAG,
"Writing volume failed");