10 static const char *
const TAG =
"es8156";
13 #define ES8156_ERROR_FAILED(func) \ 15 this->mark_failed(); \ 20 ESP_LOGCONFIG(TAG,
"Setting up ES8156...");
22 ES8156_ERROR_FAILED(this->
write_byte(ES8156_REG02_SCLK_MODE, 0x04));
23 ES8156_ERROR_FAILED(this->
write_byte(ES8156_REG20_ANALOG_SYS1, 0x2A));
24 ES8156_ERROR_FAILED(this->
write_byte(ES8156_REG21_ANALOG_SYS2, 0x3C));
25 ES8156_ERROR_FAILED(this->
write_byte(ES8156_REG22_ANALOG_SYS3, 0x00));
26 ES8156_ERROR_FAILED(this->
write_byte(ES8156_REG24_ANALOG_LP, 0x07));
27 ES8156_ERROR_FAILED(this->
write_byte(ES8156_REG23_ANALOG_SYS4, 0x00));
29 ES8156_ERROR_FAILED(this->
write_byte(ES8156_REG0A_TIME_CONTROL1, 0x01));
30 ES8156_ERROR_FAILED(this->
write_byte(ES8156_REG0B_TIME_CONTROL2, 0x01));
31 ES8156_ERROR_FAILED(this->
write_byte(ES8156_REG11_DAC_SDP, 0x00));
32 ES8156_ERROR_FAILED(this->
write_byte(ES8156_REG19_EQ_CONTROL1, 0x20));
34 ES8156_ERROR_FAILED(this->
write_byte(ES8156_REG0D_P2S_CONTROL, 0x14));
35 ES8156_ERROR_FAILED(this->
write_byte(ES8156_REG09_MISC_CONTROL2, 0x00));
36 ES8156_ERROR_FAILED(this->
write_byte(ES8156_REG18_MISC_CONTROL3, 0x00));
37 ES8156_ERROR_FAILED(this->
write_byte(ES8156_REG08_CLOCK_ON_OFF, 0x3F));
38 ES8156_ERROR_FAILED(this->
write_byte(ES8156_REG00_RESET, 0x02));
39 ES8156_ERROR_FAILED(this->
write_byte(ES8156_REG00_RESET, 0x03));
40 ES8156_ERROR_FAILED(this->
write_byte(ES8156_REG25_ANALOG_SYS5, 0x20));
44 ESP_LOGCONFIG(TAG,
"ES8156 Audio Codec:");
47 ESP_LOGCONFIG(TAG,
" Failed to initialize");
53 volume =
clamp(volume, 0.0f, 1.0f);
54 uint8_t
reg = remap<uint8_t, float>(
volume, 0.0f, 1.0f, 0, 255);
55 ESP_LOGV(TAG,
"Setting ES8156_REG14_VOLUME_CONTROL to %u (volume: %f)", reg, volume);
56 return this->
write_byte(ES8156_REG14_VOLUME_CONTROL, reg);
61 this->
read_byte(ES8156_REG14_VOLUME_CONTROL, ®);
62 return remap<float, uint8_t>(
reg, 0, 255, 0.0f, 1.0f);
70 if (!this->
read_byte(ES8156_REG13_DAC_MUTE, ®13)) {
74 ESP_LOGV(TAG,
"Read ES8156_REG13_DAC_MUTE: %u", reg13);
77 reg13 |= BIT(1) | BIT(2);
79 reg13 &= ~(BIT(1) | BIT(2));
82 ESP_LOGV(TAG,
"Setting ES8156_REG13_DAC_MUTE to %u (muted: %s)", reg13, YESNO(mute_state));
83 return this->
write_byte(ES8156_REG13_DAC_MUTE, reg13);
bool read_byte(uint8_t a_register, uint8_t *data, bool stop=true)
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)
float volume() override
Gets the current volume out from the DAC.
void dump_config() override
bool set_volume(float volume) override
Writes the volume out to the DAC.
bool set_mute_state_(bool mute_state)
Mutes or unmutes the DAC audio out.
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
Implementation of SPI Controller mode.