[Bugfix][API-1621][audio] add api to set  mic volume and zk default mic
volume is set to 1

Only Configure: No
Affected branch: MR3.0-Merge-v2.0-ZK
Affected module: audio
Is it affected on both ZXIC and MTK: mtk
Self-test: Yes
Doc Update: No

Change-Id: I2931f8c39f8088adaff9cf413724c3d4983a508f
diff --git a/LYNQ_PUBLIC/IC_src/mtk/lib/liblynq-codec/include/lynq_codec.h b/LYNQ_PUBLIC/IC_src/mtk/lib/liblynq-codec/include/lynq_codec.h
index 2e3cf37..8316c93 100755
--- a/LYNQ_PUBLIC/IC_src/mtk/lib/liblynq-codec/include/lynq_codec.h
+++ b/LYNQ_PUBLIC/IC_src/mtk/lib/liblynq-codec/include/lynq_codec.h
@@ -21,6 +21,8 @@
 int get_customer_tone_sample_rate();
 int customer_set_pa_volume(const int volume);
 int customer_get_pa_volume(int* volume);
+int set_codec_mic_volume(const int volume);
+int get_codec_mic_volume(int* volume);
 
 #ifdef __cplusplus
 }
diff --git a/LYNQ_PUBLIC/IC_src/mtk/lib/liblynq-codec/liblynq-codec/lynq_codec.c b/LYNQ_PUBLIC/IC_src/mtk/lib/liblynq-codec/liblynq-codec/lynq_codec.c
index e474b27..af7ffa5 100755
--- a/LYNQ_PUBLIC/IC_src/mtk/lib/liblynq-codec/liblynq-codec/lynq_codec.c
+++ b/LYNQ_PUBLIC/IC_src/mtk/lib/liblynq-codec/liblynq-codec/lynq_codec.c
@@ -111,6 +111,16 @@
     fclose(fp);

 }

 

+#ifdef ZK_CODEC_CFG

+static int s_codec_mic_volume=1;

+

+static char s_codec_cmd_buf[16];

+

+void get_set_codec_cmd(int reg_num, int value)

+{   

+    snprintf(s_codec_cmd_buf, sizeof(s_codec_cmd_buf), "0x%02x 0x%02x", reg_num, value);  

+}

+

 void set_zk_3104_codec(int open)

 {

     RLOGD("set_codec %d",open);

@@ -154,8 +164,10 @@
         write_codec_reg("0x0b 0x32");

         write_codec_reg("0x0c 0x00");

         write_codec_reg("0x0d 0x00");

-        write_codec_reg("0x0f 0x10");

-        write_codec_reg("0x10 0x20");

+        get_set_codec_cmd(15,s_codec_mic_volume);

+        write_codec_reg(s_codec_cmd_buf);        

+        get_set_codec_cmd(16,s_codec_mic_volume);

+        write_codec_reg(s_codec_cmd_buf);        

         write_codec_reg("0x11 0xf8");

         write_codec_reg("0x12 0xff");

         /*dongyu@2023.7.12 ZK ADC/DAC 0x13 power supply default off state, turn on during call, turn off after hang up*/

@@ -254,6 +266,7 @@
         write_codec_reg("0x6d 0x00");

     }

 }

+#endif

 

 /*hqing add for Geely demand on 11/07/2022, after playing audio, codec should sleep*/

 static void set_gsw_3104_codec(codec_op open)

@@ -515,6 +528,19 @@
 

 }

 

+int set_codec_mic_volume(const int volume)

+{

+    s_codec_mic_volume = volume;

+    return 0;

+}

+

+int get_codec_mic_volume(int* volume)

+{

+    (*volume)=s_codec_mic_volume;

+    return 0;

+}

+

+

 #elif defined(GSW_CODEC_CFG)

 

 void set_codec(media_src_t src, codec_op open_close)

@@ -545,6 +571,19 @@
     return -1;

 }

 

+int set_codec_mic_volume(const int volume)

+{

+    RLOGE("not implement\n");

+    return 1;

+}

+

+int get_codec_mic_volume(int* volume)

+{

+    RLOGE("not implement\n");

+    return 1;

+}

+

+

 #else

 const char * get_customer_tone_path()

 {

@@ -573,4 +612,16 @@
     RLOGE("not implement\n");

 }

 

+int set_codec_mic_volume(const int volume)

+{

+    RLOGE("not implement\n");

+    return 1;

+}

+

+int get_codec_mic_volume(int* volume)

+{

+    RLOGE("not implement\n");

+    return 1;

+}

+

 #endif

diff --git a/LYNQ_PUBLIC/common_src/lib/liblynq-media/liblynq-media/media_control.c b/LYNQ_PUBLIC/common_src/lib/liblynq-media/liblynq-media/media_control.c
index 92a8db3..45c4fc1 100755
--- a/LYNQ_PUBLIC/common_src/lib/liblynq-media/liblynq-media/media_control.c
+++ b/LYNQ_PUBLIC/common_src/lib/liblynq-media/liblynq-media/media_control.c
@@ -150,8 +150,14 @@
     } 

     return real_volume;

 }

- int lynq_set_mic_volume(const int volume) {

-    int real_volume;

+

+int lynq_set_mic_volume(const int volume) {

+    if(set_codec_mic_volume(volume)==0)

+    {

+        return 0;

+    }

+ 

+    int real_volume;    

     if((volume>MIC_VOLUME_LEVEL7)||(volume<MIC_VOLUME_LEVEL1))

     return 1;

     lynq_set_mic_volume_to_nvram(volume);

@@ -165,6 +171,11 @@
     {

         return 1;

     }

+

+    if(get_codec_mic_volume(volume)==0)

+    {

+        return 0;

+    }

    

     (*volume) = lynq_get_mic_current_volume();

     return 0;