OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 8268|回复: 6

STM32F429之LTDC驱动图解

[复制链接]

12

主题

39

帖子

4

精华

高级会员

Rank: 4

积分
724
金钱
724
注册时间
2013-5-10
在线时间
2 小时
发表于 2015-3-2 01:06:28 | 显示全部楼层 |阅读模式

本文基于ST官方demo板STM32F429 Discovery硬件平台,以看图说话的形式给大家讲解LTDC的主要参数配置。关于本文提到的代码部分均摘自本人另一片文章《STM32F429之LTDC代码模板》,LCD硬件为240x320,驱动IC为ili9341。本文目的意在让大家通过几张图就能掌握STM32F429 LTDC控制器的配置要领,而从干涩的文字中解脱出来,方便记忆。当然本文只是讲解了LTDC一些常用的设置,关于更多细节的操作还是得参照ST的官方datasheet。


一、关于LTDC外设的时钟配置,只需要记住下面这张图就可以了(图片来源于STM32CubeMX RCC时钟树):

该图所对应的代码如下:

  1. /* Configure LLSAI prescalers for LCD */  
  2. /* LLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */  
  3. /* LLSAI_VCO Output = LLSAI_VCO Input * LLSAI_N = 192 Mhz */  
  4. /* LLLCDCLK = LLSAI_VCO Output/PLLSAI_R = 192/3 = 64 Mhz */  
  5. /* LTDC clock frequency = LLLCDCLK / RCC_PLLSAIDivR = 64/8 = 8 Mhz */  
  6. RCC_PLLSAIConfig(192, 7, 3);  
  7. RCC_LTDCCLKDivConfig(RCC_PLLSAIDivR_Div8);  
  8.   
  9. /* Enable LLSAI Clock */  
  10. RCC_PLLSAICmd(ENABLE);  
  11. /* Wait for LLSAI activation */  
  12. while(RCC_GetFlagStatus(RCC_FLAG_PLLSAIRDY) == RESET)  
  13. {  
  14. }  



二、关于LCD的信号时序配置参数,只需要记住下面这张图就可以了:

注意:这部分需要根据LCD Datasheet要求严格配置。

改图所对应的代码如下:

  1. /* Initialize the horizontal synchronization polarity as active low*/  
  2. LTDC_InitStruct.LTDC_HSPolarity = LTDC_HSPolarity_AL;       
  3. /* Initialize the vertical synchronization polarity as active low */    
  4. LTDC_InitStruct.LTDC_VSPolarity = LTDC_VSPolarity_AL;       
  5. /* Initialize the data enable polarity as active low */   
  6. LTDC_InitStruct.LTDC_DEPolarity = LTDC_DEPolarity_AL;       
  7. /* Initialize the pixel clock polarity as input pixel clock */   
  8. LTDC_InitStruct.LTDC_PCPolarity = LTDC_PCPolarity_IPC;  
  9.   
  10. /* Timing configuration */  
  11. /* Configure horizontal synchronization width */       
  12. LTDC_InitStruct.LTDC_HorizontalSync = 9;  
  13. /* Configure vertical synchronization height */  
  14. LTDC_InitStruct.LTDC_VerticalSync = 1;  
  15. /* Configure accumulated horizontal back porch */  
  16. LTDC_InitStruct.LTDC_AccumulatedHBP = 29;   
  17. /* Configure accumulated vertical back porch */  
  18. LTDC_InitStruct.LTDC_AccumulatedVBP = 3;    
  19. /* Configure accumulated active width */    
  20. LTDC_InitStruct.LTDC_AccumulatedActiveW = 269;  
  21. /* Configure accumulated active height */  
  22. LTDC_InitStruct.LTDC_AccumulatedActiveH = 323;  
  23. /* Configure total width */  
  24. LTDC_InitStruct.LTDC_TotalWidth = 279;   
  25. /* Configure total height */  
  26. LTDC_InitStruct.LTDC_TotalHeigh = 327;  

三、LTDC的层——Layer

关于层的概念有以下几点:

1. STM32F429共有3个层,分别为Background、Layer1、Layer2,任何时候LCD显示的图像都是由层叠加后的最终结果;

2. Background层任何时候都有效,而Layer1、Layer2可以通过软件配置使能或禁止;

3. 这3个层的空间顺序,从下往上依次为Background、Layer1、Layer2,所以叠加的顺序如下图:

每个Layer支持窗口(Window)操作,所谓Window,就是指该层的图像只有在Window区域内有效,而Window区域外则用该层的DefaultColor填充。如下图:


关于Layer Window显示位置及大小的配置,记住下面这张图就可以了:

该图所对应的代码如下:

  1. /* Windowing configuration */   
  2. /* In this case all the active display area is used to display a picture then: 
  3. Horizontal start = horizontal synchronization + Horizontal back porch = 30  
  4. Horizontal stop = Horizontal start + window width -1 = 30 + 240 -1 
  5. Vertical start   = vertical synchronization + vertical back porch     = 4 
  6. Vertical stop   = Vertical start + window height -1  = 4 + 320 -1      */   
  7. LTDC_Layer_InitStruct.LTDC_HorizontalStart = 30;  
  8. LTDC_Layer_InitStruct.LTDC_HorizontalStop = (240 + 30 - 1);   
  9. LTDC_Layer_InitStruct.LTDC_VerticalStart = 4;  
  10. LTDC_Layer_InitStruct.LTDC_VerticalStop = 320 + 4 -1;   


每个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在显存中的大小。

该部分所对应的代码如下:

  1. /* Input Address configuration */      
  2. LTDC_Layer_InitStruct.LTDC_CFBStartAdress = (u32)FrameBuffer;  
  3.   
  4. /* the length of one line of pixels in bytes + 3 then: 
  5. Line Lenth = Active high width x number of bytes per pixel + 3  
  6. Active high width         = 240  
  7. number of bytes per pixel = 2    (pixel_format: RGB565)  
  8. */  
  9. LTDC_Layer_InitStruct.LTDC_CFBLineLength = ((240 * 2) + 3);  
  10.   
  11. /*  the pitch is the increment from the start of one line of pixels to the  
  12. start of the next line in bytes, then: 
  13. Pitch = Active high width x number of bytes per pixel      
  14. */  
  15. LTDC_Layer_InitStruct.LTDC_CFBPitch = (240 * 2);    
  16.   
  17. /* configure the number of lines */  
  18. LTDC_Layer_InitStruct.LTDC_CFBLineNumber = 320;  


需要注意的是,为了保证图像能正确显示,请务必确认显存中图像的大小与window显示的大小一致,即Line Length、Line Number要与(HStop-HStart)、(VStop-VStart)相一致,否则显示将不正确。

最后不要忘了设置完所有Layer的寄存器后,光调用LTDC_LayerCmd()还不够,还需要调用LTDC_ReloadConfig(ENABLE)函数才能使所有层的设置生效。


文章来源于本人博客:http://blog.csdn.net/hexiaolong2009/article/details/43988083
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

120

主题

7878

帖子

13

精华

资深版主

Rank: 8Rank: 8

积分
12012
金钱
12012
注册时间
2013-9-10
在线时间
427 小时
发表于 2015-3-2 07:34:00 | 显示全部楼层
现在,程序把烂铜烂铁变得智能化了,人呢,一旦离开了这烂铜烂铁就不知道干啥了
回复 支持 反对

使用道具 举报

0

主题

3

帖子

0

精华

初级会员

Rank: 2

积分
65
金钱
65
注册时间
2015-2-8
在线时间
19 小时
发表于 2015-3-2 14:42:35 | 显示全部楼层
谢谢分享!!!
回复 支持 反对

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165536
金钱
165536
注册时间
2010-12-1
在线时间
2117 小时
发表于 2015-3-2 19:46:38 | 显示全部楼层
不错,谢谢分享
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复 支持 反对

使用道具 举报

1

主题

16

帖子

0

精华

初级会员

Rank: 2

积分
64
金钱
64
注册时间
2015-9-6
在线时间
7 小时
发表于 2015-11-30 15:31:42 | 显示全部楼层
谢谢分享,,,
回复 支持 反对

使用道具 举报

37

主题

246

帖子

0

精华

高级会员

Rank: 4

积分
773
金钱
773
注册时间
2016-9-10
在线时间
310 小时
发表于 2018-1-16 18:01:30 | 显示全部楼层
这是标准库写的么?
回复 支持 反对

使用道具 举报

0

主题

8

帖子

0

精华

新手上路

积分
25
金钱
25
注册时间
2018-12-21
在线时间
5 小时
发表于 2018-12-21 14:36:52 | 显示全部楼层
xiexie分享
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-9 11:12

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表