📄 lcd44b0.c
字号:
#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 "LCD_Private.h" /* private modul definitions & config */
#include "GUI_Private.h"
#include "GUIDebug.h"
#include "44b.h"
#define TRUE 1
#define FALSE 0
#define LCDDisplayPin 0x0010 //GPB4
#define CLKVAL (10) // 60Mhz, fr=100Hz (CLKVAL=38.6)
#define LCDCON1_ENVID (1)
#define COLOR LCD_COLORINDEX
U32* pLCD=(U32*)0xc000000;
//#define ColorTo8Bit(c) ( (((c)&0xC00000)>>(16+6)) | (((c)&0xe000)>>(8+3)) | ((c)&0xE0) ) //0x00BBGGRR
#define SetPixel(x, y, c) \
(*(pLCD+(y)*320/4+(x)/4)) = \
((*(pLCD+(y)*320/4+(x)/4)) & ~(0xff000000>>((x)%4)*8)) | \
( ((U32)(c))<<((4-1-((x)%4))*8) )
#define GetPixelIndex(x, y) \
( ( (*(pLCD+(y)*320/4+(x)/4))>>( 32-8-(x%4)*8 ) ) & 0xff )
#define XorPixel(x, y) \
(*(pLCD+(y)*320/4+(x)/4)) = \
(0x100-1-GetPixelIndex((x), (y)))
static void LCDDisplayOpen(U8 isOpen)
{
if(isOpen){
rPDATB&=~LCDDisplayPin;
}
else{
rPDATB|=LCDDisplayPin;
}
}
/*********************************************************************
*
* LCD_L0_SetPixelIndex
*/
void LCD_L0_SetPixelIndex(int x, int y, int PixelIndex) {
SetPixel(x, y, PixelIndex);//ColorTo8Bit(PixelIndex)
}
/*********************************************************************
*
* LCD_L0_GetPixelIndex
*/
unsigned int LCD_L0_GetPixelIndex(int x, int y) {
return GetPixelIndex(x,y);
}
/*********************************************************************
*
* LCD_L0_XorPixel
*/
void LCD_L0_XorPixel(int x, int y) {
XorPixel(x, y);
}
/*********************************************************************
*
* LCD_L0_DrawHLine
*/
void LCD_L0_DrawHLine(int x0, int y, int x1) {
if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR)
{
while (x0 <= x1)
{
XorPixel(x0, y);
x0++;
}
} else
{
while (x0 <= x1)
{
SetPixel(x0, y, COLOR);
x0++;
}
}
}
/*********************************************************************
*
* LCD_L0_DrawVLine
*/
void LCD_L0_DrawVLine(int x, int y0, int y1) {
if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR)
{
while (y0 <= y1)
{
XorPixel(x, y0);
y0++;
}
}
else
{
while (y0 <= y1)
{
SetPixel(x, y0, COLOR);
y0++;
}
}
}
/*********************************************************************
*
* LCD_L0_FillRect
*/
void LCD_L0_FillRect(int x0, int y0, int x1, int y1) {
#if !LCD_SWAP_XY
for (; y0 <= y1; y0++) {
LCD_L0_DrawHLine(x0,y0, x1);
}
#else
for (; x0 <= x1; x0++) {
LCD_L0_DrawVLine(x0,y0, y1);
}
#endif
}
static void DrawBitLine1BPP(int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans) {
// LCD_PIXELINDEX aColor[2];
U16 Pixels = ((*p) << 8) | (*(p + 1));
U8 RemPixels;
p++;
// aColor[0] = *pTrans;
// aColor[1] = *(pTrans + 1);
x += Diff;
RemPixels = 16 - Diff;
Pixels <<= Diff;
if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
do {
if (RemPixels==0) {
Pixels = ((*(p + 1)) << 8) | (*(p + 2));
p += 2;
RemPixels = 16;
}
if (Pixels & 0x8000) {
XorPixel(x, y);
}
RemPixels--;
Pixels <<=1;
x++;
} while (--xsize);
}
else {
do {
if (RemPixels==0) {
Pixels = ((*(p + 1)) << 8) | (*(p + 2));
p += 2;
RemPixels = 16;
}
if (Pixels & 0x8000) {
SetPixel(x, y, *(pTrans+1));
}
RemPixels--;
Pixels <<=1;
x++;
} while (--xsize);
}
}
/*
*********************************************
* *
* Draw Bitmap 2 BPP *
* *
*********************************************
*/
#if (LCD_MAX_LOG_COLORS > 2)
static void DrawBitLine2BPP(int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans) {
LCD_PIXELINDEX pixels;
/*
// Jump to right entry point
*/
pixels = *p;
if (GUI_Context.DrawMode & LCD_DRAWMODE_TRANS) switch (Diff&3) {
case 0:
goto WriteTBit0;
case 1:
goto WriteTBit1;
case 2:
goto WriteTBit2;
default:
goto WriteTBit3;
} else switch (Diff&3) {
case 0:
goto WriteBit0;
case 1:
goto WriteBit1;
case 2:
goto WriteBit2;
default:
goto WriteBit3;
}
/*
Write without transparency
*/
WriteBit0:
SetPixel(x+0, y, *(pTrans+(pixels>>6)));
if (!--xsize)
return;
WriteBit1:
SetPixel(x+1, y, *(pTrans+(3&(pixels>>4))));
if (!--xsize)
return;
WriteBit2:
SetPixel(x+2, y, *(pTrans+(3&(pixels>>2))));
if (!--xsize)
return;
WriteBit3:
SetPixel(x+3, y, *(pTrans+(3&(pixels))));
if (!--xsize)
return;
pixels = *(++p);
x+=4;
goto WriteBit0;
/*
Write with transparency
*/
WriteTBit0:
if (pixels&(3<<6))
SetPixel(x+0, y, *(pTrans+(pixels>>6)));
if (!--xsize)
return;
WriteTBit1:
if (pixels&(3<<4))
SetPixel(x+1, y, *(pTrans+(3&(pixels>>4))));
if (!--xsize)
return;
WriteTBit2:
if (pixels&(3<<2))
SetPixel(x+2, y, *(pTrans+(3&(pixels>>2))));
if (!--xsize)
return;
WriteTBit3:
if (pixels&(3<<0))
SetPixel(x+3, y, *(pTrans+(3&(pixels))));
if (!--xsize)
return;
pixels = *(++p);
x+=4;
goto WriteTBit0;
}
#endif
/*
*********************************************
* *
* Draw Bitmap 4 BPP *
* *
*********************************************
*/
#if (LCD_MAX_LOG_COLORS > 4)
static void DrawBitLine4BPP(int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans) {
U8 pixels;
/*
// Jump to right entry point
*/
pixels = *p;
if (GUI_Context.DrawMode & LCD_DRAWMODE_TRANS) {
if ((Diff&1) ==0)
goto WriteTBit0;
goto WriteTBit1;
} else {
if ((Diff&1) ==0)
goto WriteBit0;
goto WriteBit1;
}
/*
Write without transparency
*/
WriteBit0:
SetPixel(x+0, y, *(pTrans+(pixels>>4)));
if (!--xsize)
return;
WriteBit1:
SetPixel(x+1, y, *(pTrans+(pixels&0xf)));
if (!--xsize)
return;
x+=2;
pixels = *(++p);
goto WriteBit0;
/*
Write with transparency
*/
WriteTBit0:
if (pixels>>4)
SetPixel(x+0, y, *(pTrans+(pixels>>4)));
if (!--xsize)
return;
WriteTBit1:
if (pixels&0xf)
SetPixel(x+1, y, *(pTrans+(pixels&0xf)));
if (!--xsize)
return;
x+=2;
pixels = *(++p);
goto WriteTBit0;
}
#endif
static void DrawBitLine8BPP(int x, int y, U8 const*p, int xsize, const LCD_PIXELINDEX* pTrans) {
LCD_PIXELINDEX pixel;
if ((GUI_Context.DrawMode & LCD_DRAWMODE_TRANS)==0) {
if (pTrans) {
for (;xsize > 0; xsize--,x++,p++) {
pixel = *p;
SetPixel(x, y, *(pTrans+pixel));
}
}
else {
for (;xsize > 0; xsize--,x++,p++) {
SetPixel(x, y, *p);
}
}
}
else { /* Handle transparent bitmap */
if (pTrans) {
for (; xsize > 0; xsize--, x++, p++) {
pixel = *p;
if (pixel) {
SetPixel(x+0, y, *(pTrans+pixel));
}
}
} else {
for (; xsize > 0; xsize--, x++, p++) {
pixel = *p;
if (pixel) {
SetPixel(x+0, y, pixel);
}
}
}
}
}
/*********************************************************************
*
* LCD_L0_DrawBitmap
*/
void LCD_L0_DrawBitmap (int x0, int y0,
int xsize, int ysize,
int BitsPerPixel,
int BytesPerLine,
const U8* pData, int Diff,
const LCD_PIXELINDEX* pTrans) {
int i;
for (i=0; i<ysize; i++) {
switch (BitsPerPixel) {
case 1:
DrawBitLine1BPP(x0, i+y0, pData, Diff, xsize, pTrans);
break;
#if (LCD_MAX_LOG_COLORS > 2)
case 2:
DrawBitLine2BPP(x0, i+y0, pData, Diff, xsize, pTrans);
break;
#endif
#if (LCD_MAX_LOG_COLORS > 4)
case 4:
DrawBitLine4BPP(x0, i+y0, pData, Diff, xsize, pTrans);
break;
#endif
#if (LCD_MAX_LOG_COLORS > 16)
case 8:
DrawBitLine8BPP(x0, i+y0, pData, xsize, pTrans);
break;
#endif
}
pData += BytesPerLine;
}
}
/********************************************************
* *
* LCD_L0_SetOrg *
* *
*********************************************************
Purpose: Sets the original position of the virtual display.
Has no function at this point with the PC-driver.
*/
int OrgX, OrgY;
void LCD_L0_SetOrg(int x, int y) {
OrgX = x;
OrgY = y;
}
/*********************************************************************
*
* LCD_On / LCD_Off
*/
void LCD_On (void)
{
LCDDisplayOpen(TRUE);
}
void LCD_Off(void)
{
LCDDisplayOpen(FALSE);
}
/*********************************************************************
*
* LCD_L0_Init
*/
int LCD_L0_Init(void) {
U32 LCDBASEU,LCDBASEL,LCDBANK;
GUI_DEBUG_LOG("\nLCD_Init()");
rLCDCON1=(0);
// disable
rLCDCON2=(239)|(119<<10)|(15<<21);
//320x240LCD LINEBLANK=15 (without any calculation)
//LCD 的分辨率为320×240,根据下面的公式可以计算出HOZVAL 和LINEVAL 的值,
//LINEBLANK 设为15。
//HOZVAL = ( Horizontal display size / Number of the valid VD data line) –1
//In color mode: Horizontal display size = 3 * Number of Horizontal Pixel
//LINEVAL = (Vertical display size) -1: In case of single scan display type
LCDBANK=0xc000000>>22; //这里设置的就是BANK6的起始地址0xc000000
LCDBASEU=0x0; //((U32)LCDBuffer16)&0x3fffff;
LCDBASEL=LCDBASEU+(160)*240; //LCDBASEL = LCDBASEU +(PAGEWIDTH + OFFSIZE) x (LINEVAL +1)
//OFFSIZE=0,PAGEWIDTH=320÷2。239+1=240
rLCDSADDR1= (0x3<<27) |(LCDBANK<<21)|LCDBASEU;//| ((((U32)LCDBuffer16)>>1)&0x7ffffff);
// color_mode, LCDBANK, LCDBASEU
rLCDSADDR2= (0<<29)|(0<<21)|LCDBASEL;
rLCDSADDR3= (320/2)|(0<<9);
//No virtual screen.
/*
rREDLUT=0xfca86420;
rGREENLUT=0xfca86420;
rBLUELUT=0xfffff840;
*/
//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=LCDCON1_ENVID|0<<1|0<<2|0<<3|(2<<5)|1<<7|(0x3<<8)|(0x3<<10)|(CLKVAL<<12);//|LCDCON1_MMODE;
// enable,8B_SNGL_SCAN,WDLY=16clk,WLH=16clk,CLKVAL=?
LCD_Off();
return 0;
}
/*********************************************************************
*
* LCD_L0_SetLUTEntry
*/
void LCD_L0_SetLUTEntry(U8 Pos, LCD_COLOR Color) {
}
void LCDNull_c(void);
void LCDNull_c(void) {} /* avoid empty object files */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -