Display driver callback functions¶
The display driver callback function is the only interface used by the upper-level driver framework to operate the display driver. The interface often uses register read/write functions to operate the LCD.
The display driver callback functions mainly include the following functions (optional functions do not need to be implemented; they can be left empty or assigned NULL):
Callback function |
Description |
|---|---|
[Required], screen driver initialization function (including reset, initialization procedure, and so on) |
|
[Required], screen presence detection function |
|
[Required], turn on the screen |
|
[Required], turn off the screen |
|
[Required], set the area where the screen receives data (2A, 2B area) |
|
Optional, write one pixel to the screen |
|
[Required], write a batch of pixels to the screen |
|
Optional, read one pixel of data from the screen and return the RGB value of the pixel |
|
Optional, switch the color format output to the screen |
|
Optional, set screen brightness |
|
Optional, enter standby display mode (low-power mode) |
|
Optional, exit standby display mode (low-power mode) |
|
Optional, rotate the screen by a certain angle |
|
Optional, screen self-test after bulk data transfer timeout |
|
Optional, screen reset after bulk data transfer timeout |
|
Optional, periodic screen ESD detection |
LCD controller register read/write interfaces¶
These interfaces automatically communicate with the display according to the interface type and frequency set for the LCD controller by HAL_LCDC_Init:
Register write functions:
HAL_LCDC_WriteU8Reg,HAL_LCDC_WriteU16Reg,HAL_LCDC_WriteU32RegRegister read functions:
HAL_LCDC_ReadU8Reg,HAL_LCDC_ReadU16Reg,HAL_LCDC_ReadU32Reg
Note
Registers and data are sent in little-endian order. For example, when writing a register on an SPI display:
uint8_t param[4] = {0xAA, 0xBB, 0xCC, 0xDD};
HAL_LCDC_WriteU32Reg(hlcdc, 0x78563412, ¶m, 4);
The bytes transmitted on the interface are therefore ordered as 0x12,0x34,0x56,0x78, 0xAA, 0xBB, 0xCC, 0xDD.
LCD_Init¶
The first function called by the display driver: initialization. This mainly includes:
Call
HAL_LCDC_Initto initialize the LCD controller and set the interface type, frequency, data format, and other parameters.Reset the display through the
BSP_LCD_Resetinterface, and useLCD_DRIVER_DELAY_MSfor delays.Then send the commands from the display initialization command table provided by the manufacturer to the display through SiFli’s register write interface.
The following figure is a screenshot of a display driver:
LCD_ReadID¶
The display presence detection function. The value returned by this function is compared with the LCD_ID provided when the display driver is registered. If they are the same, the display driver framework considers this display driver available. Otherwise, this display driver will not be called.
This is the LCD_ID provided during display driver registration:
LCD_DRIVER_EXPORT2(nv3051f1, LCD_ID, &lcdc_int_cfg, &LCD_drv,2);
Note
This function can directly return the registered ID. It is suitable for the following cases:
There is only one display, and compatibility with multiple display drivers is not required.
The display does not support ID reading.
LCD_DisplayOn¶
This function usually sends the Display on command of the display driver. Refer to the datasheet of the display driver IC for the command format.
LCD_DisplayOff¶
This function usually sends the Display off command of the display driver. Refer to the datasheet of the display driver IC for the command format.
LCD_SetRegion¶
This function sets the output area of the LCD controller and the receiving area of the display driver.
Set the output area of the LCD controller through
HAL_LCDC_SetROIArea.Send the receiving-window command of the display driver, generally registers 2A and 2B.
In general, these two areas can be set to the same area directly according to the parameters passed to SetRegion. For RAM-less displays such as DPI and DSI video displays, they can be set once during initialization and do not need to be set repeatedly later.
LCD_WritePixel¶
Write one pixel of data to the display.
LCD_WriteMultiplePixels¶
This function sets the framebuffer address and its area, and then triggers screen refresh.
Set the framebuffer address and coordinate area through
HAL_LCDC_LayerSetData.Use
HAL_LCDC_SendLayerData2Reg_ITto send the register address for bulk data write first, and then send RGB data to the display. For DPI and DSI video displays that do not have a register address, callHAL_LCDC_SendLayerData_ITto start sending RGB data.
LCD_ReadPixel¶
TODO.
LCD_SetColorMode¶
TODO.
LCD_SetBrightness¶
There are generally two ways to set the display backlight:
Directly modify display registers to change the LCD transparency. This is generally used on AMOLED displays, roughly as follows:
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”. This is generally used only by TFT displays and is not needed for AMOLED displays. It is roughly as follows:
rt_device_t device = rt_device_find("lcdlight"); //查找背光设备
if (device)
{
rt_err_t err = rt_device_open(device, RT_DEVICE_OFLAG_RDWR);//打开设备
uint8_t val = br;
rt_device_write(device, 0, &val, 1); //设置背光值
rt_device_close(device); //关闭device(不会关闭背光)
}
LCD_IdleModeOn¶
TODO.
LCD_IdleModeOff¶
TODO.
LCD_Rotate¶
TODO.
LCD_TimeoutDbg¶
TODO.
LCD_TimeoutReset¶
TODO.
LCD_ESDCheck¶
TODO.