//#include <string.h>
#include "lcd.h"
#include "data.h"
#include "delay.h"
//#include "pit.h"
#include "w25qxx.h"
#include "w25n01.h"
#include "uart.h"
#include "rtc.h"
#include "rtp.h"
#include "font.h"
#include "eport_drv.h"
#include "wav_dac.h"
#include "wav_pit.h"
#include "ccm_drv.h" 
#include "spi_drv.h"
#include "uart_drv.h"
#include "pwm_drv.h"
#include "trans_port.h"


#include "lt268_gra.h"

UINT8  TFTinfo[50]={0};

/*
* 函数名：Rx_CRC_CCITT
* 功能  ：CRC校验
* 输入  ：buf：数据缓存首地址
          len：数据长度
* 输出  ：无
* 作者  ：LEVETOP
*/
UINT16 Rx_CRC_CCITT(UINT8 *puchMsg, UINT16 usDataLen)
{
	UINT16 wCRCin = 0x0000;
	UINT16 wCPoly = 0x1021;
	UINT8 wChar = 0;
	int i;
	while (usDataLen--)
	{
		wChar = *(puchMsg++);
		wCRCin ^= (wChar << 8);
		for (i = 0; i < 8; i++)
		{
			if (wCRCin & 0x8000)
				wCRCin = (wCRCin << 1) ^ wCPoly;
			else
				wCRCin = wCRCin << 1;
		}
	}
	return (wCRCin&0xffff);
}


/*
* 函数名：LT_CalculateCmdAddr
* 功能  ：读取该命令的信息，并将其拆分成该命令结构体所对应的各个信息
* 输入  ：cmd：指令
          operand：操作数
* 输出  ：无
* 作者  ：LEVETOP
*/
/*
void LT_TFT_GetInfo(void)
{
	UINT32 rate=0;
	
	LT_ReadFlash(TFTinfo,0x400,50);
	
	rate=((TFTinfo[2]<<16)|(TFTinfo[3]<<8)|(TFTinfo[4]));
	
	if(rate == 0x00FFFFFF || rate == 0)
	{
//		init_ok_flag = 1;

		gBaudrate = 115200;
		LCD_XSIZE_TFT = 480;
		LCD_YSIZE_TFT = 480;
	}
	else
	{
//		init_ok_flag = 0;
		
		gBaudrate = rate;

		LCD_XSIZE_TFT = (TFTinfo[10]<<8) + TFTinfo[11];
		LCD_YSIZE_TFT = (TFTinfo[12]<<8) + TFTinfo[13];
		
		R_angle=TFTinfo[42];

		if(TFTinfo[43] != 0xFF && TFTinfo[44] != 0xFF && TFTinfo[45] != 0xFF && TFTinfo[46] != 0xFF)
		{
			Frameend[0] = TFTinfo[43];   
			Frameend[1] = TFTinfo[44];   
			Frameend[2] = TFTinfo[45];   
			Frameend[3] = TFTinfo[46];   
		}
		
		LCD_XSIZE_TFT = LCD_SIZE_X;
		LCD_YSIZE_TFT = LCD_SIZE_Y;	
		
//		init_ok_flag = 0;
	}
}
*/

void LCD_SPI_Port_Init(void)
{
	SPI_InitTypeDef SPI_InitStruct;
	SPI_InitStruct.SPI_Mode = SPI_Mode_Master;
	SPI_InitStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
	SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;          
	SPI_InitStruct.SPI_CPHA = SPI_CPHA_1Edge;
	SPI_InitStruct.SPI_CPOL = SPI_CPOL_Low;
	SPI_InitStruct.SPI_DataSize = SPI_DataSize_8b;
	SPI_InitStruct.SPI_FirstBit = SPI_FirstBit_MSB;
	
	SPI_Init(SPI3,&SPI_InitStruct);
	
	//PWM[1]/GINT[13]
	PWM_INPUT_OUTPUT_EN;
	PWM_ConfigGpio(PWM_PORT1,GPIO_OUTPUT,PWM_PULLUP_EN); //RST
	PWM_WriteGpioData(PWM_PORT1,Bit_SET);
	//PWM[0]/GINT[12]
	PWM_INPUT_OUTPUT_EN;
	PWM_ConfigGpio(PWM_PORT0,GPIO_OUTPUT,PWM_PULLUP_EN); //CS
	PWM_WriteGpioData(PWM_PORT0,Bit_SET);	
	
	EPORT_ConfigGpio(EPORT_PIN7, GPIO_OUTPUT);  			//RS/A0
	EPORT_WriteGpioData(EPORT_PIN7, Bit_SET);	
	
	//DMA_Init(DMA1_BASE_ADDR);                  
//	m_dma_control->DMA_CONFIG = 1;
	SPI3->SPIDMACR &= (~0x03);	//禁止SPI TX RX的DMA	
}

UINT8 LCD_SPI_ReadWriteByte(UINT8 Send)
{
	 UINT8 ucTemp = 0;
	 while(((SPI3->SPISRHW)&(SPISR_TXFFULL_MASK)));
	 SPI3->SPIDR = Send;
	 while(!(0x80 & SPI3->SPISR));
	 while(((SPI3->SPISRHW) & (SPISR_RXFEMP_MASK)));
	 ucTemp = SPI3->SPIDR;
	 return ucTemp;
	
/*
	//模拟spi
	UINT8 i,ucTemp;
	for(i=0;i<8;i++)
	{
		if(Send&0x80)LCD_SDA_SET;
		else        LCD_SDA_RESET;
		
		Send<<=1;
		DelayUS(1);
		LCD_CLK_SET;
		ucTemp<<=1;
		if(LCD_SDA) ucTemp++;
		LCD_CLK_RESET;
		
		DelayUS(1);
	}
	return ucTemp;
	*/
}

void LCD_PPI_Port_Init(void)
{
	#if LT268A_DATABIT_8

	//PWM[1]/GINT[13]               
	PWM_INPUT_OUTPUT_EN;
	PWM_ConfigGpio(PWM_PORT1,GPIO_OUTPUT,PWM_PULLUP_EN); //RST			/*全部设置成输出*/
	PWM_WriteGpioData(PWM_PORT1,Bit_SET);
	
	//PWM[0]/GINT[12]
	PWM_INPUT_OUTPUT_EN;
	PWM_ConfigGpio(PWM_PORT0,GPIO_OUTPUT,PWM_PULLUP_EN); //CS
	PWM_WriteGpioData(PWM_PORT0,Bit_SET);	

	EPORT_ConfigGpio(EPORT_PIN7, GPIO_OUTPUT);  			//RS
	EPORT_WriteGpioData(EPORT_PIN7, Bit_SET);
	
	SPI_ConfigGpio(SPI3,SPI_MOSI, GPIO_OUTPUT);				//RD
	SPI_WriteGpioData(SPI3,SPI_MOSI, Bit_SET);
	
	SPI_ConfigGpio(SPI3,SPI_SCK, GPIO_OUTPUT);				//WR
	SPI_WriteGpioData(SPI3,SPI_SCK, Bit_SET);
	
	EPORT_ConfigGpio(EPORT_PIN24, GPIO_OUTPUT); //DB0
	EPORT_ConfigGpio(EPORT_PIN25, GPIO_OUTPUT); //DB0
	EPORT_ConfigGpio(EPORT_PIN26, GPIO_OUTPUT); //DB0
	EPORT_ConfigGpio(EPORT_PIN27, GPIO_OUTPUT); //DB0
	EPORT_ConfigGpio(EPORT_PIN28, GPIO_OUTPUT); //DB0
	EPORT_ConfigGpio(EPORT_PIN29, GPIO_OUTPUT); //DB0
	EPORT_ConfigGpio(EPORT_PIN30, GPIO_OUTPUT); //DB0
	EPORT_ConfigGpio(EPORT_PIN31, GPIO_OUTPUT); //DB0

	EPORT3->EPDDR  = 0xFF;  //DB0-DB7
	EPORT3->EPPUER = 0xFF;
	EPORT3->EPDR   = 0x00;
	#endif
	
	#if LT268A_DATABIT_16
	
	#endif
}

void TFT_CommandWrite(UINT8 cmd)
{
	#if	LT268A_SPI
		LCD_RS_Command;
		LCD_CS_RESET;
		LCD_SPI_ReadWriteByte(cmd);
		LCD_CS_SET;
	#endif

	#if	LT268A_PPI
		LCD_RD_SET;
		LCD_RS_Command;
		LCD_CS_RESET;

		LCD_data_pin_L = cmd;
		LCD_WR_RESET;
		LCD_WR_SET;
		LCD_CS_SET;
	#endif
}

void TFT_DataWrite(UINT8 data)
{
	#if	LT268A_SPI
		LCD_RS_Data;
		LCD_CS_RESET;
		LCD_SPI_ReadWriteByte(data);
		LCD_CS_SET;
	#endif

	#if	LT268A_PPI
		LCD_RD_SET;
		LCD_RS_Data;
		LCD_CS_RESET;

		LCD_data_pin_L = data;
		LCD_WR_RESET;
		LCD_WR_SET;
		LCD_CS_SET;
	#endif
}

UINT32 TFT_DataReadID(void)
{
#if LT268A_PPI

	#if LT268A_DATABIT_8
	UINT32 Val=0;
	UINT8 dey=1;

	LCD_CS_RESET;
	LCD_RD_SET;	
	LCD_RS_Command;	
	LCD_data_pin_L = 0xD3;	  //reg = 0xD3
	LCD_WR_RESET;	
	LCD_WR_SET;	
		
	LCD_RS_Data;	
	LCD_data_pin_input;
	LCD_data_pin_L =0xFF;	
		
	LCD_RD_RESET;	       //dummy
	DelayMS(dey);
	LCD_RD_SET;	

	LCD_RD_RESET;	
	DelayMS(dey);
	LCD_RD_SET;		
	Val |= ((LCD_data_pin_read)<<24);	

	LCD_RD_RESET;	
	DelayMS(dey);
	LCD_RD_SET;		
	Val |= ((LCD_data_pin_read)<<16);	

	LCD_RD_RESET;	
	DelayMS(dey);
	LCD_RD_SET;		
	Val |= ((LCD_data_pin_read)<<8);	
		
	LCD_RD_RESET;	
	DelayMS(dey);
	LCD_RD_SET;		
	Val |= (LCD_data_pin_read);	

	LCD_CS_SET;	
		
	LCD_data_pin_output;	
	return Val;
	#endif
#endif
}

void LCD_Init(u8 lcdType,u16 pixelX,u16 pixelY)
{
	LCD_XSIZE_TFT = pixelX;
	LCD_YSIZE_TFT = pixelY;

	// Use PPI
	if (lcdType==LT268A_SPI) LCD_SPI_Port_Init();
	else LCD_PPI_Port_Init();

	
	LCD_RST_SET;              //RST
	DelayMS(10);
	LCD_RST_RESET;
	DelayMS(10);
	LCD_RST_SET;
	DelayMS(120); //Delay 120ms

/*屏的初始化代码部分，Horizontal_screen部分为设置横竖屏，此处需根据实际情况调整*/
	TFT_CommandWrite(0x11);
	DelayMS(150);

	TFT_CommandWrite(0xf0);
	TFT_DataWrite(0xc3);

	TFT_CommandWrite(0xf0);
	TFT_DataWrite(0x96);

	TFT_CommandWrite(0x36);

#if SCREEN_ORIENTATION == LANDSCAPE
	TFT_DataWrite(0xA0);	   			 //无标签 0=0x00 1=0x60  2=0xC0 3=0xA0 	   
#else								   						// 标签 : 0=0x48 1=0x08  2=0x08 3=0xE8 
	TFT_DataWrite(0x00);	
#endif
	
	TFT_CommandWrite(0x3A);
	TFT_DataWrite(0x55);

	TFT_CommandWrite(0xb4);
	TFT_DataWrite(0x01);

	TFT_CommandWrite(0xb7);
	TFT_DataWrite(0xc6);

	TFT_CommandWrite(0xe8);
	TFT_DataWrite(0x40);
	TFT_DataWrite(0x8a);
	TFT_DataWrite(0x00);
	TFT_DataWrite(0x00);
	TFT_DataWrite(0x29);
	TFT_DataWrite(0x19);
	TFT_DataWrite(0xa5);
	TFT_DataWrite(0x33);

	TFT_CommandWrite(0xc1);
	TFT_DataWrite(0x06);

	TFT_CommandWrite(0xc2);
	TFT_DataWrite(0xa7);

	TFT_CommandWrite(0xc5);
	TFT_DataWrite(0x18);
	
	TFT_CommandWrite(0xc6);               //Frame Rate Control in Normal Mode
	TFT_DataWrite(0x0f);
//	TFT_CommandWrite(0xc6);
//	TFT_DataWrite(0x01);
//	TFT_CommandWrite(0x35);                 //TE
//	TFT_DataWrite(0x00);
//	TFT_CommandWrite(0x44);                 //TE line
//	TFT_DataWrite(0x00);
//	TFT_DataWrite(0x40);

	TFT_CommandWrite(0xe0);
	TFT_DataWrite(0xf0);
	TFT_DataWrite(0x09);
	TFT_DataWrite(0x0b);
	TFT_DataWrite(0x06);
	TFT_DataWrite(0x04);
	TFT_DataWrite(0x15);
	TFT_DataWrite(0x2f);
	TFT_DataWrite(0x54);
	TFT_DataWrite(0x42);
	TFT_DataWrite(0x3c);
	TFT_DataWrite(0x17);
	TFT_DataWrite(0x14);
	TFT_DataWrite(0x18);
	TFT_DataWrite(0x1b);

	TFT_CommandWrite(0xe1);
	TFT_DataWrite(0xf0);
	TFT_DataWrite(0x09);
	TFT_DataWrite(0x0b);
	TFT_DataWrite(0x06);
	TFT_DataWrite(0x04);
	TFT_DataWrite(0x03);
	TFT_DataWrite(0x2d);
	TFT_DataWrite(0x43);
	TFT_DataWrite(0x42);
	TFT_DataWrite(0x3b);
	TFT_DataWrite(0x16);
	TFT_DataWrite(0x14);
	TFT_DataWrite(0x17);
	TFT_DataWrite(0x1b);

	TFT_CommandWrite(0xf0);
	TFT_DataWrite(0x3c);

	TFT_CommandWrite(0xf0);
	TFT_DataWrite(0x69);

//	TFT_CommandWrite(0x21);//如果黑白颜色反掉了，就把此行屏蔽掉

	DelayMS(150);
	TFT_CommandWrite(0x29);

	TFT_CommandWrite(0x2c);
}

//------------------------设定窗口----------------------------------------------------------
#define XSoff	 	0       		//X轴： XSoff = 起始偏移  ，XSoff = 终点偏移
#define XEoff 		0
#define YSoff	    0				//Y轴： YSoff = 起始偏移  ，YEoff = 终点偏移
#define YEoff 		0

void LT268_TFT_SetWindows(UINT16 XStar,UINT16 yStar,UINT16 Width,UINT16 High)
{
	UINT16 XS,XE,YS,YE;
	XS=XStar+XSoff;  	XE=XStar+XEoff+Width-1;
	YS=yStar+YSoff;  	YE=yStar+YEoff+High-1;
	
	/*-适用驱动IC : ST7789、ILI9341、、、等 -*/
	TFT_CommandWrite(0x2A);
	TFT_DataWrite(XS>>8);
	TFT_DataWrite(XS);
	TFT_DataWrite(XE>>8);
	TFT_DataWrite(XE);

	TFT_CommandWrite(0x2B);
	TFT_DataWrite(YS>>8);
	TFT_DataWrite(YS);
	TFT_DataWrite(YE>>8);
	TFT_DataWrite(YE);

	TFT_CommandWrite(0x2c);


}

//---------------------TFT Sleep Mode----------------------
void ST7789VPanelSleepInMode(void)
{
	TFT_CommandWrite(0x28);
	TFT_CommandWrite(0x10);
	DelayMS(120);
}

//---------------------TFT Sleep Out----------------------
void ST7789VPanelSleepOutMode(void)
{
	TFT_CommandWrite(0x11);
	DelayMS(120);
	TFT_CommandWrite(0x29);
}
//---------------------TFT display on/off ----------------------
void LT268_Display_ON(void)
{
	TFT_CommandWrite(0x29);
}
void LT268_Display_OFF(void)
{
	TFT_CommandWrite(0x28);
}

//--------------------LCD_PIN_TEST--------------------------------
void LCD_PIN_TEST(void)
{
	while(1)
	{
#if	LT268A_PPI
		LCD_RST_SET;
		LCD_CS_SET;
		LCD_WR_SET;
		LCD_RD_SET;
		LCD_RS_Data;
		LCD_data_pin_L = 0xff;
		DelayMS(1000);

		LCD_RST_RESET;
		LCD_CS_RESET;
		LCD_WR_RESET;
		LCD_RD_RESET;
		LCD_RS_Command;
		LCD_data_pin_L = 0x00;
		DelayMS(1000);
#endif

	}
}

//----------------------------------------------------------------------2D??-------------------------------------------------------------------
/*??*/
//x,y:??
//color:??
void LT268_TFT_DrawPoint(UINT16 x,UINT16 y,UINT16 color)
{
	LT268_TFT_SetWindows(x,y,1,1);
	LCD_RS_Data;
	LCD_CS_RESET;
	
//	TFT_Data_Tran(((UINT8*)&color),2);
	TFT_Data_Tran2(color,1);

	LCD_CS_SET;	
}

//x1,y1:??1
//x2,y2:??2
//color:??
void LT268_TFT_DrawLine(UINT16 x1,UINT16 y1,UINT16 x2,UINT16 y2,UINT16 color)
{
	UINT16 t;
	int xerr=0,yerr=0,delta_x,delta_y,distance;
	int incx,incy,uRow,uCol;
	delta_x=x2-x1; //??????
	delta_y=y2-y1;
	uRow=x1;
	uCol=y1;
	if(delta_x>0)incx=1; //??????
	else if(delta_x==0)incx=0;//???
	else {incx=-1;delta_x=-delta_x;}

	if(delta_y>0)incy=1;
	else if(delta_y==0)incy=0;//???
	else{incy=-1;delta_y=-delta_y;}

	if( delta_x>delta_y)distance=delta_x; //?????????
	else distance=delta_y;
	for(t=0;t<=distance+1;t++ )//????
	{
		LT268_TFT_DrawPoint(uRow,uCol,color);//??
		xerr+=delta_x ;
		yerr+=delta_y ;
		if(xerr>distance)
		{
			xerr-=distance;
			uRow+=incx;
		}
		if(yerr>distance)
		{
			yerr-=distance;
			uCol+=incy;
		}
	}
}

void _draw_circle_8(int xc, int yc, int x, int y, UINT16 color)
{
	LT268_TFT_DrawPoint(xc + x, yc + y, color);
	LT268_TFT_DrawPoint(xc - x, yc + y, color);
	LT268_TFT_DrawPoint(xc + x, yc - y, color);
	LT268_TFT_DrawPoint(xc - x, yc - y, color);
	LT268_TFT_DrawPoint(xc + y, yc + x, color);
	LT268_TFT_DrawPoint(xc - y, yc + x, color);
	LT268_TFT_DrawPoint(xc + y, yc - x, color);
	LT268_TFT_DrawPoint(xc - y, yc - x, color);
}

/*?????*/
//xc,yc:??
//r:???
//color:??
void LT268_TFT_DrawCircle(UINT16 xc, UINT16 yc, UINT16 r, UINT16 color)
{
	int x = 0, y = r, d;
	d = 3 - 2 * r;

	while (x <= y) {
		_draw_circle_8(xc, yc, x, y, color);
		if (d < 0) {
			d = d + 4 * x + 6;
		} else {
			d = d + 4 * (x - y) + 10;
			y--;
		}
		x++;
	}
}

/*????????*/
//x,y:??
//Width:??
//High:??
//color:??
void LT268_TFT_FillColor(UINT16 x,UINT16 y,UINT16 Width,UINT16 High,UINT16 color)
{
//	UINT32 i=0;

	LT268_TFT_SetWindows(x,y,Width,High);
	//LCD_RD_SET;
	LCD_RS_Data;
	LCD_CS_RESET;

	TFT_Data_Tran2(color,Width*High);
	
	LCD_CS_SET;
}


void LT268_TFT_DrawPoint_Buffer(UINT16 x,UINT16 y,UINT16 color,UINT16 canvas_w)
{
	if(y*2*canvas_w+2*x+1 < MAX_PixelSize - 1)
	{
		m_PngData[y*2*canvas_w+2*x+1] = color>>8;
		m_PngData[y*2*canvas_w+2*x] = color;
	}
}

/*????????*/
//x,y:??
//Width:??
//High:??
//color:??
void LT268_TFT_FillColor_Buffer(UINT16 x,UINT16 y,UINT16 Width,UINT16 High,UINT16 color,UINT16 canvas_w)
{
	UINT32 j,k;
	
//	if(x==0&&y==0&&Width==canvas_w)
//	{
//		for(j=0;j<Width*High;j++)
//			p16_m_PngData[j] = color;
//	}
//	else
//	{
		for(j=0;j<High;j++)
		{
			for(k=0;k<Width;k++)
			{
				p16_m_PngData[(y+j)*canvas_w+x+k] = color;
			}
		}
//	}
	
}

/*?????*/
//x1,y1:??1
//x2,y2:??2
//color:??
void LT268_TFT_DrawSquare_Fill(UINT16 x1,UINT16 y1,UINT16 x2,UINT16 y2,UINT16 color)
{
	UINT16 temp=0;
	if(y1>y2)
	{
		temp=y1;
		y1=y2;
		y2=temp;
	}
	if(x1>x2)
	{
		temp=x1;
		x1=x2;
		x2=temp;
	}
	LT268_TFT_FillColor(x1,y1,x2-x1+1,y2-y1+1,color);
}

