⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd_tft6448.c

📁 uc/GUI移植TFT6448底层驱动。
💻 C
📖 第 1 页 / 共 2 页
字号:
/*********************************************************************
;;;
;;; 模 块 名:LCD_TFT6448.C
;;; 功    能:LCD控制器驱动,用于支持uC_GUI
;;; 参数说明:
;;; 设    计:Zhanghua             日    期:2006-02-27
;;; 修    改:                     日    期: 
**********************************************************************/ 
 
#include "LCD_Private.h"                        /* private modul definitions & config */
#include "GUI_Private.h"
#include "GUIDebug.h"

#include "LCDConf.H"
#include "gpio.h"
#include "sleep.h"
#include "lcd_fonts.h"

#ifndef LCDCONF_H
#define LCDCONF_H
#endif

#define TRUE   1
#define FALSE  0

#define page  0x00  
//#if (LCD_CONTROLLER == 0 ) && (!defined(WIN32) | defined(LCD_SIMCONTROLLER))
#define LCD_ADD_WR_CMD(color)    *((volatile UINT16 *)0x64000000) = (color)
#define LCD_ADD_WR_X(xdata)      *((volatile UINT16 *)0x64000002) = (xdata)
#define LCD_ADD_WR_Y(ydata)      *((volatile UINT16 *)0x64000004) = (ydata)
#define LCD_ADD_WR_RX(xdata)     *((volatile UINT16 *)0x64000006) = (xdata)
#define LCD_ADD_RD_CMD(color)    (UINT8)color=*((volatile UINT16 *)0x64000000)
#define LCD_ADD_RD_X(xdata)      (UINT16)xdata=*((volatile UINT16 *)0x64000002)

#define	LCD_RESET_BUSY()		GPIO_ModeConfig(GPIO1,15,GPIO_IPUPD)
#define	LCD_READ_BUSY()         GPIO_ReadBit(GPIO1,15)
//初始化及显示控制组
int  LCD_L0_Init(void);
void LCD_L0_ReInit(void);
void LCD_L0_Off(void);
void LCD_L0_On(void);
//绘制组
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);
void LCD_L0_DrawHLine(int x0,int y,int x1);
void LCD_L0_DrawPixel(int x,int y);
void LCD_L0_DrawVLine  (int x, int y0,  int y1);            //上层调用的画竖线函数
void LCD_L0_FillRect(int x0, int y0, int x1, int y1);       //上层调用的画矩型函数
void LCD_L0_SetPixelIndex(int x, int y, int ColorIndex);    //上层调用的画点函数
void LCD_L0_XorPixel(int x, int y);                         //上层调用的异或函数
//get组
unsigned int LCD_L0_GetPixelIndex(int x, int y);            //上层调用的取点函数
void LCD_L0_SetLUTEntry(U8 Pos, LCD_COLOR color);									   	
/*
*********************************************************
*                                                       *
*           Compiler specific settings                  *
*                                                       *
*********************************************************

*/
#ifdef WIN32   /* Avoid warnings in MS-compiler */
  	#pragma warning(disable : 4244)  // warning C4244: '=' : conversion from 'long ' to 'unsigned char ', possible loss of data
  	#pragma warning(disable : 4761)  // warning C4761: integral size mismatch in argument; conversion supplied
#endif


//*********************************************************************
//#define TFT640x480
void SetPixel(int x, int y, LCD_COLOR c){
	U8 Colortemp=0;
 if((x < LCD_XSIZE) && ( y < LCD_YSIZE))
 {  
     LCD_ADD_WR_X(page);
     ns_sleep(5);
	 LCD_ADD_RD_X(Colortemp);
	 ns_sleep(5);
     LCD_ADD_WR_Y((y>>8));
     ns_sleep(5);
     LCD_ADD_WR_Y(y);
     ns_sleep(5);
     LCD_ADD_WR_X((x>>8));
     ns_sleep(5);
     LCD_ADD_WR_X(x);
     ns_sleep(5);
     LCD_ADD_WR_CMD(c);
     ns_sleep(5);
 }  
}
unsigned int GetPixelIndex(int x,int y){
    volatile UINT8 Colortemp=0;
    if((x <LCD_XSIZE) && (y < LCD_YSIZE))
	{
	   LCD_ADD_WR_X(page);
       ns_sleep(5);
	   LCD_ADD_RD_X(Colortemp);
	   ns_sleep(5);
	   LCD_ADD_WR_Y((y>>8));
       ns_sleep(5);
       LCD_ADD_WR_Y(y);
       ns_sleep(5);
       LCD_ADD_WR_RX((x>>8));
       ns_sleep(5);
       LCD_ADD_WR_RX(x);
       ns_sleep(5);
       LCD_ADD_WR_CMD(Colortemp);
       ns_sleep(5);	 
    }
    return  Colortemp;
}
void XorPixel(int x,int y){
    volatile UINT16 Colortemp=0;
    Colortemp=(UINT16)GetPixelIndex(x,y);
    Colortemp=0x00ff-Colortemp-1;
    SetPixel(x,y,Colortemp);
}
/*********************************************************************
;;;
;;; 函 数 名:LCD_L0_DrawPixel
;;; 功    能:将屏幕上指定的点设置成指定的颜色
;;; 说    明:
;;; 入口参数:
;;; 出口参数:
;;; 设    计:Zhanghua             日    期:2007-06-22
;;; 修    改:                     日    期: 
**********************************************************************/	
void LCD_L0_DrawPixel(int x,int y){
   SetPixel(x,y,LCD_COLORINDEX); 
}

/*********************************************************************
;;;
;;; 函 数 名:LCD_L0_XorPixel/LCD_L0_SetPixelIndex
;;; 功    能:由ewin调用
;;; 说    明:
;;; 入口参数:
;;; 出口参数:
;;; 设    计:Zhanghua             日    期:2006-02-27
;;; 修    改:                     日    期: 
**********************************************************************/
void LCD_L0_XorPixel(int x, int y){
	XorPixel(x,y);
}	

void LCD_L0_SetPixelIndex(int x, int y, int ColorIndex) {
  	SetPixel(x,y,(LCD_COLOR)ColorIndex);
}

/*********************************************************************
;;;
;;; 函 数 名:LCD_L0_DrawHLine
;;; 功    能:画水平线
;;; 说    明:
;;; 入口参数:
;;; 出口参数:
;;; 设    计:Zhanghua             日    期:2006-02-27
;;; 修    改:                     日    期: 
**********************************************************************/
void LCD_L0_DrawHLine(int x0, int y, int x1)
{
	if(GUI_Context.DrawMode & LCD_DRAWMODE_XOR)
	 {
    for (; x0 <= x1; x0++) {
     		XorPixel(x0, y);
       }
     } else {
              for (; x0 <= x1; x0++) {
     		    SetPixel(x0, y, LCD_COLORINDEX);
	  		}
	  }
}

/*********************************************************************
;;;
;;; 函 数 名: LCD_L0_DrawVLine
;;; 功    能:画垂直线
;;; 说    明:
;;; 入口参数:
;;; 出口参数:
;;; 设    计:Zhanghua             日    期:2006-02-27
;;; 修    改:                     日    期: 
**********************************************************************/
void LCD_L0_DrawVLine  (int x, int y0,  int y1) {
  if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
    for (; y0 <= y1; y0++) {
       XorPixel(x, y0);
    }
  } else {
    for (; y0 <= y1; y0++) {
      SetPixel(x, y0, LCD_COLORINDEX);
    }
  }
} 	 	  	 	
	
		
/*********************************************************************
;;;
;;; 函 数 名:LCD_L0_FillRect
;;; 功    能:填充一个矩形区域
;;; 说    明:
;;; 入口参数:
;;; 出口参数:
;;; 设    计:Zhanghua             日    期:2006-02-27
;;; 修    改:                     日    期: 
**********************************************************************/
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
}	  		   		
	
/*********************************************************************
;;;
;;; 函 数 名:DrawBitLine1BPP
;;; 功    能:画1bit位图
;;; 说    明:
;;; 入口参数:
;;; 出口参数:
;;; 设    计:Zhanghua             日    期:2006-02-27
;;; 修    改:                     日    期: 
**********************************************************************/
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;
	}
}


/*********************************************************************
;;;
;;; 函 数 名:DrawBitLine2BPP
;;; 功    能:画2bit位图
;;; 说    明:
;;; 入口参数:
;;; 出口参数:
;;; 设    计:Zhanghua             日    期:2006-02-27
;;; 修    改:                     日    期: 
**********************************************************************/
#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:
  LCD_L0_SetPixelIndex(x+0, y, *(pTrans+(pixels>>6)));
  if (!--xsize)
    return;
WriteBit1:
  LCD_L0_SetPixelIndex(x+1, y, *(pTrans+(3&(pixels>>4))));
  if (!--xsize)
    return;
WriteBit2:
  LCD_L0_SetPixelIndex(x+2, y, *(pTrans+(3&(pixels>>2))));
  if (!--xsize)
    return;
WriteBit3:
  LCD_L0_SetPixelIndex(x+3, y, *(pTrans+(3&(pixels))));
  if (!--xsize)
    return;
  pixels = *(++p);
  x+=4;
  goto WriteBit0;
/*
        Write with transparency
*/
WriteTBit0:
  if (pixels&(3<<6))
    LCD_L0_SetPixelIndex(x+0, y, *(pTrans+(pixels>>6)));
  if (!--xsize)
    return;
WriteTBit1:
  if (pixels&(3<<4))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -