📄 scalar.c
字号:
/*
********************************************************************************
*
* LCD控制程序
*
* 这是一个SCALAR的控制模块
*
* 文件名 : SCALAR.C
* 设计者 : Terry
********************************************************************************
* 功 能 描 述
*
********************************************************************************
*/
#include "global.h"
#include "panel.h"
#include "scalar.h"
#define REFCLK 12000
/*
********************************************************************************
* 这里定义的均是一些关键的数据
********************************************************************************
*/
#define CCR156 (PanelPadDrive>>8)|((Panel_Invert_DVS<<4)|(Panel_Invert_DHS<<5)|(Panel_Invert_DCLK<<6)|(Panel_Invert_DEN<<7))
#define CCR16A ((EN_SWAP_PORTAB<<4)|(EN_SWAP_PBBYTE<<3)|(EN_SWAP_PABYTE<<2)|(EN_SWAP_PBBIT<<1)|EN_SWAP_PABIT)
static void SarSetLvdsPLL(uint32 dclk);
static void SarGetSCRev(void);
void SarBF3Enable(bit bf);
void SarBF3Disable(bit bf);
void SarBF3EnBoard(bit bf);
void SarBF3DisBoard(bit bf);
uint32 xdata ulDotClk;
uint32 xdata ulHfreqCounter;
/*
********************************************************************************
* SCALAR的初始化数据表
********************************************************************************
*/
uint8 code postInitTab[]={
0x01, RegAddr(rP000),
0x91, //0x90, 置ADC Groud sampling enable为1,减少灰阶下的水波纹干扰,08-05-05 //chen
0x01, RegAddr(rP002), // ADC Test Control
0x05, //0x01, //08-05-08
0x01, RegAddr(rP1ED), // ADC带宽设置到最大
0x48, //SXGA: 08, WSXGA: 48 //08-05-08
0x01, RegAddr(rP1F1), // ADC Current Control
0x00, //SXGA: 2A, WSXGA: 00 //08-05-08 // ADC电流设置到最大
0x01, RegAddr(rP005),
0x00, //0x08, //08-05-08 // ADC测试用,意义不清楚
0x01, RegAddr(rP008),
0x00, // ADC通道及钳位选择
0x04, RegAddr(rP00D),
0xC0, // rP00D
0xFF, // rP00E ADC PLL Power-up Control
0x00, // rP00F Reserved
0x06, // rP010 Analog bandwidth select: 电流的设置还要取决于0x1ED的bit5
// 06(500MHz) 04(300MHz) 02(150MHz) 00(50MHz)
0x05, RegAddr(rP011),
0x72, //08-05-19 update //0x58, // rP011 SOG Clamping Control
0x85, //08-05-19 update //0x00,//0x9C, // rP012 SOG Slicer Control
0x03, // rP013 White Balance Control
0x70, //08-05-19 update //0x77, // rP014 水平的触发门限
0x00, // rP015 垂直的触发门限
// DVI Input Control
0x07, RegAddr(rP018),
B0000_0010,// // rP018
B0000_0000,// // rP019
0x00, // rP01A
0x00, // rP01B
0x00, // rP01C
0x01, // rP01D
0xB8, // rP01E
// Graphic Port Control
0x08, RegAddr(rP020),
//0xd1, // rP020 Graphic Port Control
0x51, // rP020 Graphic Port Control 不知道是否需要这样改
0x81, 0x81, // rP021, rP022 Clamp Pulse Begin and Width
0x00, // rP023 Digital Port Input Control
0x00, // rP024 保留寄存器
0x00, //0x47, // rP025 ADCLK Delay & Invert Control
0x80, // rP026 Data Delay & Swap Control
0x11, // rP027 Vsync and DE Delay
// 输入捕获接口的初始化, 初始化的是640 x 480的数据
0x0A, RegAddr(rP02E),
0xE0, 0x01, 0xE0, 0x01, // rP02E-rP031 Capture Vertical Begin for Odd or Even
0xE0, 0x01, 0x88, 0x00, // rP032-rP035
0x80, 0x02, // rP036, rP037 Capture Horizontal Width
0x08, RegAddr(rP04B),
0x77, 0x03, // rP04B, rP04C,
0xAC, 0x00, // rP04D, rP04E,
0x65, 0x01, // rP04F, rP050,
0xBE, 0x02, // rP051, rP052
// 原先设置成0x13的值会导致单像素垂直竖条画面有从左上到右下的暗带干扰,如果改成
// 0x00,0x01,0x02的值,甚者更大,但是太大的值则沟边太严重,看起来也并不是很好
0x02, RegAddr(rP060),
0x01,//0x13, // Back-end Horizontal Sharpness
// 2006/03/17, 将值由0x13改为0x02,bit4和bit6的值一旦选择上,那么在垂直竖条
// 画面时,移动鼠标会导致画面的亮度变化
0x0C, // Color Channel Select, 增益的控制方式也可以选择
0x03, RegAddr(rP064),
0x00, // rP064 Interpolation Control
0x00, // rP065 Gamma Control
0x04, // rP066 Back-end Vertical Sharpness
// Noise Reduction Filter Control
0x04, RegAddr(rP068),
0x7A, 0x15, 0x00, 0x33, // rP068-rP06B 这是NOvatek推荐的值
0x01, RegAddr(rP070),
0x30, // rP070 General Purpose Input Output
// PWM0,PWM1输出允许,VSO输出允许
0x07, RegAddr(rP072),
0x00, // rP072 Bypass Sync Control
0x00, // rP073
0x01, // rP074
0x00, // rP075
0x01, // rP076
0x00, // rP077
0x00, // rP078
// DDC通道的配置和PWM的配置(禁止DDC通道的作用)
0x02, RegAddr(rP07E),
B1001_1001, // rP07E PWM Control 1
B1100_0000, // rP07F PWM Control 2
0x01, RegAddr(rP0D6),
0xC0, // rP0D6 在规格书中是一个保留寄存器
////////////////////////////////////////////////////////////////////////
0x05, RegAddr(rP390),
0x0F, // rP390 Bright Frame Windows Border control
0xFF, 0x00, 0x00, // rP391,rP392,rP393 Bright Frame Border color control
0x07, // rP394 Bright Frame Border enable control
0x01, RegAddr(rP3A0),
0x10,
0x01, RegAddr(rP3C0),
0x7C,
/////////////////////////////////////////////////////////////////////////
0x01, RegAddr(rP150),
CCR150, // rP150 Display General Control
0x06, RegAddr(rP154),
0x02, // rP154 Display Mute and Color Control
PanelPadDrive & 0xFF, // rP155 Display Drive Control,这里的值是IC的默认值
CCR156, // rP156 Display Drive and Polarity Control
PanelClockDelay, //08-05-19 update //0x40 | PanelClockDelay, // rP157 Display Clock and Data Delay Control
0x31, // rP158 Display Dithering Control
0xA0, // rP159 Display Channel Select, 这里选这正常输出
// Display Port Control
// 其实对于初始化而言,这组值并不是很重要,也可以不设置。
0x1C, RegAddr(rP15B), // 0x1C, (rP15B>>8) & 0x03, rP15B & 0xFF,
// 对Htotal,Vtotal以及同步脉冲宽度的设置
PanelTypVTotal, PanelTypVTotal>>8, // rP15B, rP15C
PanelMinVSyncWidth, // rP15D
//PanelTypHTotal, PanelTypHTotal>>8, // rP15E, rP15F
PanelMinHTotal, PanelMinHTotal>>8, // rP15E, rP15F
PanelMinHSyncWidth, // rP160
0x00, // rP161 这是保留寄存器
// 对背景窗口的设置
PanelVActiveStart, PanelVActiveStart>>8, // rP162, rP163
PanelHeight, PanelHeight>>8, // rP164, rP165
PanelHActiveStart, PanelHActiveStart>>8, // rP166, rP167
PanelWidth, PanelWidth>>8, // rP168, rP169
// 杂项控制
CCR16A, // rP16A, A口B口交换,RGB/BGR交换,高6位和低6位交换的设置
0x00, 0x00, 0x00, // rP16B, rP16C, rP16D 背景颜色设置
0x06, // rP16E Graphic Display Active Windows Control
// 对可显示窗口的设置
PanelVActiveStart, PanelVActiveStart>>8, // rP16F, rP170
PanelHeight, PanelHeight>>8, // rP171, rP172
PanelHActiveStart, PanelHActiveStart>>8, // rP173, rP174
PanelWidth, PanelWidth>>8, // rP175, rP176
0x02, RegAddr(rP179),
PanelTypHTotal, PanelTypHTotal>>8, // rP179, rP17A
#if PanelShortHsync
0x01, RegAddr(rP186),
0x13, // rP186
#endif
// FIFO 控制
0x03, RegAddr(rP18D),
0x00, // rP18D Residual DHS Average Increament
0x03, // rP18E Clear FIFO interrupt
0x00, // rP18F Disable FIFO interrupt
0x02, RegAddr(rP1B8),
(LVDS_POL_SWAP+LVDS_CH_SWAP+LVDS_LEVEL+LVDS_ICO)&0xf9|0x04, // rP1B8 LVDS Output Control
0x00, // rP1B9 Timing Controller disable
0x01, RegAddr(rP1EF),
0x04, // 保留寄存器,厂家推荐值 08-05-09
////////////////////////////////////////////////////////////////////////////////
0x03, RegAddr(rP1BD),
0x7E,
0x10, //rP1BE
0x7E, //rP1BF
0x01, RegAddr(rP1D8),
0x0A,
//0x01, RegAddr(rP1F7),
// 0x25,
0x04, RegAddr(rP1F5), // 08-05-09
0x00, //0x46, //08-05-19 update //rP1F5
0x00, //rP1F6
0x25, //rP1F7
0x20, //rP1F8
0x01, RegAddr(rP1FA),
0x40,
// 展频控制,在EMI测试中有用
0x01, RegAddr(rP0F5),
PanelSpreadCtrl + EN_PanelSpread,
0, // 如果记录长度为0, 那么表示数据表结束
};
/*
********************************************************************************
* 函 数 名: RegDataTableOut
* 功能描述: 将寄存器数据表的数据输出到Scalar的寄存器中,数据表的格式
* 第一个自己是输出的个数,第二字节是寄存器地址,紧接的是输出
* 的数据。在该表中可以放入多个这样的子表,如果数据个数为-1
* 则表示数据表结束。
* 输 入: 寄存器数据表的指针
* 返 回: 无
********************************************************************************
*/
void RegDataTableOut(uint8 *tbl)
{
uint8 Num, Page, Addr;
while ((Num = *tbl++) != 0) {
Page = *tbl++;
Addr = *tbl++;
WrScalarBytes(((uint16)Page<<8) + Addr, Num, tbl);
tbl += Num;
}
}
/*
********************************************************************************
* 函 数 名: SarAdcPower
* 功能描述: 关闭或者打开SCALAR中ADC部分的电源
* 输 入: state : ON 打开
* : OFF 关闭
* 返 回: 无
********************************************************************************
*/
void SarAdcPower(uint8 state)
{
if (state == ON) {
WrScalarReg(rP00E, B0011_1111);
WrScalarReg(rP013, 0x83);
WrScalarRegBit(rP102, B0000_1000, B0000_1000);
}
else {
WrScalarReg(rP00E, B0111_1000);
WrScalarReg(rP013, 0x77); //0x57 //chen 08-05-09 降低关机时的功耗
WrScalarRegBit(rP102, B0000_0000, B0000_1000);
}
}
void SarMPLLPower(uint8 state)
{
if (state == ON) WrScalarRegBit(rP102, B0100_0000, B0100_0000);
else WrScalarRegBit(rP102, B0000_0000, B0100_0000);
}
void SarHPLLPower(uint8 state)
{
if (state == ON) WrScalarRegBit(rP102, B0010_0000, B0010_0000);
else WrScalarRegBit(rP102, B0000_0000, B0010_0000);
}
void SarClockPower(uint8 state)
{
if (state == ON) WrScalarRegBit(rP101, B0000_0000, B0000_1101);
else WrScalarRegBit(rP101, B0000_0000, B0000_1101);
}
void SarLVDSPower(uint8 state)
{
if (state == ON) {
WrScalarRegBit(rP1F7, B1100_0000, B1100_0000);
WrScalarRegBit(rP101, B0100_0000, B0100_0000);
}
else {
WrScalarRegBit(rP1F7, B0000_0000, B1100_0000); //B1110_0000 //B1100_0000 //chen 08-05-09 降低关机时的功耗
WrScalarRegBit(rP101, B0000_0000, B0100_0000);
}
}
void SarMiscPower(uint8 state)
{
if (state == ON) WrScalarReg(rP1EE, 0x00);
else WrScalarReg(rP1EE, 0x7F);
}
/*
********************************************************************************
* 函 数 名: SarReset
* 功能描述: 对SCALAR进行复位操作
* 输 入: 无
* 返 回: 无
********************************************************************************
*/
void SarReset(void)
{
/*
================================================================================
= 通过寄存器进行热复位
================================================================================
*/
WrScalarReg(rP101, 0x20);
WrScalarReg(rP101, 0x00);
Delay(10);
WrScalarReg(0x20A, 0x82);
}
/*
********************************************************************************
* 函 数 名: SarInit
* 功能描述: 对SCALAR进行初始化
* 输 入: 无
* 返 回: 无
********************************************************************************
*/
void SarInit(void)
{
SarReset(); // 进行硬件复位
SarGetSCRev(); // 读取IC的版本号
RegDataTableOut(postInitTab); // 输出初始化的数据
// 2006年07月07日,这里的值被修改过
WrScalarReg(rP0D9, 0x00);
WrScalarReg(rP0DA, 0x00);
WrScalarReg(rP0D9, 0x40);
WrScalarReg(rP0DA, 0x01);
WrScalarReg(rP0D9, 0x80);
WrScalarReg(rP0DA, 0x00);
SarFreeRun();
SyncClearIntFlag();
}
/*
********************************************************************************
* 函 数 名: SarPostInit
* 功能描述: 上电时对SCALAR进行初始化
* 输 入: 无
* 返 回: 无
********************************************************************************
*/
void SarPostInit(void)
{
// 08-05-09
XFR_SC_HW_RST = xB_PBUS_EN;
XFR_SC_HW_RST = xB_PBUS_EN | xB_SC_RST;
// Delay(100);
SarPower(POWER_NORMAL);
SarInit();
OsdInit();
AdcInit();
MenuInit();
}
/*
********************************************************************************
* 函 数 名: SarSetBackGround
* 功能描述: 设置SCALAR输出的背景颜色,在FreeRun的模式中会使用到,相关的寄存器
* 设置有:
* rP154,rP159,rP16B,rP16C,rP16D
* 输 入: R_color : 红色
* G_color : 绿色
* B_color : 蓝色
* 返 回: 无
********************************************************************************
*/
void SarSetBackGround(uint8 R_color, uint8 G_color, uint8 B_color)
{
WrScalarReg(rP16B, R_color);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -