# 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](lcdc-reg-read-write-func) 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](lcd-cb-func-LCD-Init)| [Required], screen driver initialization function (including reset, initialization procedure, and so on) | | [LCD_ReadID](lcd-cb-func-LCD-ReadID)| [Required], screen presence detection function | | [LCD_DisplayOn](lcd-cb-func-LCD-DisplayOn)| [Required], turn on the screen | | [LCD_DisplayOff](lcd-cb-func-LCD-DisplayOff)| [Required], turn off the screen | | [LCD_SetRegion](lcd-cb-func-LCD-SetRegion)| [Required], set the area where the screen receives data (2A, 2B area)| | [LCD_WritePixel](lcd-cb-func-LCD-WritePixel)| Optional, write one pixel to the screen| | [LCD_WriteMultiplePixels](lcd-cb-func-LCD-WriteMultiplePixels)| [Required], write a batch of pixels to the screen| | [LCD_ReadPixel](lcd-cb-func-LCD-ReadPixel)| Optional, read one pixel of data from the screen and return the RGB value of the pixel| | [LCD_SetColorMode](lcd-cb-func-LCD-SetColorMode)| Optional, switch the color format output to the screen| | [LCD_SetBrightness](lcd-cb-func-LCD-SetBrightness)| Optional, set screen brightness | | [LCD_IdleModeOn](lcd-cb-func-LCD-IdleModeOn)| Optional, enter standby display mode (low-power mode) | | [LCD_IdleModeOff](lcd-cb-func-LCD-IdleModeOff)| Optional, exit standby display mode (low-power mode) | | [LCD_Rotate](lcd-cb-func-LCD-Rotate)| Optional, rotate the screen by a certain angle | | [LCD_TimeoutDbg](lcd-cb-func-LCD-TimeoutDbg)| Optional, screen self-test after bulk data transfer timeout | | [LCD_TimeoutReset](lcd-cb-func-LCD-TimeoutReset)| Optional, screen reset after bulk data transfer timeout | | [LCD_ESDCheck](lcd-cb-func-LCD-ESDCheck) | Optional, periodic screen ESD detection | (lcdc-reg-read-write-func)= ## 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, ¶m, 4); The bytes transmitted on the interface are therefore ordered as 0x12,0x34,0x56,0x78, 0xAA, 0xBB, 0xCC, 0xDD. ``` (lcd-cb-func-LCD-Init)= ## 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](lcdc-reg-read-write-func). The following figure is a screenshot of a display driver: ```{figure} assets/LCD_Init_func.png :scale: 30 % ``` (lcd-cb-func-LCD-ReadID)= ## 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-register): ```c 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-cb-func-LCD-DisplayOn)= ## 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-cb-func-LCD-DisplayOff)= ## 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-cb-func-LCD-SetRegion)= ## 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`. 1. 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-lcdc-coordinates-relationship) (lcd-cb-func-LCD-WritePixel)= ## LCD_WritePixel Write one pixel of data to the display. (lcd-cb-func-LCD-WriteMultiplePixels)= ## 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-lcdc-coordinates-relationship) (lcd-cb-func-LCD-ReadPixel)= ## LCD_ReadPixel TODO. (lcd-cb-func-LCD-SetColorMode)= ## LCD_SetColorMode TODO. (lcd-cb-func-LCD-SetBrightness)= ## 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: ```c uint8_t bright = (uint8_t)((int)255 * br / 100); //百分比转换为0~255的值 LCD_WriteReg(hlcdc, 0x51, &bright, 1); //设置背光寄存器,一般是0x51 ``` 2. 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: ```c 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-cb-func-LCD-IdleModeOn)= ## LCD_IdleModeOn TODO. (lcd-cb-func-LCD-IdleModeOff)= ## LCD_IdleModeOff TODO. (lcd-cb-func-LCD-Rotate)= ## LCD_Rotate TODO. (lcd-cb-func-LCD-TimeoutDbg)= ## LCD_TimeoutDbg TODO. (lcd-cb-func-LCD-TimeoutReset)= ## LCD_TimeoutReset TODO. (lcd-cb-func-LCD-ESDCheck)= ## LCD_ESDCheck TODO.