/******************************************************************************* * Copyright(c) 2023 Levetop Semiconductor Co.,Led. All rights reserved. * @file LT768_Lib.h * @author UartTFT Application Team * @version V1.0.0 * @date 2023-02-24 * @brief LT768x All Function Functions ********************************************************************************/ #ifndef _LT768_Lib_H #define _LT768_Lib_H #include "LT768.h" #include "if_port.h" #include "sincostable.h" #include "bsp.h" #include "module_select.h" // External crystal oscillator #define XI_4M 0 #define XI_5M 1 #define XI_6M 0 #define XI_8M 0 #define XI_10M 0 #define XI_12M 0 extern uint8_t TFT_color; extern uint16_t LCD_XSIZE_TFT; extern uint16_t LCD_YSIZE_TFT; extern uint16_t LCD_VBPD; extern uint16_t LCD_VFPD; extern uint16_t LCD_VSPW; extern uint16_t LCD_HBPD; extern uint16_t LCD_HFPD; extern uint16_t LCD_HSPW; extern uint8_t gPCLKRISING; extern uint8_t gHSYNCPolarity; extern uint8_t gVSYNCPolarity; extern uint8_t gDEPolarity; extern uint8_t CCLK; // Core clock frequency of LT768 extern uint8_t MCLK; // Clock frequency of SDRAM extern uint8_t SCLK; // Scan clock frequency of LCD #define color256_black 0x00 #define color256_white 0xff #define color256_red 0xe0 #define color256_green 0x1c #define color256_blue 0x03 #define color256_yellow color256_red | color256_green #define color256_cyan color256_green | color256_blue #define color256_purple color256_red | color256_blue #define color65k_black 0x0000 #define color65k_white 0xffff #define color65k_red 0xf800 #define color65k_green 0x07e0 #define color65k_blue 0x001f #define color65k_yellow color65k_red | color65k_green #define color65k_cyan color65k_green | color65k_blue #define color65k_purple color65k_red | color65k_blue #define color65k_grayscale1 2113 #define color65k_grayscale2 2113 * 2 #define color65k_grayscale3 2113 * 3 #define color65k_grayscale4 2113 * 4 #define color65k_grayscale5 2113 * 5 #define color65k_grayscale6 2113 * 6 #define color65k_grayscale7 2113 * 7 #define color65k_grayscale8 2113 * 8 #define color65k_grayscale9 2113 * 9 #define color65k_grayscale10 2113 * 10 #define color65k_grayscale11 2113 * 11 #define color65k_grayscale12 2113 * 12 #define color65k_grayscale13 2113 * 13 #define color65k_grayscale14 2113 * 14 #define color65k_grayscale15 2113 * 15 #define color65k_grayscale16 2113 * 16 #define color65k_grayscale17 2113 * 17 #define color65k_grayscale18 2113 * 18 #define color65k_grayscale19 2113 * 19 #define color65k_grayscale20 2113 * 20 #define color65k_grayscale21 2113 * 21 #define color65k_grayscale22 2113 * 22 #define color65k_grayscale23 2113 * 23 #define color65k_grayscale24 2113 * 24 #define color65k_grayscale25 2113 * 25 #define color65k_grayscale26 2113 * 26 #define color65k_grayscale27 2113 * 27 #define color65k_grayscale28 2113 * 28 #define color65k_grayscale29 2113 * 29 #define color65k_grayscale30 2113 * 30 #define color16M_Gray 0x00c0c0c0 #define color16M_black 0x00000000 #define color16M_white 0x00ffffff #define color16M_red 0x00ff0000 #define color16M_green 0x0000ff00 #define color16M_blue 0x000000ff #define color16M_yellow color16M_red | color16M_green #define color16M_cyan color16M_green | color16M_blue #define color16M_purple color16M_red | color16M_blue /* LCD color */ #define White TFT_bitcolor == 0 ? 0xFFFF : 0x00FFFFFF #define Black TFT_bitcolor == 0 ? 0x0000 : 0x00000000 #define Grey TFT_bitcolor == 0 ? 0xF7DE : 0x00c0c0c0 #define Blue TFT_bitcolor == 0 ? 0x001F : 0x000000ff #define Blue2 TFT_bitcolor == 0 ? 0x051F : 0x000000ff #define Red TFT_bitcolor == 0 ? 0xF800 : 0x00ff0000 #define Green TFT_bitcolor == 0 ? 0x07E0 : 0x0000ff00 #define Cyan TFT_bitcolor == 0 ? 0x7FFF : (color16M_green | color16M_blue) #define Yellow TFT_bitcolor == 0 ? 0xFFE0 : (color16M_red | color16M_green) #define Line0 0 #define Line1 24 #define Line2 48 #define Line3 72 #define Line4 96 #define Line5 120 #define Line6 144 #define Line7 168 #define Line8 192 #define Line9 216 #define Line10 240 #define Line11 264 #define Line12 288 #define Line13 312 #define Line14 336 #define Line15 360 #define Line16 384 #define Line17 408 #define Line18 432 #define Line19 456 #define Line20 480 #define Line21 504 #define Line22 528 #define Line23 552 #define Line24 576 #define Line25 600 typedef struct { int X; int Y; } CPoint; void LT768_PLL_Initial(void); void LT768_SDRAM_initail(uint8_t mclk); void Set_LCD_Panel(void); void LT768_Init(void); void LT_ReadParam(void); /* Write data to memory */ void MPU8_8bpp_Memory_Write(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint8_t *data); void MPU8_16bpp_Memory_Write(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint8_t *data); void MPU8_24bpp_Memory_Write(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint8_t *data); void MPU16_16bpp_Memory_Write(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint16_t *data); void MPU16_24bpp_Mode1_Memory_Write(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint16_t *data); void MPU16_24bpp_Mode2_Memory_Write(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint16_t *data); /* Hardware drawing line segment */ void LT768_DrawLine(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2, uint32_t LineColor); void LT768_DrawLine_Width(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2, uint32_t LineColor, uint16_t Width); /* Hardware circle */ void LT768_DrawCircle(uint16_t XCenter, uint16_t YCenter, uint16_t R, uint32_t CircleColor); void LT768_DrawCircle_Fill(uint16_t XCenter, uint16_t YCenter, uint16_t R, uint32_t ForegroundColor); void LT768_DrawCircle_Width(uint16_t XCenter, uint16_t YCenter, uint16_t R, uint32_t CircleColor, uint32_t ForegroundColor, uint16_t Width); /* Hardware drawing ellipse */ void LT768_DrawEllipse(uint16_t XCenter, uint16_t YCenter, uint16_t X_R, uint16_t Y_R, uint32_t EllipseColor); void LT768_DrawEllipse_Fill(uint16_t XCenter, uint16_t YCenter, uint16_t X_R, uint16_t Y_R, uint32_t ForegroundColor); void LT768_DrawEllipse_Width(uint16_t XCenter, uint16_t YCenter, uint16_t X_R, uint16_t Y_R, uint32_t EllipseColor, uint32_t ForegroundColor, uint16_t Width); /* Hardware drawing rectangle */ void LT768_DrawSquare(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2, uint32_t SquareColor); void LT768_DrawSquare_Fill(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2, uint32_t ForegroundColor); void LT768_DrawSquare_Width(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2, uint32_t SquareColor, uint32_t ForegroundColor, uint16_t Width); /* Hardware drawing rounded rectangle */ void LT768_DrawCircleSquare(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2, uint16_t X_R, uint16_t Y_R, uint32_t CircleSquareColor); void LT768_DrawCircleSquare_Fill(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2, uint16_t X_R, uint16_t Y_R, uint32_t ForegroundColor); void LT768_DrawCircleSquare_Width(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2, uint16_t X_R, uint16_t Y_R, uint32_t CircleSquareColor, uint32_t ForegroundColor, uint16_t Width); /* Hardware drawing triangle */ void LT768_DrawTriangle(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2, uint16_t X3, uint16_t Y3, uint32_t TriangleColor); void LT768_DrawTriangle_Fill(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2, uint16_t X3, uint16_t Y3, uint32_t ForegroundColor); void LT768_DrawTriangle_Frame(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2, uint16_t X3, uint16_t Y3, uint32_t TriangleColor, uint32_t ForegroundColor); /* Hardware drawing quadrilateral */ void LT768_DrawQuadrilateral(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2, uint16_t X3, uint16_t Y3, uint16_t X4, uint16_t Y4, uint32_t ForegroundColor); void LT768_DrawQuadrilateral_Fill(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2, uint16_t X3, uint16_t Y3, uint16_t X4, uint16_t Y4, uint32_t ForegroundColor); void LT768_DrawTriangle_Frame(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2, uint16_t X3, uint16_t Y3, uint32_t TriangleColor, uint32_t ForegroundColor); /* Hardware drawing pentagon */ void LT768_DrawPentagon(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2, uint16_t X3, uint16_t Y3, uint16_t X4, uint16_t Y4, uint16_t X5, uint16_t Y5, uint32_t ForegroundColor); void LT768_DrawPentagon_Fill(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2, uint16_t X3, uint16_t Y3, uint16_t X4, uint16_t Y4, uint16_t X5, uint16_t Y5, uint32_t ForegroundColor); /* Hardware drawing curve */ void LT768_DrawLeftUpCurve(uint16_t XCenter, uint16_t YCenter, uint16_t X_R, uint16_t Y_R, uint32_t CurveColor); void LT768_DrawLeftDownCurve(uint16_t XCenter, uint16_t YCenter, uint16_t X_R, uint16_t Y_R, uint32_t CurveColor); void LT768_DrawRightUpCurve(uint16_t XCenter, uint16_t YCenter, uint16_t X_R, uint16_t Y_R, uint32_t CurveColor); void LT768_DrawRightDownCurve(uint16_t XCenter, uint16_t YCenter, uint16_t X_R, uint16_t Y_R, uint32_t CurveColor); void LT768_SelectDrawCurve(uint16_t XCenter, uint16_t YCenter, uint16_t X_R, uint16_t Y_R, uint32_t CurveColor, uint16_t Dir); /* Hardware drawing 1/4 ellipse */ void LT768_DrawLeftUpCurve_Fill(uint16_t XCenter, uint16_t YCenter, uint16_t X_R, uint16_t Y_R, uint32_t ForegroundColor); void LT768_DrawLeftDownCurve_Fill(uint16_t XCenter, uint16_t YCenter, uint16_t X_R, uint16_t Y_R, uint32_t ForegroundColor); void LT768_DrawRightUpCurve_Fill(uint16_t XCenter, uint16_t YCenter, uint16_t X_R, uint16_t Y_R, uint32_t ForegroundColor); void LT768_DrawRightDownCurve_Fill(uint16_t XCenter, uint16_t YCenter, uint16_t X_R, uint16_t Y_R, uint32_t ForegroundColor); void LT768_SelectDrawCurve_Fill(uint16_t XCenter, uint16_t YCenter, uint16_t X_R, uint16_t Y_R, uint32_t CurveColor, uint16_t Dir); /* Hardware drawing cylinder */ uint8_t LT768_DrawCylinder(uint16_t XCenter, uint16_t YCenter, uint16_t X_R, uint16_t Y_R, uint16_t H, uint32_t CylinderColor, uint32_t ForegroundColor, uint8_t Width); /* Hardware drawing quadrangle */ void LT768_DrawQuadrangular(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2, uint16_t X3, uint16_t Y3, uint16_t X4, uint16_t Y4, uint16_t X5, uint16_t Y5, uint16_t X6, uint16_t Y6, uint32_t QuadrangularColor, uint32_t ForegroundColor); void LT768_DrawQuadrangular1(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2, uint16_t W, uint16_t H, uint32_t QuadrangularColor, uint32_t ForegroundColor, uint8_t Width); /* table */ void LT768_MakeTable(uint16_t X1, uint16_t Y1, uint16_t W, uint16_t H, uint16_t Line, uint16_t Row, uint32_t TableColor, uint32_t ItemColor, uint32_t ForegroundColor, uint16_t width1, uint16_t width2, uint8_t mode); /* DMA transfers data to SDRAM in linear mode */ void LT768_DMA_24bit_Linear(uint8_t SCS, uint8_t Clk, uint32_t flash_addr, uint32_t memory_ad, uint32_t data_num); void LT768_DMA_32bit_Linear(uint8_t SCS, uint8_t Clk, uint32_t flash_addr, uint32_t memory_ad, uint32_t data_num); /* DMA transfers data to SDRAM in block mode */ // void LT768_DMA_24bit_Block(uint8_t SCS,uint8_t Clk,uint16_t X1,uint16_t Y1 ,uint16_t X_W,uint16_t Y_H,uint16_t P_W,uint32_t Addr); void LT768_DMA_32bit_Block(uint8_t SCS, uint8_t Clk, uint16_t X1, uint16_t Y1, uint16_t X_W, uint16_t Y_H, uint16_t P_W, uint32_t Addr); /* Use built-in font */ void LT768_Select_Internal_Font_Init(uint8_t Size, uint8_t XxN, uint8_t YxN, uint8_t ChromaKey, uint8_t Alignment); void LT768_Print_Internal_Font_String(uint16_t x, uint16_t y, uint32_t FontColor, uint32_t BackGroundColor, char *c); /* Block transfer engine (BitBLT) */ void BTE_Solid_Fill(uint32_t Des_Addr, uint16_t Des_W, uint16_t XDes, uint16_t YDes, uint16_t color, uint16_t X_W, uint16_t Y_H); void LT768_BTE_Memory_Copy(uint32_t S0_Addr, uint16_t S0_W, uint16_t XS0, uint16_t YS0, uint32_t S1_Addr, uint16_t S1_W, uint16_t XS1, uint16_t YS1, uint32_t Des_Addr, uint16_t Des_W, uint16_t XDes, uint16_t YDes, unsigned int ROP_Code, uint16_t X_W, uint16_t Y_H); void LT768_BTE_Memory_Copy_Chroma_key(uint32_t S0_Addr, uint16_t S0_W, uint16_t XS0, uint16_t YS0, uint32_t Des_Addr, uint16_t Des_W, uint16_t XDes, uint16_t YDes, uint32_t Background_color, uint16_t X_W, uint16_t Y_H); void LT768_BTE_Pattern_Fill(uint8_t P_8x8_or_16x16, uint32_t S0_Addr, uint16_t S0_W, uint16_t XS0, uint16_t YS0, uint32_t Des_Addr, uint16_t Des_W, uint16_t XDes, uint16_t YDes, unsigned int ROP_Code, uint16_t X_W, uint16_t Y_H); void LT768_BTE_Pattern_Fill_With_Chroma_key(uint8_t P_8x8_or_16x16, uint32_t S0_Addr, uint16_t S0_W, uint16_t XS0, uint16_t YS0, uint32_t Des_Addr, uint16_t Des_W, uint16_t XDes, uint16_t YDes, unsigned int ROP_Code, uint32_t Background_color, uint16_t X_W, uint16_t Y_H); void LT768_BTE_MCU_Write_MCU_16bit(uint32_t S1_Addr, uint16_t S1_W, uint16_t XS, uint16_t YS1, uint32_t Des_Addr, uint16_t Des_W, uint16_t XDes, uint16_t YDes, unsigned int ROP_Code, uint16_t X_W, uint16_t Y_H, const uint16_t *data); void LT768_BTE_MCU_Write_Chroma_key_MCU_16bit(uint32_t Des_Addr, uint16_t Des_W, uint16_t XDes, uint16_t YDes, uint32_t Background_color, uint16_t X_W, uint16_t Y_H, const uint16_t *data); void LT768_BTE_MCU_Write_ColorExpansion_MCU_16bit(uint32_t Des_Addr, uint16_t Des_W, uint16_t XDes, uint16_t YDes, uint16_t X_W, uint16_t Y_H, uint32_t Foreground_color, uint32_t Background_color, const uint16_t *data); void LT768_BTE_MCU_Write_ColorExpansion_Chroma_key_MCU_16bit(uint32_t Des_Addr, uint16_t Des_W, uint16_t XDes, uint16_t YDes, uint16_t X_W, uint16_t Y_H, uint32_t Foreground_color, const uint16_t *data); void BTE_Alpha_Blending(uint32_t S0_Addr, uint16_t S0_W, uint16_t XS0, uint16_t YS0, uint32_t S1_Addr, uint16_t S1_W, uint16_t XS1, uint16_t YS1, uint32_t Des_Addr, uint16_t Des_W, uint16_t XDes, uint16_t YDes, uint16_t X_W, uint16_t Y_H, uint8_t alpha); void LT768_BTE_Memory_Copy_1(uint32_t S0_Addr, uint16_t S0_W, uint16_t XS0, uint16_t YS0, uint32_t S1_Addr, uint16_t S1_W, uint16_t XS1, uint16_t YS1, uint32_t Des_Addr, uint16_t Des_W, uint16_t XDes, uint16_t YDes, unsigned int ROP_Code, uint16_t X_W, uint16_t Y_H, uint8_t Pic_flag); /* PIP */ void LT768_PIP_Init(uint8_t On_Off, uint8_t Select_PIP, uint32_t PAddr, uint16_t XP, uint16_t YP, uint32_t ImageWidth, uint16_t X_Dis, uint16_t Y_Dis, uint16_t X_W, uint16_t Y_H); void LT768_Set_DisWindowPos(uint8_t On_Off, uint8_t Select_PIP, uint16_t X_Dis, uint16_t Y_Dis); /* PWM */ void LT768_PWM0_Init(uint8_t on_off, uint8_t Clock_Divided, uint8_t Prescalar, uint16_t Count_Buffer, uint16_t Compare_Buffer); void LT768_PWM1_Init(uint8_t on_off, uint8_t Clock_Divided, uint8_t Prescalar, uint16_t Count_Buffer, uint16_t Compare_Buffer); void LT768_PWM0_Duty(uint16_t Compare_Buffer); void LT768_PWM1_Duty(uint16_t Compare_Buffer); /* Standby Mode */ void LT768_Standby(void); void LT768_Wkup_Standby(void); /* Suspend Mode */ void LT768_Suspend(void); void LT768_Wkup_Suspend(void); /* Sleep Mode */ void LT768_SleepMode(void); void LT768_Wkup_Sleep(void); void LT768_SPI_Init(uint8_t div, uint8_t cs); void LT768_BTE_Memory_Copy_ColorExpansion_8 ( uint32_t S0_Addr // Memory start address of SO image , uint16_t YS0 // S0 Upper left Y coordinate of image , uint32_t Des_Addr // Memory start address of destination image , uint16_t Des_W // Width of destination image , uint16_t XDes // Top left X coordinate of destination image , uint16_t YDes // Top left Y coordinate of destination image , uint16_t X_W // The width of the active window , uint16_t Y_H // The length of the active window , uint32_t Foreground_color // Foreground color , uint32_t Background_color // Background color ); void LT768_BTE_Memory_Copy_ColorExpansion_Chroma_key_8 ( uint32_t S0_Addr // Memory start address of SO image , uint16_t YS0 // S0 Upper left Y coordinate of image , uint32_t Des_Addr // Memory start address of destination image , uint16_t Des_W // Width of destination image , uint16_t XDes // Top left X coordinate of destination image , uint16_t YDes // Top left Y coordinate of destination image , uint16_t X_W // The width of the active window , uint16_t Y_H // The length of the active window , uint32_t Foreground_color // Foreground color ); void LT768_DMA_24bit_Block_Or_Line_16bpp ( uint8_t SCS // SPI : SCS£º0 SCS£º1 , uint8_t Clk // SPI clock division parameter : SPI Clock = System Clock /{(Clk+1)*2} , uint16_t X1 // Location transferred to memory X1 , uint16_t Y1 // Location transferred to memory Y1 , uint16_t X_W // Width of DMA transmission data , uint16_t Y_H // Height of DMA transmission data , uint16_t P_W // Width of picture , uint32_t Addr // Flash address , uint32_t lay0 // Address of layer , uint16_t canvas_w // Layer width ); void BTE_Pixel_16bpp_Alpha_Blending // 16-bit png image display function ( uint32_t S0_Addr // Memory start address of SO image , uint16_t S0_W // S0 Width of image , uint16_t XS0 // S0 Top left X coordinate of image , uint16_t YS0 // S0 Upper left Y coordinate of image , uint32_t S1_Addr // Memory start address of S1 image , uint16_t S1_W // S1 Width of image , uint16_t XS1 // Top left X coordinate of S1 image , uint16_t YS1 // The upper left Y coordinate of S1 image , uint32_t Des_Addr // Memory start address of destination image , uint16_t Des_W // Width of destination image , uint16_t XDes // Top left X coordinate of destination image , uint16_t YDes // Top left Y coordinate of destination image , uint16_t X_W // The width of the active window , uint16_t Y_H // The length of the active window ); void LT768_Draw_16bit ( uint8_t SCS // SPI : SCS£º0 SCS£º1 , uint8_t Clk // SPI clock division parameter : SPI Clock = System Clock /{(Clk+1)*2} , uint16_t X1 // Location transferred to memory X1 , uint16_t Y1 // Location transferred to memory Y1 , uint16_t X_W // Width of DMA transmission data , uint16_t Y_H // Height of DMA transmission data , uint16_t P_W // Width of picture , uint16_t pixel_format // Gray scale , uint32_t F_Color // Font color , uint32_t Addr // Flash address , uint32_t lay0 // Address of layer , uint16_t canvas_w // Layer width ); void LT768_Draw_16bit_2 ( uint8_t SCS // SPI : SCS£º0 SCS£º1 , uint8_t Clk // SPI clock division parameter : SPI Clock = System Clock /{(Clk+1)*2} , uint16_t X1 // Location transferred to memory X1 , uint16_t Y1 // Location transferred to memory Y1 , uint16_t X_W // Width of DMA transmission data , uint16_t Y_H // Height of DMA transmission data , uint16_t P_W // Width of picture , uint16_t pixel_format // Gray scale , uint32_t F_Color // Font color , uint32_t B_Color // Background color , uint8_t transparent // Show background se , uint32_t Addr // Flash address , uint32_t lay0 // Address of layer , uint16_t canvas_w // Layer width ); #endif