[Feature][ZXW-33]merge ZXW 0428 version
Change-Id: I11f167edfea428d9fab198ff00ff1364932d1b0b
diff --git a/ap/lib/libatext/ext_audio_func.c b/ap/lib/libatext/ext_audio_func.c
new file mode 100755
index 0000000..f1b45a7
--- /dev/null
+++ b/ap/lib/libatext/ext_audio_func.c
@@ -0,0 +1,508 @@
+/************************************************************************
+*¹¦ÄܽéÉÜ£ºÆ½Ì¨ÄÚ²¿À©Õ¹at¿Í»§¶ËºÍ·þÎñ¶Ë×¢²á£¬ËùÓÐ×¢²á¾ùÔÚext_regist_init½Ó¿ÚÖÐÍê³É£¬ÓÉat_ctlÔÚÆô¶¯Ê±µ÷ÓÃ
+*¸ºÔðÈË£º
+*±¸·ÝÈË£º
+*ÐÞ¸ÄÈÕ£º
+*ÐÞ¸ÄÄÚÈÝ£º
+*°æ±¾ºÅ£º
+************************************************************************/
+#if (APP_OS_TYPE == APP_OS_LINUX)
+#include "at_msg.h"
+#include "at_com.h"
+#include "at_context.h"
+#include "ext_dev_func.h"
+#include "ext_cmux_func.h"
+#ifdef _USE_VOICE_ALSA
+#include "tinyalsa/audio_mixer_ctrl.h"
+#include "voice_lib.h"
+#endif
+//#include "ext_regist.h"
+//#include "softap_api.h"
+//#include "at_utils.h"
+//#include "pub/drvs_ret.h"
+//#include "earpiece_api.h"
+#define DRV_SUCCESS 0
+
+/*
+typedef enum
+{
+ VP_PATH_HANDSET =0,
+ VP_PATH_SPEAKER,
+ VP_PATH_HEADSET,
+ VP_PATH_BLUETOOTH,
+ VP_PATH_BLUETOOTH_NO_NR,
+ VP_PATH_HSANDSPK,
+
+ VP_PATH_OFF = 255,
+
+ MAX_VP_PATH = VP_PATH_OFF
+}T_ZDrv_VpPath;
+*/
+/* Voice input channel selection. */
+typedef enum
+{
+ CODEC_INPUT_MICPHONE =0, /*input path in earphone mic*/
+ CODEC_INPUT_HEADSET, /*input path in headset*/
+ CODEC_INPUT_BLUETOOTH, /*input path in bluetooth*/
+ CODEC_INPUT_HANDSFREE, /*input path in mic(handsfree)*/
+
+ MAX_CODEC_INPUT_PATH
+} T_ZDrv_CodecInputPath;
+
+/* Voice output channel selection. */
+typedef enum
+{
+ CODEC_OUTPUT_RECEIVER =0, /*output path in receiver*/
+ CODEC_OUTPUT_SPEAKER, /*output path in speaker*/
+ CODEC_OUTPUT_HEADSET, /*output path in headset*/
+ CODEC_OUTPUT_BLUETOOTH, /*output path in bluetooth*/
+ CODEC_OUTPUT_HSANDSPK, /*output path in both headset and speaker*/
+
+
+ MAX_CODEC_OUTPUT_PATH
+}T_ZDrv_CodecOutputPath;
+#ifdef _CONFIG_USE_CODEC_EARPIECE_DETECT
+extern SINT32 halEarp_Open(VOID);
+extern SINT32 halEarp_Close(VOID);
+extern SINT32 halEarp_GetPlugStatus(T_ZDrvEarp_State* plug_status);
+#endif
+
+#ifdef _CONFIG_USE_CODEC
+extern SINT32 halAudioConfig_ReadReg (UINT16 regPage, UINT16 regAddress, UINT16 *regValue);
+extern SINT32 halAudioConfig_WriteReg (UINT16 regPage, UINT16 regAddress, UINT16 regValue, UINT16 regMask);
+extern SINT32 halAudioConfig_DumpReg (VOID);
+
+
+int codecWrite_act_func (int at_fd, char * at_paras, void * *res_msg, int * res_msglen)
+{
+ char *at_str = NULL;
+ UINT32 ret = DRV_SUCCESS;
+ UINT8 pPtr[40] = {0};
+ int a[4] = {0};
+ //CHAR b[6] = {0};
+ //CHAR c[6] = {0};
+ //CHAR d[6] = {0};
+ UINT16 reg_page = 0;
+ UINT16 reg_index = 0;
+ UINT16 write_value = 0;
+ UINT16 write_mask = 0;
+ at_str = at_paras;
+ at_print(AT_DEBUG,"codecWrite_act_func, at_paras:%s \n", at_paras);
+
+ //ret = sscanf (at_str, "%[0-9],%[0-9],%[0-9],%[0-9]", a, b, c, d);
+ ret = sscanf (at_str, "%d,%d,%d,%d", &a[0], &a[1], &a[2], &a[3]);
+ reg_page = a[0];
+ reg_index = a[1];
+ write_value = a[2];
+ write_mask = a[3];
+ at_print(AT_DEBUG,"zCtrm_ExtAT_WRCODEC reg_page=0x%x, reg_index=0x%x, write_value=0x%x, write_mask=0x%x\n", reg_page, reg_index, write_value, write_mask);
+
+ if (ret == 4) {
+ ret = halAudioConfig_WriteReg (reg_page, reg_index, write_value, write_mask);
+ if (ret == DRV_SUCCESS) {
+ *res_msg = at_ok_build();
+ *res_msglen = strlen (*res_msg);
+ return AT_END;
+ }
+ }
+
+ *res_msg = at_err_build(ATERR_PROC_FAILED);
+ *res_msglen = strlen (*res_msg);
+ return AT_END;
+}
+
+int codecRead_act_func (int at_fd, char * at_paras, void * *res_msg, int * res_msglen)
+{
+ char *at_str = NULL;
+ at_str = at_paras;
+ UINT32 ret = DRV_SUCCESS;
+ int a[2] = {0};
+ //CHAR b[6] = {0};
+ CHAR re_str[30] = {'\0'};
+
+ UINT16 reg_page = 0;
+ UINT16 reg_index = 0;
+ UINT16 read_value = 0;
+ at_print(AT_DEBUG,"codecRead_act_func, at_paras:%s \n", at_paras);
+
+ //ret = sscanf (at_str, "%[0-9],%[0-9]", a, b);
+ ret = sscanf (at_str, "%d,%d", &a[0], &a[1]);
+ reg_page = a[0];
+ reg_index = a[1];
+ at_print(AT_DEBUG,"codecRead_act_func reg_page=0x%x, reg_index=0x%x \n", reg_page, reg_index);
+
+ if (ret == 2) {
+ ret = halAudioConfig_ReadReg (reg_page, reg_index, &read_value);
+ if (ret == DRV_SUCCESS) {
+
+ sprintf(re_str, "0x%x=0x%x\r\n" , reg_index,read_value);
+
+ *res_msg = at_query_result_build("reg",re_str);
+
+ //*res_msg = at_ok_build();
+ *res_msglen = strlen (*res_msg);
+ return AT_END;
+ }
+ }
+
+ *res_msg = at_err_build(ATERR_PROC_FAILED);
+ *res_msglen = strlen (*res_msg);
+ return AT_END;
+}
+
+int codecDump_act_func (int at_fd, char * at_paras, void * *res_msg, int * res_msglen)
+{
+ char *at_str = NULL;
+ at_str = at_paras;
+ UINT32 ret = DRV_SUCCESS;
+ at_print(AT_DEBUG,"codecDump_act_func, at_paras:%s \n", at_paras);
+
+ if (*at_str == '1') {
+ at_print(AT_DEBUG,"codecDump_act_func is ok. \n");
+ ret = halAudioConfig_DumpReg();
+ if (ret == DRV_SUCCESS) {
+ *res_msg = at_ok_build();
+ *res_msglen = strlen (*res_msg);
+ return AT_END;
+ }
+ }
+
+ *res_msg = at_err_build(ATERR_PROC_FAILED);
+ *res_msglen = strlen (*res_msg);
+ return AT_END;
+
+
+}
+//ƽ̨ÄÚ²¿À©Õ¹atÃüÁ·¢£¬ËùÓÐÀ©Õ¹µÄ¿Í»§¶ËºÍ·þÎñ¶ËatÃüÁ¾ùÐèÒªÔڸú¯ÊýÖУ¬¸Ãº¯Êý»áÔÚat_ctlÓ¦Óóõʼ»¯Ê±£¬Íê³ÉÉÏÊöatÃüÁîµÄ×¢²á
+
+
+int extAtSdev_act_func (int at_fd, char * at_paras, void * *res_msg, int * res_msglen)
+{
+ char *at_str = NULL;
+ UINT32 ret = DRV_SUCCESS;
+ T_ZDrv_VpPath path;
+
+ UINT8 pPtr[40] = {0};
+ int a = 0;
+ //CHAR b[6] = {0};
+ UINT16 dev_num = 0;
+ at_str = at_paras;
+ at_print(AT_DEBUG,"extAtSdev_act_func, at_paras:%s \n", at_paras);
+
+ ret = sscanf (at_str, "%d", &a);
+ dev_num = a;
+ at_print(AT_DEBUG,"extAtSdev_act_func dev_num=0x%d\n", dev_num);
+
+ if (ret == 1) {
+
+ if(dev_num == 0)
+ {
+ path = VP_PATH_HANDSET;
+ at_print(AT_DEBUG, "[MDL] extAtSdev_act_func output channel=%d\r",dev_num);
+ }
+ else if(dev_num == 1)
+ {
+ path = VP_PATH_SPEAKER;
+ at_print(AT_DEBUG, "[MDL] extAtSdev_act_func output channel=%d\r",dev_num);
+ }
+ else if(dev_num == 2)
+ {
+ path = VP_PATH_HEADSET;
+ at_print(AT_DEBUG, "[MDL] extAtSdev_act_func output channel=%d\r",dev_num);
+ }
+ else
+ {
+ sprintf ( (char *) pPtr, "\r\n%s\r\n", "+CME ERROR: 6004");
+ path = VP_PATH_HANDSET;
+ *res_msg = at_err_build ("pPtr");
+ *res_msglen = strlen (*res_msg);
+ return AT_END;
+ }
+
+ ret = zDrvVp_SetPath(path);
+ if (ret == DRV_SUCCESS) {
+ *res_msg = at_ok_build();
+ *res_msglen = strlen (*res_msg);
+ return AT_END;
+ }
+ *res_msg = at_err_build(ATERR_PROC_FAILED);
+ *res_msglen = strlen (*res_msg);
+
+ return AT_END;
+ }
+ return AT_END;
+}
+int extAtRxPath_act_func (int at_fd, char * at_paras, void * *res_msg, int * res_msglen)
+{
+ char *at_str = NULL;
+ UINT32 ret = DRV_SUCCESS;
+ T_ZDrv_CodecOutputPath path;
+
+ UINT8 pPtr[40] = {0};
+ int a[2] = {0};
+ //CHAR b[6] = {0};
+ UINT16 dev_num = 0;
+ UINT16 isenable = 0;
+ at_str = at_paras;
+ at_print(AT_DEBUG,"extAtSdev_act_func, at_paras:%s \n", at_paras);
+
+ ret = sscanf (at_str, "%d %d", &a[0], &a[1]);
+ dev_num = a[0];
+ isenable = a[1];
+ at_print(AT_DEBUG,"extAtSdev_act_func dev_num=0x%d\n", dev_num);
+
+ if (ret == 2) {
+
+ if(dev_num == 0)
+ {
+ path = CODEC_OUTPUT_RECEIVER;
+ at_print(AT_DEBUG, "[MDL] extAtSdev_act_func output channel=%d\r",dev_num);
+ }
+ else if(dev_num == 1)
+ {
+ path = CODEC_OUTPUT_SPEAKER;
+ at_print(AT_DEBUG, "[MDL] extAtSdev_act_func output channel=%d\r",dev_num);
+ }
+ else if(dev_num == 2)
+ {
+ path = CODEC_OUTPUT_HEADSET;
+ at_print(AT_DEBUG, "[MDL] extAtSdev_act_func output channel=%d\r",dev_num);
+ }
+ else
+ {
+ sprintf ( (char *) pPtr, "\r\n%s\r\n", "+CME ERROR: 6004");
+ path = CODEC_OUTPUT_RECEIVER;
+ *res_msg = at_err_build ("pPtr");
+ *res_msglen = strlen (*res_msg);
+ return AT_END;
+ }
+
+ //ret = zDrvVp_SetTxPath(CODEC_INPUT_MICPHONE, TRUE);
+ ret = zDrvVp_SetRxPath(path, isenable);
+ if (ret == DRV_SUCCESS) {
+ *res_msg = at_ok_build();
+ *res_msglen = strlen (*res_msg);
+ return AT_END;
+ }
+ *res_msg = at_err_build(ATERR_PROC_FAILED);
+ *res_msglen = strlen (*res_msg);
+
+ return AT_END;
+ }
+ return AT_END;
+}
+int extAtTxPath_act_func (int at_fd, char * at_paras, void * *res_msg, int * res_msglen)
+{
+ char *at_str = NULL;
+ UINT32 ret = DRV_SUCCESS;
+ T_ZDrv_VpPath path;
+
+ UINT8 pPtr[40] = {0};
+ int a[2] = {0};
+ //CHAR b[6] = {0};
+ UINT16 dev_num = 0;
+ UINT16 isenable = 0;
+ at_str = at_paras;
+ at_print(AT_DEBUG,"extAtSdev_act_func, at_paras:%s \n", at_paras);
+
+ ret = sscanf (at_str, "%d %d", &a[0], &a[1]);
+ dev_num = a[0];
+ isenable = a[1];
+ at_print(AT_DEBUG,"extAtSdev_act_func dev_num=0x%d\n", dev_num);
+
+ if (ret == 2) {
+
+ if(dev_num == 0)
+ {
+ path = CODEC_INPUT_MICPHONE; //IN2P
+ at_print(AT_DEBUG, "[MDL] extAtSdev_act_func output channel=%d\r",dev_num);
+ }
+ else if(dev_num == 1)
+ {
+ path = CODEC_INPUT_HANDSFREE; //CODEC_INPUT_HEADSET IN2P
+ at_print(AT_DEBUG, "[MDL] extAtSdev_act_func output channel=%d\r",dev_num);
+ }
+ else if(dev_num == 2)
+ {
+ path = CODEC_INPUT_HEADSET; //CODEC_INPUT_HANDSFREE IN1P
+ at_print(AT_DEBUG, "[MDL] extAtSdev_act_func output channel=%d\r",dev_num);
+ }
+ else
+ {
+ sprintf ( (char *) pPtr, "\r\n%s\r\n", "+CME ERROR: 6004");
+ path = VP_PATH_HANDSET;
+ *res_msg = at_err_build ("pPtr");
+ *res_msglen = strlen (*res_msg);
+ return AT_END;
+ }
+
+ ret = zDrvVp_SetTxPath(path, isenable);
+ if (ret == DRV_SUCCESS) {
+ *res_msg = at_ok_build();
+ *res_msglen = strlen (*res_msg);
+ return AT_END;
+ }
+
+ *res_msg = at_err_build(ATERR_PROC_FAILED);
+ *res_msglen = strlen (*res_msg);
+
+ return AT_END;
+ }
+ return AT_END;
+}
+#endif
+
+#ifdef _CONFIG_USE_CODEC_EARPIECE_DETECT
+int extAtEarp_act_func (int at_fd, char * at_paras, void * *res_msg, int * res_msglen)
+{
+ char *at_str = NULL;
+ UINT32 ret = DRV_SUCCESS;
+ T_ZDrv_VpPath path;
+
+ UINT8 pPtr[40] = {0};
+ int a = 0;
+ //CHAR b[6] = {0};
+ UINT16 onOff = 0;
+ at_str = at_paras;
+ at_print(AT_DEBUG,"extAtSdev_act_func, at_paras:%s \n", at_paras);
+
+ ret = sscanf (at_str, "%d", &a);
+ onOff = a;
+ at_print(AT_DEBUG,"extAtSdev_act_func dev_num=0x%d\n", onOff);
+
+ if (ret == 1) {
+ if(onOff == 1)
+ {
+ ret = halEarp_Open();
+ }
+ else
+ {
+ ret = halEarp_Close();
+ }
+
+ if (ret == DRV_SUCCESS) {
+ *res_msg = at_ok_build();
+ *res_msglen = strlen (*res_msg);
+ return AT_END;
+ }
+ }
+ *res_msg = at_err_build(ATERR_PROC_FAILED);
+ *res_msglen = strlen (*res_msg);
+
+ return AT_END;
+}
+#endif
+#ifdef _USE_VOICE_ALSA
+
+
+
+
+
+
+int extAt_VPATH_act_func (int at_fd, char * at_paras, void * *res_msg, int * res_msglen)
+{
+ char *at_str = NULL;
+ UINT32 ret = DRV_SUCCESS;
+ int path;
+ int a = 0;
+ //CHAR b[6] = {0};
+ UINT16 onOff = 0;
+ at_str = at_paras;
+ at_print(AT_DEBUG,"extAt_VPATH_act_func, at_paras:%s \n", at_paras);
+
+ ret = sscanf (at_str, "%d,%d",&path,&a);
+ onOff = a;
+ at_print(AT_DEBUG,"extAt_VPATH_act_func path =%d,onOff=0x%d\n",path, onOff);
+
+ if (ret == 2) {
+ if(onOff == 1)
+ {
+ ret = set_voice_device_mode(path);
+ printf("extAt_VPATH_act_func on vpath,ret=%d\n",ret);
+ }
+ else
+ {
+ //ret = set_voice_device_mode(path);
+ printf("extAt_VPATH_act_func off vpath not support\n");
+
+ }
+ if (ret == DRV_SUCCESS) {
+ *res_msg = at_ok_build();
+ *res_msglen = strlen (*res_msg);
+ return AT_END;
+ }
+ }
+
+ *res_msg = at_err_build(ATERR_PROC_FAILED);
+ *res_msglen = strlen (*res_msg);
+
+ return AT_END;
+}
+
+int extAt_VALSA_act_func (int at_fd, char * at_paras, void * *res_msg, int * res_msglen)
+{
+ char *at_str = NULL;
+ UINT32 ret = DRV_SUCCESS;
+
+ int mode = 0;
+ int enable = 0;
+
+ UINT16 onOff = 0;
+ at_str = at_paras;
+ printf("extAt_VALSA_act_func, at_paras:%s \n", at_paras);
+
+ ret = sscanf (at_str, "%d,%d", &mode,&enable);
+ onOff = enable;
+ printf("extAt_VALSA_act_func mode=%d,enable=%d,ret=%d\n",mode,enable,ret);
+
+ if (ret == 2) {
+ if(onOff == 1)
+ {
+ ret = alsa_voice_open(mode);
+ printf("extAt_voice_act_func alsa_voice_open,ret=%d\n",ret);
+ }
+ else
+ {
+ ret = alsa_voice_close(mode);
+ printf("extAt_voice_act_func alsa_voice_close,ret=%d\n",ret);
+
+ }
+ if (ret == DRV_SUCCESS) {
+ *res_msg = at_ok_build();
+ *res_msglen = strlen (*res_msg);
+ return AT_END;
+ }
+ }
+ *res_msg = at_err_build(ATERR_PROC_FAILED);
+ *res_msglen = strlen (*res_msg);
+
+ return AT_END;
+}
+
+#endif
+
+void ext_audio_regist_init(void)
+{
+ printf("ext_audio_regist_init! \n");
+
+#ifdef _CONFIG_USE_CODEC
+ register_serv_func2("WRCODEC=", 0, 0, 0, codecWrite_act_func, NULL);
+ register_serv_func2("RDCODEC=", 0, 0, 0, codecRead_act_func, NULL);
+ register_serv_func2("DUMPCODECREG=", 0, 0, 0, codecDump_act_func, NULL);
+ register_serv_func2("ExtAT_SDEV=", 0, 0, 0, extAtSdev_act_func, NULL);
+ register_serv_func2("ExtAT_RXPATH=", 0, 0, 0, extAtRxPath_act_func, NULL);
+ register_serv_func2("ExtAT_TXPATH=", 0, 0, 0, extAtTxPath_act_func, NULL);
+#endif
+#ifdef _CONFIG_USE_CODEC_EARPIECE_DETECT
+ register_serv_func2("ExtAT_EARP=", 0, 0, 0, extAtEarp_act_func, NULL);
+#endif
+
+#ifdef _USE_VOICE_ALSA
+
+ register_serv_func2("VALSA=", 0, 0, 0, extAt_VALSA_act_func, NULL);
+ register_serv_func2("VPATH=", 0, 0, 0, extAt_VPATH_act_func, NULL);
+
+#endif
+}
+
+#endif