WhyCan Forum(哇酷开发者社区)

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn

您尚未登录。

#1 2019-12-09 08:27:48

晕哥
管理员
注册时间: 2017-09-06
累计积分: 9,190

spi + rgb LG4573 屏驱动资料 (已售罄)

转自@祝晓明: LG4573B_STM32F103RBT6_Hardware_SPI.zip


注意: 此代码只完成了 LG4573 的初始化, 并没有驱动屏幕, 需要用soc提供PCLK, HSYNC/VSYNC, RGB等信号

离线

#2 2019-12-09 08:29:52

晕哥
管理员
注册时间: 2017-09-06
累计积分: 9,190

Re: spi + rgb LG4573 屏驱动资料 (已售罄)

核心驱动代码:

#include "lcd.h"
#include "stdlib.h"
#include "delay.h"	 
#include "spi.h"

	   
//管理LCD重要参数
//默认为竖屏
_lcd_dev lcddev;

//画笔颜色,背景颜色
u16 POINT_COLOR = 0x0000,BACK_COLOR = 0xFFFF;  
u16 DeviceCode;	 

/*****************************************************************************
 * @name       :void LCD_WR_REG(u8 data)
 * @date       :2018-08-09 
 * @function   :Write an 8-bit command to the LCD screen
 * @parameters :data:Command value to be written
 * @retvalue   :None
******************************************************************************/
void LCD_WR_REG(u8 data)
{ 
   LCD_CS_CLR;     
   SPI_WriteByte(SPI2,0x70); 
   SPI_WriteByte(SPI2,data);
   LCD_CS_SET;	
}

/*****************************************************************************
 * @name       :void LCD_WR_DATA(u8 data)
 * @date       :2018-08-09 
 * @function   :Write an 8-bit data to the LCD screen
 * @parameters :data:data value to be written
 * @retvalue   :None
******************************************************************************/
void LCD_WR_DATA(u8 data)
{
   LCD_CS_CLR;
   SPI_WriteByte(SPI2,0x72); 
   SPI_WriteByte(SPI2,data);
   LCD_CS_SET;
}

/*****************************************************************************
 * @name       :void LCD_WriteReg(u8 LCD_Reg, u16 LCD_RegValue)
 * @date       :2018-08-09 
 * @function   :Write data into registers
 * @parameters :LCD_Reg:Register address
                LCD_RegValue:Data to be written
 * @retvalue   :None
******************************************************************************/
void LCD_WriteReg(u8 LCD_Reg, u8 LCD_RegValue)
{	
	LCD_WR_REG(LCD_Reg);  
	LCD_WR_DATA(LCD_RegValue);	    		 
}	   

/*****************************************************************************
 * @name       :void LCD_WriteRAM_Prepare(void)
 * @date       :2018-08-09 
 * @function   :Write GRAM
 * @parameters :None
 * @retvalue   :None
******************************************************************************/	 
void LCD_WriteRAM_Prepare(void)
{
	LCD_WR_REG(lcddev.wramcmd);
}	 

/*****************************************************************************
 * @name       :void Lcd_WriteData_16Bit(u16 Data)
 * @date       :2018-08-09 
 * @function   :Write an 16-bit command to the LCD screen
 * @parameters :Data:Data to be written
 * @retvalue   :None
******************************************************************************/	 
void Lcd_WriteData_16Bit(u16 Data)
{	
   LCD_CS_CLR;
   SPI_WriteByte(SPI2,0x72); 
   SPI_WriteByte(SPI2,Data>>8);
	 SPI_WriteByte(SPI2,Data);
   LCD_CS_SET;
}

/*****************************************************************************
 * @name       :void LCD_DrawPoint(u16 x,u16 y)
 * @date       :2018-08-09 
 * @function   :Write a pixel data at a specified location
 * @parameters :x:the x coordinate of the pixel
                y:the y coordinate of the pixel
 * @retvalue   :None
******************************************************************************/	
void LCD_DrawPoint(u16 x,u16 y)
{
	LCD_SetCursor(x,y);//设置光标位置 
	Lcd_WriteData_16Bit(POINT_COLOR); 
}

