Skip to content

Commit 8e89a4e

Browse files
committed
Init i2c_handle to NULL
1 parent 0d0b723 commit 8e89a4e

File tree

8 files changed

+17
-35
lines changed

8 files changed

+17
-35
lines changed

src/Driver/cs43l22/cs43l22.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
// };
104104

105105
static uint8_t Is_cs43l22_Stop = 1;
106-
static i2c_bus_handle_t i2c_handle;
106+
static i2c_bus_handle_t i2c_handle = NULL;
107107
volatile uint8_t OutputDev = 0;
108108

109109
/**

src/Driver/es7210/es7210.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct _coeff_div {
5252
uint32_t lrck_l; /* The low 8 bits of lrck */
5353
};
5454

55-
static i2c_bus_handle_t i2c_handle;
55+
static i2c_bus_handle_t i2c_handle = NULL;
5656
static es7210_input_mics_t mic_select = ES7210_INPUT_MIC1 | ES7210_INPUT_MIC2; /* Number of microphones */
5757

5858
/* Codec hifi mclk clock divider coefficients

src/Driver/es7243/es7243.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
return b;\
3535
}
3636

37-
static i2c_bus_handle_t i2c_handle;
37+
static i2c_bus_handle_t i2c_handle = NULL;
3838
static int es7243_addr = 0x13; // 0x26>>1;
3939
static int mclk_gpio = 0;
4040

src/Driver/es7243e/es7243e.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
//static char *TAG = "DRV7243E";
29-
static i2c_bus_handle_t i2c_handle;
29+
static i2c_bus_handle_t i2c_handle = NULL;
3030
static int es7243e_addr = 0x10; //0x20 >> 1;
3131

3232
static error_t es7243e_write_reg(uint8_t reg_add, uint8_t data)

src/Driver/es8156/es8156.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
//static const char *TAG = "DRV8156";
3737
static bool codec_init_flag = 0;
38-
static i2c_bus_handle_t i2c_handle;
38+
static i2c_bus_handle_t i2c_handle = NULL;
3939
static codec_dac_volume_config_t *dac_vol_handle;
4040

4141
#define ES8156_DAC_VOL_CFG_DEFAULT() { \

src/Driver/es8311/es8311.c

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,9 @@
5353

5454
#define MCLK_DIV_FRE 256
5555

56-
static i2c_bus_handle_t i2c_handle;
56+
static i2c_bus_handle_t i2c_handle = NULL;
5757
static int i2c_address_es8311 = ES8311_ADDR;
5858

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-
7459
/*
7560
* Clock coefficient structer
7661
*/
@@ -268,18 +253,6 @@ static void es8311_suspend(void)
268253
es8311_write_reg(ES8311_GP_REG45, 0x01);
269254
}
270255

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-
// }
283256

284257
error_t es8311_codec_init(codec_config_t *codec_cfg, i2c_bus_handle_t handle, int8_t mclk_src, int i2c_address)
285258
{
@@ -288,6 +261,7 @@ error_t es8311_codec_init(codec_config_t *codec_cfg, i2c_bus_handle_t handle, in
288261
int coeff;
289262
error_t ret = RESULT_OK;
290263
i2c_handle = handle;
264+
assert(i2c_handle != NULL);
291265
if (i2c_address > 0){
292266
i2c_address_es8311 = i2c_address;
293267
}
@@ -330,16 +304,19 @@ error_t es8311_codec_init(codec_config_t *codec_cfg, i2c_bus_handle_t handle, in
330304
*/
331305
switch (get_es8311_mclk_src()) {
332306
case FROM_MCLK_PIN:
307+
AD_LOGI( "ES8311 clock source: MCLK");
333308
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG01);
334309
regv &= 0x7F;
335310
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG01, regv);
336311
break;
337312
case FROM_SCLK_PIN:
313+
AD_LOGI( "ES8311 clock source: SCLK");
338314
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG01);
339315
regv |= 0x80;
340316
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG01, regv);
341317
break;
342318
default:
319+
AD_LOGI( "ES8311 clock source: MCLK");
343320
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG01);
344321
regv &= 0x7F;
345322
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG01, regv);
@@ -651,6 +628,7 @@ error_t es8311_stop(codec_mode_t mode)
651628

652629
error_t es8311_codec_set_voice_volume(int volume)
653630
{
631+
if (i2c_handle == 0) return RESULT_FAIL;
654632
error_t res = RESULT_OK;
655633
if (volume < 0) {
656634
volume = 0;
@@ -665,6 +643,7 @@ error_t es8311_codec_set_voice_volume(int volume)
665643

666644
error_t es8311_codec_get_voice_volume(int *volume)
667645
{
646+
if (i2c_handle == 0) return RESULT_FAIL;
668647
error_t res = RESULT_OK;
669648
int regv = 0;
670649
regv = es8311_read_reg(ES8311_DAC_REG32);
@@ -681,12 +660,14 @@ error_t es8311_codec_get_voice_volume(int *volume)
681660
error_t es8311_set_voice_mute(bool enable)
682661
{
683662
AD_LOGD( "Es8311SetVoiceMute volume:%d", enable);
663+
if (i2c_handle == 0) return RESULT_FAIL;
684664
es8311_mute(enable);
685665
return RESULT_OK;
686666
}
687667

688668
error_t es8311_get_voice_mute(int *mute)
689669
{
670+
if (i2c_handle == 0) return RESULT_FAIL;
690671
error_t res = RESULT_OK;
691672
uint8_t reg = 0;
692673
res = es8311_read_reg(ES8311_DAC_REG31);
@@ -699,6 +680,7 @@ error_t es8311_get_voice_mute(int *mute)
699680

700681
error_t es8311_set_mic_gain(es8311_mic_gain_t gain_db)
701682
{
683+
if (i2c_handle == 0) return RESULT_FAIL;
702684
error_t res = RESULT_OK;
703685
res = es8311_write_reg(ES8311_ADC_REG16, gain_db); // MIC gain scale
704686
return res;

src/Driver/es8374/es8374.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535

3636
static int codec_init_flag = 0;
37-
static i2c_bus_handle_t i2c_handle;
37+
static i2c_bus_handle_t i2c_handle = NULL;
3838
static int i2c_address_es8374 = ES8374_ADDR;
3939

4040

src/Driver/wm8994/wm8994.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106

107107
static uint32_t outputEnabled = 0;
108108
static uint32_t inputEnabled = 0;
109-
static void* i2c_handle;
109+
static void* i2c_handle = NULL;
110110
/**
111111
* @}
112112
*/

0 commit comments

Comments
 (0)