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