66 for (
int i = 0; i < 50; i++) {
81 res |=
writeReg(0x36, reg | (((
int)enable) << 5));
119 AD_LOGW(
"The es8374 codec has already been initialized!");
129 res |=
stop(codec_mode);
167 AD_LOGW(
"Codec mode not support, default is decode mode");
170 if (!ctrl_state_active) {
174 AD_LOGD(
"start default is decode mode:%d", es_mode_t);
185 }
else if (volume > 96) {
188 volume = 192 - volume * 2;
206 *volume = (192 - reg) / 2;
216 &data,
sizeof(data));
220 uint8_t regdata = 0xFF;
228 AD_LOGI(
"Read Audio Codec Register Failed!");
238 int bits = (int)bit_per_sample & 0x0f;
244 res |=
writeReg(0x10, reg | (bits << 2));
251 res |=
writeReg(0x11, reg | (bits << 2));
262 int fmt_tmp, fmt_i2s;
264 fmt_tmp = ((fmt & 0xf0) >> 4);
265 fmt_i2s = fmt & 0x0f;
270 res |=
writeReg(0x10, reg | fmt_i2s);
278 res |=
writeReg(0x11, reg | (fmt_i2s));
497 dacratio_l = 128 % 256;
498 dacratio_h = 128 / 256;
501 dacratio_l = 192 % 256;
502 dacratio_h = 192 / 256;
505 dacratio_l = 256 % 256;
506 dacratio_h = 256 / 256;
509 dacratio_l = 384 % 256;
510 dacratio_h = 384 / 256;
513 dacratio_l = 512 % 256;
514 dacratio_h = 512 / 256;
517 dacratio_l = 576 % 256;
518 dacratio_h = 576 / 256;
521 dacratio_l = 768 % 256;
522 dacratio_h = 768 / 256;
525 dacratio_l = 1024 % 256;
526 dacratio_h = 1024 / 256;
529 dacratio_l = 1152 % 256;
530 dacratio_h = 1152 / 256;
533 dacratio_l = 1408 % 256;
534 dacratio_h = 1408 / 256;
537 dacratio_l = 1536 % 256;
538 dacratio_h = 1536 / 256;
541 dacratio_l = 2112 % 256;
542 dacratio_h = 2112 / 256;
545 dacratio_l = 2304 % 256;
546 dacratio_h = 2304 / 256;
549 dacratio_l = 125 % 256;
550 dacratio_h = 125 / 256;
553 dacratio_l = 136 % 256;
554 dacratio_h = 136 / 256;
557 dacratio_l = 250 % 256;
558 dacratio_h = 250 / 256;
561 dacratio_l = 272 % 256;
562 dacratio_h = 272 / 256;
565 dacratio_l = 375 % 256;
566 dacratio_h = 375 / 256;
569 dacratio_l = 500 % 256;
570 dacratio_h = 500 / 256;
573 dacratio_l = 544 % 256;
574 dacratio_h = 544 / 256;
577 dacratio_l = 750 % 256;
578 dacratio_h = 750 / 256;
581 dacratio_l = 1000 % 256;
582 dacratio_h = 1000 / 256;
585 dacratio_l = 1088 % 256;
586 dacratio_h = 1088 / 256;
589 dacratio_l = 1496 % 256;
590 dacratio_h = 1496 / 256;
593 dacratio_l = 1500 % 256;
594 dacratio_h = 1500 / 256;
632 reg = (reg & 0xcf) | 0x14;
645 gain_n = (int)gain / 3;
646 res =
writeReg(0x22, gain_n | (gain_n << 4));
649 AD_LOGI(
"invalid microphone gain!");
658 if (volume < -96 || volume > 0) {
659 AD_LOGI(
"Warning: volume < -96! or > 0!");
666 dot = (dot >= 5 ? 1 : 0);
667 volume = (-volume << 1) + dot;
689 AD_LOGI(
"invalid microphone gain!");
705 reg |= (ms_mode << 7);
@ MCLK_DIV_20
Definition CodecConstants.h:31
@ MCLK_DIV_30
Definition CodecConstants.h:33
@ MCLK_DIV_33
Definition CodecConstants.h:21
@ MCLK_DIV_1
Definition CodecConstants.h:8
@ MCLK_DIV_24
Definition CodecConstants.h:20
@ MCLK_DIV_44
Definition CodecConstants.h:23
@ MCLK_DIV_18
Definition CodecConstants.h:18
@ MCLK_DIV_11
Definition CodecConstants.h:15
@ MCLK_DIV_16
Definition CodecConstants.h:17
@ MCLK_DIV_3
Definition CodecConstants.h:10
@ MCLK_DIV_22
Definition CodecConstants.h:19
@ MCLK_DIV_32
Definition CodecConstants.h:34
@ MCLK_DIV_9
Definition CodecConstants.h:14
@ MCLK_DIV_34
Definition CodecConstants.h:35
@ MCLK_DIV_72
Definition CodecConstants.h:26
@ MCLK_DIV_66
Definition CodecConstants.h:25
@ MCLK_DIV_14
Definition CodecConstants.h:38
@ MCLK_DIV_5
Definition CodecConstants.h:27
@ MCLK_DIV_4
Definition CodecConstants.h:11
@ MCLK_DIV_8
Definition CodecConstants.h:13
@ MCLK_DIV_2
Definition CodecConstants.h:9
@ MCLK_DIV_7
Definition CodecConstants.h:36
@ MCLK_DIV_6
Definition CodecConstants.h:12
@ MCLK_DIV_36
Definition CodecConstants.h:22
@ MCLK_DIV_48
Definition CodecConstants.h:24
@ MCLK_DIV_10
Definition CodecConstants.h:28
@ MCLK_DIV_17
Definition CodecConstants.h:30
@ MCLK_DIV_13
Definition CodecConstants.h:37
@ MCLK_DIV_15
Definition CodecConstants.h:29
@ MCLK_DIV_12
Definition CodecConstants.h:16
@ MCLK_DIV_25
Definition CodecConstants.h:32
@ LCLK_DIV_1408
Definition CodecConstants.h:54
@ LCLK_DIV_750
Definition CodecConstants.h:66
@ LCLK_DIV_1536
Definition CodecConstants.h:55
@ LCLK_DIV_272
Definition CodecConstants.h:62
@ LCLK_DIV_1500
Definition CodecConstants.h:70
@ LCLK_DIV_375
Definition CodecConstants.h:63
@ LCLK_DIV_512
Definition CodecConstants.h:49
@ LCLK_DIV_1496
Definition CodecConstants.h:69
@ LCLK_DIV_1152
Definition CodecConstants.h:53
@ LCLK_DIV_256
Definition CodecConstants.h:47
@ LCLK_DIV_128
Definition CodecConstants.h:45
@ LCLK_DIV_2304
Definition CodecConstants.h:57
@ LCLK_DIV_136
Definition CodecConstants.h:60
@ LCLK_DIV_192
Definition CodecConstants.h:46
@ LCLK_DIV_768
Definition CodecConstants.h:51
@ LCLK_DIV_250
Definition CodecConstants.h:61
@ LCLK_DIV_384
Definition CodecConstants.h:48
@ LCLK_DIV_1000
Definition CodecConstants.h:67
@ LCLK_DIV_1024
Definition CodecConstants.h:52
@ LCLK_DIV_2112
Definition CodecConstants.h:56
@ LCLK_DIV_576
Definition CodecConstants.h:50
@ LCLK_DIV_544
Definition CodecConstants.h:65
@ LCLK_DIV_1088
Definition CodecConstants.h:68
@ LCLK_DIV_500
Definition CodecConstants.h:64
@ LCLK_DIV_125
Definition CodecConstants.h:59
#define RESULT_OK
Definition DriverCommon.h:74
#define RESULT_FAIL
Definition DriverCommon.h:75
#define AD_LOGD(...)
Definition Logger.h:12
#define AD_LOGI(...)
Definition Logger.h:13
#define AD_LOGW(...)
Definition Logger.h:14
Header-only driver class for the ES8374 codec chip.
Definition ES8374.h:51
error_t writeReg(uint8_t reg_add, uint8_t data)
Definition ES8374.h:214
static constexpr int ES8374_ADDR
Definition ES8374.h:53
error_t ctrlStateActive(codec_mode_t mode, bool ctrl_state_active)
Control ES8374 codec chip.
Definition ES8374.h:149
error_t setBitsPerSample(codec_mode_t mode, sample_bits_t bit_per_sample)
Configure ES8374 data sample bits.
Definition ES8374.h:235
error_t init(codec_config_t *cfg, codec_mode_t codec_mode)
Initialize ES8374 codec chip.
Definition ES8374.h:117
error_t setD2sePga(es_d2se_pga_t gain)
Definition ES8374.h:678
void setAddress(int addr)
Defines the I2C device address.
Definition ES8374.h:60
error_t deinit(void)
Deinitialize ES8374 codec chip.
Definition ES8374.h:143
error_t setVoiceMute(bool enable)
Mute or unmute ES8374 DAC.
Definition ES8374.h:74
error_t start(codec_mode_t mode)
Start ES8374 codec chip.
Definition ES8374.h:287
error_t initReg(codec_mode_t ms_mode, i2s_format_t fmt, es_i2s_clock_t cfg)
Definition ES8374.h:695
int i2c_addr
Definition ES8374.h:772
error_t configI2S(codec_mode_t mode, I2SDefinition *iface)
Configure ES8374 codec mode and I2S interface.
Definition ES8374.h:101
error_t setAdcDacVolume(int mode, int volume, int dot)
Definition ES8374.h:655
void setWire(i2c_bus_handle_t handle)
Defines the I2C bus instance to be used.
Definition ES8374.h:57
error_t configFmt(codec_mode_t mode, i2s_format_t fmt)
Configure ES8374 I2S format.
Definition ES8374.h:259
error_t configInputDevice()
Set ES8374 ADC input mode.
Definition ES8374.h:626
void readAll()
Print all ES8374 registers.
Definition ES8374.h:65
i2c_bus_handle_t i2c_handle
Definition ES8374.h:771
error_t getVoiceMute(void)
Get ES8374 DAC mute status.
Definition ES8374.h:88
error_t setVoiceVolume(int volume)
Set voice volume (0~100)
Definition ES8374.h:180
error_t stop(codec_mode_t mode)
Stop ES8374 codec chip.
Definition ES8374.h:341
error_t setMicGain(es_mic_gain_t gain)
Set ES8374 mic gain.
Definition ES8374.h:640
error_t getVoiceVolume(int *volume)
Get voice volume (0~100)
Definition ES8374.h:197
bool initialized
Definition ES8374.h:773
int readReg(uint8_t reg_add, uint8_t *regv)
Definition ES8374.h:219
error_t configOutputDevice()
Set ES8374 DAC output mode.
Definition ES8374.h:608
error_t i2sConfigClock(es_i2s_clock_t cfg)
Configure I2S clock in MASTER mode.
Definition ES8374.h:385
Namespace for audio driver components.
Definition AudioBoard.h:5
es_d2se_pga_t
Definition ES8374.h:39
@ ES8374_PGA_GAIN_MAX
Definition ES8374.h:43
@ ES8374_PGA_GAIN_DIS
Definition ES8374.h:41
@ ES8374_PGA_GAIN_EN
Definition ES8374.h:42
@ ES8374_PGA_GAIN_MIN
Definition ES8374.h:40
sample_bits_t
Definition DriverCommon.h:235
@ BIT_LENGTH_24BITS
Definition DriverCommon.h:240
@ BIT_LENGTH_32BITS
Definition DriverCommon.h:241
@ BIT_LENGTH_16BITS
Definition DriverCommon.h:237
codec_mode_t
Definition DriverCommon.h:290
@ CODEC_MODE_ENCODE
Definition DriverCommon.h:293
@ CODEC_MODE_BOTH
Definition DriverCommon.h:295
@ CODEC_MODE_DECODE
Definition DriverCommon.h:294
@ CODEC_MODE_LINE_IN
Definition DriverCommon.h:296
int error_t
Definition DriverCommon.h:150
es_mic_gain_t
Definition DriverCommon.h:305
@ MIC_GAIN_15DB
Definition DriverCommon.h:312
@ MIC_GAIN_MIN
Definition DriverCommon.h:306
@ MIC_GAIN_24DB
Definition DriverCommon.h:315
i2s_format_t
Definition DriverCommon.h:250
void * i2c_bus_handle_t
Definition DriverCommon.h:155
I2S interface parameters for the audio codec.
Definition DriverCommon.h:384
i2s_format_t fmt
Definition DriverCommon.h:386
i2s_master_slave_t mode
Definition DriverCommon.h:385
sample_bits_t bits
Definition DriverCommon.h:388
Top-level codec configuration passed to the audio driver at init.
Definition DriverCommon.h:397
I2SDefinition i2s
Definition DriverCommon.h:400
i2s clock configuration structure for es8388 and es8374
Definition CodecConstants.h:78
es_lclk_div_t lclk_div
Definition CodecConstants.h:80
es_sclk_div_t sclk_div
Definition CodecConstants.h:79