#ifndef ____HDL_LCD_H_
#define ____HDL_LCD_H_

#include "hc32_ll.h"
#include "hdl_clk.h"

#include "lvgl.h"

/* lcd刷屏定时器处理 */
#define 	LCD_TIM_UINT		CM_TMR0_1
#define 	LCD_TIM_CLK			FCG2_PERIPH_TMR0_1
#define 	LCD_TIM_CH			TMR0_CH_B
#define 	LCD_TIM_TRIG_CH		AOS_TMR0
#define 	LCD_TIM_CH_INT 		TMR0_INT_CMP_B
#define 	LCD_TIM_CH_FLAG		TMR0_FLAG_CMP_B
#define 	LCD_TIM_INT_SRC		INT_SRC_TMR0_1_CMP_B
#define 	LCD_TIM_IRQn		INT007_IRQn

#define 	LCD_TIME_CMP_VALUE      (1563)

#define USE_HORIZONTAL 0  //设置横屏或者竖屏显示 0或1为竖屏 2或3为横屏

#define LCD_W 240
#define LCD_H 240

#define 	LCD_SPI_UINT	CM_SPI3
#define 	LCD_SPI_CLK		FCG1_PERIPH_SPI3
#define 	LCD_SPI_TX_EVT_SRC	EVT_SRC_SPI3_SPTI
#define 	LCD_SCL_PORT	GPIO_PORT_B
#define 	LCD_SCL_PIN		GPIO_PIN_07
#define 	LCD_SCL_FUNC	GPIO_FUNC_43
#define 	LCD_SDA_PORT	GPIO_PORT_B
#define 	LCD_SDA_PIN		GPIO_PIN_06
#define 	LCD_SDA_FUNC	GPIO_FUNC_40

#define 	LCD_DMA_UNIT                        CM_DMA1
#define 	LCD_DMA_CLK                         (FCG0_PERIPH_DMA1 | FCG0_PERIPH_AOS)
#define 	LCD_DMA_TX_CH                       DMA_CH0
#define 	LCD_DMA_TX_TRIG_CH                  AOS_DMA1_0
#define 	LCD_DMA_TX_INT_CH                   DMA_INT_TC_CH0
#define 	LCD_DMA_TX_INT_SRC                  INT_SRC_DMA1_TC0
#define 	LCD_DMA_TX_IRQ_NUM                  INT006_IRQn


#define 	LCD_RES_PORT	GPIO_PORT_B
#define 	LCD_RES_PIN		GPIO_PIN_05
#define 	LCD_DC_PORT		GPIO_PORT_B
#define		LCD_DC_PIN		GPIO_PIN_04
#define 	LCD_RES_SET()	GPIO_SetPins(LCD_RES_PORT, LCD_RES_PIN)
#define 	LCD_RES_CLR()	GPIO_ResetPins(LCD_RES_PORT, LCD_RES_PIN)
#define 	LCD_DC_SET()	GPIO_SetPins(LCD_DC_PORT, LCD_DC_PIN)
#define 	LCD_DC_CLR()	GPIO_ResetPins(LCD_DC_PORT, LCD_DC_PIN)

#define LCD_SCLK_Clr() GPIO_ResetPins(GPIO_PORT_B,GPIO_PIN_07)//SCL=SCLK
#define LCD_SCLK_Set() GPIO_SetPins(GPIO_PORT_B,GPIO_PIN_07)

#define LCD_MOSI_Clr() GPIO_ResetPins(GPIO_PORT_B,GPIO_PIN_06)//SDA=MOSI
#define LCD_MOSI_Set() GPIO_SetPins(GPIO_PORT_B,GPIO_PIN_06)

//画笔颜色
#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 //浅灰色(PANNEL),窗体背景色
#define LGRAYBLUE        0XA651 //浅灰蓝色(中间层颜色)
#define LBBLUE           0X2B12 //浅棕蓝色(选择条目的反色)

typedef void (*lcd_dma_callback_t)(void);
typedef void (*lcd_timer_callback_t)(void);

void hdl_lcd_init(void);

void hdl_lcd_send(uint8_t *data, uint16_t len);

void LCD_Address_Set(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2);

void LCD_DrawPoint(uint16_t x,uint16_t y,uint16_t color);

void hdl_lcd_fill(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint8_t *color);

void hdl_lcd_dma_callback_register(lcd_dma_callback_t pCBS);
void hdl_lcd_timer_callback_register(lcd_timer_callback_t pCBS);

#endif
