source: svn/trunk/zas_dstar/devices/Audio/STV82x8/STV82x8.c @ 2

Last change on this file since 2 was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
File size: 161.8 KB
Line 
1/****************************************************************************/
2/*                                                                          */
3/*           Copyright (c) 2003 Trident Technologies, Inc.                  */
4/*                       All rights reserved                                */
5/*                                                                          */
6/* The content of this file or document is CONFIDENTIAL and PROPRIETARY     */
7/* to Trident Microsystems, Inc.  It is subject to the terms of a           */
8/* License Agreement between Licensee and Trident Technologies, Inc.        */
9/* restricting among other things, the use, reproduction, distribution      */
10/* and transfer.  Each of the embodiments, including this information and   */
11/* any derivative work shall retain this copyright notice                   */
12/*                                                                          */
13/****************************************************************************/
14/******************************************************************************
15COPYRIGHT (C) ISD ST 2005
16
17-  File name                    STV82X8.c
18-. Creation date                18/May/2005
19-. Author Name                  MS Song ( e.g   ST-Korea )
20-. History
21        Version 1.0.0           18/May/2005
22        Compile                         Under visual C++
23
24        Version 1.0.1           10/Jun/2005
25        Add
26                                        STV82x8_SetScartVolumeMode()
27                                        STV82x8_SetHPBalance()
28                                        STV82x8_SetHPConfiguration()
29                                        STV82x8_GetHPStatus()
30                                        STV82x8_SetPinkNoiseGenerator()
31                                        STV82x8_SetSubWoofer()
32                                        STV82x8_SetI2SInOut()
33                                        STV82x8_SetI2SOutputSignal()
34                                        STV82x8_SetSRS_InputMode()
35                                        STV82x8_SetSRS_TRUBASS()
36                                        STV82x8_SetDynamicBass()
37                                        STV82x8_SetAVDelay()
38
39        Modify
40                                        STV82x8_Initialize()
41                                        STV82x8_UpdatePatchData()
42                                        STV82x8_SetLeftVolume()
43                                        STV82x8_SetRightVolume()
44                                        STV82x8_SetCenterVolume()
45                                        STV82x8_SetSurroundLeftVolume()
46                                        STV82x8_SetSurroundRightVolume()
47                                        STV82x8_SetHPLeftVolume()
48                                        STV82x8_SetHPRightVolume()
49                                        STV82x8_SetMasterVolume()
50                                        STV82x8_SetLSBalance()
51                                        STV82x8_ControlTurboSound()
52                                        STV82x8_AutoVolumeCtrl()
53                                        STV82x8_CheckElectricalShock()
54                                        STV82x8_GetSoundSignalState()
55                                        ttucPatchV13h
56
57        Remove
58                                        STV82x8_Set_I2SOut()
59
60        Version 1.0.2           15/Jun/2005
61        Modify
62                                        ttucPatchV14h
63
64        Version 1.0.3           17/Jun/2005
65        Add
66                                        STV82x8_SetDefaultValueFromSTDConfig
67        Modify
68                                        ttucPatchV15h
69                                        STV82x8_SwReset
70                                        STV82x8_InitDSP
71                                        STV82x8_SetSubWoofer
72                                        STV82x8_SetMonoStereoDefaultPrescale
73                                        STV82x8_SetPseudoEffect
74                                        STV82x8_SetSRSEffect
75                                        STV82x8_ControlTurboSound
76                                        STV82x8_SetOutput_RFConfig
77                                        STV82x8_SetInOutput_ScartConfig
78                                        STV82x8_AudioMatrix_LSOut
79                                        STV82x8_Control_ChannelMatrixLS
80                                        STV82x8_Set_SPDIFOut
81                                        STV82x8_ForcedMono
82                                        STV82x8_ReturnToStereoFromMono
83                                        STV82x8_PlayBeeperSound
84                                        STV82x8_All_SoundSystem_Check
85
86        Version 1.0.4           29/Jun/2005
87
88        Modify
89                                        STV82x8_AutoVolumeCtrl
90                                        STV82x8_InitRegister
91                                        STV82x8_GetSoundSystem
92                                        STV82x8_SetAVDelay
93
94        Version 1.0.5           16/Sep/2005
95
96        Add
97                                        VOLUME_TABLE1
98                                        BEEPER_DURATION_TABLE_1
99                                        BEEPER_FREQ_VOL_TABLE_1
100                                        BEEPER_DURATION_TABLE_2
101                                        BEEPER_FREQ_VOL_TABLE_2
102                                        STV82x8_SetValueForSPDIF
103                                        STV82x8_BeeperAmbulanceSound
104                                        STV82x8_GetSoundSystem_Independ
105                                        STV82x8_ChangeMTS_Manual
106                                        STV82x8_SetStereoTimeOut
107                                        STV82x8_SetScartDACMute
108                                        STV82x8_SetScartDACUnMute
109                                        STV82x8_SetLeftScartVolume
110                                        STV82x8_SetRightScartVolume
111                                        STV82x8_ScartOutBalance
112                                        STV82x8_SetSRSWOW_Effect
113                                        STV82x8_SetSRSTRS_DolbyPro1_Effect
114
115        Delete
116                                        STV82x8_SetScart2DigitalMute
117                                        STV82x8_SetScart2DigitalUnMute
118                                        STV82x8_SetSRSGain
119                                        STV82x8_SetSRSEffect
120
121        Modify
122                                        ttucPatchV18h
123                                        STV82x8_GetSoundSignalState
124                                        STV82x8_SetDefaultValueFromSTDConfig
125                                        STV82x8_SetSubWoofer
126                                        STV82x8_SetPseudoEffect
127                                        STV82x8_SetSRS_InputMode
128                                        STV82x8_PlayBeeperSound
129
130
131-. Description
132        This driver contains the code of the API functions for STV82x8 and
133        is working for 8bit micom, not relate to ST20.
134        The driver will be built according to the value of the target platform as defined by the each
135        STV82x8 families.
136        For AGC_GAIN, this value has to be adjusted on the each chassis.
137*************************************************************************************/
138//////////////////////////////////////////////////////////////////////////////////////
139//
140// $Log: STV82x8.c,v $
141// Revision 1.1  2011/07/08 03:43:14  megakiss
142// *** empty log message ***
143//
144// Revision 1.1.1.1  2009/01/09 03:18:18  hwatk
145// DSTHAL Base Skeleton, which is imported at 2009.01.09.
146//
147// Revision 1.1.1.1  2008/01/08 23:40:21  jhkoh
148// first release
149//
150// Revision 1.4  2007/04/02 11:36:08  jhkoh
151// audio °ü·Ã Ãß°¡.
152//
153// Revision 1.3  2007/03/22 11:51:34  hwatk
154// H0_13
155//
156// - Resolution Á¤º¸ °ü·Ã.
157//    . DHL_CAP_PresetCallback() ÇÔ¼ö ÂüÁ¶.
158// - DDM70 ES Board °ü·Ã
159//    . ¸ðµç Video ÀÔ·Â ±â´É È®ÀÎ (CVBS0/1, SVIDEO0/1, VGA, HDMI0/1)
160//
161// Revision 1.2  2007/03/22 11:50:29  hwatk
162// H0_13
163//
164// - Resolution Á¤º¸ °ü·Ã.
165//    . DHL_CAP_PresetCallback() ÇÔ¼ö ÂüÁ¶.
166// - DDM70 ES Board °ü·Ã
167//    . ¸ðµç Video ÀÔ·Â ±â´É È®ÀÎ (CVBS0/1, SVIDEO0/1, VGA, HDMI0/1)
168//
169// Revision 1.1  2007/02/23 13:42:55  hwatk
170// H0_10
171//
172// Revision 1.29  2006/09/27 05:16:22  blance
173// Update init interface
174//
175// Revision 1.28  2006/09/13 23:45:01  teresa
176// add i2c_num parameter, since different project connect different i2c number
177//
178// Revision 1.27  2006/09/13 10:22:06  blance
179// Add ext func.
180//
181// Revision 1.26  2006/09/08 09:16:33  blance
182// Add audio path switch.
183//
184// Revision 1.25  2006/09/07 03:58:12  blance
185// Update from Wistron.
186//
187// Revision 1.24  2006/09/05 00:59:14  blance
188// Update from Wistron.
189//
190// Revision 1.23  2006/09/01 09:48:21  blance
191// Add for extend routines.
192//
193// Revision 1.22  2006/08/14 21:25:15  teresa
194// for fast boot, to yield
195//
196// Revision 1.21  2006/08/05 22:37:32  teresa
197// for second I2c support. It's temp, we may need pass parameters in VDL to decide first or second I2C.
198//
199// Revision 1.20  2006/08/01 23:27:47  simon
200// fix careless bug when doing mask in mute function
201//
202// Revision 1.19  2006/08/01 22:17:37  simon
203// fix SAP problem and address SPDIF mute problem
204// for external path
205//
206// Revision 1.18  2006/07/29 02:30:42  simon
207// add headphone output matix in I2S and Scart output routines
208//
209// Revision 1.17  2006/07/28 23:47:08  simon
210// fix headphone problem, add subwoofer, and av selection
211//
212// Revision 1.16  2006/07/18 20:21:18  teresa
213// comment out some new modification temporaly, since it will cause no audio output.
214//
215// Revision 1.15  2006/07/18 02:54:04  teresa
216// *** empty log message ***
217//
218// Revision 1.14  2006/07/17 09:07:54  simon
219// 1. add dialog, trubass level for LS and Headphone
220// 2. support turbass on headphone
221//
222// Revision 1.13  2006/07/17 08:12:23  simon
223// 1. add headphone control
224// 2. enable Smart Vol. control for Loudspeaker and Headphone
225// 3. add ST Wide Surround Mode
226//
227// Revision 1.12  2006/07/13 09:10:06  simon
228// careless mistake: use mask write function instead of
229// over write function.
230//
231// Revision 1.11  2006/07/13 08:40:28  simon
232// add function to set each sound mode
233//
234// Revision 1.10  2006/07/13 00:09:37  teresa
235// 1. Fix SAP channel on left channel
236// 2. More SPDIF out fix
237//
238// Revision 1.9  2006/07/04 02:36:51  simon
239// 1. add I2S prescale for each I2S input
240// 2. change sound system detection
241// 3. set default timeout for stereo
242//
243// Revision 1.8  2006/07/03 23:52:54  simon
244// set I2S prescale equal to analog gain
245//
246// Revision 1.7  2006/07/03 20:50:53  simon
247// fix multi-defination problem
248//
249// Revision 1.6  2006/07/03 17:57:56  simon
250// fix SRS input mode and move balance table to header file
251//
252// Revision 1.5  2006/06/27 20:26:15  teresa
253// NO audio sound fix
254//
255// Revision 1.4  2006/06/23 23:38:42  simon
256// 1. add auto mute if no signal
257// 2. add mute all fucntion
258// 3. add bass and treble gain on Loud Speaker
259//
260// Revision 1.3  2006/06/21 22:41:44  simon
261// make code readable and following our coding standard
262//
263//
264//////////////////////////////////////////////////////////////////////////////////////
265
266
267/***********************************************************************************
268 *                                   Header files
269 **********************************************************************************/
270#include "stdio.h"
271#include "stdlib.h"
272#include "unistd.h"
273#include <sys/types.h>
274#include <sys/ioctl.h>
275#include <sys/socket.h>
276#include <sys/stat.h>
277#include <sys/time.h>
278#include <linux/types.h>
279#include <linux/ioctl.h>
280#include <fcntl.h>
281#include "i2c.h"
282#include "typedef.h"
283#include "sysdef.h"
284#include "stv82x8_reg.h"
285#include "patch.h"
286
287
288//#define SECOND_I2C
289//#define __STV_DEBUG__
290/***********************************************************************************
291 *                                  Global variables
292 **********************************************************************************/
293static INT      gSTV82x8_i2cfd = 0;         
294static unsigned char    gSlaveAddr = 0x80;          // default
295static unsigned char    gI2C_num = 0;                           //defult use first I2C.
296
297#if 0   // not reference now
298static USHORT  VOLUME_TABLE1[] =
299{
300        0x5500,0x5C00,0x6400,0x6C00,0x7400,0x7C00,0x8300,0x8900,0x8F00,0x9500,  //2  0.5~9.5
301        0x9A00,0x9E00,0xA200,0xA600,0xAA00,0xAE00,0xB000,0xB100,0xB300,0xB500,  //2 10.5~19.5
302        0xB700,0xB900,0xBB00,0xBD00,0xBF00,0xC100,0xC300,0xC480,0xC580,0xC680,  //2 20.5~29.5
303        0xC780,0xC880,0xC980,0xCA80,0xCB80,0xCC80,0xCD80,0xCE80,0xCF80,0xD080,  //2 30.5~39.5
304        0xD180,0xD280,0xD380,0xD480,0xD580,0xD680,0xD701,0xD781,0xD801,0xD881,  //2 40.5~49.5
305        0xD901,0xD981,0xDA01,0xDA81,0xDB01,0xDB81,0xDC01,0xDC81,0xDD01,0xDD81,  //2 50.5~59.5
306        0xDE01,0xDE81,0xDF01,0xDF81,0xE001,0xE081,0xE101,0xE181,0xE200,0xE201,  //2 60.5~69.5
307        0xE202,0xE281,0xE300,0xE301,0xE302,0xE381,0xE400,0xE401,0xE402,0xE481,  //2 70.5~79.5
308        0xE500,0xE501,0xE502,0xE581,0xE600,0xE601,0xE602,0xE681,0xE700,0xE701,  //2 80.5~89.5
309        0xE702,0xE781,0xE800,0xE801,0xE802,0xE881,0xE900,0xE901,0xE902,0xE903,  //2 90.5~99.5
310};
311
312
313
314static unsigned char BEEPER_OFF_TABLE[9] =  { 0xC5, 0xA5, 0x85, 0x65, 0x46, 0x44, 0x42, 0x40, 0x40 };
315static unsigned char BEEPER_DURATION_TABLE_2[10] =  { 0x13, 0x13, 0x13, 0x13, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x73 };
316static unsigned char BEEPER_FREQ_VOL_TABLE_2[10] =  { 0x74, 0x94, 0x74, 0x94, 0x54, 0x74, 0x54, 0x34, 0x54, 0x14 };
317
318#endif
319
320
321USHORT VOLUME_TABLE[] =
322{
323    0x5200,0x5800,0x6000,0x6800,0x7000,0x7800,0x8000,0x8600,0x8C00,0x9200,  //2 0~9
324    0x9800,0x9C00,0xA000,0xA400,0xA800,0xAC00,0xB000,0xB000,0xB200,0xB400,  //2 10~19
325    0xB600,0xB800,0xBA00,0xBC00,0xBE00,0xC000,0xC200,0xC400,0xC500,0xC600,  //2 20~29
326    0xC700,0xC800,0xC900,0xCA00,0xCB00,0xCC00,0xCD00,0xCE00,0xCF00,0xD000,  //2 30~39
327    0xD100,0xD200,0xD300,0xD400,0xD500,0xD600,0xD700,0xD702,0xD800,0xD802,  //2 40~49
328    0xD900,0xD902,0xDA00,0xDA02,0xDB00,0xDB02,0xDC00,0xDC02,0xDD00,0xDD02,  //2 50~59
329    0xDE00,0xDE02,0xDF00,0xDF02,0xE000,0xE002,0xE100,0xE102,0xE200,0xE201,  //2 60~69
330    0xE202,0xE203,0xE300,0xE301,0xE302,0xE303,0xE400,0xE401,0xE402,0xE403,  //2 70~79
331    0xE500,0xE501,0xE502,0xE503,0xE600,0xE601,0xE602,0xE603,0xE700,0xE701,  //2 80~89
332    0xE702,0xE703,0xE800,0xE801,0xE802,0xE803,0xE900,0xE901,0xE902,0xE903,  //2 90~100
333    0xEA00
334};
335INT gSizeofVolumeTable = sizeof(VOLUME_TABLE)/sizeof(VOLUME_TABLE[0]);
336
337unsigned char BASS_TREBLE_GAIN_TABLE[] =
338{
339    0xB0,0xAF,0xAE,0xAD,0xAC,0xAB,0xAA,0xA9,0xA8,0xA7,0xA6,0xA5,0xA4,0xA3,0xA2,0xA1,    // 0xB0 = -12 db
340    0xA0,0x9F,0x9E,0x9D,0x9C,0x9B,0x9A,0x99,0x98,0x97,0x96,0x95,0x94,0x93,0x92,0x91,
341    0x80,0x7F,0x7E,0x7D,0x7C,0x7B,0x7A,0x79,0x78,0x77,0x76,0x75,0x74,0x73,0x72,0x71,
342    0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
343    0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
344    0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
345    0x30                                                                                // 0x30 = 12 db
346};
347INT gSizeOfBassTrebleTable = sizeof(BASS_TREBLE_GAIN_TABLE)/sizeof(BASS_TREBLE_GAIN_TABLE[0]);
348
349
350unsigned char BALANCE_TABLE[] =
351{
352    0x80,0x82,0x84,0x86,0x88,0x8A,0x8B,0x8C,0x8D,0x8E,
353    0xC0,0xC2,0xC4,0xC6,0xC8,0xCA,0xCB,0xCC,0xCD,0xCE,
354    0xD0,0xD2,0xD4,0xD6,0xD8,0xDA,0xDB,0xDC,0xDD,0xDE,
355    0xE0,0xE2,0xE4,0xE6,0xE8,0xEA,0xEB,0xEC,0xED,0xEE, 
356    0xF0,0xF2,0xF4,0xF6,0xF8,0xFA,0xFB,0xFC,0xFD,0xFE,
357    0x00,
358    0x02,0x04,0x06,0x07,0x08,0x0A,0x0B,0x0C,0x0D,0x0E,
359    0x12,0x14,0x16,0x17,0x18,0x1A,0x1B,0x1C,0x1D,0x1E,
360    0x22,0x24,0x26,0x27,0x28,0x2A,0x2B,0x2C,0x2D,0x2E,
361    0x32,0x34,0x36,0x37,0x38,0x3A,0x3B,0x3C,0x3D,0x3E,
362    0x72,0x74,0x76,0x77,0x78,0x7A,0x7B,0x7C,0x7D,0x7F   
363};
364INT gSizeOfBalanceTable = sizeof(BALANCE_TABLE)/sizeof(BALANCE_TABLE[0]);
365
366static unsigned char EQUALIZER_TABLE[] =
367{
368        0xDA,0xDC,0xDE,0xE0,0xE4,0xE8,0xEC,0xF0,0xF4,0xF8,0xFC,                 //2 11step
369        0x00,
370        0x04,0x08,0x0C,0x10,0x14,0x18,0x1C,0x20,0x22,0x24,0x26,0x28             //2 12step
371};
372
373// Forbbiden to set Beeper Volume as 0 during Beeper on
374static unsigned char BEEPER_ON_TABLE[9] =  { 0x45, 0x65, 0x85, 0x65, 0x85, 0xA6, 0xA4, 0xA2, 0xA0 };
375static unsigned char BEEPER_DURATION_TABLE_1[9] =  { 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x7b };
376static unsigned char BEEPER_FREQ_VOL_TABLE_1[9] =  { 0x74, 0x94, 0x74, 0x94, 0x74, 0x94, 0x74, 0x94, 0x74 };
377static unsigned char LOUDNESS_TABLE[] ={ 0, 1, 2, 3, 4, 5, 6, 7 };  //2 8 step
378static unsigned char gCurSPDIFInput = 0;
379//static unsigned char gCurSPDIFOut = 0;
380
381
382
383/**********************************************************************************
384 *                         Internal Function Prototype
385 *********************************************************************************/
386VOID    Delay_msec(UINT msec);
387unsigned char   PIO_SetLow( VOID );
388unsigned char   PIO_SetHigh( VOID );
389unsigned char   I2cWriteSTV82x8(unsigned char ucSubAddress, unsigned char ucData);
390unsigned char   I2cReadSTV82x8(unsigned char ucSubAddress, unsigned char * pucData );
391unsigned char   STV82x8_DataMaskWrite( unsigned char ADDRESS, unsigned char DATA, unsigned char MASK_DATA );
392
393
394/**********************************************************************************
395 * Function:
396 *  VOID Delay_msec(UINT msec)
397 * Description:
398 *  Delay milliseconds
399 * Input:
400 *  UINT: in unit of msec.
401 * Return:
402 *  None
403 *********************************************************************************/
404VOID Delay_msec(UINT uiMillSec)
405{
406#if 0
407        UINT    i;
408        struct timeval tt;
409   
410        for(i=0; i< uiMillSec; i++)
411        {
412                tt.tv_sec = 0;
413                tt.tv_usec = 1000;
414        //maybe interrupted, so the real delay time is smaller than desired one
415        select(0, 0, 0, 0, &tt);
416        }
417#else
418        usleep( uiMillSec * 1000 );
419#endif
420}
421
422
423
424
425/**********************************************************************************
426 * Function:
427 *  unsigned char STV82x8_OpenDevice(unsigned char i2c_num,unsigned char ucSubAddr)
428 * Description:
429 *  This function would open the I2C file descriptor for its audio device
430 * Input:
431 *  unsigned char i2c_num:  the first I2C(0) or second I2C(1)
432 *  unsigned char ucSubAddr: the I2C address
433 * Return:
434 *  STV82X8_I2C_ERROR = I2C's communication is failed.
435 *  STV82X8_NO_ERROR = successfully open the device
436 *********************************************************************************/
437unsigned char STV82x8_OpenDevice(unsigned char i2c_num,unsigned char ucSubAddr)
438{
439    INT     nRet;
440    unsigned char   ucResult = STV82X8_NO_ERROR;   
441 
442        gSlaveAddr = ucSubAddr;
443        gI2C_num = i2c_num;
444       
445    // check for I2C file descriptor for audio device
446        if(gSTV82x8_i2cfd)
447        return ucResult;
448#if 0
449        if((gSTV82x8_i2cfd = open("/tmp/i2c-1", O_RDWR))<0)
450#else           
451        if((gSTV82x8_i2cfd = open("/dev/i2c-0", O_RDWR))<0)
452#endif 
453        {
454        gSTV82x8_i2cfd = 0;
455        TRACE0(("Open I2c device failed\n"));
456        return STV82X8_I2C_ERROR;
457        }
458        printf("OPEN SUCCESS\n");
459
460#if 0
461    // can we communicate with the device ?
462        if((nRet = ioctl(gSTV82x8_i2cfd, I2C_SLAVE, ucSubAddr>>1)) < 0)
463        {
464                close(gSTV82x8_i2cfd);
465                gSTV82x8_i2cfd = 0;
466                TRACE0(("Open I2C IOCTL failed\n"));
467                return STV82X8_I2C_ERROR;
468        }
469#else
470        nRet=0;
471#endif
472
473        return ucResult;
474}
475
476
477
478/**********************************************************************************
479 * Function:
480 *  unsigned char STV82x8_CloseDevice(VOID)
481 * Description:
482 *  This function would close the I2C file descriptor for its audio device
483 * Input:
484 *  None
485 * Return:
486 *  STV82X8_NO_ERROR = successfully close the device
487 *********************************************************************************/
488unsigned char STV82x8_CloseDevice(VOID)
489{
490        if(gSTV82x8_i2cfd)
491        {
492                close(gSTV82x8_i2cfd);
493                gSTV82x8_i2cfd = 0;
494        }
495        return STV82X8_NO_ERROR;
496}
497
498
499
500
501/******************************************************************************
502 * Function:
503 *  unsigned char STV82x8_Initialize(unsigned char ucSlaveAddr)
504 * Description:
505 *  Main S/W has to initialize STV82x8 as bellow
506 *  1) It must be executed Hardware reset the device with [pin43].
507 *      2) It must send patch data[ttucPatchVa] to STV82x8 through i2c:
508 *     Patch datas are written by the {address, value} pairs.
509 *     Be carefull !!! Boot time.
510 *     It takes about 4 ~ 5 Seconds to update Patch's data with 50 Khz
511 *     for I2C's clock speed.
512 *      3) Initialize Dsp .
513 *      4) Initialize Register.
514 *      5) Set initialize.
515 * Input:
516 *  unsigned char i2c_num: first i2c (0) or second i2c (1)
517 *  unsigned char ucSlaveAddr: device slave address
518 * Return:
519 *  STV82X8_NO_ERROR = Initalisation for STV82x8 is succeed .
520 *  STV82X8_I2C_ERROR = Initalisation for STV82x8 is failed .
521 *******************************************************************************/
522unsigned char STV82x8_Initialize(unsigned char i2c_num,unsigned char ucSlaveAddr)
523{
524        unsigned char  ucResult = STV82X8_NO_ERROR;
525
526printf("STV82x8_Initialize 11111111==\n");
527    if(STV82x8_OpenDevice(i2c_num,ucSlaveAddr))
528        return STV82X8_I2C_ERROR;
529printf("STV82x8_Initialize 22222222==\n");   
530        ucResult = STV82x8_SwReset();
531printf("STV82x8_Initialize 33333333==\n");   
532        if (ucResult == STV82X8_NO_ERROR)
533    {
534        if(STV82x8_UpdatePatchData())
535        {
536            TRACE0(("UpdatePatchData Failed\n"));         
537            return STV82X8_I2C_ERROR;
538        }
539printf("STV82x8_Initialize 33333333==\n");           
540        if(STV82x8_InitDSP())
541        {
542            TRACE0(("InitDSP Failed\n"));                   
543            return STV82X8_I2C_ERROR;
544        }
545printf("STV82x8_Initialize 33333333==\n");               
546        if(STV82x8_InitRegister())
547        {
548            TRACE0(("InitRegister Failed\n"));                   
549            return STV82X8_I2C_ERROR;
550        }
551printf("STV82x8_Initialize 33333333==\n");               
552        if(STV82x8_SetI2SInOut( STV82X8_I2S_OUTPUT ))             //Reg 01
553        {
554            TRACE0(("SetI2SInOut Failed\n"));                             
555            return STV82X8_I2C_ERROR;
556        }
557printf("STV82x8_Initialize 33333333==\n");               
558        if(STV82x8_SetI2SOutputSignal( STV82X8_I2S_OUTPUT_LR ))   //Reg 56
559        {
560            TRACE0(("SetI2SOutputSignal Failed\n"));                                       
561            return STV82X8_I2C_ERROR;
562        }
563printf("STV82x8_Initialize 33333333==\n");   
564        // do SAP/Stereo/Mono check           
565        if(STV82x8_All_SoundSystem_Check())
566        {
567            TRACE0(("STV82x8_All_SoundSystem_Check\n"));                                       
568            return STV82X8_I2C_ERROR;
569        }
570
571        //      STV82x8_SetInOutput_ScartConfig(STV82X8_INPUT_AV1);
572        //      STV82x8_SetOutput_RFConfig();
573        }
574    else
575    {
576        TRACE0(("SW Reset Failed\n"));
577    }
578 printf("STV82x8_Initialize end==\n");
579        return ucResult;
580}
581
582
583
584
585/******************************************************************************
586 * Function:
587 *  unsigned char STV82x8_HwReset(VOID)
588 * Description:
589 *  This function executes hardware reset the STV82x8's device with pin43.
590 *      H/W reset is directly controled by PIO and PIO's pin is connected
591 *      Main IC's PIO with pin43 of STV82x8.
592 *                              ________________                                _______________
593 *                                                              |                               |
594 *                                                              |_______________|
595 *
596 *                                                              |<-------------->|
597 *
598 *                                                                                              50 ms
599 * Input: None
600 * Output: None
601 * Return:
602 *  STV82X8_NO_ERROR = H/W Reset is succeed .
603 *  STV82X8_I2C_ERROR = H/W Reset is failed
604 *******************************************************************************/
605unsigned char STV82x8_HwReset(VOID)
606{
607    unsigned char   ucResult = STV82X8_NO_ERROR;
608
609        ucResult = PIO_SetLow();
610//      Delay_msec( 50 );
611        ucResult |= PIO_SetHigh();
612   
613        return ( ucResult );
614}
615
616
617
618/******************************************************************************
619 * Function:
620 *  unsigned char STV82x8_SwReset(VOID)
621 * Description:
622 *  executes software reset the device with register 0x01 of STV82x8.
623 *      If you will be setting field SOFT_RST to 1, STV82x8 will be resetted
624 *      all hardware registers except for IIC data.
625 *                      SOFT_RST Set[1]                                 SOFT_RST Set[0]
626 *                      _______________|_______________ |_______________
627 *                         |<-------------->|
628 *                                                            20 ms
629 *
630 * Input: None.
631 * Output: None
632 * Return:
633 *  STV82X8_NO_ERROR = S/W Reset is succeed.
634 *  STV82X8_I2C_ERROR = S/W Reset is failed.
635 ********************************************************************************/
636unsigned char STV82x8_SwReset(VOID)
637{
638        unsigned char  ucResult = STV82X8_NO_ERROR;
639
640        ucResult = STV82x8_DataMaskWrite( SW_RESET, STV82X8_SOFT_RESET, STV82X8_SOFT_RESETALL_MASK );
641   
642        Delay_msec(20);
643//      usleep( 500 ); //35ms
644        ucResult |= STV82x8_DataMaskWrite( SW_RESET, (STV82X8_SOFT_RESET&0xFE), STV82X8_SOFT_RESETALL_MASK );
645       
646        return(ucResult);
647}
648
649
650
651/**********************************************************************************
652 * Function:
653 *  unsigned char STV82x8_UpdatePatchData(VOID)
654 * Description:
655 *  This function update new patch data through I2C's communication.
656 * Input:
657 *  None
658 * Output:
659 *  None
660 * Return:
661 *  STV82X8_NO_ERROR = New patch data was successfully loaded.
662 *  STV82X8_I2C_ERROR  = New patch data wasn't successfully loaded.
663 **********************************************************************************/
664unsigned char STV82x8_UpdatePatchData(VOID)
665{
666        UINT   uiPatchSize, uiCount = 0;
667        unsigned char  ucResult = STV82X8_NO_ERROR;
668
669        for( uiPatchSize = 0; uiPatchSize < ( sizeof(ttucPatchV18h) / 2 );  uiPatchSize++ )
670    {
671        I2cWriteSTV82x8( ttucPatchV18h[uiCount][0], ttucPatchV18h[uiCount][1] );
672        uiCount += 1;
673//printf("uiCount:%d, uiCount%16:%d\n",uiCount, uiCount%16);
674                /*
675                if (uiCount%8==0)
676                        usleep(0);
677                */
678    }
679
680    ucResult = STV82x8_VerifiedPatchData();
681
682    return(ucResult);
683}
684
685
686
687
688/**********************************************************************************
689 * Function:
690 *  unsigned char STV82x8_VerifiedPatchData(VOID)
691 * Description:
692 *  When ST-Set is updated by new patch data through I2C, FFh register
693 *  will be atomatically updated by new patch version.
694 *      If FFh register isn't same as the patch version, patch data wasn't loaded well.
695 * Input:
696 * Output:
697 *  None
698 * Return:
699 *  STV82X8_NO_ERROR = Verified patch data was succeed.
700 *  STV82X8_I2C_ERROR = Verified patch data was failed.
701 *********************************************************************************/
702unsigned char STV82x8_VerifiedPatchData(VOID)
703{
704    unsigned char   ucRegVal, ucResult = STV82X8_NO_ERROR;
705
706        ucResult = I2cReadSTV82x8( PATCH_VERSION, &ucRegVal );
707    if( ucRegVal  != STV82X8_PATCH_VERSION )
708    {
709        ucResult = STV82X8_I2C_ERROR;
710    }
711
712    return(ucResult);
713}
714
715
716
717/**********************************************************************************
718 * Function:
719 *  unsigned char STV82x8_InitDSP(VOID)
720 * Description:
721 *  TV-Set has to set field HW_RESET[0x80] to 1 in order to initialize DSP parts
722 *      After that, TV-Set has to wait for INIT_MEM[0x84] field to be changed from 0
723 *      to 1. It means the DSP init is good. And then DSP will be started.
724 * Input:
725 * Output:
726 *  None
727 * Return:
728 *  STV82X8_NO_ERROR = DSP Init is succeed.
729 *  STV82X8_I2C_ERROR = DSP Init is failed.
730 *********************************************************************************/
731unsigned char STV82x8_InitDSP(VOID)
732{
733    unsigned char   ucRegValue = 0, ucCount = 0, ucResult = STV82X8_NO_ERROR;
734
735        ucResult = STV82x8_DataMaskWrite( HOST_CMD, STV82X8_HWINITDSP_VALUE, STV82X8_HWINITDSP_MASK );
736       
737    if( ucResult )
738        {
739           return ( ucResult );
740        }
741
742        do{
743        Delay_msec(10 ); //10ms
744                I2cReadSTV82x8( DSP_STATUS, &ucRegValue );
745                ucRegValue &= STV82X8_INIT_MEM_MASK;
746        }while( ( ++ucCount < 30 ) && ( !ucRegValue )  );
747
748        STV82x8_SetValueForSPDIF();
749        ucResult = STV82x8_DataMaskWrite ( I2S_CONFIG, 0x07, STV82X8_I2S_CONFIG_MASK );
750
751        if( ucRegValue )
752        {
753                ucResult = STV82x8_DataMaskWrite ( DSP_RUN, STV82X8_INITDSPHOSTRUN_VALUE, STV82X8_INITDSPHOSTRUN_MASK );
754        }
755        else
756        {
757                ucResult = STV82X8_I2C_ERROR;
758        }
759
760        return(ucResult);
761}
762
763
764
765/**********************************************************************************
766 * Function:
767 *  unsigned char STV82x8_InitRegister(VOID)
768 * Description:
769 *  If necessary, TV-Set will be set special register to special values into here.
770 *      Scart, Loudspeaker, Headphone and Subwoofer will be mute first.
771 *      And  then STV82x8 will be set volume control register to values of special
772 *      volume tables.
773 * Input:
774 * Output:
775 *  None
776 * Return:
777 *  STV82X8_I2C_ERROR = I2C's communication is failed.
778 *  STV82X8_INVALID_PARAM = Invalid params.
779 *  STV82X8_NO_ERROR = successfully set left volume.
780 ***********************************************************************************/
781unsigned char STV82x8_InitRegister(VOID)
782{
783        unsigned char  ucResult = STV82X8_NO_ERROR;
784
785        //set SPDIF out mute
786        ucResult |= STV82x8_DataMaskWrite( AUDIO_MATRIX3_INPUT, 0x0, STV82X8_MATRIX3_INPUT_MASK );
787
788        ucResult |= STV82x8_SetDigitalMute(STV82x8_MUTE_ALL_OUTPUT, STV82x8_ALL_OUTPUT_MASK);
789        ucResult |= STV82x8_SetDACMute();
790
791
792        ucResult |= STV82x8_SetDefaultValueFromSTDConfig();
793        ucResult |= STV82x8_SetLeftVolume( (USHORT)( VOLUME_0DB_DEFAULT_VALUE ) );
794        ucResult |= STV82x8_SetCenterVolume( (USHORT)( VOLUME_0DB_DEFAULT_VALUE ) );
795        ucResult |= STV82x8_SetMasterVolume( (USHORT)( VOLUME_TABLE[0] ) );
796    ucResult |= STV82x8_SetVolumeMode( DIFFERENTIAL_MODE );
797    ucResult |= STV82x8_SetLSBalance( (unsigned char)( STV82X8_LS_BALANCE_CENTER ) );       
798        ucResult |= STV82x8_WakeUpADC();
799        ucResult |= STV82x8_WakeUpIRQ0();
800
801        ucResult |= STV82x8_SetFMTimeOut( FM_TIME_64MS );
802 
803    // adjust the prescale for each input
804        ucResult |= STV82x8_SetMonoStereoDefaultPrescale();
805        ucResult |= STV82x8_SetScartDefaultPrescale();
806        ucResult |= STV82x8_SAPDefaultPrescale();
807    ucResult |= STV82x8_I2SDefaultPrescale(PRESCALE_I2S_0, I2S_PRESCALING_DEFAULTVALU);
808    ucResult |= STV82x8_I2SDefaultPrescale(PRESCALE_I2S_1, I2S_PRESCALING_DEFAULTVALU);
809    ucResult |= STV82x8_I2SDefaultPrescale(PRESCALE_I2S_2, I2S_PRESCALING_DEFAULTVALU);     
810
811        ucResult |= STV82x8_SetEqualizerValue( EQUALIZER_100HZ, 2 );
812        ucResult |= STV82x8_SetEqualizerValue( EQUALIZER_330HZ, 3 );
813        ucResult |= STV82x8_SetEqualizerValue( EQUALIZER_1KHZ, 4 );
814        ucResult |= STV82x8_SetEqualizerValue( EQUALIZER_3P3KHZ, 5 );
815        ucResult |= STV82x8_SetEqualizerValue( EQUALIZER_10KHZ, 6 );
816
817    // headphone related setting
818    ucResult |= STV82x8_SetHPConfiguration(STV82x8_HP_FORCE_ON, STV82x8_HP_LS_UNMUTE, STV82x8_HP_DET_ACTIVE_ON);   
819    ucResult |= STV82x8_SetHPLeftVolume(STV82X8_HEADPHONE_VOLUME_DEFAULT);
820    ucResult |= STV82x8_SetHPBalance( (unsigned char)( STV82X8_LS_BALANCE_CENTER ) );
821    ucResult |= STV82x8_AutoVolumeHPCtrl(STV82x8_SVC_ON);
822   
823        ucResult |= STV82x8_SetPseudoEffect( STV82X8_PSEUDO_OFF );
824        ucResult |= STV82x8_SetSRSWOW_Effect( STV82X8_ALL_SRS_OFF );
825
826//      ucResult |= STV82x8_ControlTurboSound( STV82X8_TURBO_SOUND_OFF, 7 ); Josie 8/23
827        ucResult |= STV82x8_ControlTurboSound( STV82X8_TURBO_SOUND_ON, 2 ); 
828
829        ucResult |= STV82x8_AutoVolumeCtrl( STV82x8_SVC_ON );   
830
831    ucResult |= STV82x8_SetAutoMuteOnOff(ON);
832 
833//    ucResult |= STV82x8_SetLoudSpkHeadPhoneGain(LS_BASS_GAIN, BASS_TREBLE_GAIN_TABLE[0]);
834     ucResult |=STV82x8_Enble_Equalizer(OFF, LS_BASS_GAIN, BASS_TREBLE_GAIN_TABLE[0] );
835    ucResult |= STV82x8_SetLoudSpkHeadPhoneGain(LS_TREBLE_GAIN, BASS_TREBLE_GAIN_TABLE[0]);   
836
837    ucResult |= STV82x8_SetStereoTimeOut(STEREO_TIME_200MS);
838 
839    // set differential mode with complimentary blance control is used
840    //STV82x8_SetScartVolumeMode(DIFFERENTIAL_MODE);
841    //STV82x8_ScartOutBalance( (unsigned char)( STV82X8_LS_BALANCE_CENTER ));
842   
843
844        ucResult |= STV82x8_SetDACUnMute();
845        ucResult |= STV82x8_SetDigitalUnMute(STV82x8_UNMUTE_ALL_OUTPUT, STV82x8_ALL_OUTPUT_MASK);
846
847        ucResult |= STV82x8_SAPConfig(0); 
848
849        return ( ucResult );
850}
851
852
853
854/***********************************************************************************
855 * Function:
856 *      unsigned char STV82x8_SetDigitalMute(unsigned char ucMute, unsigned char ucMask)
857 * Description:
858 *  This function executes that STV82x8 to process software sound mute.
859 * Input:
860 *  unsigned char ucMute:   00000001b = LS mute (STV82X8_DIGITAL_LS_MUTE)
861 *                  00000010b = Center mute
862 *                  00000100b = Subwoofer mute
863 *                  00001000b = Surrond mute
864 *                  00010000b = Scart1 mute
865 *                  00100000b = Scart2 mute
866 *                  01000000b = SPDIF mute (STV82X8_DIGITAL_SPDIF_MUTE)
867 *                  10000000b = Headphone mute (STV82x8_DIGITAL_HP_MUTE)
868 * Output:
869 *  None
870 * Return:
871 *  STV82X8_I2C_ERROR = I2C's communication is failed.
872 *  STV82X8_NO_ERROR = successfully set Digital mute.
873 **********************************************************************************/
874unsigned char STV82x8_SetDigitalMute(unsigned char ucMute, unsigned char ucMask)
875{
876        unsigned char  ucResult = STV82X8_NO_ERROR;
877
878#ifdef __STV_DEBUG__
879    STV_FUNCTION;;
880#endif
881
882        ucResult = STV82x8_DataMaskWrite(MUTE_DIGITAL,
883                                    ucMute,
884                                    ucMask);
885                                   
886    return(ucResult);
887}
888
889
890
891/***********************************************************************************
892 * Function:
893 *  unsigned char STV82x8_SetDigitalUnMute(unsigned char ucUnMute, unsigned char ucMask)
894 * Description:
895 *  This function executes that STV82x8 to process software sound unmute
896 *      except for Scart input.
897 * Input:
898 * unsigned char ucUnMute:  00000001b = LS mute
899 *                  00000010b = Center mute
900 *                  00000100b = Subwoofer mute
901 *                  00001000b = Surrond mute
902 *                  00010000b = Scart1 mute
903 *                  00100000b = Scart2 mute
904 *                  01000000b = SPDIF mute
905 *                  10000000b = Headphone mute
906 * Output:
907 *  None
908 * Return:
909 *  STV82X8_I2C_ERROR = I2C's communication is failed.
910 *  STV82X8_NO_ERROR = successfully set Digital unmute.
911 ***********************************************************************************/
912unsigned char STV82x8_SetDigitalUnMute(unsigned char ucUnMute, unsigned char ucMask)
913{
914        unsigned char ucResult = STV82X8_NO_ERROR;
915
916#ifdef __STV_DEBUG__
917    STV_FUNCTION;
918#endif
919
920        ucResult = STV82x8_DataMaskWrite( MUTE_DIGITAL,
921                                                                        ucUnMute,
922                                    ucMask);
923       
924    return(ucResult);
925}
926
927
928
929/************************************************************************************
930 * Function:
931 *  unsigned char STV82x8_SetDACMute(VOID)
932 * Description:
933 *  This function executes that STV82x8 to process DAC sound mute.
934 * Input:
935 * Output:
936 *  None
937 * Return:
938 *  STV82X8_I2C_ERROR = I2C's communication is failed.
939 *  STV82X8_NO_ERROR = successfully set ADC mute.
940 ************************************************************************************/
941unsigned char STV82x8_SetDACMute(VOID)
942{
943    unsigned char ucResult = STV82X8_NO_ERROR;
944
945#ifdef __STV_DEBUG__
946    STV_FUNCTION;
947#endif
948
949        ucResult = STV82x8_DataMaskWrite( DAC_CTRL,
950                                                                        STV82X8_DAC_MUTE_VALUE,
951                                    STV82X8_DAC_MUTE_MASK );
952
953        return(ucResult);
954}
955
956
957
958/************************************************************************************
959 * Function:
960 *  unsigned char STV82x8_SetDACUnMute(VOID)
961 * Description:
962 *  This function executes that STV82x8 to process DAC sound unmute.
963 * Input:
964 * Output:
965 *  None.
966 * Return:
967 *  STV82X8_I2C_ERROR = I2C's communication is failed.
968 *  STV82X8_NO_ERROR = successfully set ADC unmute.
969 ************************************************************************************/
970unsigned char STV82x8_SetDACUnMute(VOID)
971{
972    unsigned char   ucResult = STV82X8_NO_ERROR;
973
974#ifdef __STV_DEBUG__
975    STV_FUNCTION;
976#endif
977
978        ucResult = STV82x8_DataMaskWrite( DAC_CTRL,
979                                    STV82X8_DAC_UNMUTE_VALUE,
980                                    STV82X8_DAC_MUTE_MASK );
981       
982    return(ucResult);
983}
984
985
986
987/************************************************************************************
988 * Function:
989 *      unsigned char STV82x8_SetScart1DigitalMute(VOID)
990 * Description:
991 *  This function executes that STV82x8 to process software sound mute for Scart input.
992 * Input:
993 * Output:
994 *  None
995 * Return:
996 *  STV82X8_I2C_ERROR = I2C's communication is failed.
997 *  STV82X8_NO_ERROR = successfully set Scart digital mute.
998 ************************************************************************************/
999unsigned char STV82x8_SetScart1DigitalMute(VOID)
1000{
1001        unsigned char ucResult = STV82X8_NO_ERROR;
1002
1003#ifdef __STV_DEBUG__
1004    STV_FUNCTION;
1005#endif
1006
1007        ucResult = STV82x8_DataMaskWrite( MUTE_DIGITAL,
1008                                                                        STV82X8_DIGITAL_SCART1_MUTE,
1009                                                                        STV82X8_DIGITALMUTE_SCART1_MASK );
1010
1011        return(ucResult);
1012}
1013
1014
1015
1016/************************************************************************************
1017 * Function:
1018 *  unsigned char STV82x8_SetScart1DigitalUnMute(VOID)
1019 * Description:
1020 *  This function executes that STV82x8 to process software sound unmute for Scart input.
1021 * Input:
1022 * Output:
1023 *  None
1024 * Return:
1025 *  STV82X8_I2C_ERROR = I2C's communication is failed.
1026 *  STV82X8_NO_ERROR = successfully set Scart digital unmute.
1027 ************************************************************************************/
1028unsigned char STV82x8_SetScart1DigitalUnMute(VOID)
1029{
1030    unsigned char   ucResult = STV82X8_NO_ERROR;
1031
1032#ifdef __STV_DEBUG__
1033    STV_FUNCTION;
1034#endif
1035
1036        ucResult = STV82x8_DataMaskWrite( MUTE_DIGITAL,
1037                                                                        STV82X8_DIGITAL_SCART1_UNMUTE,
1038                                                                STV82X8_DIGITALMUTE_SCART1_MASK );
1039
1040    return(ucResult);
1041}
1042
1043
1044
1045/*************************************************************************************
1046 * Function:
1047 *  unsigned char STV82x8_SetSPDIFDigitalMute(VOID)
1048 * Description:
1049 *  This function executes that STV82x8 to process software sound mute for Scart input.
1050 * Input:
1051 * Output:
1052 *  None
1053 * Return:
1054 *  STV82X8_I2C_ERROR = I2C's communication is failed.
1055 *  STV82X8_NO_ERROR = successfully set Scart digital mute.
1056 ************************************************************************************/
1057unsigned char STV82x8_SetSPDIFDigitalMute(VOID)
1058{
1059        unsigned char ucResult = STV82X8_NO_ERROR;
1060
1061#ifdef __STV_DEBUG__
1062    STV_FUNCTION;
1063#endif
1064
1065        ucResult = STV82x8_DataMaskWrite( MUTE_DIGITAL,
1066                                                                        STV82X8_DIGITAL_SPDIF_MUTE,
1067                                                                        STV82X8_DIGITALMUTE_SPDIF_MASK );
1068
1069    return(ucResult);
1070}
1071
1072
1073
1074
1075/*************************************************************************************
1076 * Function:
1077 *  unsigned char STV82x8_SetSPDIFDigitalUnMute(VOID)
1078 * Description:
1079 *  This function executes that STV82x8 to process software sound unmute for Scart input.
1080 * Input:
1081 * Output:
1082 *  None
1083 * Return:
1084 *  STV82X8_I2C_ERROR = I2C's communication is failed.
1085 *  STV82X8_NO_ERROR = successfully set Scart digital unmute.
1086 *************************************************************************************/
1087unsigned char STV82x8_SetSPDIFDigitalUnMute(VOID)
1088{
1089    unsigned char ucResult = STV82X8_NO_ERROR;
1090
1091#ifdef __STV_DEBUG__
1092    STV_FUNCTION;
1093#endif
1094
1095        ucResult = STV82x8_DataMaskWrite( MUTE_DIGITAL,
1096                                                                        STV82X8_DIGITAL_SPDIF_UNMUTE,
1097                                                                        STV82X8_DIGITALMUTE_SPDIF_MASK );
1098
1099    return(ucResult);
1100}
1101
1102
1103/*************************************************************************************
1104 * Function:
1105 *  unsigned char STV82x8_SetSPDIFDigitalMute(VOID)
1106 * Description:
1107 *  This function executes that STV82x8 to process software sound mute for Scart input.
1108 * Input:
1109 * Output:
1110 *  None
1111 * Return:
1112 *  STV82X8_I2C_ERROR = I2C's communication is failed.
1113 *  STV82X8_NO_ERROR = successfully set Scart digital mute.
1114 ************************************************************************************/
1115unsigned char STV82x8_SetSPDIFMute(VOID)
1116{
1117        unsigned char ucResult = STV82X8_NO_ERROR;
1118
1119#ifdef __STV_DEBUG__
1120    STV_FUNCTION;
1121#endif
1122
1123        //read current SPDIF input
1124        I2cReadSTV82x8(AUDIO_MATRIX3_INPUT, &gCurSPDIFInput);
1125        ucResult |= STV82x8_DataMaskWrite( AUDIO_MATRIX3_INPUT, 0x0, STV82X8_MATRIX3_INPUT_MASK );
1126       
1127    return(ucResult);
1128}
1129
1130
1131
1132
1133/*************************************************************************************
1134 * Function:
1135 *  unsigned char STV82x8_SetSPDIFDigitalUnMute(VOID)
1136 * Description:
1137 *  This function executes that STV82x8 to process software sound unmute for Scart input.
1138 * Input:
1139 * Output:
1140 *  None
1141 * Return:
1142 *  STV82X8_I2C_ERROR = I2C's communication is failed.
1143 *  STV82X8_NO_ERROR = successfully set Scart digital unmute.
1144 *************************************************************************************/
1145unsigned char STV82x8_SetSPDIFUnMute(VOID)
1146{
1147    unsigned char ucResult = STV82X8_NO_ERROR;
1148
1149#ifdef __STV_DEBUG__
1150    STV_FUNCTION;
1151#endif
1152
1153        ucResult |= STV82x8_DataMaskWrite( AUDIO_MATRIX3_INPUT, gCurSPDIFInput, STV82X8_MATRIX3_INPUT_MASK );
1154
1155
1156    return(ucResult);
1157}
1158
1159/*************************************************************************************
1160 * Function:
1161 *  unsigned char STV82x8_SetScartDACMute(VOID)
1162 * Description:
1163 *  This function executes that STV82x8 to process software sound mute for Scart input.
1164 * Input:
1165 * Output:
1166 *  None
1167 * Return:
1168 *  STV82X8_I2C_ERROR = I2C's communication is failed.
1169 *  STV82X8_NO_ERROR = successfully set Scart digital unmute.
1170 ************************************************************************************/
1171unsigned char STV82x8_SetScartDACMute(VOID)
1172{
1173    unsigned char   ucResult = STV82X8_NO_ERROR;
1174
1175#ifdef __STV_DEBUG__
1176    STV_FUNCTION;
1177#endif
1178
1179        ucResult = STV82x8_DataMaskWrite(DAC_CTRL,
1180                                                                STV82X8_SC_DAC_MUTE_VALUE,
1181                                    STV82X8_SC_DAC_MUTE_MASK );
1182   
1183    return(ucResult);
1184}
1185
1186
1187
1188/**********************************************************************************
1189 * Function:
1190 *  unsigned char STV82x8_SetScartDACUnMute(VOID)
1191 * Description:
1192 *  This function executes that STV82x8 to process software sound unmute
1193 *      for Scart input.
1194 * Input:
1195 * Output:
1196 *  None
1197 * Return:
1198 *  STV82X8_I2C_ERROR = I2C's communication is failed.
1199 *  STV82X8_NO_ERROR = successfully set Scart digital unmute.
1200 **********************************************************************************/
1201unsigned char STV82x8_SetScartDACUnMute(VOID)
1202{
1203    unsigned char   ucResult = STV82X8_NO_ERROR;
1204
1205#ifdef __STV_DEBUG__
1206    STV_FUNCTION;
1207#endif
1208
1209        ucResult = STV82x8_DataMaskWrite(DAC_CTRL,
1210                                    STV82X8_SC_DAC_UNMUTE_VALUE,
1211                                    STV82X8_SC_DAC_MUTE_MASK );
1212                                   
1213        return (ucResult);
1214}
1215
1216
1217
1218/***********************************************************************************
1219 * Function:
1220 *  unsigned char STV82x8_SetVolumeMode(unsigned char ucVolumeMode)
1221 * Description:
1222 *  This function set volume mode between Independential and Differential mode.
1223 * Input:
1224 *  INDEPENDANT_MODE = Volume mode is independant.
1225 *  DIFFERENTIAL_MODE = Volume mode is differential.
1226 * Output:
1227 *  None
1228 * Return:
1229 *  STV82X8_I2C_ERROR = I2C's communication is failed.
1230 *  STV82X8_INVALID_PARAM = Invalid params.
1231 *  STV82X8_NO_ERROR = successfully set left volume.
1232 **********************************************************************************/
1233unsigned char STV82x8_SetVolumeMode(unsigned char ucVolumeMode)
1234{
1235        unsigned char ucResult = STV82X8_NO_ERROR;
1236
1237#ifdef __STV_DEBUG__
1238    STV_FUNCTION;
1239#endif
1240
1241        if( ucVolumeMode == INDEPENDANT_MODE )
1242        {
1243                ucResult = STV82x8_DataMaskWrite( VOLUME_MODES,
1244                                                                                        STV82X8_VOLUMEMODE_INDEPENDANT,
1245                                                                                        STV82X8_VOLUMEMODE_MASK );
1246                if( ucResult )
1247                        ucResult = STV82X8_I2C_ERROR;
1248         }
1249        else if( ucVolumeMode == DIFFERENTIAL_MODE )
1250        {
1251                ucResult = STV82x8_DataMaskWrite( VOLUME_MODES,
1252                                                                                        STV82X8_VOLUMEMODE_DIFFERENTIAL,
1253                                                                                        STV82X8_VOLUMEMODE_MASK );
1254                if( ucResult )
1255                        ucResult = STV82X8_I2C_ERROR;
1256        }
1257        else
1258        {
1259                ucResult = STV82X8_INVALID_PARAM;
1260        }
1261
1262        return ( ucResult );
1263}
1264
1265
1266
1267/*************************************************************************************
1268 * Function:
1269 *  unsigned char STV82x8_SetScartVolumeMode(unsigned char ucVolumeMode)
1270 * Description:
1271 *  This function set volume mode for scart between Independential and Differential mode.
1272 * Input:
1273 *  INDEPENDANT_MODE = Volume mode is independant.
1274 *  DIFFERENTIAL_MODE = Volume mode is differential.
1275 * Output:
1276 *  None
1277 * Return:
1278 *  STV82x8_I2C_ERROR = I2C's communication is failed.
1279 *  STV82x8_INVALID_PARAM = Invalid params.
1280 *  STV82x8_NO_ERROR = No error.
1281 *************************************************************************************/
1282unsigned char STV82x8_SetScartVolumeMode(unsigned char ucVolumeMode)
1283{
1284    unsigned char ucResult = STV82X8_NO_ERROR;
1285
1286#ifdef __STV_DEBUG__
1287    STV_FUNCTION;
1288#endif
1289
1290        if( ucVolumeMode == INDEPENDANT_MODE )
1291        {
1292                ucResult = STV82x8_DataMaskWrite(VOLUME_MODES,
1293                                                                        STV82X8_SCART_VOLUMEMODE_INDEPENDANT,
1294                                        STV82X8_SCART_VOLUMEMODE_MASK );
1295        }
1296        else if( ucVolumeMode == DIFFERENTIAL_MODE )
1297        {
1298                ucResult = STV82x8_DataMaskWrite(VOLUME_MODES,
1299                                                                        STV82X8_SCART_VOLUMEMODE_DIFFERENTIAL,
1300                                        STV82X8_SCART_VOLUMEMODE_MASK );
1301        }
1302        else
1303        {
1304                ucResult = STV82X8_INVALID_PARAM;
1305        }
1306
1307        return ( ucResult );
1308}
1309
1310
1311
1312
1313/****************************************************************************************
1314 * Function:
1315 *  unsigned char STV82x8_SetLeftVolume(USHORT usVolume )
1316 * Description:
1317 *  This function set left volume to special value.
1318 * Input:
1319 *  Left volume = 10-bit volume value.
1320 *              X X X X     X X X X      X X X X     X X X X
1321 *              -----------------              ---
1322 *                      MSB                                LSB
1323 * Output:
1324 *  None
1325 * Return:
1326 *  STV82X8_I2C_ERROR = I2C's communication is failed.
1327 *  STV82X8_NO_ERROR = successfully set left volume.
1328 * *************************************************************************************/
1329unsigned char STV82x8_SetLeftVolume(USHORT usVolume )
1330{
1331    unsigned char   ucVolumeMSB, ucVolumeLSB;
1332    unsigned char   ucResult = STV82X8_NO_ERROR;
1333
1334#ifdef __STV_DEBUG__
1335    STV_FUNCTION;
1336#endif
1337
1338        ucVolumeMSB = (unsigned char)(( usVolume >> NORMAL_VOLUME_SHIFT ) & VOLUME_MSB_MASK );
1339        ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK );
1340
1341        ucResult = I2cWriteSTV82x8( LS_L_VOLUME_MSB, ucVolumeMSB );
1342        ucResult |= I2cWriteSTV82x8( LS_L_VOLUME_LSB, ucVolumeLSB );
1343
1344        return ( ucResult );
1345}
1346
1347
1348/************************************************************************************
1349 * Function:
1350 *  unsigned char STV82x8_SetRightVolume(USHORT usVolume )
1351 * Description:
1352 *  This function set right volume to special value.
1353 * Input:
1354 *  Rightt volume = 10-bit volume value.
1355 *              X X X X     X X X X      X X X X     X X X X
1356 *              -----------------              ---
1357 *                      MSB                                LSB
1358 * Output:
1359 *  None
1360 * Return:
1361 *  STV82X8_I2C_ERROR = I2C's communication is failed.
1362 *  STV82X8_NO_ERROR = successfully set left volume.
1363 ************************************************************************************/
1364unsigned char STV82x8_SetRightVolume(USHORT usVolume )
1365{
1366    unsigned char   ucVolumeMSB, ucVolumeLSB;
1367    unsigned char   ucResult = STV82X8_NO_ERROR;   
1368
1369#ifdef __STV_DEBUG__
1370    STV_FUNCTION;
1371#endif
1372
1373        ucVolumeMSB = (unsigned char)(( usVolume >> NORMAL_VOLUME_SHIFT ) & VOLUME_MSB_MASK );
1374        ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK );
1375
1376        ucResult = STV82x8_SetVolumeMode( INDEPENDANT_MODE );
1377
1378        ucResult = I2cWriteSTV82x8( LS_R_VOLUME_MSB, ucVolumeMSB );
1379        ucResult |= I2cWriteSTV82x8( LS_R_VOLUME_LSB, ucVolumeLSB );
1380
1381        return ( ucResult );
1382}
1383
1384
1385
1386/************************************************************************************
1387 * Function:
1388 *  unsigned char STV82x8_SetCenterVolume(USHORT usVolume)
1389 * Description:
1390 *  This function set center volume to special value.
1391 * Input:
1392 *  Center volume = 10-bit volume value.
1393 *              X X X X     X X X X      X X X X     X X X X
1394 *              -----------------                 ---
1395 *                      MSB                                        LSB
1396 * Output:
1397 *  None
1398 * Return:
1399 *  STV82X8_I2C_ERROR = I2C's communication is failed.
1400 *  STV82X8_NO_ERROR = successfully set left volume.
1401 * ***********************************************************************************/
1402unsigned char STV82x8_SetCenterVolume(USHORT usVolume)
1403{
1404    unsigned char   ucVolumeMSB, ucVolumeLSB;
1405    unsigned char   ucResult = STV82X8_NO_ERROR;
1406
1407#ifdef __STV_DEBUG__
1408    STV_FUNCTION;
1409#endif
1410
1411        ucVolumeMSB = (unsigned char)(( usVolume >> NORMAL_VOLUME_SHIFT ) & VOLUME_MSB_MASK );
1412        ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK );
1413
1414        ucResult = I2cWriteSTV82x8( LS_C_VOLUME_MSB, ucVolumeMSB );
1415        ucResult |= I2cWriteSTV82x8( LS_C_VOLUME_LSB, ucVolumeLSB );
1416
1417        return ( ucResult );
1418}
1419
1420
1421/*************************************************************************************
1422 * Function:
1423 *  unsigned char STV82x8_SetSurroundLeftVolume(USHORT usVolume)
1424 * Description:
1425 *  This function set surround left volume to special value.
1426 * Input:
1427 *  Left volume = 10-bit volume value.
1428 *                      X X X X     X X X X      X X X X     X X X X
1429 *                      -----------------                          ---
1430 *                              MSB                                                LSB
1431 * Output:
1432 *  None
1433 * Return:
1434 *  STV82X8_I2C_ERROR = I2C's communication is failed.
1435 *  STV82X8_NO_ERROR = successfully set left volume.
1436 *************************************************************************************/
1437unsigned char STV82x8_SetSurroundLeftVolume(USHORT usVolume)
1438{
1439    unsigned char   ucVolumeMSB, ucVolumeLSB;
1440    unsigned char   ucResult = STV82X8_NO_ERROR;
1441
1442#ifdef __STV_DEBUG__
1443    STV_FUNCTION;
1444#endif
1445
1446        ucVolumeMSB = (unsigned char)(( usVolume >> NORMAL_VOLUME_SHIFT ) & VOLUME_MSB_MASK );
1447        ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK );
1448
1449        ucResult = I2cWriteSTV82x8( LS_SL_VOLUME_MSB,  ucVolumeMSB );
1450        ucResult |= I2cWriteSTV82x8( LS_SL_VOLUME_LSB,  ucVolumeLSB );
1451
1452        return ( ucResult );
1453}
1454
1455
1456
1457/*************************************************************************************
1458 * Function:
1459 *  unsigned char STV82x8_SetSurroundRightVolume(USHORT usVolume)
1460 * Description:
1461 *  This function set surround right volume to special value.
1462 * Input:
1463 *  Right volume = 10-bit volume value.
1464 *              X X X X     X X X X      X X X X     X X X X
1465 *              -----------------                          ---
1466 *                      MSB                                                LSB
1467 * Output:
1468 *  None
1469 * Return:
1470 *  STV82X8_I2C_ERROR = I2C's communication is failed.
1471 *  STV82X8_NO_ERROR = successfully set left volume.
1472 ***********************************************************************************/
1473unsigned char STV82x8_SetSurroundRightVolume(USHORT usVolume)
1474{
1475    unsigned char   ucVolumeMSB, ucVolumeLSB;
1476    unsigned char    ucResult = STV82X8_NO_ERROR;
1477
1478#ifdef __STV_DEBUG__
1479    STV_FUNCTION;
1480#endif
1481
1482        ucVolumeMSB = (unsigned char)(( usVolume >> NORMAL_VOLUME_SHIFT ) & VOLUME_MSB_MASK );
1483        ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK );
1484
1485        ucResult = STV82x8_SetVolumeMode( INDEPENDANT_MODE );
1486
1487        ucResult = I2cWriteSTV82x8( LS_SR_VOLUME_MSB, ucVolumeMSB );
1488        ucResult |= I2cWriteSTV82x8( LS_SR_VOLUME_LSB, ucVolumeLSB );
1489
1490        return ( ucResult );
1491}
1492
1493
1494
1495/***********************************************************************************
1496 * Function:
1497 *  unsigned char STV82x8_SetHPLeftVolume(USHORT usVolume)
1498 * Description:
1499 *  This function set HP left volume to special value.
1500 * Input:
1501 *  usVolume = 10-bit Left HP volume value.
1502 *              X X X X     X X X X      X X X X     X X X X
1503 *              -----------------                          ---
1504 *              MSB                                                LSB
1505 * Output:
1506 *  None
1507 * Return:
1508 *  STV82x8_I2C_ERROR = I2C's communication is failed.
1509 *  STV82x8_NO_ERROR = No error.
1510 ***********************************************************************************/
1511unsigned char STV82x8_SetHPLeftVolume(USHORT usVolume)
1512{
1513    unsigned char   ucVolumeMSB, ucVolumeLSB;
1514    unsigned char   ucResult  = STV82X8_NO_ERROR;
1515
1516#ifdef __STV_DEBUG__
1517    STV_FUNCTION;
1518#endif
1519
1520        ucVolumeMSB = (unsigned char)(( usVolume >> NORMAL_VOLUME_SHIFT ) & VOLUME_MSB_MASK );
1521        ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK );
1522
1523        ucResult = I2cWriteSTV82x8( HP_L_VOL_MSB, (unsigned char)( ucVolumeMSB ) );
1524        ucResult |= I2cWriteSTV82x8( HP_L_VOL_LSB, (unsigned char)( ucVolumeLSB ) );
1525
1526        return ( ucResult );
1527}
1528
1529
1530
1531/************************************************************************************
1532 * Function:
1533 *  unsigned char STV82x8_SetHPRightVolume(USHORT usVolume)
1534 * Description:
1535 *  This function set HP right volume to special value.
1536 * Input:
1537 *  usVolume = 10-bit Right HP volume value.
1538 *              X X X X     X X X X      X X X X     X X X X
1539 *              -----------------                          ---
1540 *                      MSB                                                LSB
1541 * Output:
1542 *  None
1543 * Return
1544 *  STV82x8_I2C_ERROR = I2C's communication is failed.
1545 *  STV82X8_NO_ERROR = No error.
1546 ************************************************************************************/
1547unsigned char STV82x8_SetHPRightVolume(USHORT usVolume)
1548{
1549    unsigned char   ucVolumeMSB, ucVolumeLSB;
1550    unsigned char   ucResult = STV82X8_NO_ERROR;
1551
1552#ifdef __STV_DEBUG__
1553    STV_FUNCTION;
1554#endif
1555
1556        ucVolumeMSB = (unsigned char)(( usVolume >> NORMAL_VOLUME_SHIFT ) & VOLUME_MSB_MASK );
1557        ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK );
1558
1559        ucResult = STV82x8_SetVolumeMode( INDEPENDANT_MODE );
1560
1561        ucResult |= I2cWriteSTV82x8( HP_R_VOL_MSB, (unsigned char)( ucVolumeMSB ) );
1562        ucResult |= I2cWriteSTV82x8( HP_R_VOL_LSB, (unsigned char)( ucVolumeLSB ) );
1563
1564        return ( ucResult );
1565}
1566
1567
1568/************************************************************************************
1569 * Function:
1570 *  unsigned char STV82x8_SetMasterVolume(USHORT usVolume)
1571 * Description:
1572 *  This function set master volume to special value.
1573 * Input:
1574 *  Master volume = 16-bit volume value from table
1575 *                      X X X X     X X X X      X X X X     X X X X
1576 *              -----------------                          ---
1577 *                              MSB                                                LSB
1578 * Output:
1579 *  None
1580 * Return:
1581 *  STV82X8_I2C_ERROR = I2C's communication is failed.
1582 *  STV82X8_NO_ERROR = successfully set left volume.
1583 ************************************************************************************/
1584unsigned char STV82x8_SetMasterVolume(USHORT usVolume)
1585{
1586    unsigned char   ucVolumeMSB, ucVolumeLSB;
1587    unsigned char   ucResult = STV82X8_NO_ERROR; 
1588
1589#ifdef __STV_DEBUG__
1590    STV_FUNCTION;
1591#endif
1592
1593        ucVolumeMSB = (unsigned char)(( usVolume >> MASTER_VOLUME_SHIFT ) & VOLUME_MSB_MASK );
1594        ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK );
1595
1596        ucResult = I2cWriteSTV82x8( LS_MASTER_VOLUME_MSB, ucVolumeMSB );
1597        ucResult |= I2cWriteSTV82x8( LS_MASTER_VOLUME_LSB,  ucVolumeLSB );
1598
1599        return ( ucResult );
1600}
1601
1602
1603
1604/***********************************************************************************
1605 * Function:
1606 *  unsigned char STV82x8_SetLeftScartVolume(USHORT usVolume)
1607 * Description:
1608 *  This function set left scart volume to special value.
1609 * Input:
1610 *  Left volume = 10-bit volume value.
1611 *              X X X X     X X X X      X X X X     X X X X
1612 *              -----------------                ---
1613 *                      MSB                              LSB
1614 * Output:
1615 *  None
1616 * Return:
1617 *  STV82X8_I2C_ERROR = I2C's communication is failed.
1618 *  STV82X8_NO_ERROR = successfully set left volume.
1619 ************************************************************************************/
1620unsigned char STV82x8_SetLeftScartVolume(USHORT usVolume)
1621{
1622    unsigned char   ucVolumeMSB, ucVolumeLSB;
1623    unsigned char   ucResult = STV82X8_NO_ERROR;
1624
1625#ifdef __STV_DEBUG__
1626    STV_FUNCTION;
1627#endif
1628
1629        ucVolumeMSB = (unsigned char)(( usVolume >> NORMAL_VOLUME_SHIFT ) & VOLUME_MSB_MASK );
1630        ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK );
1631
1632        ucResult = I2cWriteSTV82x8( AUX_L_VOL_MSB, ucVolumeMSB );
1633        ucResult |= I2cWriteSTV82x8( AUX_L_VOL_LSB,  ucVolumeLSB );
1634
1635        return ( ucResult );
1636}
1637
1638
1639
1640/*************************************************************************************
1641 * Function:
1642 *  unsigned char STV82x8_SetRightScartVolume(USHORT usVolume)
1643 * Description:
1644 *  This function set right scart volume to special value.
1645 * Input:
1646 *  Right volume = 10-bit volume value.
1647 *              X X X X     X X X X      X X X X     X X X X
1648 *              -----------------                 ---
1649 *                      MSB                                        LSB
1650 * Output:
1651 *  None
1652 * Return:
1653 *  STV82X8_I2C_ERROR = I2C's communication is failed.
1654 *  STV82X8_NO_ERROR = successfully set left volume.
1655 ************************************************************************************/
1656unsigned char STV82x8_SetRightScartVolume(USHORT usVolume)
1657{
1658    unsigned char   ucVolumeMSB, ucVolumeLSB;
1659    unsigned char   ucResult = STV82X8_NO_ERROR;
1660   
1661#ifdef __STV_DEBUG__
1662    STV_FUNCTION;
1663#endif
1664
1665        ucVolumeMSB = (unsigned char)(( usVolume >> NORMAL_VOLUME_SHIFT ) & VOLUME_MSB_MASK );
1666        ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK );
1667
1668        ucResult = STV82x8_SetScartVolumeMode( INDEPENDANT_MODE );
1669
1670        ucResult |= I2cWriteSTV82x8( AUX_R_VOL_MSB, ucVolumeMSB );
1671        ucResult |= I2cWriteSTV82x8( AUX_R_VOL_LSB,  ucVolumeLSB );
1672
1673        return ( ucResult );
1674}
1675
1676
1677/***********************************************************************************
1678 * Function:
1679 *  unsigned char STV82x8_SetLSSubWooferVolume(USHORT usVolume)
1680 * Description:
1681 *  This function set LS subwoofer volume to special value.
1682 * Input:
1683 *  Left volume = 10-bit volume value.
1684 *       X X X X     X X X X      X X X X     X X X X
1685 *         -----------------                ---
1686 *             MSB                          LSB
1687 * Output:
1688 *  None
1689 * Return:
1690 *  STV82X8_I2C_ERROR = I2C's communication is failed.
1691 *  STV82X8_NO_ERROR = successfully set left volume.
1692 ************************************************************************************/
1693unsigned char STV82x8_SetLSSubWooferVolume(USHORT usVolume)
1694{
1695    unsigned char   ucVolumeMSB, ucVolumeLSB;
1696    unsigned char   ucResult = STV82X8_NO_ERROR;
1697
1698#ifdef __STV_DEBUG__
1699    STV_FUNCTION;
1700#endif
1701
1702    ucVolumeMSB = (unsigned char)(( usVolume >> NORMAL_VOLUME_SHIFT ) & VOLUME_MSB_MASK );
1703    ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK );
1704
1705    ucResult = I2cWriteSTV82x8( LS_SUB_VOLUME_MSB, ucVolumeMSB );
1706    ucResult |= I2cWriteSTV82x8( LS_SUB_VOLUME_LSB,  ucVolumeLSB );
1707
1708    return ( ucResult );
1709}
1710
1711
1712
1713
1714
1715
1716/************************************************************************************
1717 * Function:
1718 *  unsigned char STV82x8_ScartOutBalance(unsigned char ucBalance)
1719 * Description:
1720 *  This function set scart out balance to special value.
1721 * Input:
1722 *  scart out balance
1723 *      X X X X     X X X X      X X X X     X X X X
1724 *              -----------------              ---
1725 *                      MSB                                LSB
1726 * Output:
1727 *  None
1728 * Return:
1729 *  STV82X8_I2C_ERROR = I2C's communication is failed.
1730 *  STV82X8_NO_ERROR = successfully set left volume.
1731 ************************************************************************************/
1732unsigned char STV82x8_ScartOutBalance(unsigned char ucBalance)
1733{
1734    unsigned char   ucBlanceMSB, ucResult = STV82X8_NO_ERROR;
1735
1736#ifdef __STV_DEBUG__
1737    STV_FUNCTION;
1738#endif
1739
1740        ucBlanceMSB = (unsigned char)( ucBalance & BALANCE_MSB_MASK );
1741
1742        ucResult  = STV82x8_SetScartVolumeMode( DIFFERENTIAL_MODE );
1743
1744        ucResult  |= I2cWriteSTV82x8( AUX_R_VOL_MSB, ucBlanceMSB );
1745        ucResult  |= I2cWriteSTV82x8( AUX_R_VOL_LSB, DEFAULT_LSB_BALANCE_VALUE );
1746
1747        return ( ucResult );
1748}
1749
1750
1751
1752/************************************************************************************
1753 * Function:
1754 *  unsigned char STV82x8_SetLSBalance(unsigned char ucBalance)
1755 * Description:
1756 *  This function is forcing STV82x8 to process balance of L / R speaker
1757 *      except for Scart Output.
1758 *      --------------------------------------------------------------------------------
1759 *              VOLUME_MODES            LS_L_VOLUME_MSB & LSB   LS_R_VOLUME_MSB & LSB
1760 *              independent                     Left volume                             Right volume
1761 *              differential            L/R volume                              Balance
1762 *  --------------------------------------------------------------------------------
1763 * Input:
1764 *  unsigned char ucBalance: level
1765 * Output:
1766 *  None
1767 * Return:
1768 *  STV82X8_I2C_ERROR = I2C's communication is failed.
1769 *  STV82X8_INVALID_PARAM = Invalid params.
1770 *  STV82X8_NO_ERROR = successfully set LS Balance.
1771 ************************************************************************************/
1772unsigned char STV82x8_SetLSBalance(unsigned char ucBalance)
1773{
1774    unsigned char   ucBlanceMSB, ucResult = STV82X8_NO_ERROR;
1775
1776#ifdef __STV_DEBUG__
1777    STV_FUNCTION;
1778#endif
1779
1780        ucBlanceMSB = (unsigned char)( ucBalance & BALANCE_MSB_MASK );
1781
1782        ucResult = STV82x8_SetVolumeMode( DIFFERENTIAL_MODE );
1783
1784        ucResult |= I2cWriteSTV82x8( LS_R_VOLUME_MSB, ucBlanceMSB );
1785        ucResult |= I2cWriteSTV82x8( LS_R_VOLUME_LSB, DEFAULT_LSB_BALANCE_VALUE );
1786
1787        return ( ucResult );
1788}
1789
1790/**************************************************************************************
1791 * Function:
1792 *  unsigned char STV82x8_SetSurroundBalance(unsigned char ucBalance)
1793 * Description:
1794 *  This function is forcing STV82x8 to process balance of surround.
1795 *      -----------------------------------------------------------------------------
1796 *              VOLUME_MODES    LS_L_VOLUME_MSB & LSB           LS_R_VOLUME_MSB & LSB
1797 *
1798 *          independent                 Left volume                             Right volume
1799 *
1800 *              differential            L/R volume                              Balance
1801 *      ------------------------------------------------------------------------------
1802 * Input:
1803 *  ucBalance = Balance value..
1804 * Output:
1805 *  None
1806 * Return:
1807 *  STV82x8_I2C_ERROR = I2C's communication is failed.
1808 *  STV82x8_INVALID_PARAM = Invalid params.
1809 *  STV82X8_NO_ERROR = No error.
1810 ************************************************************************************/
1811unsigned char STV82x8_SetSurroundBalance(unsigned char ucBalance)
1812{
1813    unsigned char   ucBlanceMSB, ucResult = STV82X8_NO_ERROR;
1814
1815#ifdef __STV_DEBUG__
1816    STV_FUNCTION;
1817#endif
1818
1819        ucBlanceMSB = (unsigned char)( ucBalance & BALANCE_MSB_MASK );
1820
1821        ucResult = STV82x8_SetVolumeMode( DIFFERENTIAL_MODE );
1822
1823        ucResult |= I2cWriteSTV82x8( LS_SR_VOLUME_MSB, ucBlanceMSB );
1824        ucResult |= I2cWriteSTV82x8( LS_SR_VOLUME_LSB, DEFAULT_LSB_BALANCE_VALUE );
1825
1826        return ( ucResult );
1827}
1828
1829
1830
1831/*************************************************************************************
1832 * Function:
1833 *  unsigned char STV82x8_SetHPBalance(unsigned char ucBalance)
1834 * Description:
1835 *  This function is forcing STV82x8 to process balance of HP.
1836 *      -----------------------------------------------------------------------------
1837 *              VOLUME_MODES            LS_L_VOLUME_MSB & LSB           LS_R_VOLUME_MSB & LSB
1838 *
1839 *              independent                             Left volume                                     Right volume
1840 *
1841 *              differential                    L/R volume                                      Balance
1842 *      ------------------------------------------------------------------------------
1843 * Input:
1844 *  ucBalance = Balance value..
1845 * Output:
1846 *  None
1847 * Return:
1848 *  STV82x8_I2C_ERROR = I2C's communication is failed.
1849 *  STV82x8_INVALID_PARAM = Invalid params.
1850 *  STV82X8_NO_ERROR = No error.
1851 *************************************************************************************/
1852unsigned char STV82x8_SetHPBalance(unsigned char ucBalance)
1853{
1854    unsigned char   ucBlanceMSB, ucResult = STV82X8_NO_ERROR ;
1855
1856#ifdef __STV_DEBUG__
1857    STV_FUNCTION;
1858#endif
1859
1860        ucBlanceMSB = (unsigned char)( ucBalance & BALANCE_MSB_MASK );
1861
1862        ucResult = STV82x8_SetVolumeMode( DIFFERENTIAL_MODE );
1863
1864        ucResult |= I2cWriteSTV82x8( HP_R_VOL_MSB, ucBlanceMSB );
1865        ucResult |= I2cWriteSTV82x8( HP_R_VOL_LSB, DEFAULT_LSB_BALANCE_VALUE );
1866
1867        return ( ucResult );
1868}
1869
1870
1871
1872/*************************************************************************************
1873 * Function:
1874 *  unsigned char STV82x8_WakeUpADC(VOID)
1875 * Description:
1876 *  This function wakes up of the ADC.
1877 * Input:
1878 *  None
1879 * Output:
1880 *  None
1881 * Return:
1882 *  STV82X8_I2C_ERROR = I2C's communication is failed.
1883 *  STV82X8_NO_ERROR = successfully set ADC Value.
1884 ************************************************************************************/
1885unsigned char STV82x8_WakeUpADC(VOID)
1886{
1887    unsigned char   ucResult = STV82X8_NO_ERROR;
1888
1889#ifdef __STV_DEBUG__
1890    STV_FUNCTION;
1891#endif
1892
1893        ucResult = STV82x8_DataMaskWrite( ADC_CTRL,
1894                                                                        STV82X8_ADC_WAKEUP_VALUE,
1895                                    STV82X8_ADC_WAKEUP_MASK );
1896
1897        return ( ucResult );
1898}
1899
1900
1901
1902/**************************************************************************************
1903 * Function:
1904 *  unsigned char STV82x8_WakeUpIRQ0(VOID)
1905 * Description:
1906 *  This function wakes up of the IRQ0 for Surge functioin.
1907 * Input:
1908 *  None
1909 * Output:
1910 *  None
1911 * Return:
1912 *  STV82X8_I2C_ERROR = I2C's communication is failed.
1913 *  STV82X8_NO_ERROR = successfully set IRQ 0.
1914 **************************************************************************************/
1915unsigned char STV82x8_WakeUpIRQ0(VOID)
1916{
1917        unsigned char  ucResult = STV82X8_NO_ERROR;
1918
1919#ifdef __STV_DEBUG__
1920    STV_FUNCTION;
1921#endif
1922
1923        ucResult = STV82x8_DataMaskWrite( IRQ_STAT,
1924                                                                        STV82X8_IRQ0_WAKEUP_VALUE,
1925                                    STV82X8_IRQ0_WAKEUP_MASK );
1926        return ( ucResult );
1927}
1928
1929
1930
1931
1932/************************************************************************************
1933 * Function:
1934 *  unsigned char STV82x8_SetHPConfiguration(unsigned char ucHP_Force, unsigned char ucLS_Mute, unsigned char ucHP_Active)
1935 * Description:
1936 *  This function sets head phone configuration register.
1937 * Input:
1938 * Output:
1939 *  None
1940 * Return:
1941 *  STV82x8_I2C_ERROR           = I2C's communication is failed.
1942 *  STV82x8_INVALID_PARAM       = Invalid params
1943 *  STV82X8_NO_ERROR            = No error.
1944 ************************************************************************************/
1945unsigned char STV82x8_SetHPConfiguration(unsigned char ucHP_Force, unsigned char ucLS_Mute, unsigned char ucHP_Active)
1946{
1947    unsigned char   ucResult = STV82X8_NO_ERROR;
1948
1949#ifdef __STV_DEBUG__
1950    STV_FUNCTION;
1951#endif
1952
1953        if( (( ucHP_Force != STV82x8_HP_FORCE_ON ) && ( ucHP_Force != STV82x8_HP_FORCE_OFF )) ||
1954                (( ucLS_Mute != STV82x8_HP_LS_MUTE ) && ( ucLS_Mute != STV82x8_HP_LS_UNMUTE )) ||
1955                (( ucHP_Active != STV82x8_HP_DET_ACTIVE_ON ) && ( ucHP_Active != STV82x8_HP_DET_ACTIVE_OFF )))
1956        {
1957                return ( STV82X8_INVALID_PARAM );
1958        }
1959
1960        ucResult = STV82x8_DataMaskWrite(HEADPHONE_CONFIG,
1961                                                                (unsigned char)( ucHP_Force | ucLS_Mute | ucHP_Active ),
1962                                        STV82X8_HP_CONFIG_MASK );
1963
1964        return ( ucResult );
1965}
1966
1967
1968
1969
1970/**************************************************************************************
1971 * Function:
1972 *  unsigned char STV82x8_GetHPStatus(unsigned char * pucHPStaus)
1973 * Description:
1974 *  This function returns status if HP is detected or not.
1975 * Input:
1976 *  None
1977 * Output:
1978 *  STV82x8_HP_DETECTED                 = HP signal is detected.
1979 *  STV82x8_HP_NOT_DETECTED     = HP signal isn't detected.
1980 * Return:
1981 *  STV82x8_I2C_ERROR           = I2C's communication is failed.
1982 *  STV82x8_INVALID_PARAM       = Invalid params
1983 *  STV82X8_NO_ERROR            = No error.
1984 **************************************************************************************/
1985unsigned char STV82x8_GetHPStatus(unsigned char * pucHPStaus )
1986{
1987    unsigned char   ucRegValue, ucResult = STV82X8_NO_ERROR ;
1988    *pucHPStaus  = STV82x8_HP_NOT_DETECTED;
1989
1990#ifdef __STV_DEBUG__
1991    STV_FUNCTION;
1992#endif
1993
1994        if( pucHPStaus == NULL )
1995        {
1996                return ( STV82X8_INVALID_PARAM );
1997        }
1998
1999        ucResult = I2cReadSTV82x8( HEADPHONE_CONFIG, &ucRegValue );
2000
2001        ucRegValue &= STV82X8_HP_DETECTED_MASK;
2002
2003        if( ucRegValue )
2004                 *pucHPStaus  = STV82x8_HP_DETECTED;
2005        else
2006                 *pucHPStaus  = STV82x8_HP_NOT_DETECTED;
2007
2008    return ( ucResult );
2009}
2010
2011
2012
2013/***************************************************************************************
2014 * Function:
2015 *  unsigned char STV82x8_SetSubWoofer(unsigned char ucSubWoofer, unsigned char ucBassManage, unsigned char ucBassGainSW,
2016 *                             unsigned char ucSTLFEAdd, unsigned char ucDolbyPro, unsigned char ucBassConfNum)
2017 * Description
2018 *  This function sets Bass management and mute register for Subwoofer.
2019 * Input:
2020 *  STV82x8_SUBWOOFER_ON = Subwoofer output is active.
2021 *  STV82x8_SUBWOOFER_OFF = Subwoofer output is disabled.
2022 *  STV82x8_BASSMNGT_ON = BassManagement enabled.
2023 *  STV82x8_BASSMNGT_OFF = BassManagement disables.
2024 *  STV82x8_GAINSW_ON = Level adjustment ON.
2025 *  STV82x8_GAINSW_OFF = Level adjustment OFF.
2026 *  STV82x8_STLFEAdd_ON = Add LFE Signal.
2027 *  STV82x8_STLFEAdd_OFF = No LFE Signal.
2028 *  STV82x8_DolbyPro_ON = DOLBY PROLOGIC Configuration.
2029 *  STV82x8_DolbyPro_OFF = Standard Configuration.
2030 *  STV82x8_BASSCONFI_0 = Bass Management Configuration 0.
2031 *  STV82x8_BASSCONFI_1 = Bass Management Configuration 1.
2032 *  STV82x8_BASSCONFI_2 = Bass Management Configuration 2.
2033 *  STV82x8_BASSCONFI_3 = Bass Management Configuration 3.
2034 *  STV82x8_BASSCONFI_4 = Bass Management Configuration 4.
2035 * Output:
2036 *  None
2037 * Return:
2038 *  STV82x8_I2C_ERROR           = I2C's communication is failed.
2039 *  STV82x8_INVALID_PARAM       = Invalid params
2040 *  STV82X8_NO_ERROR            = No error.
2041 *************************************************************************************/
2042unsigned char STV82x8_SetSubWoofer(unsigned char ucSubWoofer, unsigned char ucBassManage, unsigned char ucBassGainSW,
2043                            unsigned char ucSTLFEAdd, unsigned char ucDolbyPro, unsigned char ucBassConfNum)
2044                           
2045{
2046    unsigned char   ucRegValue, ucResult = STV82X8_NO_ERROR;
2047
2048#ifdef __STV_DEBUG__
2049    STV_FUNCTION;
2050#endif
2051
2052
2053        if(( ucSubWoofer != STV82x8_SUBWOOFER_ON ) && ( ucSubWoofer != STV82x8_SUBWOOFER_OFF ))
2054        {
2055                return ( STV82X8_INVALID_PARAM );
2056        }
2057        if(( ucBassManage != STV82x8_BASSMNGT_ON ) && ( ucBassManage != STV82x8_BASSMNGT_OFF ))
2058        {
2059                return ( STV82X8_INVALID_PARAM );
2060        }
2061        if(( ucBassGainSW != STV82x8_GAINSW_ON ) && ( ucBassGainSW != STV82x8_GAINSW_OFF ))
2062        {
2063                return ( STV82X8_INVALID_PARAM );
2064        }
2065        if(( ucBassGainSW != STV82x8_STLFEAdd_ON ) && ( ucBassGainSW != STV82x8_STLFEAdd_OFF ))
2066        {
2067                return ( STV82X8_INVALID_PARAM );
2068        }
2069        if(( ucBassGainSW != STV82x8_DolbyPro_ON ) && ( ucBassGainSW != STV82x8_DolbyPro_OFF ))
2070        {
2071                return ( STV82X8_INVALID_PARAM );
2072        }
2073        if(( ucBassConfNum != STV82x8_BASSCONFI_0 ) && ( ucBassConfNum != STV82x8_BASSCONFI_1 ) &&
2074                ( ucBassConfNum != STV82x8_BASSCONFI_2 ) && ( ucBassConfNum != STV82x8_BASSCONFI_3 ) &&
2075                ( ucBassConfNum != STV82x8_BASSCONFI_4 ) && ( ucBassConfNum != STV82x8_BASSCONFI_5 ) &&
2076                ( ucBassConfNum != STV82x8_BASSCONFI_6 ))
2077        {
2078                return ( STV82X8_INVALID_PARAM );
2079        }
2080
2081        if( ucSubWoofer == STV82x8_SUBWOOFER_ON )
2082        {
2083                ucResult = STV82x8_DataMaskWrite(MUTE_DIGITAL,
2084                                        STV82x8_MUTEDIG_SUBWOOFER_UNMUTE,
2085                                        STV82x8_MUTEDIG_SUBWOOFER_MASK );
2086                ucResult |= STV82x8_DataMaskWrite(DAC_CTRL,
2087                                                                        STV82x8_DAC_SUBWOOFER_UNMUTE,
2088                                        STV82x8_MUTEDIG_SUBWOOFER_MASK );
2089        }
2090        else if( ucSubWoofer == STV82x8_SUBWOOFER_OFF )
2091        {
2092                ucResult = STV82x8_DataMaskWrite(MUTE_DIGITAL,
2093                                                                        STV82x8_MUTEDIG_SUBWOOFER_MUTE,
2094                                        STV82x8_MUTEDIG_SUBWOOFER_MASK );
2095                ucResult |= STV82x8_DataMaskWrite(DAC_CTRL,
2096                                                                        STV82x8_DAC_SUBWOOFER_MUTE,
2097                                        STV82x8_MUTEDIG_SUBWOOFER_MASK );
2098        }
2099
2100        ucRegValue = ( ucBassManage | ucSTLFEAdd | ucDolbyPro | ucSubWoofer |ucBassGainSW |ucBassConfNum );
2101
2102        ucResult = STV82x8_DataMaskWrite ( OUTPUT_BASS_MNGT, ucRegValue, OUTPUT_BASS_MNGT_MASK );
2103
2104        return ( ucResult );
2105}
2106
2107
2108
2109/*****************************************************************************************
2110 * Function:
2111 *  unsigned char STV82x8_SetPinkNoiseGenerator(unsigned char ucNoiseOn, unsigned char ucSelectSpeaker, unsigned char ucOuputRange)
2112 * Description:
2113 *  This function sets pink noise generator's register.
2114 * Input:
2115 *  STV82x8_NOISE_GENERATIONB_ON = Noise Generation active.
2116 *  STV82x8_NOISE_GENERATIONB_OFF = Noise Generation not active.
2117 *  STV82x8_OUTPUT_FULLRANGE = noise is outputed with full range.
2118 *  STV82x8_OUTPUT_10_DB = noise is outputed with a 10dB attenuation.
2119 *  STV82x8_SRIGHT_NOISE_ON = Level adjustment ON.
2120 *  STV82x8_SLEFT_NOISE_ON = Level adjustment OFF.
2121 *  STV82x8_SUB_NOISE_ON = Bass Management Configuration 0.
2122 *  STV82x8_CENTER_NOISE_ON = Bass Management Configuration 1.
2123 *  STV82x8_RIGHT_NOISE_ON = Bass Management Configuration 2.
2124 *  STV82x8_LEFT_NOISE_ON = Bass Management Configuration 3.
2125 * Output:
2126 *  None
2127 * Return:
2128 *  STV82x8_I2C_ERROR           = I2C's communication is failed.
2129 *  STV82x8_INVALID_PARAM       = Invalid params
2130 *  STV82X8_NO_ERROR            = No error.
2131 *************************************************************************************/
2132unsigned char STV82x8_SetPinkNoiseGenerator(unsigned char ucNoiseOn, unsigned char ucSelectSpeaker, unsigned char ucOuputRange)
2133{
2134    unsigned char   ucRegValue, ucResult = STV82X8_NO_ERROR;
2135
2136#ifdef __STV_DEBUG__
2137    STV_FUNCTION;
2138#endif
2139
2140
2141        if(( ucNoiseOn != STV82x8_NOISE_GENERATIONB_ON ) && ( ucNoiseOn != STV82x8_NOISE_GENERATIONB_OFF ))
2142        {
2143                return ( STV82X8_INVALID_PARAM );
2144        }
2145        if(( ucOuputRange != STV82x8_OUTPUT_FULLRANGE ) && ( ucOuputRange != STV82x8_OUTPUT_10_DB ))
2146        {
2147                return ( STV82X8_INVALID_PARAM );
2148        }
2149        if(( ucSelectSpeaker != STV82x8_SRIGHT_NOISE_ON ) && ( ucSelectSpeaker != STV82x8_SLEFT_NOISE_ON ) &&
2150                ( ucSelectSpeaker != STV82x8_SUB_NOISE_ON ) && ( ucSelectSpeaker != STV82x8_CENTER_NOISE_ON) &&
2151                ( ucSelectSpeaker != STV82x8_RIGHT_NOISE_ON ) && ( ucSelectSpeaker != STV82x8_LEFT_NOISE_ON ))
2152        {
2153                return ( STV82X8_INVALID_PARAM );
2154        }
2155
2156        ucRegValue = ( ucNoiseOn |ucOuputRange |ucSelectSpeaker );
2157
2158        ucResult = I2cWriteSTV82x8( NOISE_GENERATOR, ucRegValue );
2159
2160        return ( ucResult );
2161}
2162
2163
2164/************************************************************************************
2165 * Function:
2166 *  unsigned char STV82x8_SetFMTimeOut(unsigned char ucTimeOut)
2167 * Description:
2168 *  This function set FM search time out to special value.
2169 * Input:
2170 *  FM_TIME_16MS = 16 ms.
2171 *  FM_TIME_32MS = 32 ms.
2172 *  FM_TIME_48MS = 48 ms.
2173 *  FM_TIME_64MS = 64 ms.
2174 * Output:
2175 *  None
2176 * Return:
2177 *  STV82X8_I2C_ERROR = I2C's communication is failed.
2178 *  STV82X8_INVALID_PARAM = Invalid params
2179 *  STV82X8_NO_ERROR = Successfully set time out for Am/Fm.
2180 ************************************************************************************/
2181unsigned char STV82x8_SetFMTimeOut(unsigned char ucTimeOut)
2182{
2183    unsigned char   ucResult = STV82X8_NO_ERROR;
2184
2185#ifdef __STV_DEBUG__
2186    STV_FUNCTION;
2187#endif
2188
2189        ucResult = STV82x8_DataMaskWrite(AUTOSTD_TIME,
2190                                                                ucTimeOut,
2191                                    STV82X8_FM_TIME_MASK );
2192        return ( ucResult );
2193}
2194
2195
2196/************************************************************************************
2197 * Function:
2198 *  unsigned char STV82x8_SetStereoTimeOut(unsigned char ucTimeOut)
2199 * Description:
2200 *  This function set Stereo search time out to special value.
2201 * Input:
2202 *  STEREO_TIME_20MS = 16 ms.
2203 *  STEREO_TIME_40MS = 40 ms.
2204 *  STEREO_TIME_100MS = 100 ms.
2205 *  STEREO_TIME_200MS = 200 ms.
2206 *  STEREO_TIME_400MS = 400 ms.
2207 *  STEREO_TIME_800MS = 800 ms.
2208 *  STEREO_TIME_1200MS = 1200 ms.
2209 *  STEREO_TIME_1600MS = 1600 ms.
2210 * Output:
2211 *  None
2212 * Return:
2213 *  STV82X8_I2C_ERROR = I2C's communication is failed.
2214 *  STV82X8_INVALID_PARAM = Invalid params
2215 *  STV82X8_NO_ERROR = Successfully set time out for Am/Fm.
2216 *************************************************************************************/
2217unsigned char STV82x8_SetStereoTimeOut(unsigned char ucTimeOut)
2218{
2219    unsigned char   ucResult = STV82X8_NO_ERROR;
2220
2221#ifdef __STV_DEBUG__
2222    STV_FUNCTION;
2223#endif
2224
2225        ucResult = STV82x8_DataMaskWrite( AUTOSTD_TIME,
2226                                                                                ucTimeOut,
2227                                                                                STV82X8_STEREO_TIME_MASK );
2228        return ( ucResult );
2229}
2230
2231
2232/*************************************************************************************
2233 * Function:
2234 *  unsigned char STV82x8_SetScartDefaultPrescale(VOID)
2235 * Description:
2236 *  This function set scart's register for prescale to default value.
2237 * Input:
2238 * Output:
2239 *  None
2240 * Return:
2241 *  STV82X8_I2C_ERROR = I2C's communication is failed.
2242 *  STV82X8_NO_ERROR = successfully set prescale for Scart.
2243 *************************************************************************************/
2244unsigned char STV82x8_SetScartDefaultPrescale(VOID)
2245{
2246    unsigned char   ucResult = STV82X8_NO_ERROR;
2247
2248#ifdef __STV_DEBUG__
2249    STV_FUNCTION;
2250#endif
2251
2252        ucResult = I2cWriteSTV82x8( PRESCALE_SCART, SCART_PRESCALING_DEFAULTVALU );
2253
2254        return ( ucResult );
2255}
2256
2257/**************************************************************************************
2258 * Function:
2259 *  unsigned char  STV82x8_SetMonoStereoDefaultPrescale(VOID)
2260 * Description:
2261 *  This function set Am and Fm's register for prescale to default value.
2262 * Input:
2263 * Output:
2264 *  None
2265 * Return:
2266 *  STV82X8_I2C_ERROR = I2C's communication is failed.
2267 *  STV82X8_NO_ERROR = successfully set prescale for Fm/Am.
2268 ***************************************************************************************/
2269unsigned char  STV82x8_SetMonoStereoDefaultPrescale(VOID)
2270{
2271    unsigned char   ucResult = STV82X8_NO_ERROR;
2272
2273#ifdef __STV_DEBUG__
2274    STV_FUNCTION;
2275#endif
2276
2277        ucResult = STV82x8_DataMaskWrite ( PRESCALE_MONO, MONO_PRESCALING_DEFAULTVALU, PRESCALE_MONO_MASK );
2278        ucResult |= I2cWriteSTV82x8 ( PRESCALE_STEREO, STEREO_PRESCALING_DEFAULTVALU );
2279
2280        return ( ucResult );
2281}
2282
2283
2284
2285/**************************************************************************************
2286 * Function:
2287 *  unsigned char STV82x8_SAPDefaultPrescale(VOID)
2288 * Description:
2289 *  This function set Nicam's register for prescale to default value.
2290 * Input:
2291 * Output:
2292 *  None
2293 * Return:
2294 *  STV82X8_I2C_ERROR = I2C's communication is failed.
2295 *  STV82X8_NO_ERROR = Successfully set prescale for Nicam.
2296 *************************************************************************************/
2297unsigned char STV82x8_SAPDefaultPrescale(VOID)
2298{
2299    unsigned char   ucResult = STV82X8_NO_ERROR;
2300
2301#ifdef __STV_DEBUG__
2302    STV_FUNCTION;
2303#endif
2304
2305        ucResult = I2cWriteSTV82x8 ( PRESCALE_SAP, SAP_PRESCALING_DEFAULTVALU );
2306
2307        return ( ucResult );
2308}
2309
2310
2311
2312/***************************************************************************************
2313 * Function:
2314 *  unsigned char STV82x8_I2SDefaultPrescale(unsigned char ucI2SPort, unsigned char ucPreScaleVal)
2315 * Description:
2316 *  This function set Nicam's register for prescale to default value.
2317 * Input:
2318 *  unsigned char ucI2SPort: PRESCALE_I2S_0, PRESCALE_I2S_1 or PRESCALE_I2S_2
2319 *  unsigned char ucPreScale: Prescale value
2320 * Output:
2321 *  None
2322 * Return:
2323 *  STV82X8_I2C_ERROR = I2C's communication is failed.
2324 *  STV82X8_NO_ERROR = Successfully set prescale for Nicam.
2325 ***************************************************************************************/
2326unsigned char STV82x8_I2SDefaultPrescale(unsigned char ucI2SPort, unsigned char ucPreScaleVal)
2327{
2328    unsigned char   ucResult = STV82X8_NO_ERROR;
2329
2330#ifdef __STV_DEBUG__
2331    STV_FUNCTION;
2332#endif
2333
2334        ucResult = I2cWriteSTV82x8 ( ucI2SPort, ucPreScaleVal );
2335
2336        return ( ucResult );
2337}
2338
2339
2340/*****************************************************************************************
2341 * Function:
2342 *  unsigned char STV82x8_SetEqualizerValue(unsigned char ucEqualizerIndex, unsigned char ucEQBandIndex )
2343 * Description:
2344 *  This function executes that STV82x8 is set by special equalizer band's value.
2345 * Input:
2346 *  ucEqualizerIndex =  EQUALIZER_100HZ    = Band 1.
2347 *                                      EQUALIZER_330HZ    = Band 2.
2348 *                                              EQUALIZER_1KHZ     = Band 3.
2349 *                                      EQUALIZER_3P3KHZ  = Band 4.
2350 *                                              EQUALIZER_10KHZ    = Band 5.
2351 *  ucEQBandIndex : Equalizer table index
2352 * Output:
2353 *  None
2354 * Return:
2355 *  STV82X8_I2C_ERROR = I2C's communication is failed.
2356 *  STV82X8_INVALID_PARAM = Invalid params.
2357 *  STV82X8_NO_ERROR = Successfully set Equalizer.
2358 ****************************************************************************************/
2359unsigned char STV82x8_SetEqualizerValue(unsigned char ucEqualizerIndex, unsigned char ucEQBandIndex )
2360{
2361    unsigned char   ucResult = STV82X8_NO_ERROR;
2362
2363#ifdef __STV_DEBUG__
2364    STV_FUNCTION;
2365#endif
2366
2367        if(( ucEqualizerIndex > EQUALIZER_10KHZ ) || ( ucEQBandIndex > sizeof( EQUALIZER_TABLE )))
2368                return ( STV82X8_INVALID_PARAM );
2369
2370//      ucResult = STV82x8_DataMaskWrite ( LS_EQ_BT_CTRL, STV82X8_EQUALIZE_ON, STV82X8_EQUALIZE_MASK );// Josie 8/21
2371
2372        ucResult = I2cWriteSTV82x8((unsigned char)( LS_EQ_BAND + ucEqualizerIndex ),
2373                                (unsigned char)EQUALIZER_TABLE[ucEQBandIndex] );
2374
2375        return ( ucResult );
2376}
2377
2378
2379/***************************************************************************************
2380 * Function:
2381 *  unsigned char STV82x8_SetPseudoEffect(unsigned char ucPseudo)
2382 * Description:
2383 *  This function executes all function in order to change Pseudo On & Off.
2384 *  TV-Set has to save Pseudo On & Off information because TV-Set has to
2385 *      work well, after TV-Set is restarted by Stand-by or AC On.
2386 * Input:
2387 *  On = Pseudo effect ON.
2388 *  Off = Pseudo effect OFF.
2389 * Output:
2390 *  None
2391 * Return:
2392 *  STV82X8_I2C_ERROR = I2C's communication is failed.
2393 *  STV82X8_NO_ERROR = Successfully set Pseudo.
2394 **************************************************************************************/
2395unsigned char STV82x8_SetPseudoEffect(unsigned char ucPseudo)
2396{
2397    unsigned char   ucResult = STV82X8_NO_ERROR;
2398
2399#ifdef __STV_DEBUG__
2400    STV_FUNCTION;
2401#endif
2402
2403        if(( ucPseudo != STV82X8_PSEUDO_ON ) && ( ucPseudo != STV82X8_PSEUDO_OFF ) )
2404        {
2405                return ( STV82X8_INVALID_PARAM );
2406        }
2407
2408        if( ucPseudo == STV82X8_PSEUDO_ON )
2409                ucResult = STV82x8_SetSRS_InputMode( STV82x8_SRS_MONO_LEFT );
2410        else
2411                ucResult = STV82x8_SetSRS_InputMode( STV82X8_ALL_SRS_OFF );
2412
2413        return ( ucResult );
2414}
2415
2416/*************************************************************************************
2417 * Function:
2418 *  unsigned char STV82x8_SetSRSWOW_Effect(unsigned char ucSRSWOW)
2419 * Description:
2420 *  This function executes all function in order to change SRS On & Off.
2421 *  TV-Set has to save SRS On & Off information because TV-Set has to
2422 *      work well, after TV-Set is restarted by Stand-by or AC On.
2423 * Input:
2424 *  On = SRS effect ON.
2425 *  Off = SRS effect OFF.
2426 * Output:
2427 *  None
2428 * Return:
2429 *  STV82X8_I2C_ERROR = I2C's communication is failed.
2430 *  STV82X8_NO_ERROR = Successfully set SRS.
2431 *************************************************************************************/
2432unsigned char STV82x8_SetSRSWOW_Effect(unsigned char ucSRSWOW)
2433{
2434        unsigned char   ucResult = STV82X8_NO_ERROR;
2435
2436#ifdef __STV_DEBUG__
2437    STV_FUNCTION;
2438#endif
2439
2440        if(( ucSRSWOW != STV82x8_SRS_WOW_ON ) && ( ucSRSWOW != STV82x8_SRS_WOW_OFF ) )
2441        {
2442                return ( STV82X8_INVALID_PARAM );
2443        }
2444
2445        if( ucSRSWOW == STV82x8_SRS_WOW_ON )
2446                ucResult = STV82x8_SetSRS_InputMode( STV82x8_SRS_LR_STEREO );
2447        else
2448                ucResult = STV82x8_SetSRS_InputMode( STV82X8_ALL_SRS_OFF );
2449
2450        return ( ucResult );
2451}
2452
2453
2454
2455
2456/***************************************************************************************
2457 * Function:
2458 *  unsigned char STV82x8_SetSRSTRS_DolbyPro1_Effect(unsigned char ucSRS_TruSurround, unsigned char ucDolby_ProLogic1)
2459 * Description:
2460 *  This function executes all function in order to change SRS On & Off.
2461 *      TV-Set has to save SRS On & Off information because TV-Set has to
2462 *      work well, after TV-Set is restarted by Stand-by or AC On.
2463 * Input:
2464 *  On = SRS effect ON.
2465 *  Off = SRS effect OFF.
2466 * Output:
2467 *  None
2468 * Return:
2469 *  STV82X8_I2C_ERROR = I2C's communication is failed.
2470 *  STV82X8_NO_ERROR = Successfully set SRS.
2471 ****************************************************************************************/
2472unsigned char STV82x8_SetSRSTRS_DolbyPro1_Effect(unsigned char ucSRS_TruSurround, unsigned char ucDolby_ProLogic1 )
2473{
2474    unsigned char   ucResult = STV82X8_NO_ERROR;
2475
2476#ifdef __STV_DEBUG__
2477    STV_FUNCTION;
2478#endif
2479
2480        if(( ucSRS_TruSurround != STV82x8_SRS_TRX_ON ) && ( ucSRS_TruSurround != STV82x8_SRS_TRX_OFF ) )
2481        {
2482                return ( STV82X8_INVALID_PARAM );
2483        }
2484        if(( ucDolby_ProLogic1 != STV82x8_DOLBY_PRO1_ON ) && ( ucDolby_ProLogic1 != STV82x8_DOLBY_PRO1_OFF ) )
2485        {
2486                return ( STV82X8_INVALID_PARAM );
2487        }
2488
2489        if( ucSRS_TruSurround == STV82x8_SRS_TRX_OFF )
2490        {
2491                ucResult = STV82x8_SetSRS_InputMode( STV82X8_ALL_SRS_OFF );
2492        }
2493        else if( ucDolby_ProLogic1 == STV82x8_DOLBY_PRO1_OFF )
2494        {
2495                ucResult = STV82x8_SetSRS_InputMode( STV82x8_SRS_LRC );
2496        }
2497        else if( ucDolby_ProLogic1 == STV82x8_DOLBY_PRO1_ON )
2498        {
2499                ucResult = STV82x8_SetSRS_InputMode( STV82x8_SRS_LRCS );
2500        }
2501
2502        return ( ucResult );
2503}
2504
2505
2506/****************************************************************************************
2507 * Function:
2508 *  unsigned char STV82x8_ControlTurboSound(unsigned char ucTurbo, unsigned char ucLoudnessIndex )
2509 * Description:
2510 *  This function executes all things which are related to turbo control and
2511 *      forced STV82x8 is set by turbo control register to values of special
2512 *      volume tables.
2513 * Input:
2514 *  On = Turbo effect ON.
2515 *  Off = Turbo effect OFF.
2516 * Output:
2517 *  None
2518 * Return:
2519 *  STV82X8_I2C_ERROR = I2C's communication is failed.
2520 *  STV82X8_NO_ERROR = Successfully set Turbo sound.
2521 ***************************************************************************************/
2522unsigned char STV82x8_ControlTurboSound(unsigned char ucTurbo, unsigned char ucLoudnessIndex )
2523{
2524    unsigned char  ucLoudNess, ucResult = STV82X8_NO_ERROR;
2525
2526#ifdef __STV_DEBUG__
2527    STV_FUNCTION;
2528#endif
2529
2530
2531        if( ucTurbo == STV82X8_TURBO_SOUND_ON )
2532        {
2533                ucLoudNess = ( ( LOUDNESS_TABLE[ucLoudnessIndex] << 1 ) | STV82X8_LOUNDNESS_ENABLE );
2534                ucResult = STV82x8_DataMaskWrite ( LS_LOUDNESS, ucLoudNess, LS_LOUDNESS_MASK );
2535        }
2536        else if( ucTurbo == STV82X8_TURBO_SOUND_OFF )
2537        {
2538                for( ucLoudNess = LOUDNESS_TABLE[ucLoudnessIndex]; ucLoudNess > 0; ucLoudNess-- )
2539                {
2540                        ucResult = STV82x8_DataMaskWrite ( LS_LOUDNESS, (unsigned char) ((ucLoudNess << 1) | STV82X8_LOUNDNESS_ENABLE), LS_LOUDNESS_MASK );
2541                        usleep( 100 ); //5ms
2542                }
2543                        ucResult = STV82x8_DataMaskWrite ( LS_LOUDNESS, STV82X8_LOUNDNESS_DISABLE, LS_LOUDNESS_MASK );
2544
2545        }
2546        else
2547        {
2548                ucResult = (unsigned char)( STV82X8_INVALID_PARAM );
2549        }
2550
2551        return ( ucResult );
2552}
2553
2554
2555/*************************************************************************************
2556 * Function:
2557 *  unsigned char STV82x8_AutoVolumeCtrl(unsigned char ucSvcSel)
2558 * Description:
2559 *  This function executes all things which are related to auto volume control and
2560 *      forced STV82x8 is set by auto volume control register to values of special
2561 *      volume tables.
2562 * Input:
2563 *  SvcSel = Auto volume on & off.
2564 * Output:
2565 *  None
2566 * Return:
2567 *  STV82X8_I2C_ERROR = I2C's communication is failed.
2568 *  STV82X8_NO_ERROR = Successfully set Auto volume.
2569 ************************************************************************************/
2570unsigned char STV82x8_AutoVolumeCtrl(unsigned char ucSvcSel)
2571{
2572    unsigned char   i, ucResult = STV82X8_NO_ERROR;
2573
2574#ifdef __STV_DEBUG__
2575    STV_FUNCTION;
2576#endif
2577
2578        if( ucSvcSel == STV82x8_SVC_ON )
2579        {
2580                ucResult = I2cWriteSTV82x8 ( SVC_LS_TIME_TH, STV82X8_SVC_30MSCONST_0DBGAIN );
2581                ucResult |= I2cWriteSTV82x8 ( SVC_LS_TIME_TH, STV82X8_SVC_30MSCONST_205DBGAIN );
2582
2583                for( i = 0;  i < STV82X8_LS_HP_MAKE_UP_GAIN_AUTOON; i++ )
2584                {
2585                        I2cWriteSTV82x8 ( SVC_LS_GAIN, i );
2586                }
2587
2588                ucResult |= I2cWriteSTV82x8 ( SVC_LS_TIME_TH, STV82X8_SVC_16MSCONST_205DBGAIN  );
2589
2590                ucResult |= STV82x8_DataMaskWrite( SVC_LS_CONTROL, STV82X8_AUTOSVC_ON, STV82X8_SVCON_MASK );
2591        }
2592        else if( ucSvcSel == STV82x8_SVC_OFF )
2593        {
2594                ucResult = I2cWriteSTV82x8 ( SVC_LS_TIME_TH, STV82X8_SVC_30MSCONST_205DBGAIN  );
2595                ucResult |= I2cWriteSTV82x8 ( SVC_LS_TIME_TH, STV82X8_SVC_30MSCONST_0DBGAIN  );
2596
2597                for( i = STV82X8_LS_HP_MAKE_UP_GAIN_AUTOON;  i > 0; i-- )
2598                {
2599                        I2cWriteSTV82x8 ( SVC_LS_GAIN, i );
2600                }
2601
2602                usleep( 1500 ); //100ms
2603
2604                ucResult |= STV82x8_DataMaskWrite( SVC_LS_CONTROL, STV82X8_AUTOSVC_OFF, STV82X8_SVCON_MASK );
2605        }
2606        else
2607        {
2608                ucResult = (unsigned char)( STV82X8_INVALID_PARAM );
2609        }
2610
2611        return ( ucResult );
2612}
2613
2614
2615
2616/*************************************************************************************
2617 * Function:
2618 *  unsigned char STV82x8_AutoVolumeHPCtrl(unsigned char ucSvcSel)
2619 * Description:
2620 *  This function executes all things which are related to HeadPhone auto volume
2621 *  control and forced STV82x8 is set by auto volume control register to values
2622 *  of special volume tables.
2623 * Input:
2624 *  SvcSel = HP Auto volume on & off.
2625 * Output:
2626 *  None
2627 * Return:
2628 *  STV82X8_I2C_ERROR = I2C's communication is failed.
2629 *  STV82X8_NO_ERROR = Successfully set Auto volume.
2630 ************************************************************************************/
2631unsigned char STV82x8_AutoVolumeHPCtrl(unsigned char ucSvcSel)
2632{
2633    unsigned char   i, ucResult = STV82X8_NO_ERROR;
2634
2635#ifdef __STV_DEBUG__
2636    STV_FUNCTION;
2637#endif
2638    if( ucSvcSel == STV82x8_SVC_ON )
2639    {
2640      ucResult = I2cWriteSTV82x8 ( SVC_HP_TIME_TH, STV82X8_SVC_30MSCONST_0DBGAIN );
2641      ucResult |= I2cWriteSTV82x8 ( SVC_HP_TIME_TH, STV82X8_SVC_30MSCONST_205DBGAIN );
2642
2643      for( i = 0;  i < STV82X8_LS_HP_MAKE_UP_GAIN_AUTOON; i++ )
2644      {
2645          I2cWriteSTV82x8 ( SVC_HP_GAIN, i );
2646        }
2647
2648     ucResult |= I2cWriteSTV82x8 ( SVC_HP_TIME_TH, STV82X8_SVC_16MSCONST_205DBGAIN  );
2649
2650     ucResult |= STV82x8_DataMaskWrite( SVC_HP_CONTROL, STV82X8_AUTOSVC_ON, STV82X8_SVCON_MASK );
2651    }
2652    else if( ucSvcSel == STV82x8_SVC_OFF )
2653    {
2654        ucResult = I2cWriteSTV82x8 ( SVC_HP_TIME_TH, STV82X8_SVC_30MSCONST_205DBGAIN  );
2655        ucResult |= I2cWriteSTV82x8 ( SVC_HP_TIME_TH, STV82X8_SVC_30MSCONST_0DBGAIN  );
2656
2657       for( i = STV82X8_LS_HP_MAKE_UP_GAIN_AUTOON;  i > 0; i-- )
2658      {
2659          I2cWriteSTV82x8 ( SVC_HP_GAIN, i );
2660        }
2661
2662     usleep( 1500 ); //100ms
2663
2664       ucResult |= STV82x8_DataMaskWrite( SVC_HP_CONTROL, STV82X8_AUTOSVC_OFF, STV82X8_SVCON_MASK );
2665  }
2666  else
2667   {
2668      ucResult = (unsigned char)( STV82X8_INVALID_PARAM );
2669   }
2670
2671 return ( ucResult );
2672}
2673
2674
2675/***************************************************************************************
2676 * Function:
2677 *  unsigned char STV82x8_SetOutput_RFConfig(VOID)
2678 * Description:
2679 *  Configure RF for Input & Output.
2680 *              < RF > ------------------- <  BTSC MOD >  -----------> [LS]
2681 *              < MONO_IN> --- <ADC>
2682 *              [SC1] ----------------------------------------------> [SC2]
2683 * Input:
2684 * Output:
2685 *  None
2686 * Return:
2687 *  STV82X8_I2C_ERROR = I2C's communication is failed.
2688 *  STV82X8_NO_ERROR = Success.
2689 ***************************************************************************************/
2690unsigned char STV82x8_SetOutput_RFConfig(VOID)
2691{
2692    unsigned char  ucRegVal, ucResult = STV82X8_NO_ERROR;
2693
2694#ifdef __STV_DEBUG__
2695    STV_FUNCTION;
2696#endif
2697
2698        ucResult = I2cReadSTV82x8( ADC_CTRL, &ucRegVal );
2699        if(( ucRegVal & STV82X8_ADC_WAKEUP_MASK ) == 0 )
2700        {
2701                ucResult |= STV82x8_DataMaskWrite ( (unsigned char)ADC_CTRL, (unsigned char)( ucRegVal | STV82X8_ADC_WAKEUP_MASK ), STV82X8_ADC_WAKEUP_MASK );
2702                usleep( 500 ); //35ms
2703        }
2704
2705    // loadspeaker
2706        ucResult |= STV82x8_DataMaskWrite ( AUDIO_MATRIX1_INPUT, STV82X8_AUDIOINPUT_BTSC_DEM, STV82X8_MATRIX1_INPUT_MASK );
2707    // headphone
2708    ucResult |= STV82x8_DataMaskWrite ( AUDIO_MATRIX1_INPUT, (STV82X8_AUDIOINPUT_BTSC_DEM << 3), (STV82X8_MATRIX1_INPUT_MASK << 3) );   
2709    // SPDIF out
2710    ucResult |= STV82x8_DataMaskWrite( AUDIO_MATRIX3_INPUT, STV82X8_AUDIOINPUT_BTSC_DEM<<3, STV82X8_MATRIX3_INPUT_MASK );
2711   
2712        ucResult |= STV82x8_DataMaskWrite ( ADC_CTRL, ( STV82X8_ADC_WAKEUP_MASK | STV82X8_ADCINPUT_MONO ), ( STV82X8_ADC_WAKEUP_MASK | STV82X8_ADCINPUT_MASK) );
2713        ucResult |= STV82x8_DataMaskWrite ( SCART1_2_OUTPUT_CTRL, SCARTOUT_SC2OUT_SC1_DSP, STV82X8_SCARTOUT_SC2OUT_MASK );
2714
2715        return ( ucResult );
2716}
2717
2718
2719/****************************************************************************************
2720 * Function:
2721 *  unsigned char STV82x8_SetOutput_I2SConfig(VOID)
2722 * Description:
2723 *  Configure I2S for Input & Output.
2724 *              <Tuner> ------------------- < I2S >  -----------> [LS]
2725 *              < MONO_IN> --- <ADC>
2726 *              [SC1] ----------------------------------------------> [SC2]
2727 * Input:
2728 * Output:
2729 *  None
2730 * Return:
2731 *  STV82X8_I2C_ERROR = I2C's communication is failed.
2732 *  STV82X8_NO_ERROR = Success.
2733 ****************************************************************************************/
2734unsigned char STV82x8_SetOutput_I2SConfig(VOID)
2735{
2736        unsigned char  ucRegVal, ucResult = STV82X8_NO_ERROR;
2737
2738#ifdef __STV_DEBUG__
2739    STV_FUNCTION;
2740#endif
2741
2742        ucResult = I2cReadSTV82x8( ADC_CTRL, &ucRegVal );
2743        if(( ucRegVal & STV82X8_ADC_WAKEUP_MASK ) == 1 )
2744        {
2745                ucResult |= STV82x8_DataMaskWrite ( (unsigned char)ADC_CTRL, 0, STV82X8_ADC_WAKEUP_MASK );
2746                usleep( 500 ); //35ms
2747        }
2748    // LS output
2749        ucResult |= STV82x8_DataMaskWrite ( AUDIO_MATRIX1_INPUT, STV82X8_AUDIOINPUT_I2S, STV82X8_MATRIX1_INPUT_MASK );
2750    // Headphone output
2751    ucResult |= STV82x8_DataMaskWrite ( AUDIO_MATRIX1_INPUT, (STV82X8_AUDIOINPUT_I2S << 3), (STV82X8_MATRIX1_INPUT_MASK << 3) );
2752    // SPDIF out
2753    ucResult |= STV82x8_DataMaskWrite( AUDIO_MATRIX3_INPUT, (STV82X8_AUDIOINPUT_I2S << 3), STV82X8_MATRIX3_INPUT_MASK );
2754        return ( ucResult );
2755}
2756
2757
2758/*************************************************************************************
2759 * Function:
2760 *  unsigned char STV82x8_SetInOutput_ScartConfig(unsigned char ScartNo)
2761 * Description:
2762 *  Configure SCART for Input & Output.
2763 *      SC1_IN ----->ADC-----> LS_OUT
2764 *              SC2_IN ----->
2765 *              SC3_IN------>
2766 *              SC1_IN ---------------> SC1_OUT
2767 *              SC2_IN ---------------> SC2_OUT
2768 *              SC3_IN----------------> SC3_OUT
2769 * Input:
2770 *  ScartNo     = STV82X8_INPUT_AV1 [0x01].
2771 *                              = STV82X8_INPUT_AV2 [0x02].
2772 *                          = STV82X8_INPUT_AV3 [0x03].
2773 * Output
2774 *  None
2775 * Return:
2776 *  STV82X8_I2C_ERROR = I2C's communication is failed.
2777 *  STV82X8_INVALID_PARAM = Invalid params.
2778 *  STV82X8_NO_ERROR = Success.
2779 ************************************************************************************/
2780//unsigned char STV82x8_SetInOutput_ScartConfig(unsigned char ucInputAV)  ScartNo_t
2781unsigned char STV82x8_SetInOutput_ScartConfig(ScartNo_t ScartNo)
2782{
2783    unsigned char  ucRegVal, ucResult = STV82X8_NO_ERROR;
2784
2785#ifdef __STV_DEBUG__
2786    STV_FUNCTION;
2787#endif
2788
2789        ucResult = I2cReadSTV82x8( ADC_CTRL, &ucRegVal );
2790        if(( ucRegVal & STV82X8_ADC_WAKEUP_MASK ) == 0 )
2791        {
2792                ucResult |= STV82x8_DataMaskWrite ( (unsigned char)ADC_CTRL, (unsigned char)( ucRegVal | STV82X8_ADC_WAKEUP_MASK ), STV82X8_ADC_WAKEUP_MASK );
2793            usleep( 500 ); //35ms
2794        }
2795
2796    // LS output
2797        ucResult |= STV82x8_DataMaskWrite ( AUDIO_MATRIX1_INPUT, STV82X8_AUDIOINPUT_SCART, STV82X8_MATRIX1_INPUT_MASK );
2798 
2799    // headphone output
2800    ucResult |= STV82x8_DataMaskWrite ( AUDIO_MATRIX1_INPUT, (STV82X8_AUDIOINPUT_SCART << 3), (STV82X8_MATRIX1_INPUT_MASK << 3) );
2801       
2802    //set SPDIF out from SCART input
2803        ucResult |= STV82x8_DataMaskWrite( AUDIO_MATRIX3_INPUT, STV82X8_AUDIOINPUT_SCART<<3, STV82X8_MATRIX3_INPUT_MASK );
2804
2805        switch( ScartNo )
2806        {
2807                case SCART_INPUT1:
2808                        ucResult |= STV82x8_DataMaskWrite( ADC_CTRL, ( STV82X8_ADC_WAKEUP_MASK | STV82X8_SCARTINPUT_SC1 ), ( STV82X8_ADC_WAKEUP_MASK | STV82X8_MATRIX1_INPUT_MASK ));
2809                        ucResult |= STV82x8_DataMaskWrite( SCART1_2_OUTPUT_CTRL, SCARTOUT_SC2OUT_SC1_DSP, STV82X8_SCARTOUT_SC2OUT_MASK );
2810                        break;
2811         
2812                case SCART_INPUT2:
2813                        ucResult |= STV82x8_DataMaskWrite( ADC_CTRL, ( STV82X8_ADC_WAKEUP_MASK | STV82X8_SCARTINPUT_SC2 ), ( STV82X8_ADC_WAKEUP_MASK | STV82X8_MATRIX1_INPUT_MASK ));
2814                        ucResult |= STV82x8_DataMaskWrite( SCART1_2_OUTPUT_CTRL, SCARTOUT_SC2OUT_SC2_DSP, STV82X8_SCARTOUT_SC2OUT_MASK );
2815                        break;
2816         
2817                case SCART_INPUT3:
2818                        ucResult |= STV82x8_DataMaskWrite( ADC_CTRL, ( STV82X8_ADC_WAKEUP_MASK | STV82X8_SCARTINPUT_SC3 ), ( STV82X8_ADC_WAKEUP_MASK | STV82X8_MATRIX1_INPUT_MASK ));
2819                        ucResult |= STV82x8_DataMaskWrite( SCART1_2_OUTPUT_CTRL, SCARTOUT_SC2OUT_SC3_DSP, STV82X8_SCARTOUT_SC2OUT_MASK );
2820                        break;
2821               
2822                case SCART_INPUT4:
2823                        ucResult |= STV82x8_DataMaskWrite( ADC_CTRL, ( STV82X8_ADC_WAKEUP_MASK | STV82X8_SCARTINPUT_SC4 ), ( STV82X8_ADC_WAKEUP_MASK | STV82X8_MATRIX1_INPUT_MASK ));
2824                        ucResult |= STV82x8_DataMaskWrite( SCART1_2_OUTPUT_CTRL, SCARTOUT_SC2OUT_SC4_DSP, STV82X8_SCARTOUT_SC2OUT_MASK );
2825                        break;
2826
2827                default:
2828                        ucResult |= STV82X8_INVALID_PARAM;
2829                        break;
2830        }
2831
2832    return(ucResult);
2833}
2834
2835
2836/**************************************************************************************
2837 * Function:
2838 *  unsigned char STV82x8_AudioMatrix_LSOut (unsigned char ucInput )
2839 * Description:
2840 *  This function select Input mode then output LS
2841 * Input:
2842 *  Input to DEMOD Backend
2843 *  unsigned char ucInput: 000b: Mute output
2844 *                 001b: Delay Input
2845 *                 010b: BTSC Demod Input
2846 *                 011b: Downmix LtRtInput
2847 *                 100b: I2S Input
2848 *                 101b: SCART Input
2849 * Return:
2850 *  STV82X8_I2C_ERROR = I2C's communication is failed.
2851 *  STV82X8_NO_ERROR = Success.
2852 **************************************************************************************/
2853unsigned char STV82x8_AudioMatrix_LSOut (unsigned char ucInput )
2854{
2855    unsigned char   ucResult = STV82X8_NO_ERROR;
2856
2857#ifdef __STV_DEBUG__
2858    STV_FUNCTION;
2859#endif
2860
2861        ucResult |= STV82x8_DataMaskWrite( AUDIO_MATRIX1_INPUT, ucInput, STV82X8_MATRIX1_INPUT_MASK );
2862
2863    return(ucResult);
2864}
2865
2866
2867
2868/**************************************************************************************
2869 * Function:
2870 *  unsigned char STV82x8_AudioMatrix_HeadphoneOut (unsigned char ucInput )
2871 * Description:
2872 *  This function select Input mode then output HP
2873 * Input:
2874 *  Input to DEMOD Backend
2875 *  unsigned char ucInput: 000b: Mute output
2876 *                 001b: Delay Input
2877 *                 010b: BTSC Demod Input
2878 *                 011b: Downmix LtRtInput
2879 *                 100b: I2S Input
2880 *                 101b: SCART Input
2881 * Output:
2882 *  None
2883 * Return:
2884 *  STV82X8_I2C_ERROR = I2C's communication is failed.
2885 *  STV82X8_NO_ERROR = Success.
2886 **************************************************************************************/
2887unsigned char STV82x8_AudioMatrix_HeadphoneOut (unsigned char ucInput )
2888{
2889    unsigned char   ucResult = STV82X8_NO_ERROR;
2890
2891#ifdef __STV_DEBUG__
2892    STV_FUNCTION;
2893#endif
2894
2895    ucResult |= STV82x8_DataMaskWrite( AUDIO_MATRIX1_INPUT, (ucInput << 3), (STV82X8_MATRIX1_INPUT_MASK << 3));
2896
2897    return(ucResult);
2898}
2899
2900
2901/**************************************************************************************
2902 * Function:
2903 *  unsigned char STV82x8_Control_ChannelMatrixLS (unsigned char ucInput )
2904 * Description:
2905 *  This function change ChannelMatrix for LS (Manual Mode)
2906 * Input:
2907 *  ucInput
2908 * Output:
2909 *  None
2910 * Return:
2911 *  STV82X8_I2C_ERROR = I2C's communication is failed.
2912 *  STV82X8_NO_ERROR = Success.
2913 *************************************************************************************/
2914unsigned char STV82x8_Control_ChannelMatrixLS (unsigned char ucInput )
2915{
2916    unsigned char   ucResult = STV82X8_NO_ERROR;
2917
2918#ifdef __STV_DEBUG__
2919    STV_FUNCTION;
2920#endif
2921
2922        ucResult |= STV82x8_DataMaskWrite( CHANNEL_MATRIX_LS, (unsigned char) (ucInput),
2923                                     (CM_MATRIX_LS_MASK | AUTOSTD_CTRL_LS_MASK) );
2924
2925        return(ucResult);
2926}
2927
2928
2929
2930/***************************************************************************************
2931 * Function:
2932 *  unsigned char STV82x8_Set_SPDIFOut (unsigned char Input1,  unsigned char Input2)
2933 * Description:
2934 *      This function set SPDIFOut & select Int/Ext.
2935 * Input:
2936 *  Input1, Input2
2937 * Output:
2938 *  None
2939 * Return:
2940 *  STV82X8_I2C_ERROR = I2C's communication is failed.
2941 *  STV82X8_NO_ERROR = Success.
2942 ***************************************************************************************/
2943unsigned char STV82x8_Set_SPDIFOut (unsigned char Input1,  unsigned char Input2)
2944{
2945        unsigned char  ucResult = STV82X8_NO_ERROR;
2946    unsigned char  ucMute = 0; 
2947
2948#ifdef __STV_DEBUG__
2949    STV_FUNCTION;
2950#endif
2951
2952    ucResult = I2cReadSTV82x8(MUTE_DIGITAL, &ucMute);
2953   
2954    if(Input1 == External_SPDIF)
2955    {
2956        if( (ucMute & STV82X8_DIGITAL_SPDIF_MUTE) == 0)
2957            ucResult |= STV82x8_DataMaskWrite( DAC_CTRL, Input1, STV82x8_MUX_MASK );
2958    }
2959    else
2960    {
2961           ucResult |= STV82x8_DataMaskWrite( DAC_CTRL, Input1, STV82x8_MUX_MASK );
2962    }
2963
2964        ucResult |= STV82x8_DataMaskWrite( CHANNEL_MATRIX_SPDIF, Input2, STV82x8_CMMATRIX_SPDIF_MASK );
2965
2966        return(ucResult);
2967}
2968
2969
2970
2971
2972/**************************************************************************************
2973 * Function:
2974 *  unsigned char STV82x8_RefreshSTV(VOID)
2975 * Description:
2976 *  Reinitialize STV82x8
2977 * Input:
2978 * Output:
2979 *  None
2980 * Return:
2981 *  STV82X8_I2C_ERROR = I2C's communication is failed.
2982 *  STV82X8_INVALID_PARAM = Invalid params.
2983 *  STV82X8_NO_ERROR = Success.
2984 * ************************************************************************************/
2985unsigned char STV82x8_RefreshSTV(VOID)
2986{
2987    unsigned char   ucResult = STV82X8_NO_ERROR;
2988
2989#ifdef __STV_DEBUG__
2990    STV_FUNCTION;
2991#endif
2992
2993        ucResult = STV82x8_Initialize(gI2C_num,gSlaveAddr);
2994        ucResult |= STV82x8_SetOutput_RFConfig();
2995
2996        return(ucResult);
2997}
2998
2999
3000
3001/**********************************************************************************
3002 * Function:
3003 *  unsigned char STV82x8_CheckElectricalShock(VOID)
3004 * Description:
3005 *  Sometimes TV-Set is forcing electrical shock to STV82x8.
3006 *      In case of this, TV-Set has to restart and then must happen to good sound signal.
3007 * Input:
3008 * Output:
3009 *  None
3010 * Return:
3011 *  STV82X8_I2C_ERROR = I2C's communication is failed.
3012 *  STV82X8_INVALID_PARAM = Invalid params.
3013 *  STV82X8_NO_ERROR = Success.
3014 *********************************************************************************/
3015unsigned char STV82x8_CheckElectricalShock(VOID)
3016{
3017    unsigned char   ucRegValue, ucResult = STV82X8_NO_ERROR;
3018
3019#ifdef __STV_DEBUG__
3020    STV_FUNCTION;
3021#endif
3022
3023        ucResult = I2cReadSTV82x8( IRQ_STAT, &ucRegValue );
3024
3025        if( !( ucRegValue & ( STV82X8_IRQ0_MASK | STV82X8_IRQ3_MASK )) )
3026                ucResult = STV82x8_RefreshSTV();
3027
3028    return ( ucResult );
3029}
3030
3031
3032/*************************************************************************************
3033 * Function:
3034 *  unsigned char STV82x8_AutoSearch(unsigned char * pucSoundSystem )
3035 * Description:
3036 *  This function must be called by external function whenever auto search is executed.
3037 * Input:
3038 *  None.
3039 * Output:
3040 *  unsigned char * pucSoundSystem:sound mode
3041 * Return:
3042 *  STV82X8_I2C_ERROR = I2C's communication is failed.
3043 *  STV82X8_RESOURCE_ERROR = Resource error
3044 *  STV82X8_NO_ERROR = Success.
3045 ************************************************************************************/
3046unsigned char STV82x8_AutoSearch(unsigned char * pucSoundSystem )
3047{
3048    unsigned char   ucSoundSystem,  ucResult = STV82X8_NO_ERROR;
3049
3050#ifdef __STV_DEBUG__
3051    STV_FUNCTION;
3052#endif
3053
3054        ucResult = STV82x8_All_SoundSystem_Check();
3055
3056        usleep( 1000 ); //150ms
3057
3058        ucResult |= STV82x8_GetSoundSystem(&ucSoundSystem, TRUE);
3059
3060        if(ucSoundSystem == NOTFOUND_SOUND)
3061                return ( STV82X8_RESOURCE_ERROR );
3062
3063         *pucSoundSystem = ucSoundSystem;
3064
3065    return(ucResult);
3066}
3067
3068
3069/****************************************************************************************
3070 * Function:
3071 *  unsigned char STV82x8_ForcedMono(VOID)
3072 * Description:
3073 *  If sound mode is changed by the special remote key for forced Fm mono,
3074 *  STV82x8 has to response to correct action
3075 * Input:
3076 * Output:
3077 *  None
3078 * Return:
3079 *  STV82X8_I2C_ERROR = I2C's communication is failed.
3080 *  STV82X8_NO_ERROR = Success.
3081 ***************************************************************************************/
3082unsigned char STV82x8_ForcedMono(VOID)
3083{
3084    unsigned char   ucResult = STV82X8_NO_ERROR;
3085
3086#ifdef __STV_DEBUG__
3087    STV_FUNCTION;
3088#endif
3089
3090        ucResult = STV82x8_DataMaskWrite( AUTOSTD_CTRL, STV82X8_AUTOSTD_MONO_CHECK, STV82X8_AUTOSTD_CHECK_MASK);
3091
3092        return ( ucResult );
3093}
3094
3095
3096
3097/****************************************************************************************
3098 * Function:
3099 *  unsigned char STV82x8_ReturnToStereoFromMono(VOID)
3100 * Description:
3101 *  If sound mode is changed by the special remote key for forced stereo,
3102 *      STV82x8 has to response to correct action.
3103 * Input:
3104 * Output:
3105 *  None
3106 * Return:
3107 *  STV82X8_I2C_ERROR = I2C's communication is failed.
3108 *  STV82X8_NO_ERROR = Success.
3109 * **************************************************************************************/
3110unsigned char STV82x8_ReturnToStereoFromMono(VOID)
3111{
3112    unsigned char   ucResult = STV82X8_NO_ERROR;
3113
3114#ifdef __STV_DEBUG__
3115    STV_FUNCTION;
3116#endif
3117
3118        ucResult = STV82x8_DataMaskWrite( AUTOSTD_CTRL, STV82X8_AUTOSTD_STEREO_CHECK,
3119                                     STV82X8_AUTOSTD_CHECK_MASK );
3120
3121        return(ucResult);
3122}
3123
3124
3125
3126/*****************************************************************************************
3127 * Function:
3128 *  unsigned char STV82x8_PlayBeeperSound(VOID)
3129 * Description:
3130 *  This function happens to beeper sound.
3131 * Input:
3132 * Output:
3133 *  None
3134 * Return:
3135 *  STV82X8_I2C_ERROR = I2C's communication is failed.
3136 *  STV82X8_NO_ERROR = Success.
3137 ****************************************************************************************/
3138unsigned char STV82x8_PlayBeeperSound(VOID)
3139{
3140    unsigned char   ucRegVal, ucFreqVol, ucResult = STV82X8_NO_ERROR;
3141    unsigned char   i,  ucCount = 0;
3142
3143#ifdef __STV_DEBUG__
3144    STV_FUNCTION;
3145#endif
3146
3147        ucResult = STV82x8_SetDigitalMute(STV82x8_MUTE_ALL_OUTPUT, STV82x8_ALL_OUTPUT_MASK);
3148
3149        STV82x8_DataMaskWrite( BEEPER_MODE, ( STV82X8_BEEPER_PULSE | STV82X8_BEEPEROUT_LS ),
3150                        ( STV82X8_BEEPER_PULSE_MASK | STV82X8_BEEPEROUT_LS_MASK ));
3151        usleep( 500 ); //20ms
3152
3153        for( i = 0;  i < 9; i++ )
3154        {
3155                ucFreqVol = ( BEEPER_ON_TABLE[i] );
3156                I2cWriteSTV82x8( BEEPER_FREQ_VOL, ucFreqVol );
3157                STV82x8_DataMaskWrite ( BEEPER_ON, STV82X8_BEEPER_ON, BEEPER_ON_MASK );
3158        usleep( 1000 ); //75ms
3159
3160        do
3161        {
3162            I2cReadSTV82x8( BEEPER_ON, &ucRegVal );
3163                } while(( ucRegVal != 0 ) && ( ucCount++ < 200 ));
3164        }
3165 
3166        ucResult |= STV82x8_DataMaskWrite( BEEPER_ON, STV82X8_BEEPER_OFF, BEEPER_ON_MASK );
3167        ucResult |= STV82x8_SetDigitalUnMute(STV82x8_UNMUTE_ALL_OUTPUT, STV82x8_ALL_OUTPUT_MASK);
3168        return ( ucResult );
3169}
3170
3171
3172
3173
3174/***********************************************************************************
3175 * Function:
3176 *  unsigned char STV82x8_BeeperAmbulanceSound(VOID)
3177 * Description:
3178 *  This function happens to beeper Ambulance Sound.
3179 * Input:
3180 * Output:
3181 *  None
3182 * Return:
3183 *  STV82X8_I2C_ERROR = I2C's communication is failed.
3184 *  STV82X8_NO_ERROR = Success.
3185 ***********************************************************************************/
3186unsigned char STV82x8_BeeperAmbulanceSound(VOID)
3187{
3188    unsigned char   ucRegVal, ucFreqVol, ucResult = STV82X8_NO_ERROR;
3189    unsigned char   i,  ucCount = 0;
3190
3191#ifdef __STV_DEBUG__
3192    STV_FUNCTION;
3193#endif
3194
3195        ucResult = STV82x8_SetDigitalMute(STV82x8_MUTE_ALL_OUTPUT, STV82x8_ALL_OUTPUT_MASK);
3196
3197        STV82x8_DataMaskWrite( BEEPER_MODE, ( STV82X8_BEEPER_PULSE | STV82X8_BEEPEROUT_LS ),
3198                          ( STV82X8_BEEPER_PULSE_MASK | STV82X8_BEEPEROUT_LS_MASK ));
3199        usleep( 500 ); //35ms
3200
3201        for( i = 0;  i < 9; i++ )
3202        {
3203        ucFreqVol = ( BEEPER_DURATION_TABLE_1[i] );
3204                I2cWriteSTV82x8( BEEPER_MODE, ucFreqVol );
3205
3206                ucFreqVol = ( BEEPER_FREQ_VOL_TABLE_1[i] );
3207                I2cWriteSTV82x8( BEEPER_FREQ_VOL, ucFreqVol );
3208
3209                STV82x8_DataMaskWrite ( BEEPER_ON, STV82X8_BEEPER_ON, BEEPER_ON_MASK );
3210        usleep( 1000 ); //75ms
3211
3212        do 
3213        {
3214            I2cReadSTV82x8( BEEPER_ON, &ucRegVal );
3215        } while(( ucRegVal != 0 ) && ( ucCount++ < 200 ));
3216        }
3217 
3218        ucResult |= STV82x8_DataMaskWrite( BEEPER_ON, STV82X8_BEEPER_OFF, BEEPER_ON_MASK );
3219        ucResult |= STV82x8_SetDigitalUnMute(STV82x8_UNMUTE_ALL_OUTPUT, STV82x8_ALL_OUTPUT_MASK);
3220
3221    return(ucResult);
3222}
3223
3224
3225
3226/***************************************************************************************
3227 * Function:
3228 *  unsigned char STV82x8_GetSoundSignalState(unsigned char * pucSignalState)
3229 * Description:
3230 *  Let's check if signal is good or not.
3231 * Input:
3232 *  Nnone.
3233 * Output:
3234 *  STV82X8_SOUNDSIGNAL_LOCKED  = Signal locked.
3235 *  STV82X8_SOUNDSIGNAL_UNLOCKED = Signal unlocked.
3236 * Return:
3237 *  STV82X8_I2C_ERROR = I2C's communication is failed.
3238 *  STV82X8_INVALID_PARAM = Invalid params.
3239 *  STV82X8_NO_ERROR = Success.
3240 ***************************************************************************************/
3241unsigned char STV82x8_GetSoundSignalState(unsigned char * pucSignalState)
3242{
3243    unsigned char  ucRegValue, ucResult = STV82X8_NO_ERROR;
3244
3245#ifdef __STV_DEBUG__
3246    STV_FUNCTION;
3247#endif
3248
3249    if( pucSignalState == NULL )
3250        return ( STV82X8_INVALID_PARAM );
3251
3252        ucResult = I2cReadSTV82x8( DEMOD_STAT, &ucRegValue );
3253
3254        if( ucRegValue == ( STV82X8_FM1_CAR & STV82X8_FM1_SQ ))
3255                *pucSignalState = STV82X8_SOUNDSIGNAL_LOCKED;
3256        else
3257                *pucSignalState = STV82X8_SOUNDSIGNAL_UNLOCKED;
3258
3259        return(ucResult);
3260}
3261
3262
3263
3264/*************************************************************************************
3265 * Function:
3266 *  unsigned char STV82x8_GetSoundSystem(unsigned char * pucSoundSystem, BOOL bDetectFM)
3267 * Description:
3268 *  Automatically detect soundsystem (Read 8Ch register).
3269 *      8Ch register depends on 8Ah register.
3270 * Input:
3271 *  BOOL bDetectFM: TRUE= Detect FM Carrier and FM Squelch
3272 *  None
3273 * Output:
3274 *  Sound Mode: MONO, STEREO, SAP, or None
3275 * Return:
3276 *  STV82X8_I2C_ERROR = I2C's communication is failed.
3277 *  STV82X8_INVALID_PARAM = Invalid params.
3278 *  STV82X8_NO_ERROR = Success.
3279 ************************************************************************************/
3280unsigned char STV82x8_GetSoundSystem(unsigned char * pucSoundSystem, BOOL bDetectFM)
3281{
3282    unsigned char ucRegValue, ucSTSoundID;
3283    unsigned char ucResult = STV82X8_NO_ERROR;
3284
3285#ifdef __STV_DEBUG__
3286    STV_FUNCTION;
3287#endif
3288
3289    if(bDetectFM)
3290    {
3291        ucResult = STV82x8_GetSoundSignalState( &ucRegValue );
3292           if( ucRegValue == STV82X8_SOUNDSIGNAL_UNLOCKED )
3293           {
3294            *pucSoundSystem = MONO;
3295            return( STV82X8_RESOURCE_ERROR );
3296           }
3297    }
3298
3299        ucResult |= I2cReadSTV82x8( AUTOSTD_STATUS, &ucRegValue );
3300
3301        ucSTSoundID = ( ucRegValue & STV82X8_AUTOSTD_STATUS_MASK );
3302
3303        if (ucSTSoundID & STV82X8_SAP_OK)
3304                *pucSoundSystem = SAP;
3305        else if (ucSTSoundID & STV82X8_STEREO_OK)
3306                *pucSoundSystem = STEREO;
3307        else if (ucSTSoundID & STV82X8_MONO_OK)
3308                *pucSoundSystem = MONO;
3309        else
3310                *pucSoundSystem = NOTFOUND_SOUND;
3311
3312        return(ucResult);
3313}
3314
3315
3316
3317/***********************************************************************************
3318 * Function:
3319 *  unsigned char STV82x8_GetSoundSystem_Independ(unsigned char * pucSoundSystem, BOOL bDetectFM)
3320 * Description:
3321 *  Automatically detect soundsystem(Read 8Dh register).
3322 *  8Dh register independs on 8Ah register.
3323 * Input:
3324 *  BOOL bDetectFM: TRUE= Detect FM Carrier and FM Squelch
3325 * Output:
3326 *  Sound mode: MONO, STEREO, SAP or SAP_STEREO
3327 * Return:
3328 *  STV82X8_I2C_ERROR = I2C's communication is failed.
3329 *  STV82X8_INVALID_PARAM = Invalid params.
3330 *  STV82X8_NO_ERROR = Success.
3331 ***********************************************************************************/
3332unsigned char STV82x8_GetSoundSystem_Independ(unsigned char * pucSoundSystem, BOOL bDetectFM)
3333{
3334    unsigned char ucRegValue, ucSTSoundID;
3335    unsigned char ucResult = STV82X8_NO_ERROR;
3336
3337#ifdef __STV_DEBUG__
3338    STV_FUNCTION;
3339#endif
3340
3341    if(bDetectFM)
3342    {
3343        ucResult = STV82x8_GetSoundSignalState( &ucRegValue );
3344        if( ucRegValue == STV82X8_SOUNDSIGNAL_UNLOCKED )
3345        {
3346            *pucSoundSystem = MONO;
3347            return ( STV82X8_RESOURCE_ERROR );
3348        }
3349    }
3350
3351        ucResult |= I2cReadSTV82x8( AUTOSTD_DEM_STATUS, &ucRegValue );
3352
3353        ucSTSoundID = ( ucRegValue & STV82X8_AUTOSTD_DEM_STATUS_MASK );
3354        printf("--------------------------------------%#02x\n", ucSTSoundID);
3355        if ( ucSTSoundID == (STV82X8_LCK_DET | STV82X8_ST_DET) )
3356                *pucSoundSystem = STEREO;
3357        else if ( ucSTSoundID == (STV82X8_SAP_SQ | STV82X8_SAP_DET) )
3358                *pucSoundSystem = SAP;
3359        else if ( ucSTSoundID == (STV82X8_LCK_DET | STV82X8_ST_DET | STV82X8_SAP_SQ | STV82X8_SAP_DET) )
3360                *pucSoundSystem = SAP_STEREO;
3361        else
3362                *pucSoundSystem = MONO;
3363
3364        return(ucResult);
3365}
3366
3367
3368
3369
3370/***********************************************************************************
3371 * Function:
3372 *  unsigned char STV82x8_ChangeMTS_Manual(unsigned char ucMTS)
3373 * Description:
3374 *  Manually change MTS
3375 * Input:
3376 *  unsigned char ucMTS: MTS
3377 * Return:
3378 *  STV82X8_I2C_ERROR = I2C's communication is failed.
3379 *  STV82X8_INVALID_PARAM = Invalid params.
3380 *  STV82X8_NO_ERROR = Success.
3381 **********************************************************************************/
3382unsigned char STV82x8_ChangeMTS_Manual(unsigned char ucMTS)
3383{
3384    unsigned char ucResult = STV82X8_NO_ERROR;
3385
3386#ifdef __STV_DEBUG__
3387    STV_FUNCTION;
3388#endif
3389
3390        ucResult = I2cWriteSTV82x8( MUTE_DIGITAL, STV82X8_DIGITAL_LS_MUTE );
3391
3392        ucResult |= I2cWriteSTV82x8( AUTOSTD_CTRL, ucMTS );
3393        usleep(2000 ); //150ms
3394
3395        ucResult |= I2cWriteSTV82x8( MUTE_DIGITAL, STV82X8_DIGITAL_LS_UNMUTE );
3396
3397    return(ucResult);
3398}
3399
3400/***********************************************************************************
3401 * Function:
3402 *  unsigned char STV82x8_All_SoundSystem_Check(VOID)
3403 * Description:
3404 *  This function set sound system's register for all system searching to speciall values.
3405 * Input:
3406 * Output:
3407 *  None
3408 * Return:
3409 *  STV82X8_I2C_ERROR = I2C's communication is failed.
3410 *  STV82X8_NO_ERROR = Success.
3411 ***********************************************************************************/
3412unsigned char STV82x8_All_SoundSystem_Check(VOID)
3413{
3414    unsigned char   ucResult = STV82X8_NO_ERROR;
3415
3416#ifdef __STV_DEBUG__
3417    STV_FUNCTION;
3418#endif
3419
3420        ucResult |= STV82x8_DataMaskWrite( AUTOSTD_CTRL, STV82X8_AUTOSTD_ALL_CHECK, STV82X8_AUTOSTD_CHECK_MASK );
3421
3422        return(ucResult);
3423}
3424
3425
3426
3427/***********************************************************************************
3428 * Function:
3429 *  unsigned char STV82x8_SetI2SInOut(unsigned char ucI2S_InOut)
3430 * Description:
3431 *  Select I2S input & output.
3432 *      I2S_OUTPUT[Bit 6&5] of RESET[01h] = 00h
3433 *                                              |                       |                         |                             |
3434 *              [Digital Input]  =========> |  I2S Block        |        =======>         |   Digital           |
3435 *                                                              |               |                         |  Processing         |
3436 *      I2S_OUTPUT[Bit 6&5] of RESET[01h] = 60h
3437 *                      |                               |                                                       |                       |
3438 *                                      |   Digital             | [Digital signal]  =========>          |  I2S Block    |   =====> [Digital Output]
3439 *                                      |  Processing   |                                                       |               |
3440 *
3441 *
3442 * Input:
3443 *  STV82x8_I2S_INPUT = I2S mode is input.
3444 *  STV82x8_I2S_OUTPUT = I2S mode is output.
3445 * Output:
3446 *  None
3447 * Return:
3448 *  STV82x8_I2C_ERROR           = I2C's communication is failed.
3449 *  STV82x8_INVALID_PARAM       = Invalid params.
3450 *  STV82X8_NO_ERROR            = No error.
3451 ***********************************************************************************/
3452unsigned char STV82x8_SetI2SInOut(unsigned char ucI2S_InOut)
3453{
3454    unsigned char   ucResult = STV82X8_NO_ERROR;
3455
3456#ifdef __STV_DEBUG__
3457    STV_FUNCTION;
3458#endif
3459
3460        if(( ucI2S_InOut != STV82X8_I2S_INPUT ) && ( ucI2S_InOut != STV82X8_I2S_OUTPUT ))
3461        {
3462                return ( STV82X8_INVALID_PARAM );
3463        }
3464
3465        ucResult = STV82x8_DataMaskWrite( SW_RESET, ucI2S_InOut, STV82x8_I2S_INOUT_MASK );
3466
3467        return(ucResult);
3468}
3469
3470
3471
3472
3473/***********************************************************************************
3474 * Function:
3475 *  unsigned char STV82x8_SetI2SOutputSignal(unsigned char ucI2S_Output)
3476 * Description:
3477 *  Configure I2S output.
3478 * Input:
3479 *      STV82x8_I2S_OUTPUT_SCART                = I2S's output  connection is Scart.
3480 *      STV82x8_I2S_OUTPUT_LR           = I2S's output  connection is Loud speaker.
3481 *      STV82x8_I2S_OUTPUT_HP_SURROUND  = I2S's output  connection is HP & Sur.
3482 *      STV82x8_I2S_OUTPUT_C_SUB        = I2S's output  connection is Center & Sub.
3483 *      I2S_OUTPUT[Bit 7~5] of ADC_CTRL[56h] = 00h
3484 *                             [LR Output]    -------------|I2S Block| =====> [Digital Output]
3485 *      I2S_OUTPUT[Bit 7~5] of ADC_CTRL[56h] = 20h
3486 *                                      [HP_LSS Output]-------------|I2S Block| =====> [Digital Output]
3487 *      I2S_OUTPUT[Bit 7~5] of ADC_CTRL[56h] = 40h
3488 *                                      [LS C & Sub Output]---------|I2S Block| =====> [Digital Output]
3489 *      I2S_OUTPUT[Bit 7~5] of ADC_CTRL[56h] = 60h
3490 *                              [Scart Output] -------------|I2S Block| =====> [Digital Output]
3491 *      I2S_OUTPUT[Bit 7~5] of ADC_CTRL[56h] = 80h
3492 *                                      [SPDIF Output] -------------|I2S Block| =====> [Digital Output]
3493 *      I2S_OUTPUT[Bit 7~5] of ADC_CTRL[56h] = A0h
3494 *                              [Delay]        -------------|I2S Block| =====> [Digital Output]
3495 * Output:
3496 *  None
3497 * Return:
3498 *  STV82x8_I2C_ERROR           = I2C's communication is failed.
3499 *  STV82x8_INVALID_PARAM       = Invalid params.
3500 *  STV82X8_NO_ERROR            = No error.
3501 ***********************************************************************************/
3502unsigned char STV82x8_SetI2SOutputSignal(unsigned char ucI2S_Output)
3503{
3504    unsigned char   ucResult = STV82X8_NO_ERROR;
3505
3506#ifdef __STV_DEBUG__
3507    STV_FUNCTION;
3508#endif
3509
3510        if(( ucI2S_Output != STV82X8_I2S_OUTPUT_SCART ) && ( ucI2S_Output != STV82X8_I2S_OUTPUT_LR ) &&
3511                ( ucI2S_Output != STV82X8_I2S_OUTPUT_HP_SURROUND ) && ( ucI2S_Output != STV82X8_I2S_OUTPUT_C_SUB ) &&
3512                ( ucI2S_Output != STV82X8_I2S_OUTPUT_SPDIF ) && ( ucI2S_Output != STV82X8_I2S_OUTPUT_DELAY ))
3513
3514        {
3515                return ( STV82X8_INVALID_PARAM );
3516        }
3517
3518
3519        ucResult = STV82x8_DataMaskWrite( ADC_CTRL, ucI2S_Output, STV82x8_I2S_DATA0_CTRL_MASK );
3520
3521        return (ucResult);
3522}
3523
3524/************************************************************************************************
3525 * Function:
3526 *  unsigned char STV82x8_SetSRS_InputMode(unsigned char ucSRS_InputMode )
3527 * Description:
3528 *  Select SRS Input mode and control SRS Dialog Clarity.
3529 * Input param:
3530 *      STV82x8_ALL_SRS_OFF             = SRS effect Off.
3531 *              STV82x8_SRS_MONO_LEFT               = Transform mono sound into pseudo stereo sound.
3532 *              STV82x8_SRS_MONO_DCLARITY           = Transform mono sound into pseudo stereo sound with additional voice effect.
3533 *      STV82x8_SRS_LR_STEREO               = Transform mono sound into pseudo 3D stereo sound.
3534 *      STV82x8_SRS_LR_STEREO_DCLARITY  = Transform stereo sound into enhanced 3D stereo sound
3535 *                                        for L/R with additional voice effect.
3536 *      STV82x8_SRS_LSR                 = Transform stereo sound into enhanced 3D stereo sound for L/R/Srd.
3537 *      STV82x8_SRS_LSR_DCLARITY        = Transform stereo sound into enhanced 3D stereo sound
3538 *                                        for L/R/Srd with additional voice effect.
3539 *      STV82x8_SRS_LRLsRs              = Transform stereo sound into enhanced spatial virtualized sound for L/R/Ls/Rs.
3540 *      STV82x8_SRS_LRLsRs_DCLARITY     = Transform stereo sound into enhanced spatial virtualized sound
3541 *                                        for L/R/Ls/Rs with additional voice effect.
3542 *      STV82x8_SRS_LRC                 = Transform stereo sound into enhanced spatial virtualized sound for L/R/C.
3543 *      STV82x8_SRS_LRC_DCLARITY        = Transform stereo sound into enhanced spatial virtualized sound
3544 *                                        for L/R/C with additional voice effect.
3545 *      STV82x8_SRS_LRCS                = Transform stereo sound into enhanced spatial virtualized sound for L/R/C/Srd.
3546 *      STV82x8_SRS_LRCS_DCLARITY       = Transform stereo sound into enhanced spatial virtualized sound
3547 *                                        for L/R/C/Srd with additional voice effect.
3548 *      STV82x8_SRS_LRCLsRs             = Transform stereo sound into enhanced spatial virtualized sound for L/R/C/Srd.
3549 *      STV82x8_SRS_LRCLsRs_DCLARITY    = Transform stereo sound into enhanced spatial virtualized sound
3550 *                                        for L/R/C/Srd with additional voice effect.
3551 *      STV82x8_SRS_LtRt                = Transform stereo sound into enhanced spatial virtualized sound for Lt/Rt.
3552 *      STV82x8_SRS_LtRt_DCLARITY       = Transform stereo sound into enhanced spatial virtualized sound
3553 *                                        for Lt/Rt with additional voice effect.
3554 *      STV82x8_SRS_LRCLsRs_SRS         = Transform stereo sound into enhanced 3D stereo sound for L/R/C/Ls/Rs.
3555 *      STV82x8_SRS_LRCLsRs_SRS_DCLARITY= Transform stereo sound into enhanced 3D stereo sound
3556 *                                        L/R/C/Ls/Rs with additional voice effect.
3557 *      STV82x8_SRS_LRCLsRs_TRX         = Transform stereo sound into enhanced spatial virtualized sound for L/R/C/Ls/Rs.
3558 *      STV82x8_SRS_LRCLsRs_TRX_DCLARITY= Transform stereo sound into enhanced spatial virtualized sound
3559 *                                        for L/R/C/Ls/Rs with additional voice effect.
3560 * Output:
3561 *  None
3562 * Return:
3563 *  STV82x8_I2C_ERROR           = I2C's communication is failed.
3564 *  STV82x8_INVALID_PARAM       = Invalid params.
3565 *  STV82X8_NO_ERROR            = No error.
3566 ********************************************************************************************/
3567unsigned char STV82x8_SetSRS_InputMode(unsigned char ucSRS_InputMode )
3568{
3569    unsigned char   ucResult = STV82X8_NO_ERROR;
3570    unsigned char   ucTruSrd_Ctrl, ucTruSrd_InputGain;
3571    unsigned char   ucTruSrd_DCElevation;
3572
3573#ifdef __STV_DEBUG__
3574    STV_FUNCTION;
3575#endif
3576
3577        if( ucSRS_InputMode > STV82x8_SRS_LRCLsRs_TRX_DCLARITY )
3578        {
3579                return ( STV82X8_INVALID_PARAM );
3580        }
3581
3582        ucTruSrd_Ctrl = (unsigned char)( STV82x8_TRUSURROUND_OFF );
3583        ucTruSrd_InputGain = (unsigned char)( STV82x8_TRUSRND_INPUT_GAIN );
3584        ucTruSrd_DCElevation = (unsigned char)( STV82x8_TRUSRND_DC_ELEVATION );
3585
3586        switch( ucSRS_InputMode )
3587        {
3588                case STV82x8_SRS_MONO_DCLARITY:
3589                        ucTruSrd_Ctrl = (unsigned char)( STV82x8_DIALOG_CLARITY_ON | STV82x8_HP_MODE_OFF );
3590                case STV82x8_SRS_MONO_LEFT:
3591                        ucTruSrd_Ctrl |= (unsigned char)( STV82x8_TRUSURROUND_ON | STV82x8_TRUSRND_MONO_LEFT );
3592                        break;
3593         
3594                case STV82x8_SRS_LR_STEREO_DCLARITY:
3595                        ucTruSrd_Ctrl = (unsigned char)( STV82x8_DIALOG_CLARITY_ON | STV82x8_HP_MODE_OFF );
3596                case STV82x8_SRS_LR_STEREO:
3597                        ucTruSrd_Ctrl |= (unsigned char)( STV82x8_TRUSURROUND_ON | STV82x8_TRUSRND_LR_STEREO );
3598                        break;
3599         
3600                case STV82x8_SRS_LSR_DCLARITY:
3601                        ucTruSrd_Ctrl = (unsigned char)( STV82x8_DIALOG_CLARITY_ON | STV82x8_HP_MODE_OFF );
3602                case STV82x8_SRS_LSR:
3603                        ucTruSrd_Ctrl |= (unsigned char)( STV82x8_TRUSURROUND_ON | STV82x8_TRUSRND_LSR );
3604                        break;
3605         
3606                case STV82x8_SRS_LRLsRs_DCLARITY:
3607                        ucTruSrd_Ctrl = (unsigned char)( STV82x8_DIALOG_CLARITY_ON | STV82x8_HP_MODE_OFF );
3608                case STV82x8_SRS_LRLsRs:
3609                        ucTruSrd_Ctrl |= (unsigned char)( STV82x8_TRUSURROUND_ON | STV82x8_TRUSRND_LSLsRs );
3610                        break;
3611         
3612                case STV82x8_SRS_LRC_DCLARITY:
3613                        ucTruSrd_Ctrl = (unsigned char)( STV82x8_DIALOG_CLARITY_ON | STV82x8_HP_MODE_OFF );
3614                case STV82x8_SRS_LRC:
3615                        ucTruSrd_Ctrl |= (unsigned char)( STV82x8_TRUSURROUND_ON | STV82x8_TRUSRND_LRC );
3616                        break;
3617         
3618                case STV82x8_SRS_LRCS_DCLARITY:
3619                        ucTruSrd_Ctrl = (unsigned char)( STV82x8_DIALOG_CLARITY_ON | STV82x8_HP_MODE_OFF );
3620                case STV82x8_SRS_LRCS:
3621                        ucTruSrd_Ctrl |= (unsigned char)( STV82x8_TRUSURROUND_ON | STV82x8_TRUSRND_LRCS );
3622                        break;
3623         
3624                case STV82x8_SRS_LRCLsRs_DCLARITY:
3625                        ucTruSrd_Ctrl = (unsigned char)( STV82x8_DIALOG_CLARITY_ON | STV82x8_HP_MODE_OFF );
3626                case STV82x8_SRS_LRCLsRs:
3627                        ucTruSrd_Ctrl |= (unsigned char)( STV82x8_TRUSURROUND_ON | STV82x8_TRUSRND_LRCLsRs_XT );
3628                        break;
3629         
3630                case STV82x8_SRS_LtRt_DCLARITY:
3631                        ucTruSrd_Ctrl = (unsigned char)( STV82x8_DIALOG_CLARITY_ON | STV82x8_HP_MODE_OFF );
3632                case STV82x8_SRS_LtRt:
3633                        ucTruSrd_Ctrl |= (unsigned char)( STV82x8_TRUSURROUND_ON | STV82x8_TRUSRND_LtRt );
3634                        break;
3635         
3636                case STV82x8_SRS_LRCLsRs_SRS_DCLARITY:
3637                        ucTruSrd_Ctrl = (unsigned char)( STV82x8_DIALOG_CLARITY_ON | STV82x8_HP_MODE_OFF );
3638                case STV82x8_SRS_LRCLsRs_SRS:
3639                        ucTruSrd_Ctrl |= (unsigned char )( STV82x8_TRUSURROUND_ON | STV82x8_TRUSRND_LRCLsRs_SRS );
3640                        break;
3641         
3642                case STV82x8_SRS_LRCLsRs_TRX_DCLARITY:
3643                        ucTruSrd_Ctrl = (unsigned char)( STV82x8_DIALOG_CLARITY_ON | STV82x8_HP_MODE_OFF );
3644                case STV82x8_SRS_LRCLsRs_TRX:
3645                        ucTruSrd_Ctrl |= (unsigned char)( STV82x8_TRUSURROUND_ON | STV82x8_TRUSRND_LRCLsRs_XTPRO2 );
3646                        break;
3647         
3648                case STV82X8_ALL_SRS_OFF:
3649                default:
3650                        ucTruSrd_Ctrl = (unsigned char)( STV82x8_TRUSURROUND_OFF | STV82x8_TRUSRND_LR_STEREO );
3651                        break;
3652        }
3653
3654        ucResult = I2cWriteSTV82x8( TRUSRND_CONTROL, ucTruSrd_Ctrl );
3655        ucResult |= I2cWriteSTV82x8( TRUSRND_INPUT_GAIN, ucTruSrd_InputGain );
3656        ucResult |= I2cWriteSTV82x8( TRUSRND_DC_ELEVATION, ucTruSrd_DCElevation );
3657
3658        return (ucResult);
3659}
3660
3661
3662
3663/***************************************************************************************
3664 * Function:
3665 *  unsigned char STV82x8_SetSRS_TRUBASS(unsigned char ucTrubassType, unsigned char ucSRS_TruBass)
3666 * Description:
3667 *  Control SRS TruBass.
3668 * Input:
3669 *  unsigned char ucTrubassType: TRUBASS_LS_CONTROL or TRUBASS_HP_CONTROL
3670 *  unsigned char ucSRS_TruBass:
3671 *      STV82x8_SRS_TRUBASS_OFF     = SRS Tru Bass Off.
3672 *      STV82x8_SRS_TRUBASS_SMALL   = Bass effect for small sized speakers - Not to be able to reproduce low frequencies.
3673 *      STV82x8_SRS_TRUBASS_MEDIUM  = Bass effect for medium sized speakers - Not to be fully able to reproduce low frequencies.
3674 *      STV82x8_SRS_TRUBASS_LARGE   = Bass effect for large sized speakers - To be able to reproduce low frequencies.
3675 * Output:
3676 *  None
3677 * Return:
3678 *  STV82x8_I2C_ERROR                   = I2C's communication is failed.
3679 *  STV82x8_INVALID_PARAM               = Invalid params.
3680 *  STV82X8_NO_ERROR                    = No error.
3681 ***************************************************************************************/
3682unsigned char STV82x8_SetSRS_TRUBASS(unsigned char ucTrubassType, unsigned char ucSRS_TruBass)
3683{
3684    unsigned char   ucResult = STV82X8_NO_ERROR;
3685    unsigned char   ucTruBass_LSCtrl, ucTruBass_LSLevel;
3686
3687#ifdef __STV_DEBUG__
3688    STV_FUNCTION;
3689#endif
3690
3691        if( ucSRS_TruBass > STV82x8_SRS_TRUBASS_LARGE )
3692        {
3693                return ( STV82X8_INVALID_PARAM );
3694        }
3695
3696        ucTruBass_LSCtrl = (unsigned char)( STV82x8_TRUBASS_OFF |STV82x8_TRUBASS_LF_RESPOSE_200KHZ );
3697        ucTruBass_LSLevel = (unsigned char)( STV82x8_TRUBASS_LS_LEVEL );
3698
3699        switch( ucSRS_TruBass )
3700        {
3701                case STV82x8_SRS_TRUBASS_SMALL:
3702                        ucTruBass_LSCtrl = (unsigned char)( STV82x8_TRUBASS_ON |STV82x8_TRUBASS_LF_RESPOSE_200KHZ );
3703                        break;
3704                case STV82x8_SRS_TRUBASS_MEDIUM:
3705                        ucTruBass_LSCtrl = (unsigned char)( STV82x8_TRUBASS_ON |STV82x8_TRUBASS_LF_RESPOSE_100KHZ );
3706                        break;
3707                case STV82x8_SRS_TRUBASS_LARGE:
3708                        ucTruBass_LSCtrl = (unsigned char)( STV82x8_TRUBASS_ON |STV82x8_TRUBASS_LF_RESPOSE_60KHZ );
3709                        break;
3710                case STV82x8_SRS_TRUBASS_OFF:
3711                default:
3712                        break;
3713        }
3714
3715        ucResult = I2cWriteSTV82x8( ucTrubassType, ucTruBass_LSCtrl );
3716    if(ucTrubassType == TRUBASS_LS_CONTROL)
3717        ucResult |= I2cWriteSTV82x8( TRUBASS_LS_LEVEL, ucTruBass_LSLevel );
3718    else
3719        ucResult |= I2cWriteSTV82x8( TRUBASS_HP_LEVEL, ucTruBass_LSLevel );
3720
3721        return ( ucResult );
3722}
3723
3724
3725/******************************************************************************************
3726 * Function:
3727 *  unsigned char STV82x8_SetDynamicBass(unsigned char ucDynBass_Freq, unsigned char ucBassLevel )
3728 * Description:
3729 *  This function sets ST Dynamic Bass.
3730 * Input:
3731 *  unsigned char ucDynBass_Freq:
3732 *      STV82x8_100HZ_CUT_OFF           = 100Hz cut off frequency.
3733 *              STV82x8_150HZ_CUT_OFF           = 150Hz cut off frequency.
3734 *              STV82x8_200HZ_CUT_OFF           = 200Hz cut off frequency.
3735 *  ucBassLevel = ST Dynamic Bass effect level.
3736 * Output:
3737 *  None
3738 * Return:
3739 *  STV82x8_I2C_ERROR = I2C's communication is failed.
3740 *  STV82x8_INVALID_PARAM       = Invalid params.
3741 *  STV82X8_NO_ERROR            = No error.
3742 *****************************************************************************************/
3743unsigned char STV82x8_SetDynamicBass(unsigned char ucDynBass_Freq, unsigned char ucBassLevel )
3744{
3745        unsigned char  ucResult, ucRegValue;
3746
3747#ifdef __STV_DEBUG__
3748    STV_FUNCTION;
3749#endif
3750
3751        if( ucBassLevel > STV82x8_BASS_LEVEL )
3752                return ( STV82X8_INVALID_PARAM );
3753
3754        if(( ucDynBass_Freq != STV82x8_100HZ_CUT_OFF ) && ( ucDynBass_Freq != STV82x8_150HZ_CUT_OFF ) &&
3755                ( ucDynBass_Freq != STV82x8_200HZ_CUT_OFF ))
3756                return ( STV82X8_INVALID_PARAM );
3757
3758        ucRegValue = (unsigned char)( STV82x8_ST_DYNAMIC_BASS_ON | ucDynBass_Freq | ( ucBassLevel << 3 ));
3759
3760        ucResult = I2cWriteSTV82x8( DYNAMIC_BASS_LS, ucRegValue  );
3761
3762        return (ucResult);
3763}
3764
3765
3766/*****************************************************************************************
3767 * Function:
3768 *  unsigned char STV82x8_SetAVDelay(unsigned char ucDolbyDelay, unsigned char ucTime1_msec, unsigned char ucTime2_msec)
3769 * Description:
3770 *  Set Audio/Video delay
3771 * Input:
3772 *  unsigned char ucDolbyDelay: dolby mode
3773 *  unsigned char ucTime1_msec: delay time
3774 *  unsigned char ucTime2_msec: delay time
3775 * Output:
3776 *  None.
3777 * Return:
3778 *  STV82x8_I2C_ERROR = I2C's communication is failed.
3779 *  STV82x8_INVALID_PARAM  = Invalid params.
3780 *  STV82X8_NO_ERROR = No error.
3781 ****************************************************************************************/
3782unsigned char STV82x8_SetAVDelay(unsigned char ucDolbyDelay, unsigned char ucTime1_msec, unsigned char ucTime2_msec )
3783{
3784    unsigned char ucResult = STV82X8_NO_ERROR;
3785
3786#ifdef __STV_DEBUG__
3787    STV_FUNCTION;
3788#endif
3789
3790        ucResult = STV82x8_DataMaskWrite( AV_DELAY_CONFIG, STV82x8_AV_DELAY_OFF, STV82X8_AV_DELAY_ON_MASK );
3791
3792        if((( ucDolbyDelay == STV82X8_DolbyDelay_On ) && ( (ucTime1_msec + ucTime2_msec) > STV82x8_DolbyOn_MAX_VALUE )) ||
3793                (( ucDolbyDelay == STV82X8_DolbyDelay_Off ) && ( (ucTime1_msec + ucTime2_msec) > STV82x8_DolbyOff_MAX_VALUE )))
3794                return ( STV82X8_INVALID_PARAM );
3795
3796        ucResult = STV82x8_DataMaskWrite( AV_DELAY_CONFIG, ucDolbyDelay, STV82X8_DOLBY_DELAY_ON_MASK );
3797        ucResult |= I2cWriteSTV82x8( AV_DELAY_TIME_LS,  ucTime1_msec );
3798        ucResult |= I2cWriteSTV82x8( AV_DELAY_TIME_HP,  ucTime2_msec );
3799        ucResult |= STV82x8_DataMaskWrite( AV_DELAY_CONFIG, STV82x8_AV_DELAY_ON, STV82X8_AV_DELAY_ON_MASK );
3800
3801        return(ucResult);
3802}
3803
3804
3805
3806
3807/**********************************************************************************
3808 * Function:
3809 *  unsigned char STV82x8_SetDefaultValueFromSTDConfig(VOID)
3810 * Description:
3811 *  Set standard value
3812 * Input:
3813 * Output:
3814 *  None
3815 * Return:
3816 *  STV82X8_I2C_ERROR = I2C's communication is failed.
3817 *  STV82X8_NO_ERROR = Success.
3818 *********************************************************************************/
3819unsigned char STV82x8_SetDefaultValueFromSTDConfig(VOID)
3820{
3821    unsigned char   ucResult = STV82X8_NO_ERROR;
3822
3823#ifdef __STV_DEBUG__
3824    STV_FUNCTION;
3825#endif
3826
3827        ucResult = I2cWriteSTV82x8( CETH1_REG, 0x10 );
3828        ucResult |= I2cWriteSTV82x8( SQTH1,  0x70 );
3829        ucResult |= I2cWriteSTV82x8( SAP_LEVEL_H,  0x80 );
3830        ucResult |= I2cWriteSTV82x8( SAP_LEVEL_L,  0x60 );
3831        ucResult |= I2cWriteSTV82x8( PLL_P_GAIN,  0x82 );
3832        ucResult |= I2cWriteSTV82x8( SAP_SQ_TH,  0x20 );
3833        ucResult |= I2cWriteSTV82x8( BTSC_FINE_PRESCAL_ST,  0x5C );
3834        ucResult |= I2cWriteSTV82x8( BTSC_FINE_PRESCAL_SAP,  0xC4 );
3835 
3836        return(ucResult);
3837}
3838
3839
3840
3841
3842/**********************************************************************************
3843 * Function:
3844 *   unsigned char STV82x8_SetValueForSPDIF(VOID)
3845 * Description:
3846 *  Set vaule for SPDIF
3847 * Input:
3848 * Output:
3849 *  None
3850 * Return:
3851 *  STV82X8_I2C_ERROR = I2C's communication is failed.
3852 *  STV82X8_NO_ERROR = Success.
3853 *********************************************************************************/
3854unsigned char STV82x8_SetValueForSPDIF(VOID)
3855{
3856    unsigned char   ucResult = STV82X8_NO_ERROR;
3857
3858#ifdef __STV_DEBUG__
3859    STV_FUNCTION;
3860#endif
3861
3862        ucResult = I2cWriteSTV82x8( 0x5B, 0x0d );
3863        ucResult |= STV82x8_DataMaskWrite( 0x80, 0x04, 0x04 );
3864        Delay_msec(2);
3865        ucResult |= I2cWriteSTV82x8( 0xF5, 0x00 );
3866        Delay_msec(2);
3867
3868        return(ucResult);
3869}
3870
3871/**********************************************************************************
3872 * Function:
3873 *   unsigned char STV82x8_SAPConfig()
3874 * Description:
3875 *  Set if SAP selected for second channel
3876 * Input:
3877 * Output:
3878 *  None
3879 * Return:
3880 *  STV82X8_I2C_ERROR = I2C's communication is failed.
3881 *  STV82X8_NO_ERROR = Success.
3882 *********************************************************************************/
3883unsigned char STV82x8_SAPConfig(unsigned char bSAP)
3884{
3885    unsigned char   ucResult = STV82X8_NO_ERROR;
3886
3887#ifdef __STV_DEBUG__
3888    STV_FUNCTION;
3889#endif
3890
3891        ucResult = I2cWriteSTV82x8( SAP_CONF, bSAP );
3892
3893        return(ucResult);
3894}
3895
3896
3897/************************************************************************************
3898 * Function:
3899 *  unsigned char STV82x8_DataMaskWrite(unsigned char ucADDRESS, unsigned char ucDATA, unsigned char ucMASK_DATA )
3900 * Description:
3901 *  I2C_DREAD
3902 * Input:
3903 *  unsigned char ucADDRESS: register addr
3904 *  unsigned char ucDATA: data to write
3905 *  unsigned char ucMASK_DATA: mask
3906 * Output:
3907 *  None
3908 * Return:
3909 *  STV82X8_I2C_ERROR = I2C's communication is failed.
3910 *  STV82X8_NO_ERROR = Success.
3911 ***********************************************************************************/
3912unsigned char STV82x8_DataMaskWrite(unsigned char ucADDRESS, unsigned char ucDATA, unsigned char ucMASK_DATA )
3913{
3914        unsigned char  ucRegValue=0, ucResult = STV82X8_NO_ERROR;
3915
3916        ucResult = I2cReadSTV82x8(ucADDRESS, &ucRegValue );
3917        ucRegValue &= ~ucMASK_DATA;
3918        ucRegValue |= ucDATA;
3919        ucResult = I2cWriteSTV82x8(ucADDRESS, ucRegValue );
3920   
3921    return(ucResult);
3922}
3923
3924
3925
3926/************************************************************************************
3927 * Function:
3928 *  unsigned char I2cWriteSTV82x8(unsigned char ucSubAddress, unsigned char ucData)
3929 * Description:
3930 *  Write I2C data
3931 * Input:
3932 *  unsigned char ucSubAddress: I2C sub address
3933 *  unsigned char ucData: data
3934 * Return:
3935 *  STV82X8_I2C_ERROR = I2C's communication is failed.
3936 *  STV82X8_NO_ERROR = Success.
3937 ***********************************************************************************/
3938unsigned char I2cWriteSTV82x8(unsigned char ucSubAddress, unsigned char ucData)
3939{
3940    INT     nRet = SUCCESS;
3941    CHAR    sub[4],buf[4];       
3942    unsigned char   ucResult = STV82X8_NO_ERROR;
3943    struct  i2c_iic_data i2cMsg;
3944
3945#if (BOARD_TYPE==BOARD_DDM70)
3946        return ucResult;
3947#endif
3948
3949        sub[0] = ucSubAddress;
3950        buf[0] = ucData;
3951        i2cMsg.addr = gSlaveAddr >> 1;
3952
3953        i2cMsg.sub_addr_len = 1;
3954        i2cMsg.psub_addr = sub;
3955        i2cMsg.data_len = 1;
3956        i2cMsg.buf = buf;
3957
3958        nRet = ioctl(gSTV82x8_i2cfd, I2C_DWRITE, &i2cMsg);
3959        if(nRet < 0)
3960        {
3961                TRACE0(("I2C write failed, write count mismatch\n"));
3962                ucResult = STV82X8_I2C_ERROR;
3963        }
3964 
3965    return(ucResult);
3966}
3967
3968
3969
3970
3971/************************************************************************************
3972 * Function:
3973 *  unsigned char I2cReadSTV82x8(unsigned char ucSubAddress, unsigned char * pucData )
3974 * Description:
3975 *  Read I2C data
3976 * Input:
3977 *  unsigned char ucSubAddress: I2C sub address
3978 *  unsigned char * pucData: data buffer
3979 * Return:
3980 *  STV82X8_I2C_ERROR = I2C's communication is failed.
3981 *  STV82X8_NO_ERROR = Success.
3982 ***********************************************************************************/
3983unsigned char I2cReadSTV82x8(unsigned char ucSubAddress, unsigned char * pucData )
3984{
3985    INT     nRet = SUCCESS;
3986    CHAR    sub[4];
3987    unsigned char   ucResult = STV82X8_NO_ERROR;       
3988    struct i2c_iic_data i2cMsg;
3989
3990#if (BOARD_TYPE==BOARD_DDM70)
3991        return ucResult;
3992#endif
3993
3994        sub[0] = ucSubAddress;
3995        i2cMsg.addr = gSlaveAddr >> 1;
3996        i2cMsg.sub_addr_len = 1;
3997        i2cMsg.psub_addr = sub;
3998        i2cMsg.data_len = 1;
3999        i2cMsg.buf = pucData;
4000
4001        nRet = ioctl(gSTV82x8_i2cfd, I2C_DREAD, &i2cMsg);
4002        if(nRet < 0)
4003    {
4004        TRACE0(("I2C read failed, read count mismatch\n"));
4005        ucResult = STV82X8_I2C_ERROR;
4006    }
4007
4008        return ucResult;
4009}
4010
4011void get_stv(int addr)
4012{
4013        unsigned char ret;
4014        unsigned char data;
4015       
4016        ret = I2cReadSTV82x8( (unsigned char)addr, &data );
4017        if ( ret == STV82X8_NO_ERROR )
4018                printf("|%s| ADDR=0x%x, DATA=0x%x\n", __FUNCTION__, addr, data);
4019        else
4020                printf("|%s| ERROR, LINE=%d\n", __FUNCTION__, __LINE__);
4021}
4022
4023void PrintSTV82x8Config(void)
4024{
4025        int i;
4026       
4027        for(i=0; i<256; i++)
4028                get_stv(i);
4029}
4030
4031void set_stc(int addr, int data)
4032{
4033        get_stv(addr);
4034        if ( I2cWriteSTV82x8(addr, data) != STV82X8_NO_ERROR )
4035                printf("|%s| ERROR, LINE=%d\n", __FUNCTION__, __LINE__);
4036        else
4037                get_stv(addr);
4038}
4039
4040/**********************************************************************************
4041 * Function:
4042 *  unsigned char STV82x8_SetAutoMuteOnOff(unsigned char ucOnOff)
4043 * Description:
4044 *  Set output channel automatically mute when no signal or not
4045 * Input:
4046 *  ucOnOff: ON = 1 = Set output channel automatically mute when no signal
4047 *          OFF = 0 = Output channels are never mutted
4048 * Output:
4049 *  None
4050 * Return:
4051 *  STV82X8_I2C_ERROR = I2C's communication is failed.
4052 *  STV82X8_NO_ERROR = Success.
4053 *********************************************************************************/
4054unsigned char STV82x8_SetAutoMuteOnOff(unsigned char ucOnOff)
4055{
4056    unsigned char   ucResult = STV82X8_NO_ERROR;
4057
4058#ifdef __STV_DEBUG__
4059    STV_FUNCTION;
4060#endif
4061     
4062    if(ucOnOff == ON)
4063    {
4064        ucResult = STV82x8_DataMaskWrite( AUTOSTD_CTRL, AUTOSTD_CTRL_AUTO_MUTE_ON, AUTOSTD_CTRL_AUTO_MUTE_MASK );             
4065    }
4066    else
4067    {
4068        ucResult = STV82x8_DataMaskWrite( AUTOSTD_CTRL, AUTOSTD_CTRL_AUTO_MUTE_OFF, AUTOSTD_CTRL_AUTO_MUTE_MASK );                   
4069    }
4070   
4071    return (ucResult);   
4072}
4073 
4074
4075/**********************************************************************************
4076 * Function:
4077 *  unsigned char STV82x8_SetMuteAll(BOOL bMute)
4078 * Description:
4079 *  Set all outputs, DIGITAL, SPDIF, DAC and SCART to mute or unmute state
4080 * Input:
4081 *  bMute:  ON = 1 = Mute the output
4082 *          OFF = 0 = Unmute the output
4083 * Output:
4084 *  None
4085 * Return:
4086 *  STV82X8_I2C_ERROR = I2C's communication is failed.
4087 *  STV82X8_NO_ERROR = Success.
4088 *********************************************************************************/
4089unsigned char STV82x8_SetMuteAll(BOOL bMute)
4090{
4091    unsigned char   ucResult = STV82X8_NO_ERROR;       
4092
4093#ifdef __STV_DEBUG__
4094    STV_FUNCTION;
4095#endif
4096   
4097    if(bMute)
4098    {
4099        ucResult = STV82x8_SetDigitalMute(STV82x8_MUTE_ALL_OUTPUT, STV82x8_ALL_OUTPUT_MASK);
4100        ucResult |= STV82x8_SetDACMute();
4101    }
4102    else
4103    {
4104        ucResult |= STV82x8_SetDACUnMute();
4105        ucResult |= STV82x8_SetDigitalUnMute(STV82x8_UNMUTE_ALL_OUTPUT, STV82x8_ALL_OUTPUT_MASK);
4106    }
4107   
4108    return(ucResult);
4109}
4110 
4111 
4112
4113
4114/**********************************************************************************
4115 * Function:
4116 *  unsigned char STV82x8_SetLoudSpkHeadPhoneGain(unsigned char ucType, unsigned char ucGain)
4117 * Description:
4118 *  Set standard bass gain from -12db to +12 db
4119 * Input:
4120 *  unsigned char ucType:
4121 *      LS_BASS_GAIN: LoudSpeaker Bass Gain
4122 *      LS_TREBLE_GAIN: LoudSpeaker Treble Gain
4123 *      HP_BASS_GAIN: Headphone Bass Gain
4124 *      HP_TREBLE_GAIN: HeadPphone Treble Gain
4125 *  unsigned char ucGain: gain in db
4126 * Output:
4127 *  None
4128 * Return:
4129 *  STV82X8_I2C_ERROR = I2C's communication is failed.
4130 *  STV82X8_NO_ERROR = Success.
4131 *  STV82X8_INVALID_PARAM = invalid parameter
4132 *********************************************************************************/
4133unsigned char STV82x8_SetLoudSpkHeadPhoneGain(unsigned char ucType, unsigned char ucGain)
4134{
4135    unsigned char   ucResult = STV82X8_NO_ERROR;       
4136
4137#ifdef __STV_DEBUG__
4138    STV_FUNCTION;
4139#endif
4140
4141//    ucResult = STV82x8_DataMaskWrite ( LS_EQ_BT_CTRL, STV82X8_TREBLE_ON, STV82X8_EQUALIZE_MASK ); //Josie 8/21
4142
4143       
4144    if( (LS_BASS_GAIN <= ucType) && (ucType <= HP_TREBLE_GAIN) )
4145        ucResult = I2cWriteSTV82x8(ucType, BASS_TREBLE_GAIN_TABLE[ucGain]); 
4146    else
4147        ucResult = STV82X8_INVALID_PARAM;
4148   
4149    return(ucResult);
4150 
4151} 
4152 
4153 
4154
4155/*********************************************************************************
4156 * Function:
4157 *  unsigned char STV82x8_SetSoundMode(unsigned char uSoundMode)
4158 * Description:
4159 *  The function will set sound mode manually
4160 * Input:
4161 *  unsigned char uSoundMode: MONO, STEREO, SAP, or SAP_STEREO
4162 * Output:
4163 *  None
4164 * Return:
4165 *  STV82X8_I2C_ERROR = I2C's communication is failed.
4166 *  STV82X8_NO_ERROR = Success.
4167 ********************************************************************************/
4168unsigned char STV82x8_SetSoundSystem(unsigned char ucSound)
4169{
4170    unsigned char   ucResult = STV82X8_NO_ERROR;
4171    unsigned char   ucSoundMode = MONO_CHECK;
4172    unsigned char   ucChannelMatrix = BYPASS;
4173           
4174#ifdef __STV_DEBUG__
4175    STV_FUNCTION;
4176#endif
4177           
4178    switch(ucSound)
4179    {
4180        case STEREO:
4181            ucSoundMode |= STEREO_CHECK;           
4182        break;
4183       
4184        case SAP:
4185            ucChannelMatrix = RIGHT_ONLY;       
4186            ucSoundMode |= SAP_CHECK;
4187        break;
4188       
4189        case SAP_STEREO:
4190            ucSoundMode |= (SAP_CHECK | STEREO_CHECK);
4191        break;
4192       
4193        case MONO:       
4194            ucChannelMatrix = LEFT_ONLY;
4195        break;
4196       
4197        default:
4198        break;
4199    }
4200 
4201    ucResult = STV82x8_Control_ChannelMatrixLS(ucChannelMatrix);
4202    ucResult |= STV82x8_DataMaskWrite(AUTOSTD_CTRL, ucSoundMode,
4203                                    STEREO_CHECK|MONO_CHECK|SAP_CHECK); 
4204                                     
4205    return(ucResult);
4206}
4207
4208
4209
4210/*********************************************************************************
4211 * Function:
4212 *  unsigned char STV82x8_WideSurroundMode(unsigned char ucWideSRSMode)
4213 * Description:
4214 *  The function will set sound mode manually
4215 * Input:
4216 *  unsigned char uWideSRSMode:
4217 *          ST_WIDE_SURROUND_OFF, ST_WIDE_SURROUND_MONO, ST_WIDE_SURROUND_STEREO
4218 *          ST_WIDE_SURROUND_MOVIE, ST_WIDE_SURROUND_MUSIC
4219 * Output:
4220 *  None
4221 * Return:
4222 *  STV82X8_I2C_ERROR = I2C's communication is failed.
4223 *  STV82X8_NO_ERROR = Success.
4224 ********************************************************************************/
4225unsigned char STV82x8_WideSurroundMode(unsigned char ucWideSRSMode)
4226{
4227    unsigned char   ucResult = STV82X8_NO_ERROR;
4228    unsigned char   ucSRSMode = ST_SURROUND_STEREO | ST_SURROUND_ON;
4229    unsigned char   ucMask = ST_SURROUND_ON_OFF_MASK;
4230
4231#ifdef __STV_DEBUG__
4232    STV_FUNCTION;
4233#endif
4234   
4235    switch(ucWideSRSMode)
4236    {
4237        case ST_WIDE_SURROUND_MONO_MODE:
4238            ucSRSMode = ST_SURROUND_MONO | ST_SURROUND_ON;
4239            ucMask = ST_SURROUND_ON_OFF_MASK | ST_SURROUND_MONO_STEREO_MASK ;           
4240        break;
4241       
4242        case ST_WIDE_SURROUND_STEREO_MODE:
4243            ucSRSMode = ST_SURROUND_STEREO | ST_SURROUND_ON;
4244            ucMask = ST_SURROUND_ON_OFF_MASK | ST_SURROUND_MONO_STEREO_MASK;           
4245        break;
4246               
4247        case ST_WIDE_SURROUND_MOVIE_MODE:
4248            ucSRSMode = ST_SURROUND_MOVIE | ST_SURROUND_ON;
4249            ucMask = ST_SURROUND_ON_OFF_MASK | ST_SURROUND_MOVIE_MUSIC_MASK;                       
4250        break;
4251       
4252        case ST_WIDE_SURROUND_MUSIC_MODE:
4253            ucSRSMode = ST_SURROUND_MUSIC | ST_SURROUND_ON;
4254            ucMask = ST_SURROUND_ON_OFF_MASK | ST_SURROUND_MOVIE_MUSIC_MASK;                       
4255        break;
4256       
4257        case ST_WIDE_SURROUND_OFF_MODE:
4258        default:
4259            ucSRSMode = ST_SURROUND_OFF;
4260            ucMask = ST_SURROUND_ON_OFF_MASK;
4261        break;     
4262       
4263    }
4264     
4265    ucResult = STV82x8_DataMaskWrite(STSRND_CONTROL, ucSRSMode, ucMask);
4266   
4267    return ucResult;
4268}
4269
4270
4271/*********************************************************************************
4272 * Function:
4273 *  unsigned char STV82x8_DialogClarityLevel(unsigned char ucLevel)
4274 * Description:
4275 *  The function will set DialogClarityLevel
4276 * Input:
4277 *  unsigned char ucLevel: 0 - 255 : 0db to -127.5db
4278 * Output:
4279 *  None
4280 * Return:
4281 *  STV82X8_I2C_ERROR = I2C's communication is failed.
4282 *  STV82X8_NO_ERROR = Success.
4283 ********************************************************************************/
4284unsigned char STV82x8_DialogClarityLevel(unsigned char ucLevel)
4285{
4286    unsigned char   ucResult = STV82X8_NO_ERROR;
4287
4288#ifdef __STV_DEBUG__
4289    STV_FUNCTION;
4290#endif
4291   
4292    ucResult |= I2cWriteSTV82x8(TRUSRND_DC_ELEVATION, ucLevel);
4293    return ucResult; 
4294}
4295
4296
4297
4298/*********************************************************************************
4299 * Function:
4300 *  unsigned char STV82x8_SRSTruBaseLoudspeakerHeadphoneLevel(unsigned char ucTrubassType, unsigned char ucLevel)
4301 * Description:
4302 *  The function will set LS or Headphone Trubass level
4303 * Input:
4304 *  unsigned char ucTrubassType: TRUBASS_LS_LEVEL or TRUBASS_HP_LEVEL
4305 *  unsigned char ucLevel: 0 - 255 : 0db to -127.5db
4306 * Output:
4307 *  None
4308 * Return:
4309 *  STV82X8_I2C_ERROR = I2C's communication is failed.
4310 *  STV82X8_NO_ERROR = Success.
4311 ********************************************************************************/
4312unsigned char STV82x8_SRSTruBaseLoudspeakerHeadphoneLevel(unsigned char ucTrubassType, unsigned char ucLevel)
4313{
4314    unsigned char   ucResult = STV82X8_NO_ERROR;
4315
4316#ifdef __STV_DEBUG__
4317    STV_FUNCTION;
4318#endif
4319   
4320    ucResult = I2cWriteSTV82x8(ucTrubassType, ucLevel);
4321    return ucResult; 
4322}
4323
4324
4325
4326
4327/*********************************************************************************
4328 * Function:
4329 *  unsigned char STV82x8_AuxVolSelection(unsigned char ucAuxSel)
4330 * Description:
4331 *  Select the output on wihci the AUX_VOLUME values wil be applied
4332 * Input:
4333 *  ucAuxSel: 00: No volume applied
4334 *            01: Volume applied to SCART1 ouput (SELECT_SCART_1)
4335 *            10: Volume applied to SCART2 ouput (SELECT_SCART_2)
4336 *            11: not use
4337 * Output:
4338 *  None
4339 * Return:
4340 *  STV82X8_I2C_ERROR = I2C's communication is failed.
4341 *  STV82X8_NO_ERROR = Success.
4342 ********************************************************************************/
4343unsigned char STV82x8_AuxVolSelection(unsigned char ucAuxSel)
4344{
4345 
4346    unsigned char   ucResult = STV82X8_NO_ERROR;
4347
4348#ifdef __STV_DEBUG__
4349    STV_FUNCTION;
4350#endif
4351   
4352    ucResult = I2cWriteSTV82x8(AUX_VOL_INDEX, ucAuxSel);   
4353 
4354    return ucResult; 
4355}
4356
4357
4358/*********************************************************************************
4359 * Function:
4360 *  unsigned char STV82x8_MuteSPDIF(BOOL bMute)
4361 * Description:
4362 *  The STV support internal and external SPDIF; but mute function only work on
4363 * internal path; therefore, we mute first the switch to internal path. When unmute
4364 * we check the current audio matrix then set internal or external path accordingly.
4365 * Return:
4366 *  STV82X8_I2C_ERROR = I2C's communication is failed.
4367 *  STV82X8_NO_ERROR = Success.
4368 ********************************************************************************/
4369unsigned char STV82x8_MuteSPDIF(BOOL bMute)
4370{
4371 
4372    unsigned char   ucResult = STV82X8_NO_ERROR;
4373    unsigned char   ucSPDIFMux = Internal_SPDIF;
4374    unsigned char   ucMatrixValue = 0;
4375
4376#ifdef __STV_DEBUG__
4377    STV_FUNCTION;
4378#endif
4379
4380    if(bMute)
4381    {
4382        STV82x8_SetSPDIFDigitalMute();
4383    }
4384    else
4385    {
4386        ucResult |= I2cReadSTV82x8(AUDIO_MATRIX3_INPUT, &ucMatrixValue ); 
4387        if( ((ucMatrixValue >> 3) &  0x07) == STV82X8_AUDIOINPUT_I2S )
4388            ucSPDIFMux = External_SPDIF;
4389        STV82x8_SetSPDIFDigitalUnMute();
4390    }
4391 
4392    STV82x8_Set_SPDIFOut(ucSPDIFMux, 0);                     
4393    return ucResult; 
4394}
4395
4396
4397
4398
4399unsigned char  PIO_SetLow( VOID )
4400{
4401        return STV82X8_NO_ERROR;
4402}
4403
4404
4405
4406unsigned char  PIO_SetHigh( VOID )
4407{
4408        return STV82X8_NO_ERROR;
4409}
4410
4411/***********************************************************************************
4412// unsigned char STV82x8_Enble_Equalizer(BOOL bEnable, unsigned char ucType, unsigned char ucIndex )
4413// The function is for Equalizer and Truble function selection, it inculdes data setting
4414// ucType  : type of LS_EQ_BAND(EQUALIZER_100HZ,EQUALIZER_330HZ, EQUALIZER_1KHZ, EQUALIZER_3P3KHZ,EQUALIZER_10KHZ)
4415//                       or BASS_TREBLE(LS_BASS_GAIN, LS_TREBLE_GAIN, HP_BASS_GAIN, HP_TREBLE_GAIN)
4416// ucIndex : index of Equalizer_Table or BASS_TREBLE_GAIN_TABLE
4417***********************************************************************************/
4418
4419unsigned char STV82x8_Enble_Equalizer(unsigned char ucOnOff, unsigned char ucType, unsigned char ucIndex )
4420{
4421    unsigned char   ucResult = STV82X8_NO_ERROR;
4422
4423#ifdef __STV_DEBUG__
4424    STV_FUNCTION;
4425#endif
4426    if (ucOnOff==ON){
4427
4428        ucResult = STV82x8_DataMaskWrite ( LS_EQ_BT_CTRL, STV82X8_EQUALIZE_ON, STV82X8_EQUALIZE_MASK );// Josie 8/21
4429
4430        ucResult = STV82x8_SetEqualizerValue(ucType, ucIndex );
4431        return ( ucResult );
4432     }
4433     else{
4434         ucResult = STV82x8_DataMaskWrite ( LS_EQ_BT_CTRL, STV82X8_TREBLE_ON, STV82X8_EQUALIZE_MASK ); //Josie 8/21
4435     
4436         ucResult = STV82x8_SetLoudSpkHeadPhoneGain( ucType, ucIndex);   
4437                return(ucResult);
4438     }
4439}
4440
4441/********************************************************************************************
4442*                        End Of File
4443********************************************************************************************/
4444
4445
4446int STV82x8_EXT_SetPrescale(STPrescaleInput_e STInput, int PrescaleValue)
4447{
4448        CONFINE(PrescaleValue, 0, 0x7f);
4449        switch(STInput)
4450        {
4451                case _ST_PRESCALE_MONO_:
4452                        STV82x8_DataMaskWrite(PRESCALE_MONO, PrescaleValue, PRESCALE_MONO_MASK);
4453                        break;
4454
4455                case _ST_PRESCALE_STEREO_:
4456                        STV82x8_DataMaskWrite(PRESCALE_STEREO, PrescaleValue, 0x7f);
4457                        break;
4458
4459                case _ST_RRESCALE_SAP_:
4460                        STV82x8_DataMaskWrite(PRESCALE_SAP, PrescaleValue, 0x7f);
4461                        break;
4462
4463                case _ST_PRESCALE_SIF_:
4464                        STV82x8_DataMaskWrite(PRESCALE_MONO, PrescaleValue, PRESCALE_MONO_MASK);
4465                        STV82x8_DataMaskWrite(PRESCALE_STEREO, PrescaleValue, 0x7f);
4466                        STV82x8_DataMaskWrite(PRESCALE_SAP, PrescaleValue, 0x7f);
4467                        break;
4468
4469                case _ST_PRESCALE_SCART_:
4470                        STV82x8_DataMaskWrite(PRESCALE_SCART, PrescaleValue, PRESCALE_MONO_MASK);
4471                        break;
4472
4473                case _ST_PRESCALE_I2S_:
4474                        STV82x8_DataMaskWrite(PRESCALE_I2S_0, PrescaleValue, 0x7f);
4475                        STV82x8_DataMaskWrite(PRESCALE_I2S_1, PrescaleValue, 0x7f);
4476                        STV82x8_DataMaskWrite(PRESCALE_I2S_2, PrescaleValue, 0x7f);
4477                        break;
4478
4479                case _ST_PRESCALE_I2S_0_:
4480                        STV82x8_DataMaskWrite(PRESCALE_I2S_0, PrescaleValue, 0x7f);
4481                        break;
4482                case _ST_PRESCALE_I2S_1_:
4483                        STV82x8_DataMaskWrite(PRESCALE_I2S_1, PrescaleValue, 0x7f);
4484                        break;
4485                case _ST_PRESCALE_I2S_2_:
4486                        STV82x8_DataMaskWrite(PRESCALE_I2S_2, PrescaleValue, 0x7f);
4487                        break;
4488
4489                default:
4490                        break;
4491        }
4492        return SUCCESS;
4493}
4494
4495
4496int STV82x8_EXT_SetScartOutputPath(STAudioScartInput_e STScartInput, STAudioScartOutput_e STScartOutput)
4497{
4498        switch(STScartOutput)
4499        {
4500                case _ST_SCART_OUTPUT_1_:
4501                        switch(STScartInput)
4502                        {
4503                                case _ST_SCART_INPUT_DSP_:
4504                                        STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x00, 0x07);
4505                                        break;
4506                                case _ST_SCART_INPUT_MONO_:
4507                                        STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x01, 0x07);
4508                                        break;
4509                                case _ST_SCART_INPUT_1_:
4510                                        STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x02, 0x07);
4511                                        break;
4512                                case _ST_SCART_INPUT_2_:
4513                                        STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x03, 0x07);
4514                                        break;
4515                                case _ST_SCART_INPUT_3_:
4516                                        STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x04, 0x07);
4517                                        break;
4518                                case _ST_SCART_INPUT_4_:
4519                                        STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x05, 0x07);
4520                                        break;
4521                                default:
4522                                        break;
4523                        }
4524                        break;
4525
4526                case _ST_SCART_OUTPUT_2_:
4527                        switch(STScartInput)
4528                        {
4529                                case _ST_SCART_INPUT_DSP_:
4530                                        STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x00<<4, 0x07<<4);
4531                                        break;
4532                                case _ST_SCART_INPUT_MONO_:
4533                                        STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x01<<4, 0x07<<4);
4534                                        break;
4535                                case _ST_SCART_INPUT_1_:
4536                                        STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x02<<4, 0x07<<4);
4537                                        break;
4538                                case _ST_SCART_INPUT_2_:
4539                                        STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x03<<4, 0x07<<4);
4540                                        break;
4541                                case _ST_SCART_INPUT_3_:
4542                                        STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x04<<4, 0x07<<4);
4543                                        break;
4544                                case _ST_SCART_INPUT_4_:
4545                                        STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x05<<4, 0x07<<4);
4546                                        break;
4547                                default:
4548                                        break;
4549                        }
4550                        break;
4551
4552                case _ST_SCART_OUTPUT_3_:
4553                        switch(STScartInput)
4554                        {
4555                                case _ST_SCART_INPUT_DSP_:
4556                                        STV82x8_DataMaskWrite(SCART3_OUTPUT_CTRL, 0x00, 0x07);
4557                                        break;
4558                                case _ST_SCART_INPUT_MONO_:
4559                                        STV82x8_DataMaskWrite(SCART3_OUTPUT_CTRL, 0x01, 0x07);
4560                                        break;
4561                                case _ST_SCART_INPUT_1_:
4562                                        STV82x8_DataMaskWrite(SCART3_OUTPUT_CTRL, 0x02, 0x07);
4563                                        break;
4564                                case _ST_SCART_INPUT_2_:
4565                                        STV82x8_DataMaskWrite(SCART3_OUTPUT_CTRL, 0x03, 0x07);
4566                                        break;
4567                                case _ST_SCART_INPUT_3_:
4568                                        STV82x8_DataMaskWrite(SCART3_OUTPUT_CTRL, 0x04, 0x07);
4569                                        break;
4570                                case _ST_SCART_INPUT_4_:
4571                                        STV82x8_DataMaskWrite(SCART3_OUTPUT_CTRL, 0x05, 0x07);
4572                                        break;
4573                                default:
4574                                        break;
4575                        }
4576                        break;
4577
4578                case _ST_SCART_OUTPUT_ADC_:
4579                        STV82x8_DataMaskWrite(ADC_CTRL, 0x08, 0x08);
4580                        switch(STScartInput)
4581                        {
4582                                case _ST_SCART_INPUT_1_:
4583                                        STV82x8_DataMaskWrite(ADC_CTRL, 0x00, 0x07);
4584                                        break;
4585                                case _ST_SCART_INPUT_2_:
4586                                        STV82x8_DataMaskWrite(ADC_CTRL, 0x01, 0x07);
4587                                        break;
4588                                case _ST_SCART_INPUT_3_:
4589                                        STV82x8_DataMaskWrite(ADC_CTRL, 0x02, 0x07);
4590                                        break;
4591                                case _ST_SCART_INPUT_4_:
4592                                        STV82x8_DataMaskWrite(ADC_CTRL, 0x03, 0x07);
4593                                        break;
4594                                case _ST_SCART_INPUT_MONO_:
4595                                        STV82x8_DataMaskWrite(ADC_CTRL, 0x04, 0x07);
4596                                        break;
4597                                default:
4598                                        break;
4599                        }
4600                        break;
4601        }
4602        return SUCCESS;
4603}
4604
4605
4606int STV82x8_EXT_SetAudioOutputPath(STAudioInput_e STInput, STAudioOutput_e STOutput)
4607{
4608        SAINT_CHECK((STInput>_ST_INPUT_INVALID_) && 
4609                                (STInput<_ST_INPUT_MAX_), FAILED);
4610
4611        if(STInput == _ST_INPUT_I2S_)
4612                STV82x8_EXT_PowerOffADC();
4613        else
4614                STV82x8_EXT_PowerOnADC();
4615
4616        switch(STOutput) 
4617        {
4618                case _ST_OUTPUT_LOUDSPEAKER_:
4619                        STV82x8_DataMaskWrite(AUDIO_MATRIX1_INPUT, STInput, STV82X8_MATRIX1_INPUT_MASK);
4620                        break;
4621
4622                case _ST_OUTPUT_HEADPHONE_:
4623                        STV82x8_DataMaskWrite(AUDIO_MATRIX1_INPUT, STInput<<3, STV82X8_MATRIX1_INPUT_MASK<<3);
4624                        break;
4625
4626                case _ST_OUTPUT_SCART1_:
4627                        STV82x8_DataMaskWrite(AUDIO_MATRIX2_INPUT, STInput, STV82X8_MATRIX1_INPUT_MASK);
4628                        break;
4629
4630                case _ST_OUTPUT_SCART2_:
4631                        STV82x8_DataMaskWrite(AUDIO_MATRIX2_INPUT, STInput<<3, STV82X8_MATRIX1_INPUT_MASK<<3);
4632                        break;
4633
4634                case _ST_OUTPUT_DELAY_:
4635                        STV82x8_DataMaskWrite(AUDIO_MATRIX3_INPUT, STInput, STV82X8_MATRIX1_INPUT_MASK);
4636                        break;
4637
4638                case _ST_OUTPUT_SPDIF_:
4639                        STV82x8_DataMaskWrite(AUDIO_MATRIX3_INPUT, STInput<<3, STV82X8_MATRIX1_INPUT_MASK<<3);
4640                        break;
4641
4642                default:
4643                        break;
4644        }
4645        return SUCCESS;
4646}
4647
4648static int SavedVolumeMode[5] = {DIFFERENTIAL_MODE, DIFFERENTIAL_MODE, DIFFERENTIAL_MODE, DIFFERENTIAL_MODE, DIFFERENTIAL_MODE};
4649int STV82x8_EXT_SetVolumeMode(STAudioVolumeModeDev_e AudioDev, int VolumeMode)
4650{
4651        SAINT_CHECK((VolumeMode == DIFFERENTIAL_MODE)
4652                                || (VolumeMode == INDEPENDANT_MODE), FAILED);
4653        switch(AudioDev)
4654        {
4655                case _ST_VOLUME_MODE_LS_:
4656                        if(INDEPENDANT_MODE == VolumeMode)
4657                                STV82x8_DataMaskWrite(VOLUME_MODES, 0x0<<0, 0x1<<0);
4658                        else
4659                                STV82x8_DataMaskWrite(VOLUME_MODES, 0x1<<0, 0x1<<0);
4660                        break;
4661
4662                case _ST_VOLUME_MODE_SRND_:
4663                                if(INDEPENDANT_MODE == VolumeMode)
4664                                        STV82x8_DataMaskWrite(VOLUME_MODES, 0x0<<1, 0x1<<1);
4665                                else
4666                                        STV82x8_DataMaskWrite(VOLUME_MODES, 0x1<<1, 0x1<<1);
4667                                break;
4668
4669                case _ST_VOLUME_MODE_HP_:
4670                        if(INDEPENDANT_MODE == VolumeMode)
4671                                STV82x8_DataMaskWrite(VOLUME_MODES, 0x0<<2, 0x1<<2);
4672                        else
4673                                STV82x8_DataMaskWrite(VOLUME_MODES, 0x1<<2, 0x1<<2);
4674                        break;
4675
4676
4677                case _ST_VOLUME_MODE_SCART1_:
4678                        if(INDEPENDANT_MODE == VolumeMode)
4679                                STV82x8_DataMaskWrite(VOLUME_MODES, 0x0<<3, 0x1<<3);
4680                        else
4681                                STV82x8_DataMaskWrite(VOLUME_MODES, 0x1<<3, 0x1<<3);
4682                        break;
4683
4684               
4685                case _ST_VOLUME_MODE_SCART2_:
4686                        if(INDEPENDANT_MODE == VolumeMode)
4687                                STV82x8_DataMaskWrite(VOLUME_MODES, 0x0<<4, 0x1<<4);
4688                        else
4689                                STV82x8_DataMaskWrite(VOLUME_MODES, 0x1<<4, 0x1<<4);
4690                        break;
4691
4692                default:
4693                        break;
4694        }
4695        SavedVolumeMode[AudioDev] = VolumeMode;
4696        return SUCCESS;
4697}
4698
4699
4700int STV82x8_EXT_SetVolume(STAudioVolumeDev_e AudioDev, int Volume)
4701{
4702        CONFINE(Volume, 0, 0x3ff);
4703        LOG(0, " My real Volume:%d\n", Volume);
4704        switch(AudioDev)
4705        {
4706                case _ST_VOLUME_LS_L_:
4707                        I2cWriteSTV82x8(LS_L_VOLUME_MSB, Volume >> NORMAL_VOLUME_SHIFT);
4708                        I2cWriteSTV82x8(LS_L_VOLUME_LSB, Volume & VOLUME_LSB_MASK);
4709                        break;
4710
4711                case _ST_VOLUME_LS_R_:
4712                        I2cWriteSTV82x8(LS_R_VOLUME_MSB, Volume >> NORMAL_VOLUME_SHIFT);
4713                        I2cWriteSTV82x8(LS_R_VOLUME_LSB, Volume & VOLUME_LSB_MASK);
4714                        break;
4715
4716                //In differential mode, Left channel means the volume, Right Channel means balance
4717                case _ST_VOLUME_LS_:
4718                        I2cWriteSTV82x8(LS_L_VOLUME_MSB, Volume >> NORMAL_VOLUME_SHIFT);
4719                        I2cWriteSTV82x8(LS_L_VOLUME_LSB, Volume & VOLUME_LSB_MASK);
4720                        break;
4721
4722                case _ST_VOLUME_LS_C_:
4723                        I2cWriteSTV82x8(LS_C_VOLUME_MSB, Volume >> NORMAL_VOLUME_SHIFT);
4724                        I2cWriteSTV82x8(LS_C_VOLUME_LSB, Volume & VOLUME_LSB_MASK);
4725                        break;
4726
4727                case _ST_VOLUME_LS_SUB_:
4728                        I2cWriteSTV82x8(LS_SUB_VOLUME_MSB, Volume >> NORMAL_VOLUME_SHIFT);
4729                        I2cWriteSTV82x8(LS_SUB_VOLUME_LSB, Volume & VOLUME_LSB_MASK);
4730                        break;
4731
4732                case _ST_VOLUME_MASTER_:
4733                        I2cWriteSTV82x8(LS_MASTER_VOLUME_MSB, Volume >> NORMAL_VOLUME_SHIFT);
4734                        I2cWriteSTV82x8(LS_MASTER_VOLUME_LSB, Volume & VOLUME_LSB_MASK);
4735                        break;
4736
4737                case _ST_VOLUME_LS_SL_:
4738                        I2cWriteSTV82x8(LS_SL_VOLUME_MSB, Volume >> NORMAL_VOLUME_SHIFT);
4739                        I2cWriteSTV82x8(LS_SL_VOLUME_LSB, Volume & VOLUME_LSB_MASK);
4740                        break;
4741
4742                case _ST_VOLUME_LS_SR_:
4743                        I2cWriteSTV82x8(LS_SR_VOLUME_MSB, Volume >> NORMAL_VOLUME_SHIFT);
4744                        I2cWriteSTV82x8(LS_SR_VOLUME_LSB, Volume & VOLUME_LSB_MASK);
4745                        break;
4746
4747                //In differential mode, Left channel means the volume, Right Channel means balance
4748                case _ST_VOLUME_LS_SURROUND_:
4749                        I2cWriteSTV82x8(LS_SL_VOLUME_MSB, Volume >> NORMAL_VOLUME_SHIFT);
4750                        I2cWriteSTV82x8(LS_SL_VOLUME_LSB, Volume & VOLUME_LSB_MASK);
4751                        break;
4752
4753                case _ST_VOLUME_HP_L_:
4754                        I2cWriteSTV82x8(HP_L_VOL_MSB, Volume >> NORMAL_VOLUME_SHIFT);
4755                        I2cWriteSTV82x8(HP_L_VOL_LSB, Volume & VOLUME_LSB_MASK);
4756                        break;
4757
4758                case _ST_VOLUME_HP_R_:
4759                        I2cWriteSTV82x8(HP_R_VOL_MSB, Volume >> NORMAL_VOLUME_SHIFT);
4760                        I2cWriteSTV82x8(HP_R_VOL_LSB, Volume & VOLUME_LSB_MASK);
4761                        break;
4762
4763                //In differential mode, Left channel means the volume, Right Channel means balance
4764                case _ST_VOLUME_HP_:
4765                        I2cWriteSTV82x8(HP_L_VOL_MSB, Volume >> NORMAL_VOLUME_SHIFT);
4766                        I2cWriteSTV82x8(HP_L_VOL_LSB, Volume & VOLUME_LSB_MASK);
4767                        break;
4768
4769                case _ST_VOLUME_SCART1_L_:
4770                        //Set Aux index to scart 1
4771                        STV82x8_DataMaskWrite(AUX_VOL_INDEX, 0x1, 0x3);
4772                        I2cWriteSTV82x8(AUX_L_VOL_MSB, Volume >> NORMAL_VOLUME_SHIFT);
4773                        I2cWriteSTV82x8(AUX_L_VOL_LSB, Volume & VOLUME_LSB_MASK);
4774                        break;
4775
4776                case _ST_VOLUME_SCART1_R_:     
4777                        //Set Aux index to scart 1
4778                        STV82x8_DataMaskWrite(AUX_VOL_INDEX, 0x1, 0x3);
4779                        I2cWriteSTV82x8(AUX_R_VOL_MSB, Volume >> NORMAL_VOLUME_SHIFT);
4780                        I2cWriteSTV82x8(AUX_R_VOL_LSB, Volume & VOLUME_LSB_MASK);
4781                        break;
4782
4783                //For differential mode
4784                case _ST_VOLUME_SCART1_:
4785                        //Set Aux index to scart 1
4786                        STV82x8_DataMaskWrite(AUX_VOL_INDEX, 0x1, 0x3);
4787                        I2cWriteSTV82x8(AUX_L_VOL_MSB, Volume >> NORMAL_VOLUME_SHIFT);
4788                        I2cWriteSTV82x8(AUX_L_VOL_LSB, Volume & VOLUME_LSB_MASK);
4789                        break;
4790
4791                case _ST_VOLUME_SCART2_L_:
4792                        //Set Aux index to scart 2
4793                        STV82x8_DataMaskWrite(AUX_VOL_INDEX, 0x2, 0x3);
4794                        I2cWriteSTV82x8(AUX_L_VOL_MSB, Volume >> NORMAL_VOLUME_SHIFT);
4795                        I2cWriteSTV82x8(AUX_L_VOL_LSB, Volume & VOLUME_LSB_MASK);
4796                        break;
4797
4798                case _ST_VOLUME_SCART2_R_:
4799                        //Set Aux index to scart 2
4800                        STV82x8_DataMaskWrite(AUX_VOL_INDEX, 0x2, 0x3);
4801                        I2cWriteSTV82x8(AUX_R_VOL_MSB, Volume >> NORMAL_VOLUME_SHIFT);
4802                        I2cWriteSTV82x8(AUX_R_VOL_LSB, Volume & VOLUME_LSB_MASK);
4803                        break;
4804
4805                //For differential mode
4806                case _ST_VOLUME_SCART2_:
4807                        //Set Aux index to scart 2
4808                        STV82x8_DataMaskWrite(AUX_VOL_INDEX, 0x2, 0x3);
4809                        I2cWriteSTV82x8(AUX_L_VOL_MSB, Volume >> NORMAL_VOLUME_SHIFT);
4810                        I2cWriteSTV82x8(AUX_L_VOL_LSB, Volume & VOLUME_LSB_MASK);
4811                        break;
4812
4813                default:
4814                        break;
4815        }
4816        return SUCCESS;
4817}
4818
4819
4820int STV82x8_EXT_SetBalance(STAudioVolumeDev_e AudioDev, int Balance)
4821{
4822        CONFINE(Balance, 0, 0x3ff);
4823        if(Balance == 0x200)
4824                Balance = 0;
4825        else if(Balance < 0x200)
4826                Balance = Balance + 0x200;// 0x200-->0x3ff
4827        else
4828                Balance = Balance - 0x200;// 0x1-->0x1ff
4829
4830        //here we need to convert Balance value to register value
4831        switch(AudioDev)
4832        {
4833                case _ST_VOLUME_LS_:
4834                        I2cWriteSTV82x8(LS_R_VOLUME_MSB, Balance >> NORMAL_BALANCE_SHIFT);
4835                        I2cWriteSTV82x8(LS_R_VOLUME_LSB, Balance & BALANCE_LSB_MASK);
4836                        break;
4837
4838                case _ST_VOLUME_HP_:
4839                        I2cWriteSTV82x8(HP_R_VOL_MSB, Balance >> NORMAL_BALANCE_SHIFT);
4840                        I2cWriteSTV82x8(HP_R_VOL_LSB, Balance & BALANCE_LSB_MASK);
4841                        break;
4842
4843                case _ST_VOLUME_LS_SURROUND_:
4844                        I2cWriteSTV82x8(LS_SR_VOLUME_MSB, Balance >> NORMAL_BALANCE_SHIFT);
4845                        I2cWriteSTV82x8(LS_SR_VOLUME_LSB, Balance & BALANCE_LSB_MASK);
4846                        break;
4847
4848                case _ST_VOLUME_SCART1_:
4849                        //Set Aux index to scart 1
4850                        STV82x8_DataMaskWrite(AUX_VOL_INDEX, 0x1, 0x3);
4851                        I2cWriteSTV82x8(AUX_R_VOL_MSB, Balance >> NORMAL_BALANCE_SHIFT);
4852                        I2cWriteSTV82x8(AUX_R_VOL_LSB, Balance & BALANCE_LSB_MASK);
4853                        break;
4854
4855                case _ST_VOLUME_SCART2_:
4856                        //Set Aux index to scart 2
4857                        STV82x8_DataMaskWrite(AUX_VOL_INDEX, 0x2, 0x3);
4858                        I2cWriteSTV82x8(AUX_R_VOL_MSB, Balance >> NORMAL_BALANCE_SHIFT);
4859                        I2cWriteSTV82x8(AUX_R_VOL_LSB, Balance & BALANCE_LSB_MASK);
4860                        break;
4861
4862                default:
4863                        break;
4864        }
4865        return SUCCESS;
4866}
4867
4868
4869int STV82x8_EXT_SetMute(STAudioMuteDev_e AudioDev, BOOL bMute)
4870{
4871        unsigned char MuteValue;
4872        MuteValue = bMute?1:0;
4873        switch (AudioDev) 
4874        {
4875                case _ST_SOFTMUTE_LS_:
4876                        STV82x8_DataMaskWrite(MUTE_DIGITAL, MuteValue << 0, (0x01<<0));
4877                        break;
4878       
4879                case _ST_SOFTMUTE_CENTER_:
4880                        STV82x8_DataMaskWrite(MUTE_DIGITAL, MuteValue << 1, (0x01<<1));
4881                        break;
4882       
4883                case _ST_SOFTMUTE_SUB_:
4884                        STV82x8_DataMaskWrite(MUTE_DIGITAL, MuteValue << 2, (0x01<<2));
4885                        break;
4886       
4887                case _ST_SOFTMUTE_SRND_:
4888                        STV82x8_DataMaskWrite(MUTE_DIGITAL, MuteValue << 3, (0x01<<3));
4889                        break;
4890       
4891                case _ST_SOFTMUTE_SCART1_:
4892                        STV82x8_DataMaskWrite(MUTE_DIGITAL, MuteValue << 4, (0x01<<4));
4893                        break;
4894       
4895                case _ST_SOFTMUTE_SCART2_:
4896                        STV82x8_DataMaskWrite(MUTE_DIGITAL, MuteValue << 5, (0x01<<5));
4897                        break;
4898       
4899                case _ST_SOFTMUTE_SPDIF_:
4900                        STV82x8_DataMaskWrite(MUTE_DIGITAL, MuteValue << 6, (0x01<<6));
4901                        break;
4902       
4903                case _ST_SOFTMUTE_HP_:
4904                        STV82x8_DataMaskWrite(MUTE_DIGITAL, MuteValue << 7, (0x01<<7));
4905                        break;
4906       
4907                //Adjust in F7
4908                case _ST_DACMUTE_LSLR_:
4909                        STV82x8_DataMaskWrite(DAC_CTRL, MuteValue << 1, (0x01<<1));
4910                        break;
4911
4912                case _ST_DACMUTE_CSUB_:
4913                        STV82x8_DataMaskWrite(DAC_CTRL, MuteValue << 2, (0x01<<2));
4914                        break;
4915
4916                case _ST_DACMUTE_SHP_:
4917                        STV82x8_DataMaskWrite(DAC_CTRL, MuteValue << 3, (0x01<<3));
4918                        break;
4919
4920                case _ST_DACMUTE_SCART_:
4921                        STV82x8_DataMaskWrite(DAC_CTRL, MuteValue << 4, (0x01<<4));
4922                        break;
4923
4924                case _ST_OUTPUT_SCART1_MUTE_:
4925                        STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, MuteValue << 3, (0x01<<3)); 
4926                        break;
4927
4928                case _ST_OUTPUT_SCART2_MUTE_:
4929                        STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, MuteValue << 7, (0x01<<7)); 
4930                        break;
4931
4932                case _ST_OUTPUT_SCART3_MUTE_:
4933                        STV82x8_DataMaskWrite(SCART3_OUTPUT_CTRL, MuteValue << 3, (0x01<<3)); 
4934                        break;
4935
4936                default:
4937                        break;
4938        }
4939        return 0;
4940}
4941
4942
4943int STV82x8_EXT_PowerOffADC(void)
4944{
4945    unsigned char  ucRegVal;
4946        I2cReadSTV82x8( ADC_CTRL, &ucRegVal );
4947        if(( ucRegVal & STV82X8_ADC_WAKEUP_MASK ) == 1 )
4948        {
4949                STV82x8_DataMaskWrite(ADC_CTRL, 0x00, 0x08);
4950                usleep( 500 ); //35ms
4951        }
4952        return SUCCESS;
4953}
4954
4955
4956int STV82x8_EXT_PowerOnADC(void)
4957{
4958    unsigned char  ucRegVal;
4959        I2cReadSTV82x8( ADC_CTRL, &ucRegVal );
4960        if(( ucRegVal & STV82X8_ADC_WAKEUP_MASK ) == 0 )
4961        {
4962                STV82x8_DataMaskWrite(ADC_CTRL, 0x08, 0x08);
4963                usleep( 500 ); //35ms
4964        }
4965        return SUCCESS;
4966}
4967
4968int STV82x8_EXT_SetSPDIFExtInput(BOOL bExtSrc)
4969{
4970        if(bExtSrc)
4971                STV82x8_DataMaskWrite(DAC_CTRL, 0x20, 0x20);
4972        else
4973        {
4974                STV82x8_DataMaskWrite(CHANNEL_MATRIX_LS, 0x40, 0x40);
4975                STV82x8_DataMaskWrite(DAC_CTRL, 0x00, 0x20);
4976        }
4977        return SUCCESS;
4978}
4979
4980
4981int STV82x8_EXT_EnableLSEqualizerBassTreble(BOOL bEnable)
4982{
4983        if(bEnable)
4984                STV82x8_DataMaskWrite(LS_EQ_BT_CTRL, 0x01, 0x01);
4985        else
4986                STV82x8_DataMaskWrite(LS_EQ_BT_CTRL, 0x00, 0x01);
4987        return SUCCESS;
4988}
4989
4990int STV82x8_EXT_EnableLSEqualizer(BOOL bEnable)
4991{
4992        if(bEnable)
4993                STV82x8_DataMaskWrite(LS_EQ_BT_CTRL, 0x00, 0x02);
4994        else
4995                STV82x8_DataMaskWrite(LS_EQ_BT_CTRL, 0x02, 0x02);
4996        return SUCCESS;
4997}
4998
4999
5000int STV82x8_EXT_EnableLSBassTreble(BOOL bEnable)
5001{
5002        if(bEnable)
5003                STV82x8_DataMaskWrite(LS_EQ_BT_CTRL, 0x02, 0x02);
5004        else
5005                STV82x8_DataMaskWrite(LS_EQ_BT_CTRL, 0x00, 0x02);
5006        return SUCCESS;
5007}
5008
5009
5010int STV82x8_EXT_EnableHPBassTreble(BOOL bEnable)
5011{
5012        if(bEnable)
5013                STV82x8_DataMaskWrite(LS_EQ_BT_CTRL, 0x04, 0x04);
5014        else
5015                STV82x8_DataMaskWrite(LS_EQ_BT_CTRL, 0x00, 0x04);
5016        return SUCCESS;
5017}
5018
5019
5020int STV82x8_EXT_SetBass(int Value, BOOL bHP)
5021{
5022        CONFINE(Value, 0, 0xff);
5023
5024        //Convert Value to register value
5025        if(Value >= 0xD0)
5026                Value = Value - 0xD0 + 1;       // 0x00-->0x30
5027        else
5028                Value = 0xD0 - Value;           // 0x1-->0xD0
5029
5030        if(bHP)
5031                I2cWriteSTV82x8(HP_BASS_GAIN, Value);
5032        else
5033                I2cWriteSTV82x8(LS_BASS_GAIN, Value);
5034
5035        return SUCCESS;
5036}
5037
5038
5039int STV82x8_EXT_SetTreble(int Value, BOOL bHP)
5040{
5041        CONFINE(Value, 0, 0xff);
5042
5043        //Convert Value to register value
5044        if(Value >= 0xD0)
5045                Value = Value - 0xD0 + 1;       // 0x00-->0x30
5046        else
5047                Value = 0xD0 - Value;           // 0x1-->0xd0
5048
5049        if(bHP)
5050                I2cWriteSTV82x8(HP_TREBLE_GAIN, Value);
5051        else
5052                I2cWriteSTV82x8(LS_TREBLE_GAIN, Value);
5053        return SUCCESS;
5054
5055}
5056
5057int STV82x8_EXT_SetLSEqulizer(int BandIndex, int Value)
5058{
5059        SAINT_CHECK((BandIndex>=0) && (BandIndex<5), FAILED);
5060        CONFINE(Value, 0, 0xff);
5061
5062        //Convert Value to register value
5063        if(Value >= 0xD0)
5064                Value = Value - 0xD0 + 1;       // 0x00-->0x30
5065        else
5066                Value = 0xD0 - Value;           // 0xd0-->0x00
5067       
5068        I2cWriteSTV82x8(LS_EQ_BAND + BandIndex, Value);
5069        return SUCCESS;
5070}
5071
5072
5073int STV82x8_EXT_GetSoundSystem_Independ(unsigned char * pucSoundSystem, BOOL bDetectFM)
5074{
5075    unsigned char ucRegValue, ucSTSoundID;
5076
5077    if(bDetectFM)
5078    {
5079        STV82x8_GetSoundSignalState( &ucRegValue );
5080        if( ucRegValue == STV82X8_SOUNDSIGNAL_UNLOCKED )
5081        {
5082            *pucSoundSystem = MONO;
5083            return ( STV82X8_RESOURCE_ERROR );
5084        }
5085    }
5086
5087        I2cReadSTV82x8( AUTOSTD_DEM_STATUS, &ucRegValue );
5088
5089        ucSTSoundID = ( ucRegValue & STV82X8_AUTOSTD_DEM_STATUS_MASK );
5090        if ( ucSTSoundID == (STV82X8_LCK_DET | STV82X8_ST_DET | STV82X8_SAP_SQ | STV82X8_SAP_DET) )
5091                *pucSoundSystem = SAP_STEREO;
5092        else if ( (ucSTSoundID & (STV82X8_SAP_SQ | STV82X8_SAP_DET)) == (STV82X8_SAP_SQ | STV82X8_SAP_DET))
5093                *pucSoundSystem = SAP;
5094        else if ( (ucSTSoundID & (STV82X8_LCK_DET | STV82X8_ST_DET)) ==  (STV82X8_LCK_DET | STV82X8_ST_DET))
5095                *pucSoundSystem = STEREO;
5096        else
5097                *pucSoundSystem = MONO;
5098
5099        return(SUCCESS);
5100}
5101
5102
5103unsigned char STV82x8_EXT_OpenDevice(unsigned char ucSubAddr, int I2CMasterNum)
5104{
5105    INT     nRet;
5106    unsigned char   ucResult = STV82X8_NO_ERROR;   
5107 
5108        gSlaveAddr = ucSubAddr;
5109
5110        SAINT_CHECK((I2CMasterNum == 1) || (I2CMasterNum == 2), STV82X8_I2C_ERROR);
5111
5112    // check for I2C file descriptor for audio device
5113        if(gSTV82x8_i2cfd)
5114        return ucResult;
5115        if(I2CMasterNum == 1)
5116                gSTV82x8_i2cfd = open("/dev/i2c-0", O_RDWR);
5117        else
5118                gSTV82x8_i2cfd = open("/tmp/i2c-1", O_RDWR);
5119               
5120        if(gSTV82x8_i2cfd<0)
5121        {
5122        gSTV82x8_i2cfd = 0;
5123        TRACE0(("Open I2c device failed\n"));
5124        return STV82X8_I2C_ERROR;
5125        }
5126        printf("OPEN SUCCESS\n");
5127    // can we communicate with the device ?
5128        if((nRet = ioctl(gSTV82x8_i2cfd, I2C_SLAVE, ucSubAddr>>1)) < 0)
5129        {
5130                close(gSTV82x8_i2cfd);
5131                gSTV82x8_i2cfd = 0;
5132                TRACE0(("Open I2C IOCTL failed\n"));
5133                return STV82X8_I2C_ERROR;
5134        }
5135        return ucResult;
5136}
5137
5138void STV82x8_EXT_InitializeThread(void* arg)
5139{
5140    unsigned char   ucResult = STV82X8_NO_ERROR;   
5141        if (ucResult == STV82X8_NO_ERROR)
5142    {
5143        if(STV82x8_UpdatePatchData())
5144        {
5145            TRACE0(("UpdatePatchData Failed\n"));         
5146            return;// STV82X8_I2C_ERROR;
5147        }
5148       
5149        if(STV82x8_InitDSP())
5150        {
5151            TRACE0(("InitDSP Failed\n"));                   
5152            return;// STV82X8_I2C_ERROR;
5153        }
5154           
5155        if(STV82x8_InitRegister())
5156        {
5157            TRACE0(("InitRegister Failed\n"));                   
5158            return;// STV82X8_I2C_ERROR;
5159        }
5160           
5161        if(STV82x8_SetI2SInOut( STV82X8_I2S_OUTPUT ))             //Reg 01
5162        {
5163            TRACE0(("SetI2SInOut Failed\n"));                             
5164            return;// STV82X8_I2C_ERROR;
5165        }
5166           
5167        if(STV82x8_SetI2SOutputSignal( STV82X8_I2S_OUTPUT_LR ))   //Reg 56
5168        {
5169            TRACE0(("SetI2SOutputSignal Failed\n"));                                       
5170            return;// STV82X8_I2C_ERROR;
5171        }
5172
5173        // do SAP/Stereo/Mono check           
5174        if(STV82x8_All_SoundSystem_Check())
5175        {
5176            TRACE0(("STV82x8_All_SoundSystem_Check\n"));                                       
5177            return;// STV82X8_I2C_ERROR;
5178        }
5179
5180                STV82x8_SetSubWoofer(STV82x8_SUBWOOFER_ON, STV82x8_BASSMNGT_ON, STV82x8_GAINSW_ON,
5181                                                        STV82x8_STLFEAdd_ON, STV82x8_DolbyPro_OFF, STV82x8_BASSCONFI_0);
5182                STV82x8_EXT_SetMute(_ST_SOFTMUTE_LS_, 1);
5183                STV82x8_EXT_SetVolume(_ST_VOLUME_LS_, 0);
5184                STV82x8_EXT_SetVolume(_ST_VOLUME_MASTER_, 0x3ff);
5185
5186        }
5187        return;
5188}
5189
5190//static pthread_t stv82x8_init_thread = 0;
5191
5192unsigned char STV82x8_EXT_Initialize(STAudioDrvInitParam* pInit)
5193{
5194        unsigned char  ucResult = STV82X8_NO_ERROR;
5195
5196    if(STV82x8_EXT_OpenDevice(pInit->SlaveAddr, pInit->I2CMasterNum))
5197        return STV82X8_I2C_ERROR;
5198       
5199        ucResult = STV82x8_SwReset();
5200
5201//      if(pInit->bThreadInit)
5202//              pthread_create(&stv82x8_init_thread, NULL, STV82x8_EXT_InitializeThread, NULL);
5203//      else
5204                STV82x8_EXT_InitializeThread(NULL);
5205        return ucResult;
5206}
5207
5208
Note: See TracBrowser for help on using the repository browser.