[li]/* Windowing configuration */ [/li][li]/* In this case all the active display area is used to display a picture then: [/li][li]Horizontal start = horizontal synchronization + Horizontal back porch = 30 [/li][li]Horizontal stop = Horizontal start + window width -1 = 30 + 240 -1 [/li][li]Vertical start = vertical synchronization + vertical back porch = 4 [/li][li]Vertical stop = Vertical start + window height -1 = 4 + 320 -1 */ [/li][li]LTDC_Layer_InitStruct.LTDC_HorizontalStart = 30; [/li][li]LTDC_Layer_InitStruct.LTDC_HorizontalStop = (240 + 30 - 1); [/li][li]LTDC_Layer_InitStruct.LTDC_VerticalStart = 4; [/li][li]LTDC_Layer_InitStruct.LTDC_VerticalStop = 320 + 4 -1; [/li]
每个Layer关联了一个显示缓冲区FrameBuffer,由于Background只能使用单色填充,所以它没有FrameBuffer。关于FrameBuffer有几个参数:Pixel Format、Buffer Address、Line Length、Number of lines、Buffer Pitch,这几个参数都是针对于Layer的Window而言的,它们的含义如下:
Pixel Format:不多说,RGB565、ARGB8888、ARGB1555等等;
Buffer Address:显示缓冲区的起始地址;
Line Length:window所对应的缓冲区宽度+3,以字节为单位;
Number of Lines:window所对应的缓冲区高度,以字节为单位;
Buffer Pitch:从这一行起始到下一行起始所经过的字节数,说白了就是换行时的一个行指针增量(也可以理解为整幅图像的宽度,以字节为单位);
假设Layer1的FrameBuffer如下图(RGB565):
设置window要显示的图像为下图粉色部分:
结合之前设置的Window的位置,最终显示的图像如下图(不考虑Layer2及透明色):
由此可以看到:
Start Address、Buffer Pitch决定了window在显存中每行的起始位置;
Line Length、Line Number决定了window在显存中的大小。
该部分所对应的代码如下:
[li]/* Input Address configuration */ [/li][li]LTDC_Layer_InitStruct.LTDC_CFBStartAdress = (u32)FrameBuffer; [/li][li] [/li][li]/* the length of one line of pixels in bytes + 3 then : [/li][li]Line Lenth = Active high width x number of bytes per pixel + 3 [/li][li]Active high width = 240 [/li][li]number of bytes per pixel = 2 (pixel_format : RGB565) [/li][li]*/ [/li][li]LTDC_Layer_InitStruct.LTDC_CFBLineLength = ((240 * 2) + 3); [/li][li] [/li][li]/* the pitch is the increment from the start of one line of pixels to the [/li][li]start of the next line in bytes, then : [/li][li]Pitch = Active high width x number of bytes per pixel [/li][li]*/ [/li][li]LTDC_Layer_InitStruct.LTDC_CFBPitch = (240 * 2); [/li][li] [/li][li]/* configure the number of lines */ [/li][li]LTDC_Layer_InitStruct.LTDC_CFBLineNumber = 320; [/li]
手册写的:
Total Width: The Total width is configured by programming the accumulated value
HSYNC Width + HBP + Active Width + HFP - 1 in the LTDC_TWCR register. The
HFP is the Horizontal front porch period.