📄 hal_lcd.c
字号:
/***************************************************************
* Copyright(C) 2003--2006
* Epson Electronic Technology Development (ShenZhen) co., LTD
* All rights reserved.
*
* File name: HAL_LCD.C
* Author: Eric ding
* Dept: Electronic Enginerring Department
* Date: 03/19/2003
* Descriptions: the lcd interface function
* Modified:
***************************************************************/
#include "sysLCDC.h"
/******************************* LCD COMMONALITY SETTING ************************************************/
/****************************************************************************
; Function : Set LCD Pixel CLK Divide
; Input : divide (2~32)
; Output : none
; Format : void SetLcdPClkDivide(unsigned short divide)
; Note : For RGB panel is pixel clk
; For parallel panel is output clk
;****************************************************************************/
void SetLcdPClkDivide(unsigned short divide)
{
unsigned short reg=halReadReg16(REG0030_LCD_INTERFACE_CLOCK)&0xFFF0;
if(divide>32||divide<2)
return;
divide=((divide/2-1)&0x0F);
halWriteReg16(REG0030_LCD_INTERFACE_CLOCK,reg|divide);
}
/****************************************************************************
; Function: Get LCD Pixel CLK Divide
; Input : None
; Output : Divide (2~32)
; Format : unsigned short GetLcdPClkDivide(void)
;****************************************************************************/
unsigned short GetLcdPClkDivide(void)
{
return ((halReadReg16(REG0030_LCD_INTERFACE_CLOCK) & 0x0f) + 1) * 2;
}
/****************************************************************************
; Function: Get LCD Pixel CLK Freq
; Input :
; Output :
; Format : unsigned long GetLcdPClkFreq(void)
;****************************************************************************/
unsigned long GetLcdPClkFreq(void)
{
return GetSystemClock(NULL) / GetLcdPClkDivide();
}
/****************************************************************************
; Function: Get LCD Frame Rate
; Input : None
; Output : Frame Rate
; Format : unsigned short GetLcdFrameRate(void)
;****************************************************************************/
unsigned long GetLcdFrameRate(void)
{
OutputPortDef OutputPort = GetOutputPort();
unsigned long Lcd1HTotal;
unsigned long Lcd1VTotal;
// This function only supports LCD1 using an RGB Interface
if (OutputPort != cl_PORT_LCD1)
return 0;
Lcd1HTotal = ((halReadReg16(REG0040_LCD1_HORIZONTAL_TOTAL) & 0x7f) + 1) * 8;
Lcd1VTotal = halReadReg16(REG004A_LCD1_VERTICAL_TOTAL) + 1;
return ((unsigned long) GetLcdPClkFreq() * 10) / (Lcd1HTotal * Lcd1VTotal); // Actual Hz *10
}
/****************************************************************************
; Function: Set the LCD Panel interface type
; Input : mode: 00--RGB and Serial
; 01--Reserved
; 10--Parallel and Serial
; 11--Parallel and Parallel
; Output : None
; Format : void SetPanelIfType(unsigned short mode)
;****************************************************************************/
void SetPanelIfType(unsigned short mode)
{
unsigned short reg=halReadReg16(REG0032_LCD_MODULE_CLOCK)&0xFFFC;
reg|=mode;
halWriteReg16(REG0032_LCD_MODULE_CLOCK,reg);
}
/****************************************************************************
; Function: Get the Panel interface type
; Input : None
; Output : mode: 00--RGB and Serial
; 01--Reserved
; 10--Parallel and Serial
; 11--Parallel and Parallel
; Format : unsigned short GetPanelIfType(void)
;****************************************************************************/
unsigned short GetPanelIfType(void)
{
return(halReadReg16(REG0032_LCD_MODULE_CLOCK)&0x0003);
}
/****************************************************************************
; Function: Set LCD Horizonta and Vertical Display Period
; Input : LCD number
; Horizontal Display Period in number of clocks
; Vertical Display Period in number of lines
; Output : None
; Format : void SetLcdHVDispPer (LcdDef LcdNum,unsigned short HorizDispPer,unsigned short VertDispPer)
;****************************************************************************/
void SetLcdHVDispPer (LcdDef LcdNum,unsigned short HorizDispPer,unsigned short VertDispPer)
{
unsigned short HDP,VDP;
OutputPortDef OutputPort = GetOutputPort();
HDP=(HorizDispPer/2-1)&0x00FF;
VDP=VertDispPer-1;
if(OutputPort==cl_PORT_YUV_DIGITAL)
HDP=(HorizDispPer/4-1)&0x00FF;
switch(LcdNum)
{
case cl_LCD1:
halWriteReg16(REG0042_LCD1_HDP,HDP);
halWriteReg16(REG004C_LCD1_VDP,VDP);
break;
case cl_LCD2:
halWriteReg16(REG0058_LCD2_HDP,HDP);
halWriteReg16(REG005A_LCD2_VDP,VDP);
break;
default:
break;
}
}
/****************************************************************************
; Function: Get the LCD Horizontal Display Period
; Input : OutputPort
; Output : Horizontal Display Period in number of clocks
; Format : unsigned long GetLcdHdp(OutputPortDef OutputPort)
;****************************************************************************/
unsigned long GetLcdHdp(OutputPortDef OutputPort)
{
unsigned long val32;
if (OutputPort == cl_PORT_LCD2)
return ( (halReadReg16( REG0058_LCD2_HDP ) + 1UL) * 2 );
else // cl_PORT_LCD1
{
val32 = (halReadReg16( REG0042_LCD1_HDP ) + 1UL) * 2;
switch ( halReadReg16(REG0032_LCD_MODULE_CLOCK) >> 10 )
{
default:
break;
case 0x10:
case 0x11:
case 0x12:
val32 *= 3;
break;
case 0x14:
case 0x15:
case 0x16:
val32 *= 2;
break;
}
return val32;
}
}
/****************************************************************************
; Function: Get the LCD Vertical Display Period
; Input : OutputPort
; Output : Vertical Display Period in number of lines
; Format : unsigned long GetLcdVdp(OutputPortDef OutputPort)
;****************************************************************************/
unsigned long GetLcdVdp(OutputPortDef OutputPort)
{
unsigned long val32;
if (OutputPort == cl_PORT_LCD2)
return ( halReadReg16( REG005A_LCD2_VDP) + 1 );
else // cl_PORT_LCD1
{
val32 = halReadReg16( REG004C_LCD1_VDP) + 1;
switch ( halReadReg16(REG0032_LCD_MODULE_CLOCK) >> 10 )
{
default:
break;
case 0x10:
case 0x14:
case 0x18:
val32 = val32*3 - 1;
break;
}
return val32;
}
}
/****************************************************************************
; Function: Set Lcd Output Port
; Input : port:
; 0-- PORT_ALL_OFF,
; 1-- PORT_LCD1,
; 2-- PORT_LCD2,
; 3-- PORT_YUV_DIGITAL,
; 4-- PORT_T3,
; Output : FALSE/TRUE
; Format : Boolean SetOutputPort(OutputPortDef port)
;****************************************************************************/
BOOL SetOutputPort(OutputPortDef port)
{
unsigned short reg = (unsigned short) (halReadReg16(REG0202_DISPLAY_MODE_SETTING1) & ~0x1c00);
switch (port)
{
case cl_PORT_ALL_OFF: reg &= 0xE3FF; break;
case cl_PORT_LCD1: reg |= 0x0400; break;
case cl_PORT_LCD2: reg |= 0x0800; break;
case cl_PORT_YUV_DIGITAL: reg |= 0x1000; break;
case cl_PORT_T3: reg |= 0x1400; break;
default: return FALSE;
}
halWriteReg16(REG0202_DISPLAY_MODE_SETTING1, reg);
return TRUE;
}
/****************************************************************************
; Function: Get LCD Output Port
; Input : None
; Output : port type
; Format : OutputPortDef GetOutputPort(void)
;****************************************************************************/
OutputPortDef GetOutputPort(void)
{
unsigned long PortStatus = (halReadReg16(REG0202_DISPLAY_MODE_SETTING1) >> 10) & 0x07;
switch (PortStatus)
{
case 0: return cl_PORT_ALL_OFF; break;
case 1: return cl_PORT_LCD1; break;
case 2: return cl_PORT_LCD2; break;
case 4: return cl_PORT_YUV_DIGITAL; break;
case 5: return cl_PORT_T3; break;
default: return cl_PORT_RESERVED; break;
}
}
/******************************* LCD RGB PANEL SETTING ************************************************/
/****************************************************************************
; Function: Set the RGB Panel Data Width
; Input : Panel Data Width
; Output : None
; Format : int GetPanelDataWidth(void)
;****************************************************************************/
void SetRGBPanelDataWidth(unsigned char width)
{
unsigned short reg=halReadReg16(REG0032_LCD_MODULE_CLOCK)&0xFF8F;
switch (width)
{
case RGB_PANEL_WIDTH_9:
halWriteReg16(REG0032_LCD_MODULE_CLOCK, reg|RGB_PANEL_WIDTH_9);
break;
case RGB_PANEL_WIDTH_12:
halWriteReg16(REG0032_LCD_MODULE_CLOCK, reg|RGB_PANEL_WIDTH_12);
break;
case RGB_PANEL_WIDTH_16:
halWriteReg16(REG0032_LCD_MODULE_CLOCK, reg|RGB_PANEL_WIDTH_16 );
break;
case RGB_PANEL_WIDTH_18:
halWriteReg16(REG0032_LCD_MODULE_CLOCK, reg|RGB_PANEL_WIDTH_18);
break;
case RGB_PANEL_WIDTH_24:
halWriteReg16(REG0032_LCD_MODULE_CLOCK, reg|RGB_PANEL_WIDTH_24);
break;
default:
break;
}
}
/****************************************************************************
; Function: Get the RGB Panel Data Width
; Input : None
; Output : Panel Data Width
; Format : unsigned short GetPanelDataWidth(void)
;****************************************************************************/
unsigned short GetRGBPanelDataWidth(void)
{
switch ((halReadReg16(REG0032_LCD_MODULE_CLOCK) >> 4) & 0x07)
{
case 0: return 9 ; break;
case 1: return 12; break;
case 2: return 16; break;
case 3: return 18; break;
case 4: return 24; break;
default: return -1; break;
}
}
/****************************************************************************
; Function: Set the RGB Panel Clock Polarity
; Input : mode: 0: rising edge of shift clock
; 1: falling edge of shift clock
; Output : None
; Format : void SetRGBPanelClkPol(unsigned short mode)
;****************************************************************************/
void SetRGBPanelClkPol(unsigned short mode)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -