#ifndef _LT768_Lib_H
#define _LT768_Lib_H

#include <string.h>
#include "type.h"
#include "ssi_hal.h"
#include "cache_drv.h"
//#include "lcd_demo.h"
#include "eflash_hal.h"
#include "hal.h"
#include "dma_hal.h"
#include "font_data.h"
#include "bsp.h"

#define Font_size 200
#define Font_BYTE Font_size*2
extern unsigned char Font_1[Font_BYTE];

extern unsigned short LCD_XSIZE_TFT;
extern unsigned short LCD_YSIZE_TFT;

extern unsigned short LCD_VBPD;
extern unsigned short LCD_VFPD;
extern unsigned short LCD_VSPW;
extern unsigned short LCD_HBPD;
extern unsigned short LCD_HFPD;
extern unsigned short LCD_HSPW;

extern unsigned char	gPCLKRISING;
extern unsigned char	gHSYNCPolarity;
extern unsigned char	gVSYNCPolarity;
extern unsigned char	gDEPolarity;

//#define MAIN_BUFF   (0x80000000+LCD_XSIZE_TFT*LCD_YSIZE_TFT*2*0)
//#define LAY_BUFF1 	(0x80000000+LCD_XSIZE_TFT*LCD_YSIZE_TFT*2*1)
//#define LAY_BUFF2 	(0x80000000+LCD_XSIZE_TFT*LCD_YSIZE_TFT*2*2)
//#define LAY_BUFF3 	(0x80000000+LCD_XSIZE_TFT*LCD_YSIZE_TFT*2*3)
//#define LAY_BUFF4 	(0x80000000+LCD_XSIZE_TFT*LCD_YSIZE_TFT*2*4)

/* LCD color */
#define White          0xFFFF
#define Black          0x0000
#define Grey           0xF7DE
#define Blue           0x001F
#define Blue2          0x051F
#define Red            0xF800
#define Magenta        0xF81F
#define Green          0x07E0
#define Cyan           0x7FFF
#define Yellow         0xFFE0

extern volatile unsigned int Lay_Canvas_Addr;
extern volatile unsigned short Lay_Canvas_Width;

HAL_StatusTypeDef DMAC_QUAD_SSI_read(uint32_t addr, uint32_t *buf);
void DMAC_M2MTest2(DMAC_TypeDef *pdmac,uint32_t ch,uint32_t len,uint8_t *dstbuf,uint8_t *srcbuf);
void DMAC_M2MTest3(DMAC_TypeDef *pdmac,uint32_t ch,uint32_t len,uint8_t *dstbuf,uint8_t *srcbuf);

void LT_ReadParam(void);

void LT768_DMA_24bit_Block_Init(void);
void LT768_BTE_Init(void);

void Main_Image_Start_Address(unsigned long Addr);
void Main_Image_Width(unsigned short WX);
void Main_Window_Start_XY(unsigned short WX,unsigned short HY);
void Active_Window_XY(unsigned short WX,unsigned short HY);
void Active_Window_WH(unsigned short WX,unsigned short HY);

void Canvas_Image_Start_address(unsigned int Addr);
void Canvas_image_width(unsigned short WX);

void LT768_DMA_24bit_Block_Or_Line_16bpp
( 
 unsigned char SCS
,unsigned char Clk
,unsigned short X1
,unsigned short Y1
,unsigned short X_W	
,unsigned short Y_H
,unsigned short P_W
,unsigned int Addr	
,unsigned int lay0        // 层的地址	
,unsigned short canvas_w     // 图层宽度
);

void LT768_BTE_Memory_Copy
(
 unsigned int S0_Addr     // SO图像的内存起始地址
,unsigned short S0_W       // S0图像的宽度
,unsigned short XS0        // S0图像的左上方X坐标
,unsigned short YS0        // S0图像的左上方Y坐标
,unsigned int S1_Addr     // S1图像的内存起始地址
,unsigned short S1_W       // S1图像的宽度
,unsigned short XS1        // S1图像的左上方X坐标
,unsigned short YS1        // S1图像的左上方Y坐标
,unsigned int Des_Addr    // 目的图像的内存起始地址
,unsigned short Des_W      // 目的图像的宽度
,unsigned short XDes       // 目的图像的左上方X坐标
,unsigned short YDes       // 目的图像的左上方Y坐标
,unsigned int ROP_Code     // 光栅操作模式
,unsigned short X_W       // 活动窗口的宽度
,unsigned short Y_H       // 活动窗口的长度
);


void LT768_BTE_Memory_Copy_Chroma_key(unsigned long S0_Addr,unsigned short S0_W,unsigned short XS0,unsigned short YS0,unsigned long Des_Addr,unsigned short Des_W,unsigned short XDes,unsigned short YDes,unsigned long Background_color,unsigned short X_W,unsigned short Y_H);

void BTE_Pixel_16bpp_Alpha_Blending																								//16位png图片显示函数
(
 unsigned long S0_Addr         // SO图像的内存起始地址															//用于与png图片合成的背景图
 ,unsigned short S0_W          // S0图像的宽度
 ,unsigned short XS0           // S0图像的左上方X坐标
 ,unsigned short YS0           // S0图像的左上方Y坐标
 ,unsigned long S1_Addr        // S1图像的内存起始地址														 	//png图片存放的地址
 ,unsigned short S1_W          // S1图像的宽度
 ,unsigned short XS1           // S1图像的左上方X坐标
 ,unsigned short YS1           // S1图像的左上方Y坐标
 ,unsigned long Des_Addr       // 目的图像的内存起始地址														//处理后的png图片显示地址
 ,unsigned short Des_W         // 目的图像的宽度
 ,unsigned short XDes          // 目的图像的左上方X坐标
 ,unsigned short YDes          // 目的图像的左上方X坐标
 ,unsigned short X_W           // 活动窗口的宽度
 ,unsigned short Y_H           // 活动窗口的长度
);

void BTE_Alpha_Blending(unsigned long S0_Addr,unsigned short S0_W,unsigned short XS0,unsigned short YS0,unsigned long S1_Addr,unsigned short S1_W,unsigned short XS1,unsigned short YS1,unsigned long Des_Addr,unsigned short Des_W,unsigned short XDes,unsigned short YDes,unsigned short X_W,unsigned short Y_H,unsigned char alpha);


void LT768_DrawLine(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,unsigned long color);

void LT768_DrawLine_Width
(
 unsigned short X1        // X1坐标
,unsigned short Y1        // Y1坐标
,unsigned short X2        // X2坐标
,unsigned short Y2        // Y2坐标
,unsigned long  LineColor // 线段颜色
,unsigned short Width     // 线段宽度
);

void LT768_DrawCircle(unsigned short xc,unsigned short yc,unsigned short r,unsigned long color);

void LT768_DrawCircle_Fill(unsigned short xc,unsigned short yc,unsigned short r,unsigned long color);

void LT768_DrawCircle_Width(unsigned short xc, unsigned short yc, unsigned short r,unsigned long WidthColor,unsigned long BackgroundColor,unsigned short Width);

void LT768_DrawEllipse(unsigned short x0,unsigned short y0,unsigned short rx,unsigned short ry,unsigned long color);

void LT768_DrawEllipse_Fill(unsigned short x0,unsigned short y0,unsigned short rx,unsigned short ry,unsigned long color);

void LT768_DrawEllipse_Width(unsigned short x0, unsigned short y0, unsigned short rx,unsigned short ry,unsigned long WidthColor,unsigned long BackgroundColor,unsigned short Width);

void LT768_DrawSquare(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,unsigned long color);

void LT768_DrawSquare_Fill
(
 unsigned short X1                // X1位置
,unsigned short Y1                // Y1位置
,unsigned short X2                // X2位置
,unsigned short Y2                // Y2位置
,unsigned int ForegroundColor    // 背景颜色
);

void LT768_DrawSquare_Width
(
 unsigned short X1                // X1位置
,unsigned short Y1                // Y1位置
,unsigned short X2                // X2位置
,unsigned short Y2                // Y2位置
,unsigned long SquareColor        // 画线颜色
,unsigned long ForegroundColor    // 背景颜色
,unsigned short Width             // 线宽
);

void LT768_DrawCircleSquare(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,unsigned short r,unsigned short r2,unsigned long color);

void LT768_DrawCircleSquare_Fill(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,unsigned short r,unsigned short r2,unsigned long color);

void LT768_DrawCircleSquare_Width(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,unsigned short r,unsigned short r2,unsigned long WidthColor,unsigned long BackgroundColor,unsigned short Width);

void LT768_DrawTriangle(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,unsigned short x3,unsigned short y3,unsigned long color);
void LT768_DrawTriangle_Fill(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,unsigned short x3,unsigned short y3,unsigned long color);

void LT768_DrawTriangle_Frame(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,unsigned short x3,unsigned short y3,unsigned long WidthColor,unsigned long BackgroundColor);

void LT768_DrawQuadrilateral(unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned short X3,unsigned short Y3,unsigned short X4,unsigned short Y4,unsigned long ForegroundColor);

void LT768_DrawQuadrilateral_Fill(unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned short X3,unsigned short Y3,unsigned short X4,unsigned short Y4,unsigned long ForegroundColor);

void LT768_DrawQuadrangular1( unsigned short X1,unsigned short Y1,unsigned short X2,unsigned short Y2,unsigned short Width,unsigned short High,unsigned long QuadrangularColor,unsigned long ForegroundColor,unsigned char Wid);

UINT8 LT768_DrawCylinder(unsigned short XCenter,unsigned short YCenter,unsigned short X_R,unsigned short Y_R,unsigned short High,unsigned long CylinderColor,unsigned long ForegroundColor,unsigned char Width);

void LT768_MakeTable(unsigned short X1,unsigned short Y1,unsigned short W0,unsigned short H0,unsigned short L0,unsigned short R0,unsigned long TableColor,unsigned long ItemColor,unsigned long ForegroundColor,unsigned short width1,unsigned short width2,unsigned char mode0);

void LT768_Print_Outside_Font_String(unsigned short x,unsigned short y,unsigned long FontColor,unsigned long BackGroundColor,unsigned short String_Length ,unsigned char *c);

extern volatile u8 val_blank;
void LT768_TFT_ShowAscii(UINT16 x,UINT16 y,UINT8 size,UINT8 mode,UINT16 FontColor,UINT16 BackGroundColor,UINT8 *str);
void LT768_TFT_ShowString(unsigned short x,unsigned short y,unsigned short w,unsigned char size,unsigned char mode,unsigned long FlashAddr,unsigned short FontColor,unsigned short BackGroundColor,unsigned short String_Length,unsigned char*str);
void LT768_TFT_ShowString_font(u16 x,u16 y,u16 w,u8 size,u8 mode,u32 FlashAddr,u16 FontColor,u16 BackGroundColor,u8 alignment,u16 *width_line,u16 String_Length,u8 *str);

void LT768_TFT_ShowString_48_72(unsigned short x,unsigned short y,unsigned short w,unsigned char size,unsigned char mode,unsigned long FlashAddr,unsigned short FontColor,unsigned short BackGroundColor,unsigned short String_Length,unsigned char*str);
void LT768_TFT_ShowString_48_72_UserDefineFont(unsigned short x,unsigned short y,unsigned short w,unsigned char size,unsigned char mode,unsigned long FlashAddr,unsigned short FontColor,unsigned short BackGroundColor,unsigned short String_Length,unsigned char*str);
UINT16 LT_Color8_To_16(UINT8 color);

void LT_BacklightSet(UINT16 duty); 

void LT768_Display_Zip_BMP(unsigned short x,unsigned short y,unsigned short Width,unsigned short Height,unsigned int addr,unsigned int layer_addr,unsigned short layer_width,unsigned char *zip_flag);

//解压图片所用的变量
typedef struct 
{
	unsigned char Flag;
	unsigned int data_length;
	unsigned short buff[256];
}ctb_data;
extern ctb_data CTB;
extern unsigned char  RTBuff[];
extern __align(4) unsigned short*RowBuff;
extern __align(4) unsigned short RowBuff_1[];
extern __align(4) unsigned short RowBuff_2[];
extern u8 Table_color[];
extern __align(4) unsigned short RowBuff_OLD;

#endif

