📄 tuner.c.txt
字号:
#include <ipOS.h>
#include "ip2022.h"
#include "7121.h"
#include "intel_bus_module.h"
void _I2C_Set_SCLK_LOW()
{
pin_dir_out(I2CS_VP_SCL_PORT,I2CS_VP_SCL_PIN);
pin_low(I2CS_VP_SCL_PORT, I2CS_VP_SCL_PIN);
}
void _I2C_Set_SCLK_HIGH()
{
pin_dir_out(I2CS_VP_SCL_PORT,I2CS_VP_SCL_PIN);
pin_high(I2CS_VP_SCL_PORT, I2CS_VP_SCL_PIN);
}
void _I2C_Set_SDAT_LOW()
{
pin_dir_out(I2CS_VP_SDA_PORT,I2CS_VP_SDA_PIN);
pin_low(I2CS_VP_SDA_PORT, I2CS_VP_SDA_PIN);
}
void _I2C_Set_SDAT_HIGH()
{
pin_dir_out(I2CS_VP_SDA_PORT,I2CS_VP_SDA_PIN);
pin_high(I2CS_VP_SDA_PORT, I2CS_VP_SDA_PIN);
}
bool_t _I2C_Get_SDAT(void) // reading this pin's state and ack
{
pin_dir_in(I2CS_VP_SDA_PORT,I2CS_VP_SDA_PIN);
return read_pin(I2CS_VP_SDA_PORT, I2CS_VP_SDA_PIN);
}
void wait1(u16_t counttime)
{
u16_t i;
for(i = 0;i<counttime;i++);
}
void I2cWait()
{
for(u16_t i=0;i<7;i++) //24.5
{
for(u16_t j=0;j<2000;j++)
{
;
}
}
}
void I2cStart(void)
{
_I2C_Set_SDAT_HIGH();
_I2C_Set_SCLK_HIGH();
I2cWait();
_I2C_Set_SDAT_LOW();
I2cWait();
_I2C_Set_SCLK_LOW();
I2cWait();
}
void I2cStop(void)
{
_I2C_Set_SCLK_HIGH();
I2cWait();
_I2C_Set_SDAT_LOW();
I2cWait();
_I2C_Set_SDAT_HIGH();
}
unsigned char I2cSentbyte(unsigned char bytedata)
{
u8_t i,ack=0x01;
for(i = 0; i < 8; i++) // Send all bits: 8 bits
{
if((bytedata&0x80)==0x80)
{
_I2C_Set_SDAT_HIGH();
}
else
{
_I2C_Set_SDAT_LOW();
}
I2cWait();
I2cWait();
I2cWait();
_I2C_Set_SCLK_HIGH();
I2cWait();
I2cWait();
bytedata = (bytedata << 1) ;
_I2C_Set_SCLK_LOW();
}
I2cWait();
I2cWait();
_I2C_Set_SDAT_HIGH();
I2cWait();
_I2C_Set_SCLK_HIGH();
I2cWait();
I2cWait();
ack=_I2C_Get_SDAT();
I2cWait();
I2cWait();
_I2C_Set_SCLK_LOW();
I2cWait();
I2cWait();
I2cWait();
return ack;
}
unsigned char I2cReceivebyte(void)
{
u8_t i,bytedata=0x00;
for(i=0;i<8;i++)
{
_I2C_Set_SCLK_HIGH();
I2cWait();
I2cWait();
I2cWait();
bytedata=(bytedata<<1);
if(_I2C_Get_SDAT()) bytedata=(bytedata|0x01);
_I2C_Set_SCLK_LOW();
I2cWait();
I2cWait();
}
return bytedata;
}
void SendAcknowledge(unsigned char ack)
{
_I2C_Set_SDAT_HIGH();
_I2C_Set_SCLK_HIGH();
I2cWait();
_I2C_Set_SCLK_LOW();
}
void I2cbytewrite2(u8_t subaddr,unsigned char address,unsigned char bytedata)
{
unsigned char i,ack=0x01;
I2cWait();
for(i=0;i<10;i++)
{
I2cStart();
ack=I2cSentbyte(subaddr);
if(ack==0x01)
{
I2cStop();
continue;
}
ack=I2cSentbyte(address);
if(ack==0x01)
{
I2cStop();
continue;
}
ack=I2cSentbyte(bytedata);
if(ack==0x01)
{
I2cStop();
continue;
}
wait1(240); //240
I2cStop();
wait1(240);
if(ack==0x00)
break;
}
}
void I2cbytewrite3(u8_t subaddr,unsigned char address,unsigned char *bytedata,u8_t size)
{
unsigned char i,ack=0x01;
I2cWait();
for(i=0;i<10;i++)
{
I2cStart();
ack=I2cSentbyte(subaddr);
if(ack==0x01)
{
I2cStop();
continue;
}
ack=I2cSentbyte(address);
if(ack==0x01)
{
I2cStop();
continue;
}
do{
ack=I2cSentbyte(*bytedata++);
if(ack==0x01)
{
I2cStop();
continue;
}
}while(--size!=0);
wait1(240); //240
I2cStop();
wait1(240);
if(ack==0x00)
break;
}
}
// saa7115_composite_ntsc_i2c_table (Philips Video Decoder)
/*u8_t config_i2c_table3[] = {
0x01,0x08,0x02,0xC4,0x03,0x33,0x04,0x00,0x05,0x00,0x06,0xEB,0x07,0xE0,0x08,0xB0,
0x09,0x40,0x0A,0x88,0x0B,0x44,0x0C,0x40,0x0D,0x00,0x0E,0x8D,0x0F,0x2A,0x10,0x06,
0x11,0x00,0x12,0x00,0x13,0x81,0x14,0x20,0x15,0x04,0x16,0x02,0x17,0x06,0x18,0x40,
0x19,0x80,0x1A,0x00,0x1B,0x42,0x1C,0x00,0x1D,0x00,0x30,0xCD,0x31,0x20,0x32,0x03,
0x33,0x00,0x34,0xCE,0x35,0xFB,0x36,0x30,0x37,0x00,0x38,0x01,0x39,0x20,0x3A,0x00,
0x40,0x00,0x41,0xff,0x42,0xff,0x43,0xff,0x44,0xff,0x45,0xff,0x46,0xff,0x47,0xff,
0x48,0xff,0x49,0xff,0x4a,0xff,0x4b,0xff,0x4c,0xff,0x4d,0xff,0x4e,0xff,0x4f,0xff,
0x50,0xff,0x51,0xff,0x52,0xff,0x53,0xff,0x54,0xff,0x55,0xff,0x56,0xff,0x57,0xff,
0x58,0x00,0x59,0x47,0x5a,0x06,0x5b,0x03,0x5c,0x00,0x5d,0x00,0x5e,0x00,0x5f,0x00,
0x60,0x00,0x63,0x00,0x64,0x00,0x65,0x00,0x67,0x00,0x68,0x00,0x80,0x10,0x81,0x00,
0x82,0x00,0x83,0x21,0x84,0x00,0x85,0x11,0x86,0x40,0x87,0x01,0x88,0xf0,0x90,0x00,
0x91,0x08,0x92,0x00,0x93,0x40,0x94,0x10,0x95,0x00,0x96,0xd0,0x97,0x02,0x98,0x16,
0x99,0x00,0x9a,0xf0,0x9b,0x00,0x9c,0x60,0x9d,0x01,0x9e,0xf0,0x9f,0x00,0xa0,0x02,
0xa1,0x02,0xa2,0xaa,0xa4,0x80,0xa5,0x40,0xa6,0x40,0xa8,0x18,0xa9,0x04,0xaa,0x00,
0xac,0x0c,0xad,0x02,0xae,0x00,0xb0,0x00,0xb1,0x04,0xb2,0x00,0xb3,0x04,0xb4,0x00,
0xb8,0x00,0xb9,0x00,0xba,0x00,0xbb,0x00,0xbc,0x00,0xbd,0x00,0xbe,0x00,0xbf,0x00,
0xc0,0x00,0xc1,0x08,0xc2,0x00,0xc3,0x80,0xc4,0x00,0xc5,0x00,0xc6,0xd0,0xc7,0x02,
0xc8,0x00,0xc9,0x00,0xca,0x06,0xcb,0x01,0xcc,0xd0,0xcd,0x02,0xce,0x06,0xcf,0x01,
0xd0,0x01,0xd1,0x00,0xd2,0x00,0xd4,0x80,0xd5,0x3f,0xd6,0x3f,0xd8,0x00,0xd9,0x04,
0xda,0x00,0xdc,0x00,0xdd,0x02,0xde,0x00,0xe0,0x00,0xe1,0x04,0xe2,0x00,0xe3,0x04,
0xe4,0x01,0xe8,0x00,0xe9,0x00,0xea,0x00,0xeb,0x00,0xec,0x00,0xed,0x00,0xee,0x00,
0xef,0x00,0x88,0xc0,0x88,0xf0
};*/
// saa7115_composite_pal_i2c_table (Philips Video Decoder)
u8_t config_i2c_table4[] = {
0x01,0x08,0x02,0xC4,0x03,0x33,0x04,0x00,0x05,0x00,0x06,0xEB,0x07,0xE0,0x08,0xB0,
0x09,0x41,0x0A,0x88,0x0B,0x44,0x0C,0x40,0x0D,0x00,0x0E,0x8D,0x0F,0x2A,0x10,0x06,
0x11,0x00,0x12,0x00,0x13,0x81,0x14,0x20,0x15,0x05,0x16,0x35,0x17,0x02,0x18,0x40,
0x19,0x80,0x1A,0x00,0x1B,0x42,0x1C,0x00,0x1D,0x00,0x30,0xCD,0x31,0x20,0x32,0x03,
0x33,0x00,0x34,0xCE,0x35,0xFB,0x36,0x30,0x37,0x00,0x38,0x01,0x39,0x20,0x3A,0x00,
0x40,0x00,0x41,0xff,0x42,0xff,0x43,0xff,0x44,0xff,0x45,0xff,0x46,0xff,0x47,0xff,
0x48,0xff,0x49,0xff,0x4a,0xff,0x4b,0xff,0x4c,0xff,0x4d,0xff,0x4e,0xff,0x4f,0xff,
0x50,0xff,0x51,0xff,0x52,0xff,0x53,0xff,0x54,0xff,0x55,0xff,0x56,0xff,0x57,0xff,
0x58,0x00,0x59,0x47,0x5a,0x06,0x5b,0x03,0x5c,0x00,0x5d,0x00,0x5e,0x00,0x5f,0x00,
0x60,0x00,0x63,0x00,0x64,0x00,0x65,0x00,0x67,0x00,0x68,0x00,0x80,0x10,0x81,0x00,
0x82,0x00,0x83,0x21,0x84,0x00,0x85,0x11,0x86,0x40,0x87,0x01,0x88,0xf0,0x90,0x00,
0x91,0x08,0x92,0x00,0x93,0x40,0x94,0x10,0x95,0x00,0x96,0xd0,0x97,0x02,0x98,0x16,
0x99,0x00,0x9a,0x20,0x9b,0x01,0x9c,0x60,0x9d,0x01,0x9e,0x20,0x9f,0x01,0xa0,0x02,
0xa1,0x02,0xa2,0xaa,0xa4,0x80,0xa5,0x40,0xa6,0x40,0xa8,0x18,0xa9,0x04,0xaa,0x00,
0xac,0x0c,0xad,0x02,0xae,0x00,0xb0,0x00,0xb1,0x04,0xb2,0x00,0xb3,0x04,0xb4,0x00,
0xb8,0x00,0xb9,0x00,0xba,0x00,0xbb,0x00,0xbc,0x00,0xbd,0x00,0xbe,0x00,0xbf,0x00,
0xc0,0x00,0xc1,0x08,0xc2,0x00,0xc3,0x80,0xc4,0x00,0xc5,0x00,0xc6,0xd0,0xc7,0x02,
0xc8,0x00,0xc9,0x00,0xca,0x06,0xcb,0x01,0xcc,0xd0,0xcd,0x02,0xce,0x06,0xcf,0x01,
0xd0,0x01,0xd1,0x00,0xd2,0x00,0xd4,0x80,0xd5,0x3f,0xd6,0x3f,0xd8,0x00,0xd9,0x04,
0xda,0x00,0xdc,0x00,0xdd,0x02,0xde,0x00,0xe0,0x00,0xe1,0x04,0xe2,0x00,0xe3,0x04,
0xe4,0x01,0xe8,0x00,0xe9,0x00,0xea,0x00,0xeb,0x00,0xec,0x00,0xed,0x00,0xee,0x00,
0xef,0x00,0x88,0xc0,0x88,0xf0
};
// saa7121_ntsc_i2c_table (Philips TV Output)
/*u8_t config_i2c_table5[] = {
0x00,0x00,0x01,0x00,0x02,0x00,0x03,0x00,0x04,0x00,0x05,0x00,0x06,0x00,0x07,0x00,
0x08,0x00,0x09,0x00,0x0a,0x00,0x0b,0x00,0x0c,0x00,0x0d,0x00,0x0e,0x00,0x0f,0x00,
0x10,0x00,0x11,0x00,0x12,0x00,0x13,0x00,0x14,0x00,0x15,0x00,0x16,0x00,0x17,0x00,
0x18,0x00,0x19,0x00,0x1a,0x00,0x1b,0x00,0x1c,0x00,0x1d,0x00,0x1e,0x00,0x1f,0x00,
0x20,0x00,0x21,0x00,0x22,0x00,0x23,0x00,0x24,0x00,0x25,0x00,0x26,0x00,0x27,0x00,
0x28,0x19,0x29,0x1d,0x2a,0x00,0x2b,0x00,0x2c,0x00,0x2d,0x00,0x2e,0x00,0x2f,0x00,
0x30,0x00,0x31,0x00,0x32,0x00,0x33,0x00,0x34,0x00,0x35,0x00,0x36,0x00,0x37,0x00,
0x38,0x00,0x39,0x00,0x3a,0x13,0x3b,0x00,0x3c,0x00,0x3d,0x00,0x3e,0x00,0x3f,0x00,
0x40,0x00,0x41,0x00,0x42,0x00,0x43,0x00,0x44,0x00,0x45,0x00,0x46,0x00,0x47,0x00,
0x48,0x00,0x49,0x00,0x4a,0x00,0x4b,0x00,0x4c,0x00,0x4d,0x00,0x4e,0x00,0x4f,0x00,
0x50,0x00,0x51,0x00,0x52,0x00,0x53,0x00,0x54,0x00,0x55,0x00,0x56,0x00,0x57,0x00,
0x58,0x00,0x59,0x00,0x5a,0x0c,0x5b,0x76,0x5c,0xa5,0x5d,0x2a,0x5e,0x2e,0x5f,0x2e,
0x60,0x00,0x61,0x15,0x62,0x3f,0x63,0x1f,0x64,0x7c,0x65,0xf0,0x66,0x21,0x67,0x55,
0x68,0x56,0x69,0x67,0x6a,0x58,0x6b,0x20,0x6c,0xf9,0x6d,0x00,0x6e,0x30,0x6f,0x14,
0x70,0x80,0x71,0xe8,0x72,0x10,0x73,0x42,0x74,0x03,0x75,0x03,0x76,0x05,0x77,0x16,
0x78,0x04,0x79,0x16,0x7a,0x00,0x7b,0x38,0x7c,0x40,0x7d,0x00,0x7e,0x00,0x7f,0x00,
0x00,0x00
};*/
// saa7121_pal_i2c_table (Philips TV Output)
u8_t config_i2c_table6[] = {
0x00,0x00,0x01,0x00,0x02,0x00,0x03,0x00,0x04,0x00,0x05,0x00,0x06,0x00,0x07,0x00,
0x08,0x00,0x09,0x00,0x0a,0x00,0x0b,0x00,0x0c,0x00,0x0d,0x00,0x0e,0x00,0x0f,0x00,
0x10,0x00,0x11,0x00,0x12,0x00,0x13,0x00,0x14,0x00,0x15,0x00,0x16,0x00,0x17,0x00,
0x18,0x00,0x19,0x00,0x1a,0x00,0x1b,0x00,0x1c,0x00,0x1d,0x00,0x1e,0x00,0x1f,0x00,
0x20,0x00,0x21,0x00,0x22,0x00,0x23,0x00,0x24,0x00,0x25,0x00,0x26,0x00,0x27,0x00,
0x28,0x21,0x29,0x1d,0x2a,0x00,0x2b,0x00,0x2c,0x00,0x2d,0x00,0x2e,0x00,0x2f,0x00,
0x30,0x00,0x31,0x00,0x32,0x00,0x33,0x00,0x34,0x00,0x35,0x00,0x36,0x00,0x37,0x00,
0x38,0x00,0x39,0x00,0x3a,0x13,0x3b,0x00,0x3c,0x00,0x3d,0x00,0x3e,0x00,0x3f,0x00,
0x40,0x00,0x41,0x00,0x42,0x00,0x43,0x00,0x44,0x00,0x45,0x00,0x46,0x00,0x47,0x00,
0x48,0x00,0x49,0x00,0x4a,0x00,0x4b,0x00,0x4c,0x00,0x4d,0x00,0x4e,0x00,0x4f,0x00,
0x50,0x00,0x51,0x00,0x52,0x00,0x53,0x00,0x54,0x00,0x55,0x00,0x56,0x00,0x57,0x00,
0x58,0x00,0x59,0x00,0x5a,0x0c,0x5b,0x7d,0x5c,0xaf,0x5d,0x23,0x5e,0x35,0x5f,0x35,
0x60,0x00,0x61,0x06,0x62,0x2f,0x63,0xcb,0x64,0x8a,0x65,0x09,0x66,0x2a,0x67,0x55,
0x68,0x56,0x69,0x67,0x6a,0x58,0x6b,0x20,0x6c,0x05,0x6d,0x20,0x6e,0x20,0x6f,0x14,
0x70,0x80,0x71,0xe8,0x72,0x10,0x73,0x42,0x74,0x03,0x75,0x03,0x76,0x05,0x77,0x16,
0x78,0x04,0x79,0x16,0x7a,0x00,0x7b,0x38,0x7c,0x40,0x7d,0x00,0x7e,0x00,0x7f,0x00,
0x00,0x00
};
void I2C_Init()
{
_I2C_Set_SCLK_HIGH();
I2cWait();
I2cWait();
_I2C_Set_SDAT_HIGH();
I2cWait();
I2cWait();
}
void Store_7114_PAL_RunConfig(unsigned char * ptrChar)
{
flash_erase(SAA7114_CFG_ADD, SAA7114_CFG_LEN);
flash_write(SAA7114_CFG_ADD, ptrChar, SAA7114_CFG_LEN);
}
void Get_7114_PAL_RunConfig(unsigned char * ptrChar)
{
flash_read(SAA7114_CFG_ADD, ptrChar, SAA7114_CFG_LEN);
}
void Store_7114_NTSC_RunConfig(unsigned char * ptrChar)
{
}
void saa7114_pal_config(void)
{
u8_t *p=NULL;
p=config_i2c_table4;
if(flash_read16(SAA7114_CFG_ADD)==0x0108)
{
Get_7114_PAL_RunConfig(p);
}
for(u8_t t=0;t<171;t++)
{
I2cbytewrite2(0x42,*p,*(p+1));
p=p+2;
}
}
void saa7114_ntsc_config(void)
{
/*u8_t *p=NULL;
p=config_i2c_table4;
for(u8_t t=0;t<171;t++)
{
I2cbytewrite2(0x42,*p,*(p+1));
p=p+2;
}*/
}
void Store_7121_PAL_RunConfig(unsigned char * ptrChar)
{
//flash_erase(SAA7114_CFG_ADD, SAA7114_CFG_LEN);
//flash_write(SAA7114_CFG_ADD, ptrChar, SAA7114_CFG_LEN);
}
void Store_7121_NTSC_RunConfig(unsigned char * ptrChar)
{
}
void saa7121_pal_config(void)
{
u8_t *p;
p=config_i2c_table6;
for(u8_t t=0;t<129;t++)
{
I2cbytewrite2(0x88,*p,*(p+1));
p=p+2;
}
}
void saa7121_ntsc_config(void)
{
/*u8_t *p=NULL;
p=config_i2c_table5;
for(u8_t t=0;t<129;t++)
{
I2cbytewrite2(0x88,*p,*(p+1));
p=p+2;
}*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -