LCDMem.c
上传用户:zbk8730
上传日期:2017-08-10
资源大小:12168k
文件大小:16k
- /*
- *********************************************************************************************************
- * uC/GUI
- * Universal graphic software for embedded applications
- *
- * (c) Copyright 2002, Micrium Inc., Weston, FL
- * (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH
- *
- * 礐/GUI is protected by international copyright laws. Knowledge of the
- * source code may not be used to write a similar product. This file may
- * only be used in accordance with a license and should not be redistributed
- * in any way. We appreciate your understanding and fairness.
- */
- #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 "2440addr.h"
- #include "2440lib.h"
- #include "2440slib.h"
- #include "lcdlib.h"
- #include "glib.h"
- #include "2440lcd.h"
- #include "DEMO256.h"
- #include "LCDMem.h"
- /**************************************************************
- The initial and control for 320×240 16Bpp TFT LCD----LCD_LTV350QV-F04
- **************************************************************/
- #include <stdarg.h>
- #include <string.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <ctype.h>
- #include "option.h"
- #include "2440addr.h"
- #include "2440lib.h"
- #include "2440slib.h"
- #include "lcd.h"
- #define MVAL (13)
- #define MVAL_USED (0) //0=each frame 1=rate by MVAL
- #define INVVDEN (1) //0=normal 1=inverted
- #define BSWP (0) //Byte swap control
- #define HWSWP (1) //Half word swap control
- #define M5D(n) ((n) & 0x1fffff) // To get lower 21bits
- //TFT 240320
- #define LCD_TFT_XSIZE (240)
- #define LCD_TFT_YSIZE (320)
- #define SCR_XSIZE_TFT (240)
- #define SCR_YSIZE_TFT (320)
- //TFT240320
- #define HOZVAL_TFT (LCD_TFT_XSIZE-1)
- #define LINEVAL_TFT (LCD_TFT_YSIZE-1)
- //Timing parameter for LCD LQ035Q7DB02
- #define VBPD (1) //垂直同步信号的后肩
- #define VFPD (5) //垂直同步信号的前肩
- #define VSPW (1) //垂直同步信号的脉宽
- #define HBPD (35) //水平同步信号的后肩
- #define HFPD (19) //水平同步信号的前肩
- #define HSPW (5) //水平同步信号的脉宽
- #define CLKVAL_TFT (4)
- // GPB1/TOUT1 for Backlight control(PWM)
- #define GPB1_TO_OUT() (rGPBUP &= 0xfffd, rGPBCON &= 0xfffffff3, rGPBCON |= 0x00000004)
- #define GPB1_TO_1() (rGPBDAT |= 0x0002)
- #define GPB1_TO_0() (rGPBDAT &= 0xfffd)
- //extern void Uart_Printf(char *f, ...) ;
- extern unsigned char __CHS[];
- extern unsigned char __VGA[];
- volatile static unsigned short LCD_BUFFER[SCR_YSIZE_TFT][SCR_XSIZE_TFT];
- #ifndef LCD_BUSWIDTH
- #define LCD_BUSWIDTH 16
- #endif
- #define BKCOLOR LCD_BKCOLORINDEX
- #define COLOR LCD_COLORINDEX
- static void _DrawBitLine1BPP(int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans) {
- LCD_PIXELINDEX Index0 = *(pTrans+0);
- LCD_PIXELINDEX Index1 = *(pTrans+1);
- x += Diff;
- switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
- case 0:
- do {
- LCD_L0_SetPixelIndex(x++, y, (*p & (0x80 >> Diff)) ? Index1 : Index0);
- if (++Diff == 8) {
- Diff = 0;
- p++;
- }
- } while (--xsize);
- break;
- case LCD_DRAWMODE_TRANS:
- do {
- if (*p & (0x80 >> Diff))
- LCD_L0_SetPixelIndex(x, y, Index1);
- x++;
- if (++Diff == 8) {
- Diff = 0;
- p++;
- }
- } while (--xsize);
- break;
- case LCD_DRAWMODE_XOR:;
- do {
- if (*p & (0x80 >> Diff)) {
- int Pixel = LCD_L0_GetPixelIndex(x, y);
- LCD_L0_SetPixelIndex(x, y, LCD_NUM_COLORS - 1 - Pixel);
- }
- x++;
- if (++Diff == 8) {
- Diff = 0;
- p++;
- }
- } while (--xsize);
- break;
- }
- }
- /*********************************************
- *
- * 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 = *p;
- int CurrentPixel = Diff;
- x += Diff;
- switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
- case 0:
- do {
- int Shift = (3 - CurrentPixel) << 1;
- int Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
- LCD_PIXELINDEX PixelIndex = *(pTrans + Index);
- LCD_L0_SetPixelIndex(x++, y, PixelIndex);
- if (++CurrentPixel == 4) {
- CurrentPixel = 0;
- Pixels = *(++p);
- }
- } while (--xsize);
- break;
- case LCD_DRAWMODE_TRANS:
- do {
- int Shift = (3 - CurrentPixel) << 1;
- int Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
- if (Index) {
- LCD_PIXELINDEX PixelIndex = *(pTrans + Index);
- LCD_L0_SetPixelIndex(x, y, PixelIndex);
- }
- x++;
- if (++CurrentPixel == 4) {
- CurrentPixel = 0;
- Pixels = *(++p);
- }
- } while (--xsize);
- break;
- }
- }
- #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) {
- LCD_PIXELINDEX Pixels = *p;
- int CurrentPixel = Diff;
- switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
- case 0:
- do {
- int Shift = (1 - CurrentPixel) << 2;
- int Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
- LCD_PIXELINDEX PixelIndex = *(pTrans + Index);
- LCD_L0_SetPixelIndex(x++, y, PixelIndex);
- if (++CurrentPixel == 2) {
- CurrentPixel = 0;
- Pixels = *(++p);
- }
- } while (--xsize);
- break;
- case LCD_DRAWMODE_TRANS:
- do {
- int Shift = (1 - CurrentPixel) << 2;
- int Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
- if (Index) {
- LCD_PIXELINDEX PixelIndex = *(pTrans + Index);
- LCD_L0_SetPixelIndex(x, y, PixelIndex);
- }
- x++;
- if (++CurrentPixel == 2) {
- CurrentPixel = 0;
- Pixels = *(++p);
- }
- } while (--xsize);
- break;
- }
- }
- #endif
- /*********************************************
- *
- * Draw Bitmap 8 BPP
- *
- **********************************************
- */
- #if (LCD_MAX_LOG_COLORS > 16)
- static void _DrawBitLine8BPP(int x, int y, U8 const * p, int xsize, const LCD_PIXELINDEX * pTrans) {
- LCD_PIXELINDEX Pixel;
- switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR)) {
- case 0:
- if (pTrans) {
- for (; xsize > 0; xsize--, x++, p++) {
- Pixel = *p;
- LCD_L0_SetPixelIndex(x, y, *(pTrans + Pixel));
- }
- } else {
- for (; xsize > 0; xsize--, x++, p++) {
- LCD_L0_SetPixelIndex(x, y, *p);
- }
- }
- break;
- case LCD_DRAWMODE_TRANS:
- if (pTrans) {
- for (; xsize > 0; xsize--, x++, p++) {
- Pixel = *p;
- if (Pixel) {
- LCD_L0_SetPixelIndex(x, y, *(pTrans + Pixel));
- }
- }
- } else {
- for (; xsize > 0; xsize--, x++, p++) {
- Pixel = *p;
- if (Pixel) {
- LCD_L0_SetPixelIndex(x, y, Pixel);
- }
- }
- }
- break;
- }
- }
- #endif
- /*********************************************
- *
- * Draw Bitmap 16 BPP
- *
- **********************************************
- */
- #if (LCD_BITSPERPIXEL > 8)
- static void DrawBitLine16BPP(int x, int y, U16 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;
- LCD_L0_SetPixelIndex(x, y, *(pTrans + pixel));
- }
- } else {
- for (;xsize > 0; xsize--, x++, p++) {
- LCD_L0_SetPixelIndex(x, y, *p);
- }
- }
- } else {
- if (pTrans) {
- for (; xsize > 0; xsize--, x++, p++) {
- pixel = *p;
- if (pixel) {
- LCD_L0_SetPixelIndex(x, y, *(pTrans + pixel));
- }
- }
- } else {
- for (; xsize > 0; xsize--, x++, p++) {
- pixel = *p;
- if (pixel) {
- LCD_L0_SetPixelIndex(x, y, pixel);
- }
- }
- }
- }
- }
- #endif
- /*********************************************************************
- *
- * Exported functions
- *
- **********************************************************************
- */
- /*********************************************
- *
- * LCD_L0_SetPixelIndex
- *
- **********************************************
- Purpose:
- Sets the index of the given pixel. The upper layers of emWin
- calling this routine make sure that the coordinates are in range, so
- that no check on the parameters needs to be performed.
- */
- void LCD_L0_SetPixelIndex(int x, int y, int PixelIndex)
- {
- #if 0
- U32 tempC1,tempC2;
- tempC1 = (PixelIndex & 0xff0000)<<3;
- tempC2 = (PixelIndex & 0x00ff00)<<2;
- LCD_BUFFER[y][x>>1] = tempC1 | tempC2 | (PixelIndex << 3);
- #endif
- LCD_BUFFER[y][x] = PixelIndex;
- }
- /*********************************************
- *
- * LCD_L0_GetPixelIndex
- *
- **********************************************
- Purpose:
- Returns the index of the given pixel. The upper layers of emWin
- calling this routine make sure that the coordinates are in range, so
- that no check on the parameters needs to be performed.
- */
- unsigned int LCD_L0_GetPixelIndex(int x, int y)
- {
- #if 0
- unsigned int tempC,tempC1,tempC2;
- tempC1 = (LCD_BUFFER[y][x>>1] & 0xff0000)>>3;
- tempC2 = (LCD_BUFFER[y][x>>1] & 0x00ff00)>>2;
- tempC = tempC1 | tempC2 | ((LCD_BUFFER[y][x>>1] & 0x0000ff)>>3);
- return( tempC );
- #endif
- return LCD_BUFFER[y][x];
- }
- /*********************************************
- *
- * LCD_L0_XorPixel
- *
- **********************************************
- */
- void LCD_L0_XorPixel(int x, int y) {
- LCD_PIXELINDEX PixelIndex = LCD_L0_GetPixelIndex(x, y);
- LCD_L0_SetPixelIndex(x, y, LCD_NUM_COLORS - PixelIndex - 1);
- }
- /*********************************************
- *
- * LCD_L0_DrawHLine
- *
- **********************************************
- */
- void LCD_L0_DrawHLine (int x0, int y, int x1) {
- if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR)
- {
- for (; x0 <= x1; x0++)
- {
- LCD_L0_XorPixel(x0, y);
- }
- }
- else
- {
- for (; x0 <= x1; x0++)
- {
- LCD_L0_SetPixelIndex(x0, y, LCD_COLORINDEX);
- }
- }
- }
- /*********************************************
- *
- * LCD_L0_DrawVLine
- *
- **********************************************
- */
- void LCD_L0_DrawVLine (int x, int y0, int y1) {
- if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
- for (; y0 <= y1; y0++) {
- LCD_L0_XorPixel(x, y0);
- }
- } else {
- for (; y0 <= y1; y0++) {
- LCD_L0_SetPixelIndex(x, y0, LCD_COLORINDEX);
- }
- }
- }
- /*********************************************
- *
- * LCD_L0_FillRect
- *
- **********************************************
- */
- void LCD_L0_FillRect(int x0, int y0, int x1, int y1) {
-
- for (; y0 <= y1; y0++) {
- LCD_L0_DrawHLine(x0, y0, x1);
- }
- }
- /*********************************************
- *
- * 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;
- /* Use _DrawBitLineXBPP */
- for (i=0; i<ysize; i++) {
- switch (BitsPerPixel) {
- case 1:
- _DrawBitLine1BPP(x0, i + y0, pData, Diff, xsize, pTrans);
- break;
- case 2:
- _DrawBitLine2BPP(x0, i + y0, pData, Diff, xsize, pTrans);
- break;
- case 4:
- _DrawBitLine4BPP(x0, i + y0, pData, Diff, xsize, pTrans);
- break;
- case 8:
- _DrawBitLine8BPP(x0, i + y0, pData, xsize, pTrans);
- break;
- case 16:
- DrawBitLine16BPP(x0, i + y0, (const U16 *)pData, xsize, pTrans);
- break;
- }
- pData += BytesPerLine;
- }
- }
- /*********************************************
- *
- * LCD_L0_SetOrg
- *
- **********************************************
- */
- void LCD_L0_SetOrg(int x, int y) {
- GUI_USE_PARA(x);
- GUI_USE_PARA(y);
- }
- /*********************************************
- *
- * LCD_On / LCD_Off
- *
- **********************************************
- */
- void LCD_On (void)
- {
- }
- void LCD_Off (void)
- {
-
- }
- /*********************************************
- *
- * LCD_L0_Init
- *
- **********************************************
- Purpose:
- Initialises the LCD-controller.
- */
- #if 0
- int LCD_L0_Init(void)
- {
- U16 mode = MODE_TFT_16BIT_240320;
- Lcd_Port_Init();
- Lcd_Init(mode);
- Glib_Init(mode);
- Select_Tcon();
- Lcd_PowerEnable(0, 1);
- Lcd_EnvidOnOff(1);
- Glib_ClearScr(0, mode);
- return 0;
- }
- #endif
- void LCD_L0_ReInit(void) {
- LCD_INIT_CONTROLLER(); /* macro defined in config */
- }
- /*********************************************
- *
- * LCD_L0_SetLUTEntry
- *
- **********************************************
- */
- void LCD_L0_SetLUTEntry(U8 Pos, LCD_COLOR Color) {
- GUI_USE_PARA(Pos);
- GUI_USE_PARA(Color);
- }
- ///////from here it is myself define
- /**************************************************************
- 320×240 16Bpp TFT LCD功能模块初始化
- **************************************************************/
- void Lcd_Init(void )
- {
- rGPCUP = 0x00000000;
- rGPCCON = 0xaaaa02a9;
-
- // rGPDUP=0xffffffff; // Disable Pull-up register
- rGPDUP = 0x00000000;
- rGPDCON=0xaaaaaaaa; //Initialize VD[15:8]
- rLCDCON1=(CLKVAL_TFT<<8)|(MVAL_USED<<7)|(3<<5)|(12<<1)|0;
- // TFT LCD panel,16bpp TFT,ENVID=off
- rLCDCON2=(VBPD<<24)|(LINEVAL_TFT<<14)|(VFPD<<6)|(VSPW);
- rLCDCON3=(HBPD<<19)|(HOZVAL_TFT<<8)|(HFPD);
- rLCDCON4=(MVAL<<8)|(HSPW);
- #if LCD_TYPE==LCD_TYPE_VGA1024x768
- rLCDCON5=(1<<11)|(0<<9)|(0<<8)|(0<<3)|(1<<0);
- #else
- rLCDCON5 = (1<<11) | (1<<10) | (1<<9) | (1<<8) | (0<<7) | (0<<6)
- | (1<<3) |(BSWP<<1) | (HWSWP);
- //5:6:5 VCLK posedge BSWP=0,HWSWP=1;
- #endif
- rLCDSADDR1=(((U32)LCD_BUFFER>>22)<<21)|M5D((U32)LCD_BUFFER>>1);
- rLCDSADDR2=M5D( ((U32)LCD_BUFFER+(SCR_XSIZE_TFT*LCD_TFT_YSIZE*2))>>1 );
- rLCDSADDR3=(((SCR_XSIZE_TFT-LCD_TFT_XSIZE)/1)<<11)|(LCD_TFT_XSIZE/1);
- rLCDINTMSK|=(3); // MASK LCD Sub Interrupt
- rTCONSEL &= (~7) ; // Disable LPC3480
- rTPAL=0; // Disable Temp Palette
- }
- /**************************************************************
- LCD视频和控制信号输出或者停止,1开启视频输出
- **************************************************************/
- void Lcd_EnvidOnOff(int onoff)
- {
- if(onoff==1)
- rLCDCON1|=1; // ENVID=ON
- else
- rLCDCON1 =rLCDCON1 & 0x3fffe; // ENVID Off
- }
- /**************************************************************
- 320×240 16Bpp TFT LCD 电源控制引脚使能
- **************************************************************/
- void Lcd_PowerEnable(int invpwren,int pwren)
- {
- //GPG4 is setted as LCD_PWREN
- rGPGUP=rGPGUP&(~(1<<4))|(1<<4); // Pull-up disable
- rGPGCON=rGPGCON&(~(3<<8))|(3<<8); //GPG4=LCD_PWREN
- rGPGDAT = rGPGDAT | (1<<4) ;
- // invpwren=pwren;
- //Enable LCD POWER ENABLE Function
- rLCDCON5=rLCDCON5&(~(1<<3))|(pwren<<3); // PWREN
- rLCDCON5=rLCDCON5&(~(1<<5))|(invpwren<<5); // INVPWREN
- }
- /**************************************************************
- 240×320 16Bpp TFT LCD全屏填充特定颜色单元或清屏
- **************************************************************/
- void Lcd_ClearScr( U16 c)
- {
- unsigned int x,y ;
-
- for( y = 0 ; y < SCR_YSIZE_TFT_240320 ; y++ )
- {
- for( x = 0 ; x < SCR_XSIZE_TFT_240320 ; x++ )
- {
- LCD_BUFFER[y][x] = c ;
- }
- }
- }
- int LCD_L0_Init(void)
- {
- Lcd_Init();
- Lcd_PowerEnable(0, 1);
- Lcd_EnvidOnOff(1); //turn on vedio
- Lcd_ClearScr( (0x00<<11) | (0x00<<5) | (0x00) );
- return 0;
- }