
#ifndef __LCD_H
#define __LCD_H		

#include <stdint.h>
#include <stdbool.h>
#include "globales.h"
#include "asf.h"
#include "pio.h"
#include <math.h>
#include <string.h>


#define USE_HORIZONTAL  	0 //定义液晶屏顺时针旋转方向 	0-0度旋转，1-90度旋转，2-180度旋转，3-270度旋转

#define LCD_W 480
#define LCD_H 800


   
uint16_t  POINT_COLOR;  
uint16_t  BACK_COLOR; 

typedef struct  
{										    
	uint16_t width;			//LCD 宽度
	uint16_t height;			//LCD 高度
	uint16_t id;				//LCD ID
	uint8_t  dir;			//横屏还是竖屏控制：0，竖屏；1，横屏。	
	uint16_t	 wramcmd;		//开始写gram指令
	uint16_t  rramcmd;   //开始读gram指令
	uint16_t  setxcmd;		//设置x坐标指令
	uint16_t  setycmd;		//设置y坐标指令	 
}_lcd_dev; 	

//===================================================
// Definicion de macros

#define TFT_CS_LOW()   pio_clear(PIOD,TFT_CS_PIN_MASK);
#define TFT_CS_HIGH()  pio_set(PIOD,TFT_CS_PIN_MASK);
#define TFT_DC_LOW()   pio_clear(PIOD,TFT_DC_PIN_MASK);
#define TFT_DC_HIGH()  pio_set(PIOD,TFT_DC_PIN_MASK);
#define TFT_BKL_ON()   pio_set(PIOD,TFT_BKL_PIN_MASK);
#define TFT_BKL_OFF()  pio_clear(PIOD,TFT_BKL_PIN_MASK);
#define TFT_RST_OFF()  pio_set(PIOD,TFT_RST_PIN_MASK);
#define TFT_RST_ON()   pio_clear(PIOD,TFT_RST_PIN_MASK);
#define TFT_RD_LOW()   pio_clear(PIOD,TFT_RD_PIN_MASK);
#define TFT_RD_HIGH()  pio_set(PIOD,TFT_RD_PIN_MASK);
#define TFT_WR_LOW()   pio_clear(PIOD,TFT_WR_PIN_MASK);
#define TFT_WR_HIGH()  pio_set(PIOD,TFT_WR_PIN_MASK);

extern _lcd_dev lcddev;	
void LCD_Init(void); 
void LCD_Clear(uint16_t Color);
void LCD_write(uint8_t HVAL,uint8_t LVAL);
uint16_t LCD_read(void);
void LCD_WR_DATA(uint16_t Data);
uint16_t LCD_RD_DATA(void);
void LCD_WR_REG(uint16_t Reg);
void LCD_SetCursor(uint16_t Xpos, uint16_t Ypos);
void LCD_SetWindows(uint16_t xStar, uint16_t yStar,uint16_t xEnd,uint16_t yEnd);
void LCD_DrawPoint(uint16_t x,uint16_t y);
uint16_t LCD_ReadPoint(uint16_t x,uint16_t y);
void LCD_WriteRAM_Prepare(void);
void LCD_ReadRAM_Prepare(void);
void LCD_direction(uint8_t direction );
void LCD_WR_DATA_16Bit(uint16_t Data);
uint16_t Lcd_RD_DATA_16Bit(void);
void LCD_WriteReg(uint16_t LCD_Reg, uint16_t LCD_RegValue);
void LCD_ReadReg(uint16_t LCD_Reg,uint16_t *Rval,int n);
uint16_t LCD_Read_ID(void);
uint16_t Color_To_565(uint8_t r, uint8_t g, uint8_t b);



#define WHITE         	 0xFFFF
#define BLACK         	 0x0000	 
#define BLUE         	 0x001F  
#define BRED             0XF81F
#define GRED 			 0XFFE0
#define GBLUE			 0X07FF
#define RED           	 0xF800
#define MAGENTA       	 0xF81F
#define GREEN         	 0x07E0
#define CYAN          	 0x7FFF
#define YELLOW        	 0xFFE0
#define BROWN 			 0XBC40 
#define BRRED 			 0XFC07 
#define GRAY  			 0X8430 


#define DARKBLUE      	 0X01CF	
#define LIGHTBLUE      	 0X7D7C	 
#define GRAYBLUE       	 0X5458 

 
#define LIGHTGREEN     	 0X841F 
#define LGRAY 			 0XC618 

#define LGRAYBLUE        0XA651 
#define LBBLUE           0X2B12 


					  		 
#endif  
	 
	 



