Files
player/Project/Src/Drive/Include/lcd_rgb.h

331 lines
8.6 KiB
C
Raw Normal View History

2025-06-27 00:32:57 +08:00
#ifndef __LCD_H
#define __LCD_H
#include "stm32f4xx.h"
#define LCD_CLK 9 //定义LCD驱动时钟这里为了方便计算数值应在10-70之间单位为M
#define HBP 40
#define VBP 8
#define HSW 1
#define VSW 1
#define HFP 5
#define VFP 8
#define LCD_Width 480 //LCD的像素长度
#define LCD_Height 272 //LCD的像素宽度
#define LCD_Pixels (LCD_Width*LCD_Height) //分辨率
#define LCD_MemoryAdd 0xD0000000 //显存的起始地址
// 第二层的显存的偏移地址
// 这里预留了emWin使用32位色格式时三缓冲所需的空间
// 计算方法以32位颜色格式为例每个像素点占4字节使用emWin三缓冲所需空间为480*272*4*3
//
#define LCD_MemoryAdd_OFFSET ((uint32_t)LCD_Width*LCD_Height*4*3)
/*---------------------- 函数声明 -------------------------*/
void LCD_Init(void);
void LCD_Backlight (u8 power);
/*-----------------------引脚定义--------------------------*/
//IO口时钟
#define LCD_GPIO_CLK RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD \
| RCC_AHB1Periph_GPIOJ | RCC_AHB1Periph_GPIOK | RCC_AHB1Periph_GPIOI
//红色数据线
#define LTDC_R0_PORT GPIOI
#define LTDC_R0_PIN GPIO_Pin_15
#define LTDC_R0_PINSOURCE GPIO_PinSource15
#define LTDC_R1_PORT GPIOJ
#define LTDC_R1_PIN GPIO_Pin_0
#define LTDC_R1_PINSOURCE GPIO_PinSource0
#define LTDC_R2_PORT GPIOJ
#define LTDC_R2_PIN GPIO_Pin_1
#define LTDC_R2_PINSOURCE GPIO_PinSource1
#define LTDC_R3_PORT GPIOJ
#define LTDC_R3_PIN GPIO_Pin_2
#define LTDC_R3_PINSOURCE GPIO_PinSource2
#define LTDC_R4_PORT GPIOJ
#define LTDC_R4_PIN GPIO_Pin_3
#define LTDC_R4_PINSOURCE GPIO_PinSource3
#define LTDC_R5_PORT GPIOJ
#define LTDC_R5_PIN GPIO_Pin_4
#define LTDC_R5_PINSOURCE GPIO_PinSource4
#define LTDC_R6_PORT GPIOJ
#define LTDC_R6_PIN GPIO_Pin_5
#define LTDC_R6_PINSOURCE GPIO_PinSource5
#define LTDC_R7_PORT GPIOJ
#define LTDC_R7_PIN GPIO_Pin_6
#define LTDC_R7_PINSOURCE GPIO_PinSource6
//绿色数据线
#define LTDC_G0_PORT GPIOJ
#define LTDC_G0_PIN GPIO_Pin_7
#define LTDC_G0_PINSOURCE GPIO_PinSource7
#define LTDC_G1_PORT GPIOJ
#define LTDC_G1_PIN GPIO_Pin_8
#define LTDC_G1_PINSOURCE GPIO_PinSource8
#define LTDC_G2_PORT GPIOJ
#define LTDC_G2_PIN GPIO_Pin_9
#define LTDC_G2_PINSOURCE GPIO_PinSource9
#define LTDC_G3_PORT GPIOJ
#define LTDC_G3_PIN GPIO_Pin_10
#define LTDC_G3_PINSOURCE GPIO_PinSource10
#define LTDC_G4_PORT GPIOJ
#define LTDC_G4_PIN GPIO_Pin_11
#define LTDC_G4_PINSOURCE GPIO_PinSource11
#define LTDC_G5_PORT GPIOK
#define LTDC_G5_PIN GPIO_Pin_0
#define LTDC_G5_PINSOURCE GPIO_PinSource0
#define LTDC_G6_PORT GPIOK
#define LTDC_G6_PIN GPIO_Pin_1
#define LTDC_G6_PINSOURCE GPIO_PinSource1
#define LTDC_G7_PORT GPIOK
#define LTDC_G7_PIN GPIO_Pin_2
#define LTDC_G7_PINSOURCE GPIO_PinSource2
//蓝色数据线
#define LTDC_B0_PORT GPIOJ
#define LTDC_B0_PIN GPIO_Pin_12
#define LTDC_B0_PINSOURCE GPIO_PinSource12
#define LTDC_B1_PORT GPIOJ
#define LTDC_B1_PIN GPIO_Pin_13
#define LTDC_B1_PINSOURCE GPIO_PinSource13
#define LTDC_B2_PORT GPIOJ
#define LTDC_B2_PIN GPIO_Pin_14
#define LTDC_B2_PINSOURCE GPIO_PinSource14
#define LTDC_B3_PORT GPIOJ
#define LTDC_B3_PIN GPIO_Pin_15
#define LTDC_B3_PINSOURCE GPIO_PinSource15
#define LTDC_B4_PORT GPIOK
#define LTDC_B4_PIN GPIO_Pin_3
#define LTDC_B4_PINSOURCE GPIO_PinSource3
#define LTDC_B5_PORT GPIOK
#define LTDC_B5_PIN GPIO_Pin_4
#define LTDC_B5_PINSOURCE GPIO_PinSource4
#define LTDC_B6_PORT GPIOK
#define LTDC_B6_PIN GPIO_Pin_5
#define LTDC_B6_PINSOURCE GPIO_PinSource5
#define LTDC_B7_PORT GPIOK
#define LTDC_B7_PIN GPIO_Pin_6
#define LTDC_B7_PINSOURCE GPIO_PinSource6
//控制信号线
#define LTDC_CLK_PORT GPIOI //LCD时钟引脚
#define LTDC_CLK_PIN GPIO_Pin_14
#define LTDC_CLK_PINSOURCE GPIO_PinSource14
#define LTDC_HSYNC_PORT GPIOI //行同步
#define LTDC_HSYNC_PIN GPIO_Pin_12
#define LTDC_HSYNC_PINSOURCE GPIO_PinSource12
#define LTDC_VSYNC_PORT GPIOI //帧同步
#define LTDC_VSYNC_PIN GPIO_Pin_13
#define LTDC_VSYNC_PINSOURCE GPIO_PinSource13
#define LTDC_DE_PORT GPIOK //数据使能
#define LTDC_DE_PIN GPIO_Pin_7
#define LTDC_DE_PINSOURCE GPIO_PinSource7
#define LTDC_Black_PORT GPIOD //背光
#define LTDC_Black_PIN GPIO_Pin_13
#define COLOR565TO888(color) ((((color)&0xf800)<<8)|((color)&0x07e0)<<5|(((color)&0x001f)<<3))
#define COLOR888TO565(color) ((((color)>>8)&0xf800)|(((color)>>5)&0x07e0)|(((color)>>3)&0x001f))
//把RGB转化为565格式
#define RGB(r,g,b) ((((r)>>3)<<11)|(((g)>>2)<<5)|((b)>>3))
//RGB转灰度
#define RGB2GRAY(rgb16) (((((rgb16)&0xf800)>>8)+(((rgb16)&0x07e0)>>3)+(((rgb16)&0x001f)<<3))/3)
//灰度转RGB
#define GRAY2RGB(gray) ((((gray)>>3)<<11)|(((gray)>>2)<<5)|((gray)>>3))
//#define U8 unsigned char
//#define U16 unsigned short
//#define U32 unsigned
//extern u32* LCD_ADDR;
//extern u32* LCD_ADDR1;
//typedef struct
//{
// u32 BackColor; //背景颜色
// u32 Color; //前景颜色
// u32 ScreenDis; //屏幕显示方向01
// u32 DrawMode; //绘制模式0绘制前景色时绘制背景色1绘制前景色时不绘制背景色
// u16 *DrawAddr; //绘制显存地址
// u32 LcdAddr; //当前指定的显存地址,在中断中执行切换
// u32 LcdSwitchEn; //1,当前可以切换到LcdAddr指定的显存地址0不允许切换
// int LayerBuffEnter; //进入缓冲区的次数
// int WindowSrcX; //绘制窗口起始坐标
// int WindowSrcY; //
// int WindowDstX;
// int WindowDstY;
//} LCD_Struct;
typedef struct
{
int xs;
int ys;
int xe;
int ye;
}LCD_WindowStruct;
typedef struct
{
int x_size;
int y_size;
int color;
int bkColor;
int effective; //1绘制窗口有效
LCD_WindowStruct win;
LCD_WindowStruct realwin;
u16 *draw;
u16 *show;
void(*fresh)(void);
int LcdSwitchEn;
int LayerBuffEnter;
}LCD_Struct;
// 函数LCD层设置初始化
//
void LCD_LayerInit(void);
//获取图像显示地址
u32 *LCD_GetShowAddr (void);
//获取图像绘制地址
u32 *LCD_GetDrawAddr (void);
u32 LCD_SetLayer (u32 AddrIndex);
u32 LCD_SetDrawLayer (u32 Index);
u32 LCD_SetLcdColor (u32 color);
u32 LCD_SetLcdBkColor (u32 color);
u32 LCD_SetLcdColor16 (u32 color);
u32 LCD_SetLcdBkColor16 (u32 color);
u32 LCD_GetLcdColor (void);
u32 LCD_GetLcdBkColor (void);
u32 LCD_GetLcdColor16 (void);
u32 LCD_GetLcdBkColor16 (void);
//层复制
void LCD_LayerCopy (int dst,int src);
//开始在缓冲区绘制
void LCD_LayerBufferOn (void);
//显示缓冲层
void LCD_LayerBuffShow (void);
//获取屏幕刷新状态1已刷新
int LCD_GetLayerUpdataStat (void);
//进入缓冲区
void LCD_EnterLayerBuff (void);
//切换层,不用复制显示,播放视频时用
void LCD_SwitchLayerBuff (void);
//退出缓冲区
void LCD_ExitLayerBuff (void);
//设置活动窗口
void LCD_SetWindow (int x_s,int y_s,int x_size,int y_size);
int LCD_GetWindowSizeX (void);
int LCD_GetWindowSizeY (void);
int LCD_GetLcdSizeX(void);
int LCD_GetLcdSizeY (void);
//设置绘制模式1不绘制背景0绘制背景
void LCD_SetLcdDrawMode (int mode);
void LCD_Clear (void);
//清除矩形内的显示
void LCD_ClearRect (int x,int y,int x_size,int y_size);
void LCD_DrawPoint (int x,int y,u32 mode);
void LCD_DrawPointSafe (int x,int y,u32 mode);
//以指定颜色画点,而不是前景色
void LCD_DrawPointSafeColor (int x,int y,u16 color);
//以指定色透明度画点0~32
void LCD_DrawPointSafeColorAlpha (int x,int y,u16 color,u8 alpha);
//填充矩形,已窗口坐标为原点
void LCD_FillRectByColor (int x,int y,int x_size,int y_size);
//以透明度填充矩形,已窗口坐标为原点
void LCD_FillRectByColorAlpha (int x,int y,int x_size,int y_size,u8 alpha);
//void LCD_FillRect16 (u16 *buff,int xsize,int ysize);
//void LCD_FillRectOff16 (u16 *buff,int x_s,int y_s,int xsize,int ysize);
void LCD_FillRectOff16At (int s_x,int s_y,int s_xsize,int s_ysize,u16 *buff,int x_s,int y_s,int xsize,int ysize);
//用有透明度的图片填充
void LCD_FillRectOffAtAlpha (int s_x,int s_y,int s_xsize,int s_ysize,void *buff,int x_s,int y_s,int xsize,int ysize);
void LCD_GetColors (u16 *buff,int x_s,int y_s,int x_size,int y_size);
#endif