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

LCD_Init

[Required], screen driver initialization function (including reset, initialization procedure, and so on)

LCD_ReadID

[Required], screen presence detection function

LCD_DisplayOn

[Required], turn on the screen

LCD_DisplayOff

[Required], turn off the screen

LCD_SetRegion

[Required], set the area where the screen receives data (2A, 2B area)

LCD_WritePixel

Optional, write one pixel to the screen

LCD_WriteMultiplePixels

[Required], write a batch of pixels to the screen

LCD_ReadPixel

Optional, read one pixel of data from the screen and return the RGB value of the pixel

LCD_SetColorMode

Optional, switch the color format output to the screen

LCD_SetBrightness

Optional, set screen brightness

LCD_IdleModeOn

Optional, enter standby display mode (low-power mode)

LCD_IdleModeOff

Optional, exit standby display mode (low-power mode)

LCD_Rotate

Optional, rotate the screen by a certain angle

LCD_TimeoutDbg

Optional, screen self-test after bulk data transfer timeout

LCD_TimeoutReset

Optional, screen reset after bulk data transfer timeout

LCD_ESDCheck

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:

  1. Register write functions: HAL_LCDC_WriteU8Reg, HAL_LCDC_WriteU16Reg, HAL_LCDC_WriteU32Reg

  2. Register 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, &param, 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:

  1. Call HAL_LCDC_Init to initialize the LCD controller and set the interface type, frequency, data format, and other parameters.

  2. Reset the display through the BSP_LCD_Reset interface, and use LCD_DRIVER_DELAY_MS for delays.

  3. 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:

../../_images/LCD_Init_func.png

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:

  1. There is only one display, and compatibility with multiple display drivers is not required.

  2. 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.

  1. Set the output area of the LCD controller through HAL_LCDC_SetROIArea.

  2. 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.

Relative relationship among the LCD controller output area, display driver receiving area, framebuffer area, and the three areas

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.

  1. Set the framebuffer address and coordinate area through HAL_LCDC_LayerSetData.

  2. Use HAL_LCDC_SendLayerData2Reg_IT to 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, call HAL_LCDC_SendLayerData_IT to start sending RGB data.

Relative relationship among the LCD controller output area, display driver receiving area, framebuffer area, and the three areas

LCD_ReadPixel

TODO.

LCD_SetColorMode

TODO.

LCD_SetBrightness

There are generally two ways to set the display backlight:

  1. 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
  1. 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.