UINT8 LT268_pic_to_buffer                
(
UINT16 buff_x, UINT16 buff_y, UINT16 buff_w, UINT8 *m_Data,    
UINT16 pic_x,  UINT16 pic_y,  UINT16 pic_w,  UINT32 pic_addr,
UINT16 Width,  UINT16 High,   UINT8  Cflag 
)
{
	UINT16 i,j;
	UINT32 Pic_addr=0;
	UINT16 count,count_1;
//	UINT32 R1_val,G1_val,B1_val,A1_val=15;
//	UINT32 R0_val=0,G0_val=0,B0_val=0;
//	UINT32 R2_val,G2_val,B2_val;
	
//	UINT16 *p16_m_Data;
	
	if((Width*High*2)>MAX_PixelSize)  return 0;	

//	p16_m_Data=(UINT16 *)m_Data;
	
	count=Width*2/DMA_LEN2;
	count_1=(Width*2)%DMA_LEN2;
	
	if(Cflag==0)
	{
		for(j=0;j<High;j++)
		{
			Pic_addr=pic_addr+pic_x*2+(pic_y+j)*pic_w*2;
			for(i=0;i<count;i++)
			{
				LT_ReadFlash(DMA_rxbuf1 ,Pic_addr+i*DMA_LEN2, DMA_LEN2);
//				for(k=1;k<=DMA_LEN2/2;k++)
//				{
//					m_Data[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-1] = DMA_rxbuf1[2*k-1];
//					m_Data[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-2] = DMA_rxbuf1[2*k-2];
//				}
//				pos=buff_x+buff_y*buff_w+j*buff_w+DMA_LEN2/2*i;
//				for(k=0;k<DMA_LEN2/2;k++)
//				{
//					p16_m_Data[pos+k] = p16_DMA_rxbuf1[k];
//				}
				
				LT_ReadFlash_DMA(&m_PngData[(buff_x+buff_y*buff_w+j*buff_w+DMA_LEN2*i)*2] ,Pic_addr+i*DMA_LEN2, DMA_LEN2);

			}
			if(count_1!=0)
			{
				LT_ReadFlash(DMA_rxbuf1 ,Pic_addr+i*DMA_LEN2, count_1);
//				for(k=1;k<=(count_1/2);k++)
//				{
//					m_Data[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-1] = DMA_rxbuf1[2*k-1];
//					m_Data[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-2] = DMA_rxbuf1[2*k-2];
//				}
//				pos=buff_x+buff_y*buff_w+j*buff_w+DMA_LEN2/2*i;
//				for(k=0;k<count_1/2;k++)
//				{
//					p16_m_Data[pos+k] = p16_DMA_rxbuf1[k];
//				}
				LT_ReadFlash_DMA(&m_PngData[(buff_x+buff_y*buff_w+j*buff_w+DMA_LEN2*i)*2] ,Pic_addr+i*DMA_LEN2, count_1);

			}
		}
	}
	
/*	
	else if(Cflag==1)
	{
		for(j=0;j<High;j++)
		{
			Pic_addr=pic_addr+pic_x*2+(pic_y+j)*pic_w*2;
			for(i=0;i<count;i++)
			{
				LT_ReadFlash(DMA_rxbuf1 ,Pic_addr+i*DMA_LEN2, DMA_LEN2);
				for(k=1;k<=DMA_LEN2/2;k++)
				{	
					//Alpha部分在上位机已经处理成0x0000的数据，每存放一个像素时判断是0x0000就虑掉
					if(DMA_rxbuf1[2*k-1]!=0x00 || DMA_rxbuf1[2*k-2]!=0x00)
					{			
						m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-1] = DMA_rxbuf1[2*k-1];				
						m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-2] = DMA_rxbuf1[2*k-2];		
					}				
				}
			}
			if(count_1!=0)
			{
				LT_ReadFlash(DMA_rxbuf1 ,Pic_addr+i*DMA_LEN2, count_1);
				for(k=1;k<=count_1/2;k++)
				{	
					//Alpha部分在上位机已经处理成0x0000的数据，每存放一个像素时判断是0x0000就虑掉
					if(DMA_rxbuf1[2*k-1]!=0x00 || DMA_rxbuf1[2*k-2]!=0x00)
					{			
						m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-1] = DMA_rxbuf1[2*k-1];				
						m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-2] = DMA_rxbuf1[2*k-2];		
					}				
				}
			}
		}	
	}
	else if(Cflag==2)
	{
		for(j=0;j<High;j++)
		{
			Pic_addr=pic_addr+pic_x*2+(pic_y+j)*pic_w*2;
			for(i=0;i<count;i++)
			{
				LT_ReadFlash(DMA_rxbuf1 ,Pic_addr+i*DMA_LEN2, DMA_LEN2);
				for(k=1;k<=DMA_LEN2/2;k++)
				{							
					A1_val = DMA_rxbuf1[2*k-1]>>4;
					if(A1_val!=0)
					{
						R1_val = DMA_rxbuf1[2*k-1]&0x0F;
						G1_val = DMA_rxbuf1[2*k-2]>>4;
						B1_val = DMA_rxbuf1[2*k-2]&0x0F;
						
						R0_val = m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-1]>>4;
						G0_val = (((m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-1] & 0x07)<<3) | (m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-2]>>5))>>2;
						B0_val = (m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-2] & 0x1F)>>1;
						
						R2_val = ((R1_val * A1_val + R0_val * (15-A1_val))/15)<<1;
						G2_val = ((G1_val * A1_val + G0_val * (15-A1_val))/15)<<2;
						B2_val = ((B1_val * A1_val + B0_val * (15-A1_val))/15)<<1;
						
						m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-1] = (R2_val<<3) | (G2_val>>3);
						m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-2] = ((G2_val&0x07)<<5) | B2_val;						
					}
				}

			}
			if(count_1!=0)
			{
				LT_ReadFlash(DMA_rxbuf1 ,Pic_addr+i*DMA_LEN2, count_1);
				for(k=1;k<=count_1/2;k++)
				{							
					A1_val = DMA_rxbuf1[2*k-1]>>4;
					if(A1_val!=0)
					{
						R1_val = DMA_rxbuf1[2*k-1]&0x0F;
						G1_val = DMA_rxbuf1[2*k-2]>>4;
						B1_val = DMA_rxbuf1[2*k-2]&0x0F;
						
						R0_val = m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-1]>>4;
						G0_val = (((m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-1] & 0x07)<<3) | (m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-2]>>5))>>2;
						B0_val = (m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-2] & 0x1F)>>1;
						
						R2_val = ((R1_val * A1_val + R0_val * (15-A1_val))/15)<<1;
						G2_val = ((G1_val * A1_val + G0_val * (15-A1_val))/15)<<2;
						B2_val = ((B1_val * A1_val + B0_val * (15-A1_val))/15)<<1;
						
						m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-1] = (R2_val<<3) | (G2_val>>3);
						m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-2] = ((G2_val&0x07)<<5) | B2_val;						
					}
				}
			}
		}
	}
	else if(Cflag==3)
	{
		jpg_decode_onFlash(pic_addr,0); 
	}
	else if(Cflag==4)
	{
		UINT16 m=0,n=0;
		UINT8  Table_head[12],Table_len[4],zipIndex=0;
		UINT16 count_0=0,count_1=0,Table_num=0;
		UINT32 totallen=0,zipdlen=0,slen=0,alen=0,dlen1=0,dlen2=0,post=0;
		UINT16 *pU16_ColorTB,*pU16_mPngData,cdata0=0,cdata1=0;
		UINT32 Data_ADDR=0;

		pU16_ColorTB  = (UINT16 *)&Table_color;
		pU16_mPngData = (UINT16 *)&m_PngData;

		//图片的基本信息
		LT_ReadFlash(Table_head ,pic_addr, 12);
		if(Table_head[0]!=0x4C||Table_head[1]!=0x54) return 0xFF; 
		Width= (Table_head[2]|(Table_head[3]<<8));													  //图片的宽
		High = (Table_head[4]|(Table_head[5]<<8));							     					//图片的高
		Table_num = Table_head[6];																						//图片的颜色表个数
		//zipIndex = Table_head[7]>>4;																				//图片的数据类型bmp/png
		Cflag = Table_head[7]&0x0F;																						//图片的数据类型bmp/png
		totallen = (Table_head[8]|(Table_head[9]<<8)|(Table_head[10]<<16)|(Table_head[11]<<24));  //图片的数据长度
		//printf("Table_head[0] ==  0x%x       0x%x       \r\n",Table_head[0],Table_head[1]);
		//printf("W,H= %d  %d    Table_num=%d  Cflag=%d  totallen=%d  \r\n",Width,High,Table_num,Cflag,totallen);
		zippic.w=Width;
		zippic.h=High;
		zippic.dtype=Cflag;


		//图片的数据解码
		for(k=0;k<Table_num;k++)
		{
			//获取单个颜色表的信息
			LT_ReadFlash(Table_len   ,pic_addr+12+516*k, 4);
			LT_ReadFlash_DMA(Table_color ,pic_addr+16+516*k, 512);
			zipdlen = (Table_len[0]|(Table_len[1]<<8)|(Table_len[2]<<16));         //单表__压缩数据的长度
			zipIndex= Table_len[3];												   											 //单表__压缩数据的类型
			Data_ADDR = pic_addr+12+Table_num*516+post;																	//单表__压缩数据的起始地址
			post+=zipdlen;																													//单表__压缩数据的累加长度		
		//printf("Table_num=%d zipdlen=%d  zipIndex=%d  ADDR=0x%x  post=%d  \r\n",k,zipdlen,zipIndex,Data_ADDR,post);

			dlen1=(DMA_LEN3/2);           //单buff长度
			dlen2=DMA_LEN3;             //双buff长度
			count_0=zipdlen/dlen2;
			count_1=zipdlen%dlen2;
		//printf("count_0=%d count_1=%d   \r\n",count_0,count_1);

			if(zipIndex==0)
			{
				if(Cflag==3)
				{
					for(i=0;i<count_0;i++)
					{
						LT_ReadFlash_DMA(DMA_rxbuf1 ,Data_ADDR+i*dlen2, dlen2);       //原始压缩数据
						for(n=0;n<dlen2;n++) pU16_mPngData[alen+n]=pU16_ColorTB[DMA_rxbuf1[n]];
						alen+=dlen2;		//printf("    alen 0 = %d  \r\n",alen);
					}
					if(count_1!=0)
					{
						LT_ReadFlash_DMA(DMA_rxbuf1 ,Data_ADDR+i*dlen2 , count_1);
						for(n=0;n<count_1;n++) pU16_mPngData[alen+n]=pU16_ColorTB[DMA_rxbuf1[n]];
						alen+=count_1;  //printf("    alen 1 = %d  \r\n",alen);
					}
				}
				else if(Cflag==4)
				{
					for(i=0;i<count_0;i++)
					{
						LT_ReadFlash_DMA(DMA_rxbuf1 , Data_ADDR+i*dlen2, dlen2);
						for(n=0;n<dlen2;n++)
						{
							cdata1=pU16_ColorTB[DMA_rxbuf1[n]];							//表格png数据
							pU16_mPngData[alen+n]=cdata1;
						}
						alen+=dlen2;
					}
					if(count_1!=0)
					{
						LT_ReadFlash_DMA(DMA_rxbuf1 ,Data_ADDR+i*dlen2 , count_1);
						for(n=0;n<count_1;n++)
						{
							 cdata1=pU16_ColorTB[DMA_rxbuf1[n]];
							 pU16_mPngData[alen+n]=cdata1;     
						}
						alen+=count_1;																			 	
					}
				}
				else if(Cflag==5)
				{
					for(i=0;i<count_0;i++)
					{
						LT_ReadFlash_DMA(DMA_rxbuf1 ,Data_ADDR+i*dlen2, dlen2);
						for(n=0;n<dlen2;n++)
								pU16_mPngData[alen+n]=pU16_ColorTB[DMA_rxbuf1[n]]; 
						alen+=dlen2;

					}
					if(count_1!=0)
					{
						LT_ReadFlash_DMA(DMA_rxbuf1 ,Data_ADDR+i*dlen2 , count_1);
						for(n=0;n<count_1;n++)
								pU16_mPngData[alen+n]=pU16_ColorTB[DMA_rxbuf1[n]]; 
						alen+=count_1;					
					}
				}				
			}
			else if(zipIndex==1)
			{
				if(Cflag==3)
				{
					for(i=0;i<count_0;i++)
					{
						LT_ReadFlash_DMA(DMA_rxbuf1 ,Data_ADDR+i*dlen2, dlen2);
						for(n=0;n<dlen2;n+=2)
						{
							slen = DMA_rxbuf1[n]+1;
							for(m=0;m<slen;m++)
							       pU16_mPngData[alen+m]=pU16_ColorTB[DMA_rxbuf1[n+1]];
							alen+=slen;  //printf("    alen 2 = %d  \r\n",alen);
						}
					}
					if(count_1!=0)
					{
						LT_ReadFlash_DMA(DMA_rxbuf1 ,Data_ADDR+i*dlen2 , count_1);
						for(n=0;n<count_1;n+=2)
						{
							slen = DMA_rxbuf1[n]+1;
							for(m=0;m<slen;m++)
							       pU16_mPngData[alen+m]=pU16_ColorTB[DMA_rxbuf1[n+1]];
							alen+=slen;   //printf("    alen 3 = %d  \r\n",alen);
						}
					}
				}
				else if(Cflag==4)
				{
					for(i=0;i<count_0;i++)
					{
						LT_ReadFlash_DMA(DMA_rxbuf1 ,Data_ADDR+i*dlen2, dlen2);
						for(n=0;n<dlen2;n+=2)
						{
							slen=DMA_rxbuf1[n]+1;				            //单次压缩长度
							cdata1=pU16_ColorTB[DMA_rxbuf1[n+1]];		//单次png数据
									for(m=0;m<slen;m++)pU16_mPngData[alen+m]=cdata1;
							alen+=slen;
						}
					}
					if(count_1!=0)
					{
						LT_ReadFlash_DMA(DMA_rxbuf1 ,Data_ADDR+i*dlen2 , count_1);
						for(n=0;n<count_1;n+=2)
						{
							slen=DMA_rxbuf1[n]+1;				    
							cdata1=pU16_ColorTB[DMA_rxbuf1[n+1]];		
									for(m=0;m<slen;m++)pU16_mPngData[alen+m]=cdata1;
							alen+=slen;																																												
						}
					}
				}
				else if(Cflag==5)
				{
					for(i=0;i<count_0;i++)
					{
						LT_ReadFlash_DMA(DMA_rxbuf1 ,Data_ADDR+i*dlen2, dlen2);
						for(n=0;n<dlen2;n+=2)
						{
							slen=DMA_rxbuf1[n]+1;				   
							cdata1=pU16_ColorTB[DMA_rxbuf1[n+1]];
							for(m=0;m<slen;m++)
									pU16_mPngData[alen+m]=cdata1;
							alen+=slen;																																														
						}
					}
					if(count_1!=0)
					{
						LT_ReadFlash_DMA(DMA_rxbuf1 ,Data_ADDR+i*dlen2 , count_1);
						for(n=0;n<count_1;n+=2)
						{
							slen=DMA_rxbuf1[n]+1;				
							cdata1=pU16_ColorTB[DMA_rxbuf1[n+1]];	
							for(m=0;m<slen;m++)
									pU16_mPngData[alen+m]=cdata1;
							alen+=slen;																																															
						}
					}
				}				
			}
		}
		return Cflag;
	}
	else if(Cflag==0x9f)
	{
		R1_val = color1_9F&0x0F;
		G1_val = (color2_9F>>4)&0x0f;
		B1_val = color2_9F&0x0F;
//		printf("R1_val=%x  %x %x \r\n",R1_val,G1_val,B1_val);

		for(j=0;j<High;j++)
		{
			Pic_addr=pic_addr+pic_x*2+(pic_y+j)*pic_w*2;
			for(i=0;i<count;i++)
			{
				LT_ReadFlash(DMA_rxbuf1 ,Pic_addr+i*DMA_LEN2, DMA_LEN2);
				for(k=1;k<=DMA_LEN2/2;k++)
				{							
					A1_val = DMA_rxbuf1[2*k-1]>>4;
					if(A1_val!=0)
					{
						R0_val = m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-1]>>4;
						G0_val = (((m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-1] & 0x07)<<3) | (m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-2]>>5))>>2;
						B0_val = (m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-2] & 0x1F)>>1;
						
						R2_val = ((R1_val * A1_val + R0_val * (15-A1_val))/15)<<1;
						G2_val = ((G1_val * A1_val + G0_val * (15-A1_val))/15)<<2;
						B2_val = ((B1_val * A1_val + B0_val * (15-A1_val))/15)<<1;
						
						m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-1] = (R2_val<<3) | (G2_val>>3);
						m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-2] = ((G2_val&0x07)<<5) | B2_val;						
					}
				}

			}
			if(count_1!=0)
			{
				LT_ReadFlash(DMA_rxbuf1 ,Pic_addr+i*DMA_LEN2, count_1);
				for(k=1;k<=(count_1/2);k++)
				{							
					A1_val = DMA_rxbuf1[2*k-1]>>4;
					if(A1_val!=0)
					{
						R0_val = m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-1]>>4;
						G0_val = (((m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-1] & 0x07)<<3) | (m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-2]>>5))>>2;
						B0_val = (m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-2] & 0x1F)>>1;
						
						R2_val = ((R1_val * A1_val + R0_val * (15-A1_val))/15)<<1;
						G2_val = ((G1_val * A1_val + G0_val * (15-A1_val))/15)<<2;
						B2_val = ((B1_val * A1_val + B0_val * (15-A1_val))/15)<<1;
						
						m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-1] = (R2_val<<3) | (G2_val>>3);
						m_PngData[buff_x*2+buff_y*buff_w*2+j*2*buff_w+DMA_LEN2*i+2*k-2] = ((G2_val&0x07)<<5) | B2_val;						
					}
				}
			}
		}
	}
	*/
	return 0xff;
}

/************************将缓存区中的数据显示到屏幕 ***************************************/
UINT8 LT268_buffer_to_TFT      
(
UINT16 buff_x, UINT16 buff_y, UINT16 buff_w, UINT8* m_Data,
UINT16 TFT_x,  UINT16 TFT_y,  UINT16 Width,  UINT16 High
)
{	
	
	UINT32 j;
	
	LT268_TFT_SetWindows(TFT_x,TFT_y,Width,High);
	LCD_RS_Data;
	LCD_CS_RESET;
	
	if((buff_x==0)&&(buff_w==Width))
	{
			TFT_Data_Tran(&m_PngData[buff_y*buff_w*2],Width*High*2);
	}
	else
	{
		for(j=0;j<High;j++)
		{
			TFT_Data_Tran(&m_PngData[buff_x*2+buff_y*buff_w*2+j*buff_w*2],Width*2);
		}		
	}
		
	
	LCD_CS_SET;
	
	return 1;

}


/*????_ASCII????*/
//x,y:????
//size_w,size_h:???????
//disp_w:????????
//mode: 0:?????  1:????
//FontColor:????
//BackGroundColor:????
//num:??
void LT268_TFT_Show_Internal_Char(UINT16 x,UINT16 y,UINT8 size_w,UINT8 size_h,UINT8 disp_w,UINT8 mode,UINT16 FontColor,UINT16 BackGroundColor,UINT8 num)
{
	UINT8 temp;
	UINT16 i,j,k;
	UINT16 x_buff=0,y_buff=0; //,csize;
	UINT16 disp_rowby,font_rowby;
	
	disp_rowby = (disp_w*1+7)/8;  
	font_rowby = (size_w/2*1+7)/8;
	//printf("disp_rowby =%d font_rowby=%d \r\n",disp_rowby,font_rowby);
	
//	csize = font_rowby*size_h; 							//???????????????????
	
 	num=num-' ';//???????(ASCII??????????,??-' '?????????)
	
	if(mode==1)
	{
		/*
		if(FullScreen_Pic_Addr==0)
			LT268_TFT_FillColor_Buffer(0,0,disp_w,size_h,FullScreen_Square_Color,disp_w);
		else
		LT268_pic_to_buffer(0,0,disp_w,m_PngData,
													x,y,LCD_XSIZE_TFT,FullScreen_Pic_Addr,
													disp_w,size_h,0);
		*/
	}
	else
	{
		LT268_TFT_FillColor_Buffer(0,0,disp_w,size_h,BackGroundColor,disp_w);
	}
	
//	if(GrayFont.bit==1)
//	{
		for(i=0;i<size_h;i++)
		{
			for(k=0;k<disp_rowby;k++)
			{
				if(size_w==12) 	  	temp=Font_0612[num][i*font_rowby+k];	//??1206??
				else if(size_w==16) 	temp=Font_0816[num][i*font_rowby+k];	//??1608??	
				else if(size_w==24) 	temp=Font_1224[num][i*font_rowby+k];	//??2412??
				else if(size_w==32)	temp=Font_1632[num][i*font_rowby+k];	//??3216??
				else return;											//????size

				for(j=0;j<8;j++)
				{
					if(temp&0x80)		 LT268_TFT_DrawPoint_Buffer(x_buff,y_buff,FontColor,disp_w);
					temp<<=1;
					x_buff++;
					if(x_buff>=disp_w)break;
				}
			}
			x_buff=0;
			y_buff++;
		}
//	}
	
	LT268_buffer_to_TFT(0,0,disp_w,m_PngData,x,y,disp_w,size_h);
	
}
//????Ascll???
//x,y :?????
//size:????
//mode: 0:?????  1:????
//FontColor:????
//BackGroundColor:????
//str:???
void Display_Text(UINT16 x,UINT16 y,UINT8 size,UINT8 mode,UINT16 fgColor,UINT16 bgColor,char *str)
{
//	UINT8 x0=x;
	Disable_Interrupts;
    while((*str<='~')&&(*str>=' '))//?????????!
    {
        if(x+size/2>=LCD_XSIZE_TFT){x=0;y+=size;}
        if(y+size>LCD_YSIZE_TFT)break;//??
        LT268_TFT_Show_Internal_Char(x,y,size,size,size/2,mode,fgColor,bgColor,*str);

        x+=size/2;
        str++;
    }
	Enable_Interrupts;
}

void Backlight_Init(void)
{
	//PWM_Csr:0=1/2 ,1=1/4 ,2=1/8 ,3=1/16  ,others=1
	//PWMoutput=75Mhz/(PWM_Prescaler+1)/(PWM_Csr)/(PWM_Period+1)
	
	PWM_OutputInit(PWM_PORT3,4,PWM_CLK_DIV_1,99,0,0);    // 74=2k  24=6k   14=10k   4=30k, duty=0
}

//背光亮度

void Backlight_Adjust(u8 brightness)
{
	PWM->PWM_CMR3 = brightness;								//high leve = duty+1
}

void Backlight_Enable(bool state)
{
	if (state) CCM->PCFG3 |= (7<<0);
	else CCM->PCFG3 &= ~(7<<0);	
}

void Screen_Clear(UINT16 color)
{
	LT268_TFT_DrawSquare_Fill(0,0,LCD_XSIZE_TFT-1,LCD_YSIZE_TFT-1,color);
}

void Clear_Screen(UINT16 color)
{
	u16 x,y,pixelData;
	u32 i,bmpSize;
	unsigned const char *bmpPtr;
	
	bmpSize=LCD_XSIZE_TFT*LCD_YSIZE_TFT;
	printf("LCD_X=%d LCD_Y=%d ",LCD_XSIZE_TFT,LCD_YSIZE_TFT);
	x=y=0;
	for (i=0;i<bmpSize;i++)
	{
		LT268_TFT_DrawPoint(x,y,grYELLOW);
		x++;
		if(x>=LCD_XSIZE_TFT)
		{
			x=0;
			y++;
		}
	}
	printf("LCD_X=%d LCD_Y=%d ",LCD_XSIZE_TFT,LCD_YSIZE_TFT);
}

void Display_16BitBMP(UINT16 x,UINT16 y,unsigned const char *bmp,UINT16 transColor)
{
	UINT32 i,bmpSize,sizeX,sizeY;
	UINT16 locX,pixelData;
	unsigned const char *bmpPtr;	
	locX=x; 
	x=0;	
	
	sizeX=*(u16 *)  bmp;
	sizeY=*(u16 *)(bmp+4);
	
	bmpSize=sizeX*sizeY;
	bmpPtr=bmp+8;
	
	INTX_DISABLE();
	for (i=0;i<bmpSize;i++)
	{
		pixelData=*(u16 *)bmpPtr;
		bmpPtr+=2;
		
		if (pixelData!=transColor)
			LT268_TFT_DrawPoint(locX+x,y,pixelData);
		
		x++;
		if(x>=sizeX)
		{
			x=0;
			y++;
		}
	}
	INTX_ENABLE();
}

