11#define ERROR_CHECK(err, msg) \
13 this->mark_failed(LOG_STR(msg)); \
19 {AIC3204_PAGE_CTRL, 0x00},
21 {AIC3204_SW_RST, 0x01},
37 {AIC3204_CODEC_IF, 0x30},
39 {AIC3204_SCLK_MFP3, 0x02},
40 {AIC3204_AUDIO_IF_4, 0x01},
41 {AIC3204_AUDIO_IF_5, 0x01},
43 {AIC3204_DAC_SIG_PROC, 0x01},
45 {AIC3204_PAGE_CTRL, 0x01},
47 {AIC3204_LDO_CTRL, 0x09},
50 {AIC3204_PWR_CFG, 0x08},
52 {AIC3204_LDO_CTRL, 0x01},
58 {AIC3204_CM_CTRL, 0x40},
61 {AIC3204_PLAY_CFG1, 0x00},
62 {AIC3204_PLAY_CFG2, 0x00},
64 {AIC3204_REF_STARTUP, 0x01},
68 {AIC3204_HP_START, 0x25},
70 {AIC3204_HPL_ROUTE, 0x08},
72 {AIC3204_HPR_ROUTE, 0x08},
74 {AIC3204_LOL_ROUTE, 0x08},
76 {AIC3204_LOR_ROUTE, 0x08},
78 {AIC3204_HPL_GAIN, 0x3e},
80 {AIC3204_HPR_GAIN, 0x3e},
82 {AIC3204_LOL_DRV_GAIN, 0x00},
84 {AIC3204_LOR_DRV_GAIN, 0x00},
86 {AIC3204_OP_PWR_CTRL, 0x3C},
90 ERROR_CHECK(this->
write_registers(AIC3204_INIT),
"Failed to initialize");
96 ERROR_CHECK(this->
write_byte(AIC3204_PAGE_CTRL, 0x00),
"Set PAGE_CTRL failed");
99 ERROR_CHECK(this->
write_byte(AIC3204_DAC_CH_SET1, 0xd4),
"Set DAC_CH_SET1 failed");
103 ERROR_CHECK(this->
write_mute_(),
"Set mute failed");
108 ESP_LOGCONFIG(TAG,
"AIC3204:");
109 LOG_I2C_DEVICE(
this);
124 ESP_LOGVV(TAG,
"Setting auto_mute_mode to 0x%.2x", this->
auto_mute_mode_);
139 mute_mode_byte |= this->
is_muted_ ? 0x0c : 0x00;
140 if (!this->
write_byte(AIC3204_PAGE_CTRL, 0x00) || !this->
write_byte(AIC3204_DAC_CH_SET2, mute_mode_byte)) {
141 ESP_LOGE(TAG,
"Writing mute modes failed");
148 const int8_t dvc_min_byte = -127;
149 const int8_t dvc_max_byte = 48;
151 int8_t volume_byte = dvc_min_byte + (this->
volume_ * (dvc_max_byte - dvc_min_byte));
152 volume_byte = clamp<int8_t>(volume_byte, dvc_min_byte, dvc_max_byte);
154 ESP_LOGVV(TAG,
"Setting volume to 0x%.2x", volume_byte & 0xFF);
156 if ((!this->
write_byte(AIC3204_PAGE_CTRL, 0x00)) || (!this->
write_byte(AIC3204_DACL_VOL_D, volume_byte)) ||
157 (!this->
write_byte(AIC3204_DACR_VOL_D, volume_byte))) {
158 ESP_LOGE(TAG,
"Writing volume failed");