/****************************************************************************/ /* */ /* Copyright (c) 2003 Trident Technologies, Inc. */ /* All rights reserved */ /* */ /* The content of this file or document is CONFIDENTIAL and PROPRIETARY */ /* to Trident Microsystems, Inc. It is subject to the terms of a */ /* License Agreement between Licensee and Trident Technologies, Inc. */ /* restricting among other things, the use, reproduction, distribution */ /* and transfer. Each of the embodiments, including this information and */ /* any derivative work shall retain this copyright notice */ /* */ /****************************************************************************/ /****************************************************************************** COPYRIGHT (C) ISD ST 2005 - File name STV82X8.c -. Creation date 18/May/2005 -. Author Name MS Song ( e.g ST-Korea ) -. History Version 1.0.0 18/May/2005 Compile Under visual C++ Version 1.0.1 10/Jun/2005 Add STV82x8_SetScartVolumeMode() STV82x8_SetHPBalance() STV82x8_SetHPConfiguration() STV82x8_GetHPStatus() STV82x8_SetPinkNoiseGenerator() STV82x8_SetSubWoofer() STV82x8_SetI2SInOut() STV82x8_SetI2SOutputSignal() STV82x8_SetSRS_InputMode() STV82x8_SetSRS_TRUBASS() STV82x8_SetDynamicBass() STV82x8_SetAVDelay() Modify STV82x8_Initialize() STV82x8_UpdatePatchData() STV82x8_SetLeftVolume() STV82x8_SetRightVolume() STV82x8_SetCenterVolume() STV82x8_SetSurroundLeftVolume() STV82x8_SetSurroundRightVolume() STV82x8_SetHPLeftVolume() STV82x8_SetHPRightVolume() STV82x8_SetMasterVolume() STV82x8_SetLSBalance() STV82x8_ControlTurboSound() STV82x8_AutoVolumeCtrl() STV82x8_CheckElectricalShock() STV82x8_GetSoundSignalState() ttucPatchV13h Remove STV82x8_Set_I2SOut() Version 1.0.2 15/Jun/2005 Modify ttucPatchV14h Version 1.0.3 17/Jun/2005 Add STV82x8_SetDefaultValueFromSTDConfig Modify ttucPatchV15h STV82x8_SwReset STV82x8_InitDSP STV82x8_SetSubWoofer STV82x8_SetMonoStereoDefaultPrescale STV82x8_SetPseudoEffect STV82x8_SetSRSEffect STV82x8_ControlTurboSound STV82x8_SetOutput_RFConfig STV82x8_SetInOutput_ScartConfig STV82x8_AudioMatrix_LSOut STV82x8_Control_ChannelMatrixLS STV82x8_Set_SPDIFOut STV82x8_ForcedMono STV82x8_ReturnToStereoFromMono STV82x8_PlayBeeperSound STV82x8_All_SoundSystem_Check Version 1.0.4 29/Jun/2005 Modify STV82x8_AutoVolumeCtrl STV82x8_InitRegister STV82x8_GetSoundSystem STV82x8_SetAVDelay Version 1.0.5 16/Sep/2005 Add VOLUME_TABLE1 BEEPER_DURATION_TABLE_1 BEEPER_FREQ_VOL_TABLE_1 BEEPER_DURATION_TABLE_2 BEEPER_FREQ_VOL_TABLE_2 STV82x8_SetValueForSPDIF STV82x8_BeeperAmbulanceSound STV82x8_GetSoundSystem_Independ STV82x8_ChangeMTS_Manual STV82x8_SetStereoTimeOut STV82x8_SetScartDACMute STV82x8_SetScartDACUnMute STV82x8_SetLeftScartVolume STV82x8_SetRightScartVolume STV82x8_ScartOutBalance STV82x8_SetSRSWOW_Effect STV82x8_SetSRSTRS_DolbyPro1_Effect Delete STV82x8_SetScart2DigitalMute STV82x8_SetScart2DigitalUnMute STV82x8_SetSRSGain STV82x8_SetSRSEffect Modify ttucPatchV18h STV82x8_GetSoundSignalState STV82x8_SetDefaultValueFromSTDConfig STV82x8_SetSubWoofer STV82x8_SetPseudoEffect STV82x8_SetSRS_InputMode STV82x8_PlayBeeperSound -. Description This driver contains the code of the API functions for STV82x8 and is working for 8bit micom, not relate to ST20. The driver will be built according to the value of the target platform as defined by the each STV82x8 families. For AGC_GAIN, this value has to be adjusted on the each chassis. *************************************************************************************/ ////////////////////////////////////////////////////////////////////////////////////// // // $Log: STV82x8.c,v $ // Revision 1.1 2011/07/08 03:43:14 megakiss // *** empty log message *** // // Revision 1.1.1.1 2009/01/09 03:18:18 hwatk // DSTHAL Base Skeleton, which is imported at 2009.01.09. // // Revision 1.1.1.1 2008/01/08 23:40:21 jhkoh // first release // // Revision 1.4 2007/04/02 11:36:08 jhkoh // audio °ü·Ã Ãß°¡. // // Revision 1.3 2007/03/22 11:51:34 hwatk // H0_13 // // - Resolution Á¤º¸ °ü·Ã. // . DHL_CAP_PresetCallback() ÇÔ¼ö ÂüÁ¶. // - DDM70 ES Board °ü·Ã // . ¸ðµç Video ÀÔ·Â ±â´É È®ÀÎ (CVBS0/1, SVIDEO0/1, VGA, HDMI0/1) // // Revision 1.2 2007/03/22 11:50:29 hwatk // H0_13 // // - Resolution Á¤º¸ °ü·Ã. // . DHL_CAP_PresetCallback() ÇÔ¼ö ÂüÁ¶. // - DDM70 ES Board °ü·Ã // . ¸ðµç Video ÀÔ·Â ±â´É È®ÀÎ (CVBS0/1, SVIDEO0/1, VGA, HDMI0/1) // // Revision 1.1 2007/02/23 13:42:55 hwatk // H0_10 // // Revision 1.29 2006/09/27 05:16:22 blance // Update init interface // // Revision 1.28 2006/09/13 23:45:01 teresa // add i2c_num parameter, since different project connect different i2c number // // Revision 1.27 2006/09/13 10:22:06 blance // Add ext func. // // Revision 1.26 2006/09/08 09:16:33 blance // Add audio path switch. // // Revision 1.25 2006/09/07 03:58:12 blance // Update from Wistron. // // Revision 1.24 2006/09/05 00:59:14 blance // Update from Wistron. // // Revision 1.23 2006/09/01 09:48:21 blance // Add for extend routines. // // Revision 1.22 2006/08/14 21:25:15 teresa // for fast boot, to yield // // Revision 1.21 2006/08/05 22:37:32 teresa // for second I2c support. It's temp, we may need pass parameters in VDL to decide first or second I2C. // // Revision 1.20 2006/08/01 23:27:47 simon // fix careless bug when doing mask in mute function // // Revision 1.19 2006/08/01 22:17:37 simon // fix SAP problem and address SPDIF mute problem // for external path // // Revision 1.18 2006/07/29 02:30:42 simon // add headphone output matix in I2S and Scart output routines // // Revision 1.17 2006/07/28 23:47:08 simon // fix headphone problem, add subwoofer, and av selection // // Revision 1.16 2006/07/18 20:21:18 teresa // comment out some new modification temporaly, since it will cause no audio output. // // Revision 1.15 2006/07/18 02:54:04 teresa // *** empty log message *** // // Revision 1.14 2006/07/17 09:07:54 simon // 1. add dialog, trubass level for LS and Headphone // 2. support turbass on headphone // // Revision 1.13 2006/07/17 08:12:23 simon // 1. add headphone control // 2. enable Smart Vol. control for Loudspeaker and Headphone // 3. add ST Wide Surround Mode // // Revision 1.12 2006/07/13 09:10:06 simon // careless mistake: use mask write function instead of // over write function. // // Revision 1.11 2006/07/13 08:40:28 simon // add function to set each sound mode // // Revision 1.10 2006/07/13 00:09:37 teresa // 1. Fix SAP channel on left channel // 2. More SPDIF out fix // // Revision 1.9 2006/07/04 02:36:51 simon // 1. add I2S prescale for each I2S input // 2. change sound system detection // 3. set default timeout for stereo // // Revision 1.8 2006/07/03 23:52:54 simon // set I2S prescale equal to analog gain // // Revision 1.7 2006/07/03 20:50:53 simon // fix multi-defination problem // // Revision 1.6 2006/07/03 17:57:56 simon // fix SRS input mode and move balance table to header file // // Revision 1.5 2006/06/27 20:26:15 teresa // NO audio sound fix // // Revision 1.4 2006/06/23 23:38:42 simon // 1. add auto mute if no signal // 2. add mute all fucntion // 3. add bass and treble gain on Loud Speaker // // Revision 1.3 2006/06/21 22:41:44 simon // make code readable and following our coding standard // // ////////////////////////////////////////////////////////////////////////////////////// /*********************************************************************************** * Header files **********************************************************************************/ #include "stdio.h" #include "stdlib.h" #include "unistd.h" #include #include #include #include #include #include #include #include #include "i2c.h" #include "typedef.h" #include "sysdef.h" #include "stv82x8_reg.h" #include "patch.h" //#define SECOND_I2C //#define __STV_DEBUG__ /*********************************************************************************** * Global variables **********************************************************************************/ static INT gSTV82x8_i2cfd = 0; static unsigned char gSlaveAddr = 0x80; // default static unsigned char gI2C_num = 0; //defult use first I2C. #if 0 // not reference now static USHORT VOLUME_TABLE1[] = { 0x5500,0x5C00,0x6400,0x6C00,0x7400,0x7C00,0x8300,0x8900,0x8F00,0x9500, //2 0.5~9.5 0x9A00,0x9E00,0xA200,0xA600,0xAA00,0xAE00,0xB000,0xB100,0xB300,0xB500, //2 10.5~19.5 0xB700,0xB900,0xBB00,0xBD00,0xBF00,0xC100,0xC300,0xC480,0xC580,0xC680, //2 20.5~29.5 0xC780,0xC880,0xC980,0xCA80,0xCB80,0xCC80,0xCD80,0xCE80,0xCF80,0xD080, //2 30.5~39.5 0xD180,0xD280,0xD380,0xD480,0xD580,0xD680,0xD701,0xD781,0xD801,0xD881, //2 40.5~49.5 0xD901,0xD981,0xDA01,0xDA81,0xDB01,0xDB81,0xDC01,0xDC81,0xDD01,0xDD81, //2 50.5~59.5 0xDE01,0xDE81,0xDF01,0xDF81,0xE001,0xE081,0xE101,0xE181,0xE200,0xE201, //2 60.5~69.5 0xE202,0xE281,0xE300,0xE301,0xE302,0xE381,0xE400,0xE401,0xE402,0xE481, //2 70.5~79.5 0xE500,0xE501,0xE502,0xE581,0xE600,0xE601,0xE602,0xE681,0xE700,0xE701, //2 80.5~89.5 0xE702,0xE781,0xE800,0xE801,0xE802,0xE881,0xE900,0xE901,0xE902,0xE903, //2 90.5~99.5 }; static unsigned char BEEPER_OFF_TABLE[9] = { 0xC5, 0xA5, 0x85, 0x65, 0x46, 0x44, 0x42, 0x40, 0x40 }; static unsigned char BEEPER_DURATION_TABLE_2[10] = { 0x13, 0x13, 0x13, 0x13, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x73 }; static unsigned char BEEPER_FREQ_VOL_TABLE_2[10] = { 0x74, 0x94, 0x74, 0x94, 0x54, 0x74, 0x54, 0x34, 0x54, 0x14 }; #endif USHORT VOLUME_TABLE[] = { 0x5200,0x5800,0x6000,0x6800,0x7000,0x7800,0x8000,0x8600,0x8C00,0x9200, //2 0~9 0x9800,0x9C00,0xA000,0xA400,0xA800,0xAC00,0xB000,0xB000,0xB200,0xB400, //2 10~19 0xB600,0xB800,0xBA00,0xBC00,0xBE00,0xC000,0xC200,0xC400,0xC500,0xC600, //2 20~29 0xC700,0xC800,0xC900,0xCA00,0xCB00,0xCC00,0xCD00,0xCE00,0xCF00,0xD000, //2 30~39 0xD100,0xD200,0xD300,0xD400,0xD500,0xD600,0xD700,0xD702,0xD800,0xD802, //2 40~49 0xD900,0xD902,0xDA00,0xDA02,0xDB00,0xDB02,0xDC00,0xDC02,0xDD00,0xDD02, //2 50~59 0xDE00,0xDE02,0xDF00,0xDF02,0xE000,0xE002,0xE100,0xE102,0xE200,0xE201, //2 60~69 0xE202,0xE203,0xE300,0xE301,0xE302,0xE303,0xE400,0xE401,0xE402,0xE403, //2 70~79 0xE500,0xE501,0xE502,0xE503,0xE600,0xE601,0xE602,0xE603,0xE700,0xE701, //2 80~89 0xE702,0xE703,0xE800,0xE801,0xE802,0xE803,0xE900,0xE901,0xE902,0xE903, //2 90~100 0xEA00 }; INT gSizeofVolumeTable = sizeof(VOLUME_TABLE)/sizeof(VOLUME_TABLE[0]); unsigned char BASS_TREBLE_GAIN_TABLE[] = { 0xB0,0xAF,0xAE,0xAD,0xAC,0xAB,0xAA,0xA9,0xA8,0xA7,0xA6,0xA5,0xA4,0xA3,0xA2,0xA1, // 0xB0 = -12 db 0xA0,0x9F,0x9E,0x9D,0x9C,0x9B,0x9A,0x99,0x98,0x97,0x96,0x95,0x94,0x93,0x92,0x91, 0x80,0x7F,0x7E,0x7D,0x7C,0x7B,0x7A,0x79,0x78,0x77,0x76,0x75,0x74,0x73,0x72,0x71, 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F, 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F, 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F, 0x30 // 0x30 = 12 db }; INT gSizeOfBassTrebleTable = sizeof(BASS_TREBLE_GAIN_TABLE)/sizeof(BASS_TREBLE_GAIN_TABLE[0]); unsigned char BALANCE_TABLE[] = { 0x80,0x82,0x84,0x86,0x88,0x8A,0x8B,0x8C,0x8D,0x8E, 0xC0,0xC2,0xC4,0xC6,0xC8,0xCA,0xCB,0xCC,0xCD,0xCE, 0xD0,0xD2,0xD4,0xD6,0xD8,0xDA,0xDB,0xDC,0xDD,0xDE, 0xE0,0xE2,0xE4,0xE6,0xE8,0xEA,0xEB,0xEC,0xED,0xEE, 0xF0,0xF2,0xF4,0xF6,0xF8,0xFA,0xFB,0xFC,0xFD,0xFE, 0x00, 0x02,0x04,0x06,0x07,0x08,0x0A,0x0B,0x0C,0x0D,0x0E, 0x12,0x14,0x16,0x17,0x18,0x1A,0x1B,0x1C,0x1D,0x1E, 0x22,0x24,0x26,0x27,0x28,0x2A,0x2B,0x2C,0x2D,0x2E, 0x32,0x34,0x36,0x37,0x38,0x3A,0x3B,0x3C,0x3D,0x3E, 0x72,0x74,0x76,0x77,0x78,0x7A,0x7B,0x7C,0x7D,0x7F }; INT gSizeOfBalanceTable = sizeof(BALANCE_TABLE)/sizeof(BALANCE_TABLE[0]); static unsigned char EQUALIZER_TABLE[] = { 0xDA,0xDC,0xDE,0xE0,0xE4,0xE8,0xEC,0xF0,0xF4,0xF8,0xFC, //2 11step 0x00, 0x04,0x08,0x0C,0x10,0x14,0x18,0x1C,0x20,0x22,0x24,0x26,0x28 //2 12step }; // Forbbiden to set Beeper Volume as 0 during Beeper on static unsigned char BEEPER_ON_TABLE[9] = { 0x45, 0x65, 0x85, 0x65, 0x85, 0xA6, 0xA4, 0xA2, 0xA0 }; static unsigned char BEEPER_DURATION_TABLE_1[9] = { 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x7b }; static unsigned char BEEPER_FREQ_VOL_TABLE_1[9] = { 0x74, 0x94, 0x74, 0x94, 0x74, 0x94, 0x74, 0x94, 0x74 }; static unsigned char LOUDNESS_TABLE[] ={ 0, 1, 2, 3, 4, 5, 6, 7 }; //2 8 step static unsigned char gCurSPDIFInput = 0; //static unsigned char gCurSPDIFOut = 0; /********************************************************************************** * Internal Function Prototype *********************************************************************************/ VOID Delay_msec(UINT msec); unsigned char PIO_SetLow( VOID ); unsigned char PIO_SetHigh( VOID ); unsigned char I2cWriteSTV82x8(unsigned char ucSubAddress, unsigned char ucData); unsigned char I2cReadSTV82x8(unsigned char ucSubAddress, unsigned char * pucData ); unsigned char STV82x8_DataMaskWrite( unsigned char ADDRESS, unsigned char DATA, unsigned char MASK_DATA ); /********************************************************************************** * Function: * VOID Delay_msec(UINT msec) * Description: * Delay milliseconds * Input: * UINT: in unit of msec. * Return: * None *********************************************************************************/ VOID Delay_msec(UINT uiMillSec) { #if 0 UINT i; struct timeval tt; for(i=0; i< uiMillSec; i++) { tt.tv_sec = 0; tt.tv_usec = 1000; //maybe interrupted, so the real delay time is smaller than desired one select(0, 0, 0, 0, &tt); } #else usleep( uiMillSec * 1000 ); #endif } /********************************************************************************** * Function: * unsigned char STV82x8_OpenDevice(unsigned char i2c_num,unsigned char ucSubAddr) * Description: * This function would open the I2C file descriptor for its audio device * Input: * unsigned char i2c_num: the first I2C(0) or second I2C(1) * unsigned char ucSubAddr: the I2C address * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully open the device *********************************************************************************/ unsigned char STV82x8_OpenDevice(unsigned char i2c_num,unsigned char ucSubAddr) { INT nRet; unsigned char ucResult = STV82X8_NO_ERROR; gSlaveAddr = ucSubAddr; gI2C_num = i2c_num; // check for I2C file descriptor for audio device if(gSTV82x8_i2cfd) return ucResult; #if 0 if((gSTV82x8_i2cfd = open("/tmp/i2c-1", O_RDWR))<0) #else if((gSTV82x8_i2cfd = open("/dev/i2c-0", O_RDWR))<0) #endif { gSTV82x8_i2cfd = 0; TRACE0(("Open I2c device failed\n")); return STV82X8_I2C_ERROR; } printf("OPEN SUCCESS\n"); #if 0 // can we communicate with the device ? if((nRet = ioctl(gSTV82x8_i2cfd, I2C_SLAVE, ucSubAddr>>1)) < 0) { close(gSTV82x8_i2cfd); gSTV82x8_i2cfd = 0; TRACE0(("Open I2C IOCTL failed\n")); return STV82X8_I2C_ERROR; } #else nRet=0; #endif return ucResult; } /********************************************************************************** * Function: * unsigned char STV82x8_CloseDevice(VOID) * Description: * This function would close the I2C file descriptor for its audio device * Input: * None * Return: * STV82X8_NO_ERROR = successfully close the device *********************************************************************************/ unsigned char STV82x8_CloseDevice(VOID) { if(gSTV82x8_i2cfd) { close(gSTV82x8_i2cfd); gSTV82x8_i2cfd = 0; } return STV82X8_NO_ERROR; } /****************************************************************************** * Function: * unsigned char STV82x8_Initialize(unsigned char ucSlaveAddr) * Description: * Main S/W has to initialize STV82x8 as bellow * 1) It must be executed Hardware reset the device with [pin43]. * 2) It must send patch data[ttucPatchVa] to STV82x8 through i2c: * Patch datas are written by the {address, value} pairs. * Be carefull !!! Boot time. * It takes about 4 ~ 5 Seconds to update Patch's data with 50 Khz * for I2C's clock speed. * 3) Initialize Dsp . * 4) Initialize Register. * 5) Set initialize. * Input: * unsigned char i2c_num: first i2c (0) or second i2c (1) * unsigned char ucSlaveAddr: device slave address * Return: * STV82X8_NO_ERROR = Initalisation for STV82x8 is succeed . * STV82X8_I2C_ERROR = Initalisation for STV82x8 is failed . *******************************************************************************/ unsigned char STV82x8_Initialize(unsigned char i2c_num,unsigned char ucSlaveAddr) { unsigned char ucResult = STV82X8_NO_ERROR; printf("STV82x8_Initialize 11111111==\n"); if(STV82x8_OpenDevice(i2c_num,ucSlaveAddr)) return STV82X8_I2C_ERROR; printf("STV82x8_Initialize 22222222==\n"); ucResult = STV82x8_SwReset(); printf("STV82x8_Initialize 33333333==\n"); if (ucResult == STV82X8_NO_ERROR) { if(STV82x8_UpdatePatchData()) { TRACE0(("UpdatePatchData Failed\n")); return STV82X8_I2C_ERROR; } printf("STV82x8_Initialize 33333333==\n"); if(STV82x8_InitDSP()) { TRACE0(("InitDSP Failed\n")); return STV82X8_I2C_ERROR; } printf("STV82x8_Initialize 33333333==\n"); if(STV82x8_InitRegister()) { TRACE0(("InitRegister Failed\n")); return STV82X8_I2C_ERROR; } printf("STV82x8_Initialize 33333333==\n"); if(STV82x8_SetI2SInOut( STV82X8_I2S_OUTPUT )) //Reg 01 { TRACE0(("SetI2SInOut Failed\n")); return STV82X8_I2C_ERROR; } printf("STV82x8_Initialize 33333333==\n"); if(STV82x8_SetI2SOutputSignal( STV82X8_I2S_OUTPUT_LR )) //Reg 56 { TRACE0(("SetI2SOutputSignal Failed\n")); return STV82X8_I2C_ERROR; } printf("STV82x8_Initialize 33333333==\n"); // do SAP/Stereo/Mono check if(STV82x8_All_SoundSystem_Check()) { TRACE0(("STV82x8_All_SoundSystem_Check\n")); return STV82X8_I2C_ERROR; } // STV82x8_SetInOutput_ScartConfig(STV82X8_INPUT_AV1); // STV82x8_SetOutput_RFConfig(); } else { TRACE0(("SW Reset Failed\n")); } printf("STV82x8_Initialize end==\n"); return ucResult; } /****************************************************************************** * Function: * unsigned char STV82x8_HwReset(VOID) * Description: * This function executes hardware reset the STV82x8's device with pin43. * H/W reset is directly controled by PIO and PIO's pin is connected * Main IC's PIO with pin43 of STV82x8. * ________________ _______________ * | | * |_______________| * * |<-------------->| * * 50 ms * Input: None * Output: None * Return: * STV82X8_NO_ERROR = H/W Reset is succeed . * STV82X8_I2C_ERROR = H/W Reset is failed *******************************************************************************/ unsigned char STV82x8_HwReset(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; ucResult = PIO_SetLow(); // Delay_msec( 50 ); ucResult |= PIO_SetHigh(); return ( ucResult ); } /****************************************************************************** * Function: * unsigned char STV82x8_SwReset(VOID) * Description: * executes software reset the device with register 0x01 of STV82x8. * If you will be setting field SOFT_RST to 1, STV82x8 will be resetted * all hardware registers except for IIC data. * SOFT_RST Set[1] SOFT_RST Set[0] * _______________|_______________ |_______________ * |<-------------->| * 20 ms * * Input: None. * Output: None * Return: * STV82X8_NO_ERROR = S/W Reset is succeed. * STV82X8_I2C_ERROR = S/W Reset is failed. ********************************************************************************/ unsigned char STV82x8_SwReset(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; ucResult = STV82x8_DataMaskWrite( SW_RESET, STV82X8_SOFT_RESET, STV82X8_SOFT_RESETALL_MASK ); Delay_msec(20); // usleep( 500 ); //35ms ucResult |= STV82x8_DataMaskWrite( SW_RESET, (STV82X8_SOFT_RESET&0xFE), STV82X8_SOFT_RESETALL_MASK ); return(ucResult); } /********************************************************************************** * Function: * unsigned char STV82x8_UpdatePatchData(VOID) * Description: * This function update new patch data through I2C's communication. * Input: * None * Output: * None * Return: * STV82X8_NO_ERROR = New patch data was successfully loaded. * STV82X8_I2C_ERROR = New patch data wasn't successfully loaded. **********************************************************************************/ unsigned char STV82x8_UpdatePatchData(VOID) { UINT uiPatchSize, uiCount = 0; unsigned char ucResult = STV82X8_NO_ERROR; for( uiPatchSize = 0; uiPatchSize < ( sizeof(ttucPatchV18h) / 2 ); uiPatchSize++ ) { I2cWriteSTV82x8( ttucPatchV18h[uiCount][0], ttucPatchV18h[uiCount][1] ); uiCount += 1; //printf("uiCount:%d, uiCount%16:%d\n",uiCount, uiCount%16); /* if (uiCount%8==0) usleep(0); */ } ucResult = STV82x8_VerifiedPatchData(); return(ucResult); } /********************************************************************************** * Function: * unsigned char STV82x8_VerifiedPatchData(VOID) * Description: * When ST-Set is updated by new patch data through I2C, FFh register * will be atomatically updated by new patch version. * If FFh register isn't same as the patch version, patch data wasn't loaded well. * Input: * Output: * None * Return: * STV82X8_NO_ERROR = Verified patch data was succeed. * STV82X8_I2C_ERROR = Verified patch data was failed. *********************************************************************************/ unsigned char STV82x8_VerifiedPatchData(VOID) { unsigned char ucRegVal, ucResult = STV82X8_NO_ERROR; ucResult = I2cReadSTV82x8( PATCH_VERSION, &ucRegVal ); if( ucRegVal != STV82X8_PATCH_VERSION ) { ucResult = STV82X8_I2C_ERROR; } return(ucResult); } /********************************************************************************** * Function: * unsigned char STV82x8_InitDSP(VOID) * Description: * TV-Set has to set field HW_RESET[0x80] to 1 in order to initialize DSP parts * After that, TV-Set has to wait for INIT_MEM[0x84] field to be changed from 0 * to 1. It means the DSP init is good. And then DSP will be started. * Input: * Output: * None * Return: * STV82X8_NO_ERROR = DSP Init is succeed. * STV82X8_I2C_ERROR = DSP Init is failed. *********************************************************************************/ unsigned char STV82x8_InitDSP(VOID) { unsigned char ucRegValue = 0, ucCount = 0, ucResult = STV82X8_NO_ERROR; ucResult = STV82x8_DataMaskWrite( HOST_CMD, STV82X8_HWINITDSP_VALUE, STV82X8_HWINITDSP_MASK ); if( ucResult ) { return ( ucResult ); } do{ Delay_msec(10 ); //10ms I2cReadSTV82x8( DSP_STATUS, &ucRegValue ); ucRegValue &= STV82X8_INIT_MEM_MASK; }while( ( ++ucCount < 30 ) && ( !ucRegValue ) ); STV82x8_SetValueForSPDIF(); ucResult = STV82x8_DataMaskWrite ( I2S_CONFIG, 0x07, STV82X8_I2S_CONFIG_MASK ); if( ucRegValue ) { ucResult = STV82x8_DataMaskWrite ( DSP_RUN, STV82X8_INITDSPHOSTRUN_VALUE, STV82X8_INITDSPHOSTRUN_MASK ); } else { ucResult = STV82X8_I2C_ERROR; } return(ucResult); } /********************************************************************************** * Function: * unsigned char STV82x8_InitRegister(VOID) * Description: * If necessary, TV-Set will be set special register to special values into here. * Scart, Loudspeaker, Headphone and Subwoofer will be mute first. * And then STV82x8 will be set volume control register to values of special * volume tables. * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_INVALID_PARAM = Invalid params. * STV82X8_NO_ERROR = successfully set left volume. ***********************************************************************************/ unsigned char STV82x8_InitRegister(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; //set SPDIF out mute ucResult |= STV82x8_DataMaskWrite( AUDIO_MATRIX3_INPUT, 0x0, STV82X8_MATRIX3_INPUT_MASK ); ucResult |= STV82x8_SetDigitalMute(STV82x8_MUTE_ALL_OUTPUT, STV82x8_ALL_OUTPUT_MASK); ucResult |= STV82x8_SetDACMute(); ucResult |= STV82x8_SetDefaultValueFromSTDConfig(); ucResult |= STV82x8_SetLeftVolume( (USHORT)( VOLUME_0DB_DEFAULT_VALUE ) ); ucResult |= STV82x8_SetCenterVolume( (USHORT)( VOLUME_0DB_DEFAULT_VALUE ) ); ucResult |= STV82x8_SetMasterVolume( (USHORT)( VOLUME_TABLE[0] ) ); ucResult |= STV82x8_SetVolumeMode( DIFFERENTIAL_MODE ); ucResult |= STV82x8_SetLSBalance( (unsigned char)( STV82X8_LS_BALANCE_CENTER ) ); ucResult |= STV82x8_WakeUpADC(); ucResult |= STV82x8_WakeUpIRQ0(); ucResult |= STV82x8_SetFMTimeOut( FM_TIME_64MS ); // adjust the prescale for each input ucResult |= STV82x8_SetMonoStereoDefaultPrescale(); ucResult |= STV82x8_SetScartDefaultPrescale(); ucResult |= STV82x8_SAPDefaultPrescale(); ucResult |= STV82x8_I2SDefaultPrescale(PRESCALE_I2S_0, I2S_PRESCALING_DEFAULTVALU); ucResult |= STV82x8_I2SDefaultPrescale(PRESCALE_I2S_1, I2S_PRESCALING_DEFAULTVALU); ucResult |= STV82x8_I2SDefaultPrescale(PRESCALE_I2S_2, I2S_PRESCALING_DEFAULTVALU); ucResult |= STV82x8_SetEqualizerValue( EQUALIZER_100HZ, 2 ); ucResult |= STV82x8_SetEqualizerValue( EQUALIZER_330HZ, 3 ); ucResult |= STV82x8_SetEqualizerValue( EQUALIZER_1KHZ, 4 ); ucResult |= STV82x8_SetEqualizerValue( EQUALIZER_3P3KHZ, 5 ); ucResult |= STV82x8_SetEqualizerValue( EQUALIZER_10KHZ, 6 ); // headphone related setting ucResult |= STV82x8_SetHPConfiguration(STV82x8_HP_FORCE_ON, STV82x8_HP_LS_UNMUTE, STV82x8_HP_DET_ACTIVE_ON); ucResult |= STV82x8_SetHPLeftVolume(STV82X8_HEADPHONE_VOLUME_DEFAULT); ucResult |= STV82x8_SetHPBalance( (unsigned char)( STV82X8_LS_BALANCE_CENTER ) ); ucResult |= STV82x8_AutoVolumeHPCtrl(STV82x8_SVC_ON); ucResult |= STV82x8_SetPseudoEffect( STV82X8_PSEUDO_OFF ); ucResult |= STV82x8_SetSRSWOW_Effect( STV82X8_ALL_SRS_OFF ); // ucResult |= STV82x8_ControlTurboSound( STV82X8_TURBO_SOUND_OFF, 7 ); Josie 8/23 ucResult |= STV82x8_ControlTurboSound( STV82X8_TURBO_SOUND_ON, 2 ); ucResult |= STV82x8_AutoVolumeCtrl( STV82x8_SVC_ON ); ucResult |= STV82x8_SetAutoMuteOnOff(ON); // ucResult |= STV82x8_SetLoudSpkHeadPhoneGain(LS_BASS_GAIN, BASS_TREBLE_GAIN_TABLE[0]); ucResult |=STV82x8_Enble_Equalizer(OFF, LS_BASS_GAIN, BASS_TREBLE_GAIN_TABLE[0] ); ucResult |= STV82x8_SetLoudSpkHeadPhoneGain(LS_TREBLE_GAIN, BASS_TREBLE_GAIN_TABLE[0]); ucResult |= STV82x8_SetStereoTimeOut(STEREO_TIME_200MS); // set differential mode with complimentary blance control is used //STV82x8_SetScartVolumeMode(DIFFERENTIAL_MODE); //STV82x8_ScartOutBalance( (unsigned char)( STV82X8_LS_BALANCE_CENTER )); ucResult |= STV82x8_SetDACUnMute(); ucResult |= STV82x8_SetDigitalUnMute(STV82x8_UNMUTE_ALL_OUTPUT, STV82x8_ALL_OUTPUT_MASK); ucResult |= STV82x8_SAPConfig(0); return ( ucResult ); } /*********************************************************************************** * Function: * unsigned char STV82x8_SetDigitalMute(unsigned char ucMute, unsigned char ucMask) * Description: * This function executes that STV82x8 to process software sound mute. * Input: * unsigned char ucMute: 00000001b = LS mute (STV82X8_DIGITAL_LS_MUTE) * 00000010b = Center mute * 00000100b = Subwoofer mute * 00001000b = Surrond mute * 00010000b = Scart1 mute * 00100000b = Scart2 mute * 01000000b = SPDIF mute (STV82X8_DIGITAL_SPDIF_MUTE) * 10000000b = Headphone mute (STV82x8_DIGITAL_HP_MUTE) * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set Digital mute. **********************************************************************************/ unsigned char STV82x8_SetDigitalMute(unsigned char ucMute, unsigned char ucMask) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION;; #endif ucResult = STV82x8_DataMaskWrite(MUTE_DIGITAL, ucMute, ucMask); return(ucResult); } /*********************************************************************************** * Function: * unsigned char STV82x8_SetDigitalUnMute(unsigned char ucUnMute, unsigned char ucMask) * Description: * This function executes that STV82x8 to process software sound unmute * except for Scart input. * Input: * unsigned char ucUnMute: 00000001b = LS mute * 00000010b = Center mute * 00000100b = Subwoofer mute * 00001000b = Surrond mute * 00010000b = Scart1 mute * 00100000b = Scart2 mute * 01000000b = SPDIF mute * 10000000b = Headphone mute * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set Digital unmute. ***********************************************************************************/ unsigned char STV82x8_SetDigitalUnMute(unsigned char ucUnMute, unsigned char ucMask) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = STV82x8_DataMaskWrite( MUTE_DIGITAL, ucUnMute, ucMask); return(ucResult); } /************************************************************************************ * Function: * unsigned char STV82x8_SetDACMute(VOID) * Description: * This function executes that STV82x8 to process DAC sound mute. * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set ADC mute. ************************************************************************************/ unsigned char STV82x8_SetDACMute(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = STV82x8_DataMaskWrite( DAC_CTRL, STV82X8_DAC_MUTE_VALUE, STV82X8_DAC_MUTE_MASK ); return(ucResult); } /************************************************************************************ * Function: * unsigned char STV82x8_SetDACUnMute(VOID) * Description: * This function executes that STV82x8 to process DAC sound unmute. * Input: * Output: * None. * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set ADC unmute. ************************************************************************************/ unsigned char STV82x8_SetDACUnMute(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = STV82x8_DataMaskWrite( DAC_CTRL, STV82X8_DAC_UNMUTE_VALUE, STV82X8_DAC_MUTE_MASK ); return(ucResult); } /************************************************************************************ * Function: * unsigned char STV82x8_SetScart1DigitalMute(VOID) * Description: * This function executes that STV82x8 to process software sound mute for Scart input. * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set Scart digital mute. ************************************************************************************/ unsigned char STV82x8_SetScart1DigitalMute(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = STV82x8_DataMaskWrite( MUTE_DIGITAL, STV82X8_DIGITAL_SCART1_MUTE, STV82X8_DIGITALMUTE_SCART1_MASK ); return(ucResult); } /************************************************************************************ * Function: * unsigned char STV82x8_SetScart1DigitalUnMute(VOID) * Description: * This function executes that STV82x8 to process software sound unmute for Scart input. * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set Scart digital unmute. ************************************************************************************/ unsigned char STV82x8_SetScart1DigitalUnMute(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = STV82x8_DataMaskWrite( MUTE_DIGITAL, STV82X8_DIGITAL_SCART1_UNMUTE, STV82X8_DIGITALMUTE_SCART1_MASK ); return(ucResult); } /************************************************************************************* * Function: * unsigned char STV82x8_SetSPDIFDigitalMute(VOID) * Description: * This function executes that STV82x8 to process software sound mute for Scart input. * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set Scart digital mute. ************************************************************************************/ unsigned char STV82x8_SetSPDIFDigitalMute(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = STV82x8_DataMaskWrite( MUTE_DIGITAL, STV82X8_DIGITAL_SPDIF_MUTE, STV82X8_DIGITALMUTE_SPDIF_MASK ); return(ucResult); } /************************************************************************************* * Function: * unsigned char STV82x8_SetSPDIFDigitalUnMute(VOID) * Description: * This function executes that STV82x8 to process software sound unmute for Scart input. * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set Scart digital unmute. *************************************************************************************/ unsigned char STV82x8_SetSPDIFDigitalUnMute(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = STV82x8_DataMaskWrite( MUTE_DIGITAL, STV82X8_DIGITAL_SPDIF_UNMUTE, STV82X8_DIGITALMUTE_SPDIF_MASK ); return(ucResult); } /************************************************************************************* * Function: * unsigned char STV82x8_SetSPDIFDigitalMute(VOID) * Description: * This function executes that STV82x8 to process software sound mute for Scart input. * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set Scart digital mute. ************************************************************************************/ unsigned char STV82x8_SetSPDIFMute(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif //read current SPDIF input I2cReadSTV82x8(AUDIO_MATRIX3_INPUT, &gCurSPDIFInput); ucResult |= STV82x8_DataMaskWrite( AUDIO_MATRIX3_INPUT, 0x0, STV82X8_MATRIX3_INPUT_MASK ); return(ucResult); } /************************************************************************************* * Function: * unsigned char STV82x8_SetSPDIFDigitalUnMute(VOID) * Description: * This function executes that STV82x8 to process software sound unmute for Scart input. * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set Scart digital unmute. *************************************************************************************/ unsigned char STV82x8_SetSPDIFUnMute(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult |= STV82x8_DataMaskWrite( AUDIO_MATRIX3_INPUT, gCurSPDIFInput, STV82X8_MATRIX3_INPUT_MASK ); return(ucResult); } /************************************************************************************* * Function: * unsigned char STV82x8_SetScartDACMute(VOID) * Description: * This function executes that STV82x8 to process software sound mute for Scart input. * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set Scart digital unmute. ************************************************************************************/ unsigned char STV82x8_SetScartDACMute(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = STV82x8_DataMaskWrite(DAC_CTRL, STV82X8_SC_DAC_MUTE_VALUE, STV82X8_SC_DAC_MUTE_MASK ); return(ucResult); } /********************************************************************************** * Function: * unsigned char STV82x8_SetScartDACUnMute(VOID) * Description: * This function executes that STV82x8 to process software sound unmute * for Scart input. * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set Scart digital unmute. **********************************************************************************/ unsigned char STV82x8_SetScartDACUnMute(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = STV82x8_DataMaskWrite(DAC_CTRL, STV82X8_SC_DAC_UNMUTE_VALUE, STV82X8_SC_DAC_MUTE_MASK ); return (ucResult); } /*********************************************************************************** * Function: * unsigned char STV82x8_SetVolumeMode(unsigned char ucVolumeMode) * Description: * This function set volume mode between Independential and Differential mode. * Input: * INDEPENDANT_MODE = Volume mode is independant. * DIFFERENTIAL_MODE = Volume mode is differential. * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_INVALID_PARAM = Invalid params. * STV82X8_NO_ERROR = successfully set left volume. **********************************************************************************/ unsigned char STV82x8_SetVolumeMode(unsigned char ucVolumeMode) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if( ucVolumeMode == INDEPENDANT_MODE ) { ucResult = STV82x8_DataMaskWrite( VOLUME_MODES, STV82X8_VOLUMEMODE_INDEPENDANT, STV82X8_VOLUMEMODE_MASK ); if( ucResult ) ucResult = STV82X8_I2C_ERROR; } else if( ucVolumeMode == DIFFERENTIAL_MODE ) { ucResult = STV82x8_DataMaskWrite( VOLUME_MODES, STV82X8_VOLUMEMODE_DIFFERENTIAL, STV82X8_VOLUMEMODE_MASK ); if( ucResult ) ucResult = STV82X8_I2C_ERROR; } else { ucResult = STV82X8_INVALID_PARAM; } return ( ucResult ); } /************************************************************************************* * Function: * unsigned char STV82x8_SetScartVolumeMode(unsigned char ucVolumeMode) * Description: * This function set volume mode for scart between Independential and Differential mode. * Input: * INDEPENDANT_MODE = Volume mode is independant. * DIFFERENTIAL_MODE = Volume mode is differential. * Output: * None * Return: * STV82x8_I2C_ERROR = I2C's communication is failed. * STV82x8_INVALID_PARAM = Invalid params. * STV82x8_NO_ERROR = No error. *************************************************************************************/ unsigned char STV82x8_SetScartVolumeMode(unsigned char ucVolumeMode) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if( ucVolumeMode == INDEPENDANT_MODE ) { ucResult = STV82x8_DataMaskWrite(VOLUME_MODES, STV82X8_SCART_VOLUMEMODE_INDEPENDANT, STV82X8_SCART_VOLUMEMODE_MASK ); } else if( ucVolumeMode == DIFFERENTIAL_MODE ) { ucResult = STV82x8_DataMaskWrite(VOLUME_MODES, STV82X8_SCART_VOLUMEMODE_DIFFERENTIAL, STV82X8_SCART_VOLUMEMODE_MASK ); } else { ucResult = STV82X8_INVALID_PARAM; } return ( ucResult ); } /**************************************************************************************** * Function: * unsigned char STV82x8_SetLeftVolume(USHORT usVolume ) * Description: * This function set left volume to special value. * Input: * Left volume = 10-bit volume value. * X X X X X X X X X X X X X X X X * ----------------- --- * MSB LSB * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set left volume. * *************************************************************************************/ unsigned char STV82x8_SetLeftVolume(USHORT usVolume ) { unsigned char ucVolumeMSB, ucVolumeLSB; unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucVolumeMSB = (unsigned char)(( usVolume >> NORMAL_VOLUME_SHIFT ) & VOLUME_MSB_MASK ); ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK ); ucResult = I2cWriteSTV82x8( LS_L_VOLUME_MSB, ucVolumeMSB ); ucResult |= I2cWriteSTV82x8( LS_L_VOLUME_LSB, ucVolumeLSB ); return ( ucResult ); } /************************************************************************************ * Function: * unsigned char STV82x8_SetRightVolume(USHORT usVolume ) * Description: * This function set right volume to special value. * Input: * Rightt volume = 10-bit volume value. * X X X X X X X X X X X X X X X X * ----------------- --- * MSB LSB * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set left volume. ************************************************************************************/ unsigned char STV82x8_SetRightVolume(USHORT usVolume ) { unsigned char ucVolumeMSB, ucVolumeLSB; unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucVolumeMSB = (unsigned char)(( usVolume >> NORMAL_VOLUME_SHIFT ) & VOLUME_MSB_MASK ); ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK ); ucResult = STV82x8_SetVolumeMode( INDEPENDANT_MODE ); ucResult = I2cWriteSTV82x8( LS_R_VOLUME_MSB, ucVolumeMSB ); ucResult |= I2cWriteSTV82x8( LS_R_VOLUME_LSB, ucVolumeLSB ); return ( ucResult ); } /************************************************************************************ * Function: * unsigned char STV82x8_SetCenterVolume(USHORT usVolume) * Description: * This function set center volume to special value. * Input: * Center volume = 10-bit volume value. * X X X X X X X X X X X X X X X X * ----------------- --- * MSB LSB * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set left volume. * ***********************************************************************************/ unsigned char STV82x8_SetCenterVolume(USHORT usVolume) { unsigned char ucVolumeMSB, ucVolumeLSB; unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucVolumeMSB = (unsigned char)(( usVolume >> NORMAL_VOLUME_SHIFT ) & VOLUME_MSB_MASK ); ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK ); ucResult = I2cWriteSTV82x8( LS_C_VOLUME_MSB, ucVolumeMSB ); ucResult |= I2cWriteSTV82x8( LS_C_VOLUME_LSB, ucVolumeLSB ); return ( ucResult ); } /************************************************************************************* * Function: * unsigned char STV82x8_SetSurroundLeftVolume(USHORT usVolume) * Description: * This function set surround left volume to special value. * Input: * Left volume = 10-bit volume value. * X X X X X X X X X X X X X X X X * ----------------- --- * MSB LSB * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set left volume. *************************************************************************************/ unsigned char STV82x8_SetSurroundLeftVolume(USHORT usVolume) { unsigned char ucVolumeMSB, ucVolumeLSB; unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucVolumeMSB = (unsigned char)(( usVolume >> NORMAL_VOLUME_SHIFT ) & VOLUME_MSB_MASK ); ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK ); ucResult = I2cWriteSTV82x8( LS_SL_VOLUME_MSB, ucVolumeMSB ); ucResult |= I2cWriteSTV82x8( LS_SL_VOLUME_LSB, ucVolumeLSB ); return ( ucResult ); } /************************************************************************************* * Function: * unsigned char STV82x8_SetSurroundRightVolume(USHORT usVolume) * Description: * This function set surround right volume to special value. * Input: * Right volume = 10-bit volume value. * X X X X X X X X X X X X X X X X * ----------------- --- * MSB LSB * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set left volume. ***********************************************************************************/ unsigned char STV82x8_SetSurroundRightVolume(USHORT usVolume) { unsigned char ucVolumeMSB, ucVolumeLSB; unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucVolumeMSB = (unsigned char)(( usVolume >> NORMAL_VOLUME_SHIFT ) & VOLUME_MSB_MASK ); ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK ); ucResult = STV82x8_SetVolumeMode( INDEPENDANT_MODE ); ucResult = I2cWriteSTV82x8( LS_SR_VOLUME_MSB, ucVolumeMSB ); ucResult |= I2cWriteSTV82x8( LS_SR_VOLUME_LSB, ucVolumeLSB ); return ( ucResult ); } /*********************************************************************************** * Function: * unsigned char STV82x8_SetHPLeftVolume(USHORT usVolume) * Description: * This function set HP left volume to special value. * Input: * usVolume = 10-bit Left HP volume value. * X X X X X X X X X X X X X X X X * ----------------- --- * MSB LSB * Output: * None * Return: * STV82x8_I2C_ERROR = I2C's communication is failed. * STV82x8_NO_ERROR = No error. ***********************************************************************************/ unsigned char STV82x8_SetHPLeftVolume(USHORT usVolume) { unsigned char ucVolumeMSB, ucVolumeLSB; unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucVolumeMSB = (unsigned char)(( usVolume >> NORMAL_VOLUME_SHIFT ) & VOLUME_MSB_MASK ); ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK ); ucResult = I2cWriteSTV82x8( HP_L_VOL_MSB, (unsigned char)( ucVolumeMSB ) ); ucResult |= I2cWriteSTV82x8( HP_L_VOL_LSB, (unsigned char)( ucVolumeLSB ) ); return ( ucResult ); } /************************************************************************************ * Function: * unsigned char STV82x8_SetHPRightVolume(USHORT usVolume) * Description: * This function set HP right volume to special value. * Input: * usVolume = 10-bit Right HP volume value. * X X X X X X X X X X X X X X X X * ----------------- --- * MSB LSB * Output: * None * Return * STV82x8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = No error. ************************************************************************************/ unsigned char STV82x8_SetHPRightVolume(USHORT usVolume) { unsigned char ucVolumeMSB, ucVolumeLSB; unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucVolumeMSB = (unsigned char)(( usVolume >> NORMAL_VOLUME_SHIFT ) & VOLUME_MSB_MASK ); ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK ); ucResult = STV82x8_SetVolumeMode( INDEPENDANT_MODE ); ucResult |= I2cWriteSTV82x8( HP_R_VOL_MSB, (unsigned char)( ucVolumeMSB ) ); ucResult |= I2cWriteSTV82x8( HP_R_VOL_LSB, (unsigned char)( ucVolumeLSB ) ); return ( ucResult ); } /************************************************************************************ * Function: * unsigned char STV82x8_SetMasterVolume(USHORT usVolume) * Description: * This function set master volume to special value. * Input: * Master volume = 16-bit volume value from table * X X X X X X X X X X X X X X X X * ----------------- --- * MSB LSB * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set left volume. ************************************************************************************/ unsigned char STV82x8_SetMasterVolume(USHORT usVolume) { unsigned char ucVolumeMSB, ucVolumeLSB; unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucVolumeMSB = (unsigned char)(( usVolume >> MASTER_VOLUME_SHIFT ) & VOLUME_MSB_MASK ); ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK ); ucResult = I2cWriteSTV82x8( LS_MASTER_VOLUME_MSB, ucVolumeMSB ); ucResult |= I2cWriteSTV82x8( LS_MASTER_VOLUME_LSB, ucVolumeLSB ); return ( ucResult ); } /*********************************************************************************** * Function: * unsigned char STV82x8_SetLeftScartVolume(USHORT usVolume) * Description: * This function set left scart volume to special value. * Input: * Left volume = 10-bit volume value. * X X X X X X X X X X X X X X X X * ----------------- --- * MSB LSB * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set left volume. ************************************************************************************/ unsigned char STV82x8_SetLeftScartVolume(USHORT usVolume) { unsigned char ucVolumeMSB, ucVolumeLSB; unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucVolumeMSB = (unsigned char)(( usVolume >> NORMAL_VOLUME_SHIFT ) & VOLUME_MSB_MASK ); ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK ); ucResult = I2cWriteSTV82x8( AUX_L_VOL_MSB, ucVolumeMSB ); ucResult |= I2cWriteSTV82x8( AUX_L_VOL_LSB, ucVolumeLSB ); return ( ucResult ); } /************************************************************************************* * Function: * unsigned char STV82x8_SetRightScartVolume(USHORT usVolume) * Description: * This function set right scart volume to special value. * Input: * Right volume = 10-bit volume value. * X X X X X X X X X X X X X X X X * ----------------- --- * MSB LSB * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set left volume. ************************************************************************************/ unsigned char STV82x8_SetRightScartVolume(USHORT usVolume) { unsigned char ucVolumeMSB, ucVolumeLSB; unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucVolumeMSB = (unsigned char)(( usVolume >> NORMAL_VOLUME_SHIFT ) & VOLUME_MSB_MASK ); ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK ); ucResult = STV82x8_SetScartVolumeMode( INDEPENDANT_MODE ); ucResult |= I2cWriteSTV82x8( AUX_R_VOL_MSB, ucVolumeMSB ); ucResult |= I2cWriteSTV82x8( AUX_R_VOL_LSB, ucVolumeLSB ); return ( ucResult ); } /*********************************************************************************** * Function: * unsigned char STV82x8_SetLSSubWooferVolume(USHORT usVolume) * Description: * This function set LS subwoofer volume to special value. * Input: * Left volume = 10-bit volume value. * X X X X X X X X X X X X X X X X * ----------------- --- * MSB LSB * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set left volume. ************************************************************************************/ unsigned char STV82x8_SetLSSubWooferVolume(USHORT usVolume) { unsigned char ucVolumeMSB, ucVolumeLSB; unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucVolumeMSB = (unsigned char)(( usVolume >> NORMAL_VOLUME_SHIFT ) & VOLUME_MSB_MASK ); ucVolumeLSB = (unsigned char)( usVolume & VOLUME_LSB_MASK ); ucResult = I2cWriteSTV82x8( LS_SUB_VOLUME_MSB, ucVolumeMSB ); ucResult |= I2cWriteSTV82x8( LS_SUB_VOLUME_LSB, ucVolumeLSB ); return ( ucResult ); } /************************************************************************************ * Function: * unsigned char STV82x8_ScartOutBalance(unsigned char ucBalance) * Description: * This function set scart out balance to special value. * Input: * scart out balance * X X X X X X X X X X X X X X X X * ----------------- --- * MSB LSB * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set left volume. ************************************************************************************/ unsigned char STV82x8_ScartOutBalance(unsigned char ucBalance) { unsigned char ucBlanceMSB, ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucBlanceMSB = (unsigned char)( ucBalance & BALANCE_MSB_MASK ); ucResult = STV82x8_SetScartVolumeMode( DIFFERENTIAL_MODE ); ucResult |= I2cWriteSTV82x8( AUX_R_VOL_MSB, ucBlanceMSB ); ucResult |= I2cWriteSTV82x8( AUX_R_VOL_LSB, DEFAULT_LSB_BALANCE_VALUE ); return ( ucResult ); } /************************************************************************************ * Function: * unsigned char STV82x8_SetLSBalance(unsigned char ucBalance) * Description: * This function is forcing STV82x8 to process balance of L / R speaker * except for Scart Output. * -------------------------------------------------------------------------------- * VOLUME_MODES LS_L_VOLUME_MSB & LSB LS_R_VOLUME_MSB & LSB * independent Left volume Right volume * differential L/R volume Balance * -------------------------------------------------------------------------------- * Input: * unsigned char ucBalance: level * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_INVALID_PARAM = Invalid params. * STV82X8_NO_ERROR = successfully set LS Balance. ************************************************************************************/ unsigned char STV82x8_SetLSBalance(unsigned char ucBalance) { unsigned char ucBlanceMSB, ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucBlanceMSB = (unsigned char)( ucBalance & BALANCE_MSB_MASK ); ucResult = STV82x8_SetVolumeMode( DIFFERENTIAL_MODE ); ucResult |= I2cWriteSTV82x8( LS_R_VOLUME_MSB, ucBlanceMSB ); ucResult |= I2cWriteSTV82x8( LS_R_VOLUME_LSB, DEFAULT_LSB_BALANCE_VALUE ); return ( ucResult ); } /************************************************************************************** * Function: * unsigned char STV82x8_SetSurroundBalance(unsigned char ucBalance) * Description: * This function is forcing STV82x8 to process balance of surround. * ----------------------------------------------------------------------------- * VOLUME_MODES LS_L_VOLUME_MSB & LSB LS_R_VOLUME_MSB & LSB * * independent Left volume Right volume * * differential L/R volume Balance * ------------------------------------------------------------------------------ * Input: * ucBalance = Balance value.. * Output: * None * Return: * STV82x8_I2C_ERROR = I2C's communication is failed. * STV82x8_INVALID_PARAM = Invalid params. * STV82X8_NO_ERROR = No error. ************************************************************************************/ unsigned char STV82x8_SetSurroundBalance(unsigned char ucBalance) { unsigned char ucBlanceMSB, ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucBlanceMSB = (unsigned char)( ucBalance & BALANCE_MSB_MASK ); ucResult = STV82x8_SetVolumeMode( DIFFERENTIAL_MODE ); ucResult |= I2cWriteSTV82x8( LS_SR_VOLUME_MSB, ucBlanceMSB ); ucResult |= I2cWriteSTV82x8( LS_SR_VOLUME_LSB, DEFAULT_LSB_BALANCE_VALUE ); return ( ucResult ); } /************************************************************************************* * Function: * unsigned char STV82x8_SetHPBalance(unsigned char ucBalance) * Description: * This function is forcing STV82x8 to process balance of HP. * ----------------------------------------------------------------------------- * VOLUME_MODES LS_L_VOLUME_MSB & LSB LS_R_VOLUME_MSB & LSB * * independent Left volume Right volume * * differential L/R volume Balance * ------------------------------------------------------------------------------ * Input: * ucBalance = Balance value.. * Output: * None * Return: * STV82x8_I2C_ERROR = I2C's communication is failed. * STV82x8_INVALID_PARAM = Invalid params. * STV82X8_NO_ERROR = No error. *************************************************************************************/ unsigned char STV82x8_SetHPBalance(unsigned char ucBalance) { unsigned char ucBlanceMSB, ucResult = STV82X8_NO_ERROR ; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucBlanceMSB = (unsigned char)( ucBalance & BALANCE_MSB_MASK ); ucResult = STV82x8_SetVolumeMode( DIFFERENTIAL_MODE ); ucResult |= I2cWriteSTV82x8( HP_R_VOL_MSB, ucBlanceMSB ); ucResult |= I2cWriteSTV82x8( HP_R_VOL_LSB, DEFAULT_LSB_BALANCE_VALUE ); return ( ucResult ); } /************************************************************************************* * Function: * unsigned char STV82x8_WakeUpADC(VOID) * Description: * This function wakes up of the ADC. * Input: * None * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set ADC Value. ************************************************************************************/ unsigned char STV82x8_WakeUpADC(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = STV82x8_DataMaskWrite( ADC_CTRL, STV82X8_ADC_WAKEUP_VALUE, STV82X8_ADC_WAKEUP_MASK ); return ( ucResult ); } /************************************************************************************** * Function: * unsigned char STV82x8_WakeUpIRQ0(VOID) * Description: * This function wakes up of the IRQ0 for Surge functioin. * Input: * None * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set IRQ 0. **************************************************************************************/ unsigned char STV82x8_WakeUpIRQ0(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = STV82x8_DataMaskWrite( IRQ_STAT, STV82X8_IRQ0_WAKEUP_VALUE, STV82X8_IRQ0_WAKEUP_MASK ); return ( ucResult ); } /************************************************************************************ * Function: * unsigned char STV82x8_SetHPConfiguration(unsigned char ucHP_Force, unsigned char ucLS_Mute, unsigned char ucHP_Active) * Description: * This function sets head phone configuration register. * Input: * Output: * None * Return: * STV82x8_I2C_ERROR = I2C's communication is failed. * STV82x8_INVALID_PARAM = Invalid params * STV82X8_NO_ERROR = No error. ************************************************************************************/ unsigned char STV82x8_SetHPConfiguration(unsigned char ucHP_Force, unsigned char ucLS_Mute, unsigned char ucHP_Active) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if( (( ucHP_Force != STV82x8_HP_FORCE_ON ) && ( ucHP_Force != STV82x8_HP_FORCE_OFF )) || (( ucLS_Mute != STV82x8_HP_LS_MUTE ) && ( ucLS_Mute != STV82x8_HP_LS_UNMUTE )) || (( ucHP_Active != STV82x8_HP_DET_ACTIVE_ON ) && ( ucHP_Active != STV82x8_HP_DET_ACTIVE_OFF ))) { return ( STV82X8_INVALID_PARAM ); } ucResult = STV82x8_DataMaskWrite(HEADPHONE_CONFIG, (unsigned char)( ucHP_Force | ucLS_Mute | ucHP_Active ), STV82X8_HP_CONFIG_MASK ); return ( ucResult ); } /************************************************************************************** * Function: * unsigned char STV82x8_GetHPStatus(unsigned char * pucHPStaus) * Description: * This function returns status if HP is detected or not. * Input: * None * Output: * STV82x8_HP_DETECTED = HP signal is detected. * STV82x8_HP_NOT_DETECTED = HP signal isn't detected. * Return: * STV82x8_I2C_ERROR = I2C's communication is failed. * STV82x8_INVALID_PARAM = Invalid params * STV82X8_NO_ERROR = No error. **************************************************************************************/ unsigned char STV82x8_GetHPStatus(unsigned char * pucHPStaus ) { unsigned char ucRegValue, ucResult = STV82X8_NO_ERROR ; *pucHPStaus = STV82x8_HP_NOT_DETECTED; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if( pucHPStaus == NULL ) { return ( STV82X8_INVALID_PARAM ); } ucResult = I2cReadSTV82x8( HEADPHONE_CONFIG, &ucRegValue ); ucRegValue &= STV82X8_HP_DETECTED_MASK; if( ucRegValue ) *pucHPStaus = STV82x8_HP_DETECTED; else *pucHPStaus = STV82x8_HP_NOT_DETECTED; return ( ucResult ); } /*************************************************************************************** * Function: * unsigned char STV82x8_SetSubWoofer(unsigned char ucSubWoofer, unsigned char ucBassManage, unsigned char ucBassGainSW, * unsigned char ucSTLFEAdd, unsigned char ucDolbyPro, unsigned char ucBassConfNum) * Description * This function sets Bass management and mute register for Subwoofer. * Input: * STV82x8_SUBWOOFER_ON = Subwoofer output is active. * STV82x8_SUBWOOFER_OFF = Subwoofer output is disabled. * STV82x8_BASSMNGT_ON = BassManagement enabled. * STV82x8_BASSMNGT_OFF = BassManagement disables. * STV82x8_GAINSW_ON = Level adjustment ON. * STV82x8_GAINSW_OFF = Level adjustment OFF. * STV82x8_STLFEAdd_ON = Add LFE Signal. * STV82x8_STLFEAdd_OFF = No LFE Signal. * STV82x8_DolbyPro_ON = DOLBY PROLOGIC Configuration. * STV82x8_DolbyPro_OFF = Standard Configuration. * STV82x8_BASSCONFI_0 = Bass Management Configuration 0. * STV82x8_BASSCONFI_1 = Bass Management Configuration 1. * STV82x8_BASSCONFI_2 = Bass Management Configuration 2. * STV82x8_BASSCONFI_3 = Bass Management Configuration 3. * STV82x8_BASSCONFI_4 = Bass Management Configuration 4. * Output: * None * Return: * STV82x8_I2C_ERROR = I2C's communication is failed. * STV82x8_INVALID_PARAM = Invalid params * STV82X8_NO_ERROR = No error. *************************************************************************************/ unsigned char STV82x8_SetSubWoofer(unsigned char ucSubWoofer, unsigned char ucBassManage, unsigned char ucBassGainSW, unsigned char ucSTLFEAdd, unsigned char ucDolbyPro, unsigned char ucBassConfNum) { unsigned char ucRegValue, ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if(( ucSubWoofer != STV82x8_SUBWOOFER_ON ) && ( ucSubWoofer != STV82x8_SUBWOOFER_OFF )) { return ( STV82X8_INVALID_PARAM ); } if(( ucBassManage != STV82x8_BASSMNGT_ON ) && ( ucBassManage != STV82x8_BASSMNGT_OFF )) { return ( STV82X8_INVALID_PARAM ); } if(( ucBassGainSW != STV82x8_GAINSW_ON ) && ( ucBassGainSW != STV82x8_GAINSW_OFF )) { return ( STV82X8_INVALID_PARAM ); } if(( ucBassGainSW != STV82x8_STLFEAdd_ON ) && ( ucBassGainSW != STV82x8_STLFEAdd_OFF )) { return ( STV82X8_INVALID_PARAM ); } if(( ucBassGainSW != STV82x8_DolbyPro_ON ) && ( ucBassGainSW != STV82x8_DolbyPro_OFF )) { return ( STV82X8_INVALID_PARAM ); } if(( ucBassConfNum != STV82x8_BASSCONFI_0 ) && ( ucBassConfNum != STV82x8_BASSCONFI_1 ) && ( ucBassConfNum != STV82x8_BASSCONFI_2 ) && ( ucBassConfNum != STV82x8_BASSCONFI_3 ) && ( ucBassConfNum != STV82x8_BASSCONFI_4 ) && ( ucBassConfNum != STV82x8_BASSCONFI_5 ) && ( ucBassConfNum != STV82x8_BASSCONFI_6 )) { return ( STV82X8_INVALID_PARAM ); } if( ucSubWoofer == STV82x8_SUBWOOFER_ON ) { ucResult = STV82x8_DataMaskWrite(MUTE_DIGITAL, STV82x8_MUTEDIG_SUBWOOFER_UNMUTE, STV82x8_MUTEDIG_SUBWOOFER_MASK ); ucResult |= STV82x8_DataMaskWrite(DAC_CTRL, STV82x8_DAC_SUBWOOFER_UNMUTE, STV82x8_MUTEDIG_SUBWOOFER_MASK ); } else if( ucSubWoofer == STV82x8_SUBWOOFER_OFF ) { ucResult = STV82x8_DataMaskWrite(MUTE_DIGITAL, STV82x8_MUTEDIG_SUBWOOFER_MUTE, STV82x8_MUTEDIG_SUBWOOFER_MASK ); ucResult |= STV82x8_DataMaskWrite(DAC_CTRL, STV82x8_DAC_SUBWOOFER_MUTE, STV82x8_MUTEDIG_SUBWOOFER_MASK ); } ucRegValue = ( ucBassManage | ucSTLFEAdd | ucDolbyPro | ucSubWoofer |ucBassGainSW |ucBassConfNum ); ucResult = STV82x8_DataMaskWrite ( OUTPUT_BASS_MNGT, ucRegValue, OUTPUT_BASS_MNGT_MASK ); return ( ucResult ); } /***************************************************************************************** * Function: * unsigned char STV82x8_SetPinkNoiseGenerator(unsigned char ucNoiseOn, unsigned char ucSelectSpeaker, unsigned char ucOuputRange) * Description: * This function sets pink noise generator's register. * Input: * STV82x8_NOISE_GENERATIONB_ON = Noise Generation active. * STV82x8_NOISE_GENERATIONB_OFF = Noise Generation not active. * STV82x8_OUTPUT_FULLRANGE = noise is outputed with full range. * STV82x8_OUTPUT_10_DB = noise is outputed with a 10dB attenuation. * STV82x8_SRIGHT_NOISE_ON = Level adjustment ON. * STV82x8_SLEFT_NOISE_ON = Level adjustment OFF. * STV82x8_SUB_NOISE_ON = Bass Management Configuration 0. * STV82x8_CENTER_NOISE_ON = Bass Management Configuration 1. * STV82x8_RIGHT_NOISE_ON = Bass Management Configuration 2. * STV82x8_LEFT_NOISE_ON = Bass Management Configuration 3. * Output: * None * Return: * STV82x8_I2C_ERROR = I2C's communication is failed. * STV82x8_INVALID_PARAM = Invalid params * STV82X8_NO_ERROR = No error. *************************************************************************************/ unsigned char STV82x8_SetPinkNoiseGenerator(unsigned char ucNoiseOn, unsigned char ucSelectSpeaker, unsigned char ucOuputRange) { unsigned char ucRegValue, ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if(( ucNoiseOn != STV82x8_NOISE_GENERATIONB_ON ) && ( ucNoiseOn != STV82x8_NOISE_GENERATIONB_OFF )) { return ( STV82X8_INVALID_PARAM ); } if(( ucOuputRange != STV82x8_OUTPUT_FULLRANGE ) && ( ucOuputRange != STV82x8_OUTPUT_10_DB )) { return ( STV82X8_INVALID_PARAM ); } if(( ucSelectSpeaker != STV82x8_SRIGHT_NOISE_ON ) && ( ucSelectSpeaker != STV82x8_SLEFT_NOISE_ON ) && ( ucSelectSpeaker != STV82x8_SUB_NOISE_ON ) && ( ucSelectSpeaker != STV82x8_CENTER_NOISE_ON) && ( ucSelectSpeaker != STV82x8_RIGHT_NOISE_ON ) && ( ucSelectSpeaker != STV82x8_LEFT_NOISE_ON )) { return ( STV82X8_INVALID_PARAM ); } ucRegValue = ( ucNoiseOn |ucOuputRange |ucSelectSpeaker ); ucResult = I2cWriteSTV82x8( NOISE_GENERATOR, ucRegValue ); return ( ucResult ); } /************************************************************************************ * Function: * unsigned char STV82x8_SetFMTimeOut(unsigned char ucTimeOut) * Description: * This function set FM search time out to special value. * Input: * FM_TIME_16MS = 16 ms. * FM_TIME_32MS = 32 ms. * FM_TIME_48MS = 48 ms. * FM_TIME_64MS = 64 ms. * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_INVALID_PARAM = Invalid params * STV82X8_NO_ERROR = Successfully set time out for Am/Fm. ************************************************************************************/ unsigned char STV82x8_SetFMTimeOut(unsigned char ucTimeOut) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = STV82x8_DataMaskWrite(AUTOSTD_TIME, ucTimeOut, STV82X8_FM_TIME_MASK ); return ( ucResult ); } /************************************************************************************ * Function: * unsigned char STV82x8_SetStereoTimeOut(unsigned char ucTimeOut) * Description: * This function set Stereo search time out to special value. * Input: * STEREO_TIME_20MS = 16 ms. * STEREO_TIME_40MS = 40 ms. * STEREO_TIME_100MS = 100 ms. * STEREO_TIME_200MS = 200 ms. * STEREO_TIME_400MS = 400 ms. * STEREO_TIME_800MS = 800 ms. * STEREO_TIME_1200MS = 1200 ms. * STEREO_TIME_1600MS = 1600 ms. * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_INVALID_PARAM = Invalid params * STV82X8_NO_ERROR = Successfully set time out for Am/Fm. *************************************************************************************/ unsigned char STV82x8_SetStereoTimeOut(unsigned char ucTimeOut) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = STV82x8_DataMaskWrite( AUTOSTD_TIME, ucTimeOut, STV82X8_STEREO_TIME_MASK ); return ( ucResult ); } /************************************************************************************* * Function: * unsigned char STV82x8_SetScartDefaultPrescale(VOID) * Description: * This function set scart's register for prescale to default value. * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set prescale for Scart. *************************************************************************************/ unsigned char STV82x8_SetScartDefaultPrescale(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = I2cWriteSTV82x8( PRESCALE_SCART, SCART_PRESCALING_DEFAULTVALU ); return ( ucResult ); } /************************************************************************************** * Function: * unsigned char STV82x8_SetMonoStereoDefaultPrescale(VOID) * Description: * This function set Am and Fm's register for prescale to default value. * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = successfully set prescale for Fm/Am. ***************************************************************************************/ unsigned char STV82x8_SetMonoStereoDefaultPrescale(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = STV82x8_DataMaskWrite ( PRESCALE_MONO, MONO_PRESCALING_DEFAULTVALU, PRESCALE_MONO_MASK ); ucResult |= I2cWriteSTV82x8 ( PRESCALE_STEREO, STEREO_PRESCALING_DEFAULTVALU ); return ( ucResult ); } /************************************************************************************** * Function: * unsigned char STV82x8_SAPDefaultPrescale(VOID) * Description: * This function set Nicam's register for prescale to default value. * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Successfully set prescale for Nicam. *************************************************************************************/ unsigned char STV82x8_SAPDefaultPrescale(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = I2cWriteSTV82x8 ( PRESCALE_SAP, SAP_PRESCALING_DEFAULTVALU ); return ( ucResult ); } /*************************************************************************************** * Function: * unsigned char STV82x8_I2SDefaultPrescale(unsigned char ucI2SPort, unsigned char ucPreScaleVal) * Description: * This function set Nicam's register for prescale to default value. * Input: * unsigned char ucI2SPort: PRESCALE_I2S_0, PRESCALE_I2S_1 or PRESCALE_I2S_2 * unsigned char ucPreScale: Prescale value * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Successfully set prescale for Nicam. ***************************************************************************************/ unsigned char STV82x8_I2SDefaultPrescale(unsigned char ucI2SPort, unsigned char ucPreScaleVal) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = I2cWriteSTV82x8 ( ucI2SPort, ucPreScaleVal ); return ( ucResult ); } /***************************************************************************************** * Function: * unsigned char STV82x8_SetEqualizerValue(unsigned char ucEqualizerIndex, unsigned char ucEQBandIndex ) * Description: * This function executes that STV82x8 is set by special equalizer band's value. * Input: * ucEqualizerIndex = EQUALIZER_100HZ = Band 1. * EQUALIZER_330HZ = Band 2. * EQUALIZER_1KHZ = Band 3. * EQUALIZER_3P3KHZ = Band 4. * EQUALIZER_10KHZ = Band 5. * ucEQBandIndex : Equalizer table index * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_INVALID_PARAM = Invalid params. * STV82X8_NO_ERROR = Successfully set Equalizer. ****************************************************************************************/ unsigned char STV82x8_SetEqualizerValue(unsigned char ucEqualizerIndex, unsigned char ucEQBandIndex ) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if(( ucEqualizerIndex > EQUALIZER_10KHZ ) || ( ucEQBandIndex > sizeof( EQUALIZER_TABLE ))) return ( STV82X8_INVALID_PARAM ); // ucResult = STV82x8_DataMaskWrite ( LS_EQ_BT_CTRL, STV82X8_EQUALIZE_ON, STV82X8_EQUALIZE_MASK );// Josie 8/21 ucResult = I2cWriteSTV82x8((unsigned char)( LS_EQ_BAND + ucEqualizerIndex ), (unsigned char)EQUALIZER_TABLE[ucEQBandIndex] ); return ( ucResult ); } /*************************************************************************************** * Function: * unsigned char STV82x8_SetPseudoEffect(unsigned char ucPseudo) * Description: * This function executes all function in order to change Pseudo On & Off. * TV-Set has to save Pseudo On & Off information because TV-Set has to * work well, after TV-Set is restarted by Stand-by or AC On. * Input: * On = Pseudo effect ON. * Off = Pseudo effect OFF. * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Successfully set Pseudo. **************************************************************************************/ unsigned char STV82x8_SetPseudoEffect(unsigned char ucPseudo) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if(( ucPseudo != STV82X8_PSEUDO_ON ) && ( ucPseudo != STV82X8_PSEUDO_OFF ) ) { return ( STV82X8_INVALID_PARAM ); } if( ucPseudo == STV82X8_PSEUDO_ON ) ucResult = STV82x8_SetSRS_InputMode( STV82x8_SRS_MONO_LEFT ); else ucResult = STV82x8_SetSRS_InputMode( STV82X8_ALL_SRS_OFF ); return ( ucResult ); } /************************************************************************************* * Function: * unsigned char STV82x8_SetSRSWOW_Effect(unsigned char ucSRSWOW) * Description: * This function executes all function in order to change SRS On & Off. * TV-Set has to save SRS On & Off information because TV-Set has to * work well, after TV-Set is restarted by Stand-by or AC On. * Input: * On = SRS effect ON. * Off = SRS effect OFF. * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Successfully set SRS. *************************************************************************************/ unsigned char STV82x8_SetSRSWOW_Effect(unsigned char ucSRSWOW) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if(( ucSRSWOW != STV82x8_SRS_WOW_ON ) && ( ucSRSWOW != STV82x8_SRS_WOW_OFF ) ) { return ( STV82X8_INVALID_PARAM ); } if( ucSRSWOW == STV82x8_SRS_WOW_ON ) ucResult = STV82x8_SetSRS_InputMode( STV82x8_SRS_LR_STEREO ); else ucResult = STV82x8_SetSRS_InputMode( STV82X8_ALL_SRS_OFF ); return ( ucResult ); } /*************************************************************************************** * Function: * unsigned char STV82x8_SetSRSTRS_DolbyPro1_Effect(unsigned char ucSRS_TruSurround, unsigned char ucDolby_ProLogic1) * Description: * This function executes all function in order to change SRS On & Off. * TV-Set has to save SRS On & Off information because TV-Set has to * work well, after TV-Set is restarted by Stand-by or AC On. * Input: * On = SRS effect ON. * Off = SRS effect OFF. * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Successfully set SRS. ****************************************************************************************/ unsigned char STV82x8_SetSRSTRS_DolbyPro1_Effect(unsigned char ucSRS_TruSurround, unsigned char ucDolby_ProLogic1 ) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if(( ucSRS_TruSurround != STV82x8_SRS_TRX_ON ) && ( ucSRS_TruSurround != STV82x8_SRS_TRX_OFF ) ) { return ( STV82X8_INVALID_PARAM ); } if(( ucDolby_ProLogic1 != STV82x8_DOLBY_PRO1_ON ) && ( ucDolby_ProLogic1 != STV82x8_DOLBY_PRO1_OFF ) ) { return ( STV82X8_INVALID_PARAM ); } if( ucSRS_TruSurround == STV82x8_SRS_TRX_OFF ) { ucResult = STV82x8_SetSRS_InputMode( STV82X8_ALL_SRS_OFF ); } else if( ucDolby_ProLogic1 == STV82x8_DOLBY_PRO1_OFF ) { ucResult = STV82x8_SetSRS_InputMode( STV82x8_SRS_LRC ); } else if( ucDolby_ProLogic1 == STV82x8_DOLBY_PRO1_ON ) { ucResult = STV82x8_SetSRS_InputMode( STV82x8_SRS_LRCS ); } return ( ucResult ); } /**************************************************************************************** * Function: * unsigned char STV82x8_ControlTurboSound(unsigned char ucTurbo, unsigned char ucLoudnessIndex ) * Description: * This function executes all things which are related to turbo control and * forced STV82x8 is set by turbo control register to values of special * volume tables. * Input: * On = Turbo effect ON. * Off = Turbo effect OFF. * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Successfully set Turbo sound. ***************************************************************************************/ unsigned char STV82x8_ControlTurboSound(unsigned char ucTurbo, unsigned char ucLoudnessIndex ) { unsigned char ucLoudNess, ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if( ucTurbo == STV82X8_TURBO_SOUND_ON ) { ucLoudNess = ( ( LOUDNESS_TABLE[ucLoudnessIndex] << 1 ) | STV82X8_LOUNDNESS_ENABLE ); ucResult = STV82x8_DataMaskWrite ( LS_LOUDNESS, ucLoudNess, LS_LOUDNESS_MASK ); } else if( ucTurbo == STV82X8_TURBO_SOUND_OFF ) { for( ucLoudNess = LOUDNESS_TABLE[ucLoudnessIndex]; ucLoudNess > 0; ucLoudNess-- ) { ucResult = STV82x8_DataMaskWrite ( LS_LOUDNESS, (unsigned char) ((ucLoudNess << 1) | STV82X8_LOUNDNESS_ENABLE), LS_LOUDNESS_MASK ); usleep( 100 ); //5ms } ucResult = STV82x8_DataMaskWrite ( LS_LOUDNESS, STV82X8_LOUNDNESS_DISABLE, LS_LOUDNESS_MASK ); } else { ucResult = (unsigned char)( STV82X8_INVALID_PARAM ); } return ( ucResult ); } /************************************************************************************* * Function: * unsigned char STV82x8_AutoVolumeCtrl(unsigned char ucSvcSel) * Description: * This function executes all things which are related to auto volume control and * forced STV82x8 is set by auto volume control register to values of special * volume tables. * Input: * SvcSel = Auto volume on & off. * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Successfully set Auto volume. ************************************************************************************/ unsigned char STV82x8_AutoVolumeCtrl(unsigned char ucSvcSel) { unsigned char i, ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if( ucSvcSel == STV82x8_SVC_ON ) { ucResult = I2cWriteSTV82x8 ( SVC_LS_TIME_TH, STV82X8_SVC_30MSCONST_0DBGAIN ); ucResult |= I2cWriteSTV82x8 ( SVC_LS_TIME_TH, STV82X8_SVC_30MSCONST_205DBGAIN ); for( i = 0; i < STV82X8_LS_HP_MAKE_UP_GAIN_AUTOON; i++ ) { I2cWriteSTV82x8 ( SVC_LS_GAIN, i ); } ucResult |= I2cWriteSTV82x8 ( SVC_LS_TIME_TH, STV82X8_SVC_16MSCONST_205DBGAIN ); ucResult |= STV82x8_DataMaskWrite( SVC_LS_CONTROL, STV82X8_AUTOSVC_ON, STV82X8_SVCON_MASK ); } else if( ucSvcSel == STV82x8_SVC_OFF ) { ucResult = I2cWriteSTV82x8 ( SVC_LS_TIME_TH, STV82X8_SVC_30MSCONST_205DBGAIN ); ucResult |= I2cWriteSTV82x8 ( SVC_LS_TIME_TH, STV82X8_SVC_30MSCONST_0DBGAIN ); for( i = STV82X8_LS_HP_MAKE_UP_GAIN_AUTOON; i > 0; i-- ) { I2cWriteSTV82x8 ( SVC_LS_GAIN, i ); } usleep( 1500 ); //100ms ucResult |= STV82x8_DataMaskWrite( SVC_LS_CONTROL, STV82X8_AUTOSVC_OFF, STV82X8_SVCON_MASK ); } else { ucResult = (unsigned char)( STV82X8_INVALID_PARAM ); } return ( ucResult ); } /************************************************************************************* * Function: * unsigned char STV82x8_AutoVolumeHPCtrl(unsigned char ucSvcSel) * Description: * This function executes all things which are related to HeadPhone auto volume * control and forced STV82x8 is set by auto volume control register to values * of special volume tables. * Input: * SvcSel = HP Auto volume on & off. * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Successfully set Auto volume. ************************************************************************************/ unsigned char STV82x8_AutoVolumeHPCtrl(unsigned char ucSvcSel) { unsigned char i, ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if( ucSvcSel == STV82x8_SVC_ON ) { ucResult = I2cWriteSTV82x8 ( SVC_HP_TIME_TH, STV82X8_SVC_30MSCONST_0DBGAIN ); ucResult |= I2cWriteSTV82x8 ( SVC_HP_TIME_TH, STV82X8_SVC_30MSCONST_205DBGAIN ); for( i = 0; i < STV82X8_LS_HP_MAKE_UP_GAIN_AUTOON; i++ ) { I2cWriteSTV82x8 ( SVC_HP_GAIN, i ); } ucResult |= I2cWriteSTV82x8 ( SVC_HP_TIME_TH, STV82X8_SVC_16MSCONST_205DBGAIN ); ucResult |= STV82x8_DataMaskWrite( SVC_HP_CONTROL, STV82X8_AUTOSVC_ON, STV82X8_SVCON_MASK ); } else if( ucSvcSel == STV82x8_SVC_OFF ) { ucResult = I2cWriteSTV82x8 ( SVC_HP_TIME_TH, STV82X8_SVC_30MSCONST_205DBGAIN ); ucResult |= I2cWriteSTV82x8 ( SVC_HP_TIME_TH, STV82X8_SVC_30MSCONST_0DBGAIN ); for( i = STV82X8_LS_HP_MAKE_UP_GAIN_AUTOON; i > 0; i-- ) { I2cWriteSTV82x8 ( SVC_HP_GAIN, i ); } usleep( 1500 ); //100ms ucResult |= STV82x8_DataMaskWrite( SVC_HP_CONTROL, STV82X8_AUTOSVC_OFF, STV82X8_SVCON_MASK ); } else { ucResult = (unsigned char)( STV82X8_INVALID_PARAM ); } return ( ucResult ); } /*************************************************************************************** * Function: * unsigned char STV82x8_SetOutput_RFConfig(VOID) * Description: * Configure RF for Input & Output. * < RF > ------------------- < BTSC MOD > -----------> [LS] * < MONO_IN> --- * [SC1] ----------------------------------------------> [SC2] * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. ***************************************************************************************/ unsigned char STV82x8_SetOutput_RFConfig(VOID) { unsigned char ucRegVal, ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = I2cReadSTV82x8( ADC_CTRL, &ucRegVal ); if(( ucRegVal & STV82X8_ADC_WAKEUP_MASK ) == 0 ) { ucResult |= STV82x8_DataMaskWrite ( (unsigned char)ADC_CTRL, (unsigned char)( ucRegVal | STV82X8_ADC_WAKEUP_MASK ), STV82X8_ADC_WAKEUP_MASK ); usleep( 500 ); //35ms } // loadspeaker ucResult |= STV82x8_DataMaskWrite ( AUDIO_MATRIX1_INPUT, STV82X8_AUDIOINPUT_BTSC_DEM, STV82X8_MATRIX1_INPUT_MASK ); // headphone ucResult |= STV82x8_DataMaskWrite ( AUDIO_MATRIX1_INPUT, (STV82X8_AUDIOINPUT_BTSC_DEM << 3), (STV82X8_MATRIX1_INPUT_MASK << 3) ); // SPDIF out ucResult |= STV82x8_DataMaskWrite( AUDIO_MATRIX3_INPUT, STV82X8_AUDIOINPUT_BTSC_DEM<<3, STV82X8_MATRIX3_INPUT_MASK ); ucResult |= STV82x8_DataMaskWrite ( ADC_CTRL, ( STV82X8_ADC_WAKEUP_MASK | STV82X8_ADCINPUT_MONO ), ( STV82X8_ADC_WAKEUP_MASK | STV82X8_ADCINPUT_MASK) ); ucResult |= STV82x8_DataMaskWrite ( SCART1_2_OUTPUT_CTRL, SCARTOUT_SC2OUT_SC1_DSP, STV82X8_SCARTOUT_SC2OUT_MASK ); return ( ucResult ); } /**************************************************************************************** * Function: * unsigned char STV82x8_SetOutput_I2SConfig(VOID) * Description: * Configure I2S for Input & Output. * ------------------- < I2S > -----------> [LS] * < MONO_IN> --- * [SC1] ----------------------------------------------> [SC2] * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. ****************************************************************************************/ unsigned char STV82x8_SetOutput_I2SConfig(VOID) { unsigned char ucRegVal, ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = I2cReadSTV82x8( ADC_CTRL, &ucRegVal ); if(( ucRegVal & STV82X8_ADC_WAKEUP_MASK ) == 1 ) { ucResult |= STV82x8_DataMaskWrite ( (unsigned char)ADC_CTRL, 0, STV82X8_ADC_WAKEUP_MASK ); usleep( 500 ); //35ms } // LS output ucResult |= STV82x8_DataMaskWrite ( AUDIO_MATRIX1_INPUT, STV82X8_AUDIOINPUT_I2S, STV82X8_MATRIX1_INPUT_MASK ); // Headphone output ucResult |= STV82x8_DataMaskWrite ( AUDIO_MATRIX1_INPUT, (STV82X8_AUDIOINPUT_I2S << 3), (STV82X8_MATRIX1_INPUT_MASK << 3) ); // SPDIF out ucResult |= STV82x8_DataMaskWrite( AUDIO_MATRIX3_INPUT, (STV82X8_AUDIOINPUT_I2S << 3), STV82X8_MATRIX3_INPUT_MASK ); return ( ucResult ); } /************************************************************************************* * Function: * unsigned char STV82x8_SetInOutput_ScartConfig(unsigned char ScartNo) * Description: * Configure SCART for Input & Output. * SC1_IN ----->ADC-----> LS_OUT * SC2_IN -----> * SC3_IN------> * SC1_IN ---------------> SC1_OUT * SC2_IN ---------------> SC2_OUT * SC3_IN----------------> SC3_OUT * Input: * ScartNo = STV82X8_INPUT_AV1 [0x01]. * = STV82X8_INPUT_AV2 [0x02]. * = STV82X8_INPUT_AV3 [0x03]. * Output * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_INVALID_PARAM = Invalid params. * STV82X8_NO_ERROR = Success. ************************************************************************************/ //unsigned char STV82x8_SetInOutput_ScartConfig(unsigned char ucInputAV) ScartNo_t unsigned char STV82x8_SetInOutput_ScartConfig(ScartNo_t ScartNo) { unsigned char ucRegVal, ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = I2cReadSTV82x8( ADC_CTRL, &ucRegVal ); if(( ucRegVal & STV82X8_ADC_WAKEUP_MASK ) == 0 ) { ucResult |= STV82x8_DataMaskWrite ( (unsigned char)ADC_CTRL, (unsigned char)( ucRegVal | STV82X8_ADC_WAKEUP_MASK ), STV82X8_ADC_WAKEUP_MASK ); usleep( 500 ); //35ms } // LS output ucResult |= STV82x8_DataMaskWrite ( AUDIO_MATRIX1_INPUT, STV82X8_AUDIOINPUT_SCART, STV82X8_MATRIX1_INPUT_MASK ); // headphone output ucResult |= STV82x8_DataMaskWrite ( AUDIO_MATRIX1_INPUT, (STV82X8_AUDIOINPUT_SCART << 3), (STV82X8_MATRIX1_INPUT_MASK << 3) ); //set SPDIF out from SCART input ucResult |= STV82x8_DataMaskWrite( AUDIO_MATRIX3_INPUT, STV82X8_AUDIOINPUT_SCART<<3, STV82X8_MATRIX3_INPUT_MASK ); switch( ScartNo ) { case SCART_INPUT1: ucResult |= STV82x8_DataMaskWrite( ADC_CTRL, ( STV82X8_ADC_WAKEUP_MASK | STV82X8_SCARTINPUT_SC1 ), ( STV82X8_ADC_WAKEUP_MASK | STV82X8_MATRIX1_INPUT_MASK )); ucResult |= STV82x8_DataMaskWrite( SCART1_2_OUTPUT_CTRL, SCARTOUT_SC2OUT_SC1_DSP, STV82X8_SCARTOUT_SC2OUT_MASK ); break; case SCART_INPUT2: ucResult |= STV82x8_DataMaskWrite( ADC_CTRL, ( STV82X8_ADC_WAKEUP_MASK | STV82X8_SCARTINPUT_SC2 ), ( STV82X8_ADC_WAKEUP_MASK | STV82X8_MATRIX1_INPUT_MASK )); ucResult |= STV82x8_DataMaskWrite( SCART1_2_OUTPUT_CTRL, SCARTOUT_SC2OUT_SC2_DSP, STV82X8_SCARTOUT_SC2OUT_MASK ); break; case SCART_INPUT3: ucResult |= STV82x8_DataMaskWrite( ADC_CTRL, ( STV82X8_ADC_WAKEUP_MASK | STV82X8_SCARTINPUT_SC3 ), ( STV82X8_ADC_WAKEUP_MASK | STV82X8_MATRIX1_INPUT_MASK )); ucResult |= STV82x8_DataMaskWrite( SCART1_2_OUTPUT_CTRL, SCARTOUT_SC2OUT_SC3_DSP, STV82X8_SCARTOUT_SC2OUT_MASK ); break; case SCART_INPUT4: ucResult |= STV82x8_DataMaskWrite( ADC_CTRL, ( STV82X8_ADC_WAKEUP_MASK | STV82X8_SCARTINPUT_SC4 ), ( STV82X8_ADC_WAKEUP_MASK | STV82X8_MATRIX1_INPUT_MASK )); ucResult |= STV82x8_DataMaskWrite( SCART1_2_OUTPUT_CTRL, SCARTOUT_SC2OUT_SC4_DSP, STV82X8_SCARTOUT_SC2OUT_MASK ); break; default: ucResult |= STV82X8_INVALID_PARAM; break; } return(ucResult); } /************************************************************************************** * Function: * unsigned char STV82x8_AudioMatrix_LSOut (unsigned char ucInput ) * Description: * This function select Input mode then output LS * Input: * Input to DEMOD Backend * unsigned char ucInput: 000b: Mute output * 001b: Delay Input * 010b: BTSC Demod Input * 011b: Downmix LtRtInput * 100b: I2S Input * 101b: SCART Input * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. **************************************************************************************/ unsigned char STV82x8_AudioMatrix_LSOut (unsigned char ucInput ) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult |= STV82x8_DataMaskWrite( AUDIO_MATRIX1_INPUT, ucInput, STV82X8_MATRIX1_INPUT_MASK ); return(ucResult); } /************************************************************************************** * Function: * unsigned char STV82x8_AudioMatrix_HeadphoneOut (unsigned char ucInput ) * Description: * This function select Input mode then output HP * Input: * Input to DEMOD Backend * unsigned char ucInput: 000b: Mute output * 001b: Delay Input * 010b: BTSC Demod Input * 011b: Downmix LtRtInput * 100b: I2S Input * 101b: SCART Input * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. **************************************************************************************/ unsigned char STV82x8_AudioMatrix_HeadphoneOut (unsigned char ucInput ) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult |= STV82x8_DataMaskWrite( AUDIO_MATRIX1_INPUT, (ucInput << 3), (STV82X8_MATRIX1_INPUT_MASK << 3)); return(ucResult); } /************************************************************************************** * Function: * unsigned char STV82x8_Control_ChannelMatrixLS (unsigned char ucInput ) * Description: * This function change ChannelMatrix for LS (Manual Mode) * Input: * ucInput * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. *************************************************************************************/ unsigned char STV82x8_Control_ChannelMatrixLS (unsigned char ucInput ) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult |= STV82x8_DataMaskWrite( CHANNEL_MATRIX_LS, (unsigned char) (ucInput), (CM_MATRIX_LS_MASK | AUTOSTD_CTRL_LS_MASK) ); return(ucResult); } /*************************************************************************************** * Function: * unsigned char STV82x8_Set_SPDIFOut (unsigned char Input1, unsigned char Input2) * Description: * This function set SPDIFOut & select Int/Ext. * Input: * Input1, Input2 * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. ***************************************************************************************/ unsigned char STV82x8_Set_SPDIFOut (unsigned char Input1, unsigned char Input2) { unsigned char ucResult = STV82X8_NO_ERROR; unsigned char ucMute = 0; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = I2cReadSTV82x8(MUTE_DIGITAL, &ucMute); if(Input1 == External_SPDIF) { if( (ucMute & STV82X8_DIGITAL_SPDIF_MUTE) == 0) ucResult |= STV82x8_DataMaskWrite( DAC_CTRL, Input1, STV82x8_MUX_MASK ); } else { ucResult |= STV82x8_DataMaskWrite( DAC_CTRL, Input1, STV82x8_MUX_MASK ); } ucResult |= STV82x8_DataMaskWrite( CHANNEL_MATRIX_SPDIF, Input2, STV82x8_CMMATRIX_SPDIF_MASK ); return(ucResult); } /************************************************************************************** * Function: * unsigned char STV82x8_RefreshSTV(VOID) * Description: * Reinitialize STV82x8 * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_INVALID_PARAM = Invalid params. * STV82X8_NO_ERROR = Success. * ************************************************************************************/ unsigned char STV82x8_RefreshSTV(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = STV82x8_Initialize(gI2C_num,gSlaveAddr); ucResult |= STV82x8_SetOutput_RFConfig(); return(ucResult); } /********************************************************************************** * Function: * unsigned char STV82x8_CheckElectricalShock(VOID) * Description: * Sometimes TV-Set is forcing electrical shock to STV82x8. * In case of this, TV-Set has to restart and then must happen to good sound signal. * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_INVALID_PARAM = Invalid params. * STV82X8_NO_ERROR = Success. *********************************************************************************/ unsigned char STV82x8_CheckElectricalShock(VOID) { unsigned char ucRegValue, ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = I2cReadSTV82x8( IRQ_STAT, &ucRegValue ); if( !( ucRegValue & ( STV82X8_IRQ0_MASK | STV82X8_IRQ3_MASK )) ) ucResult = STV82x8_RefreshSTV(); return ( ucResult ); } /************************************************************************************* * Function: * unsigned char STV82x8_AutoSearch(unsigned char * pucSoundSystem ) * Description: * This function must be called by external function whenever auto search is executed. * Input: * None. * Output: * unsigned char * pucSoundSystem:sound mode * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_RESOURCE_ERROR = Resource error * STV82X8_NO_ERROR = Success. ************************************************************************************/ unsigned char STV82x8_AutoSearch(unsigned char * pucSoundSystem ) { unsigned char ucSoundSystem, ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = STV82x8_All_SoundSystem_Check(); usleep( 1000 ); //150ms ucResult |= STV82x8_GetSoundSystem(&ucSoundSystem, TRUE); if(ucSoundSystem == NOTFOUND_SOUND) return ( STV82X8_RESOURCE_ERROR ); *pucSoundSystem = ucSoundSystem; return(ucResult); } /**************************************************************************************** * Function: * unsigned char STV82x8_ForcedMono(VOID) * Description: * If sound mode is changed by the special remote key for forced Fm mono, * STV82x8 has to response to correct action * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. ***************************************************************************************/ unsigned char STV82x8_ForcedMono(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = STV82x8_DataMaskWrite( AUTOSTD_CTRL, STV82X8_AUTOSTD_MONO_CHECK, STV82X8_AUTOSTD_CHECK_MASK); return ( ucResult ); } /**************************************************************************************** * Function: * unsigned char STV82x8_ReturnToStereoFromMono(VOID) * Description: * If sound mode is changed by the special remote key for forced stereo, * STV82x8 has to response to correct action. * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. * **************************************************************************************/ unsigned char STV82x8_ReturnToStereoFromMono(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = STV82x8_DataMaskWrite( AUTOSTD_CTRL, STV82X8_AUTOSTD_STEREO_CHECK, STV82X8_AUTOSTD_CHECK_MASK ); return(ucResult); } /***************************************************************************************** * Function: * unsigned char STV82x8_PlayBeeperSound(VOID) * Description: * This function happens to beeper sound. * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. ****************************************************************************************/ unsigned char STV82x8_PlayBeeperSound(VOID) { unsigned char ucRegVal, ucFreqVol, ucResult = STV82X8_NO_ERROR; unsigned char i, ucCount = 0; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = STV82x8_SetDigitalMute(STV82x8_MUTE_ALL_OUTPUT, STV82x8_ALL_OUTPUT_MASK); STV82x8_DataMaskWrite( BEEPER_MODE, ( STV82X8_BEEPER_PULSE | STV82X8_BEEPEROUT_LS ), ( STV82X8_BEEPER_PULSE_MASK | STV82X8_BEEPEROUT_LS_MASK )); usleep( 500 ); //20ms for( i = 0; i < 9; i++ ) { ucFreqVol = ( BEEPER_ON_TABLE[i] ); I2cWriteSTV82x8( BEEPER_FREQ_VOL, ucFreqVol ); STV82x8_DataMaskWrite ( BEEPER_ON, STV82X8_BEEPER_ON, BEEPER_ON_MASK ); usleep( 1000 ); //75ms do { I2cReadSTV82x8( BEEPER_ON, &ucRegVal ); } while(( ucRegVal != 0 ) && ( ucCount++ < 200 )); } ucResult |= STV82x8_DataMaskWrite( BEEPER_ON, STV82X8_BEEPER_OFF, BEEPER_ON_MASK ); ucResult |= STV82x8_SetDigitalUnMute(STV82x8_UNMUTE_ALL_OUTPUT, STV82x8_ALL_OUTPUT_MASK); return ( ucResult ); } /*********************************************************************************** * Function: * unsigned char STV82x8_BeeperAmbulanceSound(VOID) * Description: * This function happens to beeper Ambulance Sound. * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. ***********************************************************************************/ unsigned char STV82x8_BeeperAmbulanceSound(VOID) { unsigned char ucRegVal, ucFreqVol, ucResult = STV82X8_NO_ERROR; unsigned char i, ucCount = 0; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = STV82x8_SetDigitalMute(STV82x8_MUTE_ALL_OUTPUT, STV82x8_ALL_OUTPUT_MASK); STV82x8_DataMaskWrite( BEEPER_MODE, ( STV82X8_BEEPER_PULSE | STV82X8_BEEPEROUT_LS ), ( STV82X8_BEEPER_PULSE_MASK | STV82X8_BEEPEROUT_LS_MASK )); usleep( 500 ); //35ms for( i = 0; i < 9; i++ ) { ucFreqVol = ( BEEPER_DURATION_TABLE_1[i] ); I2cWriteSTV82x8( BEEPER_MODE, ucFreqVol ); ucFreqVol = ( BEEPER_FREQ_VOL_TABLE_1[i] ); I2cWriteSTV82x8( BEEPER_FREQ_VOL, ucFreqVol ); STV82x8_DataMaskWrite ( BEEPER_ON, STV82X8_BEEPER_ON, BEEPER_ON_MASK ); usleep( 1000 ); //75ms do { I2cReadSTV82x8( BEEPER_ON, &ucRegVal ); } while(( ucRegVal != 0 ) && ( ucCount++ < 200 )); } ucResult |= STV82x8_DataMaskWrite( BEEPER_ON, STV82X8_BEEPER_OFF, BEEPER_ON_MASK ); ucResult |= STV82x8_SetDigitalUnMute(STV82x8_UNMUTE_ALL_OUTPUT, STV82x8_ALL_OUTPUT_MASK); return(ucResult); } /*************************************************************************************** * Function: * unsigned char STV82x8_GetSoundSignalState(unsigned char * pucSignalState) * Description: * Let's check if signal is good or not. * Input: * Nnone. * Output: * STV82X8_SOUNDSIGNAL_LOCKED = Signal locked. * STV82X8_SOUNDSIGNAL_UNLOCKED = Signal unlocked. * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_INVALID_PARAM = Invalid params. * STV82X8_NO_ERROR = Success. ***************************************************************************************/ unsigned char STV82x8_GetSoundSignalState(unsigned char * pucSignalState) { unsigned char ucRegValue, ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if( pucSignalState == NULL ) return ( STV82X8_INVALID_PARAM ); ucResult = I2cReadSTV82x8( DEMOD_STAT, &ucRegValue ); if( ucRegValue == ( STV82X8_FM1_CAR & STV82X8_FM1_SQ )) *pucSignalState = STV82X8_SOUNDSIGNAL_LOCKED; else *pucSignalState = STV82X8_SOUNDSIGNAL_UNLOCKED; return(ucResult); } /************************************************************************************* * Function: * unsigned char STV82x8_GetSoundSystem(unsigned char * pucSoundSystem, BOOL bDetectFM) * Description: * Automatically detect soundsystem (Read 8Ch register). * 8Ch register depends on 8Ah register. * Input: * BOOL bDetectFM: TRUE= Detect FM Carrier and FM Squelch * None * Output: * Sound Mode: MONO, STEREO, SAP, or None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_INVALID_PARAM = Invalid params. * STV82X8_NO_ERROR = Success. ************************************************************************************/ unsigned char STV82x8_GetSoundSystem(unsigned char * pucSoundSystem, BOOL bDetectFM) { unsigned char ucRegValue, ucSTSoundID; unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if(bDetectFM) { ucResult = STV82x8_GetSoundSignalState( &ucRegValue ); if( ucRegValue == STV82X8_SOUNDSIGNAL_UNLOCKED ) { *pucSoundSystem = MONO; return( STV82X8_RESOURCE_ERROR ); } } ucResult |= I2cReadSTV82x8( AUTOSTD_STATUS, &ucRegValue ); ucSTSoundID = ( ucRegValue & STV82X8_AUTOSTD_STATUS_MASK ); if (ucSTSoundID & STV82X8_SAP_OK) *pucSoundSystem = SAP; else if (ucSTSoundID & STV82X8_STEREO_OK) *pucSoundSystem = STEREO; else if (ucSTSoundID & STV82X8_MONO_OK) *pucSoundSystem = MONO; else *pucSoundSystem = NOTFOUND_SOUND; return(ucResult); } /*********************************************************************************** * Function: * unsigned char STV82x8_GetSoundSystem_Independ(unsigned char * pucSoundSystem, BOOL bDetectFM) * Description: * Automatically detect soundsystem(Read 8Dh register). * 8Dh register independs on 8Ah register. * Input: * BOOL bDetectFM: TRUE= Detect FM Carrier and FM Squelch * Output: * Sound mode: MONO, STEREO, SAP or SAP_STEREO * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_INVALID_PARAM = Invalid params. * STV82X8_NO_ERROR = Success. ***********************************************************************************/ unsigned char STV82x8_GetSoundSystem_Independ(unsigned char * pucSoundSystem, BOOL bDetectFM) { unsigned char ucRegValue, ucSTSoundID; unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if(bDetectFM) { ucResult = STV82x8_GetSoundSignalState( &ucRegValue ); if( ucRegValue == STV82X8_SOUNDSIGNAL_UNLOCKED ) { *pucSoundSystem = MONO; return ( STV82X8_RESOURCE_ERROR ); } } ucResult |= I2cReadSTV82x8( AUTOSTD_DEM_STATUS, &ucRegValue ); ucSTSoundID = ( ucRegValue & STV82X8_AUTOSTD_DEM_STATUS_MASK ); printf("--------------------------------------%#02x\n", ucSTSoundID); if ( ucSTSoundID == (STV82X8_LCK_DET | STV82X8_ST_DET) ) *pucSoundSystem = STEREO; else if ( ucSTSoundID == (STV82X8_SAP_SQ | STV82X8_SAP_DET) ) *pucSoundSystem = SAP; else if ( ucSTSoundID == (STV82X8_LCK_DET | STV82X8_ST_DET | STV82X8_SAP_SQ | STV82X8_SAP_DET) ) *pucSoundSystem = SAP_STEREO; else *pucSoundSystem = MONO; return(ucResult); } /*********************************************************************************** * Function: * unsigned char STV82x8_ChangeMTS_Manual(unsigned char ucMTS) * Description: * Manually change MTS * Input: * unsigned char ucMTS: MTS * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_INVALID_PARAM = Invalid params. * STV82X8_NO_ERROR = Success. **********************************************************************************/ unsigned char STV82x8_ChangeMTS_Manual(unsigned char ucMTS) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = I2cWriteSTV82x8( MUTE_DIGITAL, STV82X8_DIGITAL_LS_MUTE ); ucResult |= I2cWriteSTV82x8( AUTOSTD_CTRL, ucMTS ); usleep(2000 ); //150ms ucResult |= I2cWriteSTV82x8( MUTE_DIGITAL, STV82X8_DIGITAL_LS_UNMUTE ); return(ucResult); } /*********************************************************************************** * Function: * unsigned char STV82x8_All_SoundSystem_Check(VOID) * Description: * This function set sound system's register for all system searching to speciall values. * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. ***********************************************************************************/ unsigned char STV82x8_All_SoundSystem_Check(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult |= STV82x8_DataMaskWrite( AUTOSTD_CTRL, STV82X8_AUTOSTD_ALL_CHECK, STV82X8_AUTOSTD_CHECK_MASK ); return(ucResult); } /*********************************************************************************** * Function: * unsigned char STV82x8_SetI2SInOut(unsigned char ucI2S_InOut) * Description: * Select I2S input & output. * I2S_OUTPUT[Bit 6&5] of RESET[01h] = 00h * | | | | * [Digital Input] =========> | I2S Block | =======> | Digital | * | | | Processing | * I2S_OUTPUT[Bit 6&5] of RESET[01h] = 60h * | | | | * | Digital | [Digital signal] =========> | I2S Block | =====> [Digital Output] * | Processing | | | * * * Input: * STV82x8_I2S_INPUT = I2S mode is input. * STV82x8_I2S_OUTPUT = I2S mode is output. * Output: * None * Return: * STV82x8_I2C_ERROR = I2C's communication is failed. * STV82x8_INVALID_PARAM = Invalid params. * STV82X8_NO_ERROR = No error. ***********************************************************************************/ unsigned char STV82x8_SetI2SInOut(unsigned char ucI2S_InOut) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if(( ucI2S_InOut != STV82X8_I2S_INPUT ) && ( ucI2S_InOut != STV82X8_I2S_OUTPUT )) { return ( STV82X8_INVALID_PARAM ); } ucResult = STV82x8_DataMaskWrite( SW_RESET, ucI2S_InOut, STV82x8_I2S_INOUT_MASK ); return(ucResult); } /*********************************************************************************** * Function: * unsigned char STV82x8_SetI2SOutputSignal(unsigned char ucI2S_Output) * Description: * Configure I2S output. * Input: * STV82x8_I2S_OUTPUT_SCART = I2S's output connection is Scart. * STV82x8_I2S_OUTPUT_LR = I2S's output connection is Loud speaker. * STV82x8_I2S_OUTPUT_HP_SURROUND = I2S's output connection is HP & Sur. * STV82x8_I2S_OUTPUT_C_SUB = I2S's output connection is Center & Sub. * I2S_OUTPUT[Bit 7~5] of ADC_CTRL[56h] = 00h * [LR Output] -------------|I2S Block| =====> [Digital Output] * I2S_OUTPUT[Bit 7~5] of ADC_CTRL[56h] = 20h * [HP_LSS Output]-------------|I2S Block| =====> [Digital Output] * I2S_OUTPUT[Bit 7~5] of ADC_CTRL[56h] = 40h * [LS C & Sub Output]---------|I2S Block| =====> [Digital Output] * I2S_OUTPUT[Bit 7~5] of ADC_CTRL[56h] = 60h * [Scart Output] -------------|I2S Block| =====> [Digital Output] * I2S_OUTPUT[Bit 7~5] of ADC_CTRL[56h] = 80h * [SPDIF Output] -------------|I2S Block| =====> [Digital Output] * I2S_OUTPUT[Bit 7~5] of ADC_CTRL[56h] = A0h * [Delay] -------------|I2S Block| =====> [Digital Output] * Output: * None * Return: * STV82x8_I2C_ERROR = I2C's communication is failed. * STV82x8_INVALID_PARAM = Invalid params. * STV82X8_NO_ERROR = No error. ***********************************************************************************/ unsigned char STV82x8_SetI2SOutputSignal(unsigned char ucI2S_Output) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if(( ucI2S_Output != STV82X8_I2S_OUTPUT_SCART ) && ( ucI2S_Output != STV82X8_I2S_OUTPUT_LR ) && ( ucI2S_Output != STV82X8_I2S_OUTPUT_HP_SURROUND ) && ( ucI2S_Output != STV82X8_I2S_OUTPUT_C_SUB ) && ( ucI2S_Output != STV82X8_I2S_OUTPUT_SPDIF ) && ( ucI2S_Output != STV82X8_I2S_OUTPUT_DELAY )) { return ( STV82X8_INVALID_PARAM ); } ucResult = STV82x8_DataMaskWrite( ADC_CTRL, ucI2S_Output, STV82x8_I2S_DATA0_CTRL_MASK ); return (ucResult); } /************************************************************************************************ * Function: * unsigned char STV82x8_SetSRS_InputMode(unsigned char ucSRS_InputMode ) * Description: * Select SRS Input mode and control SRS Dialog Clarity. * Input param: * STV82x8_ALL_SRS_OFF = SRS effect Off. * STV82x8_SRS_MONO_LEFT = Transform mono sound into pseudo stereo sound. * STV82x8_SRS_MONO_DCLARITY = Transform mono sound into pseudo stereo sound with additional voice effect. * STV82x8_SRS_LR_STEREO = Transform mono sound into pseudo 3D stereo sound. * STV82x8_SRS_LR_STEREO_DCLARITY = Transform stereo sound into enhanced 3D stereo sound * for L/R with additional voice effect. * STV82x8_SRS_LSR = Transform stereo sound into enhanced 3D stereo sound for L/R/Srd. * STV82x8_SRS_LSR_DCLARITY = Transform stereo sound into enhanced 3D stereo sound * for L/R/Srd with additional voice effect. * STV82x8_SRS_LRLsRs = Transform stereo sound into enhanced spatial virtualized sound for L/R/Ls/Rs. * STV82x8_SRS_LRLsRs_DCLARITY = Transform stereo sound into enhanced spatial virtualized sound * for L/R/Ls/Rs with additional voice effect. * STV82x8_SRS_LRC = Transform stereo sound into enhanced spatial virtualized sound for L/R/C. * STV82x8_SRS_LRC_DCLARITY = Transform stereo sound into enhanced spatial virtualized sound * for L/R/C with additional voice effect. * STV82x8_SRS_LRCS = Transform stereo sound into enhanced spatial virtualized sound for L/R/C/Srd. * STV82x8_SRS_LRCS_DCLARITY = Transform stereo sound into enhanced spatial virtualized sound * for L/R/C/Srd with additional voice effect. * STV82x8_SRS_LRCLsRs = Transform stereo sound into enhanced spatial virtualized sound for L/R/C/Srd. * STV82x8_SRS_LRCLsRs_DCLARITY = Transform stereo sound into enhanced spatial virtualized sound * for L/R/C/Srd with additional voice effect. * STV82x8_SRS_LtRt = Transform stereo sound into enhanced spatial virtualized sound for Lt/Rt. * STV82x8_SRS_LtRt_DCLARITY = Transform stereo sound into enhanced spatial virtualized sound * for Lt/Rt with additional voice effect. * STV82x8_SRS_LRCLsRs_SRS = Transform stereo sound into enhanced 3D stereo sound for L/R/C/Ls/Rs. * STV82x8_SRS_LRCLsRs_SRS_DCLARITY= Transform stereo sound into enhanced 3D stereo sound * L/R/C/Ls/Rs with additional voice effect. * STV82x8_SRS_LRCLsRs_TRX = Transform stereo sound into enhanced spatial virtualized sound for L/R/C/Ls/Rs. * STV82x8_SRS_LRCLsRs_TRX_DCLARITY= Transform stereo sound into enhanced spatial virtualized sound * for L/R/C/Ls/Rs with additional voice effect. * Output: * None * Return: * STV82x8_I2C_ERROR = I2C's communication is failed. * STV82x8_INVALID_PARAM = Invalid params. * STV82X8_NO_ERROR = No error. ********************************************************************************************/ unsigned char STV82x8_SetSRS_InputMode(unsigned char ucSRS_InputMode ) { unsigned char ucResult = STV82X8_NO_ERROR; unsigned char ucTruSrd_Ctrl, ucTruSrd_InputGain; unsigned char ucTruSrd_DCElevation; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if( ucSRS_InputMode > STV82x8_SRS_LRCLsRs_TRX_DCLARITY ) { return ( STV82X8_INVALID_PARAM ); } ucTruSrd_Ctrl = (unsigned char)( STV82x8_TRUSURROUND_OFF ); ucTruSrd_InputGain = (unsigned char)( STV82x8_TRUSRND_INPUT_GAIN ); ucTruSrd_DCElevation = (unsigned char)( STV82x8_TRUSRND_DC_ELEVATION ); switch( ucSRS_InputMode ) { case STV82x8_SRS_MONO_DCLARITY: ucTruSrd_Ctrl = (unsigned char)( STV82x8_DIALOG_CLARITY_ON | STV82x8_HP_MODE_OFF ); case STV82x8_SRS_MONO_LEFT: ucTruSrd_Ctrl |= (unsigned char)( STV82x8_TRUSURROUND_ON | STV82x8_TRUSRND_MONO_LEFT ); break; case STV82x8_SRS_LR_STEREO_DCLARITY: ucTruSrd_Ctrl = (unsigned char)( STV82x8_DIALOG_CLARITY_ON | STV82x8_HP_MODE_OFF ); case STV82x8_SRS_LR_STEREO: ucTruSrd_Ctrl |= (unsigned char)( STV82x8_TRUSURROUND_ON | STV82x8_TRUSRND_LR_STEREO ); break; case STV82x8_SRS_LSR_DCLARITY: ucTruSrd_Ctrl = (unsigned char)( STV82x8_DIALOG_CLARITY_ON | STV82x8_HP_MODE_OFF ); case STV82x8_SRS_LSR: ucTruSrd_Ctrl |= (unsigned char)( STV82x8_TRUSURROUND_ON | STV82x8_TRUSRND_LSR ); break; case STV82x8_SRS_LRLsRs_DCLARITY: ucTruSrd_Ctrl = (unsigned char)( STV82x8_DIALOG_CLARITY_ON | STV82x8_HP_MODE_OFF ); case STV82x8_SRS_LRLsRs: ucTruSrd_Ctrl |= (unsigned char)( STV82x8_TRUSURROUND_ON | STV82x8_TRUSRND_LSLsRs ); break; case STV82x8_SRS_LRC_DCLARITY: ucTruSrd_Ctrl = (unsigned char)( STV82x8_DIALOG_CLARITY_ON | STV82x8_HP_MODE_OFF ); case STV82x8_SRS_LRC: ucTruSrd_Ctrl |= (unsigned char)( STV82x8_TRUSURROUND_ON | STV82x8_TRUSRND_LRC ); break; case STV82x8_SRS_LRCS_DCLARITY: ucTruSrd_Ctrl = (unsigned char)( STV82x8_DIALOG_CLARITY_ON | STV82x8_HP_MODE_OFF ); case STV82x8_SRS_LRCS: ucTruSrd_Ctrl |= (unsigned char)( STV82x8_TRUSURROUND_ON | STV82x8_TRUSRND_LRCS ); break; case STV82x8_SRS_LRCLsRs_DCLARITY: ucTruSrd_Ctrl = (unsigned char)( STV82x8_DIALOG_CLARITY_ON | STV82x8_HP_MODE_OFF ); case STV82x8_SRS_LRCLsRs: ucTruSrd_Ctrl |= (unsigned char)( STV82x8_TRUSURROUND_ON | STV82x8_TRUSRND_LRCLsRs_XT ); break; case STV82x8_SRS_LtRt_DCLARITY: ucTruSrd_Ctrl = (unsigned char)( STV82x8_DIALOG_CLARITY_ON | STV82x8_HP_MODE_OFF ); case STV82x8_SRS_LtRt: ucTruSrd_Ctrl |= (unsigned char)( STV82x8_TRUSURROUND_ON | STV82x8_TRUSRND_LtRt ); break; case STV82x8_SRS_LRCLsRs_SRS_DCLARITY: ucTruSrd_Ctrl = (unsigned char)( STV82x8_DIALOG_CLARITY_ON | STV82x8_HP_MODE_OFF ); case STV82x8_SRS_LRCLsRs_SRS: ucTruSrd_Ctrl |= (unsigned char )( STV82x8_TRUSURROUND_ON | STV82x8_TRUSRND_LRCLsRs_SRS ); break; case STV82x8_SRS_LRCLsRs_TRX_DCLARITY: ucTruSrd_Ctrl = (unsigned char)( STV82x8_DIALOG_CLARITY_ON | STV82x8_HP_MODE_OFF ); case STV82x8_SRS_LRCLsRs_TRX: ucTruSrd_Ctrl |= (unsigned char)( STV82x8_TRUSURROUND_ON | STV82x8_TRUSRND_LRCLsRs_XTPRO2 ); break; case STV82X8_ALL_SRS_OFF: default: ucTruSrd_Ctrl = (unsigned char)( STV82x8_TRUSURROUND_OFF | STV82x8_TRUSRND_LR_STEREO ); break; } ucResult = I2cWriteSTV82x8( TRUSRND_CONTROL, ucTruSrd_Ctrl ); ucResult |= I2cWriteSTV82x8( TRUSRND_INPUT_GAIN, ucTruSrd_InputGain ); ucResult |= I2cWriteSTV82x8( TRUSRND_DC_ELEVATION, ucTruSrd_DCElevation ); return (ucResult); } /*************************************************************************************** * Function: * unsigned char STV82x8_SetSRS_TRUBASS(unsigned char ucTrubassType, unsigned char ucSRS_TruBass) * Description: * Control SRS TruBass. * Input: * unsigned char ucTrubassType: TRUBASS_LS_CONTROL or TRUBASS_HP_CONTROL * unsigned char ucSRS_TruBass: * STV82x8_SRS_TRUBASS_OFF = SRS Tru Bass Off. * STV82x8_SRS_TRUBASS_SMALL = Bass effect for small sized speakers - Not to be able to reproduce low frequencies. * STV82x8_SRS_TRUBASS_MEDIUM = Bass effect for medium sized speakers - Not to be fully able to reproduce low frequencies. * STV82x8_SRS_TRUBASS_LARGE = Bass effect for large sized speakers - To be able to reproduce low frequencies. * Output: * None * Return: * STV82x8_I2C_ERROR = I2C's communication is failed. * STV82x8_INVALID_PARAM = Invalid params. * STV82X8_NO_ERROR = No error. ***************************************************************************************/ unsigned char STV82x8_SetSRS_TRUBASS(unsigned char ucTrubassType, unsigned char ucSRS_TruBass) { unsigned char ucResult = STV82X8_NO_ERROR; unsigned char ucTruBass_LSCtrl, ucTruBass_LSLevel; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if( ucSRS_TruBass > STV82x8_SRS_TRUBASS_LARGE ) { return ( STV82X8_INVALID_PARAM ); } ucTruBass_LSCtrl = (unsigned char)( STV82x8_TRUBASS_OFF |STV82x8_TRUBASS_LF_RESPOSE_200KHZ ); ucTruBass_LSLevel = (unsigned char)( STV82x8_TRUBASS_LS_LEVEL ); switch( ucSRS_TruBass ) { case STV82x8_SRS_TRUBASS_SMALL: ucTruBass_LSCtrl = (unsigned char)( STV82x8_TRUBASS_ON |STV82x8_TRUBASS_LF_RESPOSE_200KHZ ); break; case STV82x8_SRS_TRUBASS_MEDIUM: ucTruBass_LSCtrl = (unsigned char)( STV82x8_TRUBASS_ON |STV82x8_TRUBASS_LF_RESPOSE_100KHZ ); break; case STV82x8_SRS_TRUBASS_LARGE: ucTruBass_LSCtrl = (unsigned char)( STV82x8_TRUBASS_ON |STV82x8_TRUBASS_LF_RESPOSE_60KHZ ); break; case STV82x8_SRS_TRUBASS_OFF: default: break; } ucResult = I2cWriteSTV82x8( ucTrubassType, ucTruBass_LSCtrl ); if(ucTrubassType == TRUBASS_LS_CONTROL) ucResult |= I2cWriteSTV82x8( TRUBASS_LS_LEVEL, ucTruBass_LSLevel ); else ucResult |= I2cWriteSTV82x8( TRUBASS_HP_LEVEL, ucTruBass_LSLevel ); return ( ucResult ); } /****************************************************************************************** * Function: * unsigned char STV82x8_SetDynamicBass(unsigned char ucDynBass_Freq, unsigned char ucBassLevel ) * Description: * This function sets ST Dynamic Bass. * Input: * unsigned char ucDynBass_Freq: * STV82x8_100HZ_CUT_OFF = 100Hz cut off frequency. * STV82x8_150HZ_CUT_OFF = 150Hz cut off frequency. * STV82x8_200HZ_CUT_OFF = 200Hz cut off frequency. * ucBassLevel = ST Dynamic Bass effect level. * Output: * None * Return: * STV82x8_I2C_ERROR = I2C's communication is failed. * STV82x8_INVALID_PARAM = Invalid params. * STV82X8_NO_ERROR = No error. *****************************************************************************************/ unsigned char STV82x8_SetDynamicBass(unsigned char ucDynBass_Freq, unsigned char ucBassLevel ) { unsigned char ucResult, ucRegValue; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if( ucBassLevel > STV82x8_BASS_LEVEL ) return ( STV82X8_INVALID_PARAM ); if(( ucDynBass_Freq != STV82x8_100HZ_CUT_OFF ) && ( ucDynBass_Freq != STV82x8_150HZ_CUT_OFF ) && ( ucDynBass_Freq != STV82x8_200HZ_CUT_OFF )) return ( STV82X8_INVALID_PARAM ); ucRegValue = (unsigned char)( STV82x8_ST_DYNAMIC_BASS_ON | ucDynBass_Freq | ( ucBassLevel << 3 )); ucResult = I2cWriteSTV82x8( DYNAMIC_BASS_LS, ucRegValue ); return (ucResult); } /***************************************************************************************** * Function: * unsigned char STV82x8_SetAVDelay(unsigned char ucDolbyDelay, unsigned char ucTime1_msec, unsigned char ucTime2_msec) * Description: * Set Audio/Video delay * Input: * unsigned char ucDolbyDelay: dolby mode * unsigned char ucTime1_msec: delay time * unsigned char ucTime2_msec: delay time * Output: * None. * Return: * STV82x8_I2C_ERROR = I2C's communication is failed. * STV82x8_INVALID_PARAM = Invalid params. * STV82X8_NO_ERROR = No error. ****************************************************************************************/ unsigned char STV82x8_SetAVDelay(unsigned char ucDolbyDelay, unsigned char ucTime1_msec, unsigned char ucTime2_msec ) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = STV82x8_DataMaskWrite( AV_DELAY_CONFIG, STV82x8_AV_DELAY_OFF, STV82X8_AV_DELAY_ON_MASK ); if((( ucDolbyDelay == STV82X8_DolbyDelay_On ) && ( (ucTime1_msec + ucTime2_msec) > STV82x8_DolbyOn_MAX_VALUE )) || (( ucDolbyDelay == STV82X8_DolbyDelay_Off ) && ( (ucTime1_msec + ucTime2_msec) > STV82x8_DolbyOff_MAX_VALUE ))) return ( STV82X8_INVALID_PARAM ); ucResult = STV82x8_DataMaskWrite( AV_DELAY_CONFIG, ucDolbyDelay, STV82X8_DOLBY_DELAY_ON_MASK ); ucResult |= I2cWriteSTV82x8( AV_DELAY_TIME_LS, ucTime1_msec ); ucResult |= I2cWriteSTV82x8( AV_DELAY_TIME_HP, ucTime2_msec ); ucResult |= STV82x8_DataMaskWrite( AV_DELAY_CONFIG, STV82x8_AV_DELAY_ON, STV82X8_AV_DELAY_ON_MASK ); return(ucResult); } /********************************************************************************** * Function: * unsigned char STV82x8_SetDefaultValueFromSTDConfig(VOID) * Description: * Set standard value * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. *********************************************************************************/ unsigned char STV82x8_SetDefaultValueFromSTDConfig(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = I2cWriteSTV82x8( CETH1_REG, 0x10 ); ucResult |= I2cWriteSTV82x8( SQTH1, 0x70 ); ucResult |= I2cWriteSTV82x8( SAP_LEVEL_H, 0x80 ); ucResult |= I2cWriteSTV82x8( SAP_LEVEL_L, 0x60 ); ucResult |= I2cWriteSTV82x8( PLL_P_GAIN, 0x82 ); ucResult |= I2cWriteSTV82x8( SAP_SQ_TH, 0x20 ); ucResult |= I2cWriteSTV82x8( BTSC_FINE_PRESCAL_ST, 0x5C ); ucResult |= I2cWriteSTV82x8( BTSC_FINE_PRESCAL_SAP, 0xC4 ); return(ucResult); } /********************************************************************************** * Function: * unsigned char STV82x8_SetValueForSPDIF(VOID) * Description: * Set vaule for SPDIF * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. *********************************************************************************/ unsigned char STV82x8_SetValueForSPDIF(VOID) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = I2cWriteSTV82x8( 0x5B, 0x0d ); ucResult |= STV82x8_DataMaskWrite( 0x80, 0x04, 0x04 ); Delay_msec(2); ucResult |= I2cWriteSTV82x8( 0xF5, 0x00 ); Delay_msec(2); return(ucResult); } /********************************************************************************** * Function: * unsigned char STV82x8_SAPConfig() * Description: * Set if SAP selected for second channel * Input: * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. *********************************************************************************/ unsigned char STV82x8_SAPConfig(unsigned char bSAP) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = I2cWriteSTV82x8( SAP_CONF, bSAP ); return(ucResult); } /************************************************************************************ * Function: * unsigned char STV82x8_DataMaskWrite(unsigned char ucADDRESS, unsigned char ucDATA, unsigned char ucMASK_DATA ) * Description: * I2C_DREAD * Input: * unsigned char ucADDRESS: register addr * unsigned char ucDATA: data to write * unsigned char ucMASK_DATA: mask * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. ***********************************************************************************/ unsigned char STV82x8_DataMaskWrite(unsigned char ucADDRESS, unsigned char ucDATA, unsigned char ucMASK_DATA ) { unsigned char ucRegValue=0, ucResult = STV82X8_NO_ERROR; ucResult = I2cReadSTV82x8(ucADDRESS, &ucRegValue ); ucRegValue &= ~ucMASK_DATA; ucRegValue |= ucDATA; ucResult = I2cWriteSTV82x8(ucADDRESS, ucRegValue ); return(ucResult); } /************************************************************************************ * Function: * unsigned char I2cWriteSTV82x8(unsigned char ucSubAddress, unsigned char ucData) * Description: * Write I2C data * Input: * unsigned char ucSubAddress: I2C sub address * unsigned char ucData: data * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. ***********************************************************************************/ unsigned char I2cWriteSTV82x8(unsigned char ucSubAddress, unsigned char ucData) { INT nRet = SUCCESS; CHAR sub[4],buf[4]; unsigned char ucResult = STV82X8_NO_ERROR; struct i2c_iic_data i2cMsg; #if (BOARD_TYPE==BOARD_DDM70) return ucResult; #endif sub[0] = ucSubAddress; buf[0] = ucData; i2cMsg.addr = gSlaveAddr >> 1; i2cMsg.sub_addr_len = 1; i2cMsg.psub_addr = sub; i2cMsg.data_len = 1; i2cMsg.buf = buf; nRet = ioctl(gSTV82x8_i2cfd, I2C_DWRITE, &i2cMsg); if(nRet < 0) { TRACE0(("I2C write failed, write count mismatch\n")); ucResult = STV82X8_I2C_ERROR; } return(ucResult); } /************************************************************************************ * Function: * unsigned char I2cReadSTV82x8(unsigned char ucSubAddress, unsigned char * pucData ) * Description: * Read I2C data * Input: * unsigned char ucSubAddress: I2C sub address * unsigned char * pucData: data buffer * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. ***********************************************************************************/ unsigned char I2cReadSTV82x8(unsigned char ucSubAddress, unsigned char * pucData ) { INT nRet = SUCCESS; CHAR sub[4]; unsigned char ucResult = STV82X8_NO_ERROR; struct i2c_iic_data i2cMsg; #if (BOARD_TYPE==BOARD_DDM70) return ucResult; #endif sub[0] = ucSubAddress; i2cMsg.addr = gSlaveAddr >> 1; i2cMsg.sub_addr_len = 1; i2cMsg.psub_addr = sub; i2cMsg.data_len = 1; i2cMsg.buf = pucData; nRet = ioctl(gSTV82x8_i2cfd, I2C_DREAD, &i2cMsg); if(nRet < 0) { TRACE0(("I2C read failed, read count mismatch\n")); ucResult = STV82X8_I2C_ERROR; } return ucResult; } void get_stv(int addr) { unsigned char ret; unsigned char data; ret = I2cReadSTV82x8( (unsigned char)addr, &data ); if ( ret == STV82X8_NO_ERROR ) printf("|%s| ADDR=0x%x, DATA=0x%x\n", __FUNCTION__, addr, data); else printf("|%s| ERROR, LINE=%d\n", __FUNCTION__, __LINE__); } void PrintSTV82x8Config(void) { int i; for(i=0; i<256; i++) get_stv(i); } void set_stc(int addr, int data) { get_stv(addr); if ( I2cWriteSTV82x8(addr, data) != STV82X8_NO_ERROR ) printf("|%s| ERROR, LINE=%d\n", __FUNCTION__, __LINE__); else get_stv(addr); } /********************************************************************************** * Function: * unsigned char STV82x8_SetAutoMuteOnOff(unsigned char ucOnOff) * Description: * Set output channel automatically mute when no signal or not * Input: * ucOnOff: ON = 1 = Set output channel automatically mute when no signal * OFF = 0 = Output channels are never mutted * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. *********************************************************************************/ unsigned char STV82x8_SetAutoMuteOnOff(unsigned char ucOnOff) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if(ucOnOff == ON) { ucResult = STV82x8_DataMaskWrite( AUTOSTD_CTRL, AUTOSTD_CTRL_AUTO_MUTE_ON, AUTOSTD_CTRL_AUTO_MUTE_MASK ); } else { ucResult = STV82x8_DataMaskWrite( AUTOSTD_CTRL, AUTOSTD_CTRL_AUTO_MUTE_OFF, AUTOSTD_CTRL_AUTO_MUTE_MASK ); } return (ucResult); } /********************************************************************************** * Function: * unsigned char STV82x8_SetMuteAll(BOOL bMute) * Description: * Set all outputs, DIGITAL, SPDIF, DAC and SCART to mute or unmute state * Input: * bMute: ON = 1 = Mute the output * OFF = 0 = Unmute the output * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. *********************************************************************************/ unsigned char STV82x8_SetMuteAll(BOOL bMute) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if(bMute) { ucResult = STV82x8_SetDigitalMute(STV82x8_MUTE_ALL_OUTPUT, STV82x8_ALL_OUTPUT_MASK); ucResult |= STV82x8_SetDACMute(); } else { ucResult |= STV82x8_SetDACUnMute(); ucResult |= STV82x8_SetDigitalUnMute(STV82x8_UNMUTE_ALL_OUTPUT, STV82x8_ALL_OUTPUT_MASK); } return(ucResult); } /********************************************************************************** * Function: * unsigned char STV82x8_SetLoudSpkHeadPhoneGain(unsigned char ucType, unsigned char ucGain) * Description: * Set standard bass gain from -12db to +12 db * Input: * unsigned char ucType: * LS_BASS_GAIN: LoudSpeaker Bass Gain * LS_TREBLE_GAIN: LoudSpeaker Treble Gain * HP_BASS_GAIN: Headphone Bass Gain * HP_TREBLE_GAIN: HeadPphone Treble Gain * unsigned char ucGain: gain in db * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. * STV82X8_INVALID_PARAM = invalid parameter *********************************************************************************/ unsigned char STV82x8_SetLoudSpkHeadPhoneGain(unsigned char ucType, unsigned char ucGain) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif // ucResult = STV82x8_DataMaskWrite ( LS_EQ_BT_CTRL, STV82X8_TREBLE_ON, STV82X8_EQUALIZE_MASK ); //Josie 8/21 if( (LS_BASS_GAIN <= ucType) && (ucType <= HP_TREBLE_GAIN) ) ucResult = I2cWriteSTV82x8(ucType, BASS_TREBLE_GAIN_TABLE[ucGain]); else ucResult = STV82X8_INVALID_PARAM; return(ucResult); } /********************************************************************************* * Function: * unsigned char STV82x8_SetSoundMode(unsigned char uSoundMode) * Description: * The function will set sound mode manually * Input: * unsigned char uSoundMode: MONO, STEREO, SAP, or SAP_STEREO * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. ********************************************************************************/ unsigned char STV82x8_SetSoundSystem(unsigned char ucSound) { unsigned char ucResult = STV82X8_NO_ERROR; unsigned char ucSoundMode = MONO_CHECK; unsigned char ucChannelMatrix = BYPASS; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif switch(ucSound) { case STEREO: ucSoundMode |= STEREO_CHECK; break; case SAP: ucChannelMatrix = RIGHT_ONLY; ucSoundMode |= SAP_CHECK; break; case SAP_STEREO: ucSoundMode |= (SAP_CHECK | STEREO_CHECK); break; case MONO: ucChannelMatrix = LEFT_ONLY; break; default: break; } ucResult = STV82x8_Control_ChannelMatrixLS(ucChannelMatrix); ucResult |= STV82x8_DataMaskWrite(AUTOSTD_CTRL, ucSoundMode, STEREO_CHECK|MONO_CHECK|SAP_CHECK); return(ucResult); } /********************************************************************************* * Function: * unsigned char STV82x8_WideSurroundMode(unsigned char ucWideSRSMode) * Description: * The function will set sound mode manually * Input: * unsigned char uWideSRSMode: * ST_WIDE_SURROUND_OFF, ST_WIDE_SURROUND_MONO, ST_WIDE_SURROUND_STEREO * ST_WIDE_SURROUND_MOVIE, ST_WIDE_SURROUND_MUSIC * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. ********************************************************************************/ unsigned char STV82x8_WideSurroundMode(unsigned char ucWideSRSMode) { unsigned char ucResult = STV82X8_NO_ERROR; unsigned char ucSRSMode = ST_SURROUND_STEREO | ST_SURROUND_ON; unsigned char ucMask = ST_SURROUND_ON_OFF_MASK; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif switch(ucWideSRSMode) { case ST_WIDE_SURROUND_MONO_MODE: ucSRSMode = ST_SURROUND_MONO | ST_SURROUND_ON; ucMask = ST_SURROUND_ON_OFF_MASK | ST_SURROUND_MONO_STEREO_MASK ; break; case ST_WIDE_SURROUND_STEREO_MODE: ucSRSMode = ST_SURROUND_STEREO | ST_SURROUND_ON; ucMask = ST_SURROUND_ON_OFF_MASK | ST_SURROUND_MONO_STEREO_MASK; break; case ST_WIDE_SURROUND_MOVIE_MODE: ucSRSMode = ST_SURROUND_MOVIE | ST_SURROUND_ON; ucMask = ST_SURROUND_ON_OFF_MASK | ST_SURROUND_MOVIE_MUSIC_MASK; break; case ST_WIDE_SURROUND_MUSIC_MODE: ucSRSMode = ST_SURROUND_MUSIC | ST_SURROUND_ON; ucMask = ST_SURROUND_ON_OFF_MASK | ST_SURROUND_MOVIE_MUSIC_MASK; break; case ST_WIDE_SURROUND_OFF_MODE: default: ucSRSMode = ST_SURROUND_OFF; ucMask = ST_SURROUND_ON_OFF_MASK; break; } ucResult = STV82x8_DataMaskWrite(STSRND_CONTROL, ucSRSMode, ucMask); return ucResult; } /********************************************************************************* * Function: * unsigned char STV82x8_DialogClarityLevel(unsigned char ucLevel) * Description: * The function will set DialogClarityLevel * Input: * unsigned char ucLevel: 0 - 255 : 0db to -127.5db * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. ********************************************************************************/ unsigned char STV82x8_DialogClarityLevel(unsigned char ucLevel) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult |= I2cWriteSTV82x8(TRUSRND_DC_ELEVATION, ucLevel); return ucResult; } /********************************************************************************* * Function: * unsigned char STV82x8_SRSTruBaseLoudspeakerHeadphoneLevel(unsigned char ucTrubassType, unsigned char ucLevel) * Description: * The function will set LS or Headphone Trubass level * Input: * unsigned char ucTrubassType: TRUBASS_LS_LEVEL or TRUBASS_HP_LEVEL * unsigned char ucLevel: 0 - 255 : 0db to -127.5db * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. ********************************************************************************/ unsigned char STV82x8_SRSTruBaseLoudspeakerHeadphoneLevel(unsigned char ucTrubassType, unsigned char ucLevel) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = I2cWriteSTV82x8(ucTrubassType, ucLevel); return ucResult; } /********************************************************************************* * Function: * unsigned char STV82x8_AuxVolSelection(unsigned char ucAuxSel) * Description: * Select the output on wihci the AUX_VOLUME values wil be applied * Input: * ucAuxSel: 00: No volume applied * 01: Volume applied to SCART1 ouput (SELECT_SCART_1) * 10: Volume applied to SCART2 ouput (SELECT_SCART_2) * 11: not use * Output: * None * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. ********************************************************************************/ unsigned char STV82x8_AuxVolSelection(unsigned char ucAuxSel) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif ucResult = I2cWriteSTV82x8(AUX_VOL_INDEX, ucAuxSel); return ucResult; } /********************************************************************************* * Function: * unsigned char STV82x8_MuteSPDIF(BOOL bMute) * Description: * The STV support internal and external SPDIF; but mute function only work on * internal path; therefore, we mute first the switch to internal path. When unmute * we check the current audio matrix then set internal or external path accordingly. * Return: * STV82X8_I2C_ERROR = I2C's communication is failed. * STV82X8_NO_ERROR = Success. ********************************************************************************/ unsigned char STV82x8_MuteSPDIF(BOOL bMute) { unsigned char ucResult = STV82X8_NO_ERROR; unsigned char ucSPDIFMux = Internal_SPDIF; unsigned char ucMatrixValue = 0; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if(bMute) { STV82x8_SetSPDIFDigitalMute(); } else { ucResult |= I2cReadSTV82x8(AUDIO_MATRIX3_INPUT, &ucMatrixValue ); if( ((ucMatrixValue >> 3) & 0x07) == STV82X8_AUDIOINPUT_I2S ) ucSPDIFMux = External_SPDIF; STV82x8_SetSPDIFDigitalUnMute(); } STV82x8_Set_SPDIFOut(ucSPDIFMux, 0); return ucResult; } unsigned char PIO_SetLow( VOID ) { return STV82X8_NO_ERROR; } unsigned char PIO_SetHigh( VOID ) { return STV82X8_NO_ERROR; } /*********************************************************************************** // unsigned char STV82x8_Enble_Equalizer(BOOL bEnable, unsigned char ucType, unsigned char ucIndex ) // The function is for Equalizer and Truble function selection, it inculdes data setting // ucType : type of LS_EQ_BAND(EQUALIZER_100HZ,EQUALIZER_330HZ, EQUALIZER_1KHZ, EQUALIZER_3P3KHZ,EQUALIZER_10KHZ) // or BASS_TREBLE(LS_BASS_GAIN, LS_TREBLE_GAIN, HP_BASS_GAIN, HP_TREBLE_GAIN) // ucIndex : index of Equalizer_Table or BASS_TREBLE_GAIN_TABLE ***********************************************************************************/ unsigned char STV82x8_Enble_Equalizer(unsigned char ucOnOff, unsigned char ucType, unsigned char ucIndex ) { unsigned char ucResult = STV82X8_NO_ERROR; #ifdef __STV_DEBUG__ STV_FUNCTION; #endif if (ucOnOff==ON){ ucResult = STV82x8_DataMaskWrite ( LS_EQ_BT_CTRL, STV82X8_EQUALIZE_ON, STV82X8_EQUALIZE_MASK );// Josie 8/21 ucResult = STV82x8_SetEqualizerValue(ucType, ucIndex ); return ( ucResult ); } else{ ucResult = STV82x8_DataMaskWrite ( LS_EQ_BT_CTRL, STV82X8_TREBLE_ON, STV82X8_EQUALIZE_MASK ); //Josie 8/21 ucResult = STV82x8_SetLoudSpkHeadPhoneGain( ucType, ucIndex); return(ucResult); } } /******************************************************************************************** * End Of File ********************************************************************************************/ int STV82x8_EXT_SetPrescale(STPrescaleInput_e STInput, int PrescaleValue) { CONFINE(PrescaleValue, 0, 0x7f); switch(STInput) { case _ST_PRESCALE_MONO_: STV82x8_DataMaskWrite(PRESCALE_MONO, PrescaleValue, PRESCALE_MONO_MASK); break; case _ST_PRESCALE_STEREO_: STV82x8_DataMaskWrite(PRESCALE_STEREO, PrescaleValue, 0x7f); break; case _ST_RRESCALE_SAP_: STV82x8_DataMaskWrite(PRESCALE_SAP, PrescaleValue, 0x7f); break; case _ST_PRESCALE_SIF_: STV82x8_DataMaskWrite(PRESCALE_MONO, PrescaleValue, PRESCALE_MONO_MASK); STV82x8_DataMaskWrite(PRESCALE_STEREO, PrescaleValue, 0x7f); STV82x8_DataMaskWrite(PRESCALE_SAP, PrescaleValue, 0x7f); break; case _ST_PRESCALE_SCART_: STV82x8_DataMaskWrite(PRESCALE_SCART, PrescaleValue, PRESCALE_MONO_MASK); break; case _ST_PRESCALE_I2S_: STV82x8_DataMaskWrite(PRESCALE_I2S_0, PrescaleValue, 0x7f); STV82x8_DataMaskWrite(PRESCALE_I2S_1, PrescaleValue, 0x7f); STV82x8_DataMaskWrite(PRESCALE_I2S_2, PrescaleValue, 0x7f); break; case _ST_PRESCALE_I2S_0_: STV82x8_DataMaskWrite(PRESCALE_I2S_0, PrescaleValue, 0x7f); break; case _ST_PRESCALE_I2S_1_: STV82x8_DataMaskWrite(PRESCALE_I2S_1, PrescaleValue, 0x7f); break; case _ST_PRESCALE_I2S_2_: STV82x8_DataMaskWrite(PRESCALE_I2S_2, PrescaleValue, 0x7f); break; default: break; } return SUCCESS; } int STV82x8_EXT_SetScartOutputPath(STAudioScartInput_e STScartInput, STAudioScartOutput_e STScartOutput) { switch(STScartOutput) { case _ST_SCART_OUTPUT_1_: switch(STScartInput) { case _ST_SCART_INPUT_DSP_: STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x00, 0x07); break; case _ST_SCART_INPUT_MONO_: STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x01, 0x07); break; case _ST_SCART_INPUT_1_: STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x02, 0x07); break; case _ST_SCART_INPUT_2_: STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x03, 0x07); break; case _ST_SCART_INPUT_3_: STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x04, 0x07); break; case _ST_SCART_INPUT_4_: STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x05, 0x07); break; default: break; } break; case _ST_SCART_OUTPUT_2_: switch(STScartInput) { case _ST_SCART_INPUT_DSP_: STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x00<<4, 0x07<<4); break; case _ST_SCART_INPUT_MONO_: STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x01<<4, 0x07<<4); break; case _ST_SCART_INPUT_1_: STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x02<<4, 0x07<<4); break; case _ST_SCART_INPUT_2_: STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x03<<4, 0x07<<4); break; case _ST_SCART_INPUT_3_: STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x04<<4, 0x07<<4); break; case _ST_SCART_INPUT_4_: STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, 0x05<<4, 0x07<<4); break; default: break; } break; case _ST_SCART_OUTPUT_3_: switch(STScartInput) { case _ST_SCART_INPUT_DSP_: STV82x8_DataMaskWrite(SCART3_OUTPUT_CTRL, 0x00, 0x07); break; case _ST_SCART_INPUT_MONO_: STV82x8_DataMaskWrite(SCART3_OUTPUT_CTRL, 0x01, 0x07); break; case _ST_SCART_INPUT_1_: STV82x8_DataMaskWrite(SCART3_OUTPUT_CTRL, 0x02, 0x07); break; case _ST_SCART_INPUT_2_: STV82x8_DataMaskWrite(SCART3_OUTPUT_CTRL, 0x03, 0x07); break; case _ST_SCART_INPUT_3_: STV82x8_DataMaskWrite(SCART3_OUTPUT_CTRL, 0x04, 0x07); break; case _ST_SCART_INPUT_4_: STV82x8_DataMaskWrite(SCART3_OUTPUT_CTRL, 0x05, 0x07); break; default: break; } break; case _ST_SCART_OUTPUT_ADC_: STV82x8_DataMaskWrite(ADC_CTRL, 0x08, 0x08); switch(STScartInput) { case _ST_SCART_INPUT_1_: STV82x8_DataMaskWrite(ADC_CTRL, 0x00, 0x07); break; case _ST_SCART_INPUT_2_: STV82x8_DataMaskWrite(ADC_CTRL, 0x01, 0x07); break; case _ST_SCART_INPUT_3_: STV82x8_DataMaskWrite(ADC_CTRL, 0x02, 0x07); break; case _ST_SCART_INPUT_4_: STV82x8_DataMaskWrite(ADC_CTRL, 0x03, 0x07); break; case _ST_SCART_INPUT_MONO_: STV82x8_DataMaskWrite(ADC_CTRL, 0x04, 0x07); break; default: break; } break; } return SUCCESS; } int STV82x8_EXT_SetAudioOutputPath(STAudioInput_e STInput, STAudioOutput_e STOutput) { SAINT_CHECK((STInput>_ST_INPUT_INVALID_) && (STInput<_ST_INPUT_MAX_), FAILED); if(STInput == _ST_INPUT_I2S_) STV82x8_EXT_PowerOffADC(); else STV82x8_EXT_PowerOnADC(); switch(STOutput) { case _ST_OUTPUT_LOUDSPEAKER_: STV82x8_DataMaskWrite(AUDIO_MATRIX1_INPUT, STInput, STV82X8_MATRIX1_INPUT_MASK); break; case _ST_OUTPUT_HEADPHONE_: STV82x8_DataMaskWrite(AUDIO_MATRIX1_INPUT, STInput<<3, STV82X8_MATRIX1_INPUT_MASK<<3); break; case _ST_OUTPUT_SCART1_: STV82x8_DataMaskWrite(AUDIO_MATRIX2_INPUT, STInput, STV82X8_MATRIX1_INPUT_MASK); break; case _ST_OUTPUT_SCART2_: STV82x8_DataMaskWrite(AUDIO_MATRIX2_INPUT, STInput<<3, STV82X8_MATRIX1_INPUT_MASK<<3); break; case _ST_OUTPUT_DELAY_: STV82x8_DataMaskWrite(AUDIO_MATRIX3_INPUT, STInput, STV82X8_MATRIX1_INPUT_MASK); break; case _ST_OUTPUT_SPDIF_: STV82x8_DataMaskWrite(AUDIO_MATRIX3_INPUT, STInput<<3, STV82X8_MATRIX1_INPUT_MASK<<3); break; default: break; } return SUCCESS; } static int SavedVolumeMode[5] = {DIFFERENTIAL_MODE, DIFFERENTIAL_MODE, DIFFERENTIAL_MODE, DIFFERENTIAL_MODE, DIFFERENTIAL_MODE}; int STV82x8_EXT_SetVolumeMode(STAudioVolumeModeDev_e AudioDev, int VolumeMode) { SAINT_CHECK((VolumeMode == DIFFERENTIAL_MODE) || (VolumeMode == INDEPENDANT_MODE), FAILED); switch(AudioDev) { case _ST_VOLUME_MODE_LS_: if(INDEPENDANT_MODE == VolumeMode) STV82x8_DataMaskWrite(VOLUME_MODES, 0x0<<0, 0x1<<0); else STV82x8_DataMaskWrite(VOLUME_MODES, 0x1<<0, 0x1<<0); break; case _ST_VOLUME_MODE_SRND_: if(INDEPENDANT_MODE == VolumeMode) STV82x8_DataMaskWrite(VOLUME_MODES, 0x0<<1, 0x1<<1); else STV82x8_DataMaskWrite(VOLUME_MODES, 0x1<<1, 0x1<<1); break; case _ST_VOLUME_MODE_HP_: if(INDEPENDANT_MODE == VolumeMode) STV82x8_DataMaskWrite(VOLUME_MODES, 0x0<<2, 0x1<<2); else STV82x8_DataMaskWrite(VOLUME_MODES, 0x1<<2, 0x1<<2); break; case _ST_VOLUME_MODE_SCART1_: if(INDEPENDANT_MODE == VolumeMode) STV82x8_DataMaskWrite(VOLUME_MODES, 0x0<<3, 0x1<<3); else STV82x8_DataMaskWrite(VOLUME_MODES, 0x1<<3, 0x1<<3); break; case _ST_VOLUME_MODE_SCART2_: if(INDEPENDANT_MODE == VolumeMode) STV82x8_DataMaskWrite(VOLUME_MODES, 0x0<<4, 0x1<<4); else STV82x8_DataMaskWrite(VOLUME_MODES, 0x1<<4, 0x1<<4); break; default: break; } SavedVolumeMode[AudioDev] = VolumeMode; return SUCCESS; } int STV82x8_EXT_SetVolume(STAudioVolumeDev_e AudioDev, int Volume) { CONFINE(Volume, 0, 0x3ff); LOG(0, " My real Volume:%d\n", Volume); switch(AudioDev) { case _ST_VOLUME_LS_L_: I2cWriteSTV82x8(LS_L_VOLUME_MSB, Volume >> NORMAL_VOLUME_SHIFT); I2cWriteSTV82x8(LS_L_VOLUME_LSB, Volume & VOLUME_LSB_MASK); break; case _ST_VOLUME_LS_R_: I2cWriteSTV82x8(LS_R_VOLUME_MSB, Volume >> NORMAL_VOLUME_SHIFT); I2cWriteSTV82x8(LS_R_VOLUME_LSB, Volume & VOLUME_LSB_MASK); break; //In differential mode, Left channel means the volume, Right Channel means balance case _ST_VOLUME_LS_: I2cWriteSTV82x8(LS_L_VOLUME_MSB, Volume >> NORMAL_VOLUME_SHIFT); I2cWriteSTV82x8(LS_L_VOLUME_LSB, Volume & VOLUME_LSB_MASK); break; case _ST_VOLUME_LS_C_: I2cWriteSTV82x8(LS_C_VOLUME_MSB, Volume >> NORMAL_VOLUME_SHIFT); I2cWriteSTV82x8(LS_C_VOLUME_LSB, Volume & VOLUME_LSB_MASK); break; case _ST_VOLUME_LS_SUB_: I2cWriteSTV82x8(LS_SUB_VOLUME_MSB, Volume >> NORMAL_VOLUME_SHIFT); I2cWriteSTV82x8(LS_SUB_VOLUME_LSB, Volume & VOLUME_LSB_MASK); break; case _ST_VOLUME_MASTER_: I2cWriteSTV82x8(LS_MASTER_VOLUME_MSB, Volume >> NORMAL_VOLUME_SHIFT); I2cWriteSTV82x8(LS_MASTER_VOLUME_LSB, Volume & VOLUME_LSB_MASK); break; case _ST_VOLUME_LS_SL_: I2cWriteSTV82x8(LS_SL_VOLUME_MSB, Volume >> NORMAL_VOLUME_SHIFT); I2cWriteSTV82x8(LS_SL_VOLUME_LSB, Volume & VOLUME_LSB_MASK); break; case _ST_VOLUME_LS_SR_: I2cWriteSTV82x8(LS_SR_VOLUME_MSB, Volume >> NORMAL_VOLUME_SHIFT); I2cWriteSTV82x8(LS_SR_VOLUME_LSB, Volume & VOLUME_LSB_MASK); break; //In differential mode, Left channel means the volume, Right Channel means balance case _ST_VOLUME_LS_SURROUND_: I2cWriteSTV82x8(LS_SL_VOLUME_MSB, Volume >> NORMAL_VOLUME_SHIFT); I2cWriteSTV82x8(LS_SL_VOLUME_LSB, Volume & VOLUME_LSB_MASK); break; case _ST_VOLUME_HP_L_: I2cWriteSTV82x8(HP_L_VOL_MSB, Volume >> NORMAL_VOLUME_SHIFT); I2cWriteSTV82x8(HP_L_VOL_LSB, Volume & VOLUME_LSB_MASK); break; case _ST_VOLUME_HP_R_: I2cWriteSTV82x8(HP_R_VOL_MSB, Volume >> NORMAL_VOLUME_SHIFT); I2cWriteSTV82x8(HP_R_VOL_LSB, Volume & VOLUME_LSB_MASK); break; //In differential mode, Left channel means the volume, Right Channel means balance case _ST_VOLUME_HP_: I2cWriteSTV82x8(HP_L_VOL_MSB, Volume >> NORMAL_VOLUME_SHIFT); I2cWriteSTV82x8(HP_L_VOL_LSB, Volume & VOLUME_LSB_MASK); break; case _ST_VOLUME_SCART1_L_: //Set Aux index to scart 1 STV82x8_DataMaskWrite(AUX_VOL_INDEX, 0x1, 0x3); I2cWriteSTV82x8(AUX_L_VOL_MSB, Volume >> NORMAL_VOLUME_SHIFT); I2cWriteSTV82x8(AUX_L_VOL_LSB, Volume & VOLUME_LSB_MASK); break; case _ST_VOLUME_SCART1_R_: //Set Aux index to scart 1 STV82x8_DataMaskWrite(AUX_VOL_INDEX, 0x1, 0x3); I2cWriteSTV82x8(AUX_R_VOL_MSB, Volume >> NORMAL_VOLUME_SHIFT); I2cWriteSTV82x8(AUX_R_VOL_LSB, Volume & VOLUME_LSB_MASK); break; //For differential mode case _ST_VOLUME_SCART1_: //Set Aux index to scart 1 STV82x8_DataMaskWrite(AUX_VOL_INDEX, 0x1, 0x3); I2cWriteSTV82x8(AUX_L_VOL_MSB, Volume >> NORMAL_VOLUME_SHIFT); I2cWriteSTV82x8(AUX_L_VOL_LSB, Volume & VOLUME_LSB_MASK); break; case _ST_VOLUME_SCART2_L_: //Set Aux index to scart 2 STV82x8_DataMaskWrite(AUX_VOL_INDEX, 0x2, 0x3); I2cWriteSTV82x8(AUX_L_VOL_MSB, Volume >> NORMAL_VOLUME_SHIFT); I2cWriteSTV82x8(AUX_L_VOL_LSB, Volume & VOLUME_LSB_MASK); break; case _ST_VOLUME_SCART2_R_: //Set Aux index to scart 2 STV82x8_DataMaskWrite(AUX_VOL_INDEX, 0x2, 0x3); I2cWriteSTV82x8(AUX_R_VOL_MSB, Volume >> NORMAL_VOLUME_SHIFT); I2cWriteSTV82x8(AUX_R_VOL_LSB, Volume & VOLUME_LSB_MASK); break; //For differential mode case _ST_VOLUME_SCART2_: //Set Aux index to scart 2 STV82x8_DataMaskWrite(AUX_VOL_INDEX, 0x2, 0x3); I2cWriteSTV82x8(AUX_L_VOL_MSB, Volume >> NORMAL_VOLUME_SHIFT); I2cWriteSTV82x8(AUX_L_VOL_LSB, Volume & VOLUME_LSB_MASK); break; default: break; } return SUCCESS; } int STV82x8_EXT_SetBalance(STAudioVolumeDev_e AudioDev, int Balance) { CONFINE(Balance, 0, 0x3ff); if(Balance == 0x200) Balance = 0; else if(Balance < 0x200) Balance = Balance + 0x200;// 0x200-->0x3ff else Balance = Balance - 0x200;// 0x1-->0x1ff //here we need to convert Balance value to register value switch(AudioDev) { case _ST_VOLUME_LS_: I2cWriteSTV82x8(LS_R_VOLUME_MSB, Balance >> NORMAL_BALANCE_SHIFT); I2cWriteSTV82x8(LS_R_VOLUME_LSB, Balance & BALANCE_LSB_MASK); break; case _ST_VOLUME_HP_: I2cWriteSTV82x8(HP_R_VOL_MSB, Balance >> NORMAL_BALANCE_SHIFT); I2cWriteSTV82x8(HP_R_VOL_LSB, Balance & BALANCE_LSB_MASK); break; case _ST_VOLUME_LS_SURROUND_: I2cWriteSTV82x8(LS_SR_VOLUME_MSB, Balance >> NORMAL_BALANCE_SHIFT); I2cWriteSTV82x8(LS_SR_VOLUME_LSB, Balance & BALANCE_LSB_MASK); break; case _ST_VOLUME_SCART1_: //Set Aux index to scart 1 STV82x8_DataMaskWrite(AUX_VOL_INDEX, 0x1, 0x3); I2cWriteSTV82x8(AUX_R_VOL_MSB, Balance >> NORMAL_BALANCE_SHIFT); I2cWriteSTV82x8(AUX_R_VOL_LSB, Balance & BALANCE_LSB_MASK); break; case _ST_VOLUME_SCART2_: //Set Aux index to scart 2 STV82x8_DataMaskWrite(AUX_VOL_INDEX, 0x2, 0x3); I2cWriteSTV82x8(AUX_R_VOL_MSB, Balance >> NORMAL_BALANCE_SHIFT); I2cWriteSTV82x8(AUX_R_VOL_LSB, Balance & BALANCE_LSB_MASK); break; default: break; } return SUCCESS; } int STV82x8_EXT_SetMute(STAudioMuteDev_e AudioDev, BOOL bMute) { unsigned char MuteValue; MuteValue = bMute?1:0; switch (AudioDev) { case _ST_SOFTMUTE_LS_: STV82x8_DataMaskWrite(MUTE_DIGITAL, MuteValue << 0, (0x01<<0)); break; case _ST_SOFTMUTE_CENTER_: STV82x8_DataMaskWrite(MUTE_DIGITAL, MuteValue << 1, (0x01<<1)); break; case _ST_SOFTMUTE_SUB_: STV82x8_DataMaskWrite(MUTE_DIGITAL, MuteValue << 2, (0x01<<2)); break; case _ST_SOFTMUTE_SRND_: STV82x8_DataMaskWrite(MUTE_DIGITAL, MuteValue << 3, (0x01<<3)); break; case _ST_SOFTMUTE_SCART1_: STV82x8_DataMaskWrite(MUTE_DIGITAL, MuteValue << 4, (0x01<<4)); break; case _ST_SOFTMUTE_SCART2_: STV82x8_DataMaskWrite(MUTE_DIGITAL, MuteValue << 5, (0x01<<5)); break; case _ST_SOFTMUTE_SPDIF_: STV82x8_DataMaskWrite(MUTE_DIGITAL, MuteValue << 6, (0x01<<6)); break; case _ST_SOFTMUTE_HP_: STV82x8_DataMaskWrite(MUTE_DIGITAL, MuteValue << 7, (0x01<<7)); break; //Adjust in F7 case _ST_DACMUTE_LSLR_: STV82x8_DataMaskWrite(DAC_CTRL, MuteValue << 1, (0x01<<1)); break; case _ST_DACMUTE_CSUB_: STV82x8_DataMaskWrite(DAC_CTRL, MuteValue << 2, (0x01<<2)); break; case _ST_DACMUTE_SHP_: STV82x8_DataMaskWrite(DAC_CTRL, MuteValue << 3, (0x01<<3)); break; case _ST_DACMUTE_SCART_: STV82x8_DataMaskWrite(DAC_CTRL, MuteValue << 4, (0x01<<4)); break; case _ST_OUTPUT_SCART1_MUTE_: STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, MuteValue << 3, (0x01<<3)); break; case _ST_OUTPUT_SCART2_MUTE_: STV82x8_DataMaskWrite(SCART1_2_OUTPUT_CTRL, MuteValue << 7, (0x01<<7)); break; case _ST_OUTPUT_SCART3_MUTE_: STV82x8_DataMaskWrite(SCART3_OUTPUT_CTRL, MuteValue << 3, (0x01<<3)); break; default: break; } return 0; } int STV82x8_EXT_PowerOffADC(void) { unsigned char ucRegVal; I2cReadSTV82x8( ADC_CTRL, &ucRegVal ); if(( ucRegVal & STV82X8_ADC_WAKEUP_MASK ) == 1 ) { STV82x8_DataMaskWrite(ADC_CTRL, 0x00, 0x08); usleep( 500 ); //35ms } return SUCCESS; } int STV82x8_EXT_PowerOnADC(void) { unsigned char ucRegVal; I2cReadSTV82x8( ADC_CTRL, &ucRegVal ); if(( ucRegVal & STV82X8_ADC_WAKEUP_MASK ) == 0 ) { STV82x8_DataMaskWrite(ADC_CTRL, 0x08, 0x08); usleep( 500 ); //35ms } return SUCCESS; } int STV82x8_EXT_SetSPDIFExtInput(BOOL bExtSrc) { if(bExtSrc) STV82x8_DataMaskWrite(DAC_CTRL, 0x20, 0x20); else { STV82x8_DataMaskWrite(CHANNEL_MATRIX_LS, 0x40, 0x40); STV82x8_DataMaskWrite(DAC_CTRL, 0x00, 0x20); } return SUCCESS; } int STV82x8_EXT_EnableLSEqualizerBassTreble(BOOL bEnable) { if(bEnable) STV82x8_DataMaskWrite(LS_EQ_BT_CTRL, 0x01, 0x01); else STV82x8_DataMaskWrite(LS_EQ_BT_CTRL, 0x00, 0x01); return SUCCESS; } int STV82x8_EXT_EnableLSEqualizer(BOOL bEnable) { if(bEnable) STV82x8_DataMaskWrite(LS_EQ_BT_CTRL, 0x00, 0x02); else STV82x8_DataMaskWrite(LS_EQ_BT_CTRL, 0x02, 0x02); return SUCCESS; } int STV82x8_EXT_EnableLSBassTreble(BOOL bEnable) { if(bEnable) STV82x8_DataMaskWrite(LS_EQ_BT_CTRL, 0x02, 0x02); else STV82x8_DataMaskWrite(LS_EQ_BT_CTRL, 0x00, 0x02); return SUCCESS; } int STV82x8_EXT_EnableHPBassTreble(BOOL bEnable) { if(bEnable) STV82x8_DataMaskWrite(LS_EQ_BT_CTRL, 0x04, 0x04); else STV82x8_DataMaskWrite(LS_EQ_BT_CTRL, 0x00, 0x04); return SUCCESS; } int STV82x8_EXT_SetBass(int Value, BOOL bHP) { CONFINE(Value, 0, 0xff); //Convert Value to register value if(Value >= 0xD0) Value = Value - 0xD0 + 1; // 0x00-->0x30 else Value = 0xD0 - Value; // 0x1-->0xD0 if(bHP) I2cWriteSTV82x8(HP_BASS_GAIN, Value); else I2cWriteSTV82x8(LS_BASS_GAIN, Value); return SUCCESS; } int STV82x8_EXT_SetTreble(int Value, BOOL bHP) { CONFINE(Value, 0, 0xff); //Convert Value to register value if(Value >= 0xD0) Value = Value - 0xD0 + 1; // 0x00-->0x30 else Value = 0xD0 - Value; // 0x1-->0xd0 if(bHP) I2cWriteSTV82x8(HP_TREBLE_GAIN, Value); else I2cWriteSTV82x8(LS_TREBLE_GAIN, Value); return SUCCESS; } int STV82x8_EXT_SetLSEqulizer(int BandIndex, int Value) { SAINT_CHECK((BandIndex>=0) && (BandIndex<5), FAILED); CONFINE(Value, 0, 0xff); //Convert Value to register value if(Value >= 0xD0) Value = Value - 0xD0 + 1; // 0x00-->0x30 else Value = 0xD0 - Value; // 0xd0-->0x00 I2cWriteSTV82x8(LS_EQ_BAND + BandIndex, Value); return SUCCESS; } int STV82x8_EXT_GetSoundSystem_Independ(unsigned char * pucSoundSystem, BOOL bDetectFM) { unsigned char ucRegValue, ucSTSoundID; if(bDetectFM) { STV82x8_GetSoundSignalState( &ucRegValue ); if( ucRegValue == STV82X8_SOUNDSIGNAL_UNLOCKED ) { *pucSoundSystem = MONO; return ( STV82X8_RESOURCE_ERROR ); } } I2cReadSTV82x8( AUTOSTD_DEM_STATUS, &ucRegValue ); ucSTSoundID = ( ucRegValue & STV82X8_AUTOSTD_DEM_STATUS_MASK ); if ( ucSTSoundID == (STV82X8_LCK_DET | STV82X8_ST_DET | STV82X8_SAP_SQ | STV82X8_SAP_DET) ) *pucSoundSystem = SAP_STEREO; else if ( (ucSTSoundID & (STV82X8_SAP_SQ | STV82X8_SAP_DET)) == (STV82X8_SAP_SQ | STV82X8_SAP_DET)) *pucSoundSystem = SAP; else if ( (ucSTSoundID & (STV82X8_LCK_DET | STV82X8_ST_DET)) == (STV82X8_LCK_DET | STV82X8_ST_DET)) *pucSoundSystem = STEREO; else *pucSoundSystem = MONO; return(SUCCESS); } unsigned char STV82x8_EXT_OpenDevice(unsigned char ucSubAddr, int I2CMasterNum) { INT nRet; unsigned char ucResult = STV82X8_NO_ERROR; gSlaveAddr = ucSubAddr; SAINT_CHECK((I2CMasterNum == 1) || (I2CMasterNum == 2), STV82X8_I2C_ERROR); // check for I2C file descriptor for audio device if(gSTV82x8_i2cfd) return ucResult; if(I2CMasterNum == 1) gSTV82x8_i2cfd = open("/dev/i2c-0", O_RDWR); else gSTV82x8_i2cfd = open("/tmp/i2c-1", O_RDWR); if(gSTV82x8_i2cfd<0) { gSTV82x8_i2cfd = 0; TRACE0(("Open I2c device failed\n")); return STV82X8_I2C_ERROR; } printf("OPEN SUCCESS\n"); // can we communicate with the device ? if((nRet = ioctl(gSTV82x8_i2cfd, I2C_SLAVE, ucSubAddr>>1)) < 0) { close(gSTV82x8_i2cfd); gSTV82x8_i2cfd = 0; TRACE0(("Open I2C IOCTL failed\n")); return STV82X8_I2C_ERROR; } return ucResult; } void STV82x8_EXT_InitializeThread(void* arg) { unsigned char ucResult = STV82X8_NO_ERROR; if (ucResult == STV82X8_NO_ERROR) { if(STV82x8_UpdatePatchData()) { TRACE0(("UpdatePatchData Failed\n")); return;// STV82X8_I2C_ERROR; } if(STV82x8_InitDSP()) { TRACE0(("InitDSP Failed\n")); return;// STV82X8_I2C_ERROR; } if(STV82x8_InitRegister()) { TRACE0(("InitRegister Failed\n")); return;// STV82X8_I2C_ERROR; } if(STV82x8_SetI2SInOut( STV82X8_I2S_OUTPUT )) //Reg 01 { TRACE0(("SetI2SInOut Failed\n")); return;// STV82X8_I2C_ERROR; } if(STV82x8_SetI2SOutputSignal( STV82X8_I2S_OUTPUT_LR )) //Reg 56 { TRACE0(("SetI2SOutputSignal Failed\n")); return;// STV82X8_I2C_ERROR; } // do SAP/Stereo/Mono check if(STV82x8_All_SoundSystem_Check()) { TRACE0(("STV82x8_All_SoundSystem_Check\n")); return;// STV82X8_I2C_ERROR; } STV82x8_SetSubWoofer(STV82x8_SUBWOOFER_ON, STV82x8_BASSMNGT_ON, STV82x8_GAINSW_ON, STV82x8_STLFEAdd_ON, STV82x8_DolbyPro_OFF, STV82x8_BASSCONFI_0); STV82x8_EXT_SetMute(_ST_SOFTMUTE_LS_, 1); STV82x8_EXT_SetVolume(_ST_VOLUME_LS_, 0); STV82x8_EXT_SetVolume(_ST_VOLUME_MASTER_, 0x3ff); } return; } //static pthread_t stv82x8_init_thread = 0; unsigned char STV82x8_EXT_Initialize(STAudioDrvInitParam* pInit) { unsigned char ucResult = STV82X8_NO_ERROR; if(STV82x8_EXT_OpenDevice(pInit->SlaveAddr, pInit->I2CMasterNum)) return STV82X8_I2C_ERROR; ucResult = STV82x8_SwReset(); // if(pInit->bThreadInit) // pthread_create(&stv82x8_init_thread, NULL, STV82x8_EXT_InitializeThread, NULL); // else STV82x8_EXT_InitializeThread(NULL); return ucResult; }