zoukankan      html  css  js  c++  java
  • STM32F4 LTDC学习

    很久没有写东西了,也很久没看文档了吼吼,觉得有点无聊,找来F4看看,主要看F429。督促自己多看多记录。

    首先配置同步时序先看参考手册

    下面看一个实际例子,一块439的开发板

    设置:

     1  LTDC_InitStruct.LTDC_HorizontalSync = 40;
     2   /*  */
     3   LTDC_InitStruct.LTDC_VerticalSync = 9;
     4   /*  */
     5   LTDC_InitStruct.LTDC_AccumulatedHBP = 42; 
     6   /*  */
     7   LTDC_InitStruct.LTDC_AccumulatedVBP = 11;  
     8   /*  */
     9   LTDC_InitStruct.LTDC_AccumulatedActiveW = 522;
    10   /*  */
    11   LTDC_InitStruct.LTDC_AccumulatedActiveH = 283;
    12   /*  */
    13   LTDC_InitStruct.LTDC_TotalWidth = 524; 
    14   /*  */
    15   LTDC_InitStruct.LTDC_TotalHeigh = 285;
    16             
    17   LTDC_Init(&LTDC_InitStruct);
    配置时序

    注意每个参数定义,之前是累加

    看下完整的初始化代码

      1 void LCD_Init(void)
      2 {
      3   LTDC_InitTypeDef       LTDC_InitStruct;
      4   LTDC_Layer_InitTypeDef LTDC_Layer_InitStruct;
      5   LTDC_Layer_TypeDef     LTDC_Layerx;
      6   
      7     
      8   /* IO¿Ú³õʼ»¯ */
      9   LCD_GPIOInit();
     10     
     11   LCD_DisplayOff();
     12   /* ʹÄÜLCDʱÖÓ */
     13   RCC_APB2PeriphClockCmd(RCC_APB2Periph_LTDC, ENABLE);
     14   /* ʹÄÜDMAʧ×Ù*/
     15   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2D, ENABLE);
     16     
     17   /* ˮƽͬ²½ÐźÅ---µÍµçƽÓÐЧ */
     18   LTDC_InitStruct.LTDC_HSPolarity = LTDC_HSPolarity_AL;     
     19   /* ´¹Ö±Í¬²½ÐźÅ---µÍµçƽÓÐЧ */  
     20   LTDC_InitStruct.LTDC_VSPolarity = LTDC_VSPolarity_AL;     
     21   /* Êý¾ÝʹÄÜÐźÅ---µÍµçƽÓÐЧ */
     22   LTDC_InitStruct.LTDC_DEPolarity = LTDC_DEPolarity_AL;     
     23   /* ÏñËØʱÖÓÅäÖÃ--- */ 
     24   LTDC_InitStruct.LTDC_PCPolarity = LTDC_DEPolarity_AL;
     25     /* LCD±³¹âÉèÖà */
     26   LTDC_InitStruct.LTDC_BackgroundRedValue = 0;            
     27   LTDC_InitStruct.LTDC_BackgroundGreenValue = 0;          
     28   LTDC_InitStruct.LTDC_BackgroundBlueValue = 0;      
     29   /*
     30    ****************************************************************************
     31    *PLLSAI_VCO = HSE*PLLSAI_N / PLL_M = 8 * 192 / 8 = 192MHz
     32    *PLLLCDCLK = PLLSAI_VCO / PLLSAI_R = 192 / 3 = 64 Mhz
     33    *LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDivR = 64 / 8 = 8 Mhz
     34    ****************************************************************************
     35    */
     36   RCC_PLLSAIConfig(192, 7, 3);
     37   RCC_LTDCCLKDivConfig(RCC_PLLSAIDivR_Div4);    
     38   /* ʹÄÜPLLSAIʱÖÓ */
     39   RCC_PLLSAICmd(ENABLE);
     40   /* µÈ´ýPLLSAIʱÖÓ */
     41   while(RCC_GetFlagStatus(RCC_FLAG_PLLSAIRDY) == RESET){}
     42   /*  */
     43   LTDC_InitStruct.LTDC_HorizontalSync = 40;
     44   /*  */
     45   LTDC_InitStruct.LTDC_VerticalSync = 9;
     46   /*  */
     47   LTDC_InitStruct.LTDC_AccumulatedHBP = 42; 
     48   /*  */
     49   LTDC_InitStruct.LTDC_AccumulatedVBP = 11;  
     50   /*  */
     51   LTDC_InitStruct.LTDC_AccumulatedActiveW = 522;
     52   /*  */
     53   LTDC_InitStruct.LTDC_AccumulatedActiveH = 283;
     54   /*  */
     55   LTDC_InitStruct.LTDC_TotalWidth = 524; 
     56   /*  */
     57   LTDC_InitStruct.LTDC_TotalHeigh = 285;
     58             
     59   LTDC_Init(&LTDC_InitStruct);
     60         
     61   LTDC_Layer_InitStruct.LTDC_HorizontalStart = 43;
     62   LTDC_Layer_InitStruct.LTDC_HorizontalStop = (480 + 43 - 1); 
     63   LTDC_Layer_InitStruct.LTDC_VarticalStart = 12;
     64   LTDC_Layer_InitStruct.LTDC_VerticalStop = (272 + 12 - 1);    
     65 
     66   /* Pixel Format configuration*/            
     67   LTDC_Layer_InitStruct.LTDC_PixelFormat = LTDC_Pixelformat_RGB565;
     68   /* Alpha constant (255 totally opaque) */
     69   LTDC_Layer_InitStruct.LTDC_ConstantAlpha = 255; 
     70   /* Default Color configuration (configure A,R,G,B component values) */          
     71   LTDC_Layer_InitStruct.LTDC_DefaultColorBlue = 0;        
     72   LTDC_Layer_InitStruct.LTDC_DefaultColorGreen = 0;       
     73   LTDC_Layer_InitStruct.LTDC_DefaultColorRed = 0;         
     74   LTDC_Layer_InitStruct.LTDC_DefaultColorAlpha = 0;
     75   /* Configure blending factors */       
     76   LTDC_Layer_InitStruct.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_CA;    
     77   LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_CA;
     78   /* the length of one line of pixels in bytes + 3 then :
     79      Line Lenth = Active high width x number of bytes per pixel + 3 
     80      Active high width         = LCD_PIXEL_WIDTH 
     81      number of bytes per pixel = 2    (pixel_format : RGB565) 
     82   */
     83   LTDC_Layer_InitStruct.LTDC_CFBLineLength = ((480 * 2) + 3);
     84   /*  the pitch is the increment from the start of one line of pixels to the 
     85       start of the next line in bytes, then :
     86       Pitch = Active high width x number of bytes per pixel     
     87   */ 
     88   LTDC_Layer_InitStruct.LTDC_CFBPitch = (480 * 2);
     89   /* configure the number of lines */  
     90   LTDC_Layer_InitStruct.LTDC_CFBLineNumber = 272;
     91 
     92   /* Input Address configuration */    
     93   LTDC_Layer_InitStruct.LTDC_CFBStartAdress = LCD_FRAME_BUFFER;
     94    
     95   LTDC_LayerInit(LTDC_Layer1, &LTDC_Layer_InitStruct);
     96 
     97   /* Configure Layer2 */
     98   LTDC_Layer_InitStruct.LTDC_CFBStartAdress = LCD_FRAME_BUFFER + BUFFER_OFFSET;
     99   LTDC_Layer_InitStruct.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_PAxCA;    
    100   LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_PAxCA;
    101   LTDC_LayerInit(LTDC_Layer2, &LTDC_Layer_InitStruct);
    102     
    103   LTDC_ReloadConfig(LTDC_IMReload);
    104   
    105   /* Enable foreground & background Layers */
    106   LTDC_LayerCmd(LTDC_Layer1, ENABLE);
    107 //  LTDC_LayerCmd(LTDC_Layer2, ENABLE);
    108   LTDC_ReloadConfig(LTDC_IMReload);
    109     
    110   LCD_DisplayOn();
    111 }
    LCD_Init

    LTDC_DefaultColorBlue就是背景色

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

    填色直接写内存

     1 int main (void)
     2 {
     3   uint32_t i, j;
     4   uint16_t *addr = (uint16_t *)LCD_FRAME_BUFFER;
     5     
     6     
     7   SDRAM_Init();
     8   LCD_Init();
     9     j = 0;
    10   while (1) {
    11         
    12     for (i = 0; i < 0x2000000;i++);
    13     for (i = 0; i < 480 * 272; i++) 
    14     {
    15       addr[i] = 1 << j;
    16     }
    17     j++;
    18     if (j > 15)j = 0;        
    19   }    
    20 }
    LCD display RGB
  • 相关阅读:
    太白老师 day06 编码 encode decode
    太白老师day6 1.代码块 2.is==id 3.小数据池
    MySQL 基本语法(1.表字段操作,2表记录管理 3.运算符管理4.SQL查询 5.约束6.索引
    List 接口常用子类及其特点
    Java 集合框架
    Java 常用工具类之基本对象包装类
    Java 常用工具类之 String 类
    Java 多线程间通信
    Java 多线程通信之多生产者/多消费者
    Java 之多线程通信(等待/唤醒)
  • 原文地址:https://www.cnblogs.com/wwjdwy/p/4582076.html
Copyright © 2011-2022 走看看