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