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