📄 hal_lut.c
字号:
/************************************************************************
; HAL_LUT.C
;
; The routines in this file comprise Look_up Table set
;
; The Function is basic operation of LCDC
;
; Copyright (c) 2002 Epson Research and Development, Inc.
;
; All Rights Reserved.
; 2002.11.12 D Eric Start.
;
;************************************************************************/
#include "sysLCDC.h"
/****************************************************************************
; Function: Set LUT 1
; Input : the pointer of the LUT
; the size of the LUT
; Output : None
; Format : void SetLut1(unsigned char * pLut, unsigned long size)
;****************************************************************************/
void SetLut1(unsigned char * pLut, unsigned long size)
{
unsigned long i;
unsigned long LutRegIndex;
unsigned short reg;
LutRegIndex = REG0400_LUT1_DATA0;
for (i = 0; i < size; ++i)
{
reg = (unsigned short) (pLut[0] | (pLut[1] << 8));
halWriteReg16(LutRegIndex, reg);
LutRegIndex += 2;
reg = pLut[2];
halWriteReg16(LutRegIndex, reg);
LutRegIndex += 2;
pLut += 3;
}
}
/****************************************************************************
; Function: Set LUT 2
; Input : the pointer of the LUT
; the size of the LUT
; Output : None
; Format : void SetLut2(unsigned char * pLut, unsigned long size)
;****************************************************************************/
void SetLut2(unsigned char * pLut, unsigned long size)
{
unsigned long i;
unsigned long LutRegIndex;
unsigned short reg;
LutRegIndex = REG0800_LUT2_DATA0;
for (i = 0; i < size; ++i)
{
reg = (unsigned short) (pLut[0] | (pLut[1] << 8));
halWriteReg16(LutRegIndex, reg);
LutRegIndex += 2;
reg = pLut[2];
halWriteReg16(LutRegIndex, reg);
LutRegIndex += 2;
pLut += 3;
}
}
/****************************************************************************
; Function: Set LUT1 Entry
; Input : entry address
; red green blue
; Output : None
; Format : void SetLut1Entry(int addr, unsigned char red, unsigned char green, unsigned char blue)
;****************************************************************************/
void SetLut1Entry(unsigned long addr, unsigned char red, unsigned char green, unsigned char blue)
{
unsigned short reg;
unsigned long LutIndex;
LutIndex = REG0400_LUT1_DATA0 + addr*4;
halWriteReg16(LutIndex, (unsigned short) ((green << 8) | red));
LutIndex += 2;
reg = blue;
halWriteReg16(LutIndex, reg);
}
/****************************************************************************
; Function: Set the LUT2 Entry
; Input : entry address
; red green blue
; Output : None
; Format : void SetLut2Entry(int addr, unsigned char red, unsigned char green, unsigned char blue)
;****************************************************************************/
void SetLut2Entry(unsigned long addr, unsigned char red, unsigned char green, unsigned char blue)
{
unsigned long LutIndex;
LutIndex = REG0800_LUT2_DATA0 + addr*4;
halWriteReg16(LutIndex, (unsigned short) ((green << 8) | red));
LutIndex += 2;
halWriteReg16(LutIndex, blue);
}
/****************************************************************************
; Function: Get Lut1 Entry
; Input : entry address
; the poiter of red green blue
; Output : None
; Format : void GetLut1Entry (int addr, unsigned char * pRed, unsigned char * pGreen, unsigned char * pBlue)
;****************************************************************************/
void GetLut1Entry(unsigned long addr, unsigned char * pRed, unsigned char * pGreen, unsigned char * pBlue)
{
unsigned short reg;
unsigned long LutIndex;
LutIndex = REG0400_LUT1_DATA0 + addr*4;
reg = halReadReg16(LutIndex);
if (pRed != NULL)
*pRed = (unsigned char) reg;
if (pGreen != NULL)
*pGreen = (unsigned char) (reg >> 8);
if (pBlue != NULL)
{
LutIndex += 2;
reg = halReadReg16(LutIndex);
*pBlue = (unsigned char) reg;
}
}
/****************************************************************************
; Function: Get Lut2 Entry
; Input : entry address
; the pointer of red green blue
; Output : None
; Format : void GetLut2Entry(int addr, unsigned char * pRed, unsigned char * pGreen, unsigned char * pBlue)
;****************************************************************************/
void GetLut2Entry(unsigned long addr, unsigned char * pRed, unsigned char * pGreen, unsigned char * pBlue)
{
unsigned short reg;
unsigned long LutIndex;
LutIndex = REG0800_LUT2_DATA0 + addr*4;
reg = halReadReg16(LutIndex);
*pRed = (unsigned char) reg;
*pGreen = (unsigned char) (reg >> 8);
LutIndex += 2;
reg = halReadReg16(LutIndex);
*pBlue = (unsigned char) reg;
}
/****************************************************************************
; Function: Set Lut Bypass Enable
; Input : LUT Number
; Enable/Disable
; Output : None
; Format : void SetLutBypassEnable(LutDef lut, unsigned short enable)
;****************************************************************************/
void SetLutBypassEnable(LutDef LutNum, unsigned short enable)
{
unsigned short reg = halReadReg16(REG0200_DISPLAY_MODE_SETTING0);
switch (LutNum)
{
default:
case cl_LUT1:
if (enable)
reg |= 0x0010;
else
reg &= 0xFFEF;
break;
case cl_LUT2:
if (enable)
reg |= 0x0020;
else
reg &= 0xFFDF;
break;
}
halWriteReg16(REG0200_DISPLAY_MODE_SETTING0, reg);
}
/****************************************************************************
; Function: Get Lut Bypass Enable
; Input : Lut Number
; Output : Enable/Disable
; Format : Boolean GetLutBypassEnable(LutDef lut)
;****************************************************************************/
BOOL GetLutBypassEnable(LutDef LutNum)
{
switch (LutNum)
{
default:
case cl_LUT1:
if (halReadReg16(REG0200_DISPLAY_MODE_SETTING0) & 0x0010)
return TRUE;
else
return FALSE;
break;
case cl_LUT2:
if (halReadReg16(REG0200_DISPLAY_MODE_SETTING0) & 0x0020)
return TRUE;
else
return FALSE;
break;
}
}
/****************************************************************************
; Function : Get Lut Mode
; Input : Lut Number
; Output : Lut Mode
; Format : unsigned short GetLutMode(LutDef LutNum)
;****************************************************************************/
unsigned short GetLutMode(LutDef LutNum)
{
int bpp;
int LutBypass;
switch (LutNum)
{
default:
case cl_LUT1:
bpp = GetBitsPerPixel(cl_MAIN_WINDOW);
LutBypass = GetLutBypassEnable(cl_LUT1);
if (LutBypass || (bpp>16))
{
switch (bpp)
{
case 8: return cl_LUT_BYPASS_8BPP_332RGB; break;
case 16: return cl_LUT_BYPASS_16BPP_565RGB; break;
case 32: return cl_LUT_BYPASS_32BPP_0888RGB; break;
default: return cl_LUT_ERROR; break;
}
}
else
{
switch (bpp)
{
case 8: return cl_LUT_NOBYPASS_8BPP_STANDARDLUT; break;
case 16: return cl_LUT_NOBYPASS_16BPP_565LUT; break;
default: return cl_LUT_ERROR; break;
}
}
break;
case cl_LUT2:
bpp = GetBitsPerPixel(cl_PIP_WINDOW);
LutBypass = GetLutBypassEnable(cl_LUT2);
if (LutBypass)
{
switch (bpp)
{
case 8: return cl_LUT_BYPASS_8BPP_332RGB; break;
case 16: return cl_LUT_BYPASS_16BPP_565RGB; break;
case 32: return cl_LUT_BYPASS_32BPP_0888RGB; break;
default: return cl_LUT_ERROR; break;
}
}
else
{
switch (bpp)
{
case 8: return cl_LUT_NOBYPASS_8BPP_332LUT; break;
case 16: return cl_LUT_NOBYPASS_16BPP_565LUT; break;
default: return cl_LUT_ERROR; break;
}
}
break;
}
}
/****************************************************************************
; Function: Initialize LUT
; Input : the LUT number
; the LUT mode
; Output : None
; Format : void InitLut(LutDef WhichLut, LutModeDef LutMode)
;****************************************************************************/
void InitLut(LutDef WhichLut, LutModeDef LutMode)
{
unsigned short i;
unsigned char red, green, blue;
//define the funtion pointer of LUT set
void (*pSetLut)(unsigned char * pLut, unsigned long size);
void (*pSetLutEntry)(unsigned long addr, unsigned char red, unsigned char green, unsigned char blue);
if (WhichLut == cl_LUT2)
{
pSetLut = SetLut2;
pSetLutEntry = SetLut2Entry;
}
else
{
pSetLut = SetLut1;
pSetLutEntry = SetLut1Entry;
}
switch (LutMode)
{
default:
break;
case cl_LUT_NOBYPASS_8BPP_STANDARDLUT:
(*pSetLut)(LutInfo.lut1, (sizeof(LutInfo.lut1) / sizeof(LutInfo.lut1[0]))/3);
break;
case cl_LUT_NOBYPASS_8BPP_332LUT:
for (i = 0; i < 8; ++i)
{
red = green = (unsigned char) ((i * 0xff) / 7);
if (i < 4)
blue = (unsigned char) ((i * 0xff) / 3);
else
blue = 0xff;
(*pSetLutEntry)(i, red, green, blue);
}
break;
case cl_LUT_NOBYPASS_16BPP_565LUT:
for (i = 0; i < 64; ++i)
{
if (i < 32)
red = blue = (unsigned char) ((i * 0xff) / 31);
else
red = blue = 0xff;
green = (unsigned char) ((i * 0xff) / 63);
(*pSetLutEntry)(i, red, green, blue);
}
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -