10static const char *
const TAG =
"pcm5122";
21 ESP_LOGE(TAG,
"Write failed");
28 this->
reg(PCM5122_REG_RESET) = PCM5122_RESET_MODULES;
30 this->
reg(PCM5122_REG_RESET) = 0x00;
33 optional<uint8_t> err_detect = this->
read_byte(PCM5122_REG_ERROR_DETECT);
34 if (!err_detect.has_value()) {
35 ESP_LOGE(TAG,
"Failed to read ERROR_DETECT");
39 uint8_t err_detect_val = err_detect.value();
40 err_detect_val |= PCM5122_ERROR_DETECT_IGNORE_CLKHALT;
41 err_detect_val &= ~PCM5122_ERROR_DETECT_DISABLE_DIV_AUTOSET;
42 this->
reg(PCM5122_REG_ERROR_DETECT) = err_detect_val;
48 alen = PCM5122_AUDIO_FORMAT_ALEN_16BIT;
51 alen = PCM5122_AUDIO_FORMAT_ALEN_24BIT;
55 alen = PCM5122_AUDIO_FORMAT_ALEN_32BIT;
58 this->
reg(PCM5122_REG_AUDIO_FORMAT) = PCM5122_AUDIO_FORMAT_I2S | alen;
72 ESP_LOGE(TAG,
"Write failed");
76 optional<uint8_t> pll_ref = this->
read_byte(PCM5122_REG_PLL_REF);
77 if (!pll_ref.has_value()) {
78 ESP_LOGE(TAG,
"Failed to read PLL_REF");
82 uint8_t pll_ref_val = pll_ref.value();
83 pll_ref_val &= ~PCM5122_PLL_REF_MASK;
84 pll_ref_val |= PCM5122_PLL_REF_SOURCE_BCK;
85 this->
reg(PCM5122_REG_PLL_REF) = pll_ref_val;
99 const char *channel_mix_str;
102 channel_mix_str =
"left only";
105 channel_mix_str =
"right only";
108 channel_mix_str =
"swapped";
111 channel_mix_str =
"stereo";
114 ESP_LOGCONFIG(TAG,
"Audio DAC:");
115 LOG_I2C_DEVICE(
this);
117 " Bits per sample: %u\n"
120 " Volume range: %.1f dB to %.1f dB\n"
149 if (!this->
write_byte(PCM5122_REG_PAGE_SELECT, page)) {
158 uint8_t mute_byte = this->
is_muted() ? 0x11 : 0x00;
160 ESP_LOGE(TAG,
"Writing mute failed");
170 const uint8_t dvol_max_volume =
static_cast<uint8_t
>(lroundf(0x30 - this->
volume_max_db_ * 2.0f));
171 const uint8_t dvol_min_volume =
static_cast<uint8_t
>(lroundf(0x30 - this->
volume_min_db_ * 2.0f));
173 const uint8_t volume_byte =
174 dvol_max_volume +
static_cast<uint8_t
>(lroundf((1.0f - this->
volume_) * (dvol_min_volume - dvol_max_volume)));
176 ESP_LOGV(TAG,
"Setting volume to 0x%.2x", volume_byte);
179 !this->
write_byte(PCM5122_REG_DVOL_RIGHT, volume_byte)) {
180 ESP_LOGE(TAG,
"Writing volume failed");
189 ESP_LOGE(TAG,
"Writing analog gain failed");
198 ESP_LOGE(TAG,
"Writing channel mix failed");
226 (this->
standby_ ? PCM5122_POWER_CONTROL_RQST : 0) | (this->
powerdown_ ? PCM5122_POWER_CONTROL_RQPD : 0);
228 ESP_LOGE(TAG,
"Writing power control failed");
void mark_failed()
Mark this component as failed.
virtual void digital_write(bool value)=0
bool write_byte(uint8_t a_register, uint8_t data) const
bool read_byte(uint8_t a_register, uint8_t *data)
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
bool set_standby(bool enable)
bool write_channel_mix_()
bool set_volume(float volume) override
bool set_mute_on() override
bool set_mute_off() override
void dump_config() override
bool write_analog_gain_()
bool select_page_(uint8_t page)
bool set_powerdown(bool enable)
bool write_power_control_()
PCM5122AnalogGain analog_gain_
PCM5122BitsPerSample bits_per_sample_
PCM5122ChannelMix channel_mix_
@ PCM5122_ANALOG_GAIN_0DB
@ PCM5122_CHANNEL_MIX_SWAPPED
@ PCM5122_CHANNEL_MIX_LEFT_ONLY
@ PCM5122_CHANNEL_MIX_RIGHT_ONLY
@ PCM5122_BITS_PER_SAMPLE_16
@ PCM5122_BITS_PER_SAMPLE_32
@ PCM5122_BITS_PER_SAMPLE_24
void HOT delay(uint32_t ms)