#ifndef __BSP_LCD_H
#define __BSP_LCD_H

#ifdef __cplusplus
	extern "C" {
#endif
#include "main.h"
#include "stm32f4xx.h"
#include "bsp_ltdc.h"
#include "bsp_dma2d.h"
#include "fonts.h"

#define POLY_X(Z)              ((int32_t)((Points + Z)->X))
#define POLY_Y(Z)              ((int32_t)((Points + Z)->Y)) 
#define ABS(X)  ((X) > 0 ? (X) : -(X))

//LCD参数

#define LCD_DEFAULT_FONT        Font16 

/** 
  * @brief  LCD液晶类型
  */   
typedef enum
{ 
  INCH_5  = 0x00,   /* 野火5寸屏 */
  INCH_7,           /* 野火7寸屏 */
  INCH_4_3,         /* 野火4.3寸屏 */
  LCD_TYPE_NUM      /* LCD类型总数*/
}LCD_TypeDef;
// 前使用的LCD，默认为4.3寸屏 */
extern LCD_TypeDef cur_lcd;

typedef struct 
{ 
  uint32_t  TextColor; 
  uint32_t  BackColor;  
  sFONT     *pFont;
  sFONT     *pCnFont;
}LCD_DrawPropTypeDef;   

typedef struct 
{
  int16_t X;
  int16_t Y;
}Point, *pPoint; 

/** 
  * @brief  字体对齐模式  
  */ 
typedef enum
{
  CENTER_MODE             = 0x01,    /* 居中对齐 */
  RIGHT_MODE              = 0x02,    /* 右对齐   */
  LEFT_MODE               = 0x03     /* 左对齐   */
}Text_AlignModeTypdef;


typedef struct  
{	
	// uint16_t pixel_width;   // 像素宽
	// uint16_t pixel_height;  // 像素高
	uint16_t width;			//LCD 宽度
	uint16_t height;			//LCD 高度


	uint8_t  dir;			//横屏还是竖屏控制：0，竖屏；1，横屏。
	uint8_t  pixelsize;			//像素大小。

	uint32_t color_format; // Layer2 Addr
	uint32_t color;
	uint32_t backcolor;
	LCD_DrawPropTypeDef draw_prop[2];
	uint8_t show_num_mode;  // 显示数组模式， 0 多余位补0 ， 1 不补0

	uint16_t activelayer;	//active layer
	uint32_t layeraddr[2];   // Layer0 Addr

}MY_LCD_TypeDef; 
extern MY_LCD_TypeDef my_lcd;	//管理LCD重要参数


void LCD_Init(void);
uint8_t  LCD_DeInit(void);

void LCD_DisplayDirection(uint8_t dir);
void LCD_SetLayer( uint8_t layer,uint32_t buf_addr, uint32_t layer_color_format,
				 uint32_t layer_back_color,uint8_t alpha );
void LCD_Set_Active_layer( uint8_t layer_no );


void     LCD_SetTextColor(uint32_t Color);
uint32_t LCD_GetTextColor(void);
void     LCD_SetBackColor(uint32_t Color);
uint32_t LCD_GetBackColor(void);
void LCD_SetColors(uint32_t TextColor, uint32_t BackColor);
void     LCD_SetFont(sFONT *fonts);
sFONT    *LCD_GetFont(void);

void LCD_Draw_Point(uint16_t x,uint16_t y,uint32_t color);
uint32_t LCD_Read_Point(uint16_t x,uint16_t y);


// static void LCD_Draw_Point(uint16_t x,uint16_t y,uint32_t color);
void LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3);
void LCD_DrawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
void LCD_DrawCircle(uint16_t x, uint16_t y, uint16_t r);
void LCD_Fill(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, uint32_t color);
void LCD_Color_Fill(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, uint16_t *color);
void LCD_Clear( uint32_t color);


void 	LCD_DisplayChar(uint16_t x, uint16_t y, uint8_t c);				//	显示单个ASCII字符
void 	LCD_DisplayString( uint16_t x, uint16_t y, char *p);
//>>>>>	显示整数或小数
void  LCD_ShowNumMode(uint8_t mode);		// 设置显示模式，多余位填充空格还是填充0
void  LCD_DisplayNumber( uint16_t Line, int32_t number, uint8_t len)  ;					// 显示整数
void  LCD_DisplayDecimals( uint16_t Line, double decimals, uint8_t len, uint8_t decs) ;	// 显示小数
// 中文
void LCD_DispChar_CH (uint16_t Xpos, uint16_t Ypos, uint16_t Text);
void LCD_DisplayStringLine_EN_CH(uint16_t Line, uint8_t *ptr);

void LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Text_AlignModeTypdef Mode);
void LCD_DisplayStringLine(uint16_t Line, uint8_t *ptr);


void LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii);
void LCD_FillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height);
void LCD_FillCircle(uint16_t x, uint16_t y, uint16_t r);

void 	LCD_DrawImage(uint16_t x,uint16_t y,uint16_t width,uint16_t height,const uint8_t *pImage) ;

//画笔颜色 ARGB8888
#if LCD_PIXFORMAT == LTDC_PIXEL_FORMAT_ARGB8888 || LCD_PIXFORMAT == LTDC_PIXEL_FORMAT_RGB888
#define LCD_COLOR_BLUE          ((uint32_t)0xFF0000FF)
#define LCD_COLOR_GREEN         ((uint32_t)0xFF00FF00)
#define LCD_COLOR_RED           ((uint32_t)0xFFFF0000)
#define LCD_COLOR_CYAN          ((uint32_t)0xFF00FFFF)
#define LCD_COLOR_MAGENTA       ((uint32_t)0xFFFF00FF)
#define LCD_COLOR_YELLOW        ((uint32_t)0xFFFFFF00)
#define LCD_COLOR_LIGHTBLUE     ((uint32_t)0xFF8080FF)
#define LCD_COLOR_LIGHTGREEN    ((uint32_t)0xFF80FF80)
#define LCD_COLOR_LIGHTRED      ((uint32_t)0xFFFF8080)
#define LCD_COLOR_LIGHTCYAN     ((uint32_t)0xFF80FFFF)
#define LCD_COLOR_LIGHTMAGENTA  ((uint32_t)0xFFFF80FF)
#define LCD_COLOR_LIGHTYELLOW   ((uint32_t)0xFFFFFF80)
#define LCD_COLOR_DARKBLUE      ((uint32_t)0xFF000080)
#define LCD_COLOR_DARKGREEN     ((uint32_t)0xFF008000)
#define LCD_COLOR_DARKRED       ((uint32_t)0xFF800000)
#define LCD_COLOR_DARKCYAN      ((uint32_t)0xFF008080)
#define LCD_COLOR_DARKMAGENTA   ((uint32_t)0xFF800080)
#define LCD_COLOR_DARKYELLOW    ((uint32_t)0xFF808000)
#define LCD_COLOR_WHITE         ((uint32_t)0xFFFFFFFF)
#define LCD_COLOR_LIGHTGRAY     ((uint32_t)0xFFD3D3D3)
#define LCD_COLOR_GRAY          ((uint32_t)0xFF808080)
#define LCD_COLOR_DARKGRAY      ((uint32_t)0xFF404040)
#define LCD_COLOR_BLACK         ((uint32_t)0xFF000000)
#define LCD_COLOR_BROWN         ((uint32_t)0xFFA52A2A)
#define LCD_COLOR_ORANGE        ((uint32_t)0xFFFFA500)
#define LCD_COLOR_TRANSPARENT   ((uint32_t)0xFF000000)
#else
# RGB565
#define LCD_COLOR_WHITE			0xFFFF
#define LCD_COLOR_BLACK			0x0000	  
#define LCD_COLOR_BLUE				0x001F  
#define LCD_COLOR_RED				0xF800
#define LCD_COLOR_MAGENTA			0xF81F
#define LCD_COLOR_GREEN 			0x07E0
#define LCD_COLOR_CYAN				0x7FFF
#define LCD_COLOR_YELLOW			0xFFE0
#define LCD_COLOR_BROWN			0XBC40 //棕色
#define LCD_COLOR_GRAY				0X8430 //灰色
#define LCD_COLOR_LIGHTGRAY			0XC618 //浅灰色(PANNEL),窗体背景色
#define LCD_COLOR_BRRED_RGB565			0XFC07 //棕红色
#define LCD_COLOR_BRED_RGB565				0XF81F
#define LCD_COLOR_GRED_RGB565				0XFFE0
#define LCD_COLOR_GBLUE_RGB565			0X07FF
#endif


#ifdef __cplusplus
	}
#endif
#endif

/**
 * LCD_ShowString(10,80,240,24,24,"LTDC TEST");
 */