屏驱回调函数

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):

回调函数

说明

LCD_Init

【必选】,Screen driver initialization function (including reset, initialization program, etc.)

LCD_ReadID

【必选】,Screen in-place detection function

LCD_DisplayOn

【必选】,Turn on the screen

LCD_DisplayOff

【必选】,Turn off the screen

LCD_SetRegion

【必选】,Set the area when the screen receives data(2A,2B 的区域)

LCD_WritePixel

可选,Write a pixel point to the screen

LCD_WriteMultiplePixels

【必选】,Write batch pixel points to the screen

LCD_ReadPixel

可选,Read a pixel point data on the screen, return the RGB value of the pixel

LCD_SetColorMode

可选,Switch the color format output to the screen

LCD_SetBrightness

可选,Set the brightness of the screen

LCD_IdleModeOn

可选,Enter standby display mode (low power consumption mode)

LCD_IdleModeOff

可选,Exit standby display mode (low power consumption mode)

LCD_Rotate

可选,Rotate the screen by a certain angle

LCD_TimeoutDbg

可选,After batch sending times out, the screen performs self-check

LCD_TimeoutReset

可选,After batch sending times out, the screen resets

LCD_ESDCheck

可选,Screen timed ESD detection

Read-write interface for LCD controller registers

这些接口会自动根据LCD控制器根据HAL_LCDC_Init设置的接口类型、频率去跟屏幕通信:

  1. Register write functionHAL_LCDC_WriteU8RegHAL_LCDC_WriteU16RegHAL_LCDC_WriteU32Reg

  2. Register read functionHAL_LCDC_ReadU8RegHAL_LCDC_ReadU16RegHAL_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, &param, 4);

则在接口上传输的是按照0x12,0x34,0x56,0x78, 0xAA, 0xBB, 0xCC, 0xDD的字节顺序。

LCD_Init

The first function called by the screen driver, initialization。 这里面主要是:

  1. 调用HAL_LCDC_Init初始化LCD控制器,设定接口的类型、频率、数据格式等等。

  2. 通过BSP_LCD_Reset接口复位屏幕,使用LCD_DRIVER_DELAY_MS来做延时。

  3. 然后从厂家提供的屏幕初始化命令表里面,将命令用思澈的寄存器写接口,送到屏幕上去。

下图是某个屏驱的截图:

../../_images/LCD_Init_func.png

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:

  1. There is only one screen, no need to be compatible with multiple screen driver functions

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

  1. 通过HAL_LCDC_SetROIArea设置LCD控制器的输出区域。

  2. 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控制器输出区域、屏驱接收区域、Framebuffer所在区域、3者的相对关系

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。

  1. 通过HAL_LCDC_LayerSetData设置Framebuffer所在的地址以及坐标区域。

  2. 通过HAL_LCDC_SendLayerData2Reg_IT先发送批量写数据的寄存器地址,然后发送RGB数据到屏幕。对于DPI、DSI video这种没有寄存器地址的,调用HAL_LCDC_SendLayerData_IT启动送RGB数据。

LCD控制器输出区域、屏驱接收区域、Framebuffer所在区域、3者的相对关系

LCD_ReadPixel

TODO.

LCD_SetColorMode

TODO.

LCD_SetBrightness

To set the backlight of the screen, there are generally two methods:

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