Skip to content

Commit

Permalink
Init i2c_handle to NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Nov 1, 2024
1 parent 0d0b723 commit 8e89a4e
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/Driver/cs43l22/cs43l22.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
// };

static uint8_t Is_cs43l22_Stop = 1;
static i2c_bus_handle_t i2c_handle;
static i2c_bus_handle_t i2c_handle = NULL;
volatile uint8_t OutputDev = 0;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/es7210/es7210.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct _coeff_div {
uint32_t lrck_l; /* The low 8 bits of lrck */
};

static i2c_bus_handle_t i2c_handle;
static i2c_bus_handle_t i2c_handle = NULL;
static es7210_input_mics_t mic_select = ES7210_INPUT_MIC1 | ES7210_INPUT_MIC2; /* Number of microphones */

/* Codec hifi mclk clock divider coefficients
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/es7243/es7243.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
return b;\
}

static i2c_bus_handle_t i2c_handle;
static i2c_bus_handle_t i2c_handle = NULL;
static int es7243_addr = 0x13; // 0x26>>1;
static int mclk_gpio = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/Driver/es7243e/es7243e.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


//static char *TAG = "DRV7243E";
static i2c_bus_handle_t i2c_handle;
static i2c_bus_handle_t i2c_handle = NULL;
static int es7243e_addr = 0x10; //0x20 >> 1;

static error_t es7243e_write_reg(uint8_t reg_add, uint8_t data)
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/es8156/es8156.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

//static const char *TAG = "DRV8156";
static bool codec_init_flag = 0;
static i2c_bus_handle_t i2c_handle;
static i2c_bus_handle_t i2c_handle = NULL;
static codec_dac_volume_config_t *dac_vol_handle;

#define ES8156_DAC_VOL_CFG_DEFAULT() { \
Expand Down
38 changes: 10 additions & 28 deletions src/Driver/es8311/es8311.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,9 @@

#define MCLK_DIV_FRE 256

static i2c_bus_handle_t i2c_handle;
static i2c_bus_handle_t i2c_handle = NULL;
static int i2c_address_es8311 = ES8311_ADDR;

// /*
// * operate function of codec
// */
// func_t AUDIO_CODEC_ES8311_DEFAULT_HANDLE = {
// .audio_codec_initialize = es8311_codec_init,
// .audio_codec_deinitialize = es8311_codec_deinit,
// .audio_codec_ctrl = es8311_codec_ctrl_state_active,
// .audio_codec_config_iface = es8311_codec_config_i2s,
// .audio_codec_set_mute = es8311_set_voice_mute,
// .audio_codec_set_volume = es8311_codec_set_voice_volume,
// .audio_codec_get_volume = es8311_codec_get_voice_volume,
// .lock = NULL,
// .handle = NULL,
// };

/*
* Clock coefficient structer
*/
Expand Down Expand Up @@ -268,18 +253,6 @@ static void es8311_suspend(void)
es8311_write_reg(ES8311_GP_REG45, 0x01);
}

// /*
// * enable pa power
// */
// void es8311_pa_power(bool enable)
// {
// pinMode(get_pa_enable_gpio(), OUTPUT);
// if (enable) {
// digitalWrite(get_pa_enable_gpio(), HIGH);
// } else {
// digitalWrite(get_pa_enable_gpio(), LOW);
// }
// }

error_t es8311_codec_init(codec_config_t *codec_cfg, i2c_bus_handle_t handle, int8_t mclk_src, int i2c_address)
{
Expand All @@ -288,6 +261,7 @@ error_t es8311_codec_init(codec_config_t *codec_cfg, i2c_bus_handle_t handle, in
int coeff;
error_t ret = RESULT_OK;
i2c_handle = handle;
assert(i2c_handle != NULL);
if (i2c_address > 0){
i2c_address_es8311 = i2c_address;
}
Expand Down Expand Up @@ -330,16 +304,19 @@ error_t es8311_codec_init(codec_config_t *codec_cfg, i2c_bus_handle_t handle, in
*/
switch (get_es8311_mclk_src()) {
case FROM_MCLK_PIN:
AD_LOGI( "ES8311 clock source: MCLK");
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG01);
regv &= 0x7F;
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG01, regv);
break;
case FROM_SCLK_PIN:
AD_LOGI( "ES8311 clock source: SCLK");
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG01);
regv |= 0x80;
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG01, regv);
break;
default:
AD_LOGI( "ES8311 clock source: MCLK");
regv = es8311_read_reg(ES8311_CLK_MANAGER_REG01);
regv &= 0x7F;
ret |= es8311_write_reg(ES8311_CLK_MANAGER_REG01, regv);
Expand Down Expand Up @@ -651,6 +628,7 @@ error_t es8311_stop(codec_mode_t mode)

error_t es8311_codec_set_voice_volume(int volume)
{
if (i2c_handle == 0) return RESULT_FAIL;
error_t res = RESULT_OK;
if (volume < 0) {
volume = 0;
Expand All @@ -665,6 +643,7 @@ error_t es8311_codec_set_voice_volume(int volume)

error_t es8311_codec_get_voice_volume(int *volume)
{
if (i2c_handle == 0) return RESULT_FAIL;
error_t res = RESULT_OK;
int regv = 0;
regv = es8311_read_reg(ES8311_DAC_REG32);
Expand All @@ -681,12 +660,14 @@ error_t es8311_codec_get_voice_volume(int *volume)
error_t es8311_set_voice_mute(bool enable)
{
AD_LOGD( "Es8311SetVoiceMute volume:%d", enable);
if (i2c_handle == 0) return RESULT_FAIL;
es8311_mute(enable);
return RESULT_OK;
}

error_t es8311_get_voice_mute(int *mute)
{
if (i2c_handle == 0) return RESULT_FAIL;
error_t res = RESULT_OK;
uint8_t reg = 0;
res = es8311_read_reg(ES8311_DAC_REG31);
Expand All @@ -699,6 +680,7 @@ error_t es8311_get_voice_mute(int *mute)

error_t es8311_set_mic_gain(es8311_mic_gain_t gain_db)
{
if (i2c_handle == 0) return RESULT_FAIL;
error_t res = RESULT_OK;
res = es8311_write_reg(ES8311_ADC_REG16, gain_db); // MIC gain scale
return res;
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/es8374/es8374.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@


static int codec_init_flag = 0;
static i2c_bus_handle_t i2c_handle;
static i2c_bus_handle_t i2c_handle = NULL;
static int i2c_address_es8374 = ES8374_ADDR;


Expand Down
2 changes: 1 addition & 1 deletion src/Driver/wm8994/wm8994.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@

static uint32_t outputEnabled = 0;
static uint32_t inputEnabled = 0;
static void* i2c_handle;
static void* i2c_handle = NULL;
/**
* @}
*/
Expand Down

0 comments on commit 8e89a4e

Please sign in to comment.