blob: f1b45a7dade2863baea00d185924072b90b7a773 [file] [log] [blame]
xf.libdd93d52023-05-12 07:10:14 -07001/************************************************************************
2*¹¦ÄܽéÉÜ£ºÆ½Ì¨ÄÚ²¿À©Õ¹at¿Í»§¶ËºÍ·þÎñ¶Ë×¢²á£¬ËùÓÐ×¢²á¾ùÔÚext_regist_init½Ó¿ÚÖÐÍê³É£¬ÓÉat_ctlÔÚÆô¶¯Ê±µ÷ÓÃ
3*¸ºÔðÈË£º
4*±¸·ÝÈË£º
5*ÐÞ¸ÄÈÕ£º
6*ÐÞ¸ÄÄÚÈÝ£º
7*°æ±¾ºÅ£º
8************************************************************************/
9#if (APP_OS_TYPE == APP_OS_LINUX)
10#include "at_msg.h"
11#include "at_com.h"
12#include "at_context.h"
13#include "ext_dev_func.h"
14#include "ext_cmux_func.h"
15#ifdef _USE_VOICE_ALSA
16#include "tinyalsa/audio_mixer_ctrl.h"
17#include "voice_lib.h"
18#endif
19//#include "ext_regist.h"
20//#include "softap_api.h"
21//#include "at_utils.h"
22//#include "pub/drvs_ret.h"
23//#include "earpiece_api.h"
24#define DRV_SUCCESS 0
25
26/*
27typedef enum
28{
29 VP_PATH_HANDSET =0,
30 VP_PATH_SPEAKER,
31 VP_PATH_HEADSET,
32 VP_PATH_BLUETOOTH,
33 VP_PATH_BLUETOOTH_NO_NR,
34 VP_PATH_HSANDSPK,
35
36 VP_PATH_OFF = 255,
37
38 MAX_VP_PATH = VP_PATH_OFF
39}T_ZDrv_VpPath;
40*/
41/* Voice input channel selection. */
42typedef enum
43{
44 CODEC_INPUT_MICPHONE =0, /*input path in earphone mic*/
45 CODEC_INPUT_HEADSET, /*input path in headset*/
46 CODEC_INPUT_BLUETOOTH, /*input path in bluetooth*/
47 CODEC_INPUT_HANDSFREE, /*input path in mic(handsfree)*/
48
49 MAX_CODEC_INPUT_PATH
50} T_ZDrv_CodecInputPath;
51
52/* Voice output channel selection. */
53typedef enum
54{
55 CODEC_OUTPUT_RECEIVER =0, /*output path in receiver*/
56 CODEC_OUTPUT_SPEAKER, /*output path in speaker*/
57 CODEC_OUTPUT_HEADSET, /*output path in headset*/
58 CODEC_OUTPUT_BLUETOOTH, /*output path in bluetooth*/
59 CODEC_OUTPUT_HSANDSPK, /*output path in both headset and speaker*/
60
61
62 MAX_CODEC_OUTPUT_PATH
63}T_ZDrv_CodecOutputPath;
64#ifdef _CONFIG_USE_CODEC_EARPIECE_DETECT
65extern SINT32 halEarp_Open(VOID);
66extern SINT32 halEarp_Close(VOID);
67extern SINT32 halEarp_GetPlugStatus(T_ZDrvEarp_State* plug_status);
68#endif
69
70#ifdef _CONFIG_USE_CODEC
71extern SINT32 halAudioConfig_ReadReg (UINT16 regPage, UINT16 regAddress, UINT16 *regValue);
72extern SINT32 halAudioConfig_WriteReg (UINT16 regPage, UINT16 regAddress, UINT16 regValue, UINT16 regMask);
73extern SINT32 halAudioConfig_DumpReg (VOID);
74
75
76int codecWrite_act_func (int at_fd, char * at_paras, void * *res_msg, int * res_msglen)
77{
78 char *at_str = NULL;
79 UINT32 ret = DRV_SUCCESS;
80 UINT8 pPtr[40] = {0};
81 int a[4] = {0};
82 //CHAR b[6] = {0};
83 //CHAR c[6] = {0};
84 //CHAR d[6] = {0};
85 UINT16 reg_page = 0;
86 UINT16 reg_index = 0;
87 UINT16 write_value = 0;
88 UINT16 write_mask = 0;
89 at_str = at_paras;
90 at_print(AT_DEBUG,"codecWrite_act_func, at_paras:%s \n", at_paras);
91
92 //ret = sscanf (at_str, "%[0-9],%[0-9],%[0-9],%[0-9]", a, b, c, d);
93 ret = sscanf (at_str, "%d,%d,%d,%d", &a[0], &a[1], &a[2], &a[3]);
94 reg_page = a[0];
95 reg_index = a[1];
96 write_value = a[2];
97 write_mask = a[3];
98 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);
99
100 if (ret == 4) {
101 ret = halAudioConfig_WriteReg (reg_page, reg_index, write_value, write_mask);
102 if (ret == DRV_SUCCESS) {
103 *res_msg = at_ok_build();
104 *res_msglen = strlen (*res_msg);
105 return AT_END;
106 }
107 }
108
109 *res_msg = at_err_build(ATERR_PROC_FAILED);
110 *res_msglen = strlen (*res_msg);
111 return AT_END;
112}
113
114int codecRead_act_func (int at_fd, char * at_paras, void * *res_msg, int * res_msglen)
115{
116 char *at_str = NULL;
117 at_str = at_paras;
118 UINT32 ret = DRV_SUCCESS;
119 int a[2] = {0};
120 //CHAR b[6] = {0};
121 CHAR re_str[30] = {'\0'};
122
123 UINT16 reg_page = 0;
124 UINT16 reg_index = 0;
125 UINT16 read_value = 0;
126 at_print(AT_DEBUG,"codecRead_act_func, at_paras:%s \n", at_paras);
127
128 //ret = sscanf (at_str, "%[0-9],%[0-9]", a, b);
129 ret = sscanf (at_str, "%d,%d", &a[0], &a[1]);
130 reg_page = a[0];
131 reg_index = a[1];
132 at_print(AT_DEBUG,"codecRead_act_func reg_page=0x%x, reg_index=0x%x \n", reg_page, reg_index);
133
134 if (ret == 2) {
135 ret = halAudioConfig_ReadReg (reg_page, reg_index, &read_value);
136 if (ret == DRV_SUCCESS) {
137
138 sprintf(re_str, "0x%x=0x%x\r\n" , reg_index,read_value);
139
140 *res_msg = at_query_result_build("reg",re_str);
141
142 //*res_msg = at_ok_build();
143 *res_msglen = strlen (*res_msg);
144 return AT_END;
145 }
146 }
147
148 *res_msg = at_err_build(ATERR_PROC_FAILED);
149 *res_msglen = strlen (*res_msg);
150 return AT_END;
151}
152
153int codecDump_act_func (int at_fd, char * at_paras, void * *res_msg, int * res_msglen)
154{
155 char *at_str = NULL;
156 at_str = at_paras;
157 UINT32 ret = DRV_SUCCESS;
158 at_print(AT_DEBUG,"codecDump_act_func, at_paras:%s \n", at_paras);
159
160 if (*at_str == '1') {
161 at_print(AT_DEBUG,"codecDump_act_func is ok. \n");
162 ret = halAudioConfig_DumpReg();
163 if (ret == DRV_SUCCESS) {
164 *res_msg = at_ok_build();
165 *res_msglen = strlen (*res_msg);
166 return AT_END;
167 }
168 }
169
170 *res_msg = at_err_build(ATERR_PROC_FAILED);
171 *res_msglen = strlen (*res_msg);
172 return AT_END;
173
174
175}
176//ƽ̨ÄÚ²¿À©Õ¹atÃüÁ·¢£¬ËùÓÐÀ©Õ¹µÄ¿Í»§¶ËºÍ·þÎñ¶ËatÃüÁ¾ùÐèÒªÔڸú¯ÊýÖУ¬¸Ãº¯Êý»áÔÚat_ctlÓ¦Óóõʼ»¯Ê±£¬Íê³ÉÉÏÊöatÃüÁîµÄ×¢²á
177
178
179int extAtSdev_act_func (int at_fd, char * at_paras, void * *res_msg, int * res_msglen)
180{
181 char *at_str = NULL;
182 UINT32 ret = DRV_SUCCESS;
183 T_ZDrv_VpPath path;
184
185 UINT8 pPtr[40] = {0};
186 int a = 0;
187 //CHAR b[6] = {0};
188 UINT16 dev_num = 0;
189 at_str = at_paras;
190 at_print(AT_DEBUG,"extAtSdev_act_func, at_paras:%s \n", at_paras);
191
192 ret = sscanf (at_str, "%d", &a);
193 dev_num = a;
194 at_print(AT_DEBUG,"extAtSdev_act_func dev_num=0x%d\n", dev_num);
195
196 if (ret == 1) {
197
198 if(dev_num == 0)
199 {
200 path = VP_PATH_HANDSET;
201 at_print(AT_DEBUG, "[MDL] extAtSdev_act_func output channel=%d\r",dev_num);
202 }
203 else if(dev_num == 1)
204 {
205 path = VP_PATH_SPEAKER;
206 at_print(AT_DEBUG, "[MDL] extAtSdev_act_func output channel=%d\r",dev_num);
207 }
208 else if(dev_num == 2)
209 {
210 path = VP_PATH_HEADSET;
211 at_print(AT_DEBUG, "[MDL] extAtSdev_act_func output channel=%d\r",dev_num);
212 }
213 else
214 {
215 sprintf ( (char *) pPtr, "\r\n%s\r\n", "+CME ERROR: 6004");
216 path = VP_PATH_HANDSET;
217 *res_msg = at_err_build ("pPtr");
218 *res_msglen = strlen (*res_msg);
219 return AT_END;
220 }
221
222 ret = zDrvVp_SetPath(path);
223 if (ret == DRV_SUCCESS) {
224 *res_msg = at_ok_build();
225 *res_msglen = strlen (*res_msg);
226 return AT_END;
227 }
228 *res_msg = at_err_build(ATERR_PROC_FAILED);
229 *res_msglen = strlen (*res_msg);
230
231 return AT_END;
232 }
233 return AT_END;
234}
235int extAtRxPath_act_func (int at_fd, char * at_paras, void * *res_msg, int * res_msglen)
236{
237 char *at_str = NULL;
238 UINT32 ret = DRV_SUCCESS;
239 T_ZDrv_CodecOutputPath path;
240
241 UINT8 pPtr[40] = {0};
242 int a[2] = {0};
243 //CHAR b[6] = {0};
244 UINT16 dev_num = 0;
245 UINT16 isenable = 0;
246 at_str = at_paras;
247 at_print(AT_DEBUG,"extAtSdev_act_func, at_paras:%s \n", at_paras);
248
249 ret = sscanf (at_str, "%d %d", &a[0], &a[1]);
250 dev_num = a[0];
251 isenable = a[1];
252 at_print(AT_DEBUG,"extAtSdev_act_func dev_num=0x%d\n", dev_num);
253
254 if (ret == 2) {
255
256 if(dev_num == 0)
257 {
258 path = CODEC_OUTPUT_RECEIVER;
259 at_print(AT_DEBUG, "[MDL] extAtSdev_act_func output channel=%d\r",dev_num);
260 }
261 else if(dev_num == 1)
262 {
263 path = CODEC_OUTPUT_SPEAKER;
264 at_print(AT_DEBUG, "[MDL] extAtSdev_act_func output channel=%d\r",dev_num);
265 }
266 else if(dev_num == 2)
267 {
268 path = CODEC_OUTPUT_HEADSET;
269 at_print(AT_DEBUG, "[MDL] extAtSdev_act_func output channel=%d\r",dev_num);
270 }
271 else
272 {
273 sprintf ( (char *) pPtr, "\r\n%s\r\n", "+CME ERROR: 6004");
274 path = CODEC_OUTPUT_RECEIVER;
275 *res_msg = at_err_build ("pPtr");
276 *res_msglen = strlen (*res_msg);
277 return AT_END;
278 }
279
280 //ret = zDrvVp_SetTxPath(CODEC_INPUT_MICPHONE, TRUE);
281 ret = zDrvVp_SetRxPath(path, isenable);
282 if (ret == DRV_SUCCESS) {
283 *res_msg = at_ok_build();
284 *res_msglen = strlen (*res_msg);
285 return AT_END;
286 }
287 *res_msg = at_err_build(ATERR_PROC_FAILED);
288 *res_msglen = strlen (*res_msg);
289
290 return AT_END;
291 }
292 return AT_END;
293}
294int extAtTxPath_act_func (int at_fd, char * at_paras, void * *res_msg, int * res_msglen)
295{
296 char *at_str = NULL;
297 UINT32 ret = DRV_SUCCESS;
298 T_ZDrv_VpPath path;
299
300 UINT8 pPtr[40] = {0};
301 int a[2] = {0};
302 //CHAR b[6] = {0};
303 UINT16 dev_num = 0;
304 UINT16 isenable = 0;
305 at_str = at_paras;
306 at_print(AT_DEBUG,"extAtSdev_act_func, at_paras:%s \n", at_paras);
307
308 ret = sscanf (at_str, "%d %d", &a[0], &a[1]);
309 dev_num = a[0];
310 isenable = a[1];
311 at_print(AT_DEBUG,"extAtSdev_act_func dev_num=0x%d\n", dev_num);
312
313 if (ret == 2) {
314
315 if(dev_num == 0)
316 {
317 path = CODEC_INPUT_MICPHONE; //IN2P
318 at_print(AT_DEBUG, "[MDL] extAtSdev_act_func output channel=%d\r",dev_num);
319 }
320 else if(dev_num == 1)
321 {
322 path = CODEC_INPUT_HANDSFREE; //CODEC_INPUT_HEADSET IN2P
323 at_print(AT_DEBUG, "[MDL] extAtSdev_act_func output channel=%d\r",dev_num);
324 }
325 else if(dev_num == 2)
326 {
327 path = CODEC_INPUT_HEADSET; //CODEC_INPUT_HANDSFREE IN1P
328 at_print(AT_DEBUG, "[MDL] extAtSdev_act_func output channel=%d\r",dev_num);
329 }
330 else
331 {
332 sprintf ( (char *) pPtr, "\r\n%s\r\n", "+CME ERROR: 6004");
333 path = VP_PATH_HANDSET;
334 *res_msg = at_err_build ("pPtr");
335 *res_msglen = strlen (*res_msg);
336 return AT_END;
337 }
338
339 ret = zDrvVp_SetTxPath(path, isenable);
340 if (ret == DRV_SUCCESS) {
341 *res_msg = at_ok_build();
342 *res_msglen = strlen (*res_msg);
343 return AT_END;
344 }
345
346 *res_msg = at_err_build(ATERR_PROC_FAILED);
347 *res_msglen = strlen (*res_msg);
348
349 return AT_END;
350 }
351 return AT_END;
352}
353#endif
354
355#ifdef _CONFIG_USE_CODEC_EARPIECE_DETECT
356int extAtEarp_act_func (int at_fd, char * at_paras, void * *res_msg, int * res_msglen)
357{
358 char *at_str = NULL;
359 UINT32 ret = DRV_SUCCESS;
360 T_ZDrv_VpPath path;
361
362 UINT8 pPtr[40] = {0};
363 int a = 0;
364 //CHAR b[6] = {0};
365 UINT16 onOff = 0;
366 at_str = at_paras;
367 at_print(AT_DEBUG,"extAtSdev_act_func, at_paras:%s \n", at_paras);
368
369 ret = sscanf (at_str, "%d", &a);
370 onOff = a;
371 at_print(AT_DEBUG,"extAtSdev_act_func dev_num=0x%d\n", onOff);
372
373 if (ret == 1) {
374 if(onOff == 1)
375 {
376 ret = halEarp_Open();
377 }
378 else
379 {
380 ret = halEarp_Close();
381 }
382
383 if (ret == DRV_SUCCESS) {
384 *res_msg = at_ok_build();
385 *res_msglen = strlen (*res_msg);
386 return AT_END;
387 }
388 }
389 *res_msg = at_err_build(ATERR_PROC_FAILED);
390 *res_msglen = strlen (*res_msg);
391
392 return AT_END;
393}
394#endif
395#ifdef _USE_VOICE_ALSA
396
397
398
399
400
401
402int extAt_VPATH_act_func (int at_fd, char * at_paras, void * *res_msg, int * res_msglen)
403{
404 char *at_str = NULL;
405 UINT32 ret = DRV_SUCCESS;
406 int path;
407 int a = 0;
408 //CHAR b[6] = {0};
409 UINT16 onOff = 0;
410 at_str = at_paras;
411 at_print(AT_DEBUG,"extAt_VPATH_act_func, at_paras:%s \n", at_paras);
412
413 ret = sscanf (at_str, "%d,%d",&path,&a);
414 onOff = a;
415 at_print(AT_DEBUG,"extAt_VPATH_act_func path =%d,onOff=0x%d\n",path, onOff);
416
417 if (ret == 2) {
418 if(onOff == 1)
419 {
420 ret = set_voice_device_mode(path);
421 printf("extAt_VPATH_act_func on vpath,ret=%d\n",ret);
422 }
423 else
424 {
425 //ret = set_voice_device_mode(path);
426 printf("extAt_VPATH_act_func off vpath not support\n");
427
428 }
429 if (ret == DRV_SUCCESS) {
430 *res_msg = at_ok_build();
431 *res_msglen = strlen (*res_msg);
432 return AT_END;
433 }
434 }
435
436 *res_msg = at_err_build(ATERR_PROC_FAILED);
437 *res_msglen = strlen (*res_msg);
438
439 return AT_END;
440}
441
442int extAt_VALSA_act_func (int at_fd, char * at_paras, void * *res_msg, int * res_msglen)
443{
444 char *at_str = NULL;
445 UINT32 ret = DRV_SUCCESS;
446
447 int mode = 0;
448 int enable = 0;
449
450 UINT16 onOff = 0;
451 at_str = at_paras;
452 printf("extAt_VALSA_act_func, at_paras:%s \n", at_paras);
453
454 ret = sscanf (at_str, "%d,%d", &mode,&enable);
455 onOff = enable;
456 printf("extAt_VALSA_act_func mode=%d,enable=%d,ret=%d\n",mode,enable,ret);
457
458 if (ret == 2) {
459 if(onOff == 1)
460 {
461 ret = alsa_voice_open(mode);
462 printf("extAt_voice_act_func alsa_voice_open,ret=%d\n",ret);
463 }
464 else
465 {
466 ret = alsa_voice_close(mode);
467 printf("extAt_voice_act_func alsa_voice_close,ret=%d\n",ret);
468
469 }
470 if (ret == DRV_SUCCESS) {
471 *res_msg = at_ok_build();
472 *res_msglen = strlen (*res_msg);
473 return AT_END;
474 }
475 }
476 *res_msg = at_err_build(ATERR_PROC_FAILED);
477 *res_msglen = strlen (*res_msg);
478
479 return AT_END;
480}
481
482#endif
483
484void ext_audio_regist_init(void)
485{
486 printf("ext_audio_regist_init! \n");
487
488#ifdef _CONFIG_USE_CODEC
489 register_serv_func2("WRCODEC=", 0, 0, 0, codecWrite_act_func, NULL);
490 register_serv_func2("RDCODEC=", 0, 0, 0, codecRead_act_func, NULL);
491 register_serv_func2("DUMPCODECREG=", 0, 0, 0, codecDump_act_func, NULL);
492 register_serv_func2("ExtAT_SDEV=", 0, 0, 0, extAtSdev_act_func, NULL);
493 register_serv_func2("ExtAT_RXPATH=", 0, 0, 0, extAtRxPath_act_func, NULL);
494 register_serv_func2("ExtAT_TXPATH=", 0, 0, 0, extAtTxPath_act_func, NULL);
495#endif
496#ifdef _CONFIG_USE_CODEC_EARPIECE_DETECT
497 register_serv_func2("ExtAT_EARP=", 0, 0, 0, extAtEarp_act_func, NULL);
498#endif
499
500#ifdef _USE_VOICE_ALSA
501
502 register_serv_func2("VALSA=", 0, 0, 0, extAt_VALSA_act_func, NULL);
503 register_serv_func2("VPATH=", 0, 0, 0, extAt_VPATH_act_func, NULL);
504
505#endif
506}
507
508#endif