/*****************************************************************************
 * @name       :void LCD_Clear(u16 Color)
 * @date       :2018-08-09 
 * @function   :Full screen filled LCD screen
 * @parameters :color:Filled color
 * @retvalue   :None
******************************************************************************/	
void LCD_Clear(u16 Color)
{
  unsigned int i,m;  
	LCD_SetWindows(0,0,lcddev.width-1,lcddev.height-1);   
	LCD_CS_CLR;
	for(i=0;i<lcddev.height;i++)
	{
    for(m=0;m<lcddev.width;m++)
    {	
			Lcd_WriteData_16Bit(Color);
		}
	}
	 LCD_CS_SET;
} 

/*****************************************************************************
 * @name       :void LCD_GPIOInit(void)
 * @date       :2018-08-09 
 * @function   :Initialization LCD screen GPIO
 * @parameters :None
 * @retvalue   :None
******************************************************************************/	
void LCD_GPIOInit(void)
{
	GPIO_InitTypeDef  GPIO_InitStructure;	      
	RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB ,ENABLE);	//使能GPIOB时钟
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9| GPIO_Pin_10| GPIO_Pin_11| GPIO_Pin_12; //GPIOB9,10,11,12
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;   //推挽输出
	GPIO_Init(GPIOB, &GPIO_InitStructure);//初始化
}

/*****************************************************************************
 * @name       :void LCD_RESET(void)
 * @date       :2018-08-09 
 * @function   :Reset LCD screen
 * @parameters :None
 * @retvalue   :None
******************************************************************************/	
void LCD_RESET(void)
{
	LCD_RST_CLR;
	delay_ms(100);	
	LCD_RST_SET;
	delay_ms(50);
}

