xref: /utopia/UTPA2-700.0.x/modules/audio/hal/M7621/audio/halSOUND.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2008-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94 
95 
96 //-------------------------------------------------------------------------------------------------
97 //  Include Files
98 //-------------------------------------------------------------------------------------------------
99 // Common Definition
100 #include "MsCommon.h"
101 #include "MsIRQ.h"
102 #include "MsOS.h"
103 #include "regCHIP.h"
104 #include "drvAUDIO_if.h"
105 #include "drvAUDIO.h"
106 #include "halAUDIO.h"
107 
108 // Internal Definition
109 #include "halSOUND.h"
110 #include "regAUDIO.h"
111 #include "halMAD2.h"
112 
113 #include "audio_mbox2.h"
114 #include "audio_comm2.h"
115 
116 #if (defined ANDROID)
117 
118   #include <sys/mman.h>
119   #include <cutils/ashmem.h>
120   #include <cutils/log.h>
121 
122   #ifndef LOGI // android 4.1 rename LOGx to ALOGx
123     #define LOGI ALOGI
124   #endif
125 
126   #ifndef LOGE // android 4.1 rename LOGx to ALOGx
127     #define LOGE ALOGE
128   #endif
129 
130   #if(OMX_AUDIO_DEBUG)
131     #define HALSOUND_PRINT(fmt, args...)    LOGI("<<android>>      " fmt, ## args)
132   #else
133     #define HALSOUND_PRINT(fmt, args...)
134   #endif
135 
136   #define HALSOUND_ERROR(fmt, args...)    LOGE("<<android>>      " fmt, ## args)
137 
138 #else
139     #ifdef CONFIG_MBOOT //mboot Speed up
140         #define HALSOUND_PRINT(fmt, args...)
141         #define HALSOUND_ERROR(fmt, args...)    printf("[[utopia]]      " fmt, ## args)
142     #else
143         #define HALSOUND_PRINT(fmt, args...)    printf("[[utopia]]      " fmt, ## args)
144         #define HALSOUND_ERROR(fmt, args...)    printf("[[utopia]]      " fmt, ## args)
145     #endif
146 #endif
147 
148 
149 //-------------------------------------------------------------------------------------------------
150 //  Driver Compiler Options
151 //-------------------------------------------------------------------------------------------------
152 #define DBG_SOUND(msg) //msg
153 #define MAX_PEQ_BAND  8
154 //-------------------------------------------------------------------------------------------------
155 //  Local Defines
156 //-------------------------------------------------------------------------------------------------
157 
158 
159 //-------------------------------------------------------------------------------------------------
160 //  Local Structures
161 //-------------------------------------------------------------------------------------------------
162 
163 
164 //-------------------------------------------------------------------------------------------------
165 //  Global Variables
166 //-------------------------------------------------------------------------------------------------
167 extern MS_U16 g_BalanceMask;
168 extern AUDIO_SHARED_VARS2 * g_AudioVars2;
169 //-------------------------------------------------------------------------------------------------
170 //  Local Variables
171 //-------------------------------------------------------------------------------------------------
172 static MS_U32 peq_band_enable = 0xFFFFFFFF;
173 static MS_U32 peq_band_precision = 0x00000000;
174 
175 const MS_U32  AVC_SOffset_TBL[13]=
176 {
177     0x200000,       // Offset +0 dB, 3.21 format for DSP
178     0x23E793,       //        +1 dB
179     0x28491D,       //        +2 dB
180     0x2D3381,       //        +3 dB
181     0x32B771,       //        +4 dB
182     0x38E7AA,       //        +5 dB
183     0x3FD930,       //        +6 dB
184     0x47A39A,       //        +7 dB
185     0x50615F,       //        +8 dB
186     0x5A3031,       //        +9 dB
187     0x653160,       //       +10 dB
188     0x718A50,       //       +11 dB
189     0x7F64F0,       //       +12 dB
190 };
191 //-------------------------------------------------------------------------------------------------
192 //  Debug Functions
193 //-------------------------------------------------------------------------------------------------
194 
195 
196 //-------------------------------------------------------------------------------------------------
197 //  Local Functions
198 //-------------------------------------------------------------------------------------------------
199 
200 
201 //-------------------------------------------------------------------------------------------------
202 //  Global Functions
203 //-------------------------------------------------------------------------------------------------
204 
205 ////////////////////////////////////////////////////////////////////////////////
206 /// @brief \b Function \b Name: HAL_SOUND_Init() @@VVV
207 /// @brief \b Function \b Description: This routine is the initialization for Audio sound effect module.
208 /// @param <IN>        \b InitTbl    : Sound effect  initial table
209 /// @param <OUT>       \b NONE    :
210 /// @param <RET>       \b NONE    :
211 /// @param <GLOBAL>    \b NONE    :
212 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_Init(void)213 void HAL_SOUND_Init(void)
214 {
215     // Toggle  to initialize DAC DATA SRAM.
216     HAL_AUDIO_SeWriteMaskByte(0x2B40,0x02,0x02);
217     AUDIO_DELAY1MS(1);
218     HAL_AUDIO_SeWriteMaskByte(0x2B40,0x02,0x00);
219 
220     //reset DSP
221     HAL_AUDIO_WriteByte( REG_SE_IDMA_CTRL0, 0x02);
222     AUDIO_DELAY1MS(2);
223     HAL_AUDIO_WriteByte( REG_SE_IDMA_CTRL0, 0x03);
224 
225 }
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 /// @brief \b Function \b Name: HAL_SOUND_Init2
229 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_Init2(void)230 void HAL_SOUND_Init2(void)
231 {
232 
233     HAL_SOUND_Init();
234     HAL_AUDSP_DspLoadCode(AU_DVB2_NONE);
235     //HAL_AUDSP_DspLoadCode(AU_SND_EFFECT);
236     HAL_AUDIO_SeSystemLoadCode();  // Do nothing in single DSP chip
237 }
238 
239 ////////////////////////////////////////////////////////////////////////////////
240 /// @brief \b Function \b Name: HAL_SOUND_SetMute() @@VVV
241 /// @brief \b Function \b Description: This routine is used to set audio u8Path S/W mute.
242 /// @param <IN>        \b u8Path    : for audio u8Path0 ~ u8Path6
243 /// @param <IN>        \b bEnable    :     TRUE --Mute
244 ///                                                    FALSE--Unmute
245 /// @param <OUT>       \b NONE    :
246 /// @param <RET>       \b NONE    :
247 /// @param <GLOBAL>    \b NONE    :
248 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetMute(MS_U8 u8Path,MS_BOOL bEnable)249 void HAL_SOUND_SetMute(MS_U8 u8Path, MS_BOOL bEnable)
250 {
251     DBG_SOUND(printf("HAL_SOUND_SetMute = %x\n", (MS_U8)bEnable ));
252 
253     switch(u8Path)
254     {
255         case AUDIO_PATH_SW_DMA_0:
256         case AUDIO_PATH_SW_DMA_1:
257         {
258             if(bEnable == TRUE)
259             {
260                 HAL_AUDIO_WriteMaskReg(M2S_MBOX_SW_DMA_READER_DDR_Ctrl, 0x8000, 0x8000);    // bit 15
261             }
262             else
263             {
264                 HAL_AUDIO_WriteMaskReg(M2S_MBOX_SW_DMA_READER_DDR_Ctrl, 0x8000, 0x0000);
265             }
266         }
267         break;
268 
269         case AUDIO_PATH_HW_DMA_0:
270         case AUDIO_PATH_HW_DMA_1:
271         {
272             if(bEnable)
273             {
274                 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH5_MIX_VOL_FRC, 0x02, 0x02);
275             }
276             else
277             {
278                 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH5_MIX_VOL_FRC, 0x02, 0x00);
279             }
280         }
281         break;
282 
283         case AUDIO_T3_PATH_AUOUT0:
284             if(bEnable)  // Mute
285               HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT0_VOLUME, 0x80, 0x80);
286             else        // UnMute
287               HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT0_VOLUME, 0x80, 0x00);
288             break;
289 
290         case AUDIO_T3_PATH_AUOUT1:
291             if(bEnable)
292               HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT1_VOLUME, 0x80, 0x80 );
293             else
294               HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT1_VOLUME, 0x80, 0x00 );
295             break;
296 
297         case AUDIO_T3_PATH_AUOUT2:
298             if(bEnable)
299               HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT2_VOLUME, 0x80, 0x80);
300             else
301               HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT2_VOLUME, 0x80, 0x00);
302             break;
303 
304         case AUDIO_T3_PATH_AUOUT3:
305             if(bEnable)
306               HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT3_VOLUME, 0x80, 0x80);
307             else
308               HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT3_VOLUME, 0x80, 0x00);
309             break;
310 
311         case AUDIO_T3_PATH_I2S:
312             if(bEnable)
313               HAL_AUDIO_WriteMaskByte(REG_SOUND_I2S_VOLUME, 0x80, 0x80);
314             else
315               HAL_AUDIO_WriteMaskByte(REG_SOUND_I2S_VOLUME, 0x80, 0x00);
316             break;
317 
318         case AUDIO_T3_PATH_SPDIF:
319             _HAL_AUDIO_SPDIF_SetMute(bEnable);
320             break;
321 
322         case AUDIO_T3_PATH_MIXER_MAIN:
323             {
324                 MS_U32 u32Value;
325 
326                 /* TODO
327                  * It's a patch here
328                  * also control multi channel volume
329                  */
330                 u32Value = HAL_MAD2_Read_DSP_sram(DSP2DmAddr_Multi_Channel_VOL, DSP_MEM_TYPE_DM);
331 
332                 if(bEnable)
333                 {
334                     HAL_AUDIO_WriteMaskByte(REG_SOUND_CH5_MIX_VOL_INT, 0x80, 0x80);
335 
336                     u32Value = u32Value | 0x008000;
337                 }
338                 else
339                 {
340                     HAL_AUDIO_WriteMaskByte(REG_SOUND_CH5_MIX_VOL_INT, 0x80, 0x00);
341 
342                     u32Value = u32Value & 0xFF7FFF;
343                 }
344 
345                 HAL_MAD2_Write_DSP_sram(DSP2DmAddr_Multi_Channel_VOL, u32Value, DSP_MEM_TYPE_DM);
346 
347             break;
348             }
349 
350         case AUDIO_T3_PATH_MIXER_SECONDARY:
351             if(bEnable)
352             {
353                 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH6_MIX_VOL_INT, 0x80, 0x80);
354             }
355             else
356             {
357                 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH6_MIX_VOL_INT, 0x80, 0x00);
358             }
359             break;
360 
361         case AUDIO_T3_PATH_MIXER_DMA_IN:
362             if(bEnable)
363             {
364                 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH8_MIX_VOL_INT, 0x80, 0x80);
365             }
366             else
367             {
368                 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH8_MIX_VOL_INT, 0x80, 0x00);
369             }
370             break;
371 
372       case AUDIO_PATH_7:
373             if(bEnable)
374             {
375                 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH7_VOLUME, 0x80, 0x80);
376             }
377             else
378             {
379                 HAL_AUDIO_WriteMaskByte(REG_SOUND_CH7_VOLUME, 0x80, 0x00);
380             }
381             break;
382 
383         case AUDIO_T3_PATH_PCM_CAPTURE1:
384             {
385                 MS_U32 u32Value;
386 
387                 u32Value = HAL_MAD2_Read_DSP_sram(DSP2DmAddr_pcmCapture_volume, DSP_MEM_TYPE_DM);
388 
389                 if(bEnable)
390                 {
391                     u32Value = u32Value | 0x008000;
392                     HAL_MAD2_Write_DSP_sram(DSP2DmAddr_pcmCapture_volume, u32Value, DSP_MEM_TYPE_DM);
393                 }
394                 else
395                 {
396                     u32Value = u32Value & 0xFF7FFF;
397                     HAL_MAD2_Write_DSP_sram(DSP2DmAddr_pcmCapture_volume, u32Value, DSP_MEM_TYPE_DM);
398                 }
399 
400                 break;
401             }
402 
403         case AUDIO_T3_PATH_DMA_WRITER1:
404             {
405                 MS_U32 u32Value;
406 
407                 u32Value = HAL_MAD2_Read_DSP_sram(DSP2DmAddr_dmaWriter1_volume, DSP_MEM_TYPE_DM);
408 
409                 if(bEnable)
410                 {
411                     u32Value = u32Value | 0x008000;
412                     HAL_MAD2_Write_DSP_sram(DSP2DmAddr_dmaWriter1_volume, u32Value, DSP_MEM_TYPE_DM);
413                 }
414                 else
415                 {
416                     u32Value = u32Value & 0xFF7FFF;
417                     HAL_MAD2_Write_DSP_sram(DSP2DmAddr_dmaWriter1_volume, u32Value, DSP_MEM_TYPE_DM);
418                 }
419 
420                 break;
421             }
422 
423         case AUDIO_T3_PATH_PCM_CAPTURE2:
424             {
425                 MS_U32 u32Value;
426 
427                 u32Value = HAL_MAD2_Read_DSP_sram(DSP2DmAddr_pcmCapture2_volume, DSP_MEM_TYPE_DM);
428 
429                 if(bEnable)
430                 {
431                     u32Value = u32Value | 0x008000;
432                     HAL_MAD2_Write_DSP_sram(DSP2DmAddr_pcmCapture2_volume, u32Value, DSP_MEM_TYPE_DM);
433                 }
434                 else
435                 {
436                     u32Value = u32Value & 0xFF7FFF;
437                     HAL_MAD2_Write_DSP_sram(DSP2DmAddr_pcmCapture2_volume, u32Value, DSP_MEM_TYPE_DM);
438                 }
439 
440                 break;
441             }
442 
443         case AUDIO_T3_PATH_MIXER_MCH_IN: //Multi-Ch 1~3
444             {
445                 MS_U32 u32Value;
446 
447                 u32Value = HAL_MAD2_Read_DSP_sram(DSP2DmAddr_Multi_Channel_VOL, DSP_MEM_TYPE_DM);
448 
449                 if(bEnable)
450                 {
451                     u32Value = u32Value | 0x008000;
452                     HAL_MAD2_Write_DSP_sram(DSP2DmAddr_Multi_Channel_VOL, u32Value, DSP_MEM_TYPE_DM);
453                 }
454                 else
455                 {
456                     u32Value = u32Value & 0xFF7FFF;
457                     HAL_MAD2_Write_DSP_sram(DSP2DmAddr_Multi_Channel_VOL, u32Value, DSP_MEM_TYPE_DM);
458                 }
459 
460                 break;
461             }
462 
463         default:
464             break;
465     }
466 }
467 
468 ////////////////////////////////////////////////////////////////////////////////
469 /// @brief \b Function \b Name: HAL_SOUND_AbsoluteVolume()  @@VVV
470 /// @brief \b Function \b Description: This routine is used to set the absolute volume of audio u8Path.
471 /// @param <IN>        \b u8Path    : for audio CH1~CH6
472 /// @param <IN>        \b u8u8Vol1    :     MSB 7-bit register u8Value of 10-bit volume
473 ///                                range from 0x00 to 0x7E , gain: +12db to   -114db (-1 db per step)
474 /// @param <IN>        \b u8u8Vol2    :     LSB 3-bit register u8Value of 10-bit volume
475 ///                                range from 0x00 to 0x07 , gain:  -0db to -0.875db (-0.125 db per step)
476 /// @param <OUT>       \b NONE    :
477 /// @param <RET>       \b NONE    :
478 /// @param <GLOBAL>    \b NONE    :
479 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_AbsoluteVolume(MS_U8 u8Path,MS_U8 u8u8Vol1,MS_U8 u8u8Vol2)480 void HAL_SOUND_AbsoluteVolume(MS_U8 u8Path, MS_U8 u8u8Vol1, MS_U8 u8u8Vol2)
481 {
482     switch(u8Path)
483     {
484         case AUDIO_T3_PATH_AUOUT0:
485             HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT0_VOLUME, 0x7F, u8u8Vol1);
486             HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT0_VOL_FRAC, 0xE0, (u8u8Vol2<<5));
487             HAL_AUDIO_WriteMaskByte(M2S_MBOX_VOLUME_EN, 0x01, 0x01);   // bEnable DSP CH1 sound effect
488             break;
489 
490         case AUDIO_T3_PATH_AUOUT1:
491             HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT1_VOLUME, 0x7F, u8u8Vol1);
492             HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT1_VOL_FRAC, 0xE0, (u8u8Vol2<<5));
493             HAL_AUDIO_WriteMaskByte(M2S_MBOX_VOLUME_EN, 0x02, 0x02);   // bEnable DSP CH2 sound effect
494             break;
495 
496         case AUDIO_T3_PATH_AUOUT2:
497             HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT2_VOLUME, 0x7F, u8u8Vol1);
498             HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT2_VOL_FRAC, 0xE0, (u8u8Vol2<<5));
499             HAL_AUDIO_WriteMaskByte(M2S_MBOX_VOLUME_EN, 0x04, 0x04);   // bEnable DSP CH3 sound effect
500             break;
501         case AUDIO_T3_PATH_AUOUT3:
502             HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT3_VOLUME, 0x7F, u8u8Vol1);
503             HAL_AUDIO_WriteMaskByte(REG_SOUND_AUOUT3_VOL_FRAC, 0xE0, (u8u8Vol2<<5));
504             HAL_AUDIO_WriteMaskByte(M2S_MBOX_VOLUME_EN, 0x08, 0x08);   // bEnable DSP CH4 sound effect
505             break;
506 
507         case AUDIO_T3_PATH_I2S:
508             HAL_AUDIO_WriteMaskByte(REG_SOUND_I2S_VOLUME, 0x7F, u8u8Vol1);
509             HAL_AUDIO_WriteMaskByte(REG_SOUND_I2S_VOL_FRAC, 0xE0, (u8u8Vol2<<5));
510             HAL_AUDIO_WriteMaskByte(M2S_MBOX_VOLUME_EN, 0x10, 0x10);   // bEnable DSP CH5 sound effect
511             break;
512 
513         case AUDIO_T3_PATH_SPDIF:
514             HAL_AUDIO_WriteMaskByte(REG_SOUND_SPDIF_VOLUME, 0x7F, u8u8Vol1);
515             HAL_AUDIO_WriteMaskByte(REG_SOUND_SPDIF_VOL_FRAC, 0xE0, (u8u8Vol2<<5));
516             HAL_AUDIO_WriteMaskByte(M2S_MBOX_VOLUME_EN, 0x20, 0x20);   // bEnable DSP CH6 sound effect
517 
518             break;
519 
520         case AUDIO_T3_PATH_I2S2:
521             HAL_AUDIO_WriteMaskByte(REG_SOUND_I2S2_VOLUME, 0x7F, u8u8Vol1);
522             HAL_AUDIO_WriteMaskByte(REG_SOUND_I2S2_VOL_FRAC, 0xE0, (u8u8Vol2<<5));
523             HAL_AUDIO_WriteMaskByte(M2S_MBOX_VOLUME_EN, 0x20, 0x20);   // bEnable AUDIO_T3_PATH_I2S2
524             break;
525 
526         case AUDIO_T3_PATH_MIXER_MAIN:  //CH5
527         {
528             MS_U32 u32Value;
529             MS_U32 u32Muteflag;
530 
531             HAL_AUDIO_WriteMaskByte(REG_SOUND_CH5_MIX_VOL_INT, 0x7F, u8u8Vol1);
532             HAL_AUDIO_WriteMaskByte(REG_SOUND_CH5_MIX_VOL_FRC, 0xE0, (u8u8Vol2<<5));
533 
534             /* TODO
535              * It's a patch here
536              * also control multi channel volume
537              */
538             u32Muteflag = HAL_MAD2_Read_DSP_sram(DSP2DmAddr_Multi_Channel_VOL, DSP_MEM_TYPE_DM);
539 
540             u8u8Vol1 = u8u8Vol1 & 0x7F;
541             u8u8Vol2 = (u8u8Vol2<<5) & 0xE0;
542             u32Value = ((MS_U32)u8u8Vol1)<<8;
543             u32Value = u32Value + (MS_U32)u8u8Vol2;
544             u32Value = u32Value | (u32Muteflag & 0x008000);
545             HAL_MAD2_Write_DSP_sram(DSP2DmAddr_Multi_Channel_VOL, u32Value, DSP_MEM_TYPE_DM);
546 
547             break;
548         }
549 
550         case AUDIO_T3_PATH_MIXER_SECONDARY: //CH6
551             HAL_AUDIO_WriteMaskByte(REG_SOUND_CH6_MIX_VOL_INT, 0x7F, u8u8Vol1);
552             HAL_AUDIO_WriteMaskByte(REG_SOUND_CH6_MIX_VOL_FRC, 0xE0, (u8u8Vol2<<5));
553             break;
554 
555         case AUDIO_T3_PATH_MIXER_DMA_IN: //CH8
556             HAL_AUDIO_WriteMaskByte(REG_SOUND_CH8_MIX_VOL_INT, 0x7F, u8u8Vol1);
557             HAL_AUDIO_WriteMaskByte(REG_SOUND_CH8_MIX_VOL_FRC, 0xE0, (u8u8Vol2<<5));
558             break;
559 
560         case AUDIO_PATH_7: //CH7
561             HAL_AUDIO_WriteMaskByte(REG_SOUND_CH7_VOLUME, 0x7F, u8u8Vol1);
562             HAL_AUDIO_WriteMaskByte(REG_SOUND_CH7_VOL_FRAC, 0xE0, (u8u8Vol2<<5));
563             break;
564 
565         case AUDIO_T3_PATH_PCM_CAPTURE1:
566         {
567             MS_U32 u32Value;
568             MS_U32 u32Muteflag;
569             u32Muteflag = HAL_MAD2_Read_DSP_sram(DSP2DmAddr_pcmCapture_volume, DSP_MEM_TYPE_DM);
570 
571             u8u8Vol1 = u8u8Vol1 & 0x7F;
572             u8u8Vol2 = (u8u8Vol2<<5) & 0xE0;
573             u32Value = ((MS_U32)u8u8Vol1)<<8;
574             u32Value = u32Value + (MS_U32)u8u8Vol2;
575             u32Value = u32Value | (u32Muteflag & 0x008000);
576             HAL_MAD2_Write_DSP_sram(DSP2DmAddr_pcmCapture_volume, u32Value, DSP_MEM_TYPE_DM);
577 
578             break;
579         }
580 
581         case AUDIO_T3_PATH_PCM_CAPTURE2:
582         {
583             MS_U32 u32Value;
584             MS_U32 u32Muteflag;
585             u32Muteflag = HAL_MAD2_Read_DSP_sram(DSP2DmAddr_pcmCapture2_volume, DSP_MEM_TYPE_DM);
586 
587             u8u8Vol1 = u8u8Vol1 & 0x7F;
588             u8u8Vol2 = (u8u8Vol2<<5) & 0xE0;
589             u32Value = ((MS_U32)u8u8Vol1)<<8;
590             u32Value = u32Value + (MS_U32)u8u8Vol2;
591             u32Value = u32Value | (u32Muteflag & 0x008000);
592             HAL_MAD2_Write_DSP_sram(DSP2DmAddr_pcmCapture2_volume, u32Value, DSP_MEM_TYPE_DM);
593 
594             break;
595         }
596 
597         case AUDIO_T3_PATH_DMA_WRITER1:
598         {
599             MS_U32 u32Value;
600             MS_U32 u32Muteflag;
601             u32Muteflag = HAL_MAD2_Read_DSP_sram(DSP2DmAddr_dmaWriter1_volume, DSP_MEM_TYPE_DM);
602 
603             u8u8Vol1 = u8u8Vol1 & 0x7F;
604             u8u8Vol2 = (u8u8Vol2<<5) & 0xE0;
605             u32Value = ((MS_U32)u8u8Vol1)<<8;
606             u32Value = u32Value + (MS_U32)u8u8Vol2;
607             u32Value = u32Value | (u32Muteflag & 0x008000);
608             HAL_MAD2_Write_DSP_sram(DSP2DmAddr_dmaWriter1_volume, u32Value, DSP_MEM_TYPE_DM);
609 
610             break;
611         }
612 
613         case AUDIO_T3_PATH_MIXER_MCH_IN: //Multi-Ch 1~3
614         {
615             MS_U32 u32Value;
616             MS_U32 u32Muteflag;
617             u32Muteflag = HAL_MAD2_Read_DSP_sram(DSP2DmAddr_Multi_Channel_VOL, DSP_MEM_TYPE_DM);
618 
619             u8u8Vol1 = u8u8Vol1 & 0x7F;
620             u8u8Vol2 = (u8u8Vol2<<5) & 0xE0;
621             u32Value = ((MS_U32)u8u8Vol1)<<8;
622             u32Value = u32Value + (MS_U32)u8u8Vol2;
623             u32Value = u32Value | (u32Muteflag & 0x008000);
624             HAL_MAD2_Write_DSP_sram(DSP2DmAddr_Multi_Channel_VOL, u32Value, DSP_MEM_TYPE_DM);
625             break;
626         }
627 
628         default:
629             break;
630     }
631 
632 }
633 
634 ////////////////////////////////////////////////////////////////////////////////
635 /// @brief \b Function \b Name: HAL_SOUND_SetPreScale() @@VVV
636 /// @brief \b Function \b Description: This routine is used to set the u8Prescale of audio u8Path.
637 /// @param <IN>        \b u8Path    : for audio u8Path0 ~ u8Path5
638 /// @param <IN>        \b u8Prescale    :     range from 0x01 to 0xFF , gain: -13.75db to +18db (0.125 db per step)
639 ///                                    0x00: disable pre-scale
640 ///                                    0x6F: gain = 0db
641 ///                                    0xFF: gain = +18db
642 /// @param <OUT>       \b NONE    :
643 /// @param <RET>       \b NONE    :
644 /// @param <GLOBAL>    \b NONE    :
645 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetPreScale(MS_U8 u8Path,MS_U8 u8Prescale)646 void HAL_SOUND_SetPreScale(MS_U8 u8Path, MS_U8 u8Prescale)
647 {
648     switch (u8Path)
649     {
650         case AUDIO_PATH_MAIN:
651             HAL_AUDIO_WriteByte(REG_SOUND_MAIN_PERSCALE, u8Prescale);
652             break;
653 
654         default:
655             HAL_AUDIO_WriteByte(REG_SOUND_MAIN_PERSCALE, u8Prescale);
656             break;
657     }
658 }
659 
660 ////////////////////////////////////////////////////////////////////////////////
661 /// @brief \b Function \b Name: HAL_SOUND_GetPreScale()
662 /// @brief \b Function \b Description: This routine is used to set the u8Prescale of audio u8Path.
663 /// @param <IN>        \b u8Path    : for audio u8Path0 ~ u8Path5
664 /// @param <IN>        \b u8Prescale    :     range from 0x01 to 0xFF , gain: -13.75db to +18db (0.125 db per step)
665 ///                                    0x00: disable pre-scale
666 ///                                    0x6F: gain = 0db
667 ///                                    0xFF: gain = +18db
668 /// @param <OUT>       \b NONE    :
669 /// @param <RET>       \b NONE    :
670 /// @param <GLOBAL>    \b NONE    :
671 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetPreScale(MS_U8 u8Path)672 MS_U16 HAL_SOUND_GetPreScale(MS_U8 u8Path)
673 {
674     MS_U16 tmp=0;
675     switch ( u8Path )
676     {
677         case AUDIO_PATH_MAIN:
678             tmp = HAL_AUDIO_ReadByte(REG_SOUND_MAIN_PERSCALE);
679             break;
680 
681         default:
682             tmp = HAL_AUDIO_ReadByte(REG_SOUND_MAIN_PERSCALE);
683             break;
684     }
685     return tmp;
686 }
687 
688 ////////////////////////////////////////////////////////////////////////////////
689 /// @brief \b Function \b Name: HAL_SOUND_SetOutputPhaseShiftMask()   @@VVV
690 /// @brief \b Function \b Description: This routine is used to Set Output Signal Phase Shift Mask. ( 0 degree normal or 180 degree inverse)
691 /// @param <IN>        \b u8Path    :    AUDIO_PATH_TYPE
692 /// @param <IN>        \b u8Channel    :   0 for Left channel; 1 for Right channel
693 /// @param <OUT>       \b NONE    :
694 /// @param <RET>       \b NONE    :
695 /// @param <GLOBAL>    \b NONE    :
696 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetOutputPhaseShiftMask(AUDIO_OUTPUT_TYPE u8Output,MS_U8 u8Channel)697 void HAL_SOUND_SetOutputPhaseShiftMask(AUDIO_OUTPUT_TYPE u8Output, MS_U8 u8Channel)
698 {
699     MS_U16 PhaseShiftMaskBit = 0;
700     MS_BOOL ctrl_flag = TRUE;
701 
702     switch(u8Output)
703     {
704         case AUDIO_AUOUT0_OUTPUT:
705             if (u8Channel)
706             {
707                 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_DAC0_R_BIT;
708             }
709             else
710             {
711                 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_DAC0_L_BIT;
712             }
713             break;
714 
715         case AUDIO_AUOUT1_OUTPUT:
716         case AUDIO_HP_OUTPUT:
717             if (u8Channel)
718             {
719                 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_DAC1_R_BIT;
720             }
721             else
722             {
723                 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_DAC1_L_BIT;
724             }
725             break;
726 
727         case AUDIO_AUOUT2_OUTPUT:
728             if (u8Channel)
729             {
730                 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_DAC2_R_BIT;
731             }
732             else
733             {
734                 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_DAC2_L_BIT;
735             }
736             break;
737 
738         case AUDIO_AUOUT3_OUTPUT:
739             if (u8Channel)
740             {
741                 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_DAC3_R_BIT;
742             }
743             else
744             {
745                 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_DAC3_L_BIT;
746             }
747             break;
748 
749         case AUDIO_I2S_OUTPUT:
750             if (u8Channel)
751             {
752                 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_I2S0_R_BIT;
753             }
754             else
755             {
756                 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_I2S0_L_BIT;
757             }
758             break;
759 
760         case AUDIO_I2S2_OUTPUT:
761             if (u8Channel)
762             {
763                 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_I2S1_R_BIT;
764             }
765             else
766             {
767                 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_I2S1_L_BIT;
768             }
769             break;
770 
771         case AUDIO_I2S3_OUTPUT:
772             if (u8Channel)
773             {
774                 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_I2S2_R_BIT;
775             }
776             else
777             {
778                 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_I2S2_L_BIT;
779             }
780             break;
781 
782         case AUDIO_I2S4_OUTPUT:
783             if (u8Channel)
784             {
785                 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_I2S3_R_BIT;
786             }
787             else
788             {
789                 PhaseShiftMaskBit = M2S_MBOX_PHASE_SHIFT_I2S3_L_BIT;
790             }
791             break;
792 
793         default:
794             ctrl_flag = FALSE;
795             printf("Warning! un-support OutputPhaseShift case(%u). \r\n", u8Output);
796             break;
797     }
798 
799     if (ctrl_flag)
800     {
801         HAL_AUDIO_WriteMaskReg(M2S_MBOX_PHASE_SHIFT_CTRL, 1<<(PhaseShiftMaskBit), 1<<(PhaseShiftMaskBit));
802     }
803 }
804 
805 ////////////////////////////////////////////////////////////////////////////////
806 /// @brief \b Function \b Name: HAL_SOUND_EnableBalance()   @@VVV
807 /// @brief \b Function \b Description: This routine is used to Enable/Disable Balance featue.
808 /// @param <IN>        \b u8Enable    :    Balance Enable bits
809 /// @param <OUT>       \b NONE    :
810 /// @param <RET>       \b NONE    :
811 /// @param <GLOBAL>    \b NONE    :
812 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableBalance(MS_U8 u8Enable)813 void HAL_SOUND_EnableBalance(MS_U8 u8Enable)
814 {
815     HAL_AUDIO_WriteMaskByte(M2S_MBOX_BALANCE_EN+1, 0x80, (u8Enable<<7)); // Balance enable flag
816 
817     if (u8Enable)
818         HAL_AUDIO_WriteMaskReg(M2S_MBOX_BALANCE_EN, g_BalanceMask, 0xFFFF); // Balance enable
819     else
820         HAL_AUDIO_WriteMaskReg(M2S_MBOX_BALANCE_EN, g_BalanceMask, 0x0000); // Balance disable
821 }
822 
823 ////////////////////////////////////////////////////////////////////////////////
824 /// @brief \b Function \b Name: HAL_SOUND_SetBalanceMask()   @@VVV
825 /// @brief \b Function \b Description: This routine is used to Set Balance Mask.
826 /// @param <IN>        \b u8Path    :    AUDIO_PATH_TYPE
827 /// @param <IN>        \b u8Enable    :    TRUE or FALSE
828 /// @param <OUT>       \b NONE    :
829 /// @param <RET>       \b NONE    :
830 /// @param <GLOBAL>    \b NONE    :
831 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetBalanceMask(AUDIO_OUTPUT_TYPE u8Output,MS_BOOL u8Enable)832 void HAL_SOUND_SetBalanceMask(AUDIO_OUTPUT_TYPE u8Output, MS_BOOL u8Enable)
833 {
834     MS_U16 BalanceMaskBit = 0;
835     MS_BOOL ctrl_flag = TRUE;
836 
837     switch(u8Output)
838     {
839         case AUDIO_AUOUT0_OUTPUT:
840             BalanceMaskBit = M2S_MBOX_BAL_DAC0_EN_BIT;
841             break;
842         case AUDIO_AUOUT1_OUTPUT:
843         case AUDIO_HP_OUTPUT:
844             BalanceMaskBit = M2S_MBOX_BAL_DAC1_EN_BIT;
845             break;
846         case AUDIO_AUOUT2_OUTPUT:
847             BalanceMaskBit = M2S_MBOX_BAL_DAC2_EN_BIT;
848             break;
849         case AUDIO_AUOUT3_OUTPUT:
850             BalanceMaskBit = M2S_MBOX_BAL_DAC3_EN_BIT;
851             break;
852 
853         case AUDIO_I2S_OUTPUT:
854             BalanceMaskBit = M2S_MBOX_BAL_I2S0_EN_BIT;
855             break;
856         case AUDIO_I2S2_OUTPUT:
857             BalanceMaskBit = M2S_MBOX_BAL_I2S1_EN_BIT;
858             break;
859         case AUDIO_I2S3_OUTPUT:
860             BalanceMaskBit = M2S_MBOX_BAL_I2S2_EN_BIT;
861             break;
862         case AUDIO_I2S4_OUTPUT:
863             BalanceMaskBit = M2S_MBOX_BAL_I2S3_EN_BIT;
864             break;
865 
866         case AUDIO_SPDIF_OUTPUT:
867             BalanceMaskBit = M2S_MBOX_BAL_SPDIF_EN_BIT;
868             break;
869 
870         case AUDIO_HDMI_ARC_OUTPUT:  // tmp disable, no this choice
871             ctrl_flag = FALSE;
872             break;
873 
874         case AUDIO_HDMI_OUTPUT:  // tmp disable, no this choice
875             ctrl_flag = FALSE;
876             break;
877 
878         default:
879             printf("Warning! un-support BalanceMask case(%u). \r\n", u8Output);
880             ctrl_flag = FALSE;
881             break;
882     }
883 
884     if (ctrl_flag)
885     {
886         g_BalanceMask = ((g_BalanceMask & (~(BalanceMaskBit))) | (u8Enable<<BalanceMaskBit));
887         HAL_SOUND_EnableBalance(TRUE);
888     }
889 }
890 
891 const MS_U8 BalanceTab[]=
892 {
893     0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,  /// 0 ~ 9
894     0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,  /// 10 ~ 19
895     0x14,0x15,0x16,0x17,0x18,0x1A,0x1B,0x1C,0x1F,0x20,  /// 20 ~ 29
896     0x22,0x23,0x25,0x27,0x29,0x2B,0x2E,0x30,0x33,0x36,  /// 30 ~ 39
897     0x38,0x3D,0x41,0x46,0x4B,0x51,0x59,0x66,0x72,0x8B,  /// 40 ~ 49
898     0xFF    /// 50
899 };
900 
901 ////////////////////////////////////////////////////////////////////////////////
902 /// @brief \b Function \b Name: HAL_SOUND_SetBalance()    @@VVV
903 /// @brief \b Function \b Description: This routine is used to set Balance value.
904 /// @param <IN>        \b u8Balance     :   0~49    -> R channel volume down
905 ///                                     :   50      -> L/R the same (0 dB)
906 ///                                     :   51~100  -> L channel volume down
907 /// @param <OUT>       \b NONE    :
908 /// @param <RET>       \b NONE    :
909 /// @param <GLOBAL>    \b NONE    :
910 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetBalance(MS_U8 u8Balance)911 void HAL_SOUND_SetBalance(MS_U8 u8Balance)
912 {
913     MS_U8 value_l = 0, value_r = 0;
914 
915     //printf("apiAud>> u8Balance = %02bx\n", u8Balance);
916     if(u8Balance==50)
917     {
918         value_l = 0x00;
919         value_r = 0x00;
920     }
921     else if(u8Balance<50)
922     {
923         value_l = 0x00;
924         value_r = BalanceTab[(50-u8Balance)];
925     }
926     else if(u8Balance>50)
927     {
928         value_l = BalanceTab[(u8Balance-50)];
929         value_r = 0x00;
930     }
931     //AUD_DEBUG(printf("\napiAud>> Balance UI:0x%bx L:0x%bx R:0x%bx",u8Balance,value_l,value_r));
932     HAL_SOUND_SetBalance_L(value_l);
933     HAL_SOUND_SetBalance_R(value_r);
934 }
935 
936 ////////////////////////////////////////////////////////////////////////////////
937 /// @brief \b Function \b Name: HAL_SOUND_SetBalance_L()    @@VVV
938 /// @brief \b Function \b Description: This routine is used to set Absolute Balance u8Value of main L-channel.
939 /// @param <IN>        \b u8Balance_L   : L-channel balance register u8Value
940 ///                                       0x00(0dB)~0xFF(mute), step: -0.25 (dB/step)
941 /// @param <OUT>       \b NONE    :
942 /// @param <RET>       \b NONE    :
943 /// @param <GLOBAL>    \b NONE    :
944 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetBalance_L(MS_U8 u8Balance_L)945 void HAL_SOUND_SetBalance_L(MS_U8 u8Balance_L)
946 {
947     HAL_AUDIO_WriteByte(REG_SOUND_BALANCEL, u8Balance_L);
948 }
949 
950 ////////////////////////////////////////////////////////////////////////////////
951 /// @brief \b Function \b Name: HAL_SOUND_GetBalance_L()
952 /// @brief \b Function \b Description: This routine is used to set absolute Balance u8Value of main u8Path L-channel.
953 /// @param <IN>        \b NONE    :
954 /// @param <OUT>       \b u8Balance_L   : L-channel balance register u8Value
955 ///                                       0x00(0dB)~0xFF(mute), step: -0.25 (dB/step)
956 /// @param <RET>       \b NONE    :
957 /// @param <GLOBAL>    \b NONE    :
958 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetBalance_L(void)959 MS_U16 HAL_SOUND_GetBalance_L(void)
960 {
961     return(HAL_AUDIO_ReadByte(REG_SOUND_BALANCEL));
962 }
963 
964 ////////////////////////////////////////////////////////////////////////////////
965 /// @brief \b Function \b Name: HAL_SOUND_SetBalance_R()    @@VVV
966 /// @brief \b Function \b Description: This routine is used to set Absolute Balance u8Value of main R-channel.
967 /// @param <IN>        \b u8Balance_R   : R-channel balance register u8Value
968 ///                                       0x00(0dB)~0xFF(mute), step: -0.25 (dB/step)
969 /// @param <OUT>       \b NONE    :
970 /// @param <RET>       \b NONE    :
971 /// @param <GLOBAL>    \b NONE    :
972 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetBalance_R(MS_U8 u8Balance_R)973 void HAL_SOUND_SetBalance_R(MS_U8 u8Balance_R)
974 {
975     HAL_AUDIO_WriteByte(REG_SOUND_BALANCER, u8Balance_R);
976 }
977 
978 ////////////////////////////////////////////////////////////////////////////////
979 /// @brief \b Function \b Name: HAL_SOUND_GetBalance_R()
980 /// @brief \b Function \b Description: This routine is used to set absolute Balance u8Value of main u8Path R-channel.
981 /// @param <IN>        \b NONE    :
982 /// @param <OUT>       \b u8Balance_R   : R-channel balance register u8Value
983 ///                                       0x00(0dB)~0xFF(mute), step: -0.25 (dB/step)
984 /// @param <RET>       \b NONE    :
985 /// @param <GLOBAL>    \b NONE    :
986 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetBalance_R(void)987 MS_U16 HAL_SOUND_GetBalance_R(void)
988 {
989     return(HAL_AUDIO_ReadByte(REG_SOUND_BALANCER));
990 }
991 
992 ////////////////////////////////////////////////////////////////////////////////
993 /// @brief \b Function \b Name: HAL_SOUND_SetDynamicBass()
994 /// @brief \b Function \b Description: This routine is used to set the DynamicBass u8Level of main u8Path .
995 /// @param <IN>        \b u8Level    :
996 /// @param <OUT>       \b NONE    :
997 /// @param <RET>       \b NONE    :
998 /// @param <GLOBAL>    \b NONE    :
999 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetDynamicBass(MS_U8 u8Level)1000 void HAL_SOUND_SetDynamicBass(MS_U8 u8Level)
1001 {
1002     HAL_AUDIO_WriteByte(M2S_MBOX_SUPBASS_CTRL, u8Level);
1003 
1004     if(u8Level == 0)
1005     {
1006         HAL_AUDIO_WriteMaskByte(REG_SOUND_MAIN_SNDEFFECT, 0x20, 0x00);
1007     }
1008     else
1009     {
1010         HAL_AUDIO_WriteMaskByte(REG_SOUND_MAIN_SNDEFFECT, 0x20, 0x20);
1011     }
1012 
1013 }
1014 
1015 ////////////////////////////////////////////////////////////////////////////////
1016 /// @brief \b Function \b Name: HAL_SOUND_SetBass() @@VVV
1017 /// @brief \b Function \b Description: This routine is used to set the Bass u8Value of main u8Path .
1018 /// @param <IN>        \b u8Level :  max: 100 (+15dB)
1019 ///                                        50 (  0dB)
1020 ///                                  min:   0 (-16dB)
1021 /// @param <OUT>       \b NONE    :
1022 /// @param <RET>       \b NONE    :
1023 /// @param <GLOBAL>    \b NONE    :
1024 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetBass(MS_U8 u8Level)1025 void HAL_SOUND_SetBass(MS_U8 u8Level)
1026 {
1027     MS_S32 u8Value;
1028 
1029     if(u8Level >= 100)
1030     {
1031         u8Value = 0x30;
1032     }
1033     else
1034     {
1035         u8Value = ((int)u8Level-50)*48/50; //16/50;
1036     }
1037 
1038     DBG_SOUND(printf("Bass:%d",u8Level));
1039     DBG_SOUND(printf("==>%x\r\n",u8Value));
1040 
1041     HAL_AUDIO_WriteByte(REG_SOUND_BASS, (MS_U8)u8Value);
1042 }
1043 
1044 ////////////////////////////////////////////////////////////////////////////////
1045 /// @brief \b Function \b Name: HAL_SOUND_GetBass()
1046 /// @brief \b Function \b Description: This routine is used to get the u16Value gain.
1047 /// @param <IN>        \b NONE    :
1048 /// @param <OUT>       \b u16Bass :  max: 0x30 (+15dB)
1049 ///                                       0x00 (  0dB), step = 0.25 (dB/step)
1050 ///                                  min: 0xD0 (-16dB)
1051 /// @param <RET>       \b NONE    :
1052 /// @param <GLOBAL>    \b NONE    :
1053 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetBass(void)1054 MS_U16 HAL_SOUND_GetBass(void)
1055 {
1056     MS_U16 u16Bass = 0;
1057 
1058     u16Bass = HAL_AUDIO_ReadByte(REG_SOUND_BASS);
1059     return u16Bass;
1060 }
1061 
1062 ////////////////////////////////////////////////////////////////////////////////
1063 /// @brief \b Function \b Name: HAL_SOUND_AbsoluteBass()    @@VVV
1064 /// @brief \b Function \b Description: This routine is used to set the absolute Bass u8Value of main u8Path .
1065 /// @param <IN>        \b bass    :  max: 0x30 (+15dB)
1066 ///                                       0x00 (  0dB), step = 0.25 (dB/step)
1067 ///                                  min: 0xD0 (-16dB)
1068 /// @param <OUT>       \b NONE    :
1069 /// @param <RET>       \b NONE    :
1070 /// @param <GLOBAL>    \b NONE    :
1071 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_AbsoluteBass(MS_U8 u8Bass)1072 void HAL_SOUND_AbsoluteBass(MS_U8 u8Bass)
1073 {
1074     if ((u8Bass > 0x30) && (u8Bass <= 0x7F))
1075     {
1076         u8Bass = 0x30;
1077     }
1078     if ((u8Bass < 0xD0) && (u8Bass >= 0x80))
1079     {
1080         u8Bass = 0xD0;
1081     }
1082     HAL_AUDIO_WriteByte(REG_SOUND_BASS, u8Bass);
1083 }
1084 
1085 ////////////////////////////////////////////////////////////////////////////////
1086 /// @brief \b Function \b Name: HAL_SOUND_SetTreble()   @@VVV
1087 //// @brief \b Function \b Description: This routine is used to set the Treble u8Value of main u8Path .
1088 /// @param <IN>        \b u8Level :  max: 100 (+15dB)
1089 ///                                        50 (  0dB)
1090 ///                                  min:   0 (-16dB)
1091 /// @param <OUT>       \b NONE    :
1092 /// @param <RET>       \b NONE    :
1093 /// @param <GLOBAL>    \b NONE    :
1094 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetTreble(MS_U8 u8Level)1095 void HAL_SOUND_SetTreble(MS_U8 u8Level)
1096 {
1097     MS_S32 u8Value;
1098 
1099     if (u8Level >= 100)
1100     {
1101         u8Value = 0x30;
1102     }
1103     else
1104     {
1105         u8Value = ((int)u8Level-50)*48/50; //16/50;
1106     }
1107 
1108     DBG_SOUND(printf("Treble:%d",u8Level));
1109     DBG_SOUND(printf("==>%x\r\n",u8Value));
1110 
1111     HAL_AUDIO_WriteByte(REG_SOUND_TREBLE, (MS_U8)u8Value);
1112 }
1113 
1114 ////////////////////////////////////////////////////////////////////////////////
1115 /// @brief \b Function \b Name: HAL_SOUND_GetTreble()
1116 /// @brief \b Function \b Description: This routine is used to get the u16Value gain.
1117 /// @param <IN>        \b NONE    :
1118 /// @param <OUT>       \b u16Treble :  max: 0x30 (+15dB)
1119 ///                                         0x00 (  0dB), step = 0.25 (dB/step)
1120 ///                                    min: 0xD0 (-16dB)
1121 /// @param <RET>       \b NONE    :
1122 /// @param <GLOBAL>    \b NONE    :
1123 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetTreble(void)1124 MS_U16 HAL_SOUND_GetTreble(void)
1125 {
1126     MS_U16 u16Treble = 0;
1127 
1128     u16Treble = HAL_AUDIO_ReadByte(REG_SOUND_TREBLE);
1129     return u16Treble;
1130 }
1131 
1132 ////////////////////////////////////////////////////////////////////////////////
1133 /// @brief \b Function \b Name: HAL_SOUND_AbsoluteTreble()  @@VVV
1134 /// @brief \b Function \b Description: This routine is used to set the absolute Treble u8Value of main u8Path .
1135 /// @param <IN>        \b u8Treble:  max: 0x30 (+15dB)
1136 ///                                       0x00 (  0dB), step = 0.25 (dB/step)
1137 ///                                  min: 0xD0 (-16dB)
1138 /// @param <OUT>       \b NONE    :
1139 /// @param <RET>       \b NONE    :
1140 /// @param <GLOBAL>    \b NONE    :
1141 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_AbsoluteTreble(MS_U8 u8Treble)1142 void HAL_SOUND_AbsoluteTreble(MS_U8 u8Treble)
1143 {
1144     if ((u8Treble > 0x30) && (u8Treble <= 0x7F))
1145     {
1146         u8Treble = 0x30;
1147     }
1148     if ((u8Treble < 0xD0) && (u8Treble >= 0x80))
1149     {
1150         u8Treble = 0xD0;
1151     }
1152     HAL_AUDIO_WriteByte(REG_SOUND_TREBLE, u8Treble);
1153 }
1154 
1155 ////////////////////////////////////////////////////////////////////////////////
1156 /// @brief \b Function \b Name: HAL_SOUND_SetEq()   @@VVV
1157 /// @brief \b Function \b Description: This routine is used to set the the 5-band EQ u8Level  .
1158 /// @param <IN>        \b band    :  EQ band 0~4
1159 /// @param <IN>        \b u8Level    :  Absolute EQ register u8Value
1160 /// @param <OUT>       \b NONE    :
1161 /// @param <RET>       \b NONE    :
1162 /// @param <GLOBAL>    \b NONE    :
1163 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetEq(MS_U8 u8Band,MS_U8 u8Level)1164 void HAL_SOUND_SetEq(MS_U8 u8Band, MS_U8 u8Level)
1165 {
1166     MS_U8 value;
1167 
1168     if( u8Band>4)
1169     {
1170         return;
1171     }
1172 
1173     if(u8Level>=100)
1174     {
1175         value = 0x30;
1176     }
1177     else
1178     {
1179         value = ((int)u8Level-50)*48/50;
1180     }
1181 
1182     HAL_AUDIO_WriteByte(REG_SOUND_EQ1 + (u8Band*2), value);
1183 }
1184 
1185 ////////////////////////////////////////////////////////////////////////////////
1186 /// @brief \b Function \b Name: HAL_SOUND_GetEq()
1187 /// @brief \b Function \b Description: This routine is used to set the the 5-band EQ u8Level  .
1188 /// @param <IN>        \b band    :  EQ band 0~4
1189 /// @param <IN>        \b u8Level    :  Absolute EQ register u8Value
1190 /// @param <OUT>       \b NONE    :
1191 /// @param <RET>       \b NONE    :
1192 /// @param <GLOBAL>    \b NONE    :
1193 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetEq(MS_U8 u8Band)1194 MS_U16 HAL_SOUND_GetEq(MS_U8 u8Band)
1195 {
1196     MS_U16 value = 0;
1197 
1198     value = HAL_AUDIO_ReadByte(REG_SOUND_EQ1 + (u8Band*2));
1199     return value;
1200 }
1201 
1202 ////////////////////////////////////////////////////////////////////////////////
1203 /// @brief \b Function \b Name: HAL_SOUND_SetEq7()  @@VVV
1204 /// @brief \b Function \b Description: This routine is used to set the the 7-band EQ u8Level  .
1205 /// @param <IN>        \b u8Band    :  EQ band 0~6
1206 /// @param <IN>        \b u8Level    :  Absolute EQ register u8Value
1207 /// @param <OUT>       \b NONE    :
1208 /// @param <RET>       \b NONE    :
1209 /// @param <GLOBAL>    \b NONE    :
1210 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetEq7(MS_U8 u8Band,MS_U8 u8Level)1211 void HAL_SOUND_SetEq7(MS_U8 u8Band, MS_U8 u8Level)
1212 {
1213     MS_U8 value;
1214 
1215     if( u8Band>6)
1216       return;
1217 
1218     if(u8Level==100)
1219         value = 0x30;
1220     else
1221         value = ((int)u8Level-50)*48/50;
1222 
1223     HAL_AUDIO_WriteByte(REG_SOUND_EQ_BASE + (u8Band*2), value);
1224 }
1225 
1226 ////////////////////////////////////////////////////////////////////////////////
1227 /// @brief \b Function \b Name: HAL_SOUND_SetADCThreshold() @@VVV
1228 /// @brief \b Function \b Description: This routine is used to set the ADC input energy threshold to reduce the background noise .
1229 /// @param <IN>        \b u8Threshold    :  NR threshold u8Level
1230 /// @param <OUT>       \b NONE    :
1231 /// @param <RET>       \b NONE    :
1232 /// @param <GLOBAL>    \b NONE    :
1233 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetADCThreshold(MS_U8 u8Threshold)1234 void HAL_SOUND_SetADCThreshold(MS_U8 u8Threshold)
1235 {
1236     HAL_AUDIO_WriteByte(REG_SOUND_NR_THRESHOLD, u8Threshold);
1237 }
1238 
1239 ////////////////////////////////////////////////////////////////////////////////
1240 /// @brief \b Function \b Name: HAL_SOUND_SetDRCThreshold() @@VVV
1241 /// @brief \b Function \b Description: This routine is used to set the DRC  threshold u8Level.
1242 /// @param <IN>        \b u8Threshold    :  DRC threshold u8Level
1243 ///                                    0x00--  0    dBFS
1244 ///                                    0x01--  -0.5    dBFS
1245 ///                                    0x20--  -16    dBFS
1246 ///                                    0x50--  -40    dBFS
1247 /// @param <IN>        \b Type    :   SPEAKER or HEADPHONE case
1248 /// @param <OUT>       \b NONE    :
1249 /// @param <RET>       \b NONE    :
1250 /// @param <GLOBAL>    \b NONE    :
1251 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetDRCThreshold(MS_U8 u8Level,AUDIO_SOUNDEFFECT_TYPE Type)1252 void HAL_SOUND_SetDRCThreshold(MS_U8 u8Level, AUDIO_SOUNDEFFECT_TYPE Type)
1253 {
1254     if (u8Level >= 0x50)
1255     u8Level = 0x50;
1256 
1257     switch (Type)
1258     {
1259         case AUDIO_SOUNDEFFECT_SPEAKER:
1260             HAL_AUDIO_WriteByte(REG_SOUND_DRC_THRESHOLD, u8Level); //[ 7: 0]
1261             break;
1262 
1263         case AUDIO_SOUNDEFFECT_HEADPHONE:
1264             HAL_AUDIO_WriteByte(REG_SOUND_DRC_THRESHOLD+1, u8Level); //[15: 8]
1265             break;
1266 
1267         default:
1268             printf("Warning! Invalid AUDIO_SOUNDEFFECT_TYPE(%u). \r\n", Type);
1269             break;
1270     }
1271 }
1272 
1273 ////////////////////////////////////////////////////////////////////////////////
1274 /// @brief \b Function \b Name: HAL_SOUND_GetDRCThreshold()
1275 /// @brief \b Function \b Description: This routine is used to get the DRC  threshold u8Level.
1276 /// @param <IN>        \b NONE
1277 /// @param <OUT>       \b Threshold value    :
1278 /// @param <RET>       \b NONE    :
1279 /// @param <GLOBAL>    \b NONE    :
1280 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetDRCThreshold(void)1281 MS_U16 HAL_SOUND_GetDRCThreshold(void)
1282 {
1283     return(HAL_AUDIO_SeReadByte(REG_SOUND_DRC_THRESHOLD));
1284 }
1285 
1286 ////////////////////////////////////////////////////////////////////////////////
1287 /// @brief \b Function \b Name: HAL_SOUND_SetDRCEntry() @@VVV
1288 /// @brief \b Function \b Description: This routine is used to set the DRC Entry u8Enable.
1289 /// @param <IN>        \b Type    :   SPEAKER or HEADPHONE case
1290 /// @param <IN>        \b u8Enable:   DRC EntrySelect u8Enable
1291 ///                                   0 -- DRC before VOL function; 1 -- DRC behind VOL function;
1292 /// @param <OUT>       \b NONE    :
1293 /// @param <RET>       \b NONE    :
1294 /// @param <GLOBAL>    \b NONE    :
1295 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetDRCEntry(AUDIO_SOUNDEFFECT_TYPE Type,MS_U8 u8Enable)1296 void HAL_SOUND_SetDRCEntry(AUDIO_SOUNDEFFECT_TYPE Type, MS_U8 u8Enable)
1297 {
1298     switch (Type)
1299     {
1300         case AUDIO_SOUNDEFFECT_SPEAKER:
1301             HAL_AUDIO_WriteMaskReg(M2S_MBOX_SNDEFF_CTRL2, 1<<(M2S_MBOX_SPK_VOL_BSND_CTRL_BIT), u8Enable<<(M2S_MBOX_SPK_VOL_BSND_CTRL_BIT));
1302             break;
1303 
1304         case AUDIO_SOUNDEFFECT_HEADPHONE:
1305             HAL_AUDIO_WriteMaskReg(M2S_MBOX_SNDEFF_CTRL2, 1<<(M2S_MBOX_HP_VOL_BSND_CTRL_BIT), u8Enable<<(M2S_MBOX_HP_VOL_BSND_CTRL_BIT));
1306             break;
1307 
1308         default:
1309             printf("Warning! Invalid AUDIO_SOUNDEFFECT_TYPE(%u). \r\n", Type);
1310             break;
1311     }
1312 }
1313 
1314 ////////////////////////////////////////////////////////////////////////////////
1315 /// @brief \b Function \b Name: HAL_SOUND_SetAVCThreshold() @@VVV
1316 /// @brief \b Function \b Description: This routine is used to set the AVC  threshold u8Level.
1317 /// @param <IN>        \b u8Threshold    :  AVC threshold u8Level
1318 ///                                    0x00--  0    dBFS
1319 ///                                    0x01--  -0.5    dBFS
1320 ///                                    0x20--  -16    dBFS
1321 ///                                    0x50--  -40    dBFS
1322 /// @param <OUT>       \b NONE    :
1323 /// @param <RET>       \b NONE    :
1324 /// @param <GLOBAL>    \b NONE    :
1325 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetAVCThreshold(MS_U8 u8Level)1326 void HAL_SOUND_SetAVCThreshold(MS_U8 u8Level)
1327 {
1328     if (u8Level >= 0x50)
1329     u8Level = 0x50;
1330 
1331     HAL_AUDIO_WriteByte(REG_SOUND_AVC_THRESHOLD,u8Level);
1332 }
1333 
1334 ////////////////////////////////////////////////////////////////////////////////
1335 /// @brief \b Function \b Name: HAL_SOUND_GetAVCThreshold()
1336 /// @brief \b Function \b Description: This routine is used to set the AVC  threshold u8Level.
1337 /// @param <IN>        \b NONE
1338 /// @param <OUT>       \b Threshold value    :
1339 /// @param <RET>       \b NONE    :
1340 /// @param <GLOBAL>    \b NONE    :
1341 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetAVCThreshold(void)1342 MS_U16 HAL_SOUND_GetAVCThreshold(void)
1343 {
1344     return (HAL_AUDIO_SeReadByte(REG_SOUND_AVC_THRESHOLD));
1345 }
1346 
1347 ////////////////////////////////////////////////////////////////////////////////
1348 /// @brief \b Function \b Name: HAL_SOUND_SetAvcMode()  @@VVV
1349 /// @brief \b Function \b Description: This routine is used to set the AVC  mode.
1350 /// @param <IN>        \b u8AvcMode    :  AVC threshold u8Level
1351 ///                                    0: L mode
1352 ///                                    1: S mode
1353 ///                                    2: M mode
1354 /// @param <OUT>       \b NONE    :
1355 /// @param <RET>       \b NONE    :
1356 /// @param <GLOBAL>    \b NONE    :
1357 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetAvcMode(MS_U8 u8AvcMode)1358 void HAL_SOUND_SetAvcMode(MS_U8 u8AvcMode )
1359 {
1360     switch (u8AvcMode)
1361     {
1362         case 0:
1363             HAL_AUDIO_WriteMaskByte(REG_SOUND_AVC_MODE ,0x03 ,0x00);
1364             break;
1365         case 1:
1366             HAL_AUDIO_WriteMaskByte(REG_SOUND_AVC_MODE ,0x03 ,0x01);
1367             break;
1368         case 2:
1369             HAL_AUDIO_WriteMaskByte(REG_SOUND_AVC_MODE ,0x03 ,0x02);
1370             break;
1371         default:
1372             break;
1373     }
1374 }
1375 
1376 ////////////////////////////////////////////////////////////////////////////////
1377 /// @brief \b Function \b Name: HAL_SOUND_GetAvcMode()
1378 /// @brief \b Function \b Description: This routine is used to set the AVC  mode.
1379 /// @param <RET>        \b u8AvcMode    :  AVC threshold u8Level
1380 ///                                    0: L mode
1381 ///                                    1: S mode
1382 ///                                    2: M mode
1383 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetAvcMode(void)1384 MS_U16  HAL_SOUND_GetAvcMode(void)
1385 {
1386     return (HAL_AUDIO_ReadByte(REG_SOUND_AVC_MODE)&0x03);
1387 }
1388 
1389 ////////////////////////////////////////////////////////////////////////////////
1390 /// @brief \b Function \b Name: HAL_SOUND_SetAvcAT()    @@VVV
1391 /// @brief \b Function \b Description: This routine is used to set the AVC  attack time .
1392 /// @param <IN>        \b u8AvcAT    :  AVC attack time
1393 ///                                 AvcAT = 0 --> 2 sec
1394 ///                                 AvcAT = 1 --> 1 sec
1395 ///                                 AvcAT = 2 --> 500 ms
1396 ///                                 AvcAT = 3 --> 400 ms
1397 ///                                 AvcAT = 4 --> 300 ms
1398 ///                                 AvcAT = 5 --> 200 ms
1399 ///                                 AvcAT = 6 --> 100 ms
1400 ///                                 AvcAT = 7 --> 20  ms
1401 /// @param <OUT>       \b NONE    :
1402 /// @param <RET>       \b NONE    :
1403 /// @param <GLOBAL>    \b NONE    :
1404 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetAvcAT(MS_U8 u8AvcAT)1405 void HAL_SOUND_SetAvcAT(MS_U8 u8AvcAT )
1406 {
1407     if (u8AvcAT>7)
1408         u8AvcAT=7;
1409 
1410     HAL_AUDIO_WriteMaskByte(REG_SOUND_AVC_AT ,0xE0 ,(u8AvcAT<<5));
1411 }
1412 
1413 ////////////////////////////////////////////////////////////////////////////////
1414 /// @brief \b Function \b Name: HAL_SOUND_GetAvcAT()
1415 /// @brief \b Function \b Description: This routine is used to set the AVC  mode.
1416 /// @param <RET>
1417 ///                                 AvcAT = 0 --> 2 sec
1418 ///                                 AvcAT = 1 --> 1 sec
1419 ///                                 AvcAT = 2 --> 500 ms
1420 ///                                 AvcAT = 3 --> 400 ms
1421 ///                                 AvcAT = 4 --> 300  ms
1422 ///                                 AvcAT = 5 --> 200 ms
1423 ///                                 AvcAT = 6 --> 100 ms
1424 ///                                 AvcAT = 7 --> 20  ms
1425 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetAvcAT(void)1426 MS_U16  HAL_SOUND_GetAvcAT(void)
1427 {
1428     return((HAL_AUDIO_ReadByte(REG_SOUND_AVC_AT)&0xE0)>>5);
1429 }
1430 
1431 ////////////////////////////////////////////////////////////////////////////////
1432 /// @brief \b Function \b Name: HAL_SOUND_SetAvcRT()    @@VVV
1433 /// @brief \b Function \b Description: This routine is used to set the AVC  release time .
1434 /// @param <IN>        \b u8AvcRT    :  AVC release time
1435 ///                                 u8AvcRT = 0 --> 2 sec
1436 ///                                 u8AvcRT = 1 --> 1 sec
1437 ///                                 u8AvcRT = 2 --> 500 ms
1438 ///                                 u8AvcRT = 3 --> 400 ms
1439 ///                                 u8AvcRT = 4 --> 300 ms
1440 ///                                 u8AvcRT = 5 --> 200 ms
1441 ///                                 u8AvcRT = 6 --> 100 ms
1442 ///                                 u8AvcRT = 7 --> 20  ms
1443 /// @param <OUT>       \b NONE    :
1444 /// @param <RET>       \b NONE    :
1445 /// @param <GLOBAL>    \b NONE    :
1446 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetAvcRT(MS_U8 u8AvcRT)1447 void HAL_SOUND_SetAvcRT(MS_U8 u8AvcRT )
1448 {
1449     if (u8AvcRT>7)
1450         u8AvcRT=7;
1451 
1452     HAL_AUDIO_WriteMaskByte(REG_SOUND_AVC_RT ,0x1C ,(u8AvcRT<<2));
1453 }
1454 
1455 ////////////////////////////////////////////////////////////////////////////////
1456 /// @brief \b Function \b Name: HAL_SOUND_GetAvcRT()
1457 /// @brief \b Function \b Description: This routine is used to set the AVC  mode.
1458 /// @param <RET>        \b u8AvcRT    :  AVC release time
1459 ///                                 u8AvcRT = 0 --> 2 sec
1460 ///                                 u8AvcRT = 1 --> 1 sec
1461 ///                                 u8AvcRT = 2 --> 500 ms
1462 ///                                 u8AvcRT = 3 --> 400 ms
1463 ///                                 u8AvcRT = 4 --> 300 ms
1464 ///                                 u8AvcRT = 5 --> 200 ms
1465 ///                                 u8AvcRT = 6 --> 100 ms
1466 ///                                 u8AvcRT = 7 --> 20  ms
1467 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetAvcRT(void)1468 MS_U16  HAL_SOUND_GetAvcRT(void)
1469 {
1470     MS_U16 Mode=0;
1471 
1472     Mode = (HAL_AUDIO_ReadByte(REG_SOUND_AVC_RT)&0x1C) >> 2;
1473    return Mode;
1474 }
1475 
1476 ////////////////////////////////////////////////////////////////////////////////
1477 /// @brief \b Function \b Name: HAL_SOUND_EnablePEQ()
1478 /// @brief \b Function \b Description: This routine is used to Enable/Disable PEQ featue
1479 /// @param <IN>        \b Enpeq   :     TRUE  -- Enable  PEQ
1480 ///                                     FALSE -- Disable PEQ
1481 /// @param <OUT>       \b NONE    :
1482 /// @param <RET>       \b NONE    :
1483 /// @param <GLOBAL>    \b NONE    :
1484 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnablePEQ(MS_BOOL Enpeq)1485 void HAL_SOUND_EnablePEQ(MS_BOOL Enpeq)
1486 {
1487     HAL_AUDIO_WriteMaskByte(0x2D20, 0x01, Enpeq);
1488 }
1489 
1490 ////////////////////////////////////////////////////////////////////////////////
1491 /// @brief \b Function \b Name: HAL_SOUND_GetPEQ_Status()
1492 /// @brief \b Function \b Description: This routine is used to get the PEQ is enable or not
1493 /// @param <IN>        \b NONE    :
1494 /// @param <OUT>       \b NONE    :
1495 /// @param <RET>       \b bEnable :     TRUE  -- Enable  PEQ
1496 ///                                     FALSE -- Disable PEQ
1497 /// @param <GLOBAL>    \b NONE    :
1498 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetPEQ_Status(void)1499 MS_U16 HAL_SOUND_GetPEQ_Status(void)
1500 {
1501     if ((HAL_AUDIO_ReadByte(0x2D20)&0x01) == 0x01)
1502     {
1503         return 1;
1504     }
1505     else
1506     {
1507         return 0;
1508     }
1509 }
1510 
1511 ////////////////////////////////////////////////////////////////////////////////
1512 /// @brief \b Function \b Name: HAL_SOUND_EnableHPF()   @@VVV
1513 /// @brief \b Function \b Description: This routine is used to Enable/Disable HPF featue.
1514 /// @param <IN>        \b bEnable :     TRUE  -- Enable  HPF
1515 ///                                     FALSE -- Disable HPF
1516 /// @param <OUT>       \b NONE    :
1517 /// @param <RET>       \b NONE    :
1518 /// @param <GLOBAL>    \b NONE    :
1519 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableHPF(MS_BOOL bEnable)1520 void HAL_SOUND_EnableHPF(MS_BOOL bEnable)
1521 {
1522     HAL_AUDIO_WriteMaskByte(0x2D20, 0x04, bEnable<<2);
1523 }
1524 
1525 ////////////////////////////////////////////////////////////////////////////////
1526 /// @brief \b Function \b Name: HAL_SOUND_GetHPF_Status()
1527 /// @brief \b Function \b Description: This routine is used to get the HPF is enable or not
1528 /// @param <IN>        \b NONE    :
1529 /// @param <OUT>       \b NONE    :
1530 /// @param <RET>       \b bEnable :     TRUE  -- Enable  HPF
1531 ///                                     FALSE -- Disable HPF
1532 /// @param <GLOBAL>    \b NONE    :
1533 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetHPF_Status(void)1534 MS_U16 HAL_SOUND_GetHPF_Status(void)
1535 {
1536     if ((HAL_AUDIO_ReadByte(0x2D20)&0x04) == 0x04)
1537     {
1538         return 1;
1539     }
1540     else
1541     {
1542         return 0;
1543     }
1544 }
1545 
1546 ////////////////////////////////////////////////////////////////////////////////
1547 /// @brief \b Function \b Name: HAL_SOUND_EnableDcRemove()
1548 /// @brief \b Function \b Description: This routine is used to Enable/Disable DC remove.
1549 /// @param <IN>        \b EnDcRemove :  TRUE  -- Enable  DC remove
1550 ///                                     FALSE -- Disable DC remove
1551 /// @param <OUT>       \b NONE    :
1552 /// @param <RET>       \b NONE    :
1553 /// @param <GLOBAL>    \b NONE    :
1554 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableDcRemove(MS_BOOL EnDcRemove)1555 MS_BOOL HAL_SOUND_EnableDcRemove(MS_BOOL EnDcRemove)
1556 {
1557     HAL_AUDIO_WriteMaskByte(0x2D20, 0x08, EnDcRemove<<3);
1558     return 1;
1559 }
1560 
1561 ////////////////////////////////////////////////////////////////////////////////
1562 /// @brief \b Function \b Name: HAL_SOUND_EnableKTVEcho()  @@VVV
1563 /// @brief \b Function \b Description: This routine is used to bEnable/disable the KTVEcho featue.
1564 /// @param <IN>        \b bEnable :     TRUE  -- Enable  KTVEcho
1565 ///                                     FALSE -- Disable KTVEcho
1566 /// @param <OUT>       \b NONE    :
1567 /// @param <RET>       \b NONE    :
1568 /// @param <GLOBAL>    \b NONE    :
1569 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableKTVEcho(MS_BOOL bEnable)1570 void HAL_SOUND_EnableKTVEcho(MS_BOOL bEnable)
1571 {
1572     HAL_AUDIO_WriteMaskByte(0x2D20, 0x10, bEnable<<4);
1573 }
1574 
1575 ////////////////////////////////////////////////////////////////////////////////
1576 /// @brief \b Function \b Name: HAL_SOUND_EnableEaseVol()  @@VVV
1577 /// @brief \b Function \b Description: This routine is used to bEnable/disable the EaseVol featue.
1578 /// @param <IN>        \b bEnable :     TRUE  -- Enable  EaseVol
1579 ///                                     FALSE -- Disable EaseVol
1580 /// @param <OUT>       \b NONE    :
1581 /// @param <RET>       \b NONE    :
1582 /// @param <GLOBAL>    \b NONE    :
1583 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableEaseVol(MS_BOOL bEnable)1584 void HAL_SOUND_EnableEaseVol(MS_BOOL bEnable)
1585 {
1586     HAL_AUDIO_WriteMaskByte(0x2D20, 0x40, bEnable<<6);
1587 }
1588 
1589 ////////////////////////////////////////////////////////////////////////////////
1590 /// @brief \b Function \b Name: HAL_SOUND_EnableEQ()   @@VVV
1591 /// @brief \b Function \b Description: This routine is used to Enable/Disable GEQ featue.
1592 /// @param <IN>        \b bEnable :     TRUE  -- Enable  GEQ
1593 ///                                     FALSE -- Disable GEQ
1594 /// @param <OUT>       \b NONE    :
1595 /// @param <RET>       \b NONE    :
1596 /// @param <GLOBAL>    \b NONE    :
1597 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableEQ(MS_BOOL bEnable)1598 void HAL_SOUND_EnableEQ(MS_BOOL bEnable)
1599 {
1600     HAL_AUDIO_WriteMaskByte(0x2D20, 0x80, bEnable<<7);
1601 }
1602 
1603 ////////////////////////////////////////////////////////////////////////////////
1604 /// @brief \b Function \b Name: HAL_SOUND_GetEQ_Status()
1605 /// @brief \b Function \b Description: This routine is used to get the GEQ is enable or not
1606 /// @param <IN>        \b NONE    :
1607 /// @param <OUT>       \b NONE    :
1608 /// @param <RET>       \b bEnable :     TRUE  -- Enable  GEQ
1609 ///                                     FALSE -- Disable GEQ
1610 /// @param <GLOBAL>    \b NONE    :
1611 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetEQ_Status(void)1612 MS_U16 HAL_SOUND_GetEQ_Status(void)
1613 {
1614     if ((HAL_AUDIO_ReadByte(0x2D20)&0x80) == 0x80)
1615     {
1616         return 1;
1617     }
1618     else
1619     {
1620         return 0;
1621     }
1622 }
1623 
1624 ////////////////////////////////////////////////////////////////////////////////
1625 /// @brief \b Function \b Name: HAL_SOUND_EnableSurround()  @@VVV
1626 /// @brief \b Function \b Description: This routine is used to Enable/Disable Surround featue.
1627 /// @param <IN>        \b bEnable :     TRUE  -- Enable  Surround
1628 ///                                     FALSE -- Disable Surround
1629 /// @param <OUT>       \b NONE    :
1630 /// @param <RET>       \b NONE    :
1631 /// @param <GLOBAL>    \b NONE    :
1632 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableSurround(MS_BOOL bEnable)1633 void HAL_SOUND_EnableSurround(MS_BOOL bEnable)
1634 {
1635     HAL_AUDIO_WriteMaskByte(0x2D21, 0x04, bEnable<<2);
1636 }
1637 
1638 ////////////////////////////////////////////////////////////////////////////////
1639 /// @brief \b Function \b Name: HAL_SOUND_GetSurround_Status()
1640 /// @brief \b Function \b Description: This routine is used to get the Surround is enable or not
1641 /// @param <IN>        \b NONE    :
1642 /// @param <OUT>       \b NONE    :
1643 /// @param <RET>       \b bEnable :     TRUE  -- Enable  Surround
1644 ///                                     FALSE -- Disable Surround
1645 /// @param <GLOBAL>    \b NONE    :
1646 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetSurround_Status(void)1647 MS_U16 HAL_SOUND_GetSurround_Status(void)
1648 {
1649     if ((HAL_AUDIO_ReadByte(0x2D21)&0x04) == 0x04)
1650     {
1651         return 1;
1652     }
1653     else
1654     {
1655         return 0;
1656     }
1657 }
1658 
1659 ////////////////////////////////////////////////////////////////////////////////
1660 /// @brief \b Function \b Name: HAL_SOUND_EnableTone()  @@VVV
1661 /// @brief \b Function \b Description: This routine is used to Enable/Disable the Bass & Treble featue.
1662 /// @param <IN>        \b bEnable :     TRUE  -- Enable  Tone
1663 ///                                     FALSE -- Disable Tone
1664 /// @param <OUT>       \b NONE    :
1665 /// @param <RET>       \b NONE    :
1666 /// @param <GLOBAL>    \b NONE    :
1667 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableTone(MS_BOOL bEnable)1668 void HAL_SOUND_EnableTone(MS_BOOL bEnable)
1669 {
1670     HAL_AUDIO_WriteMaskByte(0x2D21, 0x08, bEnable<<3);
1671 }
1672 
1673 ////////////////////////////////////////////////////////////////////////////////
1674 /// @brief \b Function \b Name: HAL_SOUND_GetTone_Status()
1675 /// @brief \b Function \b Description: This routine is used to get Bass & Trebleis enable or not
1676 /// @param <IN>        \b NONE    :
1677 /// @param <OUT>       \b NONE    :
1678 /// @param <RET>       \b bEnable :     TRUE  -- Enable  Tone
1679 ///                                     FALSE -- Disable Tone
1680 /// @param <GLOBAL>    \b NONE    :
1681 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetTone_Status(void)1682 MS_U16 HAL_SOUND_GetTone_Status(void)
1683 {
1684     if ((HAL_AUDIO_ReadByte(0x2D21)&0x08) == 0x08)
1685     {
1686         return 1;
1687     }
1688     else
1689     {
1690         return 0;
1691     }
1692 }
1693 
1694 ////////////////////////////////////////////////////////////////////////////////
1695 /// @brief \b Function \b Name: HAL_SOUND_EnableAutoVolume() @@VVV
1696 /// @brief \b Function \b Description: This routine is used to Enable/Disable the AVC featue.
1697 /// @param <IN>        \b bEnable :     TRUE  -- Enable  AVC (AutoVolume)
1698 ///                                     FALSE -- Disable AVC (AutoVolume)
1699 /// @param <OUT>       \b NONE    :
1700 /// @param <RET>       \b NONE    :
1701 /// @param <GLOBAL>    \b NONE    :
1702 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableAutoVolume(MS_BOOL bEnable)1703 void HAL_SOUND_EnableAutoVolume(MS_BOOL bEnable)
1704 {
1705     HAL_AUDIO_WriteMaskByte(0x2D21, 0x10, bEnable<<4);
1706 }
1707 
1708 ////////////////////////////////////////////////////////////////////////////////
1709 /// @brief \b Function \b Name: HAL_SOUND_GetAutoVolume_Status()
1710 /// @brief \b Function \b Description: This routine is used to get the AutoVolume is enable or not
1711 /// @param <IN>        \b NONE    :
1712 /// @param <OUT>       \b NONE    :
1713 /// @param <RET>       \b bEnable :     TRUE  -- Enable  AVC (AutoVolume)
1714 ///                                     FALSE -- Disable AVC (AutoVolume)
1715 /// @param <GLOBAL>    \b NONE    :
1716 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetAutoVolume_Status(void)1717 MS_U16 HAL_SOUND_GetAutoVolume_Status(void)
1718 {
1719     if ((HAL_AUDIO_ReadByte(0x2D21)&0x10) == 0x10)
1720     {
1721         return 1;
1722     }
1723     else
1724     {
1725         return 0;
1726     }
1727 }
1728 
1729 ////////////////////////////////////////////////////////////////////////////////
1730 /// @brief \b Function \b Name: HAL_SOUND_EnableDRC() @@VVV
1731 /// @brief \b Function \b Description: This routine is used to Enable/Disable the DRC featue.
1732 /// @param <IN>        \b bEnable :     TRUE  -- Enable  DRC
1733 ///                                     FALSE -- Disable DRC
1734 /// @param <OUT>       \b NONE    :
1735 /// @param <RET>       \b NONE    :
1736 /// @param <GLOBAL>    \b NONE    :
1737 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableDRC(MS_BOOL bEnable)1738 void HAL_SOUND_EnableDRC(MS_BOOL bEnable)
1739 {
1740     HAL_AUDIO_WriteMaskByte(0x2D21, 0x20, bEnable<<5);
1741 }
1742 
1743 ////////////////////////////////////////////////////////////////////////////////
1744 /// @brief \b Function \b Name: HAL_SOUND_EnableNR()
1745 /// @brief \b Function \b Description: This routine is used to Enable/Disable the NR(Noise Reduction) featue and set NR thershold.
1746 /// @param <IN>        \b bEnable :     TRUE  -- Enable  NR
1747 ///                                     FALSE -- Disable NR
1748 /// @param <OUT>       \b NONE    :
1749 /// @param <RET>       \b NONE    :
1750 /// @param <GLOBAL>    \b NONE    :
1751 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_EnableNR(MS_U8 u8Level)1752 void HAL_SOUND_EnableNR(MS_U8 u8Level)
1753 {
1754     HAL_AUDIO_WriteMaskByte(0x2D32, 0xFF, u8Level);
1755 }
1756 
1757 ////////////////////////////////////////////////////////////////////////////////
1758 /// @brief \b Function \b Name: HAL_SOUND_SetNRAttenuate()
1759 /// @brief \b Function \b Description: This routine is used to set the attenuate u8Level while NR is bEnabled.
1760 /// @param <IN>        \b u8Mode    :     0 :    Auto fading to -24 dB
1761 ///                                                  1 :    Auto fading to -24 dB
1762 ///                                                  2 :    Auto fading to -24 dB
1763 ///                                                  3 :    Auto fading to -24 dB
1764 /// @param <OUT>       \b NONE    :
1765 /// @param <RET>       \b NONE    :
1766 /// @param <GLOBAL>    \b NONE    :
1767 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetNRAttenuate(MS_U8 u8Mode)1768 void HAL_SOUND_SetNRAttenuate(MS_U8 u8Mode)
1769 {
1770     u8Mode = u8Mode;
1771 }
1772 
1773 ////////////////////////////////////////////////////////////////////////////////
1774 /// @brief \b Function \b Name: HAL_SOUND_PowerDown_Wait() @@VVV
1775 /// @brief \b Function \b Description: This routine is used to DSP power-down wait function.
1776 /// @param <IN>        \b bEnable    :     TRUE --Not wait
1777 ///                                                    FALSE--wait
1778 /// @param <OUT>       \b NONE    :
1779 /// @param <RET>       \b NONE    :
1780 /// @param <GLOBAL>    \b NONE    :
1781 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_PowerDown_Wait(MS_BOOL bEnable)1782 void HAL_SOUND_PowerDown_Wait(MS_BOOL bEnable)
1783 {
1784     HAL_AUDIO_WriteMaskByte(0x2D31, 0x01, bEnable);
1785 }
1786 
1787 ////////////////////////////////////////////////////////////////////////////////
1788 /// @brief \b Function \b Name: HAL_SOUND_SetAdAbsoluteVolume()  @@VVV
1789 /// @brief \b Function \b Description: This routine is used to set the absolute volume of AD.
1790 /// @param <IN>        \b u8u8Vol1    :     MSB 7-bit register u8Value of 10-bit volume
1791 ///                                range from 0x00 to 0x7E , gain: +12db to   -114db (-1 db per step)
1792 /// @param <IN>        \b u8u8Vol2    :     LSB 3-bit register u8Value of 10-bit volume
1793 ///                                range from 0x00 to 0x07 , gain:  -0db to -0.875db (-0.125 db per step)
1794 /// @param <OUT>       \b NONE    :
1795 /// @param <RET>       \b NONE    :
1796 /// @param <GLOBAL>    \b NONE    :
1797 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetAdAbsoluteVolume(MS_U8 u8Vol1,MS_U8 u8Vol2)1798 void HAL_SOUND_SetAdAbsoluteVolume(MS_U8 u8Vol1, MS_U8 u8Vol2)
1799 {
1800     MS_U32 Vol = ((u8Vol1<<3) | (u8Vol2&0x07));
1801     HAL_DEC_R2_Set_SHM_PARAM(R2_SHM_PARAM_AD_VOLUME, ADEC1, Vol, 0);
1802     // Vol[10:0] =  mute[10]|int[9:3]|fra[2:0]
1803 }
1804 
1805 ////////////////////////////////////////////////////////////////////////////////
1806 /// @brief \b Function \b Name: HAL_SOUND_SetAdMute()  @@VVV
1807 /// @brief \b Function \b Description: This routine is used to set AD mute.
1808 /// @param <IN>        \b bEnable    :     TRUE --Mute AD
1809 ///                                        FALSE--Unmute AD
1810 /// @param <OUT>       \b NONE    :
1811 /// @param <RET>       \b NONE    :
1812 /// @param <GLOBAL>    \b NONE    :
1813 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetAdMute(MS_BOOL bEnable)1814 void HAL_SOUND_SetAdMute(MS_BOOL bEnable)
1815 {
1816     HAL_DEC_R2_Set_SHM_PARAM(R2_SHM_PARAM_AD_VOLUME_MUTE, ADEC1, bEnable, 0);
1817 }
1818 
1819 ////////////////////////////////////////////////////////////////////////////////
1820 /// @brief \b Function \b Name: HAL_SOUND_SetCH1AudioDelay()
1821 /// @brief \b Function \b Description: This routine is used to set Main audio delay.
1822 /// @param <IN>        \b u16Delay  :   0x20~0xC8(32~200), in ms unit
1823 /// @param <OUT>       \b NONE    :
1824 /// @param <RET>       \b NONE    :
1825 /// @param <GLOBAL>    \b NONE    :
1826 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetCH1AudioDelay(MS_U16 u16Delay)1827 void HAL_SOUND_SetCH1AudioDelay(MS_U16 u16Delay)
1828 {
1829     if (u16Delay > AUDIO_DELAY_UPPER_BOUND)
1830     {
1831         printf("Warning! Invalid value (%u), main audio delay should be less than %u ms. \r\n", u16Delay, AUDIO_DELAY_UPPER_BOUND);
1832         u16Delay = AUDIO_DELAY_UPPER_BOUND;
1833     }
1834 
1835     if (u16Delay < AUDIO_DELAY_LOWER_BOUND)
1836     {
1837         printf("Warning! Invalid value (%u), main audio delay should be larger than %u ms. \r\n", u16Delay, AUDIO_DELAY_LOWER_BOUND);
1838         u16Delay = AUDIO_DELAY_LOWER_BOUND;
1839     }
1840 
1841     HAL_MAD2_Write_DSP_sram(DSP2PmAddr_mainAudioDelay, u16Delay, DSP_MEM_TYPE_PM);
1842 }
1843 
1844 ////////////////////////////////////////////////////////////////////////////////
1845 /// @brief \b Function \b Name: HAL_SOUND_GetCH1AudioDelay()
1846 /// @brief \b Function \b Description: This routine is used to get the value of Main audio delay.
1847 /// @param <RET>       \b u16Delay  :   0x14~0xC8(20~200), in ms unit
1848 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetCH1AudioDelay(void)1849 MS_U16 HAL_SOUND_GetCH1AudioDelay(void)
1850 {
1851     return(HAL_MAD2_Read_DSP_sram(DSP2PmAddr_mainAudioDelay, DSP_MEM_TYPE_PM));
1852 }
1853 
1854 
1855 ////////////////////////////////////////////////////////////////////////////////
1856 /// @brief \b Function \b Name: HAL_SOUND_GetCH5AudioDelay()
1857 /// @brief \b Function \b Description: This routine is used to set the u8Value of audio delay.
1858 /// @param <RET>        \b delay    :     0x14~0xC8(20~200), in ms unit
1859 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetCH5AudioDelay(void)1860 MS_U16 HAL_SOUND_GetCH5AudioDelay(void)
1861 {
1862     return(HAL_MAD2_Read_DSP_sram(DSP2PmAddr_ch5InputDelay, DSP_MEM_TYPE_PM));
1863 }
1864 
1865 ////////////////////////////////////////////////////////////////////////////////
1866 /// @brief \b Function \b Name: HAL_SOUND_GetCH6AudioDelay()
1867 /// @brief \b Function \b Description: This routine is used to set the u8Value of audio delay.
1868 /// @param <RET>        \b delay    :     0x14~0xC8(20~200), in ms unit
1869 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetCH6AudioDelay(void)1870 MS_U16 HAL_SOUND_GetCH6AudioDelay(void)
1871 {
1872     return(HAL_MAD2_Read_DSP_sram(DSP2PmAddr_ch6InputDelay, DSP_MEM_TYPE_PM));
1873 }
1874 
1875 ////////////////////////////////////////////////////////////////////////////////
1876 /// @brief \b Function \b Name: HAL_SOUND_SetSpdifAudioDelay()
1877 /// @brief \b Function \b Description: This routine is used to set SPDIF audio delay.
1878 /// @param <IN>        \b u16Delay  :   0x14~0xFA(20~250), in ms unit
1879 /// @param <OUT>       \b NONE    :
1880 /// @param <RET>       \b NONE    :
1881 /// @param <GLOBAL>    \b NONE    :
1882 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetSpdifAudioDelay(MS_U16 u16Delay)1883 void HAL_SOUND_SetSpdifAudioDelay(MS_U16 u16Delay)
1884 {
1885     if (u16Delay > AUDIO_DELAY_UPPER_BOUND_SPDIF)
1886     {
1887         printf("Warning! Invalid value (%u), spdif audio delay should be less than %u ms. \r\n", u16Delay, AUDIO_DELAY_UPPER_BOUND_SPDIF);
1888         u16Delay = AUDIO_DELAY_UPPER_BOUND_SPDIF;
1889     }
1890 
1891     if (u16Delay < AUDIO_DELAY_LOWER_BOUND_SPDIF)
1892     {
1893         printf("Warning! Invalid value (%u), spdif audio delay should be larger than %u ms. \r\n", u16Delay, AUDIO_DELAY_LOWER_BOUND_SPDIF);
1894         u16Delay = AUDIO_DELAY_LOWER_BOUND_SPDIF;
1895     }
1896 
1897     HAL_MAD2_Write_DSP_sram(DSP2PmAddr_spdifDelay, u16Delay, DSP_MEM_TYPE_PM);
1898 }
1899 
1900 ////////////////////////////////////////////////////////////////////////////////
1901 /// @brief \b Function \b Name: HAL_SOUND_GetSpdifAudioDelay()
1902 /// @brief \b Function \b Description: This routine is used to get the u8Value of audio SPDIF delay.
1903 /// @param <RET>        \b delay    :     0x14~0xC8(20~200), in ms unit
1904 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetSpdifAudioDelay(void)1905 MS_U16 HAL_SOUND_GetSpdifAudioDelay(void)
1906 {
1907     return(HAL_MAD2_Read_DSP_sram(DSP2PmAddr_spdifDelay, DSP_MEM_TYPE_PM));
1908 }
1909 
1910 ////////////////////////////////////////////////////////////////////////////////
1911 /// @brief \b Function \b Name: HAL_SOUND_GetHPAudioDelay()
1912 /// @brief \b Function \b Description: This routine is used to get the u8Value of audio SPDIF delay.
1913 /// @param <RET>        \b delay    :     0x14~0xC8(20~200), in ms unit
1914 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetHPAudioDelay(void)1915 MS_U16 HAL_SOUND_GetHPAudioDelay(void)
1916 {
1917     return(HAL_MAD2_Read_DSP_sram(DSP2PmAddr_hpDelay, DSP_MEM_TYPE_PM));
1918 }
1919 
1920 ////////////////////////////////////////////////////////////////////////////////
1921 /// @brief \b Function \b Name: HAL_SOUND_SetMenuSound() @@Need_Modify
1922 /// @brief \b Function \b Description: This routine is used to Play Menu Sound.
1923 /// @param <IN>        \b NONE    :
1924 /// @param <OUT>       \b NONE    :
1925 /// @param <RET>       \b NONE    :
1926 /// @param <GLOBAL>    \b NONE    :
1927 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_PlayMenuSound(void)1928 void HAL_SOUND_PlayMenuSound(void)
1929 {
1930      /*Cathy0721
1931      HAL_AUDIO_WriteMaskByte(0x2DAE, 0x01, 0x01);
1932      AUDIO_DELAY1MS(10);
1933      HAL_AUDIO_WriteMaskByte(0x2DAE, 0x01, 0x00);*/
1934 }
1935 
1936 ////////////////////////////////////////////////////////////////////////////////
1937 /// @brief \b Function \b Name: HAL_SOUND_SetSurroundXA() @@VVV
1938 /// @brief \b Function \b Description: This routine is used to set the Surround xA Gain.
1939 /// @param <IN>        \b u8Mode    :     0 :    0.1         xA : 0x2D8A[3:2] 00: 0.1
1940 ///                                    1 :    0.15                         01: 0.15
1941 ///                                    2 :    0.2                          10: 0.2
1942 ///                                    3 :    0.25                         11: 0.25
1943 /// @param <OUT>       \b NONE    :
1944 /// @param <RET>       \b NONE    :
1945 /// @param <GLOBAL>    \b NONE
1946 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetSurroundXA(MS_U8 u8Mode)1947 void HAL_SOUND_SetSurroundXA(MS_U8 u8Mode)
1948 {
1949    switch(u8Mode)
1950     {
1951         case 0:
1952             HAL_AUDIO_WriteMaskByte(0x2D26 ,0x0C ,0x00);
1953             break;
1954         case 1:
1955             HAL_AUDIO_WriteMaskByte(0x2D26 ,0x0C ,0x04);
1956             break;
1957         case 2:
1958             HAL_AUDIO_WriteMaskByte(0x2D26 ,0x0C ,0x08);
1959             break;
1960         case 3:
1961             HAL_AUDIO_WriteMaskByte(0x2D26 ,0x0C ,0x0C);
1962             break;
1963         default:
1964             break;
1965     }
1966 }
1967 
1968 ////////////////////////////////////////////////////////////////////////////////
1969 /// @brief \b Function \b Name: HAL_SOUND_GetSurroundXA()
1970 /// @brief \b Function \b Description: This routine is used to set the Surround xA Gain.
1971 /// @param <RET> MODE  \b u8Mode    :     0 :    0.1         xA : 0x2D8A[3:2] 00: 0.1
1972 ///                                    1 :    0.15                         01: 0.15
1973 ///                                    2 :    0.2                          10: 0.2
1974 ///                                    3 :    0.25                         11: 0.25
1975 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetSurroundXA(void)1976 MS_U16 HAL_SOUND_GetSurroundXA(void)
1977 {
1978     return((HAL_AUDIO_ReadByte(0x2D26)&0x0C)>>2);
1979 }
1980 
1981 ////////////////////////////////////////////////////////////////////////////////
1982 /// @brief \b Function \b Name: HAL_SOUND_SetSurroundXB()  @@VVV
1983 /// @brief \b Function \b Description: This routine is used to set the Surround xB Gain.
1984 /// @param <IN>        \b u8Mode    :     0 :    0.25         xB : 0x2D8A[5:4] 00: 0.25
1985 ///                                                  1 :    0.3                           01: 0.3
1986 ///                                                  2 :    0.35                          10: 0.35
1987 ///                                                  3 :    0.45                          11: 0.45
1988 /// @param <OUT>       \b NONE    :
1989 /// @param <RET>       \b NONE    :
1990 /// @param <GLOBAL>    \b NONE
1991 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetSurroundXB(MS_U8 u8Mode)1992 void HAL_SOUND_SetSurroundXB(MS_U8 u8Mode)
1993 {
1994     switch(u8Mode)
1995     {
1996         case 0:
1997             HAL_AUDIO_WriteMaskByte(0x2D26 ,0x30 ,0x00);
1998             break;
1999         case 1:
2000             HAL_AUDIO_WriteMaskByte(0x2D26 ,0x30 ,0x10);
2001             break;
2002         case 2:
2003             HAL_AUDIO_WriteMaskByte(0x2D26 ,0x30 ,0x20);
2004             break;
2005         case 3:
2006             HAL_AUDIO_WriteMaskByte(0x2D26 ,0x30 ,0x30);
2007             break;
2008         default:
2009             break;
2010     }
2011 }
2012 
2013 ////////////////////////////////////////////////////////////////////////////////
2014 /// @brief \b Function \b Name: HAL_SOUND_GetSurroundXB()
2015 /// @brief \b Function \b Description: This routine is used to set the Surround xB Gain.
2016 /// @param <RET> MODE  \b u8Mode    :     0 :    0.1         xB : 0x2D8A[3:2] 00: 0.1
2017 ///                                    1 :    0.15                         01: 0.15
2018 ///                                    2 :    0.2                          10: 0.2
2019 ///                                    3 :    0.25                         11: 0.25
2020 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetSurroundXB(void)2021 MS_U16 HAL_SOUND_GetSurroundXB(void)
2022 {
2023     return((HAL_AUDIO_ReadByte(0x2D26)&0x30)>>2);
2024 }
2025 
2026 ////////////////////////////////////////////////////////////////////////////////
2027 /// @brief \b Function \b Name: HAL_SOUND_SetSurroundXK() @@VVV
2028 /// @brief \b Function \b Description: This routine is used to set the Surround xK Gain.
2029 /// @param <IN>        \b u8Mode    :     0 :    0.1         xK : 0x2D8A[7:6]  00: 0.1
2030 ///                                                  1 :    0.2                           01: 0.2
2031 ///                                                  2 :    0.3                           10: 0.3
2032 ///                                                  3 :    0.4                           11: 0.4
2033 /// @param <OUT>       \b NONE    :
2034 /// @param <RET>       \b NONE    :
2035 /// @param <GLOBAL>    \b NONE
2036 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetSurroundXK(MS_U8 u8Mode)2037 void HAL_SOUND_SetSurroundXK(MS_U8 u8Mode)
2038 {
2039      HAL_AUDIO_WriteMaskByte(0x2D27 ,0x07 ,u8Mode);
2040 }
2041 
2042 ////////////////////////////////////////////////////////////////////////////////
2043 /// @brief \b Function \b Name: HAL_SOUND_GetSurroundXK()
2044 /// @brief \b Function \b Description: This routine is used to set the Surround xK Gain.
2045 /// @param <RET> MODE  \b u8Mode    :     0 :    0.1         xK : 0x2D27[2:0] 00: 0.1
2046 ///                                                  1 :    0.2                           01: 0.2
2047 ///                                                  2 :    0.3                           10: 0.3
2048 ///                                                  3 :    0.4                           11: 0.4
2049 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetSurroundXK(void)2050 MS_U16 HAL_SOUND_GetSurroundXK(void)
2051 {
2052     MS_U16 Mode=0;
2053 
2054     Mode = HAL_AUDIO_ReadByte(0x2D27)&0x07;
2055 
2056     return Mode;
2057 }
2058 
2059 ////////////////////////////////////////////////////////////////////////////////
2060 /// @brief \b Function \b Name: HAL_SOUND_SetSurroundLPFGain() @@VVV
2061 /// @brief \b Function \b Description: This routine is used to set the Surround LPF Gain.
2062 /// @param <IN>        \b u8Mode    :     0 :    0 dB        LPF Gain : 0x2DA0[7:6]  00: 0 dB
2063 ///                                                  1 :    2 dB                                01: 2 dB
2064 ///                                                  2 :    4 dB                                10: 4 dB
2065 ///                                                  3 :    un-support                          11: un-support
2066 /// @param <OUT>       \b NONE    :
2067 /// @param <RET>       \b NONE    :
2068 /// @param <GLOBAL>    \b NONE
2069 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetSurroundLPFGain(MS_U8 u8Mode)2070 void HAL_SOUND_SetSurroundLPFGain(MS_U8 u8Mode)
2071 {
2072    switch(u8Mode)
2073     {
2074         case 0:
2075             HAL_AUDIO_WriteMaskByte(0x2D26 ,0xC0 ,0x00);
2076             break;
2077         case 1:
2078             HAL_AUDIO_WriteMaskByte(0x2D26 ,0xC0 ,0x40);
2079             break;
2080         case 2:
2081             HAL_AUDIO_WriteMaskByte(0x2D26 ,0xC0 ,0x80);
2082             break;
2083         case 3:
2084             //HAL_AUDIO_WriteMaskByte(0x2D26 ,0xC0 ,0xC0);
2085             break;
2086         default:
2087             break;
2088     }
2089 }
2090 
2091 ////////////////////////////////////////////////////////////////////////////////
2092 /// @brief \b Function \b Name: HAL_SOUND_GetSurroundLPFGain()
2093 /// @brief \b Function \b Description: This routine is used to set the Surround xK Gain.
2094 /// @param <RET>   \b LPFGain    :
2095 //                                      0 :    0dB
2096 ///                                    1 :    2dB
2097 ///                                    2 :    4dB
2098 ///                                    3 :    up-support
2099 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_GetSurroundLPFGain(void)2100 MS_U16 HAL_SOUND_GetSurroundLPFGain(void)
2101 {
2102     return((HAL_AUDIO_ReadByte(0x2D26)&0xC0)>>6);
2103 }
2104 
2105 
2106 ////////////////////////////////////////////////////////////////////////////////
2107 /// @brief \b Function \b Name: HAL_SOUND_SetPEQCoef()
2108 /// @brief \b Function \b Description: This routine is used to set PEQ Coefficient.
2109 /// @param <IN>        \b peq_coef
2110 /// @param <OUT>       \b NONE  :
2111 /// @param <RET>       \b  NONE :
2112 /// @param <GLOBAL>    \b NONE
2113 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetPEQCoef(AUDIO_PEQ_COEF * peq_coef)2114 void HAL_SOUND_SetPEQCoef(AUDIO_PEQ_COEF *peq_coef)
2115 {
2116     MS_U16 dsp_addr;
2117     MS_U16 dsp_scale_addr;
2118 
2119     if(peq_coef->sfs == 0)
2120     {
2121         DBG_SOUND(printf("!!!only support 48K coefficient ! ! !\n");)
2122         return;
2123     }
2124 
2125     //PEQ setting
2126     if(peq_coef->type == AUDIO_COEF_PEQ || peq_coef->type == AUDIO_COEF_PREVER_PEQ)  // PEQ setting
2127     {
2128         if(peq_coef->enable == FALSE)
2129             peq_band_enable &= (0xFFFFFFFF ^ ((MS_U32)1<<peq_coef->band));
2130         else
2131             peq_band_enable |= ((MS_U32)1<<peq_coef->band);
2132 
2133         if(peq_coef->precision == AUDIO_SINGLE_PRECISION)
2134             peq_band_precision &= (0xFFFFFFFF ^ ((MS_U32)1<<peq_coef->band));
2135         else
2136             peq_band_precision |= ((MS_U32)1<<peq_coef->band);
2137 
2138         dsp_addr = DSP2PmAddr_peq48KCoeffAddr + peq_coef->band*5;
2139         dsp_scale_addr = DSP2PmAddr_peqscale48KAddr + peq_coef->band;
2140 
2141         HAL_AUDIO_WriteMaskByte(M2S_MBOX_SNDEFF_EN, 1<< (M2S_MBOX_COEFFUPDATE_EN_BIT), 1<< (M2S_MBOX_COEFFUPDATE_EN_BIT)); //disable  updating coefficient to prevent pop
2142         HAL_MAD2_Write_DSP_sram(dsp_addr,peq_coef->a0, DSP_MEM_TYPE_PM);
2143         HAL_MAD2_Write_DSP_sram(dsp_addr+1,peq_coef->a1, DSP_MEM_TYPE_PM);
2144         HAL_MAD2_Write_DSP_sram(dsp_addr+2,peq_coef->a2, DSP_MEM_TYPE_PM);
2145         HAL_MAD2_Write_DSP_sram(dsp_addr+3,peq_coef->b1, DSP_MEM_TYPE_PM);
2146         HAL_MAD2_Write_DSP_sram(dsp_addr+4,peq_coef->b2, DSP_MEM_TYPE_PM);
2147         HAL_MAD2_Write_DSP_sram(dsp_scale_addr,(MS_U32)peq_coef->scale, DSP_MEM_TYPE_PM);
2148         HAL_MAD2_Write_DSP_sram(DSP2PmAddr_peqbandEnAddr,peq_band_enable, DSP_MEM_TYPE_PM);
2149         HAL_MAD2_Write_DSP_sram(DSP2PmAddr_peqbandDoubleAddr,peq_band_precision, DSP_MEM_TYPE_PM);
2150         HAL_AUDIO_WriteMaskByte(M2S_MBOX_SNDEFF_EN, 1<< (M2S_MBOX_COEFFUPDATE_EN_BIT), 0x00); //enable coefficient update
2151     }
2152     // HLPF setting
2153     else  if(peq_coef->type == AUDIO_COEF_HPF)
2154     {
2155         HAL_AUDIO_WriteMaskByte(M2S_MBOX_SNDEFF_EN, 1<< (M2S_MBOX_COEFFUPDATE_EN_BIT), 1<< (M2S_MBOX_COEFFUPDATE_EN_BIT)); //disable  updating coefficient to prevent pop
2156         dsp_addr = DSP2PmAddr_hpf48KCoeffAddr;
2157         HAL_MAD2_Write_DSP_sram(dsp_addr,peq_coef->a0, DSP_MEM_TYPE_PM);
2158         HAL_MAD2_Write_DSP_sram(dsp_addr+1,peq_coef->a1, DSP_MEM_TYPE_PM);
2159         HAL_MAD2_Write_DSP_sram(dsp_addr+2,peq_coef->a2, DSP_MEM_TYPE_PM);
2160         HAL_MAD2_Write_DSP_sram(dsp_addr+3,peq_coef->b1, DSP_MEM_TYPE_PM);
2161         HAL_MAD2_Write_DSP_sram(dsp_addr+4,peq_coef->b2, DSP_MEM_TYPE_PM);
2162         HAL_AUDIO_WriteMaskByte(M2S_MBOX_SNDEFF_EN, 1<< (M2S_MBOX_COEFFUPDATE_EN_BIT), 0x00); //disable oefficient update
2163     }
2164     //TONE setting
2165     else  if(peq_coef->type == AUDIO_COEF_BASS ||peq_coef->type == AUDIO_COEF_TREBLE)
2166     {
2167         HAL_AUDIO_WriteMaskByte(M2S_MBOX_SNDEFF_EN, 1<< (M2S_MBOX_COEFFUPDATE_EN_BIT), 1<< (M2S_MBOX_COEFFUPDATE_EN_BIT)); //disable  updating coefficient to prevent pop
2168         if(peq_coef->type == AUDIO_COEF_BASS)
2169         {
2170             dsp_addr = DSP2PmAddr_bass48KCoeffAddr;
2171         }
2172         else
2173         {
2174             dsp_addr = DSP2PmAddr_treble48KCoeffAddr;
2175             dsp_scale_addr =DSP2PmAddr_treblescale48KAddr;
2176             HAL_MAD2_Write_DSP_sram(dsp_scale_addr,(MS_U32)peq_coef->scale, DSP_MEM_TYPE_PM);
2177          }
2178         HAL_MAD2_Write_DSP_sram(dsp_addr,peq_coef->a0, DSP_MEM_TYPE_PM);
2179         HAL_MAD2_Write_DSP_sram(dsp_addr+1,peq_coef->a1, DSP_MEM_TYPE_PM);
2180         HAL_MAD2_Write_DSP_sram(dsp_addr+2,peq_coef->a2, DSP_MEM_TYPE_PM);
2181         HAL_MAD2_Write_DSP_sram(dsp_addr+3,peq_coef->b1, DSP_MEM_TYPE_PM);
2182         HAL_MAD2_Write_DSP_sram(dsp_addr+4,peq_coef->b2, DSP_MEM_TYPE_PM);
2183         HAL_MAD2_Write_DSP_sram(DSP2PmAddr_toneSelectAddr,0x01, DSP_MEM_TYPE_PM);
2184         HAL_AUDIO_WriteMaskByte(M2S_MBOX_SNDEFF_EN, 1<< (M2S_MBOX_COEFFUPDATE_EN_BIT), 0x00); //disable oefficient update
2185     }
2186     else
2187     {
2188         DBG_SOUND(printf("!!! undefined coefficient type ! ! !\n");)
2189         return;
2190     }
2191 
2192     DBG_SOUND(printf("HAL a0 = %x", (MS_U8)(peq_coef->a0>>16)));
2193     DBG_SOUND(printf(" %x", (MS_U8)(peq_coef->a0>>8)));
2194     DBG_SOUND(printf(" %x\r\n", (MS_U8)peq_coef->a0));
2195 
2196     DBG_SOUND(printf("HAL a1 = %x", (MS_U8)(peq_coef->a1>>16)));
2197     DBG_SOUND(printf(" %x", (MS_U8)(peq_coef->a1>>8)));
2198     DBG_SOUND(printf(" %x\r\n", (MS_U8)peq_coef->a1));
2199 
2200     DBG_SOUND(printf("HAL a2 = %x", (MS_U8)(peq_coef->a2>>16)));
2201     DBG_SOUND(printf(" %x", (MS_U8)(peq_coef->a2>>8)));
2202     DBG_SOUND(printf(" %x\r\n", (MS_U8)peq_coef->a2));
2203 
2204     DBG_SOUND(printf("HAL b1 = %x", (MS_U8)(peq_coef->b1>>16)));
2205     DBG_SOUND(printf(" %x", (MS_U8)(peq_coef->b1>>8)));
2206     DBG_SOUND(printf(" %x\r\n", (MS_U8)peq_coef->b1));
2207 
2208     DBG_SOUND(printf("HAL b2 = %x", (MS_U8)(peq_coef->b2>>16)));
2209     DBG_SOUND(printf(" %x", (MS_U8)(peq_coef->b2>>8)));
2210     DBG_SOUND(printf(" %x\r\n", (MS_U8)peq_coef->b2));
2211 }
2212 
2213 ////////////////////////////////////////////////////////////////////////////////
2214 /// @brief \b Function \b Name: MDrv_SOUND_SetMixModeVolume()  @@VVV
2215 /// @brief \b Function \b Description: This routine is used to set the absolute volume of mix mode.
2216 /// @param <IN>        \b eSourceType: for audio source
2217 /// @param <IN>        \b VolType    : for vol type
2218 /// @param <IN>        \b u8u8Vol1   :     MSB 7-bit register u8Value of 10-bit volume
2219 ///                                range from 0x00 to 0x7E , gain: +12db to   -114db (-1 db per step)
2220 /// @param <IN>        \b u8u8Vol2   :     LSB 3-bit register u8Value of 10-bit volume
2221 ///                                range from 0x00 to 0x07 , gain:  -0db to -0.875db (-0.125 db per step)
2222 /// @param <OUT>       \b NONE    :
2223 /// @param <RET>       \b NONE    :
2224 /// @param <GLOBAL>    \b NONE    :
2225 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetMixModeVolume(AUDIO_SOURCE_INFO_TYPE eSourceType,AUDIO_MIX_VOL_TYPE VolType,MS_U8 u8Vol1,MS_U8 u8Vol2)2226 void HAL_SOUND_SetMixModeVolume(AUDIO_SOURCE_INFO_TYPE eSourceType, AUDIO_MIX_VOL_TYPE VolType, MS_U8 u8Vol1, MS_U8 u8Vol2  )
2227 {
2228     switch (eSourceType)
2229     {
2230         case E_AUDIO_INFO_KTV_IN:
2231             switch(VolType)
2232             {
2233                 case PCM_VOL:
2234                     HAL_AUDIO_WriteMaskByte(0x2D5B, 0x7F, u8Vol1);
2235                     HAL_AUDIO_WriteMaskByte(0x2D5A, 0xE0, (u8Vol2<<5));
2236                     break;
2237                 case MIC_VOL:
2238                     HAL_AUDIO_WriteMaskByte(0x2D5D, 0x7F, u8Vol1);
2239                     HAL_AUDIO_WriteMaskByte(0x2D5C, 0xE0, (u8Vol2<<5));
2240                     break;
2241                 case MP3_VOL:
2242                     HAL_AUDIO_WriteMaskByte(0x2D5F, 0x7F, u8Vol1);
2243                     HAL_AUDIO_WriteMaskByte(0x2D5E, 0xE0, (u8Vol2<<5));
2244 		     break;
2245 		 case ECHO1_VOL:
2246 		 	if(u8Vol1<14)
2247 		 	    u8Vol1 = 14;
2248 		      HAL_AUDIO_WriteMaskByte(0x2D57, 0x7F, u8Vol1);
2249                     HAL_AUDIO_WriteMaskByte(0x2D56, 0xE0, (u8Vol2<<5));
2250                     break;
2251 		case ECHO2_VOL:
2252 		      HAL_AUDIO_WriteMaskByte(0x2D59, 0x7F, u8Vol1);
2253                     HAL_AUDIO_WriteMaskByte(0x2D58, 0xE0, (u8Vol2<<5));
2254                     break;
2255                 default:
2256                     break;
2257             }
2258             break;
2259 
2260         case E_AUDIO_INFO_GAME_IN:
2261             switch(VolType)
2262             {
2263                 case PCM_VOL:
2264                     HAL_AUDIO_WriteMaskByte(0x2D5B, 0x7F, u8Vol1);
2265                     HAL_AUDIO_WriteMaskByte(0x2D5A, 0xE0, (u8Vol2<<5));
2266                     break;
2267                 case GAME1_VOL:
2268                     HAL_AUDIO_WriteMaskByte(0x2D5D, 0x7F, u8Vol1);
2269                     HAL_AUDIO_WriteMaskByte(0x2D5C, 0xE0, (u8Vol2<<5));
2270                     break;
2271                 case GAME2_VOL:
2272                     HAL_AUDIO_WriteMaskByte(0x2D5F, 0x7F, u8Vol1);
2273                     HAL_AUDIO_WriteMaskByte(0x2D5E, 0xE0, (u8Vol2<<5));
2274                     break;
2275                 default:
2276                     break;
2277             }
2278             break;
2279 
2280         default:
2281             break;
2282     }
2283 }
2284 
2285 ////////////////////////////////////////////////////////////////////////////////
2286 /// @brief \b Function \b Name: HAL_SOUND_SetMixModeMute() @@VVV
2287 /// @brief \b Function \b Description: This routine is used to set audio mix mode S/W mute.
2288 /// @param <IN>        \b eSourseType: for audio source type
2289 /// @param <IN>        \b VolType    : for vol type
2290 /// @param <IN>        \b bEnable    :     TRUE --Mute
2291 ///                                  :     FALSE--Unmute
2292 /// @param <OUT>       \b NONE    :
2293 /// @param <RET>       \b NONE    :
2294 /// @param <GLOBAL>    \b NONE    :
2295 ////////////////////////////////////////////////////////////////////////////////
HAL_SOUND_SetMixModeMute(AUDIO_SOURCE_INFO_TYPE eSourceType,AUDIO_MIX_VOL_TYPE VolType,MS_BOOL EnMute)2296 void HAL_SOUND_SetMixModeMute(AUDIO_SOURCE_INFO_TYPE eSourceType, AUDIO_MIX_VOL_TYPE VolType, MS_BOOL EnMute )
2297 {
2298     switch (eSourceType)
2299     {
2300         case E_AUDIO_INFO_KTV_IN:
2301             switch(VolType)
2302             {
2303                 case PCM_VOL:
2304                     if(EnMute)  // Mute
2305                         HAL_AUDIO_WriteMaskByte(0x2D5B, 0x80, 0x80);
2306                     else        // UnMute
2307                         HAL_AUDIO_WriteMaskByte(0x2D5B, 0x80, 0x00);
2308                     break;
2309                 case MIC_VOL:
2310                     if(EnMute)  // Mute
2311                         HAL_AUDIO_WriteMaskByte(0x2D5D, 0x80, 0x80);
2312                     else        // UnMute
2313                         HAL_AUDIO_WriteMaskByte(0x2D5D, 0x80, 0x00);
2314                     break;
2315                 case MP3_VOL:
2316                     if(EnMute)  // Mute
2317                         HAL_AUDIO_WriteMaskByte(0x2D5F, 0x80, 0x80);
2318                     else        // UnMute
2319                         HAL_AUDIO_WriteMaskByte(0x2D5F, 0x80, 0x00);
2320                     break;
2321                 default:
2322                     break;
2323             }
2324             break;
2325 
2326         case E_AUDIO_INFO_GAME_IN:
2327             switch(VolType)
2328             {
2329                 case PCM_VOL:
2330                     if(EnMute)  // Mute
2331                         HAL_AUDIO_WriteMaskByte(0x2D5B, 0x80, 0x80);
2332                     else        // UnMute
2333                         HAL_AUDIO_WriteMaskByte(0x2D5B, 0x80, 0x00);
2334                     break;
2335                 case GAME1_VOL:
2336                     if(EnMute)  // Mute
2337                         HAL_AUDIO_WriteMaskByte(0x2D5D, 0x80, 0x80);
2338                     else        // UnMute
2339                         HAL_AUDIO_WriteMaskByte(0x2D5D, 0x80, 0x00);
2340                     break;
2341                 case GAME2_VOL:
2342                     if(EnMute)  // Mute
2343                         HAL_AUDIO_WriteMaskByte(0x2D5F, 0x80, 0x80);
2344                     else        // UnMute
2345                         HAL_AUDIO_WriteMaskByte(0x2D5F, 0x80, 0x00);
2346                     break;
2347                 default:
2348                     break;
2349             }
2350             break;
2351 
2352         default:
2353             break;
2354     }
2355 }
2356 
2357 //******************************************************************************
2358 /// @brief \b Function \b Name: HAL_SOUND_SetParam()
2359 /// @brief \b Function \b Description: This routine is used for adjust Common Sound parameters
2360 /// @return MS_BOOL     \b : True / False
2361 //******************************************************************************
HAL_SOUND_SetParam(Sound_SET_Type Type,MS_U32 * p_param)2362 MS_BOOL HAL_SOUND_SetParam( Sound_SET_Type Type, MS_U32 *p_param )
2363 {
2364     MS_U8 param1 = (MS_U8)(p_param[0]);
2365     MS_U8 param2 = (MS_U8)(p_param[1]);
2366     MS_U8 param3 = (MS_U8)(p_param[2]);
2367     MS_U8 param4 = (MS_U8)(p_param[3]);
2368 
2369     switch(Type)
2370     {
2371         case Sound_SET_Type_SetPreScale:
2372             HAL_SOUND_SetPreScale(param1, param2);
2373             break;
2374 
2375         case Sound_SET_Type_SetMute:
2376             HAL_SOUND_SetMute(param1, param2);
2377             break;
2378 
2379         case Sound_SET_Type_SetBalance:
2380             HAL_SOUND_SetBalance(param1);
2381             break;
2382 
2383         case Sound_SET_Type_EnableEQ:
2384             HAL_SOUND_EnableEQ(param1);
2385             break;
2386 
2387         case Sound_SET_Type_EnablePEQ:
2388             HAL_SOUND_EnablePEQ(param1);
2389             break;
2390 
2391         case Sound_SET_Type_EnableTone:
2392             HAL_SOUND_EnableTone(param1);
2393             break;
2394 
2395         case Sound_SET_Type_EnableAutoVolume:
2396             HAL_SOUND_EnableAutoVolume(param1);
2397             break;
2398 
2399         case Sound_SET_Type_EnableSurround:
2400             HAL_SOUND_EnableSurround(param1);
2401             break;
2402 
2403         case Sound_SET_Type_SetBass:
2404             HAL_SOUND_SetBass(param1);
2405             break;
2406 
2407         case Sound_SET_Type_EnableBalance:
2408             HAL_SOUND_EnableBalance(param1);
2409             break;
2410 
2411         case Sound_SET_Type_AbsoluteBass:
2412             HAL_SOUND_AbsoluteBass(param1);
2413             break;
2414 
2415         case Sound_SET_Type_SetTreble:
2416             HAL_SOUND_SetTreble(param1);
2417             break;
2418 
2419         case Sound_SET_Type_SetEq:
2420             HAL_SOUND_SetEq(param1, param2);
2421             break;
2422 
2423         case Sound_SET_Type_SetEq_7band:
2424             HAL_SOUND_SetEq7(param1, param2);
2425             break;
2426 
2427         case Sound_SET_Type_SetAvc:
2428             HAL_SOUND_SetAVCThreshold(param1);
2429             HAL_SOUND_SetAvcMode(param2);
2430             HAL_SOUND_SetAvcAT(param3);
2431             HAL_SOUND_SetAvcRT(param4);
2432             break;
2433 
2434         case Sound_SET_Type_SetAudioDelay:
2435             HAL_SOUND_SetCH1AudioDelay(param1);
2436             break;
2437 
2438         case Sound_SET_Type_SetSurround:
2439             HAL_SOUND_SetSurroundXA(param1);
2440             HAL_SOUND_SetSurroundXB(param2);
2441             HAL_SOUND_SetSurroundXK(param3);
2442             HAL_SOUND_SetSurroundLPFGain(param4);
2443             break;
2444 
2445         case Sound_SET_Type_ConvertVolumeUnit:
2446             break;
2447 
2448         case Sound_SET_Type_SetDCOffet:
2449             HAL_AUDIO_WriteByte(0x2B50 ,param1);
2450             HAL_AUDIO_WriteByte(0x2B51 ,param2);
2451             break;
2452 
2453         case Sound_SET_Type_EnableSineTone:
2454         default:
2455             break;
2456     }
2457     return TRUE;
2458 }
2459 
2460 //******************************************************************************
2461 /// @brief \b Function \b Name: HAL_SND_ProcessEnable()
2462 /// @brief \b Function \b Description: This routine is used for adjust Common Sound parameters
2463 //******************************************************************************
HAL_SND_ProcessEnable(Sound_ENABLE_Type Type,MS_BOOL enable)2464 MS_BOOL HAL_SND_ProcessEnable(Sound_ENABLE_Type Type, MS_BOOL enable)
2465 {
2466     MS_BOOL status = FALSE;
2467 
2468     switch(Type)
2469     {
2470         case Sound_ENABL_Type_EQ:
2471             HAL_SOUND_EnableEQ(enable);
2472             status = TRUE;
2473             break;
2474 
2475         case Sound_ENABL_Type_PEQ:
2476             HAL_SOUND_EnablePEQ(enable);
2477             status = TRUE;
2478             break;
2479 
2480         case Sound_ENABL_Type_Tone:
2481             HAL_SOUND_EnableTone(enable);
2482             status = TRUE;
2483             break;
2484 
2485         case Sound_ENABL_Type_AutoVolume:
2486             HAL_SOUND_EnableAutoVolume(enable);
2487             status = TRUE;
2488             break;
2489 
2490         case Sound_ENABL_Type_Surround:
2491             HAL_SOUND_EnableSurround(enable);
2492             status = TRUE;
2493             break;
2494 
2495         case Sound_ENABL_Type_Balance:
2496             HAL_SOUND_EnableBalance(enable);
2497             status = TRUE;
2498             break;
2499 
2500     case Sound_ENABL_Type_DRC:
2501             HAL_SOUND_EnableDRC(enable);
2502             status = TRUE;
2503             break;
2504 
2505        case Sound_ENABL_Type_KTVEcho:
2506             HAL_SOUND_EnableKTVEcho(enable);
2507             status = TRUE;
2508             break;
2509 
2510         case Sound_ENABL_Type_Hpf:
2511             HAL_SOUND_EnableHPF(enable);
2512             status = TRUE;
2513             break;
2514 
2515         case Sound_ENABL_Type_DcRemove:
2516             HAL_SOUND_EnableDcRemove(enable);
2517             status = TRUE;
2518             break;
2519 
2520         case Sound_ENABL_Type_EaseVol:
2521             HAL_SOUND_EnableEaseVol(enable);
2522             status = TRUE;
2523             break;
2524 
2525         case Sound_ENABL_Type_HeadPhoneSoundEffect:
2526             HAL_AUDIO_WriteMaskReg(M2S_MBOX_SNDEFF_CTRL2, 1<<(M2S_MBOX_HEADPHONEPSND_CTRL_BIT), enable<<(M2S_MBOX_HEADPHONEPSND_CTRL_BIT));
2527             status = TRUE;
2528             break;
2529 
2530         default:
2531             status = FALSE;
2532             break;
2533     }
2534     return(status);
2535 }
2536 
2537 //******************************************************************************
2538 /// @brief \b Function \b Name: HAL_SND_SetParam()
2539 /// @brief \b Function \b Description: This routine is used for adjust Common Sound parameters
2540 /// @return MS_BOOL     \b : True / False
2541 //******************************************************************************
HAL_SND_SetParam(Sound_SET_PARAM_Type Type,MS_U16 param1,MS_U16 param2)2542 MS_BOOL HAL_SND_SetParam(Sound_SET_PARAM_Type Type, MS_U16 param1, MS_U16 param2)
2543 {
2544     MS_BOOL status = FALSE;
2545     MS_U16  data = 0;
2546 
2547     switch(Type)
2548     {
2549         case Sound_SET_PARAM_PreScale:
2550             HAL_SOUND_SetPreScale(param1, param2);      //param1: path, param2:prescale
2551             status = TRUE;
2552             break;
2553 
2554         case Sound_SET_PARAM_Balance:
2555             HAL_SOUND_SetBalance(param1);               // param1: balance 0~100
2556             status = TRUE;
2557             break;
2558 
2559         case Sound_SET_PARAM_AbsoluteBalance:
2560             HAL_SOUND_SetBalance_L((MS_U8)param1);             // param1: balance L  0x00(0dB)~0xFF(mute)
2561             HAL_SOUND_SetBalance_R((MS_U8)param2);             // param2: balance R  0x00(0dB)~0xFF(mute)
2562             status = TRUE;
2563             break;
2564 
2565         case Sound_SET_PARAM_Bass:
2566             HAL_SOUND_SetBass(param1);                  // param1: bass 0~100
2567             status = TRUE;
2568             break;
2569 
2570         case Sound_SET_PARAM_AbsoluteBass:              // absolute bass, param1: 0x30(+12dB)~0x00(0dB)~0xD0(-12dB)
2571             HAL_SOUND_AbsoluteBass(param1);
2572             status = TRUE;
2573             break;
2574 
2575         case Sound_SET_PARAM_Treble:
2576             HAL_SOUND_SetTreble(param1);                // param1: treble 0~100
2577             status = TRUE;
2578             break;
2579 
2580         case Sound_SET_PARAM_AbsoluteTreble:              // absolute treble, param1: 0x30(+12dB)~0x00(0dB)~0xD0(-12dB)
2581             HAL_SOUND_AbsoluteTreble(param1);
2582             status = TRUE;
2583             break;
2584 
2585         case Sound_SET_PARAM_EQ:
2586             HAL_SOUND_SetEq(param1, param2);            // param1: band 0~4, param2:level 0~100
2587             break;
2588 
2589         case Sound_SET_PARAM_AbsoluteEQ:                // absolute GEQ, param1: band 0~4, param2: 0x30(+12dB)~0x00(0dB)~0xD0(-12dB)
2590             if(param1 > 4)
2591             {
2592                 printf("Invalid value, GEQ Band should be 0~4\n");
2593             }
2594             else
2595             {
2596                 if ((param2 > 0x30) && (param2 <= 0x7F))
2597                 {
2598                     param2 = 0x30;
2599                 }
2600                 if ((param2 < 0xD0) && (param2 >= 0x80))
2601                 {
2602                     param2 = 0xD0;
2603                 }
2604                 HAL_AUDIO_WriteByte(REG_SOUND_EQ1 + (param1*2), (MS_U8)param2);
2605             }
2606             break;
2607 
2608         case Sound_SET_PARAM_Surround_XA:
2609             HAL_SOUND_SetSurroundXA(param1);
2610             status = TRUE;
2611             break;
2612 
2613         case Sound_SET_PARAM_Surround_XB:
2614             HAL_SOUND_SetSurroundXB(param1);
2615             status = TRUE;
2616             break;
2617 
2618         case Sound_SET_PARAM_Surround_XK:
2619             HAL_SOUND_SetSurroundXK(param1);
2620             status = TRUE;
2621             break;
2622 
2623         case Sound_SET_PARAM_Surround_LPFGAIN:
2624             HAL_SOUND_SetSurroundLPFGain(param1);
2625             status = TRUE;
2626             break;
2627 
2628         case Sound_SET_PARAM_NR_Threshold:
2629             HAL_SOUND_EnableNR((MS_U8)param1);      // param1: NR threshold: 0x00~0xFF
2630             status = TRUE;
2631             break;
2632 
2633         case Sound_SET_PARAM_Avc_Mode:
2634             HAL_SOUND_SetAvcMode(param1);
2635             status = TRUE;
2636             break;
2637 
2638         case Sound_SET_PARAM_Avc_Threshold:
2639             HAL_SOUND_SetAVCThreshold(param1);
2640             status = TRUE;
2641             break;
2642 
2643         case Sound_SET_PARAM_Avc_AT:
2644             HAL_SOUND_SetAvcAT(param1);
2645             status = TRUE;
2646             break;
2647 
2648         case Sound_SET_PARAM_Avc_RT:
2649             HAL_SOUND_SetAvcRT(param1);
2650             status = TRUE;
2651             break;
2652 
2653         case Sound_SET_PARAM_Drc_Threshold:
2654             HAL_SOUND_SetDRCThreshold(param1,(AUDIO_SOUNDEFFECT_TYPE)param2);
2655             status = TRUE;
2656             break;
2657 
2658         case Sound_SET_PARAM_AudioDelay:
2659             HAL_SOUND_SetCH1AudioDelay(param1);
2660             status = TRUE;
2661             break;
2662 
2663         case Sound_SET_PARAM_DCOffet:
2664             HAL_AUDIO_WriteByte(0x2B51, param1);
2665             HAL_AUDIO_WriteByte(0x2B50, param2);
2666             status = TRUE;
2667             break;
2668 
2669         case Sound_SET_PARAM_PEQ_48K_A0:
2670             if((param1>>8) > MAX_PEQ_BAND-1)
2671                 printf("PEQ paramater Band should be 0~4\n");
2672             else
2673                 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_peq48KCoeffAddr+(param1>>8)*5, ((param1&0xFF)<<16)+param2, DSP_MEM_TYPE_PM);
2674             break;
2675 
2676         case Sound_SET_PARAM_PEQ_48K_A1:
2677             if((param1>>8) > MAX_PEQ_BAND-1)
2678                 printf("PEQ paramater Band should be 0~4\n");
2679             else
2680                 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_peq48KCoeffAddr+(param1>>8)*5+1, ((param1&0xFF)<<16)+param2, DSP_MEM_TYPE_PM);
2681             break;
2682 
2683         case Sound_SET_PARAM_PEQ_48K_A2:
2684             if((param1>>8) > MAX_PEQ_BAND-1)
2685                 printf("PEQ paramater Band should be 0~4\n");
2686             else
2687                 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_peq48KCoeffAddr+(param1>>8)*5+2, ((param1&0xFF)<<16)+param2, DSP_MEM_TYPE_PM);
2688             break;
2689 
2690         case Sound_SET_PARAM_PEQ_48K_B1:
2691             if((param1>>8) > MAX_PEQ_BAND-1)
2692                 printf("PEQ paramater Band should be 0~4\n");
2693             else
2694                 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_peq48KCoeffAddr+(param1>>8)*5+3, ((param1&0xFF)<<16)+param2, DSP_MEM_TYPE_PM);
2695             break;
2696 
2697         case Sound_SET_PARAM_PEQ_48K_B2:
2698             if((param1>>8) > MAX_PEQ_BAND-1)
2699                 printf("PEQ paramater Band should be 0~4\n");
2700             else
2701                 HAL_MAD2_Write_DSP_sram(DSP2PmAddr_peq48KCoeffAddr+(param1>>8)*5+4, ((param1&0xFF)<<16)+param2, DSP_MEM_TYPE_PM);
2702             break;
2703 
2704         case Sound_SET_PARAM_PEQ_32K_A0:
2705             // No support 32K PEQ in T12
2706             break;
2707 
2708         case Sound_SET_PARAM_PEQ_32K_A1:
2709             // No support 32K PEQ in T12
2710             break;
2711 
2712         case Sound_SET_PARAM_PEQ_32K_A2:
2713             // No support 32K PEQ in T12
2714             break;
2715 
2716         case Sound_SET_PARAM_PEQ_32K_B1:
2717             // No support 32K PEQ in T12
2718             break;
2719 
2720         case Sound_SET_PARAM_PEQ_32K_B2:
2721             // No support 32K PEQ in T12
2722             break;
2723 
2724         case Sound_SET_PARAM_DMAReader:
2725             if(param1 == 0)
2726             {
2727                 if(param2 >= 4)
2728                 {
2729                     HAL_SOUND_SetMute(AUDIO_T3_PATH_MIXER_DMA_IN, true);
2730                 }
2731                 else
2732                 {
2733                     data = 0x0C + param2*4;
2734                     HAL_SOUND_AbsoluteVolume(AUDIO_T3_PATH_MIXER_DMA_IN,data,0);
2735                     HAL_SOUND_SetMute(AUDIO_T3_PATH_MIXER_DMA_IN, false);
2736                 }
2737                 status = TRUE;
2738             }
2739             break;
2740 
2741         case Sound_SET_PARAM_AVC_S_Offset:
2742             {
2743                 MS_U32 S_offset = 0x400000; // default offset: +6 dB, 3.21 format for DSP
2744                 if((param1 < 0) || (param1 > 12))
2745                 {
2746                     printf("AVC offset is out of range 0~12 dB \n");
2747                 }
2748                 else
2749                 {
2750                     S_offset = (MS_U32)AVC_SOffset_TBL[param1];
2751                 }
2752                 HAL_MAD2_Write_DSP_sram(DSP2DmAddr_AvcSOffsetAddr, S_offset, DSP_MEM_TYPE_DM);
2753                 status = TRUE;
2754                 break;
2755             }
2756 
2757         case Sound_SET_PARAM_Ease_Type_A:
2758         case Sound_SET_PARAM_Ease_Type_B:
2759         {
2760             MS_U32 u32EaseType = AUDIO_EASE_TYPE_LINEAR;
2761             MS_U32 u32DspPmEaseBase = 0;
2762 
2763             status = TRUE;
2764 
2765             switch (Type)
2766             {
2767                 case Sound_SET_PARAM_Ease_Type_A:
2768                 {
2769                     u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr;
2770                     break;
2771                 }
2772 
2773                 case Sound_SET_PARAM_Ease_Type_B:
2774                 {
2775                     u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr + 4;
2776                     break;
2777                 }
2778 
2779                 default:
2780                 {
2781                     HALSOUND_ERROR("%s: invalid audio ease command %d\n", __FUNCTION__, Type);
2782                     status = FALSE;
2783                     break;
2784                 }
2785             }
2786 
2787             switch (param1)
2788             {
2789                 case E_AUDIO_EASE_TYPE_LINEAR:
2790                 {
2791                     u32EaseType = AUDIO_EASE_TYPE_LINEAR;
2792                     break;
2793                 }
2794 
2795                 case E_AUDIO_EASE_TYPE_INCUBIC:
2796                 {
2797                     u32EaseType = AUDIO_EASE_TYPE_INCUBIC;
2798                     break;
2799                 }
2800 
2801                 case E_AUDIO_EASE_TYPE_OUTCUBIC:
2802                 {
2803                     u32EaseType = AUDIO_EASE_TYPE_OUTCUBIC;
2804                     break;
2805                 }
2806 
2807                 case E_AUDIO_EASE_TYPE_INOUTCUBIC:
2808                 {
2809                     u32EaseType = AUDIO_EASE_TYPE_INOUTCUBIC;
2810                     break;
2811                 }
2812 
2813                 default:
2814                 {
2815                     HALSOUND_ERROR("%s: invalid audio ease type %d\n", __FUNCTION__, param1);
2816                     status = FALSE;
2817                     break;
2818                 }
2819             }
2820 
2821             if (status == TRUE)
2822             {
2823                 HAL_MAD2_Write_DSP_sram((u32DspPmEaseBase + 2), u32EaseType, DSP_MEM_TYPE_PM);
2824             }
2825 
2826             break;
2827         }
2828 
2829         case Sound_SET_PARAM_Ease_Duration_A:
2830         case Sound_SET_PARAM_Ease_Duration_B:
2831         {
2832             MS_U32 u32MiniSecond = 0;
2833             MS_U32 u32SamplesOfMiniSecond = 0;
2834             MS_U32 u32DspPmEaseBase = 0;
2835 
2836             status = TRUE;
2837 
2838             switch (Type)
2839             {
2840                 case Sound_SET_PARAM_Ease_Duration_A:
2841                 {
2842                     u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr;
2843                     break;
2844                 }
2845 
2846                 case Sound_SET_PARAM_Ease_Duration_B:
2847                 {
2848                     u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr + 4;
2849                     break;
2850                 }
2851 
2852                 default:
2853                 {
2854                     HALSOUND_ERROR("%s: invalid audio ease command %d\n", __FUNCTION__, Type);
2855                     status = FALSE;
2856                     break;
2857                 }
2858             }
2859 
2860             if (status == TRUE)
2861             {
2862                 if (param1 > 60000)
2863                 {
2864                     HALSOUND_ERROR("%s: target duration (%d) of audio ease is too large!\n", __FUNCTION__, param1);
2865                     u32MiniSecond = 60000;
2866                 }
2867                 else
2868                 {
2869                     u32MiniSecond = (MS_U32)param1;
2870                 }
2871 
2872                 u32SamplesOfMiniSecond = u32MiniSecond * 48; /* samples of 1 ms in 48KHz */
2873                 HAL_MAD2_Write_DSP_sram((u32DspPmEaseBase + 1), u32SamplesOfMiniSecond, DSP_MEM_TYPE_PM);
2874             }
2875 
2876             break;
2877         }
2878 
2879         case Sound_SET_PARAM_Ease_Gain_A:
2880         case Sound_SET_PARAM_Ease_Gain_B:
2881         {
2882             MS_U32 u32Gain = 0;
2883             MS_U32 u32DspPmEaseBase = 0;
2884 
2885             status = TRUE;
2886 
2887             switch (Type)
2888             {
2889                 case Sound_SET_PARAM_Ease_Gain_A:
2890                 {
2891                     u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr;
2892                     break;
2893                 }
2894 
2895                 case Sound_SET_PARAM_Ease_Gain_B:
2896                 {
2897                     u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr + 4;
2898                     break;
2899                 }
2900 
2901                 default:
2902                 {
2903                     HALSOUND_ERROR("%s: invalid audio ease command %d\n", __FUNCTION__, Type);
2904                     status = FALSE;
2905                     break;
2906                 }
2907             }
2908 
2909             if (status == TRUE)
2910             {
2911                 u32Gain = (MS_U32)(((param1 & 0xFF) << 16) | (param2 & 0xFFFF));
2912                 if (u32Gain > 0x7FFFFF)
2913                 {
2914                     HALSOUND_ERROR("%s: target gain (0x%X) of audio ease is too large!\n", __FUNCTION__, (unsigned int)u32Gain);
2915                     u32Gain = 0x7FFFFF;
2916                 }
2917 
2918                 HAL_MAD2_Write_DSP_sram(u32DspPmEaseBase, u32Gain, DSP_MEM_TYPE_PM);
2919             }
2920 
2921             break;
2922         }
2923 
2924         case Sound_SET_PARAM_Ease_Target_Channel_A:
2925         case Sound_SET_PARAM_Ease_Target_Channel_B:
2926         {
2927             MS_U32 u32Mask = 0x000000;
2928             MS_U32 u32TargetChannel = AUDIO_EASE_CH_NONE;
2929             MS_U32 u32ChannelSetting = 0;
2930             MS_U32 u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr + 8;
2931 
2932             status = TRUE;
2933 
2934             if (param2 == TRUE)
2935             {
2936                 switch (Type)
2937                 {
2938                     case Sound_SET_PARAM_Ease_Target_Channel_A:
2939                     {
2940                         u32TargetChannel = AUDIO_EASE_CH_A;
2941                         break;
2942                     }
2943 
2944                     case Sound_SET_PARAM_Ease_Target_Channel_B:
2945                     {
2946                         u32TargetChannel = AUDIO_EASE_CH_B;
2947                         break;
2948                     }
2949 
2950                     default:
2951                     {
2952                         HALSOUND_ERROR("%s: invalid audio ease command %d\n", __FUNCTION__, Type);
2953                         status = FALSE;
2954                         break;
2955                     }
2956                 }
2957             }
2958             else
2959             {
2960                 u32TargetChannel = AUDIO_EASE_CH_NONE;
2961             }
2962 
2963             switch (param1)
2964             {
2965                 case AUDIO_PATH_4:
2966                 {
2967                     /* for Channel 5 */
2968                     u32Mask = 0x000F;
2969                     break;
2970                 }
2971 
2972                 case AUDIO_PATH_5:
2973                 {
2974                     /* for Channel 6 */
2975                     u32Mask = 0x0000F0;
2976                     u32TargetChannel <<= 4;
2977                     break;
2978                 }
2979 
2980                 case AUDIO_PATH_6:
2981                 {
2982                     /* for Channel 7 */
2983                     u32Mask = 0x000F00;
2984                     u32TargetChannel <<= 8;
2985                     break;
2986                 }
2987 
2988                 case AUDIO_PATH_7:
2989                 {
2990                     /* for Channel 8 */
2991                     u32Mask = 0x00F000;
2992                     u32TargetChannel <<= 12;
2993                     break;
2994                 }
2995 
2996                 case AUDIO_PATH_0:
2997                 {
2998                     /* for Channel 1~4 (Multi-Channel) */
2999                     u32Mask = 0x0F0000;
3000                     u32TargetChannel <<= 16;
3001                     break;
3002                 }
3003 
3004                 default:
3005                 {
3006                     HALSOUND_ERROR("%s: invalid audio ease path %d\n", __FUNCTION__, param1);
3007                     status = FALSE;
3008                     break;
3009                 }
3010             }
3011 
3012             if (status == TRUE)
3013             {
3014                 u32ChannelSetting = HAL_MAD2_Read_DSP_sram(u32DspPmEaseBase, DSP_MEM_TYPE_PM);
3015                 u32ChannelSetting = (u32ChannelSetting & (~u32Mask)) | u32TargetChannel;
3016                 HAL_MAD2_Write_DSP_sram(u32DspPmEaseBase, u32ChannelSetting, DSP_MEM_TYPE_PM);
3017             }
3018 
3019             break;
3020         }
3021 
3022         case Sound_SET_PARAM_Drc_Entry:
3023         {
3024             HAL_SOUND_SetDRCEntry((AUDIO_SOUNDEFFECT_TYPE) param1,(MS_U8)param2);
3025             status = TRUE;
3026 	        break;
3027         }
3028 
3029         case Sound_SET_PARAM_VolFadingStep:
3030         {
3031             HAL_MAD2_Write_DSP_sram(DSP2PmAddr_VolFadingStep1, param1<<8, DSP_MEM_TYPE_PM);
3032             HAL_MAD2_Write_DSP_sram(DSP2PmAddr_VolFadingStep2, param2<<8, DSP_MEM_TYPE_PM);
3033             status = TRUE;
3034             break;
3035         }
3036 
3037         case Sound_SET_PARAM_VolFadingCtrl:
3038         {
3039             HAL_MAD2_Write_DSP_sram(DSP2PmAddr_VolFadingCtrl, param1 , DSP_MEM_TYPE_PM);
3040             status = TRUE;
3041             break;
3042         }
3043 
3044         case Sound_SET_PARAM_BalanceMask:
3045         {
3046             HAL_SOUND_SetBalanceMask(param1, param2);
3047             status = TRUE;
3048             break;
3049         }
3050 
3051         case Sound_SET_PARAM_PhaseShiftMask:
3052         {
3053             HAL_SOUND_SetOutputPhaseShiftMask(param1, param2);
3054             status = TRUE;
3055             break;
3056         }
3057 
3058         default:
3059             status = FALSE;
3060             break;
3061     }
3062     return(status);
3063 }
3064 
3065 //******************************************************************************
3066 /// @brief \b Function \b Name: HAL_AUDIO_SOUND_SetParam()
3067 /// @brief \b Function \b Description: This routine is used for adjust Common Sound parameters
3068 /// @return MS_BOOL     \b : True / False
3069 //******************************************************************************
HAL_SND_GetParam(Sound_GET_PARAM_Type Type,MS_U16 param1)3070 MS_U16 HAL_SND_GetParam( Sound_GET_PARAM_Type Type, MS_U16 param1)
3071 {
3072     MS_U16 tmp=0;
3073     switch(Type)
3074     {
3075         case Sound_GET_PARAM_PreScale:
3076             tmp = HAL_SOUND_GetPreScale(param1);                           //param1: path
3077             break;
3078 
3079         case Sound_GET_PARAM_Balance_L:
3080             tmp = HAL_SOUND_GetBalance_L();                                // 0~0xFF
3081             break;
3082 
3083         case Sound_GET_PARAM_Balance_R:
3084             tmp = HAL_SOUND_GetBalance_R();                                // 0~0xFF
3085             break;
3086 
3087         case Sound_GET_PARAM_EQ:
3088            tmp = HAL_SOUND_GetEq(param1);                                  //param1: band 0~4
3089             break;
3090 
3091         case Sound_GET_PARAM_Surround_XA:
3092             tmp = HAL_SOUND_GetSurroundXA();
3093             break;
3094 
3095         case Sound_GET_PARAM_Surround_XB:
3096             tmp = HAL_SOUND_GetSurroundXB();
3097             break;
3098 
3099         case Sound_GET_PARAM_Surround_XK:
3100             tmp = HAL_SOUND_GetSurroundXK();
3101             break;
3102 
3103         case Sound_GET_PARAM_Surround_LPFGAIN:
3104             tmp = HAL_SOUND_GetSurroundLPFGain();
3105             break;
3106 
3107         case Sound_GET_PARAM_Treble:
3108             tmp = HAL_SOUND_GetTreble();
3109             break;
3110 
3111         case Sound_GET_PARAM_Bass:
3112             tmp = HAL_SOUND_GetBass();
3113             break;
3114 
3115         case Sound_GET_PARAM_Avc_Mode:
3116             tmp = HAL_SOUND_GetAvcMode();
3117             break;
3118 
3119         case Sound_GET_PARAM_Avc_Threshold:
3120             tmp = HAL_SOUND_GetAVCThreshold();
3121             break;
3122 
3123         case Sound_GET_PARAM_Avc_AT:
3124             tmp = HAL_SOUND_GetAvcAT();
3125             break;
3126 
3127         case Sound_GET_PARAM_Avc_RT:
3128             tmp = HAL_SOUND_GetAvcRT();
3129             break;
3130 
3131         case Sound_GET_PARAM_AudioDelay:
3132             tmp = HAL_SOUND_GetCH1AudioDelay();
3133             break;
3134 
3135         case Sound_GET_PARAM_DCOffet:
3136             tmp = HAL_AUDIO_ReadByte(0x2B51);
3137             tmp = ((MS_U16)HAL_AUDIO_ReadByte(0x2B50) |(tmp<<8));
3138             break;
3139 
3140         case Sound_GET_PARAM_NR_Threshold:
3141             tmp = HAL_AUDIO_ReadByte(0x2D24);
3142             break;
3143 
3144         case Sound_GET_PARAM_NR_Status:
3145            // tmp = (HAL_AUDIO_ReadByte(0x2A78) & 0x01);
3146             break;
3147 
3148         case Sound_GET_PARAM_getSignal_Energy:
3149           //  tmp = HAL_MAD_Read_DSP_sram(0x3F2B, DSP_MEM_TYPE_DM);
3150             break;
3151 
3152         case Sound_GET_PARAM_EQ_Status:
3153             tmp = HAL_SOUND_GetEQ_Status();
3154             break;
3155 
3156         case Sound_GET_PARAM_PEQ_Status:
3157             tmp = HAL_SOUND_GetPEQ_Status();
3158             break;
3159 
3160         case Sound_GET_PARAM_Tone_Status:
3161             tmp = HAL_SOUND_GetTone_Status();
3162             break;
3163 
3164         case Sound_GET_PARAM_AutoVolume_Status:
3165             tmp = HAL_SOUND_GetAutoVolume_Status();
3166             break;
3167 
3168         case Sound_GET_PARAM_Surround_Status:
3169             tmp = HAL_SOUND_GetSurround_Status();
3170             break;
3171 
3172         case Sound_GET_PARAM_Drc_Threshold:
3173             tmp = HAL_SOUND_GetDRCThreshold();
3174             break;
3175 
3176         case Sound_GET_PARAM_DMAReader_Buffer_Addr:
3177             tmp = (MS_U16)(DMA_READER_TEMP_BUFFER_ADDR>>8);
3178             break;
3179 
3180         case Sound_GET_PARAM_Ease_Type_A:
3181         case Sound_GET_PARAM_Ease_Type_B:
3182         {
3183             MS_U32 u32EaseType = AUDIO_EASE_TYPE_LINEAR;
3184             MS_U32 u32DspPmEaseBase = 0;
3185 
3186             switch (Type)
3187             {
3188                 case Sound_GET_PARAM_Ease_Type_A:
3189                 {
3190                     u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr;
3191                     break;
3192                 }
3193 
3194                 case Sound_GET_PARAM_Ease_Type_B:
3195                 {
3196                     u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr + 4;
3197                     break;
3198                 }
3199 
3200                 default:
3201                 {
3202                     u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr;
3203                     break;
3204                 }
3205             }
3206 
3207             u32EaseType = HAL_MAD2_Read_DSP_sram((u32DspPmEaseBase + 2), DSP_MEM_TYPE_PM);
3208 
3209             switch (u32EaseType)
3210             {
3211                 case AUDIO_EASE_TYPE_LINEAR:
3212                 {
3213                     tmp = E_AUDIO_EASE_TYPE_LINEAR;
3214                     break;
3215                 }
3216 
3217                 case AUDIO_EASE_TYPE_INCUBIC:
3218                 {
3219                     tmp = E_AUDIO_EASE_TYPE_INCUBIC;
3220                     break;
3221                 }
3222 
3223                 case AUDIO_EASE_TYPE_OUTCUBIC:
3224                 {
3225                     tmp = E_AUDIO_EASE_TYPE_OUTCUBIC;
3226                     break;
3227                 }
3228 
3229                 case AUDIO_EASE_TYPE_INOUTCUBIC:
3230                 {
3231                     tmp = E_AUDIO_EASE_TYPE_INOUTCUBIC;
3232                     break;
3233                 }
3234 
3235                 default:
3236                 {
3237                     HALSOUND_ERROR("%s: invalid audio ease type %u\n", __FUNCTION__, (unsigned int)u32EaseType);
3238                     break;
3239                 }
3240             }
3241 
3242             break;
3243         }
3244 
3245         case Sound_GET_PARAM_Ease_Duration_A:
3246         case Sound_GET_PARAM_Ease_Duration_B:
3247         {
3248             MS_U32 u32MiniSecond = 0;
3249             MS_U32 u32DspPmEaseBase = 0;
3250 
3251             switch (Type)
3252             {
3253                 case Sound_GET_PARAM_Ease_Duration_A:
3254                 {
3255                     u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr;
3256                     break;
3257                 }
3258 
3259                 case Sound_GET_PARAM_Ease_Duration_B:
3260                 {
3261                     u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr + 4;
3262                     break;
3263                 }
3264 
3265                 default:
3266                 {
3267                     u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr;
3268                     break;
3269                 }
3270             }
3271 
3272             u32MiniSecond = HAL_MAD2_Read_DSP_sram((u32DspPmEaseBase + 1), DSP_MEM_TYPE_PM) / 48;
3273             tmp = (MS_U16)u32MiniSecond;
3274 
3275             break;
3276         }
3277 
3278         case Sound_GET_PARAM_Ease_Gain_A:
3279         case Sound_GET_PARAM_Ease_Gain_B:
3280         {
3281             MS_U32 u32Value;
3282             MS_U32 u32DspPmEaseBase = 0;
3283 
3284             switch (Type)
3285             {
3286                 case Sound_GET_PARAM_Ease_Gain_A:
3287                 {
3288                     u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr;
3289                     break;
3290                 }
3291 
3292                 case Sound_GET_PARAM_Ease_Gain_B:
3293                 {
3294                     u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr + 4;
3295                     break;
3296                 }
3297 
3298                 default:
3299                 {
3300                     u32DspPmEaseBase = DSP2PmAddr_VolEaseAddr;
3301                     break;
3302                 }
3303             }
3304 
3305             u32Value = HAL_MAD2_Read_DSP_sram((u32DspPmEaseBase + 3), DSP_MEM_TYPE_PM);
3306             tmp = (MS_U16)(u32Value >> 8);
3307 
3308             break;
3309         }
3310 
3311         default:
3312             break;
3313     }
3314     return tmp;
3315 
3316 }
3317 
3318 
3319