屏驱回调函数¶
The screen driver callback function is the only interface for the upper-level driver framework to operate the screen driver,接口里面会经常用到寄存器的读写函数去操作LCD,
The screen driver callback function mainly includes the following functions(For non-mandatory ones, they can be left unimplemented, empty, or assigned NULL):
回调函数 |
说明 |
---|---|
【必选】,Screen driver initialization function (including reset, initialization program, etc.) |
|
【必选】,Screen in-place detection function |
|
【必选】,Turn on the screen |
|
【必选】,Turn off the screen |
|
【必选】,Set the area when the screen receives data(2A,2B 的区域) |
|
可选,Write a pixel point to the screen |
|
【必选】,Write batch pixel points to the screen |
|
可选,Read a pixel point data on the screen, return the RGB value of the pixel |
|
可选,Switch the color format output to the screen |
|
可选,Set the brightness of the screen |
|
可选,Enter standby display mode (low power consumption mode) |
|
可选,Exit standby display mode (low power consumption mode) |
|
可选,Rotate the screen by a certain angle |
|
可选,After batch sending times out, the screen performs self-check |
|
可选,After batch sending times out, the screen resets |
|
可选,Screen timed ESD detection |
Read-write interface for LCD controller registers¶
这些接口会自动根据LCD控制器根据HAL_LCDC_Init
设置的接口类型、频率去跟屏幕通信:
Register write function
HAL_LCDC_WriteU8Reg
,HAL_LCDC_WriteU16Reg
,HAL_LCDC_WriteU32Reg
Register read function
HAL_LCDC_ReadU8Reg
,HAL_LCDC_ReadU16Reg
,HAL_LCDC_ReadU32Reg
Note
The transmission of registers and data is little-endian,例如某SPI屏幕写寄存器调用:
uint8_t param[4] = {0xAA, 0xBB, 0xCC, 0xDD};
HAL_LCDC_WriteU32Reg(hlcdc, 0x78563412, ¶m, 4);
则在接口上传输的是按照0x12,0x34,0x56,0x78, 0xAA, 0xBB, 0xCC, 0xDD的字节顺序。
LCD_Init¶
The first function called by the screen driver, initialization。 这里面主要是:
调用
HAL_LCDC_Init
初始化LCD控制器,设定接口的类型、频率、数据格式等等。通过
BSP_LCD_Reset
接口复位屏幕,使用LCD_DRIVER_DELAY_MS
来做延时。然后从厂家提供的屏幕初始化命令表里面,将命令用思澈的寄存器写接口,送到屏幕上去。
下图是某个屏驱的截图:

LCD_ReadID¶
The screen in-place detection function, the value returned by this function will be compared with the LCD_ID provided during screen driver registration, if they are the same, the screen driver framework considers the screen driver usable。 Otherwise, the screen driver will not be called。
这个就是屏驱注册时提供的LCD_ID:
LCD_DRIVER_EXPORT2(nv3051f1, LCD_ID, &lcdc_int_cfg, &LCD_drv,2);
Note
This function can directly return the registered ID, applicable to the following situations:
There is only one screen, no need to be compatible with multiple screen driver functions
The screen does not support reading ID
LCD_DisplayOn¶
Generally, this function sends the Display on command of the screen driver。命令格式参考屏驱IC的Datasheet。
LCD_DisplayOff¶
Generally, this function sends the Display off command of the screen driver。命令格式参考屏驱IC的Datasheet。
LCD_SetRegion¶
This function sets the output area of the LCD controller and the receiving area of the screen driver。
通过
HAL_LCDC_SetROIArea
设置LCD控制器的输出区域。Send the receiving window command of the screen driver, usually 2A, 2B registers
一般情况下,这2个区域直接根据SetRegion
传入的参数设置相同区域即可。If it’s DPI, DSI video and other ramless screens, it can be initialized once, no need to set repeatedly later。
LCD_WritePixel¶
Write 1 pixel data to the screen
LCD_WriteMultiplePixels¶
This function sets the address and area of the Framebuffer, then triggers the screen refresh。
通过
HAL_LCDC_LayerSetData
设置Framebuffer所在的地址以及坐标区域。通过
HAL_LCDC_SendLayerData2Reg_IT
先发送批量写数据的寄存器地址,然后发送RGB数据到屏幕。对于DPI、DSI video这种没有寄存器地址的,调用HAL_LCDC_SendLayerData_IT
启动送RGB数据。
LCD_ReadPixel¶
TODO.
LCD_SetColorMode¶
TODO.
LCD_SetBrightness¶
To set the backlight of the screen, there are generally two methods:
Directly modify the screen register to change the transparency of the liquid crystal。一般用在AMOLED屏幕上,大概是这样:
uint8_t bright = (uint8_t)((int)255 * br / 100); //百分比转换为0~255的值
LCD_WriteReg(hlcdc, 0x51, &bright, 1); //设置背光寄存器,一般是0x51
Modify the brightness of the backlight device “lcdlight”。这种一般是TFT屏幕才会用到,AMOLED屏幕则不需要。大概是这样:
rt_device_t device = rt_device_find("lcdlight"); //Find the backlight device
if (device)
{
rt_err_t err = rt_device_open(device, RT_DEVICE_OFLAG_RDWR);//Open the device
uint8_t val = br;
rt_device_write(device, 0, &val, 1); //Set the backlight value
rt_device_close(device); //Close the device (will not turn off the backlight)
}
LCD_IdleModeOn¶
TODO.
LCD_IdleModeOff¶
TODO.
LCD_Rotate¶
TODO.
LCD_TimeoutDbg¶
TODO.
LCD_TimeoutReset¶
TODO.
LCD_ESDCheck¶
TODO.