53
53
54
54
#define MCLK_DIV_FRE 256
55
55
56
- static i2c_bus_handle_t i2c_handle ;
56
+ static i2c_bus_handle_t i2c_handle = NULL ;
57
57
static int i2c_address_es8311 = ES8311_ADDR ;
58
58
59
- // /*
60
- // * operate function of codec
61
- // */
62
- // func_t AUDIO_CODEC_ES8311_DEFAULT_HANDLE = {
63
- // .audio_codec_initialize = es8311_codec_init,
64
- // .audio_codec_deinitialize = es8311_codec_deinit,
65
- // .audio_codec_ctrl = es8311_codec_ctrl_state_active,
66
- // .audio_codec_config_iface = es8311_codec_config_i2s,
67
- // .audio_codec_set_mute = es8311_set_voice_mute,
68
- // .audio_codec_set_volume = es8311_codec_set_voice_volume,
69
- // .audio_codec_get_volume = es8311_codec_get_voice_volume,
70
- // .lock = NULL,
71
- // .handle = NULL,
72
- // };
73
-
74
59
/*
75
60
* Clock coefficient structer
76
61
*/
@@ -268,18 +253,6 @@ static void es8311_suspend(void)
268
253
es8311_write_reg (ES8311_GP_REG45 , 0x01 );
269
254
}
270
255
271
- // /*
272
- // * enable pa power
273
- // */
274
- // void es8311_pa_power(bool enable)
275
- // {
276
- // pinMode(get_pa_enable_gpio(), OUTPUT);
277
- // if (enable) {
278
- // digitalWrite(get_pa_enable_gpio(), HIGH);
279
- // } else {
280
- // digitalWrite(get_pa_enable_gpio(), LOW);
281
- // }
282
- // }
283
256
284
257
error_t es8311_codec_init (codec_config_t * codec_cfg , i2c_bus_handle_t handle , int8_t mclk_src , int i2c_address )
285
258
{
@@ -288,6 +261,7 @@ error_t es8311_codec_init(codec_config_t *codec_cfg, i2c_bus_handle_t handle, in
288
261
int coeff ;
289
262
error_t ret = RESULT_OK ;
290
263
i2c_handle = handle ;
264
+ assert (i2c_handle != NULL );
291
265
if (i2c_address > 0 ){
292
266
i2c_address_es8311 = i2c_address ;
293
267
}
@@ -330,16 +304,19 @@ error_t es8311_codec_init(codec_config_t *codec_cfg, i2c_bus_handle_t handle, in
330
304
*/
331
305
switch (get_es8311_mclk_src ()) {
332
306
case FROM_MCLK_PIN :
307
+ AD_LOGI ( "ES8311 clock source: MCLK" );
333
308
regv = es8311_read_reg (ES8311_CLK_MANAGER_REG01 );
334
309
regv &= 0x7F ;
335
310
ret |= es8311_write_reg (ES8311_CLK_MANAGER_REG01 , regv );
336
311
break ;
337
312
case FROM_SCLK_PIN :
313
+ AD_LOGI ( "ES8311 clock source: SCLK" );
338
314
regv = es8311_read_reg (ES8311_CLK_MANAGER_REG01 );
339
315
regv |= 0x80 ;
340
316
ret |= es8311_write_reg (ES8311_CLK_MANAGER_REG01 , regv );
341
317
break ;
342
318
default :
319
+ AD_LOGI ( "ES8311 clock source: MCLK" );
343
320
regv = es8311_read_reg (ES8311_CLK_MANAGER_REG01 );
344
321
regv &= 0x7F ;
345
322
ret |= es8311_write_reg (ES8311_CLK_MANAGER_REG01 , regv );
@@ -651,6 +628,7 @@ error_t es8311_stop(codec_mode_t mode)
651
628
652
629
error_t es8311_codec_set_voice_volume (int volume )
653
630
{
631
+ if (i2c_handle == 0 ) return RESULT_FAIL ;
654
632
error_t res = RESULT_OK ;
655
633
if (volume < 0 ) {
656
634
volume = 0 ;
@@ -665,6 +643,7 @@ error_t es8311_codec_set_voice_volume(int volume)
665
643
666
644
error_t es8311_codec_get_voice_volume (int * volume )
667
645
{
646
+ if (i2c_handle == 0 ) return RESULT_FAIL ;
668
647
error_t res = RESULT_OK ;
669
648
int regv = 0 ;
670
649
regv = es8311_read_reg (ES8311_DAC_REG32 );
@@ -681,12 +660,14 @@ error_t es8311_codec_get_voice_volume(int *volume)
681
660
error_t es8311_set_voice_mute (bool enable )
682
661
{
683
662
AD_LOGD ( "Es8311SetVoiceMute volume:%d" , enable );
663
+ if (i2c_handle == 0 ) return RESULT_FAIL ;
684
664
es8311_mute (enable );
685
665
return RESULT_OK ;
686
666
}
687
667
688
668
error_t es8311_get_voice_mute (int * mute )
689
669
{
670
+ if (i2c_handle == 0 ) return RESULT_FAIL ;
690
671
error_t res = RESULT_OK ;
691
672
uint8_t reg = 0 ;
692
673
res = es8311_read_reg (ES8311_DAC_REG31 );
@@ -699,6 +680,7 @@ error_t es8311_get_voice_mute(int *mute)
699
680
700
681
error_t es8311_set_mic_gain (es8311_mic_gain_t gain_db )
701
682
{
683
+ if (i2c_handle == 0 ) return RESULT_FAIL ;
702
684
error_t res = RESULT_OK ;
703
685
res = es8311_write_reg (ES8311_ADC_REG16 , gain_db ); // MIC gain scale
704
686
return res ;
0 commit comments