📄 lcd_lc256.c
字号:
/*256色低位在前Bit01234567*/
/*修改 :hugang hgxxx@51eda.com
*************************************************************************************************
Init & display control group
*************************************************************************************************
LCD_L0_Init() Initialize the display.
LCD_L0_ReInit() Reinitialize LCD without erasing the contents.
LCD_L0_Off() Switch LCD off.
LCD_L0_On() Switch LCD on.
*************************************************************************************************
Drawing group
*************************************************************************************************
LCD_L0_DrawBitmap() Universal draw bitmap routine.
LCD_L0_DrawHLine() Draw a horizontal line.
LCD_L0_DrawPixel() Draw a pixel in the current foreground color.
LCD_L0_DrawVLine() Draw a vertical line.
LCD_L0_FillRect() Fill a rectangular area.
LCD_L0_SetPixelIndex() Draw a pixel in a specified color.
LCD_L0_XorPixel() Invert a pixel.
*************************************************************************************************
"Get" group
*************************************************************************************************
LCD_L0_GetPixelIndex() Returs the index of the color of a specific pixel.
*************************************************************************************************
"Set" group
*************************************************************************************************
LCD_L0_SetOrg() Not yet used, reserved for future use (must exist in driver).
*************************************************************************************************
Lookup table group
*************************************************************************************************
LCD_L0_SetLUTEntry() Modifiy a single entry of LUT.
*************************************************************************************************
Misc. group (optional)
*************************************************************************************************
LCD_L0_ControlCache() Lock/unlock/flush LCD cache.
LCD_GetXSize() Return physical X-size of LCD in pixels.
LCD_GetYSize() Return physical Y-size of LCD in pixels.
LCD_GetVXSize() Return virtual X-size of LCD in pixels.
LCD_GetVYSize() Return virtual Y-size of LCD in pixels.
LCD_GetBitsPerPixel() Return the number of bits per pixel.
LCD_GetNumColors() Return the number of available colors.
LCD_GetFixedPalette() Return the fixed palette mode.
*************************************************************************************************/
#include <string.h> /* for memset */
#include <stddef.h> /* needed for definition of NULL */
#include "LCD_Private.H" /* private modul definitions & config */
#include "GUI_Private.H"
#include "GUIDebug.h"
#include "LCD_0.h" /* Defines for first display */
#include "MyDebug.h"
#include "../../../ucos_ii/includes.h"
#include "../../../inc/44blib.h"
#ifdef MYDEBUG
#define SCR_XSIZE (640)
#else
#define SCR_XSIZE (320)
#endif
#define SCR_YSIZE (240)
#define M5D(n) ((n) & 0x1fffff)
#define ARRAY_SIZE_COLOR (SCR_XSIZE/8*SCR_YSIZE)
#define HOZVAL (LCD_XSIZE/4-1)
#define HOZVAL_COLOR (LCD_XSIZE*3/8-1)
#define LINEVAL (LCD_YSIZE-1)
#define MVAL (13)
#define CLKVAL_COLOR (10) //60Mhz
#define MVAL_USED 0
#define LCD_BUF_SIZE (SCR_XSIZE * SCR_YSIZE)
#define GUISWAP(a, b) {a^=b; b^=a; a^=b;}
#if LCD_BITSPERPIXEL <= 8
#define PIXELINDEX U8
#else
#define PIXELINDEX WORD
#endif
#define SETPIXEL(x, y, c) LCD_L0_SetPixelIndex(x, y, c)
#define GETPIXEL(x, y) LCD_L0_GetPixelIndex(x,y)
#define XORPIXEL(x, y) LCD_L0_XorPixel(x,y)
//INT32U aLcdActiveBuffer[LCD_YSIZE][LCD_XSIZE/4];
//INT32U aLcdVirtualBuffer[LCD_YSIZE][LCD_XSIZE/4];
unsigned int (*aLcdActiveBuffer)[SCR_XSIZE/4];
unsigned int (*aLcdVirtualBuffer)[SCR_XSIZE/4];
void LCD_L0_DrawPixel(x, y, c)
{
// c = ( (c>>1)&0x1c ) | (c>>6) | (c<<5);
aLcdActiveBuffer[(y)][(x)/4]=( aLcdActiveBuffer[(y)][x/4] & ~(0xff000000>>((x)%4)*8) )
| ( (c)<<((4-1-((x)%4))*8) );
}
#ifndef LCD_OPTIMIZE
#define LCD_OPTIMIZE (1)
#endif
/*
********************************************************************
*
* ID translation table
*
********************************************************************
This table contains 0, 1, 2, ... and serves as translation table for DDBs
*/
#define INTS(Base) Base+0,Base+1,Base+2,Base+3,Base+4,Base+5, \
Base+6,Base+7,Base+8,Base+9,Base+10,Base+11, \
Base+12,Base+13,Base+14,Base+15
static const LCD_PIXELINDEX aID[] = {
INTS(0),
#if LCD_MAX_LOG_COLORS > 0x10
INTS(0x10),
#endif
#if LCD_MAX_LOG_COLORS > 0x20
INTS(0x20),
INTS(0x30),
#endif
#if LCD_MAX_LOG_COLORS > 0x40
INTS(0x40),
INTS(0x50),
INTS(0x60),
INTS(0x70),
#endif
#if LCD_MAX_LOG_COLORS > 0x80
INTS(0x80),
INTS(0x90),
INTS(0xa0),
INTS(0xb0),
INTS(0xc0),
INTS(0xd0),
INTS(0xe0),
INTS(0xf0)
#endif
};
static int CurPosX;
static U8* pCurPos;
#define LCD_BYTESPERLINE (3*(((LCD_VXSIZE_PHYS)+7)/8))
#define XY2OFF(x,y) (y*LCD_BYTESPERLINE+3*(x>>3))
#define OFF2PTR(Off) &aLcdActiveBuffer[0][Off]
static void SetPosXY(int x, int y) {
CurPosX = x;
//pCurPos = OFF2PTR(XY2OFF(x,y));
pCurPos = (U8*)OFF2PTR(XY2OFF(x,y));//change by lcn
switch (x&7) {
case 3:
case 4:
case 5:
pCurPos++; break;
case 6:
case 7:
pCurPos+=2;
}
}
static void SetNextPixel(LCD_PIXELINDEX c) {
switch (CurPosX&7) {
case 0: *pCurPos = (*pCurPos&~(7<<5))|(c<<5); break;
case 1: *pCurPos = (*pCurPos&~(7<<2))|(c<<2); break;
case 2: *pCurPos = (*pCurPos&~(3))|(c>>1);
pCurPos++;
*pCurPos = (*pCurPos &~(1<<7))|(c<<7);
break;
case 3: *pCurPos = (*pCurPos&~(7<<4))|(c<<4); break;
case 4: *pCurPos = (*pCurPos&~(7<<1))|(c<<1); break;
case 5: *pCurPos = (*pCurPos&~(1))|(c>>2);
pCurPos++;
*pCurPos = (*pCurPos &~(3<<6))|(c<<6);
break;
case 6: *pCurPos = (*pCurPos&~(7<<3))|(c<<3); break;
case 7: *pCurPos = (*pCurPos&~(7<<0))|(c);
pCurPos++;
break;
}
CurPosX++;
}
int LCD_L0_Init (void)
{
rPDATE=rPDATE&~(1<<5)|(1<<5); //GPE5=H
rPCONE=rPCONE&~(3<<10)|(1<<10); //GPE5=output
// rPCONC=rPCONC&~(0xff<<8)|(0xff<<8); //GPC[4:7] => VD[7:4]
if((U32)aLcdActiveBuffer==0)
{
aLcdActiveBuffer=(unsigned int (*)[SCR_XSIZE/4])malloc(ARRAY_SIZE_COLOR);
}
if((U32)aLcdVirtualBuffer==0)
{
aLcdVirtualBuffer=(unsigned int (*)[SCR_XSIZE/4])malloc(ARRAY_SIZE_COLOR);
}
rLCDCON1=(0)|(2<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_COLOR<<12);
// disable,8B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
rLCDCON2=(LINEVAL)|(HOZVAL_COLOR<<10)|(10<<21);
//LINEBLANK=10 (without any calculation)
rLCDSADDR1= (0x3<<27) | ( ((U32)aLcdActiveBuffer>>22)<<21 ) | M5D((U32)aLcdActiveBuffer>>1);
// 256-color, LCDBANK, LCDBASEU
rLCDSADDR2= M5D((((U32)aLcdActiveBuffer+(SCR_XSIZE*LCD_YSIZE))>>1)) | (MVAL<<21);
rLCDSADDR3= (LCD_XSIZE/2) | ( ((SCR_XSIZE-LCD_XSIZE)/2)<<9 );
//The following value has to be changed for better display.
rREDLUT =0xfdb96420;
rGREENLUT=0xfdb96420;
rBLUELUT =0xfb40;
rDITHMODE=0x0;
rDP1_2 =0xa5a5;
rDP4_7 =0xba5da65;
rDP3_5 =0xa5a5f;
rDP2_3 =0xd6b;
rDP5_7 =0xeb7b5ed;
rDP3_4 =0x7dbe;
rDP4_5 =0x7ebdf;
rDP6_7 =0x7fdfbfe;
rLCDCON1=(0x1)|(2<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_COLOR<<12);
return 0;
}
void LCD_L0_ReInit(void)
{
}
void LCD_L0_Off (void) {
Delay(100);
rPDATC = ( rPDATC | (1<<8) );
Delay(100);
}
void LCD_L0_On (void) {
Delay(100);
rPDATC = ( rPDATC & (~(1<<8)) );
Delay(100);
}
/*
void LCD_L0_On(void)
{
U16 i;
for(i=0;i<2000;i++);
rPDATC = ( rPDATC | (1<<8) );
for(i=0;i<2000;i++);
}
void LCD_L0_Off(void)
{
U16 i;
for(i=0;i<2000;i++);
rPDATC = ( rPDATC & (~(1<<8)) );
for(i=0;i<2000;i++);
}
*/
void LCD_L0_FillRect(int x0, int y0, int x1, int y1)
{
for (; y0 <= y1; y0++) {
LCD_L0_DrawHLine(x0,y0, x1);
}
}
void LCD_L0_DrawHLine(int x0, int y,int x1)
{
if (x0>x1) return; /* Check if nothing to draw */
if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
while (x0 <= x1) {
LCD_L0_XorPixel(x0,y);
// XORPIXEL(x0, y);
x0++;
}
} else {
while (x0 <= x1) {
LCD_L0_DrawPixel(x0,y,LCD_COLORINDEX);
// SETPIXEL(x0, y, COLOR);
x0++;
}
}
}
void LCD_L0_DrawVLine(int x, int y0, int y1)
{
if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
while (y0 <= y1) {
LCD_L0_XorPixel(x,y0);
// XORPIXEL(x, y0);
y0++;
}
} else {
while (y0 <= y1) {
LCD_L0_DrawPixel(x,y0,LCD_COLORINDEX);
// SETPIXEL(x, y0, COLOR);
y0++;
}
}
}
/*
***************************************************************
* *
* Internal bitmap routines *
* *
***************************************************************
*/
/*
*********************************************
* *
* Draw Bitmap 1 BPP *
* *
*********************************************
*/
static void DrawBitLine1BPP(int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans) {
LCD_PIXELINDEX pixels;
LCD_PIXELINDEX Index0 = *(pTrans+0);
LCD_PIXELINDEX Index1 = *(pTrans+1);
// Jump to right entry point
pixels = *p;
switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS|LCD_DRAWMODE_XOR)) {
case 0:
#if (LCD_OPTIMIZE) \
&& (!LCD_MIRROR_X) \
&& (!LCD_MIRROR_Y) \
&& (!LCD_SWAP_XY) \
&& (!LCD_SUPPORT_COMTRANS) \
&& (!LCD_SUPPORT_SEGTRANS) \
&& ((LCD_BITSPERPIXEL == 3) || (LCD_BITSPERPIXEL == 6))
SetPosXY(x+(Diff&7),y);
#endif
switch (Diff&7) {
case 0:
goto WriteBit0;
case 1:
goto WriteBit1;
case 2:
goto WriteBit2;
case 3:
goto WriteBit3;
case 4:
goto WriteBit4;
case 5:
goto WriteBit5;
case 6:
goto WriteBit6;
case 7:
goto WriteBit7;
}
break;
case LCD_DRAWMODE_TRANS:
switch (Diff&7) {
case 0:
goto WriteTBit0;
case 1:
goto WriteTBit1;
case 2:
goto WriteTBit2;
case 3:
goto WriteTBit3;
case 4:
goto WriteTBit4;
case 5:
goto WriteTBit5;
case 6:
goto WriteTBit6;
case 7:
goto WriteTBit7;
}
break;
case LCD_DRAWMODE_XOR:
switch (Diff&7) {
case 0:
goto WriteXBit0;
case 1:
goto WriteXBit1;
case 2:
goto WriteXBit2;
case 3:
goto WriteXBit3;
case 4:
goto WriteXBit4;
case 5:
goto WriteXBit5;
case 6:
goto WriteXBit6;
case 7:
goto WriteXBit7;
}
}
// Write with transparency
WriteTBit0:
if (pixels&(1<<7)) LCD_L0_DrawPixel(x+0, y, Index1);
if (!--xsize)
return;
WriteTBit1:
if (pixels&(1<<6)) LCD_L0_DrawPixel(x+1, y, Index1);
if (!--xsize)
return;
WriteTBit2:
if (pixels&(1<<5)) LCD_L0_DrawPixel(x+2, y, Index1);
if (!--xsize)
return;
WriteTBit3:
if (pixels&(1<<4)) LCD_L0_DrawPixel(x+3, y, Index1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -