#ifndef _LCD_H
#define _LCD_H
//#include "sys.h"
#include "main.h"
//////////////////////////////////////////////////////////////////////////////////	 
//本程序只供学习使用，未经作者许可，不得用于其它任何用途
//ALIENTEK STM32H7开发板
//LCD驱动代码	   
//正点原子@ALIENTEK
//技术论坛:www.openedv.com
//创建日期:2017/8/12
//版本：V1.0
//版权所有，盗版必究。
//Copyright(C) 广州市星翼电子科技有限公司 2014-2024
//All rights reserved									  
////////////////////////////////////////////////////////////////////////////////// 	
#define LCD_LED(n)              (n?HAL_GPIO_WritePin(GPIOB,GPIO_PIN_5,GPIO_PIN_SET):HAL_GPIO_WritePin(GPIOB,GPIO_PIN_5,GPIO_PIN_RESET))   //LCD背光PD13              //LCD背光PD13

//LCD LTDC重要参数集
typedef struct  
{							 
	unsigned int pwidth;			//LCD面板的宽度,固定参数,不随显示方向改变,如果为0,说明没有任何RGB屏接入
	unsigned int pheight;		//LCD面板的高度,固定参数,不随显示方向改变
	unsigned short hsw;			//水平同步宽度
	unsigned short vsw;			//垂直同步宽度
	unsigned short hbp;			//水平后廊
	unsigned short vbp;			//垂直后廊
	unsigned short hfp;			//水平前廊
	unsigned short vfp;			//垂直前廊 
	unsigned char activelayer;		//当前层编号:0/1	
	unsigned char dir;				//0,竖屏;1,横屏;
	unsigned short width;			//LCD宽度
	unsigned short height;			//LCD高度
	unsigned int pixsize;		//每个像素所占字节数
}_ltdc_dev; 

extern _ltdc_dev lcdltdc;		            //管理LCD LTDC参数
extern LTDC_HandleTypeDef LTDC_Handler;	    //LTDC句柄
extern unsigned int *ltdc_framebuf[2];					//LTDC LCD帧缓存数组指针,必须指向对应大小的内存区域

#define LCD_PIXEL_FORMAT_ARGB8888       0X00    
#define LCD_PIXEL_FORMAT_RGB888         0X01    
#define LCD_PIXEL_FORMAT_RGB565         0X02       
#define LCD_PIXEL_FORMAT_ARGB1555       0X03      
#define LCD_PIXEL_FORMAT_ARGB4444       0X04     
#define LCD_PIXEL_FORMAT_L8             0X05     
#define LCD_PIXEL_FORMAT_AL44           0X06     
#define LCD_PIXEL_FORMAT_AL88           0X07      

///////////////////////////////////////////////////////////////////////
//用户修改配置部分:

//定义颜色像素格式,一般用RGB565
#define LCD_PIXFORMAT				LCD_PIXEL_FORMAT_ARGB8888	
//定义默认背景层颜色
#define LTDC_BACKLAYERCOLOR			0X00000000	
//LCD帧缓冲区首地址,这里定义在SDRAM里面.
#define LCD_FRAME_BUF_ADDR			0XC0000000  
#define LCD_FRAME_BUF_2_ADDR		0XC0177000  

void LTDC_Switch(unsigned char sw);					//LTDC开关
void LTDC_Layer_Switch(unsigned char layerx,unsigned char sw);	//层开关
void LTDC_Select_Layer(unsigned char layerx);			//层选择
void LTDC_Display_Dir(unsigned char dir);				//显示方向控制
void LTDC_Draw_Point(unsigned short x,unsigned short y,unsigned int color);//画点函数
unsigned int LTDC_Read_Point(unsigned short x,unsigned short y);			//读点函数
void LTDC_Fill(unsigned short sx,unsigned short sy,unsigned short ex,unsigned short ey,unsigned int color);			//矩形单色填充函数
void LTDC_Color_Fill(unsigned short sx,unsigned short sy,unsigned short ex,unsigned short ey,unsigned short *color);	//矩形彩色填充函数
void LTDC_Clear(unsigned int color);					//清屏函数
unsigned char LTDC_Clk_Set(unsigned int pll3m,unsigned int pll3n,unsigned int pll3r);//LTDC时钟配置
//unsigned char LTDC_Clk_Set(unsigned int pllsain,unsigned int pllsair,unsigned int pllsaidivr);//LTDC时钟配置
void LTDC_Layer_Window_Config(unsigned char layerx,unsigned short sx,unsigned short sy,unsigned short width,unsigned short height);//LTDC层窗口设置
void LTDC_Layer_Parameter_Config(unsigned char layerx,unsigned int bufaddr,unsigned char pixformat,unsigned char alpha,unsigned char alpha0,unsigned char bfac1,unsigned char bfac2,unsigned int bkcolor);//LTDC基本参数设置
unsigned short LTDC_PanelID_Read(void);				//LCD ID读取函数
void LTDC_Init(void);						//LTDC初始化函数
#endif 