/*****************************************************************************
 * @name       :void LCD_RESET(void)
 * @date       :2018-08-09 
 * @function   :Initialization LCD screen
 * @parameters :None
 * @retvalue   :None
******************************************************************************/	 	 
void LCD_Init(void)
{  
	SPI2_Init(); //硬件SPI2初始化
	LCD_GPIOInit();//LCD GPIO初始化										 
 	LCD_RESET(); //LCD 复位
//************3.2  inch LG4573B 初始化**********//	
	//lg4573 display mode settings
	LCD_WR_REG(0x3A);
	LCD_WR_DATA(0x66);
	
	LCD_WR_REG(0xB1);
	LCD_WR_DATA(0x08);
	LCD_WR_DATA(0x3B);
	LCD_WR_DATA(0x0F);
	
	LCD_WR_REG(0xB2);
	LCD_WR_DATA(0x00);
	LCD_WR_DATA(0xC8);
	
	LCD_WR_REG(0xB3);
	LCD_WR_DATA(0x00);
	
	LCD_WR_REG(0xB4);
	LCD_WR_DATA(0x00);
	
	LCD_WR_REG(0xB5);
	LCD_WR_DATA(0x42);
	LCD_WR_DATA(0x10);
	LCD_WR_DATA(0x10);
	LCD_WR_DATA(0x00);
	LCD_WR_DATA(0x20);
	
	LCD_WR_REG(0xB6);
	LCD_WR_DATA(0x0B);
	LCD_WR_DATA(0x0F);
	LCD_WR_DATA(0x3C);
	LCD_WR_DATA(0x13);
	LCD_WR_DATA(0x13);
	LCD_WR_DATA(0xE8);
	
	LCD_WR_REG(0xB7);
	LCD_WR_DATA(0x46);
	LCD_WR_DATA(0x06);
	LCD_WR_DATA(0x0C);
	LCD_WR_DATA(0x00);
	LCD_WR_DATA(0x00);
	
	//lg4573 power settings	 
	LCD_WR_REG(0xC0);
	LCD_WR_DATA(0x01);
	LCD_WR_DATA(0x11);
	
	LCD_WR_REG(0xC3);
	LCD_WR_DATA(0x07);
	LCD_WR_DATA(0x03);
	LCD_WR_DATA(0x04);
	LCD_WR_DATA(0x04);
	LCD_WR_DATA(0x04);
	
	LCD_WR_REG(0xC4);
	LCD_WR_DATA(0x12);
	LCD_WR_DATA(0x24);
	LCD_WR_DATA(0x18);
	LCD_WR_DATA(0x18);
	LCD_WR_DATA(0x02);
	LCD_WR_DATA(0x49);
	
	LCD_WR_REG(0xC5);
	LCD_WR_DATA(0x6F);
	
	LCD_WR_REG(0xC6);
	LCD_WR_DATA(0x41);
	LCD_WR_DATA(0x63);
	//lg4573 gamma settings	  
	LCD_WR_REG(0xD0);
	LCD_WR_DATA(0x03);
	LCD_WR_DATA(0x07);
	LCD_WR_DATA(0x73);
	LCD_WR_DATA(0x35);
	LCD_WR_DATA(0x00);
	LCD_WR_DATA(0x01);
	LCD_WR_DATA(0x20);
	LCD_WR_DATA(0x00);
	LCD_WR_DATA(0x03);
	
	LCD_WR_REG(0xD1);
	LCD_WR_DATA(0x03);
	LCD_WR_DATA(0x07);
	LCD_WR_DATA(0x73);
	LCD_WR_DATA(0x35);
	LCD_WR_DATA(0x00);
	LCD_WR_DATA(0x01);
	LCD_WR_DATA(0x20);
	LCD_WR_DATA(0x00);
	LCD_WR_DATA(0x03);
	
	LCD_WR_REG(0xD2);
	LCD_WR_DATA(0x03);
	LCD_WR_DATA(0x07);
	LCD_WR_DATA(0x73);
	LCD_WR_DATA(0x35);
	LCD_WR_DATA(0x00);
	LCD_WR_DATA(0x01);
	LCD_WR_DATA(0x20);
	LCD_WR_DATA(0x00);
	LCD_WR_DATA(0x03);
	
	LCD_WR_REG(0xD3);
	LCD_WR_DATA(0x03);
	LCD_WR_DATA(0x07);
	LCD_WR_DATA(0x73);
	LCD_WR_DATA(0x35);
	LCD_WR_DATA(0x00);
	LCD_WR_DATA(0x01);
	LCD_WR_DATA(0x20);
	LCD_WR_DATA(0x00);
	LCD_WR_DATA(0x03);
	
	LCD_WR_REG(0xD4);
	LCD_WR_DATA(0x03);
	LCD_WR_DATA(0x07);
	LCD_WR_DATA(0x73);
	LCD_WR_DATA(0x35);
	LCD_WR_DATA(0x00);
	LCD_WR_DATA(0x01);
	LCD_WR_DATA(0x20);
	LCD_WR_DATA(0x00);
	LCD_WR_DATA(0x03);
	
	LCD_WR_REG(0xD5);
	LCD_WR_DATA(0x03);
	LCD_WR_DATA(0x07);
	LCD_WR_DATA(0x73);
	LCD_WR_DATA(0x35);
	LCD_WR_DATA(0x00);
	LCD_WR_DATA(0x01);
	LCD_WR_DATA(0x20);
	LCD_WR_DATA(0x00);
	LCD_WR_DATA(0x03);
	
	//lg4573 power_on
	LCD_WR_REG(0x21);  //Display Inversion ON  
	LCD_WR_REG(0x11);   //Exit Sleep
	delay_ms(20);
	LCD_WR_REG(0x11);
	delay_ms(120);
	LCD_WR_REG(0x29);

  LCD_direction(USE_HORIZONTAL);//设置LCD显示方向
	LCD_LED=1;//点亮背光	 
//	LCD_Clear(WHITE);//清全屏白色
}
 
/*****************************************************************************
 * @name       :void LCD_SetWindows(u16 xStar, u16 yStar,u16 xEnd,u16 yEnd)
 * @date       :2018-08-09 
 * @function   :Setting LCD display window
 * @parameters :xStar:the bebinning x coordinate of the LCD display window
								yStar:the bebinning y coordinate of the LCD display window
								xEnd:the endning x coordinate of the LCD display window
								yEnd:the endning y coordinate of the LCD display window
 * @retvalue   :None
******************************************************************************/ 
void LCD_SetWindows(u16 xStar, u16 yStar,u16 xEnd,u16 yEnd)
{	

	LCD_WR_REG(lcddev.setxcmd);	
	LCD_WR_DATA(xStar>>8);
	LCD_WR_DATA(0x00FF&xStar);		
	LCD_WR_DATA(xEnd>>8);
	LCD_WR_DATA(0x00FF&xEnd);

	LCD_WR_REG(lcddev.setycmd);	
	LCD_WR_DATA(yStar>>8);
	LCD_WR_DATA(0x00FF&yStar);		
	LCD_WR_DATA(yEnd>>8);
	LCD_WR_DATA(0x00FF&yEnd);	

	LCD_WriteRAM_Prepare();	//开始写入GRAM	

}   

/*****************************************************************************
 * @name       :void LCD_SetCursor(u16 Xpos, u16 Ypos)
 * @date       :2018-08-09 
 * @function   :Set coordinate value
 * @parameters :Xpos:the  x coordinate of the pixel
								Ypos:the  y coordinate of the pixel
 * @retvalue   :None
******************************************************************************/ 
void LCD_SetCursor(u16 Xpos, u16 Ypos)
{	  	    			
	LCD_SetWindows(Xpos,Ypos,Xpos,Ypos);	
} 

/*****************************************************************************
 * @name       :void LCD_direction(u8 direction)
 * @date       :2018-08-09 
 * @function   :Setting the display direction of LCD screen
 * @parameters :direction:0-0 degree
                          1-90 degree
													2-180 degree
													3-270 degree
 * @retvalue   :None
******************************************************************************/ 
void LCD_direction(u8 direction)
{ 
			lcddev.setxcmd=0x2A;
			lcddev.setycmd=0x2B;
			lcddev.wramcmd=0x2C;
	switch(direction){		  
		case 0:						 	 		
			lcddev.width=LCD_W;
			lcddev.height=LCD_H;		
//			LCD_WriteReg(0x36,(1<<3)|(0<<6)|(0<<7));//BGR==1,MY==0,MX==0,MV==0
		break;
		case 1:
			lcddev.width=LCD_H;
			lcddev.height=LCD_W;
//			LCD_WriteReg(0x36,(1<<3)|(0<<7)|(1<<6)|(1<<5));//BGR==1,MY==1,MX==0,MV==1
		break;
		case 2:						 	 		
			lcddev.width=LCD_W;
			lcddev.height=LCD_H;	
//		LCD_WriteReg(0x36,(1<<3)|(1<<6)|(1<<7));//BGR==1,MY==0,MX==0,MV==0
		break;
		case 3:
			lcddev.width=LCD_H;
			lcddev.height=LCD_W;
//			LCD_WriteReg(0x36,(1<<3)|(1<<7)|(1<<5));//BGR==1,MY==1,MX==0,MV==1
		break;	
		default:break;
	}		
}	 

离线

#3 2019-12-09 08:32:57

晕哥
管理员
注册时间: 2017-09-06
累计积分: 9,190

Re: spi + rgb LG4573 屏驱动资料 (已售罄)

后来经过比较, 驱动代码全部来自: https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/panel/panel-lg-lg4573.c

通过SPI 把 LG4573 设置为 RGB 模式。



注意: 一楼的代码只完成了 LG4573 的初始化, 并没有驱动屏幕, 需要用soc提供PCLK, HSYNC/VSYNC, RGB等信号

离线

#4 2019-12-09 08:46:02

晕哥
管理员
注册时间: 2017-09-06
累计积分: 9,190

Re: spi + rgb LG4573 屏驱动资料 (已售罄)

QQ图片20191209084439.jpg

QQ图片20191209084433.jpg

LCD图片

离线

#5 2020-06-22 23:20:13

salalei
会员
注册时间: 2020-06-22
累计积分: 3

Re: spi + rgb LG4573 屏驱动资料 (已售罄)

看这个程序 难道这个可以直接通过spi总线去刷屏幕吗?

离线

#6 2020-08-05 11:54:40

zhangmufa
会员
注册时间: 2020-08-05
累计积分: 2

Re: spi + rgb LG4573 屏驱动资料 (已售罄)

我正在弄这个,代理给的初始化代码不亮,参考下

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB