10 static const char *
const TAG =
"aic3204";
12 #define ERROR_CHECK(err, msg) \ 15 this->mark_failed(); \ 20 ESP_LOGCONFIG(TAG,
"Setting up AIC3204...");
23 ERROR_CHECK(this->
write_byte(AIC3204_PAGE_CTRL, 0x00),
"Set page 0 failed");
25 ERROR_CHECK(this->
write_byte(AIC3204_SW_RST, 0x01),
"Software reset failed");
36 ERROR_CHECK(this->
write_byte(AIC3204_NDAC, 0x82),
"Set NDAC failed");
38 ERROR_CHECK(this->
write_byte(AIC3204_MDAC, 0x82),
"Set MDAC failed");
40 ERROR_CHECK(this->
write_byte(AIC3204_DOSR, 0x80),
"Set DOSR failed");
42 ERROR_CHECK(this->
write_byte(AIC3204_CODEC_IF, 0x30),
"Set CODEC_IF failed");
44 ERROR_CHECK(this->
write_byte(AIC3204_SCLK_MFP3, 0x02),
"Set SCLK/MFP3 failed");
45 ERROR_CHECK(this->
write_byte(AIC3204_AUDIO_IF_4, 0x01),
"Set AUDIO_IF_4 failed");
46 ERROR_CHECK(this->
write_byte(AIC3204_AUDIO_IF_5, 0x01),
"Set AUDIO_IF_5 failed");
48 ERROR_CHECK(this->
write_byte(AIC3204_DAC_SIG_PROC, 0x01),
"Set DAC_SIG_PROC failed");
51 ERROR_CHECK(this->
write_byte(AIC3204_PAGE_CTRL, 0x01),
"Set page 1 failed");
53 ERROR_CHECK(this->
write_byte(AIC3204_LDO_CTRL, 0x09),
"Set LDO_CTRL failed");
56 ERROR_CHECK(this->
write_byte(AIC3204_PWR_CFG, 0x08),
"Set PWR_CFG failed");
58 ERROR_CHECK(this->
write_byte(AIC3204_LDO_CTRL, 0x01),
"Set LDO_CTRL failed");
64 ERROR_CHECK(this->
write_byte(AIC3204_CM_CTRL, 0x40),
"Set CM_CTRL failed");
67 ERROR_CHECK(this->
write_byte(AIC3204_PLAY_CFG1, 0x00),
"Set PLAY_CFG1 failed");
68 ERROR_CHECK(this->
write_byte(AIC3204_PLAY_CFG2, 0x00),
"Set PLAY_CFG2 failed");
70 ERROR_CHECK(this->
write_byte(AIC3204_REF_STARTUP, 0x01),
"Set REF_STARTUP failed");
74 ERROR_CHECK(this->
write_byte(AIC3204_HP_START, 0x25),
"Set HP_START failed");
76 ERROR_CHECK(this->
write_byte(AIC3204_HPL_ROUTE, 0x08),
"Set HPL_ROUTE failed");
78 ERROR_CHECK(this->
write_byte(AIC3204_HPR_ROUTE, 0x08),
"Set HPR_ROUTE failed");
80 ERROR_CHECK(this->
write_byte(AIC3204_LOL_ROUTE, 0x08),
"Set LOL_ROUTE failed");
82 ERROR_CHECK(this->
write_byte(AIC3204_LOR_ROUTE, 0x08),
"Set LOR_ROUTE failed");
85 ERROR_CHECK(this->
write_byte(AIC3204_HPL_GAIN, 0x3e),
"Set HPL_GAIN failed");
87 ERROR_CHECK(this->
write_byte(AIC3204_HPR_GAIN, 0x3e),
"Set HPR_GAIN failed");
89 ERROR_CHECK(this->
write_byte(AIC3204_LOL_DRV_GAIN, 0x00),
"Set LOL_DRV_GAIN failed");
91 ERROR_CHECK(this->
write_byte(AIC3204_LOR_DRV_GAIN, 0x00),
"Set LOR_DRV_GAIN failed");
94 ERROR_CHECK(this->
write_byte(AIC3204_OP_PWR_CTRL, 0x3C),
"Set OP_PWR_CTRL failed");
100 ERROR_CHECK(this->
write_byte(AIC3204_PAGE_CTRL, 0x00),
"Set PAGE_CTRL failed");
103 ERROR_CHECK(this->
write_byte(AIC3204_DAC_CH_SET1, 0xd4),
"Set DAC_CH_SET1 failed");
107 ERROR_CHECK(this->
write_mute_(),
"Set mute failed");
112 ESP_LOGCONFIG(TAG,
"AIC3204:");
113 LOG_I2C_DEVICE(
this);
116 ESP_LOGE(TAG,
"Communication with AIC3204 failed");
132 ESP_LOGVV(TAG,
"Setting auto_mute_mode to 0x%.2x", this->
auto_mute_mode_);
147 mute_mode_byte |= this->
is_muted_ ? 0x0c : 0x00;
148 if (!this->
write_byte(AIC3204_PAGE_CTRL, 0x00) || !this->
write_byte(AIC3204_DAC_CH_SET2, mute_mode_byte)) {
149 ESP_LOGE(TAG,
"Writing mute modes failed");
156 const int8_t dvc_min_byte = -127;
157 const int8_t dvc_max_byte = 48;
159 int8_t volume_byte = dvc_min_byte + (this->
volume_ * (dvc_max_byte - dvc_min_byte));
160 volume_byte = clamp<int8_t>(volume_byte, dvc_min_byte, dvc_max_byte);
162 ESP_LOGVV(TAG,
"Setting volume to 0x%.2x", volume_byte & 0xFF);
164 if ((!this->
write_byte(AIC3204_PAGE_CTRL, 0x00)) || (!this->
write_byte(AIC3204_DACL_VOL_D, volume_byte)) ||
165 (!this->
write_byte(AIC3204_DACR_VOL_D, volume_byte))) {
166 ESP_LOGE(TAG,
"Writing volume failed");
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
void dump_config() override
bool set_mute_on() override
bool set_auto_mute_mode(uint8_t auto_mute_mode)
bool set_volume(float volume) override
bool set_mute_off() override
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
Implementation of SPI Controller mode.