📄 v46x_common.c.bak
字号:
/**--------------------------------------------------------------------------
* Name V46X_Common.c
--------------------------------------------------------------------------**/
#include <string.h>
#include "..\inc\public2.h"
#include "Font12x18.C"
unsigned char _Volume = 0xFF;
unsigned char _Hue = 0xFF;
extern BYTE Source_type;
extern code BYTE OSD_Table_Title[20];
code BYTE OSDCtrlVal_Title[10] =
{ // Index
0x00, //H Start
0x00, //V Start
0x00, //H Width
0x00, //V Height
0x00, //H Space Start position & H Mirror
0x00, //V Space Start position & V Mirror
0x00, //H Space Width
0x00, //V Space Heigth
0xA6, //Ctrl. Reg
0x98 //Misc. Ctrl
};
code BYTE OSDCtrlVal[10] =
{ // Index
0x00, //H Start
0x00, //V Start
0x00, //H Width
0x00, //V Height
0x00, //H Space Start position & H Mirror
0x00, //V Space Start position & V Mirror
0x00, //H Space Width
0x00, //V Space Heigth
0x06, //Ctrl. Reg
0x98 //Misc. Ctrl
};
/**--------------------------------------------------------------------------
* Name BYTE CVD1_ReadWrite(BYTE wr_type, BYTE addr, BYTE value)
* BYTE wr_type; //0x00: for read value from Reg.
* //0x01: for write value to Reg.
* BYTE addr; //which on Reg. will read/write
* BYTE value; //buffer for read/write
*
* Description TV Decoder is indirect Reg. in V465.
* There are 2Reg. one for TV Decoder addr port (0xF0)
* other for TV Decoder data port (0xF1)
* This function usages by I2C
* Flow Chart
*
* Return None
*
* DATE Author Description
* ===========================================================================
**/
BYTE CVD1_ReadWrite(BYTE wr_type, BYTE addr, BYTE value)
{
I2C_WriteByte(V462_WRID, 0xF0, addr); //Set Address
//Set/Get Data value
if (wr_type)
I2C_WriteByte(V462_WRID, 0xF1, value);
else
value = I2C_ReadByte(V462_WRID, 0xF1);
return(value);
}
void Clr_OSDCode()
{
I2C_WriteByte(V462_WRID, ORWCTRL, 0x40); //Clear OSD buffer
}
/**--------------------------------------------------------------------------
* Name Read_OSDReg(BYTE *buf, BYTE rd_type, BYTE count, BYTE addr)
* BYTE *buf store read data from registers.
* BYTE rd_type read type 0:OSD Control registers.
* 1:OSD RAM font <not support don't set>
* 2:OSD display code
* 3:OSD display attribute
* BYTE count number of byte for read in this times
* BYTE addr begin of address index
* Description Read data from Internal OSD
*
* Flow Chart
*
* Return *str reading data buffer
*
* DATE Author Description
* ===========================================================================
* 2004-07-12 K.M. Ho This is first time implement
* 2004-10-12 KMHo Del the OSD enable
**/
void Read_OSDReg(BYTE *buf, BYTE rd_type, BYTE count, BYTE addr)
{
BYTE i, offset;
I2C_WriteByte(V462_WRID, ORWCTRL, rd_type|0xA0);
I2C_WriteByte(V462_WRID, OSDADDR_L, addr);
I2C_WriteByte(V462_WRID, OSDADDR_H, 0x00);
if (rd_type)
{ // Support Display code and attribute Read
for(offset=0,i=0; i<count; i++, offset+=2)
{ //not Support RAM font read
*(buf+offset) = I2C_ReadByte(V462_WRID, OSDDATA_L);
*(buf+offset+1) = I2C_ReadByte(V462_WRID, OSDDATA_H);
}
}
else
for(i=0; i<count; i++) //OSD Control Reg. read
*(buf+i) = I2C_ReadByte(V462_WRID, OSDDATA_L);
I2C_WriteByte(V462_WRID, ORWCTRL, 0x04); //Disable OSD Reg. Read/Write
}
/**--------------------------------------------------------------------------
* Name Write_OSDReg(BYTE *buf, BYTE wr_type, BYTE count, BYTE begin_addr)
* BYTE *buf buffer for write.
* BYTE wr_type write type 0:OSD Control registers.
* 1:OSD RAM font
* 2:OSD display code
* 3:OSD display attribute
* BYTE count number of byte for write in this times
* BYTE addr begin of address index
*
* Description Write data buffer to internal OSD Reg
*
* Flow Chart
*
* Return None
*
* DATE Author Description
* ===========================================================================
* 2004-07-12 K.M. Ho This is first time implement
* 2004-10-12 KMHo Del the OSD enable
**/
void Write_OSDReg(BYTE buf[], BYTE wr_type, BYTE count, BYTE addr)
{
BYTE i,j;
int offset;
I2C_WriteByte(V462_WRID, ORWCTRL, wr_type|0x80);
I2C_WriteByte(V462_WRID, OSDADDR_L, addr);
I2C_WriteByte(V462_WRID, OSDADDR_H, 0x00);
switch(wr_type)
{
case 0x00: //0x00 OSD Control Reg.
for (i=0; i<count; i++) //Write data to OSD Control Reg
I2C_WriteByte(V462_WRID, OSDDATA_L, buf[i]);
break;
case 0x01: //0x01 OSD Font table RAM
for (offset=0,i=0; i<count; i++) //character count
for (j=0; j<18; j++) //Write a character to 15xx Font Table RAM
{
I2C_WriteByte(V462_WRID, OSDDATA_L, buf[offset]);
I2C_WriteByte(V462_WRID, OSDDATA_H, buf[offset+1]);
offset += 2;
}
break;
case 0x02: //0x02 OSD Display code buffer
for (offset=0,i=0; i<count; i++, offset+=2)
{
I2C_WriteByte(V462_WRID, OSDDATA_L, buf[offset]);
I2C_WriteByte(V462_WRID, OSDDATA_H, buf[offset+1]);
}
break;
case 0x03: //0x03 OSD Display attribute buffer
for (offset=0,i=0; i<count; i++, offset+=2)
{ //Write data to OSD Control Reg or Attribute
I2C_WriteByte(V462_WRID, OSDDATA_L, buf[offset]);
I2C_WriteByte(V462_WRID, OSDDATA_H, buf[offset+1]);
}
break;
}
I2C_WriteByte(V462_WRID, ORWCTRL, 0x04); //Disable OSD Reg. Read/Write
}
/**--------------------------------------------------------------------------
* Name OSD_Attribute(BYTE item, BYTE length, BYTE attr_color)
*
* Description Write OSD Attribute Reg.
* bit 7 6 5 4 3 2 1 0 //Low byte: background color select
* bit F E D C B A 9 8 //Hi byte: foreground color select
* Flow Chart
*
* Return
*
* DATE Author Description
* ===========================================================================
* 2004-07-12 K.M. Ho This is first time implement
* 2005-01-28 KMHo Modify to V465 Attribute 2bytes in each char
* 2005-09-12 Microntrk Modified
**/
void OSD_Attribute(BYTE addr, BYTE length, BYTE FG_color, BYTE BG_color)
{
BYTE i;
I2C_WriteByte(V46X_WRID, ORWCTRL, 0x83);
I2C_WriteByte(V46X_WRID, OSDADDR_L, addr);
I2C_WriteByte(V46X_WRID, OSDADDR_H, 0x00);
for (i=0; i<length; i++)
{ //Write data to OSD Control Reg or Attribute
I2C_WriteByte(V46X_WRID, OSDDATA_L, BG_color);
I2C_WriteByte(V46X_WRID, OSDDATA_H, FG_color);
}
I2C_WriteByte(V46X_WRID, ORWCTRL, 0x04); //Disable OSD Reg. Read/Write
}
void Write_OSDCode(BYTE buf[], BYTE width, BYTE hight, BYTE addr)
{
BYTE i, offset;
I2C_WriteByte(V462_WRID, ORWCTRL, 0x82);
I2C_WriteByte(V462_WRID, OSDADDR_L, addr);
I2C_WriteByte(V462_WRID, OSDADDR_H, 0x00);
for (i=0; i <width*hight; i++)
{
/*
if ( !Vertical && !Horizontal )
offset = i;
else if ( !Vertical && Horizontal )
offset = (i/width)*width + width - 1 - i%width;
else if ( Vertical && !Horizontal )
offset = (hight - 1 - i/width)*width + i%width;
else
offset = (hight - 1 - i/width)*width + width -1 - i%width;
*/
offset = i;
I2C_WriteByte(V462_WRID, OSDDATA_L, buf[offset]);
I2C_WriteByte(V462_WRID, OSDDATA_H, 0x04);
}
I2C_WriteByte(V462_WRID, ORWCTRL, 0x04); //Disable OSD Reg. Read/Write
}
void Show_Subwin(BYTE subwin)
{
BYTE buf[2];
Subwin = subwin;
buf[0] = Subwin;
buf[1] = Subwin;
buf[2] = Subwin;
Write_OSDReg(buf, SEL_OSDCTRLREG, 3, 0x14);
}
void OSD_SubWin_Attr(BYTE subwin, BYTE hstart, BYTE vstart, BYTE width, BYTE hight, BYTE cstart)
{
BYTE buf[8];
buf[0] = hstart * 3 + 0x25;
buf[1] = width - 1;
buf[2] = (unsigned int)vstart * 18 / 4;
buf[3] = hight - 1;
buf[4] = 0x00;
buf[5] = 0x00;
buf[6] = 0x00;
buf[7] = cstart;
Write_OSDReg(buf, SEL_OSDCTRLREG, 8, 0x20+subwin*8); // init OSD sub Win X
}
void Set_VideoPP(BYTE video_pp)
{
video_pp = 0;
switch (video_pp)
{
case 0 :
Brightness = S_Brightness;
Contrast = S_Contrast;
Saturation = S_Saturation;
Sharpen = S_Sharpen;
break;
case 1 :
Brightness = 0x1D;
Contrast = 0x1D;
Saturation = 0x20;
Sharpen = 0x1A;
break;
case 2 :
Brightness = 0x1D;
Contrast = 0x1D;
Saturation = 0x18;
Sharpen = 0x1A;
break;
case 3 :
Brightness = 0x1D;
Contrast = 0x1D;
Saturation = 0x24;
Sharpen = 0x1A;
break;
case 4 :
Brightness = 0x20;
Contrast = 0x20;
Saturation = 0x20;
Sharpen = 0x1A;
break;
}
Adj_Brightness(Brightness);
Adj_Contrast(Contrast);
Adj_Saturation(Saturation);
Adj_Sharpen(Sharpen);
}
void Adj_Volume(BYTE volume)
{
if (_Volume == volume )
return;
_Volume = volume;
/*
if ( volume == 0 )
volume = 0xFF;
else
volume = (50 - volume) * 2 ;
*/
if ( volume == 0 )
PWM_VOLUME = 0;
else
PWM_VOLUME = volume*2.5+126;
}
void Adj_Brightness(BYTE value)
{
char i;
if ( Source_type == TV_CHL )
value+=5;
value = value * 2 + 0xA0 - 50;
for (i=0; i<3; i++)
I2C_WriteByte(V462_WRID, i+0x10, value);
}
void Adj_Contrast(BYTE value)
{
char i;
value = value * 2 + 0x58 - 50;
for (i=0; i<3; i++)
I2C_WriteByte(V462_WRID, i+0x0D, value);
}
void Adj_Saturation(BYTE value)
{
if ( value <= 25 )
value = value*5;
else
value = (value-25)*2+125;
I2C_WriteByte(V462_WRID, 0x13, value);
}
void Adj_Sharpen(char value)
{
BYTE va, vb;
value = value*2+30;
if (value & 0x40)
{
value = (value - 0x40) << 1; //value is plus
va = 0xFF - value + 1;
vb = value + 64;
}
else
{
value = 0x40 - value; //value is minus
va = value;
vb = 64 - value;
}
I2C_WriteByte(V462_WRID, 0x1E, va);
I2C_WriteByte(V462_WRID, 0x1F, vb);
I2C_WriteByte(V462_WRID, 0x20, va);
}
void Adj_Hue(char value)
{
if ( _Hue == value )
return;
_Hue = value;
value *= 2;
value -= 50;
I2C_WriteByte(V462_WRID, 0x14, value);
}
void V46X_Init()
{
PanelOFF;
SYS_RST=1; // V462 reset
Delay(10000);
SYS_RST=0; // V462 reset
Delay(10000);
SYS_RST=1;
Delay(8000);
V46X_RegInit();
SETCKH;
ScreenOFF;
CVD1OFF; //Reset TV-Decoder
CVD1ON; //
// PanelON;
I2C_WriteByte(V462_WRID, ORWCTRL, CLR_OSD_BUF); //Clear OSD buffer
/*
Write_OSDReg(OSDCtrlVal_Title, SEL_OSDCTRLREG, 10, 0); //write 10 byte
OSD_SubWin_Attr(7,0,5,10,1,0); //Display '***' in Subwin 7
Write_OSDCode(UserOSD, 10, 1, 0); //Write OSD Code buffer
OSD_Attribute(0, 10, FG_COLOR_H, BG_COLOR); //Set Title line attribute
Show_Subwin(0x80);
*/
// V46X_Gamma_Init();
Write_OSDReg(&Font12x18[0], 0x01, 64, 0x00); //Write Font code
Show_Subwin(0x00);
Write_OSDReg(OSDCtrlVal, SEL_OSDCTRLREG, 10, 0); //write 10 byte
// PanelON;